Skip to content

Commit

Permalink
Merge pull request #3 from dve/v7-compatibility
Browse files Browse the repository at this point in the history
V7 compatibility
  • Loading branch information
mstahv authored Mar 9, 2017
2 parents dab9414 + 27fca02 commit 9d23baf
Show file tree
Hide file tree
Showing 52 changed files with 610 additions and 685 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.vaadin.touchkit.extensions;
package org.vaadin.touchkit.v7.extensions;

import java.util.Locale;

import org.vaadin.touchkit.gwt.client.vcom.Html5InputSettingsState;
import org.vaadin.touchkit.v7.gwt.client.vcom.Html5InputSettingsState;

import com.vaadin.server.AbstractExtension;
import com.vaadin.v7.ui.TextField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</replace-with>

<replace-with
class="org.vaadin.touchkit.gwt.client.Android2NativeSelectReplacement">
class="org.vaadin.touchkit.v7.gwt.client.Android2NativeSelectReplacement">
<when-type-is class="com.vaadin.client.ui.VNativeSelect" />
<when-property-is name="webkitvariant" value="android2" />
</replace-with>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* the License.
*/

package org.vaadin.touchkit.gwt.client;
package org.vaadin.touchkit.v7.gwt.client;

import java.util.ArrayList;
import java.util.Iterator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.vaadin.touchkit.gwt.client.vcom;
package org.vaadin.touchkit.v7.gwt.client.vcom;

import java.util.Map.Entry;

import org.vaadin.touchkit.extensions.Html5InputSettings;
import org.vaadin.touchkit.v7.extensions.Html5InputSettings;

import com.google.gwt.dom.client.InputElement;
import com.vaadin.client.ServerConnector;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.vaadin.touchkit.gwt.client.vcom;
package org.vaadin.touchkit.v7.gwt.client.vcom;

import java.util.HashMap;
import java.util.Map;
Expand Down
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
@@ -0,0 +1,62 @@
package org.vaadin.touchkit.v7.ui;

import org.vaadin.touchkit.ui.AbstractComponentGroup;

import com.vaadin.ui.Component;
import com.vaadin.v7.ui.Field;

/**
* The VerticalComponentGroup is a layout to group controls vertically. Unlike
* with default layouts, Components in a VerticalComponentGroup are visually
* decorated from other parts of the UI.
* <p>
* Captions are rendered on the same row as the component. Relative widths are
* relative to the {@link VerticalComponentGroup} width except if the component
* has a caption, in which case a relative width is relative to the remaining
* available space.
* <p>
* Most commonly {@link Field}s in {@link VerticalComponentGroup} should be full
* width, so {@link VerticalComponentGroup} automatically sets width to 100%
* when {@link Field}s are added to it, unless they have an explicit width
* defined.
*/
@SuppressWarnings("serial")
public class VerticalComponentGroup extends AbstractComponentGroup {

/**
* Constructs a vertical component group.
*/
public VerticalComponentGroup() {
super(null);
}

/**
* Creates a vertical component group with the provided caption.
*
* @param caption
* the caption.
*/
public VerticalComponentGroup(String caption) {
super(caption);
}

/**
* In addition to normal component addition, as a side effect this method
* ensures {@link Field}s have sane width set.
*
* @see org.vaadin.touchkit.ui.AbstractComponentGroup#addComponent(com.vaadin.ui.Component,
* int)
*/
@Override
public void addComponent(Component component, int index) {
verifySaneFieldWidth(component);
super.addComponent(component, index);
}

private void verifySaneFieldWidth(Component component) {
if ((component instanceof Field) && component.getWidth() < 0) {
component.setWidth("100%");
}
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package org.vaadin.touchkit.itest;
package org.vaadin.touchkit.v7.itest;

import org.vaadin.touchkit.AbstractTouchKitIntegrationTest;
import org.vaadin.touchkit.extensions.Html5InputSettings;
import org.vaadin.touchkit.ui.VerticalComponentGroup;
import org.vaadin.touchkit.v7.AbstractTouchKitIntegrationTest;
import org.vaadin.touchkit.v7.extensions.Html5InputSettings;

import com.vaadin.ui.Button;
import com.vaadin.v7.data.fieldgroup.FieldGroup;
import com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException;
import com.vaadin.v7.data.util.BeanItem;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.v7.ui.TextField;

public class Html5InputExtensionTest extends AbstractTouchKitIntegrationTest {
Expand Down Expand Up @@ -53,24 +51,20 @@ public Html5InputExtensionTest() {
verticalComponentGroup.addComponent(any);
Button button = new Button();
button.setCaption("Apply");
button.addClickListener(new ClickListener() {

@Override
public void buttonClick(ClickEvent event) {
try {
fieldGroup.commit();
String value = any.getValue();
if (value != null) {
String[] split = value.split(":");
html5InputSettings.setProperty(split[0], split[1]);
any.setValue(null);
}
} catch (CommitException e) {
e.printStackTrace();
}
button.addClickListener(event -> {
try {
fieldGroup.commit();
String value = any.getValue();
if (value != null) {
String[] split = value.split(":");
html5InputSettings.setProperty(split[0], split[1]);
any.setValue(null);
}
} catch (CommitException e) {
e.printStackTrace();
}

}
});
});
verticalComponentGroup.addComponent(button);
addComponent(verticalComponentGroup);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.vaadin.touchkit.itest.oldtests;
package org.vaadin.touchkit.v7.itest.oldtests;

import org.vaadin.touchkit.AbstractTouchKitIntegrationTest;
import org.vaadin.touchkit.ui.NavigationManager;
import org.vaadin.touchkit.ui.NavigationView;
import org.vaadin.touchkit.v7.AbstractTouchKitIntegrationTest;

import com.vaadin.event.Action;
import com.vaadin.event.Action.Handler;
Expand All @@ -29,11 +29,13 @@ public ContextMenu() {
private Action[] actions = new Action[] { new Action("Copy"),
new Action("Paste") };

public void handleAction(Action action, Object sender, Object target) {
@Override
public void handleAction(Action action, Object sender, Object target) {
getUI().showNotification("Just test");
}

public Action[] getActions(Object target, Object sender) {
@Override
public Action[] getActions(Object target, Object sender) {
return actions;
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.vaadin.touchkit.itest.oldtests;
package org.vaadin.touchkit.v7.itest.oldtests;

import com.vaadin.v7.data.Item;
import com.vaadin.v7.data.util.HierarchicalContainer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.vaadin.touchkit.itest.oldtests;
package org.vaadin.touchkit.v7.itest.oldtests;

import java.io.Serializable;

import org.vaadin.touchkit.AbstractTouchKitIntegrationTest;
import org.vaadin.touchkit.ui.NavigationView;
import org.vaadin.touchkit.ui.VerticalComponentGroup;
import org.vaadin.touchkit.v7.AbstractTouchKitIntegrationTest;

import com.vaadin.ui.Component;
import com.vaadin.v7.data.Item;
import com.vaadin.v7.data.util.BeanItem;
import com.vaadin.ui.Component;
import com.vaadin.v7.ui.DefaultFieldFactory;
import com.vaadin.v7.ui.Field;
import com.vaadin.v7.ui.Form;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.vaadin.touchkit.itest.oldtests;
package org.vaadin.touchkit.v7.itest.oldtests;

import org.vaadin.touchkit.AbstractTouchKitIntegrationTest;
import org.vaadin.touchkit.ui.NavigationView;
import org.vaadin.touchkit.ui.VerticalComponentGroup;
import org.vaadin.touchkit.v7.AbstractTouchKitIntegrationTest;

import com.vaadin.ui.CssLayout;
import com.vaadin.v7.ui.OptionGroup;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.vaadin.touchkit.itest.oldtests;
package org.vaadin.touchkit.v7.itest.oldtests;

import org.junit.Ignore;
import org.vaadin.touchkit.ui.NavigationButton;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.vaadin.touchkit.v7.itest.oldtests;

import org.junit.Ignore;

import com.vaadin.annotations.JavaScript;
import com.vaadin.server.Page;
import com.vaadin.server.Sizeable;
import com.vaadin.ui.ComponentContainer;

@Ignore
public class TestUtils {
public static void makeSmallTabletSize(ComponentContainer c) {
c.setWidth(450, Sizeable.UNITS_PIXELS);
c.setHeight(640, Sizeable.UNITS_PIXELS);
}

public static void injectCss(String cssString) {
String script = "if ('\\v'=='v') /* ie only */ {\n"
+ " document.createStyleSheet().cssText = '"
+ cssString
+ "';\n"
+ " } else {var tag = document.createElement('style'); tag.type = 'text/css';"
+ " document.getElementsByTagName('head')[0].appendChild(tag);tag[ (typeof "
+ "document.body.style.WebkitAppearance=='string') /* webkit only */ ? 'innerText' "
+ ": 'innerHTML'] = '" + cssString + "';}";

Page.getCurrent().getJavaScript().execute(script);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@
<when-property-is name="user.agent" value="ie10" />
</replace-with>

<replace-with
class="org.vaadin.touchkit.gwt.client.Android2NativeSelectReplacement">
<when-type-is class="com.vaadin.client.ui.VNativeSelect" />
<when-property-is name="webkitvariant" value="android2" />
</replace-with>

<replace-with
class="org.vaadin.touchkit.gwt.client.ui.VSwipeViewIEImpl">
<when-type-is class="org.vaadin.touchkit.gwt.client.ui.VSwipeView" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorHierarchyChangeEvent;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractFieldConnector;
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)
Expand Down
Loading

0 comments on commit 9d23baf

Please sign in to comment.