From 7a8fd7b5c0223ef6820b4e5cdbe1c05578b17d4a Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Wed, 22 Aug 2012 13:59:26 +0300 Subject: Sending and receiving heartbeat requests (#9265) --- shared/src/com/vaadin/shared/ApplicationConstants.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'shared') diff --git a/shared/src/com/vaadin/shared/ApplicationConstants.java b/shared/src/com/vaadin/shared/ApplicationConstants.java index 31e633a210..9d1ed7341d 100644 --- a/shared/src/com/vaadin/shared/ApplicationConstants.java +++ b/shared/src/com/vaadin/shared/ApplicationConstants.java @@ -23,6 +23,8 @@ public class ApplicationConstants { public static final String UIDL_REQUEST_PATH = "UIDL/"; + public static final String HEARTBEAT_REQUEST_PATH = "HEARTBEAT/"; + public static final String CONNECTOR_RESOURCE_PREFIX = APP_REQUEST_PATH + "CONNECTOR"; -- cgit v1.2.3 From 38ffd4a097094a01c35fbd5b79563e6c8ea02e92 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Fri, 24 Aug 2012 11:25:05 +0300 Subject: Make it possible to delegate state changes to widget (#9297) --- .../ConnectorBundleLoaderFactory.java | 20 ++++++- .../widgetsetutils/metadata/ConnectorBundle.java | 20 +++++++ .../gwt/widgetsetutils/metadata/FieldProperty.java | 9 ++++ .../widgetsetutils/metadata/MethodProperty.java | 6 +++ .../gwt/widgetsetutils/metadata/Property.java | 5 ++ .../gwt/widgetsetutils/metadata/TypeVisitor.java | 3 +- .../widgetsetutils/metadata/WidgetInitVisitor.java | 45 ++++++++++++++-- .../terminal/gwt/client/ApplicationConnection.java | 61 ++++++++++++++++++++++ .../terminal/gwt/client/metadata/Property.java | 9 ++-- .../gwt/client/metadata/TypeDataStore.java | 6 +++ .../terminal/gwt/client/ui/MediaBaseConnector.java | 3 -- .../ui/splitpanel/AbstractSplitPanelConnector.java | 3 -- .../gwt/client/ui/textarea/TextAreaConnector.java | 9 ---- .../shared/annotations/DelegateToWidget.java | 25 +++++++++ .../com/vaadin/shared/ui/AbstractMediaState.java | 4 ++ .../ui/splitpanel/AbstractSplitPanelState.java | 3 ++ .../vaadin/shared/ui/textarea/TextAreaState.java | 3 ++ .../tests/serialization/DelegateToWidgetTest.html | 26 +++++++++ .../tests/serialization/DelegateToWidgetTest.java | 42 +++++++++++++++ .../vaadin/tests/widgetset/TestingWidgetSet.java | 21 ++++++++ .../tests/widgetset/client/DelegateConnector.java | 34 ++++++++++++ .../tests/widgetset/client/DelegateState.java | 50 ++++++++++++++++++ .../tests/widgetset/client/DelegateWidget.java | 50 ++++++++++++++++++ .../server/DelegateToWidgetComponent.java | 35 +++++++++++++ 24 files changed, 465 insertions(+), 27 deletions(-) create mode 100644 shared/src/com/vaadin/shared/annotations/DelegateToWidget.java create mode 100644 tests/testbench/com/vaadin/tests/serialization/DelegateToWidgetTest.html create mode 100644 tests/testbench/com/vaadin/tests/serialization/DelegateToWidgetTest.java create mode 100644 tests/testbench/com/vaadin/tests/widgetset/TestingWidgetSet.java create mode 100644 tests/testbench/com/vaadin/tests/widgetset/client/DelegateConnector.java create mode 100644 tests/testbench/com/vaadin/tests/widgetset/client/DelegateState.java create mode 100644 tests/testbench/com/vaadin/tests/widgetset/client/DelegateWidget.java create mode 100644 tests/testbench/com/vaadin/tests/widgetset/server/DelegateToWidgetComponent.java (limited to 'shared') diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorBundleLoaderFactory.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorBundleLoaderFactory.java index a2e61947e8..752f290a42 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorBundleLoaderFactory.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorBundleLoaderFactory.java @@ -30,6 +30,7 @@ import com.google.gwt.core.ext.typeinfo.TypeOracle; import com.google.gwt.user.rebind.ClassSourceFileComposerFactory; import com.google.gwt.user.rebind.SourceWriter; import com.vaadin.shared.annotations.Delayed; +import com.vaadin.shared.annotations.DelegateToWidget; import com.vaadin.shared.communication.ClientRpc; import com.vaadin.shared.communication.ServerRpc; import com.vaadin.shared.ui.Connect; @@ -182,6 +183,18 @@ public class ConnectorBundleLoaderFactory extends Generator { writeSetters(logger, w, bundle); writeGetters(logger, w, bundle); writeSerializers(logger, w, bundle); + writeDelegateToWidget(logger, w, bundle); + } + + private void writeDelegateToWidget(TreeLogger logger, SourceWriter w, + ConnectorBundle bundle) { + Set needsDelegateToWidget = bundle.getNeedsDelegateToWidget(); + for (Property property : needsDelegateToWidget) { + w.println("store.setDelegateToWidget(%s, \"%s\", \"%s\");", + getClassLiteralString(property.getBeanType()), + property.getName(), + property.getAnnotation(DelegateToWidget.class).value()); + } } private void writeSerializers(TreeLogger logger, SourceWriter w, @@ -535,8 +548,11 @@ public class ConnectorBundleLoaderFactory extends Generator { } public static void writeClassLiteral(SourceWriter w, JType type) { - w.print(type.getQualifiedSourceName()); - w.print(".class"); + w.print(getClassLiteralString(type)); + } + + public static String getClassLiteralString(JType type) { + return type.getQualifiedSourceName() + ".class"; } private void writeIdentifiers(SourceWriter w, ConnectorBundle bundle) { diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorBundle.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorBundle.java index 7515124a5a..1db551ed9a 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorBundle.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorBundle.java @@ -61,6 +61,7 @@ public class ConnectorBundle { private final Set needsSetter = new HashSet(); private final Set needsType = new HashSet(); private final Set needsGetter = new HashSet(); + private final Set needsDelegateToWidget = new HashSet(); private ConnectorBundle(String name, ConnectorBundle previousBundle, Collection visitors, @@ -585,4 +586,23 @@ public class ConnectorBundle { && previousBundle.hasSserializeSupport(type); } } + + public void setNeedsDelegateToWidget(Property property) { + if (!isNeedsDelegateToWidget(property)) { + needsDelegateToWidget.add(property); + } + } + + private boolean isNeedsDelegateToWidget(Property property) { + if (needsDelegateToWidget.contains(property)) { + return true; + } else { + return previousBundle != null + && previousBundle.isNeedsDelegateToWidget(property); + } + } + + public Set getNeedsDelegateToWidget() { + return Collections.unmodifiableSet(needsDelegateToWidget); + } } \ No newline at end of file diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/FieldProperty.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/FieldProperty.java index 31555cc30b..c4c2a50e1c 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/FieldProperty.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/FieldProperty.java @@ -16,6 +16,7 @@ package com.vaadin.terminal.gwt.widgetsetutils.metadata; +import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -29,8 +30,11 @@ import com.google.gwt.user.rebind.SourceWriter; public class FieldProperty extends Property { + private final JField field; + private FieldProperty(JClassType beanType, JField field) { super(field.getName(), beanType, field.getType()); + this.field = field; } @Override @@ -74,4 +78,9 @@ public class FieldProperty extends Property { return fields; } + @Override + public T getAnnotation(Class annotationClass) { + return field.getAnnotation(annotationClass); + } + } diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/MethodProperty.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/MethodProperty.java index f422205175..431ead7f96 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/MethodProperty.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/MethodProperty.java @@ -16,6 +16,7 @@ package com.vaadin.terminal.gwt.widgetsetutils.metadata; +import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -121,4 +122,9 @@ public class MethodProperty extends Property { + baseName.substring(1); } + @Override + public T getAnnotation(Class annotationClass) { + return setter.getAnnotation(annotationClass); + } + } diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/Property.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/Property.java index 1714489db5..5ef0293688 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/Property.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/Property.java @@ -16,6 +16,8 @@ package com.vaadin.terminal.gwt.widgetsetutils.metadata; +import java.lang.annotation.Annotation; + import com.google.gwt.core.ext.TreeLogger; import com.google.gwt.core.ext.typeinfo.JClassType; import com.google.gwt.core.ext.typeinfo.JPrimitiveType; @@ -81,4 +83,7 @@ public abstract class Property { + getName().hashCode(); } + public abstract T getAnnotation( + Class annotationClass); + } diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/TypeVisitor.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/TypeVisitor.java index 976eb6417a..cda849f564 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/TypeVisitor.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/TypeVisitor.java @@ -5,6 +5,7 @@ package com.vaadin.terminal.gwt.widgetsetutils.metadata; import com.google.gwt.core.ext.TreeLogger; +import com.google.gwt.core.ext.UnableToCompleteException; import com.google.gwt.core.ext.typeinfo.JClassType; import com.google.gwt.core.ext.typeinfo.JMethod; import com.google.gwt.core.ext.typeinfo.JType; @@ -17,7 +18,7 @@ public abstract class TypeVisitor { } public void visitConnector(TreeLogger logger, JClassType type, - ConnectorBundle bundle) { + ConnectorBundle bundle) throws UnableToCompleteException { // Default does nothing } diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/WidgetInitVisitor.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/WidgetInitVisitor.java index 4d63703151..2b0e3e1f61 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/WidgetInitVisitor.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/WidgetInitVisitor.java @@ -4,17 +4,21 @@ package com.vaadin.terminal.gwt.widgetsetutils.metadata; +import java.util.Collection; + import com.google.gwt.core.ext.TreeLogger; +import com.google.gwt.core.ext.TreeLogger.Type; +import com.google.gwt.core.ext.UnableToCompleteException; import com.google.gwt.core.ext.typeinfo.JClassType; import com.google.gwt.core.ext.typeinfo.JMethod; -import com.google.gwt.core.ext.typeinfo.JType; +import com.vaadin.shared.annotations.DelegateToWidget; import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; public class WidgetInitVisitor extends TypeVisitor { @Override public void visitConnector(TreeLogger logger, JClassType type, - ConnectorBundle bundle) { + ConnectorBundle bundle) throws UnableToCompleteException { if (ConnectorBundle.isConnectedComponentConnector(type)) { JClassType createWidgetClass = findInheritedMethod(type, "createWidget").getEnclosingType(); @@ -29,8 +33,41 @@ public class WidgetInitVisitor extends TypeVisitor { JMethod getWidget = findInheritedMethod(type, "getWidget"); bundle.setNeedsReturnType(type, getWidget); - JType widgetType = getWidget.getReturnType(); - bundle.setNeedsGwtConstructor(widgetType.isClass()); + JClassType widgetType = getWidget.getReturnType().isClass(); + bundle.setNeedsGwtConstructor(widgetType); + + JMethod getState = findInheritedMethod(type, "getState"); + JClassType stateType = getState.getReturnType().isClass(); + + Collection properties = bundle.getProperties(stateType); + for (Property property : properties) { + DelegateToWidget delegateToWidget = property + .getAnnotation(DelegateToWidget.class); + if (delegateToWidget != null) { + bundle.setNeedsDelegateToWidget(property); + String methodName = DelegateToWidget.Helper + .getDelegateTarget(property.getName(), + delegateToWidget.value()); + JMethod delegatedSetter = findInheritedMethod(widgetType, + methodName, property.getPropertyType()); + if (delegatedSetter == null) { + logger.log( + Type.ERROR, + widgetType.getName() + + "." + + methodName + + "(" + + property.getPropertyType() + .getSimpleSourceName() + + ") required by @DelegateToWidget for " + + stateType.getName() + "." + + property.getName() + + " can not be found."); + throw new UnableToCompleteException(); + } + bundle.setNeedsInvoker(widgetType, delegatedSetter); + } + } } } } diff --git a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 58357ae3fc..10f63d0f51 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -68,7 +68,10 @@ import com.vaadin.terminal.gwt.client.communication.RpcManager; import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; import com.vaadin.terminal.gwt.client.extensions.AbstractExtensionConnector; import com.vaadin.terminal.gwt.client.metadata.ConnectorBundleLoader; +import com.vaadin.terminal.gwt.client.metadata.NoDataException; +import com.vaadin.terminal.gwt.client.metadata.Property; import com.vaadin.terminal.gwt.client.metadata.Type; +import com.vaadin.terminal.gwt.client.metadata.TypeData; import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; import com.vaadin.terminal.gwt.client.ui.VContextMenu; import com.vaadin.terminal.gwt.client.ui.dd.VDragAndDropManager; @@ -1148,6 +1151,8 @@ public class ApplicationConnection { " * Hierarchy state change event processing completed", 10); + delegateToWidget(pendingStateChangeEvents); + // Fire state change events. sendStateChangeEvents(pendingStateChangeEvents); @@ -1264,6 +1269,62 @@ public class ApplicationConnection { } + private void delegateToWidget( + Collection pendingStateChangeEvents) { + VConsole.log(" * Running @DelegateToWidget"); + + for (StateChangeEvent sce : pendingStateChangeEvents) { + ServerConnector connector = sce.getConnector(); + if (connector instanceof ComponentConnector) { + ComponentConnector component = (ComponentConnector) connector; + Type type = TypeData.getType(component.getClass()); + + Type stateType; + try { + stateType = type.getMethod("getState") + .getReturnType(); + } catch (NoDataException e) { + throw new RuntimeException( + "Can not find the state type for " + + type.getSignature(), e); + } + + Set changedProperties = sce + .getChangedProperties(); + for (String propertyName : changedProperties) { + Property property = stateType + .getProperty(propertyName); + String method = property + .getDelegateToWidgetMethodName(); + if (method != null) { + doDelegateToWidget(component, property, method); + } + } + + } + } + } + + private void doDelegateToWidget(ComponentConnector component, + Property property, String methodName) { + Type type = TypeData.getType(component.getClass()); + try { + Type widgetType = type.getMethod("getWidget") + .getReturnType(); + Widget widget = component.getWidget(); + + Object propertyValue = property.getValue(component + .getState()); + + widgetType.getMethod(methodName).invoke(widget, + propertyValue); + } catch (NoDataException e) { + throw new RuntimeException( + "Missing data needed to invoke @DelegateToWidget for " + + Util.getSimpleName(component), e); + } + } + /** * Sends the state change events created while updating the state * information. diff --git a/client/src/com/vaadin/terminal/gwt/client/metadata/Property.java b/client/src/com/vaadin/terminal/gwt/client/metadata/Property.java index 082d032e64..69e41ce75d 100644 --- a/client/src/com/vaadin/terminal/gwt/client/metadata/Property.java +++ b/client/src/com/vaadin/terminal/gwt/client/metadata/Property.java @@ -4,6 +4,8 @@ package com.vaadin.terminal.gwt.client.metadata; +import com.vaadin.shared.annotations.DelegateToWidget; + public class Property { private final Type bean; private final String name; @@ -21,15 +23,12 @@ public class Property { TypeDataStore.getSetter(this).invoke(bean, value); } - public String getDelegateToWidgetMethod() { + public String getDelegateToWidgetMethodName() { String value = TypeDataStore.getDelegateToWidget(this); if (value == null) { return null; - } else if (value.isEmpty()) { - return "set" + Character.toUpperCase(value.charAt(0)) - + value.substring(1); } else { - return value; + return DelegateToWidget.Helper.getDelegateTarget(getName(), value); } } diff --git a/client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java b/client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java index 55740f69da..9c19410c88 100644 --- a/client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java +++ b/client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java @@ -101,6 +101,12 @@ public class TypeDataStore { return get().delegateToWidget.get(property); } + public void setDelegateToWidget(Class clazz, String propertyName, + String delegateValue) { + delegateToWidget.put(new Property(getType(clazz), propertyName), + delegateValue); + } + public void setReturnType(Class type, String methodName, Type returnType) { returnTypes.put(new Method(getType(type), methodName), returnType); } diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/MediaBaseConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/MediaBaseConnector.java index 2f52971aeb..33d97f4ed8 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/MediaBaseConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/MediaBaseConnector.java @@ -49,9 +49,6 @@ public abstract class MediaBaseConnector extends AbstractComponentConnector { public void onStateChanged(StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); - getWidget().setControls(getState().isShowControls()); - getWidget().setAutoplay(getState().isAutoplay()); - getWidget().setMuted(getState().isMuted()); for (int i = 0; i < getState().getSources().size(); i++) { URLReference source = getState().getSources().get(i); String sourceType = getState().getSourceTypes().get(i); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/splitpanel/AbstractSplitPanelConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/splitpanel/AbstractSplitPanelConnector.java index 9f4df02380..912f9a7c83 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/splitpanel/AbstractSplitPanelConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/splitpanel/AbstractSplitPanelConnector.java @@ -138,9 +138,6 @@ public abstract class AbstractSplitPanelConnector extends // Splitter updates SplitterState splitterState = getState().getSplitterState(); - getWidget().setLocked(splitterState.isLocked()); - getWidget().setPositionReversed(splitterState.isPositionReversed()); - getWidget().setStylenames(); getWidget().minimumPosition = splitterState.getMinPosition() diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/textarea/TextAreaConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/textarea/TextAreaConnector.java index 5fb7f97044..d5abed4fa9 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/textarea/TextAreaConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/textarea/TextAreaConnector.java @@ -18,7 +18,6 @@ package com.vaadin.terminal.gwt.client.ui.textarea; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.textarea.TextAreaState; -import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; import com.vaadin.terminal.gwt.client.ui.textfield.TextFieldConnector; import com.vaadin.ui.TextArea; @@ -30,14 +29,6 @@ public class TextAreaConnector extends TextFieldConnector { return (TextAreaState) super.getState(); } - @Override - public void onStateChanged(StateChangeEvent stateChangeEvent) { - super.onStateChanged(stateChangeEvent); - - getWidget().setRows(getState().getRows()); - getWidget().setWordwrap(getState().isWordwrap()); - } - @Override public VTextArea getWidget() { return (VTextArea) super.getWidget(); diff --git a/shared/src/com/vaadin/shared/annotations/DelegateToWidget.java b/shared/src/com/vaadin/shared/annotations/DelegateToWidget.java new file mode 100644 index 0000000000..0ac16ecea9 --- /dev/null +++ b/shared/src/com/vaadin/shared/annotations/DelegateToWidget.java @@ -0,0 +1,25 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.shared.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target({ ElementType.METHOD, ElementType.FIELD }) +public @interface DelegateToWidget { + public String value() default ""; + + public static class Helper { + public static String getDelegateTarget(String propertyName, + String annotationValue) { + String name = annotationValue; + if (name.isEmpty()) { + name = "set" + Character.toUpperCase(propertyName.charAt(0)) + + propertyName.substring(1); + } + return name; + } + } +} diff --git a/shared/src/com/vaadin/shared/ui/AbstractMediaState.java b/shared/src/com/vaadin/shared/ui/AbstractMediaState.java index 2731529caf..80d41dd797 100644 --- a/shared/src/com/vaadin/shared/ui/AbstractMediaState.java +++ b/shared/src/com/vaadin/shared/ui/AbstractMediaState.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.List; import com.vaadin.shared.ComponentState; +import com.vaadin.shared.annotations.DelegateToWidget; import com.vaadin.shared.communication.URLReference; public class AbstractMediaState extends ComponentState { @@ -39,6 +40,7 @@ public class AbstractMediaState extends ComponentState { return showControls; } + @DelegateToWidget("setControls") public void setShowControls(boolean showControls) { this.showControls = showControls; } @@ -63,6 +65,7 @@ public class AbstractMediaState extends ComponentState { return autoplay; } + @DelegateToWidget public void setAutoplay(boolean autoplay) { this.autoplay = autoplay; } @@ -71,6 +74,7 @@ public class AbstractMediaState extends ComponentState { return muted; } + @DelegateToWidget public void setMuted(boolean muted) { this.muted = muted; } diff --git a/shared/src/com/vaadin/shared/ui/splitpanel/AbstractSplitPanelState.java b/shared/src/com/vaadin/shared/ui/splitpanel/AbstractSplitPanelState.java index 46eb851edd..71f789b70d 100644 --- a/shared/src/com/vaadin/shared/ui/splitpanel/AbstractSplitPanelState.java +++ b/shared/src/com/vaadin/shared/ui/splitpanel/AbstractSplitPanelState.java @@ -19,6 +19,7 @@ import java.io.Serializable; import com.vaadin.shared.ComponentState; import com.vaadin.shared.Connector; +import com.vaadin.shared.annotations.DelegateToWidget; public class AbstractSplitPanelState extends ComponentState { @@ -120,6 +121,7 @@ public class AbstractSplitPanelState extends ComponentState { return positionReversed; } + @DelegateToWidget public void setPositionReversed(boolean positionReversed) { this.positionReversed = positionReversed; } @@ -128,6 +130,7 @@ public class AbstractSplitPanelState extends ComponentState { return locked; } + @DelegateToWidget public void setLocked(boolean locked) { this.locked = locked; } diff --git a/shared/src/com/vaadin/shared/ui/textarea/TextAreaState.java b/shared/src/com/vaadin/shared/ui/textarea/TextAreaState.java index 31cec77554..50dc1393a3 100644 --- a/shared/src/com/vaadin/shared/ui/textarea/TextAreaState.java +++ b/shared/src/com/vaadin/shared/ui/textarea/TextAreaState.java @@ -15,6 +15,7 @@ */ package com.vaadin.shared.ui.textarea; +import com.vaadin.shared.annotations.DelegateToWidget; import com.vaadin.shared.ui.textfield.AbstractTextFieldState; public class TextAreaState extends AbstractTextFieldState { @@ -33,6 +34,7 @@ public class TextAreaState extends AbstractTextFieldState { return rows; } + @DelegateToWidget public void setRows(int rows) { this.rows = rows; } @@ -41,6 +43,7 @@ public class TextAreaState extends AbstractTextFieldState { return wordwrap; } + @DelegateToWidget public void setWordwrap(boolean wordwrap) { this.wordwrap = wordwrap; } diff --git a/tests/testbench/com/vaadin/tests/serialization/DelegateToWidgetTest.html b/tests/testbench/com/vaadin/tests/serialization/DelegateToWidgetTest.html new file mode 100644 index 0000000000..12228eb9f0 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/serialization/DelegateToWidgetTest.html @@ -0,0 +1,26 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.serialization.DelegateToWidgetTest?restartApplication
assertTextvaadin=runcomvaadintestsserializationDelegateToWidgetTest::/VVerticalLayout[0]/VVerticalLayout[0]/DelegateWidget[0]My String
42
true
3.141592653589793
+ + diff --git a/tests/testbench/com/vaadin/tests/serialization/DelegateToWidgetTest.java b/tests/testbench/com/vaadin/tests/serialization/DelegateToWidgetTest.java new file mode 100644 index 0000000000..54170c880f --- /dev/null +++ b/tests/testbench/com/vaadin/tests/serialization/DelegateToWidgetTest.java @@ -0,0 +1,42 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.serialization; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.terminal.WrappedRequest; +import com.vaadin.tests.components.AbstractTestRoot; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.server.DelegateToWidgetComponent; + +@Widgetset(TestingWidgetSet.NAME) +public class DelegateToWidgetTest extends AbstractTestRoot { + @Override + protected void setup(WrappedRequest request) { + addComponent(new DelegateToWidgetComponent()); + } + + @Override + protected String getTestDescription() { + return "Verifies that @DelegateToWidget has the desired effect"; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(9297); + } + +} diff --git a/tests/testbench/com/vaadin/tests/widgetset/TestingWidgetSet.java b/tests/testbench/com/vaadin/tests/widgetset/TestingWidgetSet.java new file mode 100644 index 0000000000..0464a53a95 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/TestingWidgetSet.java @@ -0,0 +1,21 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.widgetset; + +public class TestingWidgetSet { + public static final String NAME = "com.vaadin.tests.widgetset.TestingWidgetSet"; +} diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/DelegateConnector.java b/tests/testbench/com/vaadin/tests/widgetset/client/DelegateConnector.java new file mode 100644 index 0000000000..c711be232f --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/DelegateConnector.java @@ -0,0 +1,34 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.widgetset.client; + +import com.vaadin.shared.ui.Connect; +import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; +import com.vaadin.tests.widgetset.server.DelegateToWidgetComponent; + +@Connect(DelegateToWidgetComponent.class) +public class DelegateConnector extends AbstractComponentConnector { + @Override + public DelegateWidget getWidget() { + return (DelegateWidget) super.getWidget(); + } + + @Override + public DelegateState getState() { + return (DelegateState) super.getState(); + } +} diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/DelegateState.java b/tests/testbench/com/vaadin/tests/widgetset/client/DelegateState.java new file mode 100644 index 0000000000..e9ac8a1e61 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/DelegateState.java @@ -0,0 +1,50 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.widgetset.client; + +import com.vaadin.shared.ComponentState; +import com.vaadin.shared.annotations.DelegateToWidget; + +public class DelegateState extends ComponentState { + @DelegateToWidget + public String value1; + + @DelegateToWidget("setValue2") + public int renamedValue2; + + private Boolean value3; + + private double renamedValue4; + + @DelegateToWidget + public void setValue3(Boolean value3) { + this.value3 = value3; + } + + public Boolean getValue3() { + return value3; + } + + @DelegateToWidget("setValue4") + public void setRenamedValue4(double renamedValue4) { + this.renamedValue4 = renamedValue4; + } + + public double getRenamedValue4() { + return renamedValue4; + } +} diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/DelegateWidget.java b/tests/testbench/com/vaadin/tests/widgetset/client/DelegateWidget.java new file mode 100644 index 0000000000..4776eced9a --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/DelegateWidget.java @@ -0,0 +1,50 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.widgetset.client; + +import com.google.gwt.user.client.ui.HTML; + +public class DelegateWidget extends HTML { + private String value1; + private int value2; + private Boolean value3; + private double value4; + + public void setValue1(String value1) { + this.value1 = value1; + updateText(); + } + + public void setValue2(int value2) { + this.value2 = value2; + updateText(); + } + + public void setValue3(Boolean value3) { + this.value3 = value3; + updateText(); + } + + public void setValue4(double value4) { + this.value4 = value4; + } + + private void updateText() { + setHTML(value1 + "
" + value2 + "
" + value3 + "
" + + value4 + "
"); + } +} diff --git a/tests/testbench/com/vaadin/tests/widgetset/server/DelegateToWidgetComponent.java b/tests/testbench/com/vaadin/tests/widgetset/server/DelegateToWidgetComponent.java new file mode 100644 index 0000000000..34c9699f7f --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/server/DelegateToWidgetComponent.java @@ -0,0 +1,35 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.widgetset.server; + +import com.vaadin.tests.widgetset.client.DelegateState; +import com.vaadin.ui.AbstractComponent; + +public class DelegateToWidgetComponent extends AbstractComponent { + public DelegateToWidgetComponent() { + DelegateState state = getState(); + state.value1 = "My String"; + state.renamedValue2 = 42; + state.setValue3(Boolean.TRUE); + state.setRenamedValue4(Math.PI); + } + + @Override + protected DelegateState getState() { + return (DelegateState) super.getState(); + } +} -- cgit v1.2.3 From 066491f708fd303c604b2bee7cbd46a8342f71bf Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 24 Aug 2012 08:52:20 +0300 Subject: Rename Root related classes and package to UI (#8908) Automatic renames in Eclipse of: - package com.vaadin.terminal.gwt.client.ui.root to .UI - RootConnector to UIConnector - RootServerRpc to UIServerRpc - RootState to UIState - VRoot to VUI - RootRequiresMoreInformationException to UIRequiresMoreInformationException --- .../gwt/widgetsetutils/WidgetMapGenerator.java | 4 +- .../terminal/gwt/client/ApplicationConnection.java | 34 +- .../terminal/gwt/client/ComponentLocator.java | 4 +- .../vaadin/terminal/gwt/client/VDebugConsole.java | 4 +- .../gwt/client/ui/AbstractComponentConnector.java | 6 +- .../terminal/gwt/client/ui/UI/UIConnector.java | 457 ++++++++++++++++++++ .../com/vaadin/terminal/gwt/client/ui/UI/VUI.java | 459 +++++++++++++++++++++ .../terminal/gwt/client/ui/root/RootConnector.java | 457 -------------------- .../vaadin/terminal/gwt/client/ui/root/VRoot.java | 459 --------------------- server/src/com/vaadin/Application.java | 18 +- .../RootRequiresMoreInformationException.java | 37 -- .../vaadin/UIRequiresMoreInformationException.java | 37 ++ .../com/vaadin/terminal/DefaultRootProvider.java | 4 +- server/src/com/vaadin/terminal/RootProvider.java | 4 +- server/src/com/vaadin/terminal/WrappedRequest.java | 4 +- .../gwt/server/AbstractApplicationPortlet.java | 4 +- .../gwt/server/AbstractCommunicationManager.java | 4 +- .../terminal/gwt/server/BootstrapHandler.java | 4 +- .../terminal/gwt/server/BootstrapResponse.java | 4 +- server/src/com/vaadin/ui/UI.java | 14 +- .../com/vaadin/shared/ui/root/RootServerRpc.java | 26 -- .../src/com/vaadin/shared/ui/root/RootState.java | 32 -- .../src/com/vaadin/shared/ui/root/UIServerRpc.java | 26 ++ shared/src/com/vaadin/shared/ui/root/UIState.java | 32 ++ .../component/root/CustomRootClassLoader.java | 4 +- .../vaadin/launcher/ApplicationRunnerServlet.java | 4 +- .../tests/application/RefreshStatePreserve.java | 4 +- .../tests/application/ThreadLocalInstances.java | 4 +- .../tests/components/root/LazyInitRoots.java | 6 +- .../tests/components/root/RootsInMultipleTabs.java | 4 +- .../v7a1/DifferentFeaturesForDifferentClients.java | 6 +- 31 files changed, 1083 insertions(+), 1083 deletions(-) create mode 100644 client/src/com/vaadin/terminal/gwt/client/ui/UI/UIConnector.java create mode 100644 client/src/com/vaadin/terminal/gwt/client/ui/UI/VUI.java delete mode 100644 client/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java delete mode 100644 client/src/com/vaadin/terminal/gwt/client/ui/root/VRoot.java delete mode 100644 server/src/com/vaadin/RootRequiresMoreInformationException.java create mode 100644 server/src/com/vaadin/UIRequiresMoreInformationException.java delete mode 100644 shared/src/com/vaadin/shared/ui/root/RootServerRpc.java delete mode 100644 shared/src/com/vaadin/shared/ui/root/RootState.java create mode 100644 shared/src/com/vaadin/shared/ui/root/UIServerRpc.java create mode 100644 shared/src/com/vaadin/shared/ui/root/UIState.java (limited to 'shared') diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetMapGenerator.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetMapGenerator.java index 1f5b301802..99f3a1d17b 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetMapGenerator.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetMapGenerator.java @@ -40,7 +40,7 @@ import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.Connect.LoadStyle; import com.vaadin.terminal.gwt.client.ServerConnector; import com.vaadin.terminal.gwt.client.ui.UnknownComponentConnector; -import com.vaadin.terminal.gwt.client.ui.root.RootConnector; +import com.vaadin.terminal.gwt.client.ui.UI.UIConnector; import com.vaadin.terminal.gwt.server.ClientConnector; /** @@ -284,7 +284,7 @@ public class WidgetMapGenerator extends Generator { if (connectorsWithInstantiator.contains(clientClass)) { continue; } - if (clientClass == RootConnector.class) { + if (clientClass == UIConnector.class) { // Roots are not instantiated by widgetset continue; } diff --git a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 4e8871b8ac..44f52d3e7f 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -74,10 +74,10 @@ import com.vaadin.terminal.gwt.client.metadata.Type; import com.vaadin.terminal.gwt.client.metadata.TypeData; import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; import com.vaadin.terminal.gwt.client.ui.VContextMenu; +import com.vaadin.terminal.gwt.client.ui.UI.UIConnector; import com.vaadin.terminal.gwt.client.ui.dd.VDragAndDropManager; import com.vaadin.terminal.gwt.client.ui.notification.VNotification; import com.vaadin.terminal.gwt.client.ui.notification.VNotification.HideEvent; -import com.vaadin.terminal.gwt.client.ui.root.RootConnector; import com.vaadin.terminal.gwt.client.ui.window.WindowConnector; /** @@ -156,7 +156,7 @@ public class ApplicationConnection { private Timer loadTimer3; private Element loadElement; - private final RootConnector rootConnector; + private final UIConnector uIConnector; protected boolean applicationRunning = false; @@ -211,7 +211,7 @@ public class ApplicationConnection { // Assuming UI data is eagerly loaded ConnectorBundleLoader.get().loadBundle( ConnectorBundleLoader.EAGER_BUNDLE_NAME, null); - rootConnector = GWT.create(RootConnector.class); + uIConnector = GWT.create(UIConnector.class); rpcManager = GWT.create(RpcManager.class); layoutManager = GWT.create(LayoutManager.class); layoutManager.setConnection(this); @@ -243,7 +243,7 @@ public class ApplicationConnection { initializeClientHooks(); - rootConnector.init(cnf.getRootPanelId(), this); + uIConnector.init(cnf.getRootPanelId(), this); showLoadingIndicator(); } @@ -909,7 +909,7 @@ public class ApplicationConnection { if (loadElement == null) { loadElement = DOM.createDiv(); DOM.setStyleAttribute(loadElement, "position", "absolute"); - DOM.appendChild(rootConnector.getWidget().getElement(), loadElement); + DOM.appendChild(uIConnector.getWidget().getElement(), loadElement); VConsole.log("inserting load indicator"); } DOM.setElementProperty(loadElement, "className", "v-loading-indicator"); @@ -1093,7 +1093,7 @@ public class ApplicationConnection { meta = json.getValueMap("meta"); if (meta.containsKey("repaintAll")) { repaintAll = true; - rootConnector.getWidget().clear(); + uIConnector.getWidget().clear(); getConnectorMap().clear(); if (meta.containsKey("invalidLayouts")) { validatingLayouts = true; @@ -1361,17 +1361,17 @@ public class ApplicationConnection { if (!c.getParent().getChildren().contains(c)) { VConsole.error("ERROR: Connector is connected to a parent but the parent does not contain the connector"); } - } else if ((c instanceof RootConnector && c == getRootConnector())) { - // RootConnector for this connection, leave as-is + } else if ((c instanceof UIConnector && c == getRootConnector())) { + // UIConnector for this connection, leave as-is } else if (c instanceof WindowConnector && getRootConnector().hasSubWindow( (WindowConnector) c)) { - // Sub window attached to this RootConnector, leave + // Sub window attached to this UIConnector, leave // as-is } else { // The connector has been detached from the // hierarchy, unregister it and any possible - // children. The RootConnector should never be + // children. The UIConnector should never be // unregistered even though it has no parent. connectorMap.unregisterConnector(c); unregistered++; @@ -1406,17 +1406,17 @@ public class ApplicationConnection { .getConnectorClassByEncodedTag(connectorType); // Connector does not exist so we must create it - if (connectorClass != RootConnector.class) { + if (connectorClass != UIConnector.class) { // create, initialize and register the paintable getConnector(connectorId, connectorType); } else { - // First RootConnector update. Before this the - // RootConnector has been created but not + // First UIConnector update. Before this the + // UIConnector has been created but not // initialized as the connector id has not been // known connectorMap.registerConnector(connectorId, - rootConnector); - rootConnector.doInit(connectorId, + uIConnector); + uIConnector.doInit(connectorId, ApplicationConnection.this); } } catch (final Throwable e) { @@ -2477,8 +2477,8 @@ public class ApplicationConnection { * * @return the main view */ - public RootConnector getRootConnector() { - return rootConnector; + public UIConnector getRootConnector() { + return uIConnector; } /** diff --git a/client/src/com/vaadin/terminal/gwt/client/ComponentLocator.java b/client/src/com/vaadin/terminal/gwt/client/ComponentLocator.java index 959f03e46d..f1a2b9b925 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ComponentLocator.java +++ b/client/src/com/vaadin/terminal/gwt/client/ComponentLocator.java @@ -28,9 +28,9 @@ import com.vaadin.shared.ComponentState; import com.vaadin.shared.Connector; import com.vaadin.shared.communication.SharedState; import com.vaadin.terminal.gwt.client.ui.SubPartAware; +import com.vaadin.terminal.gwt.client.ui.UI.VUI; import com.vaadin.terminal.gwt.client.ui.gridlayout.VGridLayout; import com.vaadin.terminal.gwt.client.ui.orderedlayout.VMeasuringOrderedLayout; -import com.vaadin.terminal.gwt.client.ui.root.VRoot; import com.vaadin.terminal.gwt.client.ui.tabsheet.VTabsheetPanel; import com.vaadin.terminal.gwt.client.ui.window.VWindow; import com.vaadin.terminal.gwt.client.ui.window.WindowConnector; @@ -385,7 +385,7 @@ public class ComponentLocator { return null; } - if (w instanceof VRoot) { + if (w instanceof VUI) { return ""; } else if (w instanceof VWindow) { Connector windowConnector = ConnectorMap.get(client) diff --git a/client/src/com/vaadin/terminal/gwt/client/VDebugConsole.java b/client/src/com/vaadin/terminal/gwt/client/VDebugConsole.java index 1e2a3062f1..022171f2bb 100644 --- a/client/src/com/vaadin/terminal/gwt/client/VDebugConsole.java +++ b/client/src/com/vaadin/terminal/gwt/client/VDebugConsole.java @@ -70,8 +70,8 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.Version; import com.vaadin.terminal.gwt.client.ui.VLazyExecutor; import com.vaadin.terminal.gwt.client.ui.VOverlay; +import com.vaadin.terminal.gwt.client.ui.UI.UIConnector; import com.vaadin.terminal.gwt.client.ui.notification.VNotification; -import com.vaadin.terminal.gwt.client.ui.root.RootConnector; import com.vaadin.terminal.gwt.client.ui.window.WindowConnector; /** @@ -924,7 +924,7 @@ public class VDebugConsole extends VOverlay implements Console { } protected void dumpConnectorInfo(ApplicationConnection a) { - RootConnector root = a.getRootConnector(); + UIConnector root = a.getRootConnector(); log("================"); log("Connector hierarchy for Root: " + root.getState().getCaption() + " (" + root.getConnectorId() + ")"); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java index faded22260..f36107e947 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java @@ -40,8 +40,8 @@ import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; import com.vaadin.terminal.gwt.client.metadata.NoDataException; import com.vaadin.terminal.gwt.client.metadata.Type; import com.vaadin.terminal.gwt.client.metadata.TypeData; +import com.vaadin.terminal.gwt.client.ui.UI.UIConnector; import com.vaadin.terminal.gwt.client.ui.datefield.PopupDateFieldConnector; -import com.vaadin.terminal.gwt.client.ui.root.RootConnector; public abstract class AbstractComponentConnector extends AbstractConnector implements ComponentConnector { @@ -151,7 +151,7 @@ public abstract class AbstractComponentConnector extends AbstractConnector ServerConnector parent = getParent(); if (parent instanceof ComponentContainerConnector) { ((ComponentContainerConnector) parent).updateCaption(this); - } else if (parent == null && !(this instanceof RootConnector)) { + } else if (parent == null && !(this instanceof UIConnector)) { VConsole.error("Parent of connector " + Util.getConnectorString(this) + " is null. This is typically an indication of a broken component hierarchy"); @@ -181,7 +181,7 @@ public abstract class AbstractComponentConnector extends AbstractConnector ServerConnector parent = getParent(); if (parent instanceof ComponentContainerConnector) { ((ComponentContainerConnector) parent).updateCaption(this); - } else if (parent == null && !(this instanceof RootConnector)) { + } else if (parent == null && !(this instanceof UIConnector)) { VConsole.error("Parent of connector " + Util.getConnectorString(this) + " is null. This is typically an indication of a broken component hierarchy"); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/UI/UIConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/UI/UIConnector.java new file mode 100644 index 0000000000..2fb48623fd --- /dev/null +++ b/client/src/com/vaadin/terminal/gwt/client/ui/UI/UIConnector.java @@ -0,0 +1,457 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.terminal.gwt.client.ui.UI; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.dom.client.NativeEvent; +import com.google.gwt.dom.client.Style; +import com.google.gwt.dom.client.Style.Position; +import com.google.gwt.event.logical.shared.ResizeEvent; +import com.google.gwt.event.logical.shared.ResizeHandler; +import com.google.gwt.user.client.Command; +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.Event; +import com.google.gwt.user.client.History; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.ui.RootPanel; +import com.google.gwt.user.client.ui.Widget; +import com.google.web.bindery.event.shared.HandlerRegistration; +import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.Connect; +import com.vaadin.shared.ui.Connect.LoadStyle; +import com.vaadin.shared.ui.root.PageClientRpc; +import com.vaadin.shared.ui.root.RootConstants; +import com.vaadin.shared.ui.root.UIServerRpc; +import com.vaadin.shared.ui.root.UIState; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.BrowserInfo; +import com.vaadin.terminal.gwt.client.ComponentConnector; +import com.vaadin.terminal.gwt.client.ConnectorHierarchyChangeEvent; +import com.vaadin.terminal.gwt.client.ConnectorMap; +import com.vaadin.terminal.gwt.client.Focusable; +import com.vaadin.terminal.gwt.client.Paintable; +import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.VConsole; +import com.vaadin.terminal.gwt.client.communication.RpcProxy; +import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; +import com.vaadin.terminal.gwt.client.communication.StateChangeEvent.StateChangeHandler; +import com.vaadin.terminal.gwt.client.ui.AbstractComponentContainerConnector; +import com.vaadin.terminal.gwt.client.ui.ClickEventHandler; +import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler; +import com.vaadin.terminal.gwt.client.ui.layout.MayScrollChildren; +import com.vaadin.terminal.gwt.client.ui.notification.VNotification; +import com.vaadin.terminal.gwt.client.ui.window.WindowConnector; +import com.vaadin.ui.UI; + +@Connect(value = UI.class, loadStyle = LoadStyle.EAGER) +public class UIConnector extends AbstractComponentContainerConnector + implements Paintable, MayScrollChildren { + + private UIServerRpc rpc = RpcProxy.create(UIServerRpc.class, this); + + private HandlerRegistration childStateChangeHandlerRegistration; + + private final StateChangeHandler childStateChangeHandler = new StateChangeHandler() { + @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + // TODO Should use a more specific handler that only reacts to + // size changes + onChildSizeChange(); + } + }; + + @Override + protected void init() { + super.init(); + registerRpc(PageClientRpc.class, new PageClientRpc() { + @Override + public void setTitle(String title) { + com.google.gwt.user.client.Window.setTitle(title); + } + }); + getWidget().addResizeHandler(new ResizeHandler() { + @Override + public void onResize(ResizeEvent event) { + rpc.resize(event.getHeight(), event.getWidth(), + Window.getClientWidth(), Window.getClientHeight()); + if (getState().isImmediate()) { + getConnection().sendPendingVariableChanges(); + } + } + }); + } + + @Override + public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) { + ConnectorMap paintableMap = ConnectorMap.get(getConnection()); + getWidget().rendering = true; + getWidget().id = getConnectorId(); + boolean firstPaint = getWidget().connection == null; + getWidget().connection = client; + + getWidget().immediate = getState().isImmediate(); + getWidget().resizeLazy = uidl.hasAttribute(RootConstants.RESIZE_LAZY); + String newTheme = uidl.getStringAttribute("theme"); + if (getWidget().theme != null && !newTheme.equals(getWidget().theme)) { + // Complete page refresh is needed due css can affect layout + // calculations etc + getWidget().reloadHostPage(); + } else { + getWidget().theme = newTheme; + } + // this also implicitly removes old styles + String styles = ""; + styles += getWidget().getStylePrimaryName() + " "; + if (getState().hasStyles()) { + for (String style : getState().getStyles()) { + styles += style + " "; + } + } + if (!client.getConfiguration().isStandalone()) { + styles += getWidget().getStylePrimaryName() + "-embedded"; + } + getWidget().setStyleName(styles.trim()); + + getWidget().makeScrollable(); + + clickEventHandler.handleEventHandlerRegistration(); + + // Process children + int childIndex = 0; + + // Open URL:s + boolean isClosed = false; // was this window closed? + while (childIndex < uidl.getChildCount() + && "open".equals(uidl.getChildUIDL(childIndex).getTag())) { + final UIDL open = uidl.getChildUIDL(childIndex); + final String url = client.translateVaadinUri(open + .getStringAttribute("src")); + final String target = open.getStringAttribute("name"); + if (target == null) { + // source will be opened to this browser window, but we may have + // to finish rendering this window in case this is a download + // (and window stays open). + Scheduler.get().scheduleDeferred(new Command() { + @Override + public void execute() { + VUI.goTo(url); + } + }); + } else if ("_self".equals(target)) { + // This window is closing (for sure). Only other opens are + // relevant in this change. See #3558, #2144 + isClosed = true; + VUI.goTo(url); + } else { + String options; + if (open.hasAttribute("border")) { + if (open.getStringAttribute("border").equals("minimal")) { + options = "menubar=yes,location=no,status=no"; + } else { + options = "menubar=no,location=no,status=no"; + } + + } else { + options = "resizable=yes,menubar=yes,toolbar=yes,directories=yes,location=yes,scrollbars=yes,status=yes"; + } + + if (open.hasAttribute("width")) { + int w = open.getIntAttribute("width"); + options += ",width=" + w; + } + if (open.hasAttribute("height")) { + int h = open.getIntAttribute("height"); + options += ",height=" + h; + } + + Window.open(url, target, options); + } + childIndex++; + } + if (isClosed) { + // don't render the content, something else will be opened to this + // browser view + getWidget().rendering = false; + return; + } + + // Handle other UIDL children + UIDL childUidl; + while ((childUidl = uidl.getChildUIDL(childIndex++)) != null) { + String tag = childUidl.getTag().intern(); + if (tag == "actions") { + if (getWidget().actionHandler == null) { + getWidget().actionHandler = new ShortcutActionHandler( + getWidget().id, client); + } + getWidget().actionHandler.updateActionMap(childUidl); + } else if (tag == "notifications") { + for (final Iterator it = childUidl.getChildIterator(); it + .hasNext();) { + final UIDL notification = (UIDL) it.next(); + VNotification.showNotification(client, notification); + } + } + } + + if (uidl.hasAttribute("focused")) { + // set focused component when render phase is finished + Scheduler.get().scheduleDeferred(new Command() { + @Override + public void execute() { + ComponentConnector paintable = (ComponentConnector) uidl + .getPaintableAttribute("focused", getConnection()); + + final Widget toBeFocused = paintable.getWidget(); + /* + * Two types of Widgets can be focused, either implementing + * GWT HasFocus of a thinner Vaadin specific Focusable + * interface. + */ + if (toBeFocused instanceof com.google.gwt.user.client.ui.Focusable) { + final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) toBeFocused; + toBeFocusedWidget.setFocus(true); + } else if (toBeFocused instanceof Focusable) { + ((Focusable) toBeFocused).focus(); + } else { + VConsole.log("Could not focus component"); + } + } + }); + } + + // Add window listeners on first paint, to prevent premature + // variablechanges + if (firstPaint) { + Window.addWindowClosingHandler(getWidget()); + Window.addResizeHandler(getWidget()); + } + + // finally set scroll position from UIDL + if (uidl.hasVariable("scrollTop")) { + getWidget().scrollable = true; + getWidget().scrollTop = uidl.getIntVariable("scrollTop"); + DOM.setElementPropertyInt(getWidget().getElement(), "scrollTop", + getWidget().scrollTop); + getWidget().scrollLeft = uidl.getIntVariable("scrollLeft"); + DOM.setElementPropertyInt(getWidget().getElement(), "scrollLeft", + getWidget().scrollLeft); + } else { + getWidget().scrollable = false; + } + + if (uidl.hasAttribute("scrollTo")) { + final ComponentConnector connector = (ComponentConnector) uidl + .getPaintableAttribute("scrollTo", getConnection()); + scrollIntoView(connector); + } + + if (uidl.hasAttribute(RootConstants.FRAGMENT_VARIABLE)) { + getWidget().currentFragment = uidl + .getStringAttribute(RootConstants.FRAGMENT_VARIABLE); + if (!getWidget().currentFragment.equals(History.getToken())) { + History.newItem(getWidget().currentFragment, true); + } + } else { + // Initial request for which the server doesn't yet have a fragment + // (and haven't shown any interest in getting one) + getWidget().currentFragment = History.getToken(); + + // Include current fragment in the next request + client.updateVariable(getWidget().id, + RootConstants.FRAGMENT_VARIABLE, + getWidget().currentFragment, false); + } + + if (firstPaint) { + // Queue the initial window size to be sent with the following + // request. + getWidget().sendClientResized(); + } + getWidget().rendering = false; + } + + public void init(String rootPanelId, + ApplicationConnection applicationConnection) { + DOM.sinkEvents(getWidget().getElement(), Event.ONKEYDOWN + | Event.ONSCROLL); + + // iview is focused when created so element needs tabIndex + // 1 due 0 is at the end of natural tabbing order + DOM.setElementProperty(getWidget().getElement(), "tabIndex", "1"); + + RootPanel root = RootPanel.get(rootPanelId); + + // Remove the v-app-loading or any splash screen added inside the div by + // the user + root.getElement().setInnerHTML(""); + + root.addStyleName("v-theme-" + + applicationConnection.getConfiguration().getThemeName()); + + root.add(getWidget()); + + if (applicationConnection.getConfiguration().isStandalone()) { + // set focus to iview element by default to listen possible keyboard + // shortcuts. For embedded applications this is unacceptable as we + // don't want to steal focus from the main page nor we don't want + // side-effects from focusing (scrollIntoView). + getWidget().getElement().focus(); + } + } + + private ClickEventHandler clickEventHandler = new ClickEventHandler(this) { + + @Override + protected void fireClick(NativeEvent event, + MouseEventDetails mouseDetails) { + rpc.click(mouseDetails); + } + + }; + + @Override + public void updateCaption(ComponentConnector component) { + // NOP The main view never draws caption for its layout + } + + @Override + public VUI getWidget() { + return (VUI) super.getWidget(); + } + + protected ComponentConnector getContent() { + return (ComponentConnector) getState().getContent(); + } + + protected void onChildSizeChange() { + ComponentConnector child = getContent(); + Style childStyle = child.getWidget().getElement().getStyle(); + /* + * Must set absolute position if the child has relative height and + * there's a chance of horizontal scrolling as some browsers will + * otherwise not take the scrollbar into account when calculating the + * height. Assuming v-view does not have an undefined width for now, see + * #8460. + */ + if (child.isRelativeHeight() && !BrowserInfo.get().isIE9()) { + childStyle.setPosition(Position.ABSOLUTE); + } else { + childStyle.clearPosition(); + } + } + + /** + * Checks if the given sub window is a child of this UI Connector + * + * @deprecated Should be replaced by a more generic mechanism for getting + * non-ComponentConnector children + * @param wc + * @return + */ + @Deprecated + public boolean hasSubWindow(WindowConnector wc) { + return getChildComponents().contains(wc); + } + + /** + * Return an iterator for current subwindows. This method is meant for + * testing purposes only. + * + * @return + */ + public List getSubWindows() { + ArrayList windows = new ArrayList(); + for (ComponentConnector child : getChildComponents()) { + if (child instanceof WindowConnector) { + windows.add((WindowConnector) child); + } + } + return windows; + } + + @Override + public UIState getState() { + return (UIState) super.getState(); + } + + @Override + public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) { + super.onConnectorHierarchyChange(event); + + ComponentConnector oldChild = null; + ComponentConnector newChild = getContent(); + + for (ComponentConnector c : event.getOldChildren()) { + if (!(c instanceof WindowConnector)) { + oldChild = c; + break; + } + } + + if (oldChild != newChild) { + if (childStateChangeHandlerRegistration != null) { + childStateChangeHandlerRegistration.removeHandler(); + childStateChangeHandlerRegistration = null; + } + getWidget().setWidget(newChild.getWidget()); + childStateChangeHandlerRegistration = newChild + .addStateChangeHandler(childStateChangeHandler); + // Must handle new child here as state change events are already + // fired + onChildSizeChange(); + } + + for (ComponentConnector c : getChildComponents()) { + if (c instanceof WindowConnector) { + WindowConnector wc = (WindowConnector) c; + wc.setWindowOrderAndPosition(); + } + } + + // Close removed sub windows + for (ComponentConnector c : event.getOldChildren()) { + if (c.getParent() != this && c instanceof WindowConnector) { + ((WindowConnector) c).getWidget().hide(); + } + } + } + + /** + * Tries to scroll the viewport so that the given connector is in view. + * + * @param componentConnector + * The connector which should be visible + * + */ + public void scrollIntoView(final ComponentConnector componentConnector) { + if (componentConnector == null) { + return; + } + + Scheduler.get().scheduleDeferred(new Command() { + @Override + public void execute() { + componentConnector.getWidget().getElement().scrollIntoView(); + } + }); + } + +} diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/UI/VUI.java b/client/src/com/vaadin/terminal/gwt/client/ui/UI/VUI.java new file mode 100644 index 0000000000..cb6b181f1d --- /dev/null +++ b/client/src/com/vaadin/terminal/gwt/client/ui/UI/VUI.java @@ -0,0 +1,459 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.terminal.gwt.client.ui.UI; + +import java.util.ArrayList; + +import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.dom.client.Element; +import com.google.gwt.event.logical.shared.HasResizeHandlers; +import com.google.gwt.event.logical.shared.ResizeEvent; +import com.google.gwt.event.logical.shared.ResizeHandler; +import com.google.gwt.event.logical.shared.ValueChangeEvent; +import com.google.gwt.event.logical.shared.ValueChangeHandler; +import com.google.gwt.event.shared.HandlerRegistration; +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.Event; +import com.google.gwt.user.client.History; +import com.google.gwt.user.client.Timer; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.ui.SimplePanel; +import com.vaadin.shared.ApplicationConstants; +import com.vaadin.shared.ui.root.RootConstants; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.BrowserInfo; +import com.vaadin.terminal.gwt.client.ComponentConnector; +import com.vaadin.terminal.gwt.client.ConnectorMap; +import com.vaadin.terminal.gwt.client.Focusable; +import com.vaadin.terminal.gwt.client.VConsole; +import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler; +import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner; +import com.vaadin.terminal.gwt.client.ui.TouchScrollDelegate; +import com.vaadin.terminal.gwt.client.ui.TouchScrollDelegate.TouchScrollHandler; +import com.vaadin.terminal.gwt.client.ui.VLazyExecutor; +import com.vaadin.terminal.gwt.client.ui.textfield.VTextField; + +/** + * + */ +public class VUI extends SimplePanel implements ResizeHandler, + Window.ClosingHandler, ShortcutActionHandlerOwner, Focusable, + HasResizeHandlers { + + private static final String CLASSNAME = "v-view"; + + private static int MONITOR_PARENT_TIMER_INTERVAL = 1000; + + String theme; + + String id; + + ShortcutActionHandler actionHandler; + + /* + * Last known window size used to detect whether VView should be layouted + * again. Detection must check window size, because the VView size might be + * fixed and thus not automatically adapt to changed window sizes. + */ + private int windowWidth; + private int windowHeight; + + /* + * Last know view size used to detect whether new dimensions should be sent + * to the server. + */ + private int viewWidth; + private int viewHeight; + + ApplicationConnection connection; + + /** + * Keep track of possible parent size changes when an embedded application. + * + * Uses {@link #parentWidth} and {@link #parentHeight} as an optimization to + * keep track of when there is a real change. + */ + private Timer resizeTimer; + + /** stored width of parent for embedded application auto-resize */ + private int parentWidth; + + /** stored height of parent for embedded application auto-resize */ + private int parentHeight; + + int scrollTop; + + int scrollLeft; + + boolean rendering; + + boolean scrollable; + + boolean immediate; + + boolean resizeLazy = false; + + private HandlerRegistration historyHandlerRegistration; + + private TouchScrollHandler touchScrollHandler; + + /** + * The current URI fragment, used to avoid sending updates if nothing has + * changed. + */ + String currentFragment; + + /** + * Listener for URI fragment changes. Notifies the server of the new value + * whenever the value changes. + */ + private final ValueChangeHandler historyChangeHandler = new ValueChangeHandler() { + + @Override + public void onValueChange(ValueChangeEvent event) { + String newFragment = event.getValue(); + + // Send the new fragment to the server if it has changed + if (!newFragment.equals(currentFragment) && connection != null) { + currentFragment = newFragment; + connection.updateVariable(id, RootConstants.FRAGMENT_VARIABLE, + newFragment, true); + } + } + }; + + private VLazyExecutor delayedResizeExecutor = new VLazyExecutor(200, + new ScheduledCommand() { + + @Override + public void execute() { + performSizeCheck(); + } + + }); + + public VUI() { + super(); + setStyleName(CLASSNAME); + + // Allow focusing the view by using the focus() method, the view + // should not be in the document focus flow + getElement().setTabIndex(-1); + makeScrollable(); + } + + /** + * Start to periodically monitor for parent element resizes if embedded + * application (e.g. portlet). + */ + @Override + protected void onLoad() { + super.onLoad(); + if (isMonitoringParentSize()) { + resizeTimer = new Timer() { + + @Override + public void run() { + // trigger check to see if parent size has changed, + // recalculate layouts + performSizeCheck(); + resizeTimer.schedule(MONITOR_PARENT_TIMER_INTERVAL); + } + }; + resizeTimer.schedule(MONITOR_PARENT_TIMER_INTERVAL); + } + } + + @Override + protected void onAttach() { + super.onAttach(); + historyHandlerRegistration = History + .addValueChangeHandler(historyChangeHandler); + currentFragment = History.getToken(); + } + + @Override + protected void onDetach() { + super.onDetach(); + historyHandlerRegistration.removeHandler(); + historyHandlerRegistration = null; + } + + /** + * Stop monitoring for parent element resizes. + */ + + @Override + protected void onUnload() { + if (resizeTimer != null) { + resizeTimer.cancel(); + resizeTimer = null; + } + super.onUnload(); + } + + /** + * Called when the window or parent div might have been resized. + * + * This immediately checks the sizes of the window and the parent div (if + * monitoring it) and triggers layout recalculation if they have changed. + */ + protected void performSizeCheck() { + windowSizeMaybeChanged(Window.getClientWidth(), + Window.getClientHeight()); + } + + /** + * Called when the window or parent div might have been resized. + * + * This immediately checks the sizes of the window and the parent div (if + * monitoring it) and triggers layout recalculation if they have changed. + * + * @param newWindowWidth + * The new width of the window + * @param newWindowHeight + * The new height of the window + * + * @deprecated use {@link #performSizeCheck()} + */ + @Deprecated + protected void windowSizeMaybeChanged(int newWindowWidth, + int newWindowHeight) { + boolean changed = false; + ComponentConnector connector = ConnectorMap.get(connection) + .getConnector(this); + if (windowWidth != newWindowWidth) { + windowWidth = newWindowWidth; + changed = true; + connector.getLayoutManager().reportOuterWidth(connector, + newWindowWidth); + VConsole.log("New window width: " + windowWidth); + } + if (windowHeight != newWindowHeight) { + windowHeight = newWindowHeight; + changed = true; + connector.getLayoutManager().reportOuterHeight(connector, + newWindowHeight); + VConsole.log("New window height: " + windowHeight); + } + Element parentElement = getElement().getParentElement(); + if (isMonitoringParentSize() && parentElement != null) { + // check also for parent size changes + int newParentWidth = parentElement.getClientWidth(); + int newParentHeight = parentElement.getClientHeight(); + if (parentWidth != newParentWidth) { + parentWidth = newParentWidth; + changed = true; + VConsole.log("New parent width: " + parentWidth); + } + if (parentHeight != newParentHeight) { + parentHeight = newParentHeight; + changed = true; + VConsole.log("New parent height: " + parentHeight); + } + } + if (changed) { + /* + * If the window size has changed, layout the VView again and send + * new size to the server if the size changed. (Just checking VView + * size would cause us to ignore cases when a relatively sized VView + * should shrink as the content's size is fixed and would thus not + * automatically shrink.) + */ + VConsole.log("Running layout functions due to window or parent resize"); + + // update size to avoid (most) redundant re-layout passes + // there can still be an extra layout recalculation if webkit + // overflow fix updates the size in a deferred block + if (isMonitoringParentSize() && parentElement != null) { + parentWidth = parentElement.getClientWidth(); + parentHeight = parentElement.getClientHeight(); + } + + sendClientResized(); + + connector.getLayoutManager().layoutNow(); + } + } + + public String getTheme() { + return theme; + } + + /** + * Used to reload host page on theme changes. + */ + static native void reloadHostPage() + /*-{ + $wnd.location.reload(); + }-*/; + + /** + * Returns true if the body is NOT generated, i.e if someone else has made + * the page that we're running in. Otherwise we're in charge of the whole + * page. + * + * @return true if we're running embedded + */ + public boolean isEmbedded() { + return !getElement().getOwnerDocument().getBody().getClassName() + .contains(ApplicationConstants.GENERATED_BODY_CLASSNAME); + } + + /** + * Returns true if the size of the parent should be checked periodically and + * the application should react to its changes. + * + * @return true if size of parent should be tracked + */ + protected boolean isMonitoringParentSize() { + // could also perform a more specific check (Liferay portlet) + return isEmbedded(); + } + + @Override + public void onBrowserEvent(Event event) { + super.onBrowserEvent(event); + int type = DOM.eventGetType(event); + if (type == Event.ONKEYDOWN && actionHandler != null) { + actionHandler.handleKeyboardEvent(event); + return; + } else if (scrollable && type == Event.ONSCROLL) { + updateScrollPosition(); + } + } + + /** + * Updates scroll position from DOM and saves variables to server. + */ + private void updateScrollPosition() { + int oldTop = scrollTop; + int oldLeft = scrollLeft; + scrollTop = DOM.getElementPropertyInt(getElement(), "scrollTop"); + scrollLeft = DOM.getElementPropertyInt(getElement(), "scrollLeft"); + if (connection != null && !rendering) { + if (oldTop != scrollTop) { + connection.updateVariable(id, "scrollTop", scrollTop, false); + } + if (oldLeft != scrollLeft) { + connection.updateVariable(id, "scrollLeft", scrollLeft, false); + } + } + } + + /* + * (non-Javadoc) + * + * @see + * com.google.gwt.event.logical.shared.ResizeHandler#onResize(com.google + * .gwt.event.logical.shared.ResizeEvent) + */ + + @Override + public void onResize(ResizeEvent event) { + triggerSizeChangeCheck(); + } + + /** + * Called when a resize event is received. + * + * This may trigger a lazy refresh or perform the size check immediately + * depending on the browser used and whether the server side requests + * resizes to be lazy. + */ + private void triggerSizeChangeCheck() { + /* + * IE (pre IE9 at least) will give us some false resize events due to + * problems with scrollbars. Firefox 3 might also produce some extra + * events. We postpone both the re-layouting and the server side event + * for a while to deal with these issues. + * + * We may also postpone these events to avoid slowness when resizing the + * browser window. Constantly recalculating the layout causes the resize + * operation to be really slow with complex layouts. + */ + boolean lazy = resizeLazy || BrowserInfo.get().isIE8(); + + if (lazy) { + delayedResizeExecutor.trigger(); + } else { + performSizeCheck(); + } + } + + /** + * Send new dimensions to the server. + */ + void sendClientResized() { + Element parentElement = getElement().getParentElement(); + int viewHeight = parentElement.getClientHeight(); + int viewWidth = parentElement.getClientWidth(); + + ResizeEvent.fire(this, viewWidth, viewHeight); + } + + public native static void goTo(String url) + /*-{ + $wnd.location = url; + }-*/; + + @Override + public void onWindowClosing(Window.ClosingEvent event) { + // Change focus on this window in order to ensure that all state is + // collected from textfields + // TODO this is a naive hack, that only works with text fields and may + // cause some odd issues. Should be replaced with a decent solution, see + // also related BeforeShortcutActionListener interface. Same interface + // might be usable here. + VTextField.flushChangesFromFocusedTextField(); + } + + private native static void loadAppIdListFromDOM(ArrayList list) + /*-{ + var j; + for(j in $wnd.vaadin.vaadinConfigurations) { + // $entry not needed as function is not exported + list.@java.util.Collection::add(Ljava/lang/Object;)(j); + } + }-*/; + + @Override + public ShortcutActionHandler getShortcutActionHandler() { + return actionHandler; + } + + @Override + public void focus() { + getElement().focus(); + } + + /** + * Ensures the root is scrollable eg. after style name changes. + */ + void makeScrollable() { + if (touchScrollHandler == null) { + touchScrollHandler = TouchScrollDelegate.enableTouchScrolling(this); + } + touchScrollHandler.addElement(getElement()); + } + + @Override + public HandlerRegistration addResizeHandler(ResizeHandler resizeHandler) { + return addHandler(resizeHandler, ResizeEvent.getType()); + } + +} diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java deleted file mode 100644 index 3321b07146..0000000000 --- a/client/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java +++ /dev/null @@ -1,457 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.terminal.gwt.client.ui.root; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import com.google.gwt.core.client.Scheduler; -import com.google.gwt.dom.client.NativeEvent; -import com.google.gwt.dom.client.Style; -import com.google.gwt.dom.client.Style.Position; -import com.google.gwt.event.logical.shared.ResizeEvent; -import com.google.gwt.event.logical.shared.ResizeHandler; -import com.google.gwt.user.client.Command; -import com.google.gwt.user.client.DOM; -import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.History; -import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.ui.RootPanel; -import com.google.gwt.user.client.ui.Widget; -import com.google.web.bindery.event.shared.HandlerRegistration; -import com.vaadin.shared.MouseEventDetails; -import com.vaadin.shared.ui.Connect; -import com.vaadin.shared.ui.Connect.LoadStyle; -import com.vaadin.shared.ui.root.PageClientRpc; -import com.vaadin.shared.ui.root.RootConstants; -import com.vaadin.shared.ui.root.RootServerRpc; -import com.vaadin.shared.ui.root.RootState; -import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.BrowserInfo; -import com.vaadin.terminal.gwt.client.ComponentConnector; -import com.vaadin.terminal.gwt.client.ConnectorHierarchyChangeEvent; -import com.vaadin.terminal.gwt.client.ConnectorMap; -import com.vaadin.terminal.gwt.client.Focusable; -import com.vaadin.terminal.gwt.client.Paintable; -import com.vaadin.terminal.gwt.client.UIDL; -import com.vaadin.terminal.gwt.client.VConsole; -import com.vaadin.terminal.gwt.client.communication.RpcProxy; -import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; -import com.vaadin.terminal.gwt.client.communication.StateChangeEvent.StateChangeHandler; -import com.vaadin.terminal.gwt.client.ui.AbstractComponentContainerConnector; -import com.vaadin.terminal.gwt.client.ui.ClickEventHandler; -import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler; -import com.vaadin.terminal.gwt.client.ui.layout.MayScrollChildren; -import com.vaadin.terminal.gwt.client.ui.notification.VNotification; -import com.vaadin.terminal.gwt.client.ui.window.WindowConnector; -import com.vaadin.ui.UI; - -@Connect(value = UI.class, loadStyle = LoadStyle.EAGER) -public class RootConnector extends AbstractComponentContainerConnector - implements Paintable, MayScrollChildren { - - private RootServerRpc rpc = RpcProxy.create(RootServerRpc.class, this); - - private HandlerRegistration childStateChangeHandlerRegistration; - - private final StateChangeHandler childStateChangeHandler = new StateChangeHandler() { - @Override - public void onStateChanged(StateChangeEvent stateChangeEvent) { - // TODO Should use a more specific handler that only reacts to - // size changes - onChildSizeChange(); - } - }; - - @Override - protected void init() { - super.init(); - registerRpc(PageClientRpc.class, new PageClientRpc() { - @Override - public void setTitle(String title) { - com.google.gwt.user.client.Window.setTitle(title); - } - }); - getWidget().addResizeHandler(new ResizeHandler() { - @Override - public void onResize(ResizeEvent event) { - rpc.resize(event.getHeight(), event.getWidth(), - Window.getClientWidth(), Window.getClientHeight()); - if (getState().isImmediate()) { - getConnection().sendPendingVariableChanges(); - } - } - }); - } - - @Override - public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) { - ConnectorMap paintableMap = ConnectorMap.get(getConnection()); - getWidget().rendering = true; - getWidget().id = getConnectorId(); - boolean firstPaint = getWidget().connection == null; - getWidget().connection = client; - - getWidget().immediate = getState().isImmediate(); - getWidget().resizeLazy = uidl.hasAttribute(RootConstants.RESIZE_LAZY); - String newTheme = uidl.getStringAttribute("theme"); - if (getWidget().theme != null && !newTheme.equals(getWidget().theme)) { - // Complete page refresh is needed due css can affect layout - // calculations etc - getWidget().reloadHostPage(); - } else { - getWidget().theme = newTheme; - } - // this also implicitly removes old styles - String styles = ""; - styles += getWidget().getStylePrimaryName() + " "; - if (getState().hasStyles()) { - for (String style : getState().getStyles()) { - styles += style + " "; - } - } - if (!client.getConfiguration().isStandalone()) { - styles += getWidget().getStylePrimaryName() + "-embedded"; - } - getWidget().setStyleName(styles.trim()); - - getWidget().makeScrollable(); - - clickEventHandler.handleEventHandlerRegistration(); - - // Process children - int childIndex = 0; - - // Open URL:s - boolean isClosed = false; // was this window closed? - while (childIndex < uidl.getChildCount() - && "open".equals(uidl.getChildUIDL(childIndex).getTag())) { - final UIDL open = uidl.getChildUIDL(childIndex); - final String url = client.translateVaadinUri(open - .getStringAttribute("src")); - final String target = open.getStringAttribute("name"); - if (target == null) { - // source will be opened to this browser window, but we may have - // to finish rendering this window in case this is a download - // (and window stays open). - Scheduler.get().scheduleDeferred(new Command() { - @Override - public void execute() { - VRoot.goTo(url); - } - }); - } else if ("_self".equals(target)) { - // This window is closing (for sure). Only other opens are - // relevant in this change. See #3558, #2144 - isClosed = true; - VRoot.goTo(url); - } else { - String options; - if (open.hasAttribute("border")) { - if (open.getStringAttribute("border").equals("minimal")) { - options = "menubar=yes,location=no,status=no"; - } else { - options = "menubar=no,location=no,status=no"; - } - - } else { - options = "resizable=yes,menubar=yes,toolbar=yes,directories=yes,location=yes,scrollbars=yes,status=yes"; - } - - if (open.hasAttribute("width")) { - int w = open.getIntAttribute("width"); - options += ",width=" + w; - } - if (open.hasAttribute("height")) { - int h = open.getIntAttribute("height"); - options += ",height=" + h; - } - - Window.open(url, target, options); - } - childIndex++; - } - if (isClosed) { - // don't render the content, something else will be opened to this - // browser view - getWidget().rendering = false; - return; - } - - // Handle other UIDL children - UIDL childUidl; - while ((childUidl = uidl.getChildUIDL(childIndex++)) != null) { - String tag = childUidl.getTag().intern(); - if (tag == "actions") { - if (getWidget().actionHandler == null) { - getWidget().actionHandler = new ShortcutActionHandler( - getWidget().id, client); - } - getWidget().actionHandler.updateActionMap(childUidl); - } else if (tag == "notifications") { - for (final Iterator it = childUidl.getChildIterator(); it - .hasNext();) { - final UIDL notification = (UIDL) it.next(); - VNotification.showNotification(client, notification); - } - } - } - - if (uidl.hasAttribute("focused")) { - // set focused component when render phase is finished - Scheduler.get().scheduleDeferred(new Command() { - @Override - public void execute() { - ComponentConnector paintable = (ComponentConnector) uidl - .getPaintableAttribute("focused", getConnection()); - - final Widget toBeFocused = paintable.getWidget(); - /* - * Two types of Widgets can be focused, either implementing - * GWT HasFocus of a thinner Vaadin specific Focusable - * interface. - */ - if (toBeFocused instanceof com.google.gwt.user.client.ui.Focusable) { - final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) toBeFocused; - toBeFocusedWidget.setFocus(true); - } else if (toBeFocused instanceof Focusable) { - ((Focusable) toBeFocused).focus(); - } else { - VConsole.log("Could not focus component"); - } - } - }); - } - - // Add window listeners on first paint, to prevent premature - // variablechanges - if (firstPaint) { - Window.addWindowClosingHandler(getWidget()); - Window.addResizeHandler(getWidget()); - } - - // finally set scroll position from UIDL - if (uidl.hasVariable("scrollTop")) { - getWidget().scrollable = true; - getWidget().scrollTop = uidl.getIntVariable("scrollTop"); - DOM.setElementPropertyInt(getWidget().getElement(), "scrollTop", - getWidget().scrollTop); - getWidget().scrollLeft = uidl.getIntVariable("scrollLeft"); - DOM.setElementPropertyInt(getWidget().getElement(), "scrollLeft", - getWidget().scrollLeft); - } else { - getWidget().scrollable = false; - } - - if (uidl.hasAttribute("scrollTo")) { - final ComponentConnector connector = (ComponentConnector) uidl - .getPaintableAttribute("scrollTo", getConnection()); - scrollIntoView(connector); - } - - if (uidl.hasAttribute(RootConstants.FRAGMENT_VARIABLE)) { - getWidget().currentFragment = uidl - .getStringAttribute(RootConstants.FRAGMENT_VARIABLE); - if (!getWidget().currentFragment.equals(History.getToken())) { - History.newItem(getWidget().currentFragment, true); - } - } else { - // Initial request for which the server doesn't yet have a fragment - // (and haven't shown any interest in getting one) - getWidget().currentFragment = History.getToken(); - - // Include current fragment in the next request - client.updateVariable(getWidget().id, - RootConstants.FRAGMENT_VARIABLE, - getWidget().currentFragment, false); - } - - if (firstPaint) { - // Queue the initial window size to be sent with the following - // request. - getWidget().sendClientResized(); - } - getWidget().rendering = false; - } - - public void init(String rootPanelId, - ApplicationConnection applicationConnection) { - DOM.sinkEvents(getWidget().getElement(), Event.ONKEYDOWN - | Event.ONSCROLL); - - // iview is focused when created so element needs tabIndex - // 1 due 0 is at the end of natural tabbing order - DOM.setElementProperty(getWidget().getElement(), "tabIndex", "1"); - - RootPanel root = RootPanel.get(rootPanelId); - - // Remove the v-app-loading or any splash screen added inside the div by - // the user - root.getElement().setInnerHTML(""); - - root.addStyleName("v-theme-" - + applicationConnection.getConfiguration().getThemeName()); - - root.add(getWidget()); - - if (applicationConnection.getConfiguration().isStandalone()) { - // set focus to iview element by default to listen possible keyboard - // shortcuts. For embedded applications this is unacceptable as we - // don't want to steal focus from the main page nor we don't want - // side-effects from focusing (scrollIntoView). - getWidget().getElement().focus(); - } - } - - private ClickEventHandler clickEventHandler = new ClickEventHandler(this) { - - @Override - protected void fireClick(NativeEvent event, - MouseEventDetails mouseDetails) { - rpc.click(mouseDetails); - } - - }; - - @Override - public void updateCaption(ComponentConnector component) { - // NOP The main view never draws caption for its layout - } - - @Override - public VRoot getWidget() { - return (VRoot) super.getWidget(); - } - - protected ComponentConnector getContent() { - return (ComponentConnector) getState().getContent(); - } - - protected void onChildSizeChange() { - ComponentConnector child = getContent(); - Style childStyle = child.getWidget().getElement().getStyle(); - /* - * Must set absolute position if the child has relative height and - * there's a chance of horizontal scrolling as some browsers will - * otherwise not take the scrollbar into account when calculating the - * height. Assuming v-view does not have an undefined width for now, see - * #8460. - */ - if (child.isRelativeHeight() && !BrowserInfo.get().isIE9()) { - childStyle.setPosition(Position.ABSOLUTE); - } else { - childStyle.clearPosition(); - } - } - - /** - * Checks if the given sub window is a child of this UI Connector - * - * @deprecated Should be replaced by a more generic mechanism for getting - * non-ComponentConnector children - * @param wc - * @return - */ - @Deprecated - public boolean hasSubWindow(WindowConnector wc) { - return getChildComponents().contains(wc); - } - - /** - * Return an iterator for current subwindows. This method is meant for - * testing purposes only. - * - * @return - */ - public List getSubWindows() { - ArrayList windows = new ArrayList(); - for (ComponentConnector child : getChildComponents()) { - if (child instanceof WindowConnector) { - windows.add((WindowConnector) child); - } - } - return windows; - } - - @Override - public RootState getState() { - return (RootState) super.getState(); - } - - @Override - public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) { - super.onConnectorHierarchyChange(event); - - ComponentConnector oldChild = null; - ComponentConnector newChild = getContent(); - - for (ComponentConnector c : event.getOldChildren()) { - if (!(c instanceof WindowConnector)) { - oldChild = c; - break; - } - } - - if (oldChild != newChild) { - if (childStateChangeHandlerRegistration != null) { - childStateChangeHandlerRegistration.removeHandler(); - childStateChangeHandlerRegistration = null; - } - getWidget().setWidget(newChild.getWidget()); - childStateChangeHandlerRegistration = newChild - .addStateChangeHandler(childStateChangeHandler); - // Must handle new child here as state change events are already - // fired - onChildSizeChange(); - } - - for (ComponentConnector c : getChildComponents()) { - if (c instanceof WindowConnector) { - WindowConnector wc = (WindowConnector) c; - wc.setWindowOrderAndPosition(); - } - } - - // Close removed sub windows - for (ComponentConnector c : event.getOldChildren()) { - if (c.getParent() != this && c instanceof WindowConnector) { - ((WindowConnector) c).getWidget().hide(); - } - } - } - - /** - * Tries to scroll the viewport so that the given connector is in view. - * - * @param componentConnector - * The connector which should be visible - * - */ - public void scrollIntoView(final ComponentConnector componentConnector) { - if (componentConnector == null) { - return; - } - - Scheduler.get().scheduleDeferred(new Command() { - @Override - public void execute() { - componentConnector.getWidget().getElement().scrollIntoView(); - } - }); - } - -} diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/root/VRoot.java b/client/src/com/vaadin/terminal/gwt/client/ui/root/VRoot.java deleted file mode 100644 index 162e7c55a8..0000000000 --- a/client/src/com/vaadin/terminal/gwt/client/ui/root/VRoot.java +++ /dev/null @@ -1,459 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.vaadin.terminal.gwt.client.ui.root; - -import java.util.ArrayList; - -import com.google.gwt.core.client.Scheduler.ScheduledCommand; -import com.google.gwt.dom.client.Element; -import com.google.gwt.event.logical.shared.HasResizeHandlers; -import com.google.gwt.event.logical.shared.ResizeEvent; -import com.google.gwt.event.logical.shared.ResizeHandler; -import com.google.gwt.event.logical.shared.ValueChangeEvent; -import com.google.gwt.event.logical.shared.ValueChangeHandler; -import com.google.gwt.event.shared.HandlerRegistration; -import com.google.gwt.user.client.DOM; -import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.History; -import com.google.gwt.user.client.Timer; -import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.ui.SimplePanel; -import com.vaadin.shared.ApplicationConstants; -import com.vaadin.shared.ui.root.RootConstants; -import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.BrowserInfo; -import com.vaadin.terminal.gwt.client.ComponentConnector; -import com.vaadin.terminal.gwt.client.ConnectorMap; -import com.vaadin.terminal.gwt.client.Focusable; -import com.vaadin.terminal.gwt.client.VConsole; -import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler; -import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner; -import com.vaadin.terminal.gwt.client.ui.TouchScrollDelegate; -import com.vaadin.terminal.gwt.client.ui.TouchScrollDelegate.TouchScrollHandler; -import com.vaadin.terminal.gwt.client.ui.VLazyExecutor; -import com.vaadin.terminal.gwt.client.ui.textfield.VTextField; - -/** - * - */ -public class VRoot extends SimplePanel implements ResizeHandler, - Window.ClosingHandler, ShortcutActionHandlerOwner, Focusable, - HasResizeHandlers { - - private static final String CLASSNAME = "v-view"; - - private static int MONITOR_PARENT_TIMER_INTERVAL = 1000; - - String theme; - - String id; - - ShortcutActionHandler actionHandler; - - /* - * Last known window size used to detect whether VView should be layouted - * again. Detection must check window size, because the VView size might be - * fixed and thus not automatically adapt to changed window sizes. - */ - private int windowWidth; - private int windowHeight; - - /* - * Last know view size used to detect whether new dimensions should be sent - * to the server. - */ - private int viewWidth; - private int viewHeight; - - ApplicationConnection connection; - - /** - * Keep track of possible parent size changes when an embedded application. - * - * Uses {@link #parentWidth} and {@link #parentHeight} as an optimization to - * keep track of when there is a real change. - */ - private Timer resizeTimer; - - /** stored width of parent for embedded application auto-resize */ - private int parentWidth; - - /** stored height of parent for embedded application auto-resize */ - private int parentHeight; - - int scrollTop; - - int scrollLeft; - - boolean rendering; - - boolean scrollable; - - boolean immediate; - - boolean resizeLazy = false; - - private HandlerRegistration historyHandlerRegistration; - - private TouchScrollHandler touchScrollHandler; - - /** - * The current URI fragment, used to avoid sending updates if nothing has - * changed. - */ - String currentFragment; - - /** - * Listener for URI fragment changes. Notifies the server of the new value - * whenever the value changes. - */ - private final ValueChangeHandler historyChangeHandler = new ValueChangeHandler() { - - @Override - public void onValueChange(ValueChangeEvent event) { - String newFragment = event.getValue(); - - // Send the new fragment to the server if it has changed - if (!newFragment.equals(currentFragment) && connection != null) { - currentFragment = newFragment; - connection.updateVariable(id, RootConstants.FRAGMENT_VARIABLE, - newFragment, true); - } - } - }; - - private VLazyExecutor delayedResizeExecutor = new VLazyExecutor(200, - new ScheduledCommand() { - - @Override - public void execute() { - performSizeCheck(); - } - - }); - - public VRoot() { - super(); - setStyleName(CLASSNAME); - - // Allow focusing the view by using the focus() method, the view - // should not be in the document focus flow - getElement().setTabIndex(-1); - makeScrollable(); - } - - /** - * Start to periodically monitor for parent element resizes if embedded - * application (e.g. portlet). - */ - @Override - protected void onLoad() { - super.onLoad(); - if (isMonitoringParentSize()) { - resizeTimer = new Timer() { - - @Override - public void run() { - // trigger check to see if parent size has changed, - // recalculate layouts - performSizeCheck(); - resizeTimer.schedule(MONITOR_PARENT_TIMER_INTERVAL); - } - }; - resizeTimer.schedule(MONITOR_PARENT_TIMER_INTERVAL); - } - } - - @Override - protected void onAttach() { - super.onAttach(); - historyHandlerRegistration = History - .addValueChangeHandler(historyChangeHandler); - currentFragment = History.getToken(); - } - - @Override - protected void onDetach() { - super.onDetach(); - historyHandlerRegistration.removeHandler(); - historyHandlerRegistration = null; - } - - /** - * Stop monitoring for parent element resizes. - */ - - @Override - protected void onUnload() { - if (resizeTimer != null) { - resizeTimer.cancel(); - resizeTimer = null; - } - super.onUnload(); - } - - /** - * Called when the window or parent div might have been resized. - * - * This immediately checks the sizes of the window and the parent div (if - * monitoring it) and triggers layout recalculation if they have changed. - */ - protected void performSizeCheck() { - windowSizeMaybeChanged(Window.getClientWidth(), - Window.getClientHeight()); - } - - /** - * Called when the window or parent div might have been resized. - * - * This immediately checks the sizes of the window and the parent div (if - * monitoring it) and triggers layout recalculation if they have changed. - * - * @param newWindowWidth - * The new width of the window - * @param newWindowHeight - * The new height of the window - * - * @deprecated use {@link #performSizeCheck()} - */ - @Deprecated - protected void windowSizeMaybeChanged(int newWindowWidth, - int newWindowHeight) { - boolean changed = false; - ComponentConnector connector = ConnectorMap.get(connection) - .getConnector(this); - if (windowWidth != newWindowWidth) { - windowWidth = newWindowWidth; - changed = true; - connector.getLayoutManager().reportOuterWidth(connector, - newWindowWidth); - VConsole.log("New window width: " + windowWidth); - } - if (windowHeight != newWindowHeight) { - windowHeight = newWindowHeight; - changed = true; - connector.getLayoutManager().reportOuterHeight(connector, - newWindowHeight); - VConsole.log("New window height: " + windowHeight); - } - Element parentElement = getElement().getParentElement(); - if (isMonitoringParentSize() && parentElement != null) { - // check also for parent size changes - int newParentWidth = parentElement.getClientWidth(); - int newParentHeight = parentElement.getClientHeight(); - if (parentWidth != newParentWidth) { - parentWidth = newParentWidth; - changed = true; - VConsole.log("New parent width: " + parentWidth); - } - if (parentHeight != newParentHeight) { - parentHeight = newParentHeight; - changed = true; - VConsole.log("New parent height: " + parentHeight); - } - } - if (changed) { - /* - * If the window size has changed, layout the VView again and send - * new size to the server if the size changed. (Just checking VView - * size would cause us to ignore cases when a relatively sized VView - * should shrink as the content's size is fixed and would thus not - * automatically shrink.) - */ - VConsole.log("Running layout functions due to window or parent resize"); - - // update size to avoid (most) redundant re-layout passes - // there can still be an extra layout recalculation if webkit - // overflow fix updates the size in a deferred block - if (isMonitoringParentSize() && parentElement != null) { - parentWidth = parentElement.getClientWidth(); - parentHeight = parentElement.getClientHeight(); - } - - sendClientResized(); - - connector.getLayoutManager().layoutNow(); - } - } - - public String getTheme() { - return theme; - } - - /** - * Used to reload host page on theme changes. - */ - static native void reloadHostPage() - /*-{ - $wnd.location.reload(); - }-*/; - - /** - * Returns true if the body is NOT generated, i.e if someone else has made - * the page that we're running in. Otherwise we're in charge of the whole - * page. - * - * @return true if we're running embedded - */ - public boolean isEmbedded() { - return !getElement().getOwnerDocument().getBody().getClassName() - .contains(ApplicationConstants.GENERATED_BODY_CLASSNAME); - } - - /** - * Returns true if the size of the parent should be checked periodically and - * the application should react to its changes. - * - * @return true if size of parent should be tracked - */ - protected boolean isMonitoringParentSize() { - // could also perform a more specific check (Liferay portlet) - return isEmbedded(); - } - - @Override - public void onBrowserEvent(Event event) { - super.onBrowserEvent(event); - int type = DOM.eventGetType(event); - if (type == Event.ONKEYDOWN && actionHandler != null) { - actionHandler.handleKeyboardEvent(event); - return; - } else if (scrollable && type == Event.ONSCROLL) { - updateScrollPosition(); - } - } - - /** - * Updates scroll position from DOM and saves variables to server. - */ - private void updateScrollPosition() { - int oldTop = scrollTop; - int oldLeft = scrollLeft; - scrollTop = DOM.getElementPropertyInt(getElement(), "scrollTop"); - scrollLeft = DOM.getElementPropertyInt(getElement(), "scrollLeft"); - if (connection != null && !rendering) { - if (oldTop != scrollTop) { - connection.updateVariable(id, "scrollTop", scrollTop, false); - } - if (oldLeft != scrollLeft) { - connection.updateVariable(id, "scrollLeft", scrollLeft, false); - } - } - } - - /* - * (non-Javadoc) - * - * @see - * com.google.gwt.event.logical.shared.ResizeHandler#onResize(com.google - * .gwt.event.logical.shared.ResizeEvent) - */ - - @Override - public void onResize(ResizeEvent event) { - triggerSizeChangeCheck(); - } - - /** - * Called when a resize event is received. - * - * This may trigger a lazy refresh or perform the size check immediately - * depending on the browser used and whether the server side requests - * resizes to be lazy. - */ - private void triggerSizeChangeCheck() { - /* - * IE (pre IE9 at least) will give us some false resize events due to - * problems with scrollbars. Firefox 3 might also produce some extra - * events. We postpone both the re-layouting and the server side event - * for a while to deal with these issues. - * - * We may also postpone these events to avoid slowness when resizing the - * browser window. Constantly recalculating the layout causes the resize - * operation to be really slow with complex layouts. - */ - boolean lazy = resizeLazy || BrowserInfo.get().isIE8(); - - if (lazy) { - delayedResizeExecutor.trigger(); - } else { - performSizeCheck(); - } - } - - /** - * Send new dimensions to the server. - */ - void sendClientResized() { - Element parentElement = getElement().getParentElement(); - int viewHeight = parentElement.getClientHeight(); - int viewWidth = parentElement.getClientWidth(); - - ResizeEvent.fire(this, viewWidth, viewHeight); - } - - public native static void goTo(String url) - /*-{ - $wnd.location = url; - }-*/; - - @Override - public void onWindowClosing(Window.ClosingEvent event) { - // Change focus on this window in order to ensure that all state is - // collected from textfields - // TODO this is a naive hack, that only works with text fields and may - // cause some odd issues. Should be replaced with a decent solution, see - // also related BeforeShortcutActionListener interface. Same interface - // might be usable here. - VTextField.flushChangesFromFocusedTextField(); - } - - private native static void loadAppIdListFromDOM(ArrayList list) - /*-{ - var j; - for(j in $wnd.vaadin.vaadinConfigurations) { - // $entry not needed as function is not exported - list.@java.util.Collection::add(Ljava/lang/Object;)(j); - } - }-*/; - - @Override - public ShortcutActionHandler getShortcutActionHandler() { - return actionHandler; - } - - @Override - public void focus() { - getElement().focus(); - } - - /** - * Ensures the root is scrollable eg. after style name changes. - */ - void makeScrollable() { - if (touchScrollHandler == null) { - touchScrollHandler = TouchScrollDelegate.enableTouchScrolling(this); - } - touchScrollHandler.addElement(getElement()); - } - - @Override - public HandlerRegistration addResizeHandler(ResizeHandler resizeHandler) { - return addHandler(resizeHandler, ResizeEvent.getType()); - } - -} diff --git a/server/src/com/vaadin/Application.java b/server/src/com/vaadin/Application.java index 23d407e4f3..582e05d3f4 100644 --- a/server/src/com/vaadin/Application.java +++ b/server/src/com/vaadin/Application.java @@ -1845,7 +1845,7 @@ public class Application implements Terminal.ErrorListener, Serializable { * *

* If {@link BrowserDetails} are required to create a UI, the - * implementation can throw a {@link RootRequiresMoreInformationException} + * implementation can throw a {@link UIRequiresMoreInformationException} * exception. In this case, the framework will instruct the browser to send * the additional details, whereupon this method is invoked again with the * browser details present in the wrapped request. Throwing the exception if @@ -1864,19 +1864,19 @@ public class Application implements Terminal.ErrorListener, Serializable { * @param request * the wrapped request for which a root is needed * @return a root instance to use for the request - * @throws RootRequiresMoreInformationException + * @throws UIRequiresMoreInformationException * may be thrown by an implementation to indicate that * {@link BrowserDetails} are required to create a root * * @see #getRootClassName(WrappedRequest) * @see UI - * @see RootRequiresMoreInformationException + * @see UIRequiresMoreInformationException * @see WrappedRequest#getBrowserDetails() * * @since 7.0 */ protected UI getRoot(WrappedRequest request) - throws RootRequiresMoreInformationException { + throws UIRequiresMoreInformationException { // Iterate in reverse order - test check newest provider first for (int i = rootProviders.size() - 1; i >= 0; i--) { @@ -2151,7 +2151,7 @@ public class Application implements Terminal.ErrorListener, Serializable { * Finds the {@link UI} to which a particular request belongs. If the * request originates from an existing UI, that root is returned. In other * cases, the method attempts to create and initialize a new root and might - * throw a {@link RootRequiresMoreInformationException} if all required + * throw a {@link UIRequiresMoreInformationException} if all required * information is not available. *

* Please note that this method can also return a newly created @@ -2164,17 +2164,17 @@ public class Application implements Terminal.ErrorListener, Serializable { * @param request * the request for which a root is desired * @return a root belonging to the request - * @throws RootRequiresMoreInformationException + * @throws UIRequiresMoreInformationException * if no existing root could be found and creating a new root * requires additional information from the browser * * @see #getRoot(WrappedRequest) - * @see RootRequiresMoreInformationException + * @see UIRequiresMoreInformationException * * @since 7.0 */ public UI getRootForRequest(WrappedRequest request) - throws RootRequiresMoreInformationException { + throws UIRequiresMoreInformationException { UI uI = UI.getCurrent(); if (uI != null) { return uI; @@ -2194,7 +2194,7 @@ public class Application implements Terminal.ErrorListener, Serializable { Integer retainedRootId; if (!hasBrowserDetails) { - throw new RootRequiresMoreInformationException(); + throw new UIRequiresMoreInformationException(); } else { String windowName = browserDetails.getWindowName(); retainedRootId = retainOnRefreshRoots.get(windowName); diff --git a/server/src/com/vaadin/RootRequiresMoreInformationException.java b/server/src/com/vaadin/RootRequiresMoreInformationException.java deleted file mode 100644 index 74026dd161..0000000000 --- a/server/src/com/vaadin/RootRequiresMoreInformationException.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.vaadin; - -import com.vaadin.terminal.WrappedRequest; -import com.vaadin.terminal.WrappedRequest.BrowserDetails; - -/** - * Exception that is thrown to indicate that creating or initializing the root - * requires information detailed from the web browser ({@link BrowserDetails}) - * to be present. - * - * This exception may not be thrown if that information is already present in - * the current WrappedRequest. - * - * @see Application#getRoot(WrappedRequest) - * @see WrappedRequest#getBrowserDetails() - * - * @since 7.0 - */ -public class RootRequiresMoreInformationException extends Exception { - // Nothing of interest here -} diff --git a/server/src/com/vaadin/UIRequiresMoreInformationException.java b/server/src/com/vaadin/UIRequiresMoreInformationException.java new file mode 100644 index 0000000000..682d46f207 --- /dev/null +++ b/server/src/com/vaadin/UIRequiresMoreInformationException.java @@ -0,0 +1,37 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin; + +import com.vaadin.terminal.WrappedRequest; +import com.vaadin.terminal.WrappedRequest.BrowserDetails; + +/** + * Exception that is thrown to indicate that creating or initializing the root + * requires information detailed from the web browser ({@link BrowserDetails}) + * to be present. + * + * This exception may not be thrown if that information is already present in + * the current WrappedRequest. + * + * @see Application#getRoot(WrappedRequest) + * @see WrappedRequest#getBrowserDetails() + * + * @since 7.0 + */ +public class UIRequiresMoreInformationException extends Exception { + // Nothing of interest here +} diff --git a/server/src/com/vaadin/terminal/DefaultRootProvider.java b/server/src/com/vaadin/terminal/DefaultRootProvider.java index 07533949a0..7e6631be56 100644 --- a/server/src/com/vaadin/terminal/DefaultRootProvider.java +++ b/server/src/com/vaadin/terminal/DefaultRootProvider.java @@ -17,14 +17,14 @@ package com.vaadin.terminal; import com.vaadin.Application; -import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.ui.UI; public class DefaultRootProvider extends AbstractRootProvider { @Override public Class getRootClass(Application application, - WrappedRequest request) throws RootRequiresMoreInformationException { + WrappedRequest request) throws UIRequiresMoreInformationException { Object rootClassNameObj = application .getProperty(Application.ROOT_PARAMETER); diff --git a/server/src/com/vaadin/terminal/RootProvider.java b/server/src/com/vaadin/terminal/RootProvider.java index 53173b6b94..229f2ca989 100644 --- a/server/src/com/vaadin/terminal/RootProvider.java +++ b/server/src/com/vaadin/terminal/RootProvider.java @@ -17,12 +17,12 @@ package com.vaadin.terminal; import com.vaadin.Application; -import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.ui.UI; public interface RootProvider { public Class getRootClass(Application application, - WrappedRequest request) throws RootRequiresMoreInformationException; + WrappedRequest request) throws UIRequiresMoreInformationException; public UI instantiateRoot(Application application, Class type, WrappedRequest request); diff --git a/server/src/com/vaadin/terminal/WrappedRequest.java b/server/src/com/vaadin/terminal/WrappedRequest.java index 1186d678b0..9ef98fcc41 100644 --- a/server/src/com/vaadin/terminal/WrappedRequest.java +++ b/server/src/com/vaadin/terminal/WrappedRequest.java @@ -27,7 +27,7 @@ import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import com.vaadin.Application; -import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.annotations.EagerInit; import com.vaadin.terminal.gwt.server.WebBrowser; import com.vaadin.ui.UI; @@ -220,7 +220,7 @@ public interface WrappedRequest extends Serializable { * * This information is only guaranteed to be available in some special * cases, for instance when {@link Application#getRoot} is called again - * after throwing {@link RootRequiresMoreInformationException} or in + * after throwing {@link UIRequiresMoreInformationException} or in * {@link UI#init(WrappedRequest)} for a UI class not annotated with * {@link EagerInit} * diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java b/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java index 2315a9c1d6..86668bd91f 100644 --- a/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java +++ b/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java @@ -56,7 +56,7 @@ import com.liferay.portal.kernel.util.PropsUtil; import com.vaadin.Application; import com.vaadin.Application.ApplicationStartEvent; import com.vaadin.Application.SystemMessages; -import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.terminal.DeploymentConfiguration; import com.vaadin.terminal.Terminal; import com.vaadin.terminal.WrappedRequest; @@ -500,7 +500,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet try { uI = application .getRootForRequest(wrappedRequest); - } catch (RootRequiresMoreInformationException e) { + } catch (UIRequiresMoreInformationException e) { // Ignore problem and continue without root } break; diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 39475f3131..48810d2b08 100644 --- a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -60,7 +60,7 @@ import javax.servlet.http.HttpServletResponse; import com.vaadin.Application; import com.vaadin.Application.SystemMessages; -import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.annotations.JavaScript; import com.vaadin.annotations.StyleSheet; import com.vaadin.external.json.JSONArray; @@ -2457,7 +2457,7 @@ public abstract class AbstractCommunicationManager implements Serializable { // NOTE GateIn requires the buffers to be flushed to work outWriter.flush(); out.flush(); - } catch (RootRequiresMoreInformationException e) { + } catch (UIRequiresMoreInformationException e) { // Requiring more information at this point is not allowed // TODO handle in a better way throw new RuntimeException(e); diff --git a/server/src/com/vaadin/terminal/gwt/server/BootstrapHandler.java b/server/src/com/vaadin/terminal/gwt/server/BootstrapHandler.java index b6953da35e..e52c11e2c2 100644 --- a/server/src/com/vaadin/terminal/gwt/server/BootstrapHandler.java +++ b/server/src/com/vaadin/terminal/gwt/server/BootstrapHandler.java @@ -37,7 +37,7 @@ import org.jsoup.nodes.Node; import org.jsoup.parser.Tag; import com.vaadin.Application; -import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.external.json.JSONException; import com.vaadin.external.json.JSONObject; import com.vaadin.shared.ApplicationConstants; @@ -134,7 +134,7 @@ public abstract class BootstrapHandler implements RequestHandler { } rootId = Integer.valueOf(uI.getRootId()); - } catch (RootRequiresMoreInformationException e) { + } catch (UIRequiresMoreInformationException e) { // Just keep going without rootId } diff --git a/server/src/com/vaadin/terminal/gwt/server/BootstrapResponse.java b/server/src/com/vaadin/terminal/gwt/server/BootstrapResponse.java index 4f69dda48b..b1a52cf79e 100644 --- a/server/src/com/vaadin/terminal/gwt/server/BootstrapResponse.java +++ b/server/src/com/vaadin/terminal/gwt/server/BootstrapResponse.java @@ -19,7 +19,7 @@ package com.vaadin.terminal.gwt.server; import java.util.EventObject; import com.vaadin.Application; -import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.terminal.WrappedRequest; import com.vaadin.ui.UI; @@ -110,7 +110,7 @@ public abstract class BootstrapResponse extends EventObject { * * @see Application#isRootPreserved() * @see Application#getRoot(WrappedRequest) - * @see RootRequiresMoreInformationException + * @see UIRequiresMoreInformationException * * @return The UI that will be displayed in the page being generated, or * null if all required information is not yet diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index 33eefff485..e2facefb33 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -36,8 +36,8 @@ import com.vaadin.shared.EventId; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.BorderStyle; import com.vaadin.shared.ui.root.RootConstants; -import com.vaadin.shared.ui.root.RootServerRpc; -import com.vaadin.shared.ui.root.RootState; +import com.vaadin.shared.ui.root.UIServerRpc; +import com.vaadin.shared.ui.root.UIState; import com.vaadin.terminal.Page; import com.vaadin.terminal.Page.BrowserWindowResizeEvent; import com.vaadin.terminal.Page.BrowserWindowResizeListener; @@ -429,7 +429,7 @@ public abstract class UI extends AbstractComponentContainer implements private Page page = new Page(this); - private RootServerRpc rpc = new RootServerRpc() { + private UIServerRpc rpc = new UIServerRpc() { @Override public void click(MouseEventDetails mouseDetails) { fireEvent(new ClickEvent(UI.this, mouseDetails)); @@ -498,15 +498,15 @@ public abstract class UI extends AbstractComponentContainer implements } @Override - protected RootState getState() { - return (RootState) super.getState(); + protected UIState getState() { + return (UIState) super.getState(); } @Override - public Class getStateType() { + public Class getStateType() { // This is a workaround for a problem with creating the correct state // object during build - return RootState.class; + return UIState.class; } /** diff --git a/shared/src/com/vaadin/shared/ui/root/RootServerRpc.java b/shared/src/com/vaadin/shared/ui/root/RootServerRpc.java deleted file mode 100644 index df2031f7d5..0000000000 --- a/shared/src/com/vaadin/shared/ui/root/RootServerRpc.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.shared.ui.root; - -import com.vaadin.shared.annotations.Delayed; -import com.vaadin.shared.communication.ServerRpc; -import com.vaadin.shared.ui.ClickRpc; - -public interface RootServerRpc extends ClickRpc, ServerRpc { - @Delayed(lastonly = true) - public void resize(int viewWidth, int viewHeight, int windowWidth, - int windowHeight); -} \ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/root/RootState.java b/shared/src/com/vaadin/shared/ui/root/RootState.java deleted file mode 100644 index b7c2c88ce5..0000000000 --- a/shared/src/com/vaadin/shared/ui/root/RootState.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.shared.ui.root; - -import com.vaadin.shared.ComponentState; -import com.vaadin.shared.Connector; - -public class RootState extends ComponentState { - private Connector content; - - public Connector getContent() { - return content; - } - - public void setContent(Connector content) { - this.content = content; - } - -} \ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/root/UIServerRpc.java b/shared/src/com/vaadin/shared/ui/root/UIServerRpc.java new file mode 100644 index 0000000000..20cdd48f54 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/root/UIServerRpc.java @@ -0,0 +1,26 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.shared.ui.root; + +import com.vaadin.shared.annotations.Delayed; +import com.vaadin.shared.communication.ServerRpc; +import com.vaadin.shared.ui.ClickRpc; + +public interface UIServerRpc extends ClickRpc, ServerRpc { + @Delayed(lastonly = true) + public void resize(int viewWidth, int viewHeight, int windowWidth, + int windowHeight); +} \ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/root/UIState.java b/shared/src/com/vaadin/shared/ui/root/UIState.java new file mode 100644 index 0000000000..f019d1ce67 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/root/UIState.java @@ -0,0 +1,32 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.shared.ui.root; + +import com.vaadin.shared.ComponentState; +import com.vaadin.shared.Connector; + +public class UIState extends ComponentState { + private Connector content; + + public Connector getContent() { + return content; + } + + public void setContent(Connector content) { + this.content = content; + } + +} \ No newline at end of file diff --git a/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java b/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java index 9fe486f85e..27d66ca0d0 100644 --- a/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java +++ b/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java @@ -10,7 +10,7 @@ import org.easymock.EasyMock; import com.vaadin.Application; import com.vaadin.Application.ApplicationStartEvent; -import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.terminal.DefaultRootProvider; import com.vaadin.terminal.DeploymentConfiguration; import com.vaadin.terminal.WrappedRequest; @@ -127,7 +127,7 @@ public class CustomRootClassLoader extends TestCase { @Override public UI getRootForRequest(WrappedRequest request) - throws RootRequiresMoreInformationException { + throws UIRequiresMoreInformationException { // Always create a new root for testing (can't directly use // getRoot as it's protected) return getRoot(request); diff --git a/tests/testbench/com/vaadin/launcher/ApplicationRunnerServlet.java b/tests/testbench/com/vaadin/launcher/ApplicationRunnerServlet.java index 2ac447cee3..43d4ad699e 100644 --- a/tests/testbench/com/vaadin/launcher/ApplicationRunnerServlet.java +++ b/tests/testbench/com/vaadin/launcher/ApplicationRunnerServlet.java @@ -30,7 +30,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.vaadin.Application; -import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.terminal.AbstractRootProvider; import com.vaadin.terminal.WrappedRequest; import com.vaadin.terminal.gwt.server.AbstractApplicationServlet; @@ -117,7 +117,7 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet { @Override public Class getRootClass( Application application, WrappedRequest request) - throws RootRequiresMoreInformationException { + throws UIRequiresMoreInformationException { return (Class) classToRun; } }); diff --git a/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java b/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java index 023a93438d..deff2bc486 100644 --- a/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java +++ b/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java @@ -1,7 +1,7 @@ package com.vaadin.tests.application; import com.vaadin.Application; -import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.terminal.AbstractRootProvider; import com.vaadin.terminal.WrappedRequest; import com.vaadin.tests.components.AbstractTestApplication; @@ -27,7 +27,7 @@ public class RefreshStatePreserve extends AbstractTestApplication { @Override public Class getRootClass(Application application, WrappedRequest request) - throws RootRequiresMoreInformationException { + throws UIRequiresMoreInformationException { return RefreshStateRoot.class; } }); diff --git a/tests/testbench/com/vaadin/tests/application/ThreadLocalInstances.java b/tests/testbench/com/vaadin/tests/application/ThreadLocalInstances.java index 3323e3bb28..96380b2185 100644 --- a/tests/testbench/com/vaadin/tests/application/ThreadLocalInstances.java +++ b/tests/testbench/com/vaadin/tests/application/ThreadLocalInstances.java @@ -1,7 +1,7 @@ package com.vaadin.tests.application; import com.vaadin.Application; -import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.terminal.ApplicationResource; import com.vaadin.terminal.DownloadStream; import com.vaadin.terminal.PaintException; @@ -78,7 +78,7 @@ public class ThreadLocalInstances extends AbstractTestApplication { @Override protected UI getRoot(WrappedRequest request) - throws RootRequiresMoreInformationException { + throws UIRequiresMoreInformationException { return mainWindow; } diff --git a/tests/testbench/com/vaadin/tests/components/root/LazyInitRoots.java b/tests/testbench/com/vaadin/tests/components/root/LazyInitRoots.java index aca7211aec..3c7862d298 100644 --- a/tests/testbench/com/vaadin/tests/components/root/LazyInitRoots.java +++ b/tests/testbench/com/vaadin/tests/components/root/LazyInitRoots.java @@ -1,6 +1,6 @@ package com.vaadin.tests.components.root; -import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.annotations.EagerInit; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.terminal.ExternalResource; @@ -23,13 +23,13 @@ public class LazyInitRoots extends AbstractTestApplication { @Override public UI getRoot(WrappedRequest request) - throws RootRequiresMoreInformationException { + throws UIRequiresMoreInformationException { if (request.getParameter("lazyCreate") != null) { // UI created on second request BrowserDetails browserDetails = request.getBrowserDetails(); if (browserDetails == null || browserDetails.getUriFragment() == null) { - throw new RootRequiresMoreInformationException(); + throw new UIRequiresMoreInformationException(); } else { UI uI = new UI() { @Override diff --git a/tests/testbench/com/vaadin/tests/components/root/RootsInMultipleTabs.java b/tests/testbench/com/vaadin/tests/components/root/RootsInMultipleTabs.java index 4309b6e942..13bef59fe9 100644 --- a/tests/testbench/com/vaadin/tests/components/root/RootsInMultipleTabs.java +++ b/tests/testbench/com/vaadin/tests/components/root/RootsInMultipleTabs.java @@ -1,7 +1,7 @@ package com.vaadin.tests.components.root; import com.vaadin.Application; -import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.terminal.AbstractRootProvider; import com.vaadin.terminal.WrappedRequest; import com.vaadin.tests.components.AbstractTestApplication; @@ -27,7 +27,7 @@ public class RootsInMultipleTabs extends AbstractTestApplication { @Override public Class getRootClass(Application application, WrappedRequest request) - throws RootRequiresMoreInformationException { + throws UIRequiresMoreInformationException { return TabRoot.class; } }); diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java index a601ff2eb4..6b25f4674d 100644 --- a/tests/testbench/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java +++ b/tests/testbench/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java @@ -17,7 +17,7 @@ package com.vaadin.tests.minitutorials.v7a1; import com.vaadin.Application; -import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.terminal.WrappedRequest; import com.vaadin.terminal.WrappedRequest.BrowserDetails; import com.vaadin.terminal.gwt.server.WebBrowser; @@ -36,12 +36,12 @@ public class DifferentFeaturesForDifferentClients extends Application { @Override protected UI getRoot(WrappedRequest request) - throws RootRequiresMoreInformationException { + throws UIRequiresMoreInformationException { BrowserDetails browserDetails = request.getBrowserDetails(); // This is a limitation of 7.0.0.alpha1 that there is no better way to // check if WebBrowser has been fully initialized if (browserDetails.getUriFragment() == null) { - throw new RootRequiresMoreInformationException(); + throw new UIRequiresMoreInformationException(); } // could also use screen size, browser version etc. -- cgit v1.2.3 From 5c557b50bc5f7f754d60a2ed435907b897b6750b Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 24 Aug 2012 11:47:50 +0300 Subject: Remaining Root -> UI renames (#8908) --- .../gwt/client/ApplicationConfiguration.java | 10 ++- .../terminal/gwt/client/ApplicationConnection.java | 5 +- .../terminal/gwt/client/ui/UI/UIConnector.java | 16 ++-- .../com/vaadin/terminal/gwt/client/ui/UI/VUI.java | 4 +- .../gwt/client/ui/notification/VNotification.java | 24 +++--- server/src/com/vaadin/Application.java | 5 +- .../vaadin/UIRequiresMoreInformationException.java | 2 +- .../com/vaadin/terminal/AbstractRootProvider.java | 35 --------- .../com/vaadin/terminal/AbstractUIProvider.java | 35 +++++++++ .../com/vaadin/terminal/DefaultRootProvider.java | 51 ------------- .../src/com/vaadin/terminal/DefaultUIProvider.java | 51 +++++++++++++ server/src/com/vaadin/terminal/Page.java | 26 +++---- server/src/com/vaadin/terminal/WrappedRequest.java | 5 +- .../gwt/server/AbstractApplicationPortlet.java | 16 ++-- .../gwt/server/AbstractApplicationServlet.java | 4 +- .../gwt/server/AbstractCommunicationManager.java | 88 +++++++++++----------- .../terminal/gwt/server/ApplicationServlet.java | 4 +- .../gwt/server/BootstrapFragmentResponse.java | 9 +-- .../terminal/gwt/server/BootstrapHandler.java | 57 +++++++------- .../terminal/gwt/server/BootstrapPageResponse.java | 6 +- .../terminal/gwt/server/BootstrapResponse.java | 25 +++--- .../terminal/gwt/server/ClientConnector.java | 2 +- .../com/vaadin/terminal/gwt/server/Constants.java | 2 +- .../gwt/server/PortletApplicationContext2.java | 2 +- .../terminal/gwt/server/ServletPortletHelper.java | 18 ++--- server/src/com/vaadin/ui/AbstractComponent.java | 12 +-- server/src/com/vaadin/ui/ConnectorTracker.java | 6 +- server/src/com/vaadin/ui/UI.java | 18 ++--- server/src/com/vaadin/ui/Window.java | 8 +- .../com/vaadin/shared/ApplicationConstants.java | 4 - .../com/vaadin/shared/ui/root/PageClientRpc.java | 25 ------ .../com/vaadin/shared/ui/root/RootConstants.java | 44 ----------- .../src/com/vaadin/shared/ui/root/UIServerRpc.java | 26 ------- shared/src/com/vaadin/shared/ui/root/UIState.java | 32 -------- .../src/com/vaadin/shared/ui/ui/PageClientRpc.java | 25 ++++++ .../src/com/vaadin/shared/ui/ui/UIConstants.java | 49 ++++++++++++ .../src/com/vaadin/shared/ui/ui/UIServerRpc.java | 26 +++++++ shared/src/com/vaadin/shared/ui/ui/UIState.java | 32 ++++++++ .../component/root/CustomRootClassLoader.java | 4 +- .../vaadin/launcher/ApplicationRunnerServlet.java | 4 +- .../tests/application/RefreshStatePreserve.java | 4 +- .../tests/components/root/RootsInMultipleTabs.java | 4 +- .../vaadincontext/TestAddonContextListener.java | 2 +- 43 files changed, 408 insertions(+), 419 deletions(-) delete mode 100644 server/src/com/vaadin/terminal/AbstractRootProvider.java create mode 100644 server/src/com/vaadin/terminal/AbstractUIProvider.java delete mode 100644 server/src/com/vaadin/terminal/DefaultRootProvider.java create mode 100644 server/src/com/vaadin/terminal/DefaultUIProvider.java delete mode 100644 shared/src/com/vaadin/shared/ui/root/PageClientRpc.java delete mode 100644 shared/src/com/vaadin/shared/ui/root/RootConstants.java delete mode 100644 shared/src/com/vaadin/shared/ui/root/UIServerRpc.java delete mode 100644 shared/src/com/vaadin/shared/ui/root/UIState.java create mode 100644 shared/src/com/vaadin/shared/ui/ui/PageClientRpc.java create mode 100644 shared/src/com/vaadin/shared/ui/ui/UIConstants.java create mode 100644 shared/src/com/vaadin/shared/ui/ui/UIServerRpc.java create mode 100644 shared/src/com/vaadin/shared/ui/ui/UIState.java (limited to 'shared') diff --git a/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java b/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java index aa7a9fc72a..6621de7f95 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java +++ b/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java @@ -31,6 +31,7 @@ import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Window; import com.vaadin.shared.ApplicationConstants; +import com.vaadin.shared.ui.ui.UIConstants; import com.vaadin.terminal.gwt.client.metadata.BundleLoadCallback; import com.vaadin.terminal.gwt.client.metadata.ConnectorBundleLoader; import com.vaadin.terminal.gwt.client.metadata.NoDataException; @@ -202,7 +203,7 @@ public class ApplicationConfiguration implements EntryPoint { private String id; private String themeUri; private String appUri; - private int rootId; + private int uiId; private boolean standalone; private ErrorMessage communicationError; private ErrorMessage authorizationError; @@ -288,8 +289,8 @@ public class ApplicationConfiguration implements EntryPoint { * * @return the root id */ - public int getRootId() { - return rootId; + public int getUIId() { + return uiId; } public JavaScriptObject getVersionInfoJSObject() { @@ -314,7 +315,8 @@ public class ApplicationConfiguration implements EntryPoint { appUri += '/'; } themeUri = jsoConfiguration.getConfigString("themeUri"); - rootId = jsoConfiguration.getConfigInteger("rootId").intValue(); + uiId = jsoConfiguration.getConfigInteger(UIConstants.UI_ID_PARAMETER) + .intValue(); // null -> true useDebugIdInDom = jsoConfiguration.getConfigBoolean("useDebugIdInDom") != Boolean.FALSE; diff --git a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 44f52d3e7f..fc063a1908 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -58,6 +58,7 @@ import com.vaadin.shared.Version; import com.vaadin.shared.communication.LegacyChangeVariablesInvocation; import com.vaadin.shared.communication.MethodInvocation; import com.vaadin.shared.communication.SharedState; +import com.vaadin.shared.ui.ui.UIConstants; import com.vaadin.terminal.gwt.client.ApplicationConfiguration.ErrorMessage; import com.vaadin.terminal.gwt.client.ResourceLoader.ResourceLoadEvent; import com.vaadin.terminal.gwt.client.ResourceLoader.ResourceLoadListener; @@ -495,8 +496,8 @@ public class ApplicationConnection { if (extraParams != null && extraParams.length() > 0) { uri = addGetParameters(uri, extraParams); } - uri = addGetParameters(uri, ApplicationConstants.ROOT_ID_PARAMETER - + "=" + configuration.getRootId()); + uri = addGetParameters(uri, UIConstants.UI_ID_PARAMETER + "=" + + configuration.getUIId()); doUidlRequest(uri, payload, forceSync); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/UI/UIConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/UI/UIConnector.java index 2fb48623fd..f260481c3c 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/UI/UIConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/UI/UIConnector.java @@ -36,10 +36,10 @@ import com.google.web.bindery.event.shared.HandlerRegistration; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.Connect.LoadStyle; -import com.vaadin.shared.ui.root.PageClientRpc; -import com.vaadin.shared.ui.root.RootConstants; -import com.vaadin.shared.ui.root.UIServerRpc; -import com.vaadin.shared.ui.root.UIState; +import com.vaadin.shared.ui.ui.PageClientRpc; +import com.vaadin.shared.ui.ui.UIConstants; +import com.vaadin.shared.ui.ui.UIServerRpc; +import com.vaadin.shared.ui.ui.UIState; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.ComponentConnector; @@ -107,7 +107,7 @@ public class UIConnector extends AbstractComponentContainerConnector getWidget().connection = client; getWidget().immediate = getState().isImmediate(); - getWidget().resizeLazy = uidl.hasAttribute(RootConstants.RESIZE_LAZY); + getWidget().resizeLazy = uidl.hasAttribute(UIConstants.RESIZE_LAZY); String newTheme = uidl.getStringAttribute("theme"); if (getWidget().theme != null && !newTheme.equals(getWidget().theme)) { // Complete page refresh is needed due css can affect layout @@ -263,9 +263,9 @@ public class UIConnector extends AbstractComponentContainerConnector scrollIntoView(connector); } - if (uidl.hasAttribute(RootConstants.FRAGMENT_VARIABLE)) { + if (uidl.hasAttribute(UIConstants.FRAGMENT_VARIABLE)) { getWidget().currentFragment = uidl - .getStringAttribute(RootConstants.FRAGMENT_VARIABLE); + .getStringAttribute(UIConstants.FRAGMENT_VARIABLE); if (!getWidget().currentFragment.equals(History.getToken())) { History.newItem(getWidget().currentFragment, true); } @@ -276,7 +276,7 @@ public class UIConnector extends AbstractComponentContainerConnector // Include current fragment in the next request client.updateVariable(getWidget().id, - RootConstants.FRAGMENT_VARIABLE, + UIConstants.FRAGMENT_VARIABLE, getWidget().currentFragment, false); } diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/UI/VUI.java b/client/src/com/vaadin/terminal/gwt/client/ui/UI/VUI.java index cb6b181f1d..1c4b69a3b9 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/UI/VUI.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/UI/VUI.java @@ -33,7 +33,7 @@ import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.SimplePanel; import com.vaadin.shared.ApplicationConstants; -import com.vaadin.shared.ui.root.RootConstants; +import com.vaadin.shared.ui.ui.UIConstants; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.ComponentConnector; @@ -130,7 +130,7 @@ public class VUI extends SimplePanel implements ResizeHandler, // Send the new fragment to the server if it has changed if (!newFragment.equals(currentFragment) && connection != null) { currentFragment = newFragment; - connection.updateVariable(id, RootConstants.FRAGMENT_VARIABLE, + connection.updateVariable(id, UIConstants.FRAGMENT_VARIABLE, newFragment, true); } } diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/notification/VNotification.java b/client/src/com/vaadin/terminal/gwt/client/ui/notification/VNotification.java index b4cea2dc72..b668c9a88c 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/notification/VNotification.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/notification/VNotification.java @@ -30,7 +30,7 @@ import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.Position; -import com.vaadin.shared.ui.root.RootConstants; +import com.vaadin.shared.ui.ui.UIConstants; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.UIDL; @@ -384,19 +384,19 @@ public class VNotification extends VOverlay { public static void showNotification(ApplicationConnection client, final UIDL notification) { boolean onlyPlainText = notification - .hasAttribute(RootConstants.NOTIFICATION_HTML_CONTENT_NOT_ALLOWED); + .hasAttribute(UIConstants.NOTIFICATION_HTML_CONTENT_NOT_ALLOWED); String html = ""; if (notification - .hasAttribute(RootConstants.ATTRIBUTE_NOTIFICATION_ICON)) { + .hasAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_ICON)) { final String parsedUri = client .translateVaadinUri(notification - .getStringAttribute(RootConstants.ATTRIBUTE_NOTIFICATION_ICON)); + .getStringAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_ICON)); html += ""; } if (notification - .hasAttribute(RootConstants.ATTRIBUTE_NOTIFICATION_CAPTION)) { + .hasAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_CAPTION)) { String caption = notification - .getStringAttribute(RootConstants.ATTRIBUTE_NOTIFICATION_CAPTION); + .getStringAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_CAPTION); if (onlyPlainText) { caption = Util.escapeHTML(caption); caption = caption.replaceAll("\\n", "
"); @@ -404,9 +404,9 @@ public class VNotification extends VOverlay { html += "

" + caption + "

"; } if (notification - .hasAttribute(RootConstants.ATTRIBUTE_NOTIFICATION_MESSAGE)) { + .hasAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_MESSAGE)) { String message = notification - .getStringAttribute(RootConstants.ATTRIBUTE_NOTIFICATION_MESSAGE); + .getStringAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_MESSAGE); if (onlyPlainText) { message = Util.escapeHTML(message); message = message.replaceAll("\\n", "
"); @@ -415,16 +415,16 @@ public class VNotification extends VOverlay { } final String style = notification - .hasAttribute(RootConstants.ATTRIBUTE_NOTIFICATION_STYLE) ? notification - .getStringAttribute(RootConstants.ATTRIBUTE_NOTIFICATION_STYLE) + .hasAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_STYLE) ? notification + .getStringAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_STYLE) : null; final int pos = notification - .getIntAttribute(RootConstants.ATTRIBUTE_NOTIFICATION_POSITION); + .getIntAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_POSITION); Position position = Position.values()[pos]; final int delay = notification - .getIntAttribute(RootConstants.ATTRIBUTE_NOTIFICATION_DELAY); + .getIntAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_DELAY); createNotification(delay).show(html, position, style); } diff --git a/server/src/com/vaadin/Application.java b/server/src/com/vaadin/Application.java index 1827a55b72..96d38e31cf 100644 --- a/server/src/com/vaadin/Application.java +++ b/server/src/com/vaadin/Application.java @@ -51,7 +51,7 @@ import com.vaadin.data.util.converter.ConverterFactory; import com.vaadin.data.util.converter.DefaultConverterFactory; import com.vaadin.event.EventRouter; import com.vaadin.service.ApplicationContext; -import com.vaadin.shared.ApplicationConstants; +import com.vaadin.shared.ui.ui.UIConstants; import com.vaadin.terminal.AbstractErrorMessage; import com.vaadin.terminal.ApplicationResource; import com.vaadin.terminal.CombinedRequest; @@ -2264,8 +2264,7 @@ public class Application implements Terminal.ErrorListener, Serializable { CombinedRequest combinedRequest = (CombinedRequest) request; request = combinedRequest.getSecondRequest(); } - String uiIdString = request - .getParameter(ApplicationConstants.ROOT_ID_PARAMETER); + String uiIdString = request.getParameter(UIConstants.UI_ID_PARAMETER); Integer uiId = uiIdString == null ? null : new Integer(uiIdString); return uiId; } diff --git a/server/src/com/vaadin/UIRequiresMoreInformationException.java b/server/src/com/vaadin/UIRequiresMoreInformationException.java index 0d491895e5..493c31acb6 100644 --- a/server/src/com/vaadin/UIRequiresMoreInformationException.java +++ b/server/src/com/vaadin/UIRequiresMoreInformationException.java @@ -20,7 +20,7 @@ import com.vaadin.terminal.WrappedRequest; import com.vaadin.terminal.WrappedRequest.BrowserDetails; /** - * Exception that is thrown to indicate that creating or initializing the root + * Exception that is thrown to indicate that creating or initializing the UI * requires information detailed from the web browser ({@link BrowserDetails}) * to be present. * diff --git a/server/src/com/vaadin/terminal/AbstractRootProvider.java b/server/src/com/vaadin/terminal/AbstractRootProvider.java deleted file mode 100644 index f316a58f15..0000000000 --- a/server/src/com/vaadin/terminal/AbstractRootProvider.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.vaadin.terminal; - -import com.vaadin.Application; -import com.vaadin.ui.UI; - -public abstract class AbstractRootProvider implements UIProvider { - - @Override - public UI instantiateUI(Application application, - Class type, WrappedRequest request) { - try { - return type.newInstance(); - } catch (InstantiationException e) { - throw new RuntimeException("Could not instantiate root class", e); - } catch (IllegalAccessException e) { - throw new RuntimeException("Could not access root class", e); - } - } -} diff --git a/server/src/com/vaadin/terminal/AbstractUIProvider.java b/server/src/com/vaadin/terminal/AbstractUIProvider.java new file mode 100644 index 0000000000..5bb4d35b30 --- /dev/null +++ b/server/src/com/vaadin/terminal/AbstractUIProvider.java @@ -0,0 +1,35 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.terminal; + +import com.vaadin.Application; +import com.vaadin.ui.UI; + +public abstract class AbstractUIProvider implements UIProvider { + + @Override + public UI instantiateUI(Application application, + Class type, WrappedRequest request) { + try { + return type.newInstance(); + } catch (InstantiationException e) { + throw new RuntimeException("Could not instantiate root class", e); + } catch (IllegalAccessException e) { + throw new RuntimeException("Could not access root class", e); + } + } +} diff --git a/server/src/com/vaadin/terminal/DefaultRootProvider.java b/server/src/com/vaadin/terminal/DefaultRootProvider.java deleted file mode 100644 index b201be513d..0000000000 --- a/server/src/com/vaadin/terminal/DefaultRootProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.vaadin.terminal; - -import com.vaadin.Application; -import com.vaadin.UIRequiresMoreInformationException; -import com.vaadin.ui.UI; - -public class DefaultRootProvider extends AbstractRootProvider { - - @Override - public Class getUIClass(Application application, - WrappedRequest request) throws UIRequiresMoreInformationException { - Object rootClassNameObj = application - .getProperty(Application.UI_PARAMETER); - - if (rootClassNameObj instanceof String) { - String rootClassName = rootClassNameObj.toString(); - - ClassLoader classLoader = request.getDeploymentConfiguration() - .getClassLoader(); - if (classLoader == null) { - classLoader = getClass().getClassLoader(); - } - try { - Class rootClass = Class.forName(rootClassName, - true, classLoader).asSubclass(UI.class); - - return rootClass; - } catch (ClassNotFoundException e) { - throw new RuntimeException("Could not find root class", e); - } - } - - return null; - } -} diff --git a/server/src/com/vaadin/terminal/DefaultUIProvider.java b/server/src/com/vaadin/terminal/DefaultUIProvider.java new file mode 100644 index 0000000000..8713c45b31 --- /dev/null +++ b/server/src/com/vaadin/terminal/DefaultUIProvider.java @@ -0,0 +1,51 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.terminal; + +import com.vaadin.Application; +import com.vaadin.UIRequiresMoreInformationException; +import com.vaadin.ui.UI; + +public class DefaultUIProvider extends AbstractUIProvider { + + @Override + public Class getUIClass(Application application, + WrappedRequest request) throws UIRequiresMoreInformationException { + Object uiClassNameObj = application + .getProperty(Application.UI_PARAMETER); + + if (uiClassNameObj instanceof String) { + String uiClassName = uiClassNameObj.toString(); + + ClassLoader classLoader = request.getDeploymentConfiguration() + .getClassLoader(); + if (classLoader == null) { + classLoader = getClass().getClassLoader(); + } + try { + Class uiClass = Class.forName(uiClassName, true, + classLoader).asSubclass(UI.class); + + return uiClass; + } catch (ClassNotFoundException e) { + throw new RuntimeException("Could not find UI class", e); + } + } + + return null; + } +} diff --git a/server/src/com/vaadin/terminal/Page.java b/server/src/com/vaadin/terminal/Page.java index 95f9a7b3ec..66ef7da296 100644 --- a/server/src/com/vaadin/terminal/Page.java +++ b/server/src/com/vaadin/terminal/Page.java @@ -25,8 +25,8 @@ import java.util.List; import com.vaadin.event.EventRouter; import com.vaadin.shared.ui.BorderStyle; -import com.vaadin.shared.ui.root.PageClientRpc; -import com.vaadin.shared.ui.root.RootConstants; +import com.vaadin.shared.ui.ui.PageClientRpc; +import com.vaadin.shared.ui.ui.UIConstants; import com.vaadin.terminal.WrappedRequest.BrowserDetails; import com.vaadin.terminal.gwt.server.WebApplicationContext; import com.vaadin.terminal.gwt.server.WebBrowser; @@ -474,32 +474,32 @@ public class Page implements Serializable { target.startTag("notification"); if (n.getCaption() != null) { target.addAttribute( - RootConstants.ATTRIBUTE_NOTIFICATION_CAPTION, + UIConstants.ATTRIBUTE_NOTIFICATION_CAPTION, n.getCaption()); } if (n.getDescription() != null) { target.addAttribute( - RootConstants.ATTRIBUTE_NOTIFICATION_MESSAGE, + UIConstants.ATTRIBUTE_NOTIFICATION_MESSAGE, n.getDescription()); } if (n.getIcon() != null) { target.addAttribute( - RootConstants.ATTRIBUTE_NOTIFICATION_ICON, + UIConstants.ATTRIBUTE_NOTIFICATION_ICON, n.getIcon()); } if (!n.isHtmlContentAllowed()) { target.addAttribute( - RootConstants.NOTIFICATION_HTML_CONTENT_NOT_ALLOWED, + UIConstants.NOTIFICATION_HTML_CONTENT_NOT_ALLOWED, true); } target.addAttribute( - RootConstants.ATTRIBUTE_NOTIFICATION_POSITION, n + UIConstants.ATTRIBUTE_NOTIFICATION_POSITION, n .getPosition().ordinal()); - target.addAttribute(RootConstants.ATTRIBUTE_NOTIFICATION_DELAY, + target.addAttribute(UIConstants.ATTRIBUTE_NOTIFICATION_DELAY, n.getDelayMsec()); if (n.getStyleName() != null) { target.addAttribute( - RootConstants.ATTRIBUTE_NOTIFICATION_STYLE, + UIConstants.ATTRIBUTE_NOTIFICATION_STYLE, n.getStyleName()); } target.endTag("notification"); @@ -509,7 +509,7 @@ public class Page implements Serializable { } if (fragment != null) { - target.addAttribute(RootConstants.FRAGMENT_VARIABLE, fragment); + target.addAttribute(UIConstants.FRAGMENT_VARIABLE, fragment); } } @@ -632,11 +632,11 @@ public class Page implements Serializable { * null */ public static Page getCurrent() { - UI currentRoot = UI.getCurrent(); - if (currentRoot == null) { + UI currentUI = UI.getCurrent(); + if (currentUI == null) { return null; } - return currentRoot.getPage(); + return currentUI.getPage(); } /** diff --git a/server/src/com/vaadin/terminal/WrappedRequest.java b/server/src/com/vaadin/terminal/WrappedRequest.java index 9ef98fcc41..343a60848e 100644 --- a/server/src/com/vaadin/terminal/WrappedRequest.java +++ b/server/src/com/vaadin/terminal/WrappedRequest.java @@ -219,8 +219,9 @@ public interface WrappedRequest extends Serializable { * for instance using javascript in the browser. * * This information is only guaranteed to be available in some special - * cases, for instance when {@link Application#getRoot} is called again - * after throwing {@link UIRequiresMoreInformationException} or in + * cases, for instance when + * {@link Application#getUIForRequest(WrappedRequest)} is called again after + * throwing {@link UIRequiresMoreInformationException} or in * {@link UI#init(WrappedRequest)} for a UI class not annotated with * {@link EagerInit} * diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java b/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java index 7a69a4c2b0..a9e6028090 100644 --- a/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java +++ b/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java @@ -501,23 +501,22 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet uI = application .getUIForRequest(wrappedRequest); } catch (UIRequiresMoreInformationException e) { - // Ignore problem and continue without root + // Ignore problem and continue without UI } break; case BROWSER_DETAILS: - // Should not try to find a root here as the - // combined request details might change the root + // Should not try to find a UI here as the + // combined request details might change the UI break; case FILE_UPLOAD: // no window break; case APPLICATION_RESOURCE: // use main window - should not need any window - // root = application.getRoot(); + // UI = application.getUI(); break; default: - uI = application - .getUIForRequest(wrappedRequest); + uI = application.getUIForRequest(wrappedRequest); } // if window not found, not a problem - use null } @@ -534,9 +533,8 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet uI, (ActionRequest) request, (ActionResponse) response); } else if (request instanceof EventRequest) { - applicationContext.firePortletEventRequest(application, - uI, (EventRequest) request, - (EventResponse) response); + applicationContext.firePortletEventRequest(application, uI, + (EventRequest) request, (EventResponse) response); } else if (request instanceof ResourceRequest) { applicationContext.firePortletResourceRequest(application, uI, (ResourceRequest) request, diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java index b71c6ec20c..6cf9b76b0d 100644 --- a/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java +++ b/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java @@ -321,14 +321,14 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements } else if (requestType == RequestType.UIDL) { UI uI = application.getUIForRequest(request); if (uI == null) { - throw new ServletException(ERROR_NO_ROOT_FOUND); + throw new ServletException(ERROR_NO_UI_FOUND); } // Handles AJAX UIDL requests applicationManager.handleUidlRequest(request, response, servletWrapper, uI); return; } else if (requestType == RequestType.BROWSER_DETAILS) { - // Browser details - not related to a specific root + // Browser details - not related to a specific UI applicationManager.handleBrowserDetailsRequest(request, response, application); return; diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index e19cfc4de6..87eadd5df7 100644 --- a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -74,6 +74,7 @@ import com.vaadin.shared.communication.LegacyChangeVariablesInvocation; import com.vaadin.shared.communication.MethodInvocation; import com.vaadin.shared.communication.SharedState; import com.vaadin.shared.communication.UidlValue; +import com.vaadin.shared.ui.ui.UIConstants; import com.vaadin.terminal.AbstractClientConnector; import com.vaadin.terminal.CombinedRequest; import com.vaadin.terminal.LegacyPaint; @@ -146,7 +147,7 @@ public abstract class AbstractCommunicationManager implements Serializable { public static final char VAR_ESCAPE_CHARACTER = '\u001b'; - private final HashMap rootToClientCache = new HashMap(); + private final HashMap uiToClientCache = new HashMap(); private static final int MAX_BUFFER_SIZE = 64 * 1024; @@ -570,7 +571,7 @@ public abstract class AbstractCommunicationManager implements Serializable { if (uI == null) { // This should not happen, no windows exists but // application is still open. - getLogger().warning("Could not get root for application"); + getLogger().warning("Could not get UI for application"); return; } } else { @@ -810,17 +811,17 @@ public abstract class AbstractCommunicationManager implements Serializable { @SuppressWarnings("unchecked") public void writeUidlResponse(WrappedRequest request, boolean repaintAll, - final PrintWriter outWriter, UI uI, boolean analyzeLayouts) + final PrintWriter outWriter, UI ui, boolean analyzeLayouts) throws PaintException, JSONException { ArrayList dirtyVisibleConnectors = new ArrayList(); - Application application = uI.getApplication(); + Application application = ui.getApplication(); // Paints components - ConnectorTracker rootConnectorTracker = uI.getConnectorTracker(); + ConnectorTracker uiConnectorTracker = ui.getConnectorTracker(); getLogger().log(Level.FINE, "* Creating response to client"); if (repaintAll) { - getClientCache(uI).clear(); - rootConnectorTracker.markAllConnectorsDirty(); - rootConnectorTracker.markAllClientSidesUninitialized(); + getClientCache(ui).clear(); + uiConnectorTracker.markAllConnectorsDirty(); + uiConnectorTracker.markAllClientSidesUninitialized(); // Reset sent locales locales = null; @@ -828,18 +829,18 @@ public abstract class AbstractCommunicationManager implements Serializable { } dirtyVisibleConnectors - .addAll(getDirtyVisibleConnectors(rootConnectorTracker)); + .addAll(getDirtyVisibleConnectors(uiConnectorTracker)); getLogger().log( Level.FINE, "Found " + dirtyVisibleConnectors.size() + " dirty connectors to paint"); for (ClientConnector connector : dirtyVisibleConnectors) { - boolean initialized = rootConnectorTracker + boolean initialized = uiConnectorTracker .isClientSideInitialized(connector); connector.beforeClientResponse(!initialized); } - rootConnectorTracker.markAllConnectorsClean(); + uiConnectorTracker.markAllConnectorsClean(); outWriter.print("\"changes\":["); @@ -851,12 +852,11 @@ public abstract class AbstractCommunicationManager implements Serializable { if (analyzeLayouts) { invalidComponentRelativeSizes = ComponentSizeValidator - .validateComponentRelativeSizes(uI.getContent(), null, - null); + .validateComponentRelativeSizes(ui.getContent(), null, null); // Also check any existing subwindows - if (uI.getWindows() != null) { - for (Window subWindow : uI.getWindows()) { + if (ui.getWindows() != null) { + for (Window subWindow : ui.getWindows()) { invalidComponentRelativeSizes = ComponentSizeValidator .validateComponentRelativeSizes( subWindow.getContent(), @@ -951,10 +951,10 @@ public abstract class AbstractCommunicationManager implements Serializable { outWriter.append(hierarchyInfo.toString()); outWriter.print(", "); // close hierarchy - // send server to client RPC calls for components in the root, in call + // send server to client RPC calls for components in the UI, in call // order - // collect RPC calls from components in the root in the order in + // collect RPC calls from components in the UI in the order in // which they were performed, remove the calls from components LinkedList rpcPendingQueue = new LinkedList( @@ -985,7 +985,7 @@ public abstract class AbstractCommunicationManager implements Serializable { // } paramJson.put(JsonCodec.encode( invocation.getParameters()[i], referenceParameter, - parameterType, uI.getConnectorTracker())); + parameterType, ui.getConnectorTracker())); } invocationJson.put(paramJson); rpcCalls.put(invocationJson); @@ -1087,7 +1087,7 @@ public abstract class AbstractCommunicationManager implements Serializable { final String resource = (String) i.next(); InputStream is = null; try { - is = getThemeResourceAsStream(uI, getTheme(uI), resource); + is = getThemeResourceAsStream(ui, getTheme(ui), resource); } catch (final Exception e) { // FIXME: Handle exception getLogger().log(Level.FINER, @@ -1124,7 +1124,7 @@ public abstract class AbstractCommunicationManager implements Serializable { Collection> usedClientConnectors = paintTarget .getUsedClientConnectors(); boolean typeMappingsOpen = false; - ClientCache clientCache = getClientCache(uI); + ClientCache clientCache = getClientCache(ui); List> newConnectorTypes = new ArrayList>(); @@ -1237,7 +1237,7 @@ public abstract class AbstractCommunicationManager implements Serializable { } for (ClientConnector connector : dirtyVisibleConnectors) { - rootConnectorTracker.markClientSideInitialized(connector); + uiConnectorTracker.markClientSideInitialized(connector); } writePerformanceData(outWriter); @@ -1390,11 +1390,11 @@ public abstract class AbstractCommunicationManager implements Serializable { } private ClientCache getClientCache(UI uI) { - Integer rootId = Integer.valueOf(uI.getUIId()); - ClientCache cache = rootToClientCache.get(rootId); + Integer uiId = Integer.valueOf(uI.getUIId()); + ClientCache cache = uiToClientCache.get(uiId); if (cache == null) { cache = new ClientCache(); - rootToClientCache.put(rootId, cache); + uiToClientCache.put(uiId, cache); } return cache; } @@ -1633,14 +1633,13 @@ public abstract class AbstractCommunicationManager implements Serializable { * * @param source * @param uI - * the root receiving the burst + * the UI receiving the burst * @param burst * the content of the burst as a String to be parsed * @return true if the processing of the burst was successful and there were * no messages to non-existent components */ - public boolean handleBurst(WrappedRequest source, UI uI, - final String burst) { + public boolean handleBurst(WrappedRequest source, UI uI, final String burst) { boolean success = true; try { Set enabledConnectors = new HashSet(); @@ -1878,8 +1877,7 @@ public abstract class AbstractCommunicationManager implements Serializable { } protected ClientConnector getConnector(UI uI, String connectorId) { - ClientConnector c = uI.getConnectorTracker() - .getConnector(connectorId); + ClientConnector c = uI.getConnectorTracker().getConnector(connectorId); if (c == null && connectorId.equals(getDragAndDropService().getConnectorId())) { return getDragAndDropService(); @@ -2231,7 +2229,7 @@ public abstract class AbstractCommunicationManager implements Serializable { * invisible subtrees are omitted. * * @param w - * root window for which dirty components is to be fetched + * UI window for which dirty components is to be fetched * @return */ private ArrayList getDirtyVisibleConnectors( @@ -2344,7 +2342,7 @@ public abstract class AbstractCommunicationManager implements Serializable { * We will use the same APP/* URI space as ApplicationResources but * prefix url with UPLOAD * - * eg. APP/UPLOAD/[ROOTID]/[PID]/[NAME]/[SECKEY] + * eg. APP/UPLOAD/[UIID]/[PID]/[NAME]/[SECKEY] * * SECKEY is created on each paint to make URL's unpredictable (to * prevent CSRF attacks). @@ -2353,8 +2351,8 @@ public abstract class AbstractCommunicationManager implements Serializable { * handling post */ String paintableId = owner.getConnectorId(); - int rootId = owner.getUI().getUIId(); - String key = rootId + "/" + paintableId + "/" + name; + int uiId = owner.getUI().getUIId(); + String key = uiId + "/" + paintableId + "/" + name; if (pidToNameToStreamVariable == null) { pidToNameToStreamVariable = new HashMap>(); @@ -2415,7 +2413,7 @@ public abstract class AbstractCommunicationManager implements Serializable { WrappedResponse response, Application application) throws IOException { - // if we do not yet have a currentRoot, it should be initialized + // if we do not yet have a currentUI, it should be initialized // shortly, and we should send the initial UIDL boolean sendUIDL = UI.getCurrent() == null; @@ -2425,7 +2423,7 @@ public abstract class AbstractCommunicationManager implements Serializable { UI uI = application.getUIForRequest(combinedRequest); response.setContentType("application/json; charset=UTF-8"); - // Use the same logic as for determined roots + // Use the same logic as for determined UIs BootstrapHandler bootstrapHandler = getBootstrapHandler(); BootstrapContext context = bootstrapHandler.createContext( combinedRequest, response, application, uI.getUIId()); @@ -2434,13 +2432,13 @@ public abstract class AbstractCommunicationManager implements Serializable { String theme = context.getThemeName(); String themeUri = bootstrapHandler.getThemeUri(context, theme); - // TODO These are not required if it was only the init of the root + // TODO These are not required if it was only the init of the UI // that was delayed JSONObject params = new JSONObject(); params.put("widgetset", widgetset); params.put("themeUri", themeUri); // UI id might have changed based on e.g. window.name - params.put(ApplicationConstants.ROOT_ID_PARAMETER, uI.getUIId()); + params.put(UIConstants.UI_ID_PARAMETER, uI.getUIId()); if (sendUIDL) { String initialUIDL = getInitialUIDL(combinedRequest, uI); params.put("uidl", initialUIDL); @@ -2474,7 +2472,7 @@ public abstract class AbstractCommunicationManager implements Serializable { * @param request * the request that caused the initialization * @param uI - * the root for which the UIDL should be generated + * the UI for which the UIDL should be generated * @return a string with the initial UIDL message * @throws PaintException * if an exception occurs while painting @@ -2523,7 +2521,7 @@ public abstract class AbstractCommunicationManager implements Serializable { final String mimetype = response.getDeploymentConfiguration() .getMimeType(resourceName); - // Security check: avoid accidentally serving from the root of the + // Security check: avoid accidentally serving from the UI of the // classpath instead of relative to the context class if (resourceName.startsWith("/")) { getLogger().warning( @@ -2598,8 +2596,8 @@ public abstract class AbstractCommunicationManager implements Serializable { /** * Handles file upload request submitted via Upload component. * - * @param root - * The root for this request + * @param UI + * The UI for this request * * @see #getStreamVariableTargetUrl(ReceiverOwner, String, StreamVariable) * @@ -2613,7 +2611,7 @@ public abstract class AbstractCommunicationManager implements Serializable { throws IOException, InvalidUIDLSecurityKeyException { /* - * URI pattern: APP/UPLOAD/[ROOTID]/[PID]/[NAME]/[SECKEY] See + * URI pattern: APP/UPLOAD/[UIID]/[PID]/[NAME]/[SECKEY] See * #createReceiverUrl */ @@ -2623,12 +2621,12 @@ public abstract class AbstractCommunicationManager implements Serializable { .indexOf(ServletPortletHelper.UPLOAD_URL_PREFIX) + ServletPortletHelper.UPLOAD_URL_PREFIX.length(); String uppUri = pathInfo.substring(startOfData); - String[] parts = uppUri.split("/", 4); // 0= rootid, 1 = cid, 2= name, 3 + String[] parts = uppUri.split("/", 4); // 0= UIid, 1 = cid, 2= name, 3 // = sec key - String rootId = parts[0]; + String uiId = parts[0]; String connectorId = parts[1]; String variableName = parts[2]; - UI uI = application.getUIById(Integer.parseInt(rootId)); + UI uI = application.getUIById(Integer.parseInt(uiId)); UI.setCurrent(uI); StreamVariable streamVariable = getStreamVariable(connectorId, diff --git a/server/src/com/vaadin/terminal/gwt/server/ApplicationServlet.java b/server/src/com/vaadin/terminal/gwt/server/ApplicationServlet.java index 14500b01de..857c7c738c 100644 --- a/server/src/com/vaadin/terminal/gwt/server/ApplicationServlet.java +++ b/server/src/com/vaadin/terminal/gwt/server/ApplicationServlet.java @@ -20,7 +20,7 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import com.vaadin.Application; -import com.vaadin.terminal.DefaultRootProvider; +import com.vaadin.terminal.DefaultUIProvider; import com.vaadin.terminal.gwt.server.ServletPortletHelper.ApplicationClassException; /** @@ -70,7 +70,7 @@ public class ApplicationServlet extends AbstractApplicationServlet { // Creates a new application instance try { final Application application = getApplicationClass().newInstance(); - application.addUIProvider(new DefaultRootProvider()); + application.addUIProvider(new DefaultUIProvider()); return application; } catch (final IllegalAccessException e) { diff --git a/server/src/com/vaadin/terminal/gwt/server/BootstrapFragmentResponse.java b/server/src/com/vaadin/terminal/gwt/server/BootstrapFragmentResponse.java index df77600150..6f69086523 100644 --- a/server/src/com/vaadin/terminal/gwt/server/BootstrapFragmentResponse.java +++ b/server/src/com/vaadin/terminal/gwt/server/BootstrapFragmentResponse.java @@ -48,17 +48,16 @@ public class BootstrapFragmentResponse extends BootstrapResponse { * @param application * the application for which the bootstrap page should be * generated - * @param rootId - * the generated id of the UI that will be displayed on the - * page + * @param uiId + * the generated id of the UI that will be displayed on the page * @param fragmentNodes * a mutable list containing the DOM nodes that will make up the * application HTML */ public BootstrapFragmentResponse(BootstrapHandler handler, - WrappedRequest request, Application application, Integer rootId, + WrappedRequest request, Application application, Integer uiId, List fragmentNodes) { - super(handler, request, application, rootId); + super(handler, request, application, uiId); this.fragmentNodes = fragmentNodes; } diff --git a/server/src/com/vaadin/terminal/gwt/server/BootstrapHandler.java b/server/src/com/vaadin/terminal/gwt/server/BootstrapHandler.java index 1dfe9d1685..d329159d95 100644 --- a/server/src/com/vaadin/terminal/gwt/server/BootstrapHandler.java +++ b/server/src/com/vaadin/terminal/gwt/server/BootstrapHandler.java @@ -42,6 +42,7 @@ import com.vaadin.external.json.JSONException; import com.vaadin.external.json.JSONObject; import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.Version; +import com.vaadin.shared.ui.ui.UIConstants; import com.vaadin.terminal.DeploymentConfiguration; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.RequestHandler; @@ -78,19 +79,19 @@ public abstract class BootstrapHandler implements RequestHandler { return bootstrapResponse.getApplication(); } - public Integer getRootId() { - return bootstrapResponse.getRootId(); + public Integer getUIId() { + return bootstrapResponse.getUIId(); } - public UI getRoot() { - return bootstrapResponse.getRoot(); + public UI getUI() { + return bootstrapResponse.getUI(); } public String getWidgetsetName() { if (widgetsetName == null) { - UI uI = getRoot(); + UI uI = getUI(); if (uI != null) { - widgetsetName = getWidgetsetForRoot(this); + widgetsetName = getWidgetsetForUI(this); } } return widgetsetName; @@ -98,7 +99,7 @@ public abstract class BootstrapHandler implements RequestHandler { public String getThemeName() { if (themeName == null) { - UI uI = getRoot(); + UI uI = getUI(); if (uI != null) { themeName = findAndEscapeThemeName(this); } @@ -125,7 +126,7 @@ public abstract class BootstrapHandler implements RequestHandler { throws IOException { // TODO Should all urls be handled here? - Integer rootId = null; + Integer uiId = null; try { UI uI = application.getUIForRequest(request); if (uI == null) { @@ -133,14 +134,14 @@ public abstract class BootstrapHandler implements RequestHandler { return true; } - rootId = Integer.valueOf(uI.getUIId()); + uiId = Integer.valueOf(uI.getUIId()); } catch (UIRequiresMoreInformationException e) { - // Just keep going without rootId + // Just keep going without uiId } try { BootstrapContext context = createContext(request, response, - application, rootId); + application, uiId); setupMainDiv(context); BootstrapFragmentResponse fragmentResponse = context @@ -170,8 +171,8 @@ public abstract class BootstrapHandler implements RequestHandler { Map headers = new LinkedHashMap(); Document document = Document.createShell(""); BootstrapPageResponse pageResponse = new BootstrapPageResponse( - this, request, context.getApplication(), context.getRootId(), document, - headers); + this, request, context.getApplication(), context.getUIId(), + document, headers); List fragmentNodes = fragmentResponse.getFragmentNodes(); Element body = document.body(); for (Node node : fragmentNodes) { @@ -246,7 +247,7 @@ public abstract class BootstrapHandler implements RequestHandler { head.appendElement("meta").attr("http-equiv", "X-UA-Compatible") .attr("content", "chrome=1"); - UI uI = context.getRoot(); + UI uI = context.getUI(); String title = ((uI == null || uI.getCaption() == null) ? "" : uI .getCaption()); head.appendElement("title").appendText(title); @@ -272,10 +273,10 @@ public abstract class BootstrapHandler implements RequestHandler { } public BootstrapContext createContext(WrappedRequest request, - WrappedResponse response, Application application, Integer rootId) { + WrappedResponse response, Application application, Integer uiId) { BootstrapContext context = new BootstrapContext(response, - new BootstrapFragmentResponse(this, request, - application, rootId, new ArrayList())); + new BootstrapFragmentResponse(this, request, application, uiId, + new ArrayList())); return context; } @@ -293,8 +294,8 @@ public abstract class BootstrapHandler implements RequestHandler { */ protected abstract String getApplicationId(BootstrapContext context); - public String getWidgetsetForRoot(BootstrapContext context) { - UI uI = context.getRoot(); + public String getWidgetsetForUI(BootstrapContext context) { + UI uI = context.getUI(); WrappedRequest request = context.getRequest(); String widgetset = uI.getApplication().getWidgetsetForUI(uI); @@ -417,12 +418,12 @@ public abstract class BootstrapHandler implements RequestHandler { protected JSONObject getApplicationParameters(BootstrapContext context) throws JSONException, PaintException { Application application = context.getApplication(); - Integer rootId = context.getRootId(); + Integer uiId = context.getUIId(); JSONObject appConfig = new JSONObject(); - if (rootId != null) { - appConfig.put(ApplicationConstants.ROOT_ID_PARAMETER, rootId); + if (uiId != null) { + appConfig.put(UIConstants.UI_ID_PARAMETER, uiId); } if (context.getThemeName() != null) { @@ -437,7 +438,7 @@ public abstract class BootstrapHandler implements RequestHandler { appConfig.put("widgetset", context.getWidgetsetName()); - if (rootId == null || application.isUIInitPending(rootId.intValue())) { + if (uiId == null || application.isUIInitPending(uiId.intValue())) { appConfig.put("initialPath", context.getRequest() .getRequestPathInfo()); @@ -447,7 +448,7 @@ public abstract class BootstrapHandler implements RequestHandler { } else { // write the initial UIDL into the config appConfig.put("uidl", - getInitialUIDL(context.getRequest(), context.getRoot())); + getInitialUIDL(context.getRequest(), context.getUI())); } return appConfig; @@ -533,7 +534,7 @@ public abstract class BootstrapHandler implements RequestHandler { * @return */ public String getThemeName(BootstrapContext context) { - return context.getApplication().getThemeForUI(context.getRoot()); + return context.getApplication().getThemeForUI(context.getUI()); } /** @@ -568,15 +569,15 @@ public abstract class BootstrapHandler implements RequestHandler { * * @param request * the originating request - * @param uI - * the root for which the UIDL should be generated + * @param ui + * the UI for which the UIDL should be generated * @return a string with the initial UIDL message * @throws PaintException * if an exception occurs while painting the components * @throws JSONException * if an exception occurs while formatting the output */ - protected abstract String getInitialUIDL(WrappedRequest request, UI uI) + protected abstract String getInitialUIDL(WrappedRequest request, UI ui) throws PaintException, JSONException; } diff --git a/server/src/com/vaadin/terminal/gwt/server/BootstrapPageResponse.java b/server/src/com/vaadin/terminal/gwt/server/BootstrapPageResponse.java index 535ab23c92..847578ef97 100644 --- a/server/src/com/vaadin/terminal/gwt/server/BootstrapPageResponse.java +++ b/server/src/com/vaadin/terminal/gwt/server/BootstrapPageResponse.java @@ -51,7 +51,7 @@ public class BootstrapPageResponse extends BootstrapResponse { * @param application * the application for which the bootstrap page should be * generated - * @param rootId + * @param uiId * the generated id of the UI that will be displayed on the * page * @param document @@ -60,9 +60,9 @@ public class BootstrapPageResponse extends BootstrapResponse { * a map into which header data can be added */ public BootstrapPageResponse(BootstrapHandler handler, - WrappedRequest request, Application application, Integer rootId, + WrappedRequest request, Application application, Integer uiId, Document document, Map headers) { - super(handler, request, application, rootId); + super(handler, request, application, uiId); this.headers = headers; this.document = document; } diff --git a/server/src/com/vaadin/terminal/gwt/server/BootstrapResponse.java b/server/src/com/vaadin/terminal/gwt/server/BootstrapResponse.java index 2518f7080e..a422cba345 100644 --- a/server/src/com/vaadin/terminal/gwt/server/BootstrapResponse.java +++ b/server/src/com/vaadin/terminal/gwt/server/BootstrapResponse.java @@ -33,7 +33,7 @@ import com.vaadin.ui.UI; public abstract class BootstrapResponse extends EventObject { private final WrappedRequest request; private final Application application; - private final Integer rootId; + private final Integer uiId; /** * Creates a new bootstrap event. @@ -46,16 +46,15 @@ public abstract class BootstrapResponse extends EventObject { * @param application * the application for which the bootstrap page should be * generated - * @param rootId - * the generated id of the UI that will be displayed on the - * page + * @param uiId + * the generated id of the UI that will be displayed on the page */ public BootstrapResponse(BootstrapHandler handler, WrappedRequest request, - Application application, Integer rootId) { + Application application, Integer uiId) { super(handler); this.request = request; this.application = application; - this.rootId = rootId; + this.uiId = uiId; } /** @@ -91,20 +90,20 @@ public abstract class BootstrapResponse extends EventObject { } /** - * Gets the root id that has been generated for this response. Please note + * Gets the UI id that has been generated for this response. Please note * that if {@link Application#isUiPreserved()} is enabled, a previously * created UI with a different id might eventually end up being used. * - * @return the root id + * @return the UI id */ - public Integer getRootId() { - return rootId; + public Integer getUIId() { + return uiId; } /** * Gets the UI for which this page is being rendered, if available. Some - * features of the framework will postpone the UI selection until after - * the bootstrap page has been rendered and required information from the + * features of the framework will postpone the UI selection until after the + * bootstrap page has been rendered and required information from the * browser has been sent back. This method will return null if * no UI instance is yet available. * @@ -116,7 +115,7 @@ public abstract class BootstrapResponse extends EventObject { * null if all required information is not yet * available. */ - public UI getRoot() { + public UI getUI() { return UI.getCurrent(); } } diff --git a/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java b/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java index 1a5019a7c1..c2fbbe37d4 100644 --- a/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java +++ b/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java @@ -175,7 +175,7 @@ public interface ClientConnector extends Connector, RpcTarget { public void removeExtension(Extension extension); /** - * Returns the root this connector is attached to + * Returns the UI this connector is attached to * * @return The UI this connector is attached to or null if it is not * attached to any UI diff --git a/server/src/com/vaadin/terminal/gwt/server/Constants.java b/server/src/com/vaadin/terminal/gwt/server/Constants.java index 78c043da69..40386d6eb7 100644 --- a/server/src/com/vaadin/terminal/gwt/server/Constants.java +++ b/server/src/com/vaadin/terminal/gwt/server/Constants.java @@ -78,7 +78,7 @@ public interface Constants { // Widget set parameter name static final String PARAMETER_WIDGETSET = "widgetset"; - static final String ERROR_NO_ROOT_FOUND = "Application did not return a root for the request and did not request extra information either. Something is wrong."; + static final String ERROR_NO_UI_FOUND = "No UIProvider returned a UI for the request."; static final String DEFAULT_THEME_NAME = "reindeer"; diff --git a/server/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java b/server/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java index a5a3e94954..8538d42604 100644 --- a/server/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java +++ b/server/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java @@ -395,7 +395,7 @@ public class PortletApplicationContext2 extends AbstractWebApplicationContext { PortletURL url = ((MimeResponse) response).createRenderURL(); url.setPortletMode(portletMode); throw new RuntimeException("UI.open has not yet been implemented"); - // root.open(new ExternalResource(url.toString())); + // UI.open(new ExternalResource(url.toString())); } else if (response instanceof StateAwareResponse) { ((StateAwareResponse) response).setPortletMode(portletMode); } else { diff --git a/server/src/com/vaadin/terminal/gwt/server/ServletPortletHelper.java b/server/src/com/vaadin/terminal/gwt/server/ServletPortletHelper.java index 7e669d939c..403cffb47c 100644 --- a/server/src/com/vaadin/terminal/gwt/server/ServletPortletHelper.java +++ b/server/src/com/vaadin/terminal/gwt/server/ServletPortletHelper.java @@ -9,7 +9,7 @@ import com.vaadin.terminal.WrappedRequest; import com.vaadin.ui.UI; /* - * Copyright 2011 Vaadin Ltd. + * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of @@ -43,14 +43,14 @@ class ServletPortletHelper implements Serializable { throws ApplicationClassException { String applicationParameter = deploymentConfiguration .getInitParameters().getProperty("application"); - String rootParameter = deploymentConfiguration.getInitParameters() + String uiParameter = deploymentConfiguration.getInitParameters() .getProperty(Application.UI_PARAMETER); ClassLoader classLoader = deploymentConfiguration.getClassLoader(); if (applicationParameter == null) { // Validate the parameter value - verifyRootClass(rootParameter, classLoader); + verifyUIClass(uiParameter, classLoader); // Application can be used if a valid rootLayout is defined return Application.class; @@ -66,22 +66,22 @@ class ServletPortletHelper implements Serializable { } } - private static void verifyRootClass(String className, - ClassLoader classLoader) throws ApplicationClassException { + private static void verifyUIClass(String className, ClassLoader classLoader) + throws ApplicationClassException { if (className == null) { throw new ApplicationClassException(Application.UI_PARAMETER + " init parameter not defined"); } - // Check that the root layout class can be found + // Check that the UI layout class can be found try { - Class rootClass = classLoader.loadClass(className); - if (!UI.class.isAssignableFrom(rootClass)) { + Class uiClass = classLoader.loadClass(className); + if (!UI.class.isAssignableFrom(uiClass)) { throw new ApplicationClassException(className + " does not implement UI"); } // Try finding a default constructor, else throw exception - rootClass.getConstructor(); + uiClass.getConstructor(); } catch (ClassNotFoundException e) { throw new ApplicationClassException(className + " could not be loaded", e); diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java index 0b97e1667d..a52a07f266 100644 --- a/server/src/com/vaadin/ui/AbstractComponent.java +++ b/server/src/com/vaadin/ui/AbstractComponent.java @@ -556,16 +556,6 @@ public abstract class AbstractComponent extends AbstractClientConnector getState().setReadOnly(readOnly); } - /* - * Gets the parent window of the component. Don't add a JavaDoc comment - * here, we use the default documentation from implemented interface. - */ - @Override - public UI getUI() { - // Just make method from implemented Component interface public - return super.getUI(); - } - /* * Notify the component that it's attached to a window. Don't add a JavaDoc * comment here, we use the default documentation from implemented @@ -1304,7 +1294,7 @@ public abstract class AbstractComponent extends AbstractClientConnector /** * Set a viewer for the action manager to be the parent sub window (if the - * component is in a window) or the root (otherwise). This is still a + * component is in a window) or the UI (otherwise). This is still a * simplification of the real case as this should be handled by the parent * VOverlay (on the client side) if the component is inside an VOverlay * component. diff --git a/server/src/com/vaadin/ui/ConnectorTracker.java b/server/src/com/vaadin/ui/ConnectorTracker.java index c7c7bc9784..ad5990137c 100644 --- a/server/src/com/vaadin/ui/ConnectorTracker.java +++ b/server/src/com/vaadin/ui/ConnectorTracker.java @@ -210,7 +210,7 @@ public class ConnectorTracker implements Serializable { while (iterator.hasNext()) { String connectorId = iterator.next(); ClientConnector connector = connectorIdToConnector.get(connectorId); - if (getRootForConnector(connector) != uI) { + if (getUIForConnector(connector) != uI) { // If connector is no longer part of this uI, // remove it from the map. If it is re-attached to the // application at some point it will be re-added through @@ -239,7 +239,7 @@ public class ConnectorTracker implements Serializable { * @return The uI the connector is attached to or null if it is not * attached to any uI. */ - private UI getRootForConnector(ClientConnector connector) { + private UI getUIForConnector(ClientConnector connector) { if (connector == null) { return null; } @@ -247,7 +247,7 @@ public class ConnectorTracker implements Serializable { return ((Component) connector).getUI(); } - return getRootForConnector(connector.getParent()); + return getUIForConnector(connector.getParent()); } /** diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index c0b3ed9929..aede1af54b 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -35,9 +35,9 @@ import com.vaadin.event.MouseEvents.ClickListener; import com.vaadin.shared.EventId; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.BorderStyle; -import com.vaadin.shared.ui.root.RootConstants; -import com.vaadin.shared.ui.root.UIServerRpc; -import com.vaadin.shared.ui.root.UIState; +import com.vaadin.shared.ui.ui.UIConstants; +import com.vaadin.shared.ui.ui.UIServerRpc; +import com.vaadin.shared.ui.ui.UIState; import com.vaadin.terminal.Page; import com.vaadin.terminal.Page.BrowserWindowResizeEvent; import com.vaadin.terminal.Page.BrowserWindowResizeListener; @@ -64,7 +64,7 @@ import com.vaadin.ui.Window.CloseListener; * When a new UI instance is needed, typically because the user opens a URL in a * browser window which points to {@link AbstractApplicationServlet}, * {@link Application#getUIForRequest(WrappedRequest)} is invoked to get a UI. - * That method does by default create a root according to the + * That method does by default create a UI according to the * {@value Application#UI_PARAMETER} parameter from web.xml. *

*

@@ -544,8 +544,8 @@ public abstract class UI extends AbstractComponentContainer implements if (pendingFocus != null) { // ensure focused component is still attached to this main window if (pendingFocus.getUI() == this - || (pendingFocus.getUI() != null && pendingFocus - .getUI().getParent() == this)) { + || (pendingFocus.getUI() != null && pendingFocus.getUI() + .getParent() == this)) { target.addAttribute("focused", pendingFocus); } pendingFocus = null; @@ -556,7 +556,7 @@ public abstract class UI extends AbstractComponentContainer implements } if (isResizeLazy()) { - target.addAttribute(RootConstants.RESIZE_LAZY, true); + target.addAttribute(UIConstants.RESIZE_LAZY, true); } } @@ -585,9 +585,9 @@ public abstract class UI extends AbstractComponentContainer implements actionManager.handleActions(variables, this); } - if (variables.containsKey(RootConstants.FRAGMENT_VARIABLE)) { + if (variables.containsKey(UIConstants.FRAGMENT_VARIABLE)) { String fragment = (String) variables - .get(RootConstants.FRAGMENT_VARIABLE); + .get(UIConstants.FRAGMENT_VARIABLE); getPage().setFragment(fragment, true); } } diff --git a/server/src/com/vaadin/ui/Window.java b/server/src/com/vaadin/ui/Window.java index ad2bbd0576..6102350566 100644 --- a/server/src/com/vaadin/ui/Window.java +++ b/server/src/com/vaadin/ui/Window.java @@ -224,11 +224,11 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, public void close() { UI uI = getUI(); - // Don't do anything if not attached to a root + // Don't do anything if not attached to a UI if (uI != null) { // focus is restored to the parent window uI.focus(); - // subwindow is removed from the root + // subwindow is removed from the UI uI.removeWindow(this); } } @@ -470,7 +470,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * If there are currently several windows visible, calling this method makes * this window topmost. *

- * This method can only be called if this window connected a root. Else an + * This method can only be called if this window connected a UI. Else an * illegal state exception is thrown. Also if there are modal windows and * this window is not modal, and illegal state exception is thrown. *

@@ -485,7 +485,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, for (Window w : uI.getWindows()) { if (!isModal() && w.isModal()) { throw new IllegalStateException( - "The root contains modal windows, non-modal window cannot be brought to front."); + "The UI contains modal windows, non-modal window cannot be brought to front."); } if (w.bringToFront != null) { maxBringToFront = Math.max(maxBringToFront, diff --git a/shared/src/com/vaadin/shared/ApplicationConstants.java b/shared/src/com/vaadin/shared/ApplicationConstants.java index 31e633a210..ba35ddea50 100644 --- a/shared/src/com/vaadin/shared/ApplicationConstants.java +++ b/shared/src/com/vaadin/shared/ApplicationConstants.java @@ -29,10 +29,6 @@ public class ApplicationConstants { public static final String APP_PROTOCOL_PREFIX = "app://"; public static final String CONNECTOR_PROTOCOL_PREFIX = "connector://"; public static final String UIDL_SECURITY_TOKEN_ID = "Vaadin-Security-Key"; - /** - * Name of the parameter used to transmit root ids back and forth - */ - public static final String ROOT_ID_PARAMETER = "rootId"; public static final String PARAM_UNLOADBURST = "onunloadburst"; diff --git a/shared/src/com/vaadin/shared/ui/root/PageClientRpc.java b/shared/src/com/vaadin/shared/ui/root/PageClientRpc.java deleted file mode 100644 index b7d9419057..0000000000 --- a/shared/src/com/vaadin/shared/ui/root/PageClientRpc.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.vaadin.shared.ui.root; - -import com.vaadin.shared.communication.ClientRpc; - -public interface PageClientRpc extends ClientRpc { - - public void setTitle(String title); - -} diff --git a/shared/src/com/vaadin/shared/ui/root/RootConstants.java b/shared/src/com/vaadin/shared/ui/root/RootConstants.java deleted file mode 100644 index 34c17ac71f..0000000000 --- a/shared/src/com/vaadin/shared/ui/root/RootConstants.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.shared.ui.root; - -public class RootConstants { - /** - * Attribute name for the lazy resize setting . - */ - @Deprecated - public static final String RESIZE_LAZY = "rL"; - - @Deprecated - public static final String NOTIFICATION_HTML_CONTENT_NOT_ALLOWED = "useplain"; - - @Deprecated - public static final String FRAGMENT_VARIABLE = "fragment"; - - @Deprecated - public static final String ATTRIBUTE_NOTIFICATION_STYLE = "style"; - @Deprecated - public static final String ATTRIBUTE_NOTIFICATION_CAPTION = "caption"; - @Deprecated - public static final String ATTRIBUTE_NOTIFICATION_MESSAGE = "message"; - @Deprecated - public static final String ATTRIBUTE_NOTIFICATION_ICON = "icon"; - @Deprecated - public static final String ATTRIBUTE_NOTIFICATION_POSITION = "position"; - @Deprecated - public static final String ATTRIBUTE_NOTIFICATION_DELAY = "delay"; - -} diff --git a/shared/src/com/vaadin/shared/ui/root/UIServerRpc.java b/shared/src/com/vaadin/shared/ui/root/UIServerRpc.java deleted file mode 100644 index 20cdd48f54..0000000000 --- a/shared/src/com/vaadin/shared/ui/root/UIServerRpc.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.shared.ui.root; - -import com.vaadin.shared.annotations.Delayed; -import com.vaadin.shared.communication.ServerRpc; -import com.vaadin.shared.ui.ClickRpc; - -public interface UIServerRpc extends ClickRpc, ServerRpc { - @Delayed(lastonly = true) - public void resize(int viewWidth, int viewHeight, int windowWidth, - int windowHeight); -} \ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/root/UIState.java b/shared/src/com/vaadin/shared/ui/root/UIState.java deleted file mode 100644 index f019d1ce67..0000000000 --- a/shared/src/com/vaadin/shared/ui/root/UIState.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.shared.ui.root; - -import com.vaadin.shared.ComponentState; -import com.vaadin.shared.Connector; - -public class UIState extends ComponentState { - private Connector content; - - public Connector getContent() { - return content; - } - - public void setContent(Connector content) { - this.content = content; - } - -} \ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/ui/PageClientRpc.java b/shared/src/com/vaadin/shared/ui/ui/PageClientRpc.java new file mode 100644 index 0000000000..a3cbc10cf6 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/ui/PageClientRpc.java @@ -0,0 +1,25 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.shared.ui.ui; + +import com.vaadin.shared.communication.ClientRpc; + +public interface PageClientRpc extends ClientRpc { + + public void setTitle(String title); + +} diff --git a/shared/src/com/vaadin/shared/ui/ui/UIConstants.java b/shared/src/com/vaadin/shared/ui/ui/UIConstants.java new file mode 100644 index 0000000000..76413628a4 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/ui/UIConstants.java @@ -0,0 +1,49 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.shared.ui.ui; + +public class UIConstants { + /** + * Attribute name for the lazy resize setting . + */ + @Deprecated + public static final String RESIZE_LAZY = "rL"; + + @Deprecated + public static final String NOTIFICATION_HTML_CONTENT_NOT_ALLOWED = "useplain"; + + @Deprecated + public static final String FRAGMENT_VARIABLE = "fragment"; + + @Deprecated + public static final String ATTRIBUTE_NOTIFICATION_STYLE = "style"; + @Deprecated + public static final String ATTRIBUTE_NOTIFICATION_CAPTION = "caption"; + @Deprecated + public static final String ATTRIBUTE_NOTIFICATION_MESSAGE = "message"; + @Deprecated + public static final String ATTRIBUTE_NOTIFICATION_ICON = "icon"; + @Deprecated + public static final String ATTRIBUTE_NOTIFICATION_POSITION = "position"; + @Deprecated + public static final String ATTRIBUTE_NOTIFICATION_DELAY = "delay"; + + /** + * Name of the parameter used to transmit UI ids back and forth + */ + public static final String UI_ID_PARAMETER = "uiId"; + +} diff --git a/shared/src/com/vaadin/shared/ui/ui/UIServerRpc.java b/shared/src/com/vaadin/shared/ui/ui/UIServerRpc.java new file mode 100644 index 0000000000..ef28a12415 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/ui/UIServerRpc.java @@ -0,0 +1,26 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.shared.ui.ui; + +import com.vaadin.shared.annotations.Delayed; +import com.vaadin.shared.communication.ServerRpc; +import com.vaadin.shared.ui.ClickRpc; + +public interface UIServerRpc extends ClickRpc, ServerRpc { + @Delayed(lastonly = true) + public void resize(int viewWidth, int viewHeight, int windowWidth, + int windowHeight); +} \ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/ui/UIState.java b/shared/src/com/vaadin/shared/ui/ui/UIState.java new file mode 100644 index 0000000000..01426bd8f3 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/ui/UIState.java @@ -0,0 +1,32 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.shared.ui.ui; + +import com.vaadin.shared.ComponentState; +import com.vaadin.shared.Connector; + +public class UIState extends ComponentState { + private Connector content; + + public Connector getContent() { + return content; + } + + public void setContent(Connector content) { + this.content = content; + } + +} \ No newline at end of file diff --git a/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java b/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java index 59b1299db2..aa4fa22d06 100644 --- a/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java +++ b/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java @@ -11,7 +11,7 @@ import org.easymock.EasyMock; import com.vaadin.Application; import com.vaadin.Application.ApplicationStartEvent; import com.vaadin.UIRequiresMoreInformationException; -import com.vaadin.terminal.DefaultRootProvider; +import com.vaadin.terminal.DefaultUIProvider; import com.vaadin.terminal.DeploymentConfiguration; import com.vaadin.terminal.WrappedRequest; import com.vaadin.ui.UI; @@ -113,7 +113,7 @@ public class CustomRootClassLoader extends TestCase { private Application createStubApplication() { return new Application() { { - addUIProvider(new DefaultRootProvider()); + addUIProvider(new DefaultUIProvider()); } @Override diff --git a/tests/testbench/com/vaadin/launcher/ApplicationRunnerServlet.java b/tests/testbench/com/vaadin/launcher/ApplicationRunnerServlet.java index 2611546203..8183ed2d0b 100644 --- a/tests/testbench/com/vaadin/launcher/ApplicationRunnerServlet.java +++ b/tests/testbench/com/vaadin/launcher/ApplicationRunnerServlet.java @@ -31,7 +31,7 @@ import javax.servlet.http.HttpServletResponse; import com.vaadin.Application; import com.vaadin.UIRequiresMoreInformationException; -import com.vaadin.terminal.AbstractRootProvider; +import com.vaadin.terminal.AbstractUIProvider; import com.vaadin.terminal.WrappedRequest; import com.vaadin.terminal.gwt.server.AbstractApplicationServlet; import com.vaadin.terminal.gwt.server.WrappedHttpServletRequest; @@ -112,7 +112,7 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet { final Class classToRun = getClassToRun(); if (UI.class.isAssignableFrom(classToRun)) { Application application = new Application(); - application.addUIProvider(new AbstractRootProvider() { + application.addUIProvider(new AbstractUIProvider() { @Override public Class getUIClass( diff --git a/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java b/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java index b9b9c509c1..f48ca28dbf 100644 --- a/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java +++ b/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java @@ -2,7 +2,7 @@ package com.vaadin.tests.application; import com.vaadin.Application; import com.vaadin.UIRequiresMoreInformationException; -import com.vaadin.terminal.AbstractRootProvider; +import com.vaadin.terminal.AbstractUIProvider; import com.vaadin.terminal.WrappedRequest; import com.vaadin.tests.components.AbstractTestApplication; import com.vaadin.ui.Label; @@ -23,7 +23,7 @@ public class RefreshStatePreserve extends AbstractTestApplication { public void init() { super.init(); setUiPreserved(true); - addUIProvider(new AbstractRootProvider() { + addUIProvider(new AbstractUIProvider() { @Override public Class getUIClass(Application application, WrappedRequest request) diff --git a/tests/testbench/com/vaadin/tests/components/root/RootsInMultipleTabs.java b/tests/testbench/com/vaadin/tests/components/root/RootsInMultipleTabs.java index 238983d906..97506f7ad6 100644 --- a/tests/testbench/com/vaadin/tests/components/root/RootsInMultipleTabs.java +++ b/tests/testbench/com/vaadin/tests/components/root/RootsInMultipleTabs.java @@ -2,7 +2,7 @@ package com.vaadin.tests.components.root; import com.vaadin.Application; import com.vaadin.UIRequiresMoreInformationException; -import com.vaadin.terminal.AbstractRootProvider; +import com.vaadin.terminal.AbstractUIProvider; import com.vaadin.terminal.WrappedRequest; import com.vaadin.tests.components.AbstractTestApplication; import com.vaadin.ui.Label; @@ -23,7 +23,7 @@ public class RootsInMultipleTabs extends AbstractTestApplication { } public RootsInMultipleTabs() { - addUIProvider(new AbstractRootProvider() { + addUIProvider(new AbstractUIProvider() { @Override public Class getUIClass(Application application, WrappedRequest request) diff --git a/tests/testbench/com/vaadin/tests/vaadincontext/TestAddonContextListener.java b/tests/testbench/com/vaadin/tests/vaadincontext/TestAddonContextListener.java index a525d3139b..4fa007b11d 100644 --- a/tests/testbench/com/vaadin/tests/vaadincontext/TestAddonContextListener.java +++ b/tests/testbench/com/vaadin/tests/vaadincontext/TestAddonContextListener.java @@ -42,7 +42,7 @@ public class TestAddonContextListener implements AddonContextListener { } private boolean shouldModify(BootstrapResponse response) { - UI uI = response.getRoot(); + UI uI = response.getUI(); boolean shouldModify = uI != null && uI.getClass() == BootstrapModifyRoot.class; return shouldModify; -- cgit v1.2.3 From f2cb4a9d9b3d5e89e38446906e7b556946f0a82a Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Thu, 23 Aug 2012 18:58:00 +0300 Subject: Split Embedded into several components, migrate them to Vaadin 7 (#9087) --- .../embeddedbrowser/EmbeddedBrowserConnector.java | 38 ++++ .../ui/embeddedbrowser/VEmbeddedBrowser.java | 120 +++++++++++ .../gwt/client/ui/flash/FlashConnector.java | 44 ++++ .../terminal/gwt/client/ui/flash/VFlash.java | 228 +++++++++++++++++++++ .../gwt/client/ui/image/ImageConnector.java | 67 ++++++ .../terminal/gwt/client/ui/image/VImage.java | 10 + server/src/com/vaadin/ui/AbstractEmbedded.java | 84 ++++++++ server/src/com/vaadin/ui/EmbeddedBrowser.java | 19 ++ server/src/com/vaadin/ui/Flash.java | 136 ++++++++++++ server/src/com/vaadin/ui/Image.java | 94 +++++++++ .../vaadin/shared/ui/AbstractEmbeddedState.java | 27 +++ .../ui/embeddedbrowser/EmbeddedBrowserState.java | 7 + .../src/com/vaadin/shared/ui/flash/FlashState.java | 68 ++++++ .../com/vaadin/shared/ui/image/ImageServerRpc.java | 8 + .../src/com/vaadin/shared/ui/image/ImageState.java | 7 + 15 files changed, 957 insertions(+) create mode 100644 client/src/com/vaadin/terminal/gwt/client/ui/embeddedbrowser/EmbeddedBrowserConnector.java create mode 100644 client/src/com/vaadin/terminal/gwt/client/ui/embeddedbrowser/VEmbeddedBrowser.java create mode 100644 client/src/com/vaadin/terminal/gwt/client/ui/flash/FlashConnector.java create mode 100644 client/src/com/vaadin/terminal/gwt/client/ui/flash/VFlash.java create mode 100644 client/src/com/vaadin/terminal/gwt/client/ui/image/ImageConnector.java create mode 100644 client/src/com/vaadin/terminal/gwt/client/ui/image/VImage.java create mode 100644 server/src/com/vaadin/ui/AbstractEmbedded.java create mode 100644 server/src/com/vaadin/ui/EmbeddedBrowser.java create mode 100644 server/src/com/vaadin/ui/Flash.java create mode 100644 server/src/com/vaadin/ui/Image.java create mode 100644 shared/src/com/vaadin/shared/ui/AbstractEmbeddedState.java create mode 100644 shared/src/com/vaadin/shared/ui/embeddedbrowser/EmbeddedBrowserState.java create mode 100644 shared/src/com/vaadin/shared/ui/flash/FlashState.java create mode 100644 shared/src/com/vaadin/shared/ui/image/ImageServerRpc.java create mode 100644 shared/src/com/vaadin/shared/ui/image/ImageState.java (limited to 'shared') diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/embeddedbrowser/EmbeddedBrowserConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/embeddedbrowser/EmbeddedBrowserConnector.java new file mode 100644 index 0000000000..61231c4fba --- /dev/null +++ b/client/src/com/vaadin/terminal/gwt/client/ui/embeddedbrowser/EmbeddedBrowserConnector.java @@ -0,0 +1,38 @@ +package com.vaadin.terminal.gwt.client.ui.embeddedbrowser; + +import com.vaadin.shared.ui.Connect; +import com.vaadin.shared.ui.embeddedbrowser.EmbeddedBrowserState; +import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; +import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; + +@Connect(com.vaadin.ui.EmbeddedBrowser.class) +public class EmbeddedBrowserConnector extends AbstractComponentConnector { + + @Override + protected void init() { + super.init(); + } + + @Override + public VEmbeddedBrowser getWidget() { + return (VEmbeddedBrowser) super.getWidget(); + } + + @Override + public EmbeddedBrowserState getState() { + return (EmbeddedBrowserState) super.getState(); + } + + @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + + super.onStateChanged(stateChangeEvent); + + getWidget().setAlternateText(getState().getAlternateText()); + getWidget().setSource( + getState().getSource() != null ? getState().getSource() + .getURL() : null); + getWidget().setName(getConnectorId()); + } + +} diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/embeddedbrowser/VEmbeddedBrowser.java b/client/src/com/vaadin/terminal/gwt/client/ui/embeddedbrowser/VEmbeddedBrowser.java new file mode 100644 index 0000000000..fffbff049e --- /dev/null +++ b/client/src/com/vaadin/terminal/gwt/client/ui/embeddedbrowser/VEmbeddedBrowser.java @@ -0,0 +1,120 @@ +package com.vaadin.terminal.gwt.client.ui.embeddedbrowser; + +import com.google.gwt.dom.client.Document; +import com.google.gwt.dom.client.Element; +import com.google.gwt.dom.client.IFrameElement; +import com.google.gwt.user.client.ui.Widget; + +public class VEmbeddedBrowser extends Widget { + + protected IFrameElement iframe; + protected Element altElement; + protected String altText; + + public VEmbeddedBrowser() { + Element root = Document.get().createDivElement(); + setElement(root); + + setStylePrimaryName("v-embeddedbrowser"); + + createAltTextElement(); + } + + /** + * Always creates new iframe inside widget. Will replace previous iframe. + * + * @return + */ + protected IFrameElement createIFrameElement(String src) { + String name = null; + + // Remove alt text + if (altElement != null) { + getElement().removeChild(altElement); + altElement = null; + } + + // Remove old iframe + if (iframe != null) { + name = iframe.getAttribute("name"); + getElement().removeChild(iframe); + iframe = null; + } + + iframe = Document.get().createIFrameElement(); + iframe.setSrc(src); + iframe.setFrameBorder(0); + iframe.setAttribute("width", "100%"); + iframe.setAttribute("height", "100%"); + iframe.setAttribute("allowTransparency", "true"); + + getElement().appendChild(iframe); + + // Reset old attributes (except src) + if (name != null) { + iframe.setName(name); + } + + return iframe; + } + + protected void createAltTextElement() { + if (iframe != null) { + return; + } + + if (altElement == null) { + altElement = Document.get().createSpanElement(); + getElement().appendChild(altElement); + } + + if (altText != null) { + altElement.setInnerText(altText); + } else { + altElement.setInnerText(""); + } + } + + public void setAlternateText(String altText) { + if (this.altText != altText) { + this.altText = altText; + if (altElement != null) { + if (altText != null) { + altElement.setInnerText(altText); + } else { + altElement.setInnerText(""); + } + } + } + } + + /** + * Set the source (the "src" attribute) of iframe. Will replace old iframe + * with new. + * + * @param source + * Source of iframe. + */ + public void setSource(String source) { + + if (source == null) { + if (iframe != null) { + getElement().removeChild(iframe); + iframe = null; + } + createAltTextElement(); + setAlternateText(altText); + return; + } + + if (iframe == null || iframe.getSrc() != source) { + createIFrameElement(source); + } + } + + public void setName(String name) { + if (iframe != null) { + iframe.setName(name); + } + } +} diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/flash/FlashConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/flash/FlashConnector.java new file mode 100644 index 0000000000..a9e7a71013 --- /dev/null +++ b/client/src/com/vaadin/terminal/gwt/client/ui/flash/FlashConnector.java @@ -0,0 +1,44 @@ +package com.vaadin.terminal.gwt.client.ui.flash; + +import com.vaadin.shared.ui.Connect; +import com.vaadin.shared.ui.flash.FlashState; +import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; +import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; + +@Connect(com.vaadin.ui.Flash.class) +public class FlashConnector extends AbstractComponentConnector { + + @Override + protected void init() { + super.init(); + } + + @Override + public VFlash getWidget() { + return (VFlash) super.getWidget(); + } + + @Override + public FlashState getState() { + return (FlashState) super.getState(); + } + + @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + + super.onStateChanged(stateChangeEvent); + + getWidget().setSource( + getState().getSource() != null ? getState().getSource() + .getURL() : null); + getWidget().setArchive(getState().getArchive()); + getWidget().setClassId(getState().getClassId()); + getWidget().setCodebase(getState().getCodebase()); + getWidget().setCodetype(getState().getCodetype()); + getWidget().setStandby(getState().getStandby()); + getWidget().setAlternateText(getState().getAlternateText()); + getWidget().setEmbedParams(getState().getEmbedParams()); + + getWidget().rebuildIfNeeded(); + } +} diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/flash/VFlash.java b/client/src/com/vaadin/terminal/gwt/client/ui/flash/VFlash.java new file mode 100644 index 0000000000..5d60dc66aa --- /dev/null +++ b/client/src/com/vaadin/terminal/gwt/client/ui/flash/VFlash.java @@ -0,0 +1,228 @@ +package com.vaadin.terminal.gwt.client.ui.flash; + +import java.util.HashMap; +import java.util.Map; + +import com.google.gwt.user.client.ui.HTML; +import com.vaadin.terminal.gwt.client.Util; + +public class VFlash extends HTML { + + protected String source; + protected String altText; + protected String classId; + protected String codebase; + protected String codetype; + protected String standby; + protected String archive; + protected Map embedParams = new HashMap(); + protected boolean needsRebuild = false; + protected String width; + protected String height; + + public VFlash() { + setStylePrimaryName("v-flash"); + } + + public void setSource(String source) { + if (this.source != source) { + this.source = source; + needsRebuild = true; + } + } + + public void setAlternateText(String altText) { + if (this.altText != altText) { + this.altText = altText; + needsRebuild = true; + } + } + + public void setClassId(String classId) { + if (this.classId != classId) { + this.classId = classId; + needsRebuild = true; + } + } + + public void setCodebase(String codebase) { + if (this.codebase != codebase) { + this.codebase = codebase; + needsRebuild = true; + } + } + + public void setCodetype(String codetype) { + if (this.codetype != codetype) { + this.codetype = codetype; + needsRebuild = true; + } + } + + public void setStandby(String standby) { + if (this.standby != standby) { + this.standby = standby; + needsRebuild = true; + } + } + + public void setArchive(String archive) { + if (this.archive != archive) { + this.archive = archive; + needsRebuild = true; + } + } + + /** + * Call this after changing values of widget. It will rebuild embedding + * structure if needed. + */ + public void rebuildIfNeeded() { + if (needsRebuild) { + needsRebuild = false; + this.setHTML(createFlashEmbed()); + } + } + + @Override + public void setWidth(String width) { + // super.setWidth(height); + + if (this.width != width) { + this.width = width; + needsRebuild = true; + } + } + + @Override + public void setHeight(String height) { + // super.setHeight(height); + + if (this.height != height) { + this.height = height; + needsRebuild = true; + } + } + + public void setEmbedParams(Map params) { + if (params == null) { + if (!embedParams.isEmpty()) { + embedParams.clear(); + needsRebuild = true; + } + return; + } + + if (!embedParams.equals(params)) { + embedParams = new HashMap(params); + needsRebuild = true; + } + } + + protected String createFlashEmbed() { + /* + * To ensure cross-browser compatibility we are using the twice-cooked + * method to embed flash i.e. we add a OBJECT tag for IE ActiveX and + * inside it a EMBED for all other browsers. + */ + + StringBuilder html = new StringBuilder(); + + // Start the object tag + html.append(""); + + // Ensure we have an movie parameter + if (embedParams.get("movie") == null) { + embedParams.put("movie", source); + } + + // Add parameters to OBJECT + for (String name : embedParams.keySet()) { + html.append(""); + } + + // Build inner EMBED tag + html.append(""); + + if (altText != null) { + html.append(""); + html.append(altText); + html.append(""); + } + + // End object tag + html.append(""); + + return html.toString(); + } + +} diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/image/ImageConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/image/ImageConnector.java new file mode 100644 index 0000000000..d36e224a03 --- /dev/null +++ b/client/src/com/vaadin/terminal/gwt/client/ui/image/ImageConnector.java @@ -0,0 +1,67 @@ +package com.vaadin.terminal.gwt.client.ui.image; + +import com.google.gwt.dom.client.NativeEvent; +import com.google.gwt.event.dom.client.LoadEvent; +import com.google.gwt.event.dom.client.LoadHandler; +import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.Connect; +import com.vaadin.shared.ui.image.ImageServerRpc; +import com.vaadin.shared.ui.image.ImageState; +import com.vaadin.terminal.gwt.client.communication.RpcProxy; +import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; +import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; +import com.vaadin.terminal.gwt.client.ui.ClickEventHandler; + +@Connect(com.vaadin.ui.Image.class) +public class ImageConnector extends AbstractComponentConnector { + + ImageServerRpc rpc; + + @Override + protected void init() { + super.init(); + rpc = RpcProxy.create(ImageServerRpc.class, this); + getWidget().addHandler(new LoadHandler() { + + @Override + public void onLoad(LoadEvent event) { + getLayoutManager().setNeedsMeasure(ImageConnector.this); + } + + }, LoadEvent.getType()); + } + + @Override + public VImage getWidget() { + return (VImage) super.getWidget(); + } + + @Override + public ImageState getState() { + return (ImageState) super.getState(); + } + + @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + super.onStateChanged(stateChangeEvent); + + clickEventHandler.handleEventHandlerRegistration(); + + getWidget().setUrl( + getState().getSource() != null ? getState().getSource() + .getURL() : null); + getWidget().setAltText(getState().getAlternateText()); + } + + protected final ClickEventHandler clickEventHandler = new ClickEventHandler( + this) { + + @Override + protected void fireClick(NativeEvent event, + MouseEventDetails mouseDetails) { + rpc.click(mouseDetails); + } + + }; + +} diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/image/VImage.java b/client/src/com/vaadin/terminal/gwt/client/ui/image/VImage.java new file mode 100644 index 0000000000..7e6b77ed4a --- /dev/null +++ b/client/src/com/vaadin/terminal/gwt/client/ui/image/VImage.java @@ -0,0 +1,10 @@ +package com.vaadin.terminal.gwt.client.ui.image; + +import com.google.gwt.user.client.ui.Image; + +public class VImage extends Image { + + public VImage() { + setStylePrimaryName("v-image"); + } +} diff --git a/server/src/com/vaadin/ui/AbstractEmbedded.java b/server/src/com/vaadin/ui/AbstractEmbedded.java new file mode 100644 index 0000000000..9396af5c44 --- /dev/null +++ b/server/src/com/vaadin/ui/AbstractEmbedded.java @@ -0,0 +1,84 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.ui; + +import com.vaadin.shared.ui.AbstractEmbeddedState; +import com.vaadin.terminal.Resource; +import com.vaadin.terminal.gwt.server.ResourceReference; + +/** + * Abstract base for embedding components. + * + * @author Vaadin Ltd. + * @version + * @VERSION@ + * @since 7.0 + */ +@SuppressWarnings("serial") +public abstract class AbstractEmbedded extends AbstractComponent { + + @Override + public AbstractEmbeddedState getState() { + return (AbstractEmbeddedState) super.getState(); + } + + /** + * Sets the object source resource. The dimensions are assumed if possible. + * The type is guessed from resource. + * + * @param source + * the source to set. + */ + public void setSource(Resource source) { + if (source == null) { + getState().setSource(null); + } else { + getState().setSource(new ResourceReference(source)); + } + requestRepaint(); + } + + /** + * Get the object source resource. + * + * @return the source + */ + public Resource getSource() { + ResourceReference ref = ((ResourceReference) getState().getSource()); + if (ref == null) { + return null; + } else { + return ref.getResource(); + } + } + + /** + * Sets this component's alternate text that can be presented instead of the + * component's normal content for accessibility purposes. + * + * @param altText + * A short, human-readable description of this component's + * content. + */ + public void setAlternateText(String altText) { + if (altText != getState().getAlternateText() + || (altText != null && !altText.equals(getState() + .getAlternateText()))) { + getState().setAlternateText(altText); + requestRepaint(); + } + } + + /** + * Gets this component's alternate text that can be presented instead of the + * component's normal content for accessibility purposes. + * + * @returns Alternate text + */ + public String getAlternateText() { + return getState().getAlternateText(); + } + +} diff --git a/server/src/com/vaadin/ui/EmbeddedBrowser.java b/server/src/com/vaadin/ui/EmbeddedBrowser.java new file mode 100644 index 0000000000..4e2ae18de8 --- /dev/null +++ b/server/src/com/vaadin/ui/EmbeddedBrowser.java @@ -0,0 +1,19 @@ +package com.vaadin.ui; + +import com.vaadin.shared.ui.embeddedbrowser.EmbeddedBrowserState; + +/** + * Component for embedding browser "iframe". + * + * @author Vaadin Ltd. + * @version + * @VERSION@ + * @since 7.0 + */ +public class EmbeddedBrowser extends AbstractEmbedded { + + @Override + public EmbeddedBrowserState getState() { + return (EmbeddedBrowserState) super.getState(); + } +} diff --git a/server/src/com/vaadin/ui/Flash.java b/server/src/com/vaadin/ui/Flash.java new file mode 100644 index 0000000000..0e6cf63a91 --- /dev/null +++ b/server/src/com/vaadin/ui/Flash.java @@ -0,0 +1,136 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.ui; + +import java.util.HashMap; + +import com.vaadin.shared.ui.flash.FlashState; + +/** + * Component for embedding flash objects. + * + * @author Vaadin Ltd. + * @version + * @VERSION@ + * @since 7.0 + */ +@SuppressWarnings("serial") +public class Flash extends AbstractEmbedded { + + @Override + public FlashState getState() { + return (FlashState) super.getState(); + } + + /** + * This attribute specifies the base path used to resolve relative URIs + * specified by the classid, data, and archive attributes. When absent, its + * default value is the base URI of the current document. + * + * @param codebase + * The base path + */ + public void setCodebase(String codebase) { + if (codebase != getState().getCodebase() + || (codebase != null && !codebase.equals(getState() + .getCodebase()))) { + getState().setCodebase(codebase); + requestRepaint(); + } + } + + /** + * This attribute specifies the content type of data expected when + * downloading the object specified by classid. This attribute is optional + * but recommended when classid is specified since it allows the user agent + * to avoid loading information for unsupported content types. When absent, + * it defaults to the value of the type attribute. + * + * @param codetype + * the codetype to set. + */ + public void setCodetype(String codetype) { + if (codetype != getState().getCodetype() + || (codetype != null && !codetype.equals(getState() + .getCodetype()))) { + getState().setCodetype(codetype); + requestRepaint(); + } + } + + /** + * This attribute may be used to specify a space-separated list of URIs for + * archives containing resources relevant to the object, which may include + * the resources specified by the classid and data attributes. Preloading + * archives will generally result in reduced load times for objects. + * Archives specified as relative URIs should be interpreted relative to the + * codebase attribute. + * + * @param archive + * Space-separated list of URIs with resources relevant to the + * object + */ + public void setArchive(String archive) { + if (archive != getState().getArchive() + || (archive != null && !archive.equals(getState().getArchive()))) { + getState().setArchive(archive); + requestRepaint(); + } + } + + public void setStandby(String standby) { + if (standby != getState().getStandby() + || (standby != null && !standby.equals(getState().getStandby()))) { + getState().setStandby(standby); + requestRepaint(); + } + } + + /** + * Sets an object parameter. Parameters are optional information, and they + * are passed to the instantiated object. Parameters are are stored as name + * value pairs. This overrides the previous value assigned to this + * parameter. + * + * @param name + * the name of the parameter. + * @param value + * the value of the parameter. + */ + public void setParameter(String name, String value) { + if (getState().getEmbedParams() == null) { + getState().setEmbedParams(new HashMap()); + } + getState().getEmbedParams().put(name, value); + requestRepaint(); + } + + /** + * Gets the value of an object parameter. Parameters are optional + * information, and they are passed to the instantiated object. Parameters + * are are stored as name value pairs. + * + * @return the Value of parameter or null if not found. + */ + public String getParameter(String name) { + return getState().getEmbedParams() != null ? getState() + .getEmbedParams().get(name) : null; + } + + /** + * Removes an object parameter from the list. + * + * @param name + * the name of the parameter to remove. + */ + public void removeParameter(String name) { + if (getState().getEmbedParams() == null) { + return; + } + getState().getEmbedParams().remove(name); + requestRepaint(); + } + +} diff --git a/server/src/com/vaadin/ui/Image.java b/server/src/com/vaadin/ui/Image.java new file mode 100644 index 0000000000..b0dbc9e629 --- /dev/null +++ b/server/src/com/vaadin/ui/Image.java @@ -0,0 +1,94 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.ui; + +import com.vaadin.event.MouseEvents.ClickEvent; +import com.vaadin.event.MouseEvents.ClickListener; +import com.vaadin.shared.EventId; +import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.image.ImageServerRpc; +import com.vaadin.shared.ui.image.ImageState; +import com.vaadin.terminal.Resource; + +/** + * Component for embedding images. + * + * @author Vaadin Ltd. + * @version + * @VERSION@ + * @since 7.0 + */ +@SuppressWarnings("serial") +public class Image extends AbstractEmbedded { + + protected ImageServerRpc rpc = new ImageServerRpc() { + @Override + public void click(MouseEventDetails mouseDetails) { + fireEvent(new ClickEvent(Image.this, mouseDetails)); + } + }; + + /** + * Creates a new empty Image. + */ + public Image() { + registerRpc(rpc); + } + + /** + * Creates a new empty Image with caption. + * + * @param caption + */ + public Image(String caption) { + this(); + setCaption(caption); + } + + /** + * Creates a new Image whose contents is loaded from given resource. The + * dimensions are assumed if possible. The type is guessed from resource. + * + * @param caption + * @param source + * the Source of the embedded object. + */ + public Image(String caption, Resource source) { + this(caption); + setSource(source); + } + + @Override + public ImageState getState() { + return (ImageState) super.getState(); + } + + /** + * Add a click listener to the component. The listener is called whenever + * the user clicks inside the component. Depending on the content the event + * may be blocked and in that case no event is fired. + * + * Use {@link #removeListener(ClickListener)} to remove the listener. + * + * @param listener + * The listener to add + */ + public void addListener(ClickListener listener) { + addListener(EventId.CLICK_EVENT_IDENTIFIER, ClickEvent.class, listener, + ClickListener.clickMethod); + } + + /** + * Remove a click listener from the component. The listener should earlier + * have been added using {@link #addListener(ClickListener)}. + * + * @param listener + * The listener to remove + */ + public void removeListener(ClickListener listener) { + removeListener(EventId.CLICK_EVENT_IDENTIFIER, ClickEvent.class, + listener); + } +} diff --git a/shared/src/com/vaadin/shared/ui/AbstractEmbeddedState.java b/shared/src/com/vaadin/shared/ui/AbstractEmbeddedState.java new file mode 100644 index 0000000000..96b785edd0 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/AbstractEmbeddedState.java @@ -0,0 +1,27 @@ +package com.vaadin.shared.ui; + +import com.vaadin.shared.ComponentState; +import com.vaadin.shared.communication.URLReference; + +public class AbstractEmbeddedState extends ComponentState { + + protected URLReference source; + protected String alternateText; + + public URLReference getSource() { + return source; + } + + public void setSource(URLReference source) { + this.source = source; + } + + public String getAlternateText() { + return alternateText; + } + + public void setAlternateText(String alternateText) { + this.alternateText = alternateText; + } + +} diff --git a/shared/src/com/vaadin/shared/ui/embeddedbrowser/EmbeddedBrowserState.java b/shared/src/com/vaadin/shared/ui/embeddedbrowser/EmbeddedBrowserState.java new file mode 100644 index 0000000000..cca47176a3 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/embeddedbrowser/EmbeddedBrowserState.java @@ -0,0 +1,7 @@ +package com.vaadin.shared.ui.embeddedbrowser; + +import com.vaadin.shared.ui.AbstractEmbeddedState; + +public class EmbeddedBrowserState extends AbstractEmbeddedState { + +} diff --git a/shared/src/com/vaadin/shared/ui/flash/FlashState.java b/shared/src/com/vaadin/shared/ui/flash/FlashState.java new file mode 100644 index 0000000000..2d33d1a711 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/flash/FlashState.java @@ -0,0 +1,68 @@ +package com.vaadin.shared.ui.flash; + +import java.util.Map; + +import com.vaadin.shared.ui.AbstractEmbeddedState; + +public class FlashState extends AbstractEmbeddedState { + + protected String classId; + + protected String codebase; + + protected String codetype; + + protected String archive; + + protected String standby; + + protected Map embedParams; + + public String getClassId() { + return classId; + } + + public void setClassId(String classId) { + this.classId = classId; + } + + public String getCodebase() { + return codebase; + } + + public void setCodebase(String codeBase) { + codebase = codebase; + } + + public String getCodetype() { + return codetype; + } + + public void setCodetype(String codetype) { + this.codetype = codetype; + } + + public String getArchive() { + return archive; + } + + public void setArchive(String archive) { + this.archive = archive; + } + + public String getStandby() { + return standby; + } + + public void setStandby(String standby) { + this.standby = standby; + } + + public Map getEmbedParams() { + return embedParams; + } + + public void setEmbedParams(Map embedParams) { + this.embedParams = embedParams; + } +} diff --git a/shared/src/com/vaadin/shared/ui/image/ImageServerRpc.java b/shared/src/com/vaadin/shared/ui/image/ImageServerRpc.java new file mode 100644 index 0000000000..aa48f10e5b --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/image/ImageServerRpc.java @@ -0,0 +1,8 @@ +package com.vaadin.shared.ui.image; + +import com.vaadin.shared.communication.ServerRpc; +import com.vaadin.shared.ui.ClickRpc; + +public interface ImageServerRpc extends ClickRpc, ServerRpc { + +} diff --git a/shared/src/com/vaadin/shared/ui/image/ImageState.java b/shared/src/com/vaadin/shared/ui/image/ImageState.java new file mode 100644 index 0000000000..4296c76847 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/image/ImageState.java @@ -0,0 +1,7 @@ +package com.vaadin.shared.ui.image; + +import com.vaadin.shared.ui.AbstractEmbeddedState; + +public class ImageState extends AbstractEmbeddedState { + +} -- cgit v1.2.3 From fc3f7f62b05ae69b242d64084f676d7733962c60 Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Fri, 24 Aug 2012 16:33:15 +0300 Subject: Migrate Slider to Vaadin 7 (#9304) --- .../gwt/client/ui/slider/SliderConnector.java | 89 ++++---- .../terminal/gwt/client/ui/slider/VSlider.java | 251 ++++++++++++++------- server/src/com/vaadin/ui/Slider.java | 172 ++++++-------- .../vaadin/shared/ui/slider/SliderOrientation.java | 5 + .../vaadin/shared/ui/slider/SliderServerRpc.java | 14 ++ .../com/vaadin/shared/ui/slider/SliderState.java | 60 +++++ .../vaadin/tests/components/slider/SliderTest.java | 11 +- .../vaadin/tests/integration/LiferayThemeDemo.java | 5 +- 8 files changed, 359 insertions(+), 248 deletions(-) create mode 100644 shared/src/com/vaadin/shared/ui/slider/SliderOrientation.java create mode 100644 shared/src/com/vaadin/shared/ui/slider/SliderServerRpc.java create mode 100644 shared/src/com/vaadin/shared/ui/slider/SliderState.java (limited to 'shared') diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/slider/SliderConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/slider/SliderConnector.java index 7e0617b7dc..53f3b8874b 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/slider/SliderConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/slider/SliderConnector.java @@ -15,70 +15,61 @@ */ package com.vaadin.terminal.gwt.client.ui.slider; -import com.google.gwt.core.client.Scheduler; -import com.google.gwt.user.client.Command; +import com.google.gwt.event.logical.shared.ValueChangeEvent; +import com.google.gwt.event.logical.shared.ValueChangeHandler; import com.vaadin.shared.ui.Connect; -import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.Paintable; -import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.shared.ui.slider.SliderServerRpc; +import com.vaadin.shared.ui.slider.SliderState; +import com.vaadin.terminal.gwt.client.communication.RpcProxy; +import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; import com.vaadin.terminal.gwt.client.ui.AbstractFieldConnector; import com.vaadin.ui.Slider; @Connect(Slider.class) public class SliderConnector extends AbstractFieldConnector implements - Paintable { + ValueChangeHandler { - @Override - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - - getWidget().client = client; - getWidget().id = uidl.getId(); - - if (!isRealUpdate(uidl)) { - return; - } + protected SliderServerRpc rpc = RpcProxy + .create(SliderServerRpc.class, this); - getWidget().immediate = getState().isImmediate(); - getWidget().disabled = !isEnabled(); - getWidget().readonly = isReadOnly(); + @Override + public void init() { + super.init(); + getWidget().setConnection(getConnection()); + getWidget().addValueChangeHandler(this); + } - getWidget().vertical = uidl.hasAttribute("vertical"); + @Override + public VSlider getWidget() { + return (VSlider) super.getWidget(); + } - // TODO should style names be used? + @Override + public SliderState getState() { + return (SliderState) super.getState(); + } - if (getWidget().vertical) { - getWidget().addStyleName(VSlider.CLASSNAME + "-vertical"); - } else { - getWidget().removeStyleName(VSlider.CLASSNAME + "-vertical"); - } + @Override + public void onValueChange(ValueChangeEvent event) { + rpc.valueChanged(event.getValue()); + } - getWidget().min = uidl.getDoubleAttribute("min"); - getWidget().max = uidl.getDoubleAttribute("max"); - getWidget().resolution = uidl.getIntAttribute("resolution"); - getWidget().value = new Double(uidl.getDoubleVariable("value")); + @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + super.onStateChanged(stateChangeEvent); - getWidget().setFeedbackValue(getWidget().value); + getWidget().setId(getConnectorId()); + getWidget().setImmediate(getState().isImmediate()); + getWidget().setDisabled(!isEnabled()); + getWidget().setReadOnly(isReadOnly()); + getWidget().setOrientation(getState().getOrientation()); + getWidget().setMinValue(getState().getMinValue()); + getWidget().setMaxValue(getState().getMaxValue()); + getWidget().setResolution(getState().getResolution()); + getWidget().setValue(getState().getValue(), false); + getWidget().setFeedbackValue(getState().getValue()); getWidget().buildBase(); - - if (!getWidget().vertical) { - // Draw handle with a delay to allow base to gain maximum width - Scheduler.get().scheduleDeferred(new Command() { - @Override - public void execute() { - getWidget().buildHandle(); - getWidget().setValue(getWidget().value, false); - } - }); - } else { - getWidget().buildHandle(); - getWidget().setValue(getWidget().value, false); - } - } - - @Override - public VSlider getWidget() { - return (VSlider) super.getWidget(); } } diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/slider/VSlider.java b/client/src/com/vaadin/terminal/gwt/client/ui/slider/VSlider.java index 9667522eb3..d9801626b4 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/slider/VSlider.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/slider/VSlider.java @@ -19,12 +19,17 @@ package com.vaadin.terminal.gwt.client.ui.slider; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.event.dom.client.KeyCodes; +import com.google.gwt.event.logical.shared.ValueChangeEvent; +import com.google.gwt.event.logical.shared.ValueChangeHandler; +import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HasValue; +import com.vaadin.shared.ui.slider.SliderOrientation; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.ContainerResizedListener; @@ -36,7 +41,7 @@ import com.vaadin.terminal.gwt.client.ui.VLazyExecutor; import com.vaadin.terminal.gwt.client.ui.VOverlay; public class VSlider extends SimpleFocusablePanel implements Field, - ContainerResizedListener { + ContainerResizedListener, HasValue { public static final String CLASSNAME = "v-slider"; @@ -46,20 +51,22 @@ public class VSlider extends SimpleFocusablePanel implements Field, */ private static final int MIN_SIZE = 50; - ApplicationConnection client; + protected ApplicationConnection client; - String id; + protected String id; - boolean immediate; - boolean disabled; - boolean readonly; + protected boolean immediate; + protected boolean disabled; + protected boolean readonly; private int acceleration = 1; - double min; - double max; - int resolution; - Double value; - boolean vertical; + protected double min; + protected double max; + protected int resolution; + protected Double value; + protected SliderOrientation orientation = SliderOrientation.HORIZONTAL; + + private boolean valueChangeHandlerInitialized = false; private final HTML feedback = new HTML("", false); private final VOverlay feedbackPopup = new VOverlay(true, false, true) { @@ -92,7 +99,7 @@ public class VSlider extends SimpleFocusablePanel implements Field, @Override public void execute() { - updateValueToServer(); + fireValueChanged(); acceleration = 1; } }); @@ -137,7 +144,7 @@ public class VSlider extends SimpleFocusablePanel implements Field, } private void updateFeedbackPosition() { - if (vertical) { + if (isVertical()) { feedbackPopup.setPopupPosition( DOM.getAbsoluteLeft(handle) + handle.getOffsetWidth(), DOM.getAbsoluteTop(handle) + handle.getOffsetHeight() / 2 @@ -152,16 +159,17 @@ public class VSlider extends SimpleFocusablePanel implements Field, } void buildBase() { - final String styleAttribute = vertical ? "height" : "width"; - final String oppositeStyleAttribute = vertical ? "width" : "height"; - final String domProperty = vertical ? "offsetHeight" : "offsetWidth"; + final String styleAttribute = isVertical() ? "height" : "width"; + final String oppositeStyleAttribute = isVertical() ? "width" : "height"; + final String domProperty = isVertical() ? "offsetHeight" + : "offsetWidth"; // clear unnecessary opposite style attribute DOM.setStyleAttribute(base, oppositeStyleAttribute, ""); final Element p = DOM.getParent(getElement()); if (DOM.getElementPropertyInt(p, domProperty) > 50) { - if (vertical) { + if (isVertical()) { setHeight(); } else { DOM.setStyleAttribute(base, styleAttribute, ""); @@ -176,7 +184,7 @@ public class VSlider extends SimpleFocusablePanel implements Field, public void execute() { final Element p = DOM.getParent(getElement()); if (DOM.getElementPropertyInt(p, domProperty) > (MIN_SIZE + 5)) { - if (vertical) { + if (isVertical()) { setHeight(); } else { DOM.setStyleAttribute(base, styleAttribute, ""); @@ -188,12 +196,27 @@ public class VSlider extends SimpleFocusablePanel implements Field, }); } + if (!isVertical()) { + // Draw handle with a delay to allow base to gain maximum width + Scheduler.get().scheduleDeferred(new Command() { + @Override + public void execute() { + buildHandle(); + setValue(value, false); + } + }); + } else { + buildHandle(); + setValue(value, false); + } + // TODO attach listeners for focusing and arrow keys } void buildHandle() { - final String handleAttribute = vertical ? "marginTop" : "marginLeft"; - final String oppositeHandleAttribute = vertical ? "marginLeft" + final String handleAttribute = isVertical() ? "marginTop" + : "marginLeft"; + final String oppositeHandleAttribute = isVertical() ? "marginLeft" : "marginTop"; DOM.setStyleAttribute(handle, handleAttribute, "0"); @@ -206,59 +229,6 @@ public class VSlider extends SimpleFocusablePanel implements Field, } - void setValue(Double value, boolean updateToServer) { - if (value == null) { - return; - } - - if (value < min) { - value = min; - } else if (value > max) { - value = max; - } - - // Update handle position - final String styleAttribute = vertical ? "marginTop" : "marginLeft"; - final String domProperty = vertical ? "offsetHeight" : "offsetWidth"; - final int handleSize = Integer.parseInt(DOM.getElementProperty(handle, - domProperty)); - final int baseSize = Integer.parseInt(DOM.getElementProperty(base, - domProperty)) - (2 * BASE_BORDER_WIDTH); - - final int range = baseSize - handleSize; - double v = value.doubleValue(); - - // Round value to resolution - if (resolution > 0) { - v = Math.round(v * Math.pow(10, resolution)); - v = v / Math.pow(10, resolution); - } else { - v = Math.round(v); - } - final double valueRange = max - min; - double p = 0; - if (valueRange > 0) { - p = range * ((v - min) / valueRange); - } - if (p < 0) { - p = 0; - } - if (vertical) { - p = range - p; - } - final double pos = p; - - DOM.setStyleAttribute(handle, styleAttribute, (Math.round(pos)) + "px"); - - // Update value - this.value = new Double(v); - setFeedbackValue(v); - - if (updateToServer) { - updateValueToServer(); - } - } - @Override public void onBrowserEvent(Event event) { if (disabled || readonly) { @@ -386,7 +356,7 @@ public class VSlider extends SimpleFocusablePanel implements Field, final int coord = getEventPosition(event); final int handleSize, baseSize, baseOffset; - if (vertical) { + if (isVertical()) { handleSize = handle.getOffsetHeight(); baseSize = base.getOffsetHeight(); baseOffset = base.getAbsoluteTop() - Window.getScrollTop() @@ -398,7 +368,7 @@ public class VSlider extends SimpleFocusablePanel implements Field, + handleSize / 2; } - if (vertical) { + if (isVertical()) { v = ((baseSize - (coord - baseOffset)) / (double) (baseSize - handleSize)) * (max - min) + min; } else { @@ -423,7 +393,7 @@ public class VSlider extends SimpleFocusablePanel implements Field, * @return */ protected int getEventPosition(Event event) { - if (vertical) { + if (isVertical()) { return Util.getTouchOrMouseClientY(event); } else { return Util.getTouchOrMouseClientX(event); @@ -432,7 +402,7 @@ public class VSlider extends SimpleFocusablePanel implements Field, @Override public void iLayout() { - if (vertical) { + if (isVertical()) { setHeight(); } // Update handle position @@ -451,8 +421,8 @@ public class VSlider extends SimpleFocusablePanel implements Field, DOM.setStyleAttribute(base, "overflow", ""); } - private void updateValueToServer() { - client.updateVariable(id, "value", value.doubleValue(), immediate); + private void fireValueChanged() { + ValueChangeEvent.fire(VSlider.this, value); } /** @@ -469,8 +439,8 @@ public class VSlider extends SimpleFocusablePanel implements Field, return false; } - if ((keycode == getNavigationUpKey() && vertical) - || (keycode == getNavigationRightKey() && !vertical)) { + if ((keycode == getNavigationUpKey() && isVertical()) + || (keycode == getNavigationRightKey() && !isVertical())) { if (shift) { for (int a = 0; a < acceleration; a++) { increaseValue(false); @@ -480,8 +450,8 @@ public class VSlider extends SimpleFocusablePanel implements Field, increaseValue(false); } return true; - } else if (keycode == getNavigationDownKey() && vertical - || (keycode == getNavigationLeftKey() && !vertical)) { + } else if (keycode == getNavigationDownKey() && isVertical() + || (keycode == getNavigationLeftKey() && !isVertical())) { if (shift) { for (int a = 0; a < acceleration; a++) { decreaseValue(false); @@ -539,4 +509,119 @@ public class VSlider extends SimpleFocusablePanel implements Field, protected int getNavigationRightKey() { return KeyCodes.KEY_RIGHT; } + + public void setConnection(ApplicationConnection client) { + this.client = client; + } + + public void setId(String id) { + this.id = id; + } + + public void setImmediate(boolean immediate) { + this.immediate = immediate; + } + + public void setDisabled(boolean disabled) { + this.disabled = disabled; + } + + public void setReadOnly(boolean readonly) { + this.readonly = readonly; + } + + private boolean isVertical() { + return orientation == SliderOrientation.VERTICAL; + } + + public void setOrientation(SliderOrientation orientation) { + if (this.orientation != orientation) { + this.orientation = orientation; + + if (isVertical()) { + addStyleName(VSlider.CLASSNAME + "-vertical"); + } else { + removeStyleName(VSlider.CLASSNAME + "-vertical"); + } + } + } + + public void setMinValue(double value) { + min = value; + } + + public void setMaxValue(double value) { + max = value; + } + + public void setResolution(int resolution) { + this.resolution = resolution; + } + + public HandlerRegistration addValueChangeHandler( + ValueChangeHandler handler) { + return addHandler(handler, ValueChangeEvent.getType()); + } + + public Double getValue() { + return value; + } + + public void setValue(Double value) { + if (value < min) { + value = min; + } else if (value > max) { + value = max; + } + + // Update handle position + final String styleAttribute = isVertical() ? "marginTop" : "marginLeft"; + final String domProperty = isVertical() ? "offsetHeight" + : "offsetWidth"; + final int handleSize = Integer.parseInt(DOM.getElementProperty(handle, + domProperty)); + final int baseSize = Integer.parseInt(DOM.getElementProperty(base, + domProperty)) - (2 * BASE_BORDER_WIDTH); + + final int range = baseSize - handleSize; + double v = value.doubleValue(); + + // Round value to resolution + if (resolution > 0) { + v = Math.round(v * Math.pow(10, resolution)); + v = v / Math.pow(10, resolution); + } else { + v = Math.round(v); + } + final double valueRange = max - min; + double p = 0; + if (valueRange > 0) { + p = range * ((v - min) / valueRange); + } + if (p < 0) { + p = 0; + } + if (isVertical()) { + p = range - p; + } + final double pos = p; + + DOM.setStyleAttribute(handle, styleAttribute, (Math.round(pos)) + "px"); + + // Update value + this.value = new Double(v); + setFeedbackValue(v); + } + + public void setValue(Double value, boolean fireEvents) { + if (value == null) { + return; + } + + setValue(value); + + if (fireEvents) { + fireValueChanged(); + } + } } diff --git a/server/src/com/vaadin/ui/Slider.java b/server/src/com/vaadin/ui/Slider.java index d4e2db4853..a0b1d01b01 100644 --- a/server/src/com/vaadin/ui/Slider.java +++ b/server/src/com/vaadin/ui/Slider.java @@ -16,11 +16,9 @@ package com.vaadin.ui; -import java.util.Map; - -import com.vaadin.terminal.PaintException; -import com.vaadin.terminal.PaintTarget; -import com.vaadin.terminal.Vaadin6Component; +import com.vaadin.shared.ui.slider.SliderOrientation; +import com.vaadin.shared.ui.slider.SliderServerRpc; +import com.vaadin.shared.ui.slider.SliderState; /** * A component for selecting a numerical value within a range. @@ -41,9 +39,9 @@ import com.vaadin.terminal.Vaadin6Component; * vl.addComponent(volumeIndicator); * volumeIndicator.setValue("Current volume:" + 50.0); * slider.addListener(this); - * + * * } - * + * * public void setVolume(double d) { * volumeIndicator.setValue("Current volume: " + d); * } @@ -58,28 +56,29 @@ import com.vaadin.terminal.Vaadin6Component; * * @author Vaadin Ltd. */ -public class Slider extends AbstractField implements Vaadin6Component { - - public static final int ORIENTATION_HORIZONTAL = 0; - - public static final int ORIENTATION_VERTICAL = 1; +public class Slider extends AbstractField { - /** Minimum value of slider */ - private double min = 0; + private SliderServerRpc rpc = new SliderServerRpc() { - /** Maximum value of slider */ - private double max = 100; + @Override + public void valueChanged(double value) { - /** - * Resolution, how many digits are considered relevant after the decimal - * point. Must be a non-negative value - */ - private int resolution = 0; + try { + setValue(value, true); + } catch (final ValueOutOfBoundsException e) { + // Convert to nearest bound + double out = e.getValue().doubleValue(); + if (out < getState().getMinValue()) { + out = getState().getMinValue(); + } + if (out > getState().getMaxValue()) { + out = getState().getMaxValue(); + } + Slider.super.setValue(new Double(out), false); + } + } - /** - * Slider orientation (horizontal/vertical), defaults . - */ - private int orientation = ORIENTATION_HORIZONTAL; + }; /** * Default slider constructor. Sets all values to defaults and the slide @@ -88,7 +87,8 @@ public class Slider extends AbstractField implements Vaadin6Component { */ public Slider() { super(); - super.setValue(new Double(min)); + registerRpc(rpc); + super.setValue(new Double(getState().getMinValue())); } /** @@ -153,13 +153,18 @@ public class Slider extends AbstractField implements Vaadin6Component { setCaption(caption); } + @Override + public SliderState getState() { + return (SliderState) super.getState(); + } + /** * Gets the maximum slider value * * @return the largest value the slider can have */ public double getMax() { - return max; + return getState().getMaxValue(); } /** @@ -170,11 +175,10 @@ public class Slider extends AbstractField implements Vaadin6Component { * The new maximum slider value */ public void setMax(double max) { - this.max = max; + getState().setMaxValue(max); if (getValue() > max) { setValue(max); } - markAsDirty(); } /** @@ -183,7 +187,7 @@ public class Slider extends AbstractField implements Vaadin6Component { * @return the smallest value the slider can have */ public double getMin() { - return min; + return getState().getMinValue(); } /** @@ -194,33 +198,32 @@ public class Slider extends AbstractField implements Vaadin6Component { * The new minimum slider value */ public void setMin(double min) { - this.min = min; + getState().setMinValue(min); if (getValue() < min) { setValue(min); } - markAsDirty(); } /** * Get the current orientation of the slider (horizontal or vertical). * - * @return {@link #ORIENTATION_HORIZONTAL} or - * {@link #ORIENTATION_HORIZONTAL} + * @return {@link SliderOrientation#HORIZONTAL} or + * {@link SliderOrientation#VERTICAL} */ - public int getOrientation() { - return orientation; + public SliderOrientation getOrientation() { + return getState().getOrientation(); } /** * Set the orientation of the slider. * - * @param The - * new orientation, either {@link #ORIENTATION_HORIZONTAL} or - * {@link #ORIENTATION_VERTICAL} + * @param orientation + * The new orientation, either + * {@link SliderOrientation#HORIZONTAL} or + * {@link SliderOrientation#VERTICAL} */ - public void setOrientation(int orientation) { - this.orientation = orientation; - markAsDirty(); + public void setOrientation(SliderOrientation orientation) { + getState().setOrientation(orientation); } /** @@ -230,21 +233,24 @@ public class Slider extends AbstractField implements Vaadin6Component { * @return resolution */ public int getResolution() { - return resolution; + return getState().getResolution(); } /** * Set a new resolution for the slider. The resolution is the number of * digits after the decimal point. * + * @throws IllegalArgumentException + * if resolution is negative. + * * @param resolution */ public void setResolution(int resolution) { if (resolution < 0) { - return; + throw new IllegalArgumentException( + "Cannot set a negative resolution to Slider"); } - this.resolution = resolution; - markAsDirty(); + getState().setResolution(resolution); } /** @@ -261,87 +267,36 @@ public class Slider extends AbstractField implements Vaadin6Component { @Override protected void setValue(Double value, boolean repaintIsNotNeeded) { final double v = value.doubleValue(); + final int resolution = getResolution(); double newValue; + if (resolution > 0) { // Round up to resolution newValue = (int) (v * Math.pow(10, resolution)); newValue = newValue / Math.pow(10, resolution); - if (min > newValue || max < newValue) { + if (getMin() > newValue || getMax() < newValue) { throw new ValueOutOfBoundsException(value); } } else { newValue = (int) v; - if (min > newValue || max < newValue) { + if (getMin() > newValue || getMax() < newValue) { throw new ValueOutOfBoundsException(value); } } + + getState().setValue(newValue); super.setValue(newValue, repaintIsNotNeeded); } @Override - public void setValue(Object newFieldValue) - throws com.vaadin.data.Property.ReadOnlyException { - if (newFieldValue != null && newFieldValue instanceof Number - && !(newFieldValue instanceof Double)) { + public void setValue(Object newFieldValue) { + if (newFieldValue instanceof Number) { // Support setting all types of Numbers newFieldValue = ((Number) newFieldValue).doubleValue(); } - - super.setValue(newFieldValue); - } - - @Override - public void paintContent(PaintTarget target) throws PaintException { - - target.addAttribute("min", min); - if (max > min) { - target.addAttribute("max", max); - } else { - target.addAttribute("max", min); - } - target.addAttribute("resolution", resolution); - - if (resolution > 0) { - target.addVariable(this, "value", getValue().doubleValue()); - } else { - target.addVariable(this, "value", getValue().intValue()); - } - - if (orientation == ORIENTATION_VERTICAL) { - target.addAttribute("vertical", true); - } - - } - - /** - * Invoked when the value of a variable has changed. Slider listeners are - * notified if the slider value has changed. - * - * @param source - * @param variables - */ - @Override - public void changeVariables(Object source, Map variables) { - if (variables.containsKey("value")) { - final Object value = variables.get("value"); - final Double newValue = new Double(value.toString()); - if (newValue != null && newValue != getValue() - && !newValue.equals(getValue())) { - try { - setValue(newValue, true); - } catch (final ValueOutOfBoundsException e) { - // Convert to nearest bound - double out = e.getValue().doubleValue(); - if (out < min) { - out = min; - } - if (out > max) { - out = max; - } - super.setValue(new Double(out), false); - } - } - } + setValue(newFieldValue); + // The cast is safe if the above call returned without throwing + getState().setValue((Double) newFieldValue); } /** @@ -373,7 +328,6 @@ public class Slider extends AbstractField implements Vaadin6Component { public Double getValue() { return value; } - } @Override diff --git a/shared/src/com/vaadin/shared/ui/slider/SliderOrientation.java b/shared/src/com/vaadin/shared/ui/slider/SliderOrientation.java new file mode 100644 index 0000000000..d130550946 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/slider/SliderOrientation.java @@ -0,0 +1,5 @@ +package com.vaadin.shared.ui.slider; + +public enum SliderOrientation { + HORIZONTAL, VERTICAL; +} diff --git a/shared/src/com/vaadin/shared/ui/slider/SliderServerRpc.java b/shared/src/com/vaadin/shared/ui/slider/SliderServerRpc.java new file mode 100644 index 0000000000..6ea02f0a95 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/slider/SliderServerRpc.java @@ -0,0 +1,14 @@ +package com.vaadin.shared.ui.slider; + +import com.vaadin.shared.communication.ServerRpc; + +public interface SliderServerRpc extends ServerRpc { + + /** + * Invoked when the value of a variable has changed. Slider listeners are + * notified if the slider value has changed. + * + * @param value + */ + public void valueChanged(double value); +} diff --git a/shared/src/com/vaadin/shared/ui/slider/SliderState.java b/shared/src/com/vaadin/shared/ui/slider/SliderState.java new file mode 100644 index 0000000000..98168b80af --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/slider/SliderState.java @@ -0,0 +1,60 @@ +package com.vaadin.shared.ui.slider; + +import com.vaadin.shared.AbstractFieldState; + +public class SliderState extends AbstractFieldState { + + protected double value; + + protected double maxValue; + protected double minValue; + + /** + * The number of fractional digits that are considered significant. Must be + * non-negative. + */ + protected int resolution; + + protected SliderOrientation orientation; + + public double getValue() { + return value; + } + + public void setValue(double value) { + this.value = value; + } + + public double getMaxValue() { + return maxValue; + } + + public void setMaxValue(double maxValue) { + this.maxValue = maxValue; + } + + public double getMinValue() { + return minValue; + } + + public void setMinValue(double minValue) { + this.minValue = minValue; + } + + public int getResolution() { + return resolution; + } + + public void setResolution(int resolution) { + this.resolution = resolution; + } + + public SliderOrientation getOrientation() { + return orientation; + } + + public void setOrientation(SliderOrientation orientation) { + this.orientation = orientation; + } + +} diff --git a/tests/testbench/com/vaadin/tests/components/slider/SliderTest.java b/tests/testbench/com/vaadin/tests/components/slider/SliderTest.java index 9be1fea987..0b9c2d6c5a 100644 --- a/tests/testbench/com/vaadin/tests/components/slider/SliderTest.java +++ b/tests/testbench/com/vaadin/tests/components/slider/SliderTest.java @@ -2,6 +2,7 @@ package com.vaadin.tests.components.slider; import java.util.LinkedHashMap; +import com.vaadin.shared.ui.slider.SliderOrientation; import com.vaadin.tests.components.abstractfield.AbstractFieldTest; import com.vaadin.ui.Slider; @@ -21,9 +22,9 @@ public class SliderTest extends AbstractFieldTest { } }; - private Command orientationCommand = new Command() { + private Command orientationCommand = new Command() { @Override - public void execute(Slider c, Integer value, Object data) { + public void execute(Slider c, SliderOrientation value, Object data) { c.setOrientation(value); } }; @@ -56,9 +57,9 @@ public class SliderTest extends AbstractFieldTest { } private void createOrientationSelect(String category) { - LinkedHashMap options = new LinkedHashMap(); - options.put("Horizontal", Slider.ORIENTATION_HORIZONTAL); - options.put("Vertical", Slider.ORIENTATION_VERTICAL); + LinkedHashMap options = new LinkedHashMap(); + options.put("Horizontal", SliderOrientation.HORIZONTAL); + options.put("Vertical", SliderOrientation.VERTICAL); createSelectAction("Orientation", category, options, "Horizontal", orientationCommand); diff --git a/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java b/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java index 41a3d18f9f..a233191070 100644 --- a/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java +++ b/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java @@ -10,6 +10,7 @@ import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.event.Action; import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.label.ContentMode; +import com.vaadin.shared.ui.slider.SliderOrientation; import com.vaadin.terminal.ExternalResource; import com.vaadin.terminal.Page; import com.vaadin.terminal.Resource; @@ -39,7 +40,6 @@ import com.vaadin.ui.NativeSelect; import com.vaadin.ui.Notification; import com.vaadin.ui.Panel; import com.vaadin.ui.PopupView; -import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.Slider; import com.vaadin.ui.Slider.ValueOutOfBoundsException; import com.vaadin.ui.TabSheet; @@ -50,6 +50,7 @@ import com.vaadin.ui.TextArea; import com.vaadin.ui.TextField; import com.vaadin.ui.Tree; import com.vaadin.ui.TwinColSelect; +import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.VerticalSplitPanel; import com.vaadin.ui.Window; @@ -534,7 +535,7 @@ public class LiferayThemeDemo extends Application.LegacyApplication { l.addComponent(new Label("Vertical Slider", ContentMode.XHTML)); s = new Slider(); - s.setOrientation(Slider.ORIENTATION_VERTICAL); + s.setOrientation(SliderOrientation.VERTICAL); s.setHeight("200px"); try { s.setValue(50); -- cgit v1.2.3 From 3f4235c67fe174dad112fedcece85851fb83ef92 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 27 Aug 2012 15:58:01 +0300 Subject: Reverted accidentally commited fixed version number (#9413) --- shared/src/com/vaadin/shared/Version.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'shared') diff --git a/shared/src/com/vaadin/shared/Version.java b/shared/src/com/vaadin/shared/Version.java index 9320698318..16f466fc6e 100644 --- a/shared/src/com/vaadin/shared/Version.java +++ b/shared/src/com/vaadin/shared/Version.java @@ -47,10 +47,10 @@ public class Version implements Serializable { /* Initialize version numbers from string replaced by build-script. */ static { - if ("7.0.0.dev-20120816-12".equals("@" + "VERSION" + "@")) { + if ("@VERSION@".equals("@" + "VERSION" + "@")) { VERSION = "9.9.9.INTERNAL-DEBUG-BUILD"; } else { - VERSION = "7.0.0.dev-20120816-12"; + VERSION = "@VERSION@"; } final String[] digits = VERSION.split("\\.", 4); VERSION_MAJOR = Integer.parseInt(digits[0]); -- cgit v1.2.3