Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V7 compatibility #3

Merged
merged 13 commits into from
Mar 9, 2017
Next Next commit
Make ButtonTest v8 ready
  • Loading branch information
dve committed Mar 9, 2017
commit 1d9664ff598e81c72d34c64bbc1384a83cc5f20b
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.vaadin.touchkit.v7.gwt.client.vcom;

import java.util.List;

import org.vaadin.touchkit.gwt.client.ui.VerticalComponentGroupWidget;
import org.vaadin.touchkit.v7.ui.VerticalComponentGroup;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorHierarchyChangeEvent;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractLayoutConnector;
import com.vaadin.client.ui.Icon;
import com.vaadin.shared.ComponentConstants;
import com.vaadin.shared.communication.URLReference;
import com.vaadin.shared.ui.ComponentStateUtil;
import com.vaadin.shared.ui.Connect;
import com.vaadin.v7.client.ui.AbstractFieldConnector;

@SuppressWarnings("serial")
@Connect(VerticalComponentGroup.class)
public class VerticalComponentGroupConnector extends AbstractLayoutConnector {

@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
super.onStateChanged(stateChangeEvent);
}

@Override
public void onConnectorHierarchyChange(
ConnectorHierarchyChangeEvent event) {
if (getParent() == null) {
// Component is removed, skip stuff to save user from JS exceptions
// and some milliseconds of lost life
return;
}

List<ComponentConnector> oldChildren = event.getOldChildren();

List<ComponentConnector> children = getChildComponents();
for (int i = 0; i < children.size(); ++i) {
ComponentConnector connector = children.get(i);
Widget widget = connector.getWidget();
getWidget().addOrMove(widget, i);
oldChildren.remove(connector);
}

for (ComponentConnector oldChild : event.getOldChildren()) {
if (oldChild.getParent() != this) {
getWidget().remove(oldChild.getWidget());
}
}
}

@Override
protected VerticalComponentGroupWidget createWidget() {
return GWT.create(VerticalComponentGroupWidget.class);
}

@Override
public VerticalComponentGroupWidget getWidget() {
return (VerticalComponentGroupWidget) super.getWidget();
}

@Override
public void updateCaption(ComponentConnector connector) {
URLReference urlReference = connector.getState().resources
.get(ComponentConstants.ICON_RESOURCE);
Icon icon = null;
if (urlReference != null) {
icon = getConnection().getIcon(urlReference.getURL());
}
Widget child = connector.getWidget();
String style = "v-caption";
if (ComponentStateUtil.hasStyles(connector.getState())) {
for (String customStyle : connector.getState().styles) {
style += " " + "v-caption-" + customStyle;
}
}
if (connector instanceof AbstractFieldConnector) {
AbstractFieldConnector field = (AbstractFieldConnector) connector;
if (field.isRequiredIndicatorVisible()) {
style += " v-caption-required";
}
}
getWidget().updateCaption(child, connector.getState().caption, icon,
connector.getState().width, style);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Notification.Type;
import com.vaadin.v7.ui.themes.BaseTheme;
import com.vaadin.ui.themes.ValoTheme;;

public class ButtonTest extends AbstractTouchKitIntegrationTest implements
ClickListener {
Expand All @@ -21,7 +21,7 @@ public ButtonTest() {

Button link = new Button();
link.setCaption("link caption");
link.setStyleName(BaseTheme.BUTTON_LINK);
link.setStyleName(ValoTheme.BUTTON_LINK);
link.addClickListener(this);

addComponent(button);
Expand Down