diff options
author | John Ahlroos <john@vaadin.com> | 2012-09-03 11:41:06 +0300 |
---|---|---|
committer | John Ahlroos <john@vaadin.com> | 2012-09-03 11:41:06 +0300 |
commit | 971b0684482dd3b7eb4efac09b9c24e1ea2b305d (patch) | |
tree | 6d6a4be640837500cfaa2f805a8602a9f4803871 | |
parent | 340cd7899812b444941584d383d930fe8155159b (diff) | |
parent | f85c152a48686a8a0dca38ca12b4f3509cac056f (diff) | |
download | vaadin-framework-971b0684482dd3b7eb4efac09b9c24e1ea2b305d.tar.gz vaadin-framework-971b0684482dd3b7eb4efac09b9c24e1ea2b305d.zip |
Merge branch 'master' into layoutgraph
Conflicts:
shared/src/com/vaadin/shared/ComponentState.java
149 files changed, 2207 insertions, 3084 deletions
diff --git a/WebContent/VAADIN/vaadinBootstrap.js b/WebContent/VAADIN/vaadinBootstrap.js index 1f5f3fa973..36cf2ec8eb 100644 --- a/WebContent/VAADIN/vaadinBootstrap.js +++ b/WebContent/VAADIN/vaadinBootstrap.js @@ -153,15 +153,11 @@ var bootstrapApp = function(mayDefer) { var themeUri = getConfig('themeUri'); - if (themeUri) { - loadTheme(themeUri); - } + loadTheme(themeUri); var widgetsetBase = getConfig('widgetsetBase'); var widgetset = getConfig('widgetset'); - if (widgetset && widgetsetBase) { - loadWidgetset(widgetsetBase, widgetset); - } + loadWidgetset(widgetsetBase, widgetset); if (getConfig('uidl') === undefined) { if (mayDefer) { diff --git a/client/src/com/vaadin/client/ComponentLocator.java b/client/src/com/vaadin/client/ComponentLocator.java index 03dd966538..dabea6c8d7 100644 --- a/client/src/com/vaadin/client/ComponentLocator.java +++ b/client/src/com/vaadin/client/ComponentLocator.java @@ -615,7 +615,7 @@ public class ComponentLocator { private ServerConnector findConnectorById(ServerConnector root, String id) { SharedState state = root.getState(); if (state instanceof ComponentState - && id.equals(((ComponentState) state).getId())) { + && id.equals(((ComponentState) state).id)) { return root; } for (ServerConnector child : root.getChildren()) { diff --git a/client/src/com/vaadin/client/LayoutManager.java b/client/src/com/vaadin/client/LayoutManager.java index b456010721..e7617a6b0b 100644 --- a/client/src/com/vaadin/client/LayoutManager.java +++ b/client/src/com/vaadin/client/LayoutManager.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -1121,7 +1121,8 @@ public class LayoutManager { int assignedHeight) { assert component.isRelativeHeight(); - float percentSize = parsePercent(component.getState().getHeight()); + float percentSize = parsePercent(component.getState().height == null ? "" + : component.getState().height); int effectiveHeight = Math.round(assignedHeight * (percentSize / 100)); reportOuterHeight(component, effectiveHeight); @@ -1144,7 +1145,8 @@ public class LayoutManager { int assignedWidth) { assert component.isRelativeWidth(); - float percentSize = parsePercent(component.getState().getWidth()); + float percentSize = parsePercent(component.getState().width == null ? "" + : component.getState().width); int effectiveWidth = Math.round(assignedWidth * (percentSize / 100)); reportOuterWidth(component, effectiveWidth); diff --git a/client/src/com/vaadin/client/Util.java b/client/src/com/vaadin/client/Util.java index f0caf4772f..f832dbfda2 100644 --- a/client/src/com/vaadin/client/Util.java +++ b/client/src/com/vaadin/client/Util.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -44,6 +44,7 @@ import com.vaadin.client.ui.VOverlay; import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.ComponentState; import com.vaadin.shared.communication.MethodInvocation; +import com.vaadin.shared.ui.ComponentStateUtil; public class Util { @@ -168,6 +169,9 @@ public class Util { * @return An escaped version of <literal>attribute</literal>. */ public static String escapeAttribute(String attribute) { + if (attribute == null) { + return ""; + } attribute = attribute.replace("\"", """); attribute = attribute.replace("'", "'"); attribute = attribute.replace(">", ">"); @@ -517,18 +521,20 @@ public class Util { * @return */ public static FloatSize parseRelativeSize(ComponentState state) { - if (state.isUndefinedHeight() && state.isUndefinedWidth()) { + if (ComponentStateUtil.isUndefinedHeight(state) + && ComponentStateUtil.isUndefinedWidth(state)) { return null; } - float relativeWidth = Util.parseRelativeSize(state.getWidth()); - float relativeHeight = Util.parseRelativeSize(state.getHeight()); + float relativeWidth = Util.parseRelativeSize(state.width); + float relativeHeight = Util.parseRelativeSize(state.height); FloatSize relativeSize = new FloatSize(relativeWidth, relativeHeight); return relativeSize; } + @Deprecated public static boolean isCached(UIDL uidl) { return uidl.getBooleanAttribute("cached"); diff --git a/client/src/com/vaadin/client/VCaption.java b/client/src/com/vaadin/client/VCaption.java index 58e0b847f0..aadc7b88ad 100644 --- a/client/src/com/vaadin/client/VCaption.java +++ b/client/src/com/vaadin/client/VCaption.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -25,6 +25,7 @@ import com.vaadin.client.ui.Icon; import com.vaadin.shared.AbstractFieldState; import com.vaadin.shared.ComponentConstants; import com.vaadin.shared.ComponentState; +import com.vaadin.shared.ui.ComponentStateUtil; public class VCaption extends HTML { @@ -110,8 +111,8 @@ public class VCaption extends HTML { placedAfterComponent = true; String style = CLASSNAME; - if (owner.getState().hasStyles()) { - for (String customStyle : owner.getState().getStyles()) { + if (ComponentStateUtil.hasStyles(owner.getState())) { + for (String customStyle : owner.getState().styles) { style += " " + CLASSNAME + "-" + customStyle; } } @@ -123,11 +124,11 @@ public class VCaption extends HTML { boolean hasIcon = owner.getState().resources .containsKey(ComponentConstants.ICON_RESOURCE); boolean showRequired = false; - boolean showError = owner.getState().getErrorMessage() != null; + boolean showError = owner.getState().errorMessage != null; if (owner.getState() instanceof AbstractFieldState) { AbstractFieldState abstractFieldState = (AbstractFieldState) owner .getState(); - showError = showError && !abstractFieldState.isHideErrors(); + showError = showError && !abstractFieldState.hideErrors; } if (owner instanceof AbstractFieldConnector) { showRequired = ((AbstractFieldConnector) owner).isRequired(); @@ -154,7 +155,7 @@ public class VCaption extends HTML { icon = null; } - if (owner.getState().getCaption() != null) { + if (owner.getState().caption != null) { // A caption text should be shown if the attribute is set // If the caption is null the ATTRIBUTE_CAPTION should not be set to // avoid ending up here. @@ -168,7 +169,7 @@ public class VCaption extends HTML { } // Update caption text - String c = owner.getState().getCaption(); + String c = owner.getState().caption; // A text forces the caption to be above the component. placedAfterComponent = false; if (c == null || c.trim().equals("")) { @@ -191,7 +192,8 @@ public class VCaption extends HTML { captionText = null; } - if (owner.getState().hasDescription() && captionText != null) { + if (ComponentStateUtil.hasDescription(owner.getState()) + && captionText != null) { addStyleDependentName("hasdescription"); } else { removeStyleDependentName("hasdescription"); @@ -392,13 +394,13 @@ public class VCaption extends HTML { } public static boolean isNeeded(ComponentState state) { - if (state.getCaption() != null) { + if (state.caption != null) { return true; } if (state.resources.containsKey(ComponentConstants.ICON_RESOURCE)) { return true; } - if (state.getErrorMessage() != null) { + if (state.errorMessage != null) { return true; } diff --git a/client/src/com/vaadin/client/VDebugConsole.java b/client/src/com/vaadin/client/VDebugConsole.java index bdb24066ca..2db5e028cf 100644 --- a/client/src/com/vaadin/client/VDebugConsole.java +++ b/client/src/com/vaadin/client/VDebugConsole.java @@ -924,7 +924,7 @@ public class VDebugConsole extends VOverlay implements Console { protected void dumpConnectorInfo(ApplicationConnection a) { UIConnector root = a.getRootConnector(); log("================"); - log("Connector hierarchy for Root: " + root.getState().getCaption() + log("Connector hierarchy for Root: " + root.getState().caption + " (" + root.getConnectorId() + ")"); Set<ServerConnector> connectorsInHierarchy = new HashSet<ServerConnector>(); SimpleTree rootHierachy = dumpConnectorHierarchy(root, "", diff --git a/client/src/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java b/client/src/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java index 7cab90a90d..f6d643d1ba 100644 --- a/client/src/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java +++ b/client/src/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -48,7 +48,7 @@ public class JavaScriptManagerConnector extends AbstractExtensionConnector { public void onStateChanged(StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); - Set<String> newNames = getState().getNames(); + Set<String> newNames = getState().names; // Current names now only contains orphan callbacks currentNames.removeAll(newNames); diff --git a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java index c886d2f94c..a17c3bc514 100644 --- a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java +++ b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java @@ -42,6 +42,7 @@ import com.vaadin.client.ui.datefield.PopupDateFieldConnector; import com.vaadin.shared.ComponentConstants; import com.vaadin.shared.ComponentState; import com.vaadin.shared.Connector; +import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.TabIndexState; import com.vaadin.ui.themes.BaseTheme; @@ -125,8 +126,8 @@ implements ComponentConnector { public void onStateChanged(StateChangeEvent stateChangeEvent) { ConnectorMap paintableMap = ConnectorMap.get(getConnection()); - if (getState().getId() != null) { - getWidget().getElement().setId(getState().getId()); + if (getState().id != null) { + getWidget().getElement().setId(getState().id); } else { getWidget().getElement().removeAttribute("id"); @@ -139,8 +140,8 @@ implements ComponentConnector { */ if (getState() instanceof TabIndexState && getWidget() instanceof Focusable) { - ((Focusable) getWidget()).setTabIndex(((TabIndexState) getState()) - .getTabIndex()); + ((Focusable) getWidget()) + .setTabIndex(((TabIndexState) getState()).tabIndex); } super.onStateChanged(stateChangeEvent); @@ -193,8 +194,8 @@ implements ComponentConnector { } private void updateComponentSize() { - String newWidth = getState().getWidth(); - String newHeight = getState().getHeight(); + String newWidth = getState().width == null ? "" : getState().width; + String newHeight = getState().height == null ? "" : getState().height; // Parent should be updated if either dimension changed between relative // and non-relative @@ -229,22 +230,22 @@ implements ComponentConnector { @Override public boolean isRelativeHeight() { - return getState().getHeight().endsWith("%"); + return getState().height != null && getState().height.endsWith("%"); } @Override public boolean isRelativeWidth() { - return getState().getWidth().endsWith("%"); + return getState().width != null && getState().width.endsWith("%"); } @Override public boolean isUndefinedHeight() { - return getState().getHeight().length() == 0; + return getState().height == null || getState().height.length() == 0; } @Override public boolean isUndefinedWidth() { - return getState().getWidth().length() == 0; + return getState().width == null && getState().width.length() == 0; } /* @@ -279,14 +280,14 @@ implements ComponentConnector { // add / remove error style name setWidgetStyleNameWithPrefix(primaryStyleName, ApplicationConnection.ERROR_CLASSNAME_EXT, - null != state.getErrorMessage()); + null != state.errorMessage); // add additional user defined style names as class names, prefixed with // component default class name. remove nonexistent style names. - if (state.hasStyles()) { + if (ComponentStateUtil.hasStyles(state)) { // add new style names List<String> newStyles = new ArrayList<String>(); - newStyles.addAll(state.getStyles()); + newStyles.addAll(state.styles); newStyles.removeAll(styleNames); for (String newStyle : newStyles) { setWidgetStyleName(newStyle, true); @@ -294,14 +295,14 @@ implements ComponentConnector { true); } // remove nonexistent style names - styleNames.removeAll(state.getStyles()); + styleNames.removeAll(state.styles); for (String oldStyle : styleNames) { setWidgetStyleName(oldStyle, false); setWidgetStyleNameWithPrefix(primaryStyleName + "-", oldStyle, false); } styleNames.clear(); - styleNames.addAll(state.getStyles()); + styleNames.addAll(state.styles); } else { // remove all old style names for (String oldStyle : styleNames) { @@ -374,7 +375,7 @@ implements ComponentConnector { @Override @Deprecated public boolean isReadOnly() { - return getState().isReadOnly(); + return getState().readOnly; } @Override @@ -393,7 +394,7 @@ implements ComponentConnector { */ @Override public boolean hasEventListener(String eventIdentifier) { - Set<String> reg = getState().getRegisteredEventListeners(); + Set<String> reg = getState().registeredEventListeners; return (reg != null && reg.contains(eventIdentifier)); } @@ -426,8 +427,7 @@ implements ComponentConnector { */ @Override public TooltipInfo getTooltipInfo(Element element) { - return new TooltipInfo(getState().getDescription(), getState() - .getErrorMessage()); + return new TooltipInfo(getState().description, getState().errorMessage); } /** diff --git a/client/src/com/vaadin/client/ui/AbstractConnector.java b/client/src/com/vaadin/client/ui/AbstractConnector.java index 2820b7b2c1..bad374c2f0 100644 --- a/client/src/com/vaadin/client/ui/AbstractConnector.java +++ b/client/src/com/vaadin/client/ui/AbstractConnector.java @@ -333,7 +333,7 @@ StateChangeHandler { @Override public boolean isEnabled() { - if (!getState().isEnabled()) { + if (!getState().enabled) { return false; } diff --git a/client/src/com/vaadin/client/ui/AbstractFieldConnector.java b/client/src/com/vaadin/client/ui/AbstractFieldConnector.java index 9a6f285187..1ba371c448 100644 --- a/client/src/com/vaadin/client/ui/AbstractFieldConnector.java +++ b/client/src/com/vaadin/client/ui/AbstractFieldConnector.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -27,11 +27,11 @@ public abstract class AbstractFieldConnector extends AbstractComponentConnector @Override public boolean isReadOnly() { - return super.isReadOnly() || getState().isPropertyReadOnly(); + return super.isReadOnly() || getState().propertyReadOnly; } public boolean isModified() { - return getState().isModified(); + return getState().modified; } /** @@ -43,7 +43,7 @@ public abstract class AbstractFieldConnector extends AbstractComponentConnector * @return true if required indicator should be shown */ public boolean isRequired() { - return getState().isRequired() && !isReadOnly(); + return getState().required && !isReadOnly(); } @Override diff --git a/client/src/com/vaadin/client/ui/MediaBaseConnector.java b/client/src/com/vaadin/client/ui/MediaBaseConnector.java index 8a17e052ba..961ba4821e 100644 --- a/client/src/com/vaadin/client/ui/MediaBaseConnector.java +++ b/client/src/com/vaadin/client/ui/MediaBaseConnector.java @@ -49,12 +49,12 @@ public abstract class MediaBaseConnector extends AbstractComponentConnector { public void onStateChanged(StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); - for (int i = 0; i < getState().getSources().size(); i++) { - URLReference source = getState().getSources().get(i); - String sourceType = getState().getSourceTypes().get(i); + for (int i = 0; i < getState().sources.size(); i++) { + URLReference source = getState().sources.get(i); + String sourceType = getState().sourceTypes.get(i); getWidget().addSource(source.getURL(), sourceType); } - setAltText(getState().getAltText()); + setAltText(getState().altText); } @Override @@ -66,7 +66,7 @@ public abstract class MediaBaseConnector extends AbstractComponentConnector { if (altText == null || "".equals(altText)) { altText = getDefaultAltHtml(); - } else if (!getState().isHtmlContentAllowed()) { + } else if (!getState().htmlContentAllowed) { altText = Util.escapeHTML(altText); } getWidget().setAltText(altText); diff --git a/client/src/com/vaadin/client/ui/UI/UIConnector.java b/client/src/com/vaadin/client/ui/UI/UIConnector.java index 920bf152f9..cb8b0ece9e 100644 --- a/client/src/com/vaadin/client/ui/UI/UIConnector.java +++ b/client/src/com/vaadin/client/ui/UI/UIConnector.java @@ -52,6 +52,7 @@ import com.vaadin.client.ui.layout.MayScrollChildren; import com.vaadin.client.ui.notification.VNotification; import com.vaadin.client.ui.window.WindowConnector; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.Connect.LoadStyle; import com.vaadin.shared.ui.ui.PageClientRpc; @@ -91,7 +92,7 @@ public class UIConnector extends AbstractComponentContainerConnector implements public void onResize(ResizeEvent event) { rpc.resize(event.getHeight(), event.getWidth(), Window.getClientWidth(), Window.getClientHeight()); - if (getState().isImmediate()) { + if (getState().immediate) { getConnection().sendPendingVariableChanges(); } } @@ -106,7 +107,7 @@ public class UIConnector extends AbstractComponentContainerConnector implements boolean firstPaint = getWidget().connection == null; getWidget().connection = client; - getWidget().immediate = getState().isImmediate(); + getWidget().immediate = getState().immediate; getWidget().resizeLazy = uidl.hasAttribute(UIConstants.RESIZE_LAZY); String newTheme = uidl.getStringAttribute("theme"); if (getWidget().theme != null && !newTheme.equals(getWidget().theme)) { @@ -119,8 +120,8 @@ public class UIConnector extends AbstractComponentContainerConnector implements // this also implicitly removes old styles String styles = ""; styles += getWidget().getStylePrimaryName() + " "; - if (getState().hasStyles()) { - for (String style : getState().getStyles()) { + if (ComponentStateUtil.hasStyles(getState())) { + for (String style : getState().styles) { styles += style + " "; } } @@ -338,7 +339,7 @@ public class UIConnector extends AbstractComponentContainerConnector implements } protected ComponentConnector getContent() { - return (ComponentConnector) getState().getContent(); + return (ComponentConnector) getState().content; } protected void onChildSizeChange() { diff --git a/client/src/com/vaadin/client/ui/absolutelayout/AbsoluteLayoutConnector.java b/client/src/com/vaadin/client/ui/absolutelayout/AbsoluteLayoutConnector.java index b453499c27..be29f5f512 100644 --- a/client/src/com/vaadin/client/ui/absolutelayout/AbsoluteLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/absolutelayout/AbsoluteLayoutConnector.java @@ -126,7 +126,8 @@ public class AbsoluteLayoutConnector extends for (ComponentConnector child : getChildComponents()) { getWrapper(child).setPosition( - getState().getConnectorPosition(child)); + getState().connectorToCssPosition.get(child + .getConnectorId())); } }; diff --git a/client/src/com/vaadin/client/ui/audio/AudioConnector.java b/client/src/com/vaadin/client/ui/audio/AudioConnector.java index 8c2fa179c8..bfa282ca09 100644 --- a/client/src/com/vaadin/client/ui/audio/AudioConnector.java +++ b/client/src/com/vaadin/client/ui/audio/AudioConnector.java @@ -35,7 +35,7 @@ public class AudioConnector extends MediaBaseConnector { Style style = getWidget().getElement().getStyle(); // Make sure that the controls are not clipped if visible. - if (getState().isShowControls() + if (getState().showControls && (style.getHeight() == null || "".equals(style.getHeight()))) { if (BrowserInfo.get().isChrome()) { style.setHeight(32, Unit.PX); diff --git a/client/src/com/vaadin/client/ui/button/ButtonConnector.java b/client/src/com/vaadin/client/ui/button/ButtonConnector.java index 65acddb0a4..b15813c99e 100644 --- a/client/src/com/vaadin/client/ui/button/ButtonConnector.java +++ b/client/src/com/vaadin/client/ui/button/ButtonConnector.java @@ -65,7 +65,7 @@ public class ButtonConnector extends AbstractComponentConnector implements addStateChangeHandler("errorMessage", new StateChangeHandler() { @Override public void onStateChanged(StateChangeEvent stateChangeEvent) { - if (null != getState().getErrorMessage()) { + if (null != getState().errorMessage) { if (getWidget().errorIndicatorElement == null) { getWidget().errorIndicatorElement = DOM.createSpan(); getWidget().errorIndicatorElement @@ -117,14 +117,14 @@ public class ButtonConnector extends AbstractComponentConnector implements if (changedProperties.contains("caption") || changedProperties.contains("htmlContentAllowed")) { // Set text - if (getState().isHtmlContentAllowed()) { - getWidget().setHtml(getState().getCaption()); + if (getState().htmlContentAllowed) { + getWidget().setHtml(getState().caption); } else { - getWidget().setText(getState().getCaption()); + getWidget().setText(getState().caption); } } - getWidget().clickShortcut = getState().getClickShortcutKeyCode(); + getWidget().clickShortcut = getState().clickShortcutKeyCode; } @Override @@ -153,7 +153,7 @@ public class ButtonConnector extends AbstractComponentConnector implements @Override public void onClick(ClickEvent event) { - if (getState().isDisableOnClick()) { + if (getState().disableOnClick) { getWidget().setEnabled(false); rpc.disableOnClick(); } diff --git a/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java b/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java index 1a6547a85c..35816039da 100644 --- a/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java +++ b/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java @@ -73,7 +73,7 @@ public class CheckBoxConnector extends AbstractFieldConnector implements blurHandlerRegistration = EventHelper.updateBlurHandler(this, blurHandlerRegistration); - if (null != getState().getErrorMessage()) { + if (null != getState().errorMessage) { if (getWidget().errorIndicatorElement == null) { getWidget().errorIndicatorElement = DOM.createSpan(); getWidget().errorIndicatorElement.setInnerHTML(" "); @@ -113,9 +113,9 @@ public class CheckBoxConnector extends AbstractFieldConnector implements } // Set text - getWidget().setText(getState().getCaption()); - getWidget().setValue(getState().isChecked()); - getWidget().immediate = getState().isImmediate(); + getWidget().setText(getState().caption); + getWidget().setValue(getState().checked); + getWidget().immediate = getState().immediate; } @Override diff --git a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java index fc060f3deb..d89836d6e2 100644 --- a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java +++ b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java @@ -71,7 +71,7 @@ public class ComboBoxConnector extends AbstractFieldConnector implements getWidget().filteringmode = uidl.getIntAttribute("filteringmode"); } - getWidget().immediate = getState().isImmediate(); + getWidget().immediate = getState().immediate; getWidget().nullSelectionAllowed = uidl.hasAttribute("nullselect"); diff --git a/client/src/com/vaadin/client/ui/combobox/VFilterSelect.java b/client/src/com/vaadin/client/ui/combobox/VFilterSelect.java index 9bf758fcba..8692622892 100644 --- a/client/src/com/vaadin/client/ui/combobox/VFilterSelect.java +++ b/client/src/com/vaadin/client/ui/combobox/VFilterSelect.java @@ -72,6 +72,7 @@ import com.vaadin.client.ui.menubar.MenuBar; import com.vaadin.client.ui.menubar.MenuItem; import com.vaadin.shared.ComponentState; import com.vaadin.shared.EventId; +import com.vaadin.shared.ui.ComponentStateUtil; /** * Client side implementation of the Select component. @@ -580,8 +581,8 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, */ public void updateStyleNames(UIDL uidl, ComponentState componentState) { setStyleName(CLASSNAME + "-suggestpopup"); - if (componentState.hasStyles()) { - for (String style : componentState.getStyles()) { + if (ComponentStateUtil.hasStyles(componentState)) { + for (String style : componentState.styles) { if (!"".equals(style)) { addStyleDependentName(style); } diff --git a/client/src/com/vaadin/client/ui/csslayout/CssLayoutConnector.java b/client/src/com/vaadin/client/ui/csslayout/CssLayoutConnector.java index 0d7e511ddb..cc1d15e026 100644 --- a/client/src/com/vaadin/client/ui/csslayout/CssLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/csslayout/CssLayoutConnector.java @@ -75,10 +75,10 @@ public class CssLayoutConnector extends AbstractLayoutConnector { super.onStateChanged(stateChangeEvent); for (ComponentConnector child : getChildComponents()) { - if (!getState().getChildCss().containsKey(child)) { + if (!getState().childCss.containsKey(child)) { continue; } - String css = getState().getChildCss().get(child); + String css = getState().childCss.get(child); Style style = child.getWidget().getElement().getStyle(); // should we remove styles also? How can we know what we have added // as it is added directly to the child component? diff --git a/client/src/com/vaadin/client/ui/customlayout/CustomLayoutConnector.java b/client/src/com/vaadin/client/ui/customlayout/CustomLayoutConnector.java index c06bbd5391..0049a4dd3d 100644 --- a/client/src/com/vaadin/client/ui/customlayout/CustomLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/customlayout/CustomLayoutConnector.java @@ -62,8 +62,8 @@ public class CustomLayoutConnector extends AbstractLayoutConnector implements // later on. return; } - String templateName = getState().getTemplateName(); - String templateContents = getState().getTemplateContents(); + String templateName = getState().templateName; + String templateContents = getState().templateContents; if (templateName != null) { // Get the HTML-template from client. Overrides templateContents @@ -92,7 +92,7 @@ public class CustomLayoutConnector extends AbstractLayoutConnector implements // For all contained widgets for (ComponentConnector child : getChildComponents()) { - String location = getState().getChildLocations().get(child); + String location = getState().childLocations.get(child); try { getWidget().setWidget(child.getWidget(), location); } catch (final IllegalArgumentException e) { diff --git a/client/src/com/vaadin/client/ui/datefield/AbstractDateFieldConnector.java b/client/src/com/vaadin/client/ui/datefield/AbstractDateFieldConnector.java index 62facc380c..cc98767e00 100644 --- a/client/src/com/vaadin/client/ui/datefield/AbstractDateFieldConnector.java +++ b/client/src/com/vaadin/client/ui/datefield/AbstractDateFieldConnector.java @@ -37,7 +37,7 @@ public class AbstractDateFieldConnector extends AbstractFieldConnector // Save details getWidget().client = client; getWidget().paintableId = uidl.getId(); - getWidget().immediate = getState().isImmediate(); + getWidget().immediate = getState().immediate; getWidget().readonly = isReadOnly(); getWidget().enabled = isEnabled(); diff --git a/client/src/com/vaadin/client/ui/draganddropwrapper/DragAndDropWrapperConnector.java b/client/src/com/vaadin/client/ui/draganddropwrapper/DragAndDropWrapperConnector.java index 96c68bbbb5..3bbc6f05d1 100644 --- a/client/src/com/vaadin/client/ui/draganddropwrapper/DragAndDropWrapperConnector.java +++ b/client/src/com/vaadin/client/ui/draganddropwrapper/DragAndDropWrapperConnector.java @@ -73,7 +73,7 @@ public class DragAndDropWrapperConnector extends CustomComponentConnector .getMapAttribute(DragAndDropWrapperConstants.HTML5_DATA_FLAVORS); // Used to prevent wrapper from stealing tooltips when not defined - getWidget().hasTooltip = getState().hasDescription(); + getWidget().hasTooltip = getState().description != null; } } diff --git a/client/src/com/vaadin/client/ui/embedded/EmbeddedConnector.java b/client/src/com/vaadin/client/ui/embedded/EmbeddedConnector.java index dffb73f099..2a1b4dcc44 100644 --- a/client/src/com/vaadin/client/ui/embedded/EmbeddedConnector.java +++ b/client/src/com/vaadin/client/ui/embedded/EmbeddedConnector.java @@ -101,8 +101,8 @@ public class EmbeddedConnector extends AbstractComponentConnector implements // Set attributes Style style = el.getStyle(); - style.setProperty("width", getState().getWidth()); - style.setProperty("height", getState().getHeight()); + style.setProperty("width", getState().width); + style.setProperty("height", getState().height); DOM.setElementProperty(el, "src", getWidget().getSrc(uidl, client)); diff --git a/client/src/com/vaadin/client/ui/embedded/VEmbedded.java b/client/src/com/vaadin/client/ui/embedded/VEmbedded.java index 239bb4ad46..4dc85cd10c 100644 --- a/client/src/com/vaadin/client/ui/embedded/VEmbedded.java +++ b/client/src/com/vaadin/client/ui/embedded/VEmbedded.java @@ -100,8 +100,8 @@ public class VEmbedded extends HTML { ComponentConnector paintable = ConnectorMap.get(client).getConnector( this); - String height = paintable.getState().getHeight(); - String width = paintable.getState().getWidth(); + String height = paintable.getState().height; + String width = paintable.getState().width; // Add width and height html.append("width=\"" + Util.escapeAttribute(width) + "\" "); diff --git a/client/src/com/vaadin/client/ui/embeddedbrowser/EmbeddedBrowserConnector.java b/client/src/com/vaadin/client/ui/embeddedbrowser/EmbeddedBrowserConnector.java index b0cd6d773d..10445dbff5 100644 --- a/client/src/com/vaadin/client/ui/embeddedbrowser/EmbeddedBrowserConnector.java +++ b/client/src/com/vaadin/client/ui/embeddedbrowser/EmbeddedBrowserConnector.java @@ -29,7 +29,7 @@ public class EmbeddedBrowserConnector extends AbstractComponentConnector { super.onStateChanged(stateChangeEvent); - getWidget().setAlternateText(getState().getAlternateText()); + getWidget().setAlternateText(getState().alternateText); getWidget().setSource( getResourceUrl(AbstractEmbeddedState.SOURCE_RESOURCE)); getWidget().setName(getConnectorId()); diff --git a/client/src/com/vaadin/client/ui/flash/FlashConnector.java b/client/src/com/vaadin/client/ui/flash/FlashConnector.java index cc5423dd20..eaccc4736c 100644 --- a/client/src/com/vaadin/client/ui/flash/FlashConnector.java +++ b/client/src/com/vaadin/client/ui/flash/FlashConnector.java @@ -31,13 +31,13 @@ public class FlashConnector extends AbstractComponentConnector { getWidget().setSource( getResourceUrl(AbstractEmbeddedState.SOURCE_RESOURCE)); - 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().setArchive(getState().archive); + getWidget().setClassId(getState().classId); + getWidget().setCodebase(getState().codebase); + getWidget().setCodetype(getState().codetype); + getWidget().setStandby(getState().standby); + getWidget().setAlternateText(getState().alternateText); + getWidget().setEmbedParams(getState().embedParams); getWidget().rebuildIfNeeded(); } diff --git a/client/src/com/vaadin/client/ui/form/FormConnector.java b/client/src/com/vaadin/client/ui/form/FormConnector.java index 1b97bbc4cb..25b4a76a09 100644 --- a/client/src/com/vaadin/client/ui/form/FormConnector.java +++ b/client/src/com/vaadin/client/ui/form/FormConnector.java @@ -29,6 +29,7 @@ import com.vaadin.client.ui.ShortcutActionHandler; import com.vaadin.client.ui.layout.ElementResizeEvent; import com.vaadin.client.ui.layout.ElementResizeListener; import com.vaadin.client.ui.layout.MayScrollChildren; +import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.form.FormState; import com.vaadin.ui.Form; @@ -81,8 +82,8 @@ public class FormConnector extends AbstractComponentContainerConnector } boolean legendEmpty = true; - if (getState().getCaption() != null) { - getWidget().caption.setInnerText(getState().getCaption()); + if (getState().caption != null) { + getWidget().caption.setInnerText(getState().caption); legendEmpty = false; } else { getWidget().caption.setInnerText(""); @@ -105,16 +106,15 @@ public class FormConnector extends AbstractComponentContainerConnector getWidget().removeStyleDependentName("nocaption"); } - if (null != getState().getErrorMessage()) { - getWidget().errorMessage - .updateMessage(getState().getErrorMessage()); + if (null != getState().errorMessage) { + getWidget().errorMessage.updateMessage(getState().errorMessage); getWidget().errorMessage.setVisible(true); } else { getWidget().errorMessage.setVisible(false); } - if (getState().hasDescription()) { - getWidget().desc.setInnerHTML(getState().getDescription()); + if (ComponentStateUtil.hasDescription(getState())) { + getWidget().desc.setInnerHTML(getState().description); if (getWidget().desc.getParentElement() == null) { getWidget().fieldSet.insertAfter(getWidget().desc, getWidget().legend); @@ -128,10 +128,9 @@ public class FormConnector extends AbstractComponentContainerConnector // first render footer so it will be easier to handle relative height of // main layout - if (getState().getFooter() != null) { + if (getState().footer != null) { // render footer - ComponentConnector newFooter = (ComponentConnector) getState() - .getFooter(); + ComponentConnector newFooter = (ComponentConnector) getState().footer; Widget newFooterWidget = newFooter.getWidget(); if (getWidget().footer == null) { getLayoutManager().addElementResizeListener( @@ -158,8 +157,7 @@ public class FormConnector extends AbstractComponentContainerConnector } } - ComponentConnector newLayout = (ComponentConnector) getState() - .getLayout(); + ComponentConnector newLayout = (ComponentConnector) getState().layout; Widget newLayoutWidget = newLayout.getWidget(); if (getWidget().lo == null) { // Layout not rendered before @@ -208,7 +206,7 @@ public class FormConnector extends AbstractComponentContainerConnector @Override public boolean isReadOnly() { - return super.isReadOnly() || getState().isPropertyReadOnly(); + return super.isReadOnly() || getState().propertyReadOnly; } @Override diff --git a/client/src/com/vaadin/client/ui/formlayout/FormLayoutConnector.java b/client/src/com/vaadin/client/ui/formlayout/FormLayoutConnector.java index c1c6cee324..c78137345f 100644 --- a/client/src/com/vaadin/client/ui/formlayout/FormLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/formlayout/FormLayoutConnector.java @@ -46,9 +46,8 @@ public class FormLayoutConnector extends AbstractLayoutConnector { VFormLayoutTable formLayoutTable = getWidget().table; - formLayoutTable.setMargins(new MarginInfo(getState() - .getMarginsBitmask())); - formLayoutTable.setSpacing(getState().isSpacing()); + formLayoutTable.setMargins(new MarginInfo(getState().marginsBitmask)); + formLayoutTable.setSpacing(getState().spacing); } @@ -99,12 +98,11 @@ public class FormLayoutConnector extends AbstractLayoutConnector { // FIXME This incorrectly depends on AbstractFieldConnector if (component instanceof AbstractFieldConnector) { - hideErrors = ((AbstractFieldConnector) component).getState() - .isHideErrors(); + hideErrors = ((AbstractFieldConnector) component).getState().hideErrors; } - getWidget().table.updateError(component.getWidget(), component - .getState().getErrorMessage(), hideErrors); + getWidget().table.updateError(component.getWidget(), + component.getState().errorMessage, hideErrors); } @Override diff --git a/client/src/com/vaadin/client/ui/formlayout/VFormLayout.java b/client/src/com/vaadin/client/ui/formlayout/VFormLayout.java index 890275dfe4..f2f6e0bc72 100644 --- a/client/src/com/vaadin/client/ui/formlayout/VFormLayout.java +++ b/client/src/com/vaadin/client/ui/formlayout/VFormLayout.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -38,6 +38,7 @@ import com.vaadin.client.ui.AbstractFieldConnector; import com.vaadin.client.ui.Icon; import com.vaadin.shared.ComponentConstants; import com.vaadin.shared.ComponentState; +import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.MarginInfo; /** @@ -66,8 +67,8 @@ public class VFormLayout extends SimplePanel { */ private String[] getStylesFromState(ComponentState state, boolean enabled) { List<String> styles = new ArrayList<String>(); - if (state.hasStyles()) { - for (String name : state.getStyles()) { + if (ComponentStateUtil.hasStyles(state)) { + for (String name : state.styles) { styles.add(name); } } @@ -271,13 +272,13 @@ public class VFormLayout extends SimplePanel { } - if (state.getCaption() != null) { + if (state.caption != null) { if (captionText == null) { captionText = DOM.createSpan(); DOM.insertChild(getElement(), captionText, icon == null ? 0 : 1); } - String c = state.getCaption(); + String c = state.caption; if (c == null) { c = ""; } else { @@ -288,7 +289,7 @@ public class VFormLayout extends SimplePanel { // TODO should span also be removed } - if (state.hasDescription() && captionText != null) { + if (state.description != null && captionText != null) { addStyleDependentName("hasdescription"); } else { removeStyleDependentName("hasdescription"); diff --git a/client/src/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java b/client/src/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java index 16c82c2d21..317836370c 100644 --- a/client/src/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java @@ -106,8 +106,8 @@ public class GridLayoutConnector extends AbstractComponentContainerConnector return; } - int cols = getState().getColumns(); - int rows = getState().getRows(); + int cols = getState().columns; + int rows = getState().rows; layout.columnWidths = new int[cols]; layout.rowHeights = new int[rows]; @@ -164,9 +164,9 @@ public class GridLayoutConnector extends AbstractComponentContainerConnector layout.rowExpandRatioArray = uidl.getIntArrayAttribute("rowExpand"); layout.updateMarginStyleNames(new MarginInfo(getState() - .getMarginsBitmask())); +.marginsBitmask)); - layout.updateSpacingStyleName(getState().isSpacing()); + layout.updateSpacingStyleName(getState().spacing); if (needCaptionUpdate) { needCaptionUpdate = false; diff --git a/client/src/com/vaadin/client/ui/image/ImageConnector.java b/client/src/com/vaadin/client/ui/image/ImageConnector.java index 7c3eb973d2..22067b051e 100644 --- a/client/src/com/vaadin/client/ui/image/ImageConnector.java +++ b/client/src/com/vaadin/client/ui/image/ImageConnector.java @@ -50,7 +50,7 @@ public class ImageConnector extends AbstractComponentConnector { getWidget().setUrl( getResourceUrl(AbstractEmbeddedState.SOURCE_RESOURCE)); - getWidget().setAltText(getState().getAlternateText()); + getWidget().setAltText(getState().alternateText); } protected final ClickEventHandler clickEventHandler = new ClickEventHandler( diff --git a/client/src/com/vaadin/client/ui/layout/LayoutDependencyTree.java b/client/src/com/vaadin/client/ui/layout/LayoutDependencyTree.java index ff2346d5ac..b94488896e 100644 --- a/client/src/com/vaadin/client/ui/layout/LayoutDependencyTree.java +++ b/client/src/com/vaadin/client/ui/layout/LayoutDependencyTree.java @@ -311,8 +311,8 @@ public class LayoutDependencyTree { } ComponentState state = connector.getState(); s += " sizing: " - + getSizeDefinition(direction == VERTICAL ? state - .getHeight() : state.getWidth()) + "\n"; + + getSizeDefinition(direction == VERTICAL ? state.height + : state.width) + "\n"; if (needsLayout) { s += "Needs layout\n"; diff --git a/client/src/com/vaadin/client/ui/link/LinkConnector.java b/client/src/com/vaadin/client/ui/link/LinkConnector.java index 26e0e78654..d7e5f0b25f 100644 --- a/client/src/com/vaadin/client/ui/link/LinkConnector.java +++ b/client/src/com/vaadin/client/ui/link/LinkConnector.java @@ -85,10 +85,10 @@ public class LinkConnector extends AbstractComponentConnector implements .getIntAttribute("targetWidth") : -1; // Set link caption - getWidget().captionElement.setInnerText(getState().getCaption()); + getWidget().captionElement.setInnerText(getState().caption); // handle error - if (null != getState().getErrorMessage()) { + if (null != getState().errorMessage) { if (getWidget().errorIndicatorElement == null) { getWidget().errorIndicatorElement = DOM.createDiv(); DOM.setElementProperty(getWidget().errorIndicatorElement, diff --git a/client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java b/client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java index d187468ee5..fcd1a3bdac 100644 --- a/client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java +++ b/client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java @@ -29,6 +29,7 @@ import com.vaadin.client.Util; import com.vaadin.client.ui.AbstractComponentConnector; import com.vaadin.client.ui.Icon; import com.vaadin.client.ui.SimpleManagedLayout; +import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.Connect.LoadStyle; import com.vaadin.shared.ui.menubar.MenuBarConstants; @@ -69,7 +70,8 @@ public class MenuBarConnector extends AbstractComponentConnector implements UIDL options = uidl.getChildUIDL(0); - if (null != getState() && !getState().isUndefinedWidth()) { + if (null != getState() + && !ComponentStateUtil.isUndefinedWidth(getState())) { UIDL moreItemUIDL = options.getChildUIDL(0); StringBuffer itemHTML = new StringBuffer(); @@ -141,8 +143,8 @@ public class MenuBarConnector extends AbstractComponentConnector implements // this is the top-level style that also propagates to items - // any item specific styles are set above in // currentItem.updateFromUIDL(item, client) - if (getState().hasStyles()) { - for (String style : getState().getStyles()) { + if (ComponentStateUtil.hasStyles(getState())) { + for (String style : getState().styles) { currentMenu.addStyleDependentName(style); } } diff --git a/client/src/com/vaadin/client/ui/nativebutton/NativeButtonConnector.java b/client/src/com/vaadin/client/ui/nativebutton/NativeButtonConnector.java index e821ae1422..75a4d3f893 100644 --- a/client/src/com/vaadin/client/ui/nativebutton/NativeButtonConnector.java +++ b/client/src/com/vaadin/client/ui/nativebutton/NativeButtonConnector.java @@ -61,21 +61,21 @@ public class NativeButtonConnector extends AbstractComponentConnector implements public void onStateChanged(StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); - getWidget().disableOnClick = getState().isDisableOnClick(); + getWidget().disableOnClick = getState().disableOnClick; focusHandlerRegistration = EventHelper.updateFocusHandler(this, focusHandlerRegistration); blurHandlerRegistration = EventHelper.updateBlurHandler(this, blurHandlerRegistration); // Set text - if (getState().isHtmlContentAllowed()) { - getWidget().setHTML(getState().getCaption()); + if (getState().htmlContentAllowed) { + getWidget().setHTML(getState().caption); } else { - getWidget().setText(getState().getCaption()); + getWidget().setText(getState().caption); } // handle error - if (null != getState().getErrorMessage()) { + if (null != getState().errorMessage) { if (getWidget().errorIndicatorElement == null) { getWidget().errorIndicatorElement = DOM.createSpan(); getWidget().errorIndicatorElement diff --git a/client/src/com/vaadin/client/ui/optiongroup/OptionGroupBaseConnector.java b/client/src/com/vaadin/client/ui/optiongroup/OptionGroupBaseConnector.java index 9367176c76..0081ff3c70 100644 --- a/client/src/com/vaadin/client/ui/optiongroup/OptionGroupBaseConnector.java +++ b/client/src/com/vaadin/client/ui/optiongroup/OptionGroupBaseConnector.java @@ -43,7 +43,7 @@ public abstract class OptionGroupBaseConnector extends AbstractFieldConnector getWidget().disabled = !isEnabled(); getWidget().multiselect = "multi".equals(uidl .getStringAttribute("selectmode")); - getWidget().immediate = getState().isImmediate(); + getWidget().immediate = getState().immediate; getWidget().nullSelectionAllowed = uidl .getBooleanAttribute("nullselect"); getWidget().nullSelectionItemAvailable = uidl diff --git a/client/src/com/vaadin/client/ui/orderedlayout/AbstractBoxLayoutConnector.java b/client/src/com/vaadin/client/ui/orderedlayout/AbstractBoxLayoutConnector.java index a4fcea81f5..6402d0696f 100644 --- a/client/src/com/vaadin/client/ui/orderedlayout/AbstractBoxLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/orderedlayout/AbstractBoxLayoutConnector.java @@ -108,23 +108,23 @@ public abstract class AbstractBoxLayoutConnector extends Slot slot = getWidget().getSlot(child); - String caption = child.getState().getCaption(); + String caption = child.getState().caption; URLReference iconUrl = child.getState().resources .get(ComponentConstants.ICON_RESOURCE); String iconUrlString = iconUrl != null ? iconUrl.toString() : null; - List<String> styles = child.getState().getStyles(); - String error = child.getState().getErrorMessage(); + List<String> styles = child.getState().styles; + String error = child.getState().errorMessage; boolean showError = error != null; if (child.getState() instanceof AbstractFieldState) { AbstractFieldState abstractFieldState = (AbstractFieldState) child .getState(); - showError = showError && !abstractFieldState.isHideErrors(); + showError = showError && !abstractFieldState.hideErrors; } boolean required = false; if (child instanceof AbstractFieldConnector) { required = ((AbstractFieldConnector) child).isRequired(); } - boolean enabled = child.getState().isEnabled(); + boolean enabled = child.getState().enabled; slot.setCaption(caption, iconUrlString, styles, error, showError, required, @@ -213,8 +213,8 @@ public abstract class AbstractBoxLayoutConnector extends super.onStateChanged(stateChangeEvent); clickEventHandler.handleEventHandlerRegistration(); - getWidget().setMargin(new MarginInfo(getState().getMarginsBitmask())); - getWidget().setSpacing(getState().isSpacing()); + getWidget().setMargin(new MarginInfo(getState().marginsBitmask)); + getWidget().setSpacing(getState().spacing); hasExpandRatio.clear(); hasVerticalAlignment.clear(); @@ -224,8 +224,7 @@ public abstract class AbstractBoxLayoutConnector extends boolean equalExpandRatio = getWidget().vertical ? !isUndefinedHeight() : !isUndefinedWidth(); for (ComponentConnector child : getChildComponents()) { - double expandRatio = getState().getChildData().get(child) - .getExpandRatio(); + double expandRatio = getState().childData.get(child).expandRatio; if (expandRatio > 0) { equalExpandRatio = false; break; @@ -235,12 +234,12 @@ public abstract class AbstractBoxLayoutConnector extends for (ComponentConnector child : getChildComponents()) { Slot slot = getWidget().getSlot(child); - AlignmentInfo alignment = new AlignmentInfo(getState() - .getChildData().get(child).getAlignmentBitmask()); + AlignmentInfo alignment = new AlignmentInfo( + getState().childData.get(child).alignmentBitmask); slot.setAlignment(alignment); - double expandRatio = getState().getChildData().get(child) - .getExpandRatio(); + double expandRatio = getState().childData.get(child).expandRatio; + if (equalExpandRatio) { expandRatio = 1; } else if (expandRatio == 0) { diff --git a/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java b/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java index d7cae9195f..5b1462b33c 100644 --- a/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -124,18 +124,16 @@ public abstract class AbstractOrderedLayoutConnector extends for (ComponentConnector child : getChildComponents()) { VLayoutSlot slot = layout.getSlotForChild(child.getWidget()); - AlignmentInfo alignment = new AlignmentInfo(getState() - .getChildData().get(child).getAlignmentBitmask()); + AlignmentInfo alignment = new AlignmentInfo( + getState().childData.get(child).alignmentBitmask); slot.setAlignment(alignment); - double expandRatio = getState().getChildData().get(child) - .getExpandRatio(); + double expandRatio = getState().childData.get(child).expandRatio; slot.setExpandRatio(expandRatio); } - layout.updateMarginStyleNames(new MarginInfo(getState() - .getMarginsBitmask())); - layout.updateSpacingStyleName(getState().isSpacing()); + layout.updateMarginStyleNames(new MarginInfo(getState().marginsBitmask)); + layout.updateSpacingStyleName(getState().spacing); getLayoutManager().setNeedsLayout(this); } @@ -254,9 +252,9 @@ public abstract class AbstractOrderedLayoutConnector extends private String getDefinedSize(boolean isVertical) { if (isVertical) { - return getState().getHeight(); + return getState().height == null ? "" : getState().height; } else { - return getState().getWidth(); + return getState().width == null ? "" : getState().width; } } diff --git a/client/src/com/vaadin/client/ui/panel/PanelConnector.java b/client/src/com/vaadin/client/ui/panel/PanelConnector.java index f991d295b4..35a2681590 100644 --- a/client/src/com/vaadin/client/ui/panel/PanelConnector.java +++ b/client/src/com/vaadin/client/ui/panel/PanelConnector.java @@ -33,6 +33,7 @@ import com.vaadin.client.ui.ShortcutActionHandler; import com.vaadin.client.ui.SimpleManagedLayout; import com.vaadin.client.ui.layout.MayScrollChildren; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.panel.PanelServerRpc; import com.vaadin.shared.ui.panel.PanelState; @@ -98,9 +99,8 @@ public class PanelConnector extends AbstractComponentContainerConnector + "-deco"); getWidget().captionNode.setClassName(VPanel.CLASSNAME + "-caption"); boolean hasCaption = false; - if (getState().getCaption() != null - && !"".equals(getState().getCaption())) { - getWidget().setCaption(getState().getCaption()); + if (getState().caption != null && !"".equals(getState().caption)) { + getWidget().setCaption(getState().caption); hasCaption = true; } else { getWidget().setCaption(""); @@ -117,8 +117,8 @@ public class PanelConnector extends AbstractComponentContainerConnector String captionClass = captionBaseClass; String contentClass = contentBaseClass; String decoClass = decoBaseClass; - if (getState().hasStyles()) { - for (String style : getState().getStyles()) { + if (ComponentStateUtil.hasStyles(getState())) { + for (String style : getState().styles) { captionClass += " " + captionBaseClass + "-" + style; contentClass += " " + contentBaseClass + "-" + style; decoClass += " " + decoBaseClass + "-" + style; @@ -147,7 +147,7 @@ public class PanelConnector extends AbstractComponentContainerConnector } getWidget().setErrorIndicatorVisible( - null != getState().getErrorMessage()); +null != getState().errorMessage); // We may have actions attached to this panel if (uidl.getChildCount() > 0) { @@ -164,20 +164,20 @@ public class PanelConnector extends AbstractComponentContainerConnector } } - if (getState().getScrollTop() != getWidget().scrollTop) { + if (getState().scrollTop != getWidget().scrollTop) { // Sizes are not yet up to date, so changing the scroll position // is deferred to after the layout phase - uidlScrollTop = getState().getScrollTop(); + uidlScrollTop = getState().scrollTop; } - if (getState().getScrollLeft() != getWidget().scrollLeft) { + if (getState().scrollLeft != getWidget().scrollLeft) { // Sizes are not yet up to date, so changing the scroll position // is deferred to after the layout phase - uidlScrollLeft = getState().getScrollLeft(); + uidlScrollLeft = getState().scrollLeft; } // And apply tab index - getWidget().contentNode.setTabIndex(getState().getTabIndex()); + getWidget().contentNode.setTabIndex(getState().tabIndex); } @Override diff --git a/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java b/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java index 5a4950cc0a..8def4d244d 100644 --- a/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java +++ b/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java @@ -23,6 +23,7 @@ import com.vaadin.client.VCaption; import com.vaadin.client.VCaptionWrapper; import com.vaadin.client.ui.AbstractComponentContainerConnector; import com.vaadin.client.ui.PostLayoutListener; +import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.Connect; import com.vaadin.ui.PopupView; @@ -69,12 +70,12 @@ public class PopupViewConnector extends AbstractComponentContainerConnector // showPopupOnTop(popup, hostReference); getWidget().preparePopup(getWidget().popup); getWidget().popup.updateFromUIDL(popupUIDL, client); - if (getState().hasStyles()) { + if (ComponentStateUtil.hasStyles(getState())) { final StringBuffer styleBuf = new StringBuffer(); final String primaryName = getWidget().popup .getStylePrimaryName(); styleBuf.append(primaryName); - for (String style : getState().getStyles()) { + for (String style : getState().styles) { styleBuf.append(" "); styleBuf.append(primaryName); styleBuf.append("-"); diff --git a/client/src/com/vaadin/client/ui/richtextarea/RichTextAreaConnector.java b/client/src/com/vaadin/client/ui/richtextarea/RichTextAreaConnector.java index b5c5e0d88b..5933286f8f 100644 --- a/client/src/com/vaadin/client/ui/richtextarea/RichTextAreaConnector.java +++ b/client/src/com/vaadin/client/ui/richtextarea/RichTextAreaConnector.java @@ -51,7 +51,7 @@ public class RichTextAreaConnector extends AbstractFieldConnector implements } getWidget().setReadOnly(isReadOnly()); - getWidget().immediate = getState().isImmediate(); + getWidget().immediate = getState().immediate; int newMaxLength = uidl.hasAttribute("maxLength") ? uidl .getIntAttribute("maxLength") : -1; if (newMaxLength >= 0) { diff --git a/client/src/com/vaadin/client/ui/slider/SliderConnector.java b/client/src/com/vaadin/client/ui/slider/SliderConnector.java index ab9a618c6d..e4c76b6ce8 100644 --- a/client/src/com/vaadin/client/ui/slider/SliderConnector.java +++ b/client/src/com/vaadin/client/ui/slider/SliderConnector.java @@ -59,15 +59,15 @@ public class SliderConnector extends AbstractFieldConnector implements super.onStateChanged(stateChangeEvent); getWidget().setId(getConnectorId()); - getWidget().setImmediate(getState().isImmediate()); + getWidget().setImmediate(getState().immediate); 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().setOrientation(getState().orientation); + getWidget().setMinValue(getState().minValue); + getWidget().setMaxValue(getState().maxValue); + getWidget().setResolution(getState().resolution); + getWidget().setValue(getState().value, false); + getWidget().setFeedbackValue(getState().value); getWidget().buildBase(); } diff --git a/client/src/com/vaadin/client/ui/splitpanel/AbstractSplitPanelConnector.java b/client/src/com/vaadin/client/ui/splitpanel/AbstractSplitPanelConnector.java index 19b1129aea..229d3894cf 100644 --- a/client/src/com/vaadin/client/ui/splitpanel/AbstractSplitPanelConnector.java +++ b/client/src/com/vaadin/client/ui/splitpanel/AbstractSplitPanelConnector.java @@ -37,6 +37,7 @@ import com.vaadin.client.ui.SimpleManagedLayout; import com.vaadin.client.ui.splitpanel.VAbstractSplitPanel.SplitterMoveHandler; import com.vaadin.client.ui.splitpanel.VAbstractSplitPanel.SplitterMoveHandler.SplitterMoveEvent; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelRpc; import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelState; import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelState.SplitterState; @@ -123,31 +124,31 @@ public abstract class AbstractSplitPanelConnector extends public void onStateChanged(StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); - getWidget().immediate = getState().isImmediate(); + getWidget().immediate = getState().immediate; getWidget().setEnabled(isEnabled()); clickEventHandler.handleEventHandlerRegistration(); - if (getState().hasStyles()) { - getWidget().componentStyleNames = getState().getStyles(); + if (ComponentStateUtil.hasStyles(getState())) { + getWidget().componentStyleNames = getState().styles; } else { getWidget().componentStyleNames = new LinkedList<String>(); } // Splitter updates - SplitterState splitterState = getState().getSplitterState(); + SplitterState splitterState = getState().splitterState; getWidget().setStylenames(); - getWidget().minimumPosition = splitterState.getMinPosition() - + splitterState.getMinPositionUnit(); + getWidget().minimumPosition = splitterState.minPosition + + splitterState.minPositionUnit; - getWidget().maximumPosition = splitterState.getMaxPosition() - + splitterState.getMaxPositionUnit(); + getWidget().maximumPosition = splitterState.maxPosition + + splitterState.maxPositionUnit; - getWidget().position = splitterState.getPosition() - + splitterState.getPositionUnit(); + getWidget().position = splitterState.position + + splitterState.positionUnit; // This is needed at least for cases like #3458 to take // appearing/disappearing scrollbars into account. @@ -198,11 +199,11 @@ public abstract class AbstractSplitPanelConnector extends } private ComponentConnector getFirstChild() { - return (ComponentConnector) getState().getFirstChild(); + return (ComponentConnector) getState().firstChild; } private ComponentConnector getSecondChild() { - return (ComponentConnector) getState().getSecondChild(); + return (ComponentConnector) getState().secondChild; } @Override diff --git a/client/src/com/vaadin/client/ui/table/TableConnector.java b/client/src/com/vaadin/client/ui/table/TableConnector.java index 891d4880b3..a84a321653 100644 --- a/client/src/com/vaadin/client/ui/table/TableConnector.java +++ b/client/src/com/vaadin/client/ui/table/TableConnector.java @@ -105,7 +105,7 @@ public class TableConnector extends AbstractComponentContainerConnector } getWidget().paintableId = uidl.getStringAttribute("id"); - getWidget().immediate = getState().isImmediate(); + getWidget().immediate = getState().immediate; int previousTotalRows = getWidget().totalRows; getWidget().updateTotalRows(uidl); @@ -334,7 +334,7 @@ public class TableConnector extends AbstractComponentContainerConnector @Override public boolean isReadOnly() { - return super.isReadOnly() || getState().isPropertyReadOnly(); + return super.isReadOnly() || getState().propertyReadOnly; } @Override diff --git a/client/src/com/vaadin/client/ui/tabsheet/VTabsheet.java b/client/src/com/vaadin/client/ui/tabsheet/VTabsheet.java index ba72f319e1..b2ad68e79b 100644 --- a/client/src/com/vaadin/client/ui/tabsheet/VTabsheet.java +++ b/client/src/com/vaadin/client/ui/tabsheet/VTabsheet.java @@ -58,6 +58,7 @@ import com.vaadin.client.VCaption; import com.vaadin.client.ui.label.VLabel; import com.vaadin.shared.ComponentState; import com.vaadin.shared.EventId; +import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.shared.ui.tabsheet.TabsheetBaseConstants; import com.vaadin.shared.ui.tabsheet.TabsheetConstants; @@ -739,8 +740,8 @@ public class VTabsheet extends VTabsheetBase implements Focusable, void handleStyleNames(UIDL uidl, ComponentState state) { // Add proper stylenames for all elements (easier to prevent unwanted // style inheritance) - if (state.hasStyles()) { - final List<String> styles = state.getStyles(); + if (ComponentStateUtil.hasStyles(state)) { + final List<String> styles = state.styles; if (!currentStyle.equals(styles.toString())) { currentStyle = styles.toString(); final String tabsBaseClass = TABS_CLASSNAME; @@ -1009,8 +1010,7 @@ public class VTabsheet extends VTabsheetBase implements Focusable, if (!isDynamicWidth()) { ComponentConnector paintable = ConnectorMap.get(client) .getConnector(this); - DOM.setStyleAttribute(tabs, "width", paintable.getState() - .getWidth()); + DOM.setStyleAttribute(tabs, "width", paintable.getState().width); } // Make sure scrollerIndex is valid diff --git a/client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java b/client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java index 4216919245..7fa68f2bc6 100644 --- a/client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java +++ b/client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java @@ -51,9 +51,9 @@ public class TextFieldConnector extends AbstractFieldConnector implements getWidget().setReadOnly(isReadOnly()); - getWidget().setInputPrompt(getState().getInputPrompt()); - getWidget().setMaxLength(getState().getMaxLength()); - getWidget().setImmediate(getState().isImmediate()); + getWidget().setInputPrompt(getState().inputPrompt); + getWidget().setMaxLength(getState().maxLength); + getWidget().setImmediate(getState().immediate); getWidget().listenTextChangeEvents = hasEventListener("ie"); if (getWidget().listenTextChangeEvents) { @@ -74,9 +74,9 @@ public class TextFieldConnector extends AbstractFieldConnector implements getWidget().sinkEvents(VTextField.TEXTCHANGE_EVENTS); getWidget().attachCutEventListener(getWidget().getElement()); } - getWidget().setColumns(getState().getColumns()); + getWidget().setColumns(getState().columns); - final String text = getState().getText(); + final String text = getState().text; /* * We skip the text content update if field has been repainted, but text diff --git a/client/src/com/vaadin/client/ui/tree/TreeConnector.java b/client/src/com/vaadin/client/ui/tree/TreeConnector.java index c7fb8084fa..7fd3b105b6 100644 --- a/client/src/com/vaadin/client/ui/tree/TreeConnector.java +++ b/client/src/com/vaadin/client/ui/tree/TreeConnector.java @@ -57,7 +57,7 @@ public class TreeConnector extends AbstractComponentConnector implements getWidget().paintableId = uidl.getId(); - getWidget().immediate = getState().isImmediate(); + getWidget().immediate = getState().immediate; getWidget().disabled = !isEnabled(); getWidget().readonly = isReadOnly(); @@ -257,7 +257,7 @@ public class TreeConnector extends AbstractComponentConnector implements @Override public boolean isReadOnly() { - return super.isReadOnly() || getState().isPropertyReadOnly(); + return super.isReadOnly() || getState().propertyReadOnly; } @Override diff --git a/client/src/com/vaadin/client/ui/upload/UploadConnector.java b/client/src/com/vaadin/client/ui/upload/UploadConnector.java index 8c23ccfbf7..7a69138d21 100644 --- a/client/src/com/vaadin/client/ui/upload/UploadConnector.java +++ b/client/src/com/vaadin/client/ui/upload/UploadConnector.java @@ -41,7 +41,7 @@ public class UploadConnector extends AbstractComponentConnector implements getWidget().submit(); return; } - getWidget().setImmediate(getState().isImmediate()); + getWidget().setImmediate(getState().immediate); getWidget().client = client; getWidget().paintableId = uidl.getId(); getWidget().nextUploadId = uidl.getIntAttribute("nextid"); diff --git a/client/src/com/vaadin/client/ui/window/WindowConnector.java b/client/src/com/vaadin/client/ui/window/WindowConnector.java index 7c83556283..f26592350a 100644 --- a/client/src/com/vaadin/client/ui/window/WindowConnector.java +++ b/client/src/com/vaadin/client/ui/window/WindowConnector.java @@ -36,8 +36,8 @@ import com.vaadin.client.ui.AbstractComponentContainerConnector; import com.vaadin.client.ui.ClickEventHandler; import com.vaadin.client.ui.PostLayoutListener; import com.vaadin.client.ui.ShortcutActionHandler; -import com.vaadin.client.ui.SimpleManagedLayout; import com.vaadin.client.ui.ShortcutActionHandler.BeforeShortcutActionListener; +import com.vaadin.client.ui.SimpleManagedLayout; import com.vaadin.client.ui.layout.MayScrollChildren; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.Connect; @@ -97,7 +97,7 @@ public class WindowConnector extends AbstractComponentContainerConnector + "_window_close"); if (isRealUpdate(uidl)) { - if (getState().isModal() != getWidget().vaadinModality) { + if (getState().modal != getWidget().vaadinModality) { getWidget().setVaadinModality(!getWidget().vaadinModality); } if (!getWidget().isAttached()) { @@ -105,12 +105,12 @@ public class WindowConnector extends AbstractComponentContainerConnector // possible centering getWidget().show(); } - if (getState().isResizable() != getWidget().resizable) { - getWidget().setResizable(getState().isResizable()); + if (getState().resizable != getWidget().resizable) { + getWidget().setResizable(getState().resizable); } - getWidget().resizeLazy = getState().isResizeLazy(); + getWidget().resizeLazy = getState().resizeLazy; - getWidget().setDraggable(getState().isDraggable()); + getWidget().setDraggable(getState().draggable); // Caption must be set before required header size is measured. If // the caption attribute is missing the caption should be cleared. @@ -118,7 +118,7 @@ public class WindowConnector extends AbstractComponentContainerConnector if (getIcon() != null) { iconURL = getIcon(); } - getWidget().setCaption(getState().getCaption(), iconURL); + getWidget().setCaption(getState().caption, iconURL); } getWidget().visibilityChangesDisabled = true; @@ -129,13 +129,13 @@ public class WindowConnector extends AbstractComponentContainerConnector clickEventHandler.handleEventHandlerRegistration(); - getWidget().immediate = getState().isImmediate(); + getWidget().immediate = getState().immediate; getWidget().setClosable(!isReadOnly()); // Initialize the position form UIDL - int positionx = getState().getPositionX(); - int positiony = getState().getPositionY(); + int positionx = getState().positionX; + int positiony = getState().positionY; if (positionx >= 0 || positiony >= 0) { if (positionx < 0) { positionx = 0; @@ -162,16 +162,16 @@ public class WindowConnector extends AbstractComponentContainerConnector } // setting scrollposition must happen after children is rendered - getWidget().contentPanel.setScrollPosition(getState().getScrollTop()); - getWidget().contentPanel.setHorizontalScrollPosition(getState() - .getScrollLeft()); + getWidget().contentPanel.setScrollPosition(getState().scrollTop); + getWidget().contentPanel + .setHorizontalScrollPosition(getState().scrollLeft); // Center this window on screen if requested // This had to be here because we might not know the content size before // everything is painted into the window // centered is this is unset on move/resize - getWidget().centered = getState().isCentered(); + getWidget().centered = getState().centered; getWidget().setVisible(true); // ensure window is not larger than browser window diff --git a/server/src/com/vaadin/Application.java b/server/src/com/vaadin/Application.java index 164f04bb79..cd34fb7540 100644 --- a/server/src/com/vaadin/Application.java +++ b/server/src/com/vaadin/Application.java @@ -26,10 +26,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; -import java.util.EventListener; import java.util.EventObject; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -37,14 +35,14 @@ import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; -import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; -import com.vaadin.annotations.EagerInit; +import com.vaadin.annotations.PreserveOnRefresh; import com.vaadin.annotations.Theme; +import com.vaadin.annotations.Title; import com.vaadin.annotations.Widgetset; import com.vaadin.data.util.converter.Converter; import com.vaadin.data.util.converter.ConverterFactory; @@ -211,15 +209,16 @@ public class Application implements Terminal.ErrorListener, Serializable { * This implementation simulates the way of finding a window for a * request by extracting a window name from the requested path and * passes that name to {@link #getWindow(String)}. - * + * <p> * {@inheritDoc} - * - * @see #getWindow(String) - * @see Application#getUI(WrappedRequest) */ - @Override - public UI.LegacyWindow getUI(WrappedRequest request) { + protected <T extends UI> T createUIInstance(WrappedRequest request, + Class<T> uiClass) { + return uiClass.cast(getUIInstance(request)); + } + + private UI getUIInstance(WrappedRequest request) { String pathInfo = request.getRequestPathInfo(); String name = null; if (pathInfo != null && pathInfo.length() > 0) { @@ -237,6 +236,19 @@ public class Application implements Terminal.ErrorListener, Serializable { } /** + * This implementation simulates the way of finding a window for a + * request by extracting a window name from the requested path and + * passes that name to {@link #getWindow(String)}. + * + * <p> + * {@inheritDoc} + */ + @Override + public Class<? extends UI> getUIClass(WrappedRequest request) { + return getUIInstance(request).getClass(); + } + + /** * Sets the application's theme. * <p> * Note that this theme can be overridden for a specific UI with @@ -270,9 +282,9 @@ public class Application implements Terminal.ErrorListener, Serializable { * <p> * {@inheritDoc} */ - @Override - public String getThemeForUI(UI uI) { + public String getThemeForUI(WrappedRequest request, + Class<? extends UI> uiClass) { return theme; } @@ -430,11 +442,6 @@ public class Application implements Terminal.ErrorListener, Serializable { private DeploymentConfiguration configuration; /** - * The current user or <code>null</code> if no user has logged in. - */ - private Object user; - - /** * The application's URL. */ private URL applicationUrl; @@ -450,16 +457,6 @@ public class Application implements Terminal.ErrorListener, Serializable { private Locale locale; /** - * List of listeners listening user changes. - */ - private LinkedList<UserChangeListener> userChangeListeners = null; - - /** - * Application resource mapping: key <-> resource. - */ - private long lastResourceKeyNumber = 0; - - /** * URL where the user is redirected to on application close, or null if * application is just closed without redirection. */ @@ -492,73 +489,11 @@ public class Application implements Terminal.ErrorListener, Serializable { private final EventRouter eventRouter = new EventRouter(); - /** - * Keeps track of which uIs have been inited. - * <p> - * TODO Investigate whether this might be derived from the different states - * in getUIForRrequest. - * </p> - */ - private Set<Integer> initedUIs = new HashSet<Integer>(); - private List<UIProvider> uiProviders = new LinkedList<UIProvider>(); private GlobalResourceHandler globalResourceHandler; /** - * Gets the user of the application. - * - * <p> - * Vaadin doesn't define of use user object in any way - it only provides - * this getter and setter methods for convenience. The user is any object - * that has been stored to the application with {@link #setUser(Object)}. - * </p> - * - * @return the User of the application. - */ - public Object getUser() { - return user; - } - - /** - * <p> - * Sets the user of the application instance. An application instance may - * have a user associated to it. This can be set in login procedure or - * application initialization. - * </p> - * <p> - * A component performing the user login procedure can assign the user - * property of the application and make the user object available to other - * components of the application. - * </p> - * <p> - * Vaadin doesn't define of use user object in any way - it only provides - * getter and setter methods for convenience. The user reference stored to - * the application can be read with {@link #getUser()}. - * </p> - * - * @param user - * the new user. - */ - public void setUser(Object user) { - final Object prevUser = this.user; - if (user == prevUser || (user != null && user.equals(prevUser))) { - return; - } - - this.user = user; - if (userChangeListeners != null) { - final Object[] listeners = userChangeListeners.toArray(); - final UserChangeEvent event = new UserChangeEvent(this, user, - prevUser); - for (int i = 0; i < listeners.length; i++) { - ((UserChangeListener) listeners[i]) - .applicationUserChanged(event); - } - } - } - - /** * Gets the URL of the application. * * <p> @@ -720,142 +655,6 @@ public class Application implements Terminal.ErrorListener, Serializable { } /** - * <p> - * An event that characterizes a change in the current selection. - * </p> - * Application user change event sent when the setUser is called to change - * the current user of the application. - * - * @since 3.0 - */ - public class UserChangeEvent extends java.util.EventObject { - - /** - * New user of the application. - */ - private final Object newUser; - - /** - * Previous user of the application. - */ - private final Object prevUser; - - /** - * Constructor for user change event. - * - * @param source - * the application source. - * @param newUser - * the new User. - * @param prevUser - * the previous User. - */ - public UserChangeEvent(Application source, Object newUser, - Object prevUser) { - super(source); - this.newUser = newUser; - this.prevUser = prevUser; - } - - /** - * Gets the new user of the application. - * - * @return the new User. - */ - public Object getNewUser() { - return newUser; - } - - /** - * Gets the previous user of the application. - * - * @return the previous Vaadin user, if user has not changed ever on - * application it returns <code>null</code> - */ - public Object getPreviousUser() { - return prevUser; - } - - /** - * Gets the application where the user change occurred. - * - * @return the Application. - */ - public Application getApplication() { - return (Application) getSource(); - } - } - - /** - * The <code>UserChangeListener</code> interface for listening application - * user changes. - * - * @since 3.0 - */ - public interface UserChangeListener extends EventListener, Serializable { - - /** - * The <code>applicationUserChanged</code> method Invoked when the - * application user has changed. - * - * @param event - * the change event. - */ - public void applicationUserChanged(Application.UserChangeEvent event); - } - - /** - * Adds the user change listener. - * - * This allows one to get notification each time {@link #setUser(Object)} is - * called. - * - * @param listener - * the user change listener to add. - */ - public void addUserChangeListener(UserChangeListener listener) { - if (userChangeListeners == null) { - userChangeListeners = new LinkedList<UserChangeListener>(); - } - userChangeListeners.add(listener); - } - - /** - * @deprecated Since 7.0, replaced by - * {@link #addUserChangeListener(UserChangeListener)} - **/ - @Deprecated - public void addListener(UserChangeListener listener) { - addUserChangeListener(listener); - } - - /** - * Removes the user change listener. - * - * @param listener - * the user change listener to remove. - */ - - public void removeUserChangeListener(UserChangeListener listener) { - if (userChangeListeners == null) { - return; - } - userChangeListeners.remove(listener); - if (userChangeListeners.isEmpty()) { - userChangeListeners = null; - } - } - - /** - * @deprecated Since 7.0, replaced by - * {@link #removeUserChangeListener(UserChangeListener)} - **/ - @Deprecated - public void removeListener(UserChangeListener listener) { - removeUserChangeListener(listener); - } - - /** * Window detach event. * * This event is sent each time a window is removed from the application @@ -1782,67 +1581,98 @@ public class Application implements Terminal.ErrorListener, Serializable { } /** - * Gets a UI for a request for which no UI is already known. This method is - * called when the framework processes a request that does not originate - * from an existing UI instance. This typically happens when a host page is - * requested. - * + * Gets the UI class for a request for which no UI is already known. This + * method is called when the framework processes a request that does not + * originate from an existing UI instance. This typically happens when a + * host page is requested. * <p> * Subclasses of Application may override this method to provide custom - * logic for choosing how to create a suitable UI or for picking an already - * created UI. If an existing UI is picked, care should be taken to avoid - * keeping the same UI open in multiple browser windows, as that will cause - * the states to go out of sync. - * </p> - * + * logic for choosing what kind of UI to use. * <p> - * If {@link BrowserDetails} are required to create a UI, the 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 the browser - * details are already available is not supported. - * </p> + * The default implementation in {@link Application} uses the + * {@value #UI_PARAMETER} parameter from web.xml for finding the name of the + * UI class. If {@link DeploymentConfiguration#getClassLoader()} does not + * return <code>null</code>, the returned {@link ClassLoader} is used for + * loading the UI class. Otherwise the {@link ClassLoader} used to load this + * class is used. * - * <p> - * The default implementation in {@link Application} creates a new instance - * of the UI class returned by {@link #getUIClassName(WrappedRequest)}, - * which in turn uses the {@value #UI_PARAMETER} parameter from web.xml. If - * {@link DeploymentConfiguration#getClassLoader()} for the request returns - * a {@link ClassLoader}, it is used for loading the UI class. Otherwise the - * {@link ClassLoader} used to load this class is used. * </p> * * @param request * the wrapped request for which a UI is needed * @return a UI instance to use for the request - * @throws UIRequiresMoreInformationException - * may be thrown by an implementation to indicate that - * {@link BrowserDetails} are required to create a UI * - * @see #getUIClassName(WrappedRequest) * @see UI - * @see UIRequiresMoreInformationException * @see WrappedRequest#getBrowserDetails() * * @since 7.0 */ - protected UI getUI(WrappedRequest request) - throws UIRequiresMoreInformationException { - - // Iterate in reverse order - test check newest provider first - for (int i = uiProviders.size() - 1; i >= 0; i--) { + public Class<? extends UI> getUIClass(WrappedRequest request) { + // Iterate in reverse order - check newest provider first + int providersSize = uiProviders.size(); + if (providersSize == 0) { + throw new IllegalStateException("There are no UI providers"); + } + for (int i = providersSize - 1; i >= 0; i--) { UIProvider provider = uiProviders.get(i); Class<? extends UI> uiClass = provider.getUIClass(this, request); if (uiClass != null) { - return provider.instantiateUI(this, uiClass, request); + return uiClass; + } + } + + throw new RuntimeException( + "No UI provider returned an UI class for request"); + } + + /** + * Creates an UI instance for a request for which no UI is already known. + * This method is called when the framework processes a request that does + * not originate from an existing UI instance. This typically happens when a + * host page is requested. + * <p> + * Subclasses of Application may override this method to provide custom + * logic for choosing how to create a suitable UI or for picking an already + * created UI. If an existing UI is picked, care should be taken to avoid + * keeping the same UI open in multiple browser windows, as that will cause + * the states to go out of sync. + * </p> + * + * @param request + * @param uiClass + * @return + */ + protected <T extends UI> T createUIInstance(WrappedRequest request, + Class<T> uiClass) { + int providersSize = uiProviders.size(); + if (providersSize == 0) { + throw new IllegalStateException("There are no UI providers"); + } + + for (int i = providersSize - 1; i >= 0; i--) { + UIProvider provider = uiProviders.get(i); + + Class<? extends UI> providerClass = provider.getUIClass(this, + request); + if (providerClass != null) { + if (providerClass != uiClass) { + getLogger().warning( + "Mismatching UI classes. Expected " + uiClass + + " but got " + providerClass + " from " + + provider); + // Try with next provider if we didn't get the expected + // class + continue; + } + return uiClass.cast(provider.instantiateUI(this, uiClass, + request)); } } throw new RuntimeException( - "No UI providers available or providers are not able to find UI instance"); + "No UI provider created an UI instance for request"); } /** @@ -1858,8 +1688,9 @@ public class Application implements Terminal.ErrorListener, Serializable { * * @since 7.0 */ - public String getThemeForUI(UI uI) { - Theme uiTheme = getAnnotationFor(uI.getClass(), Theme.class); + public String getThemeForUI(WrappedRequest request, + Class<? extends UI> uiClass) { + Theme uiTheme = getAnnotationFor(uiClass, Theme.class); if (uiTheme != null) { return uiTheme.value(); } else { @@ -1870,18 +1701,22 @@ public class Application implements Terminal.ErrorListener, Serializable { /** * Finds the widgetset to use for a specific UI. If no specific widgetset is * required, <code>null</code> is returned. + * <p> + * The default implementation uses the @{@link Widgetset} annotation if it's + * defined for the UI class. * - * TODO Tell what the default implementation does once it does something. - * - * @param uI - * the UI to get a widgetset for + * @param request + * the wrapped request for which to get a widgetset + * @param uiClass + * the UI class to get a widgetset for * @return the name of the widgetset, or <code>null</code> if the default * widgetset should be used * * @since 7.0 */ - public String getWidgetsetForUI(UI uI) { - Widgetset uiWidgetset = getAnnotationFor(uI.getClass(), Widgetset.class); + public String getWidgetsetForUI(WrappedRequest request, + Class<? extends UI> uiClass) { + Widgetset uiWidgetset = getAnnotationFor(uiClass, Widgetset.class); if (uiWidgetset != null) { return uiWidgetset.value(); } else { @@ -2023,8 +1858,6 @@ public class Application implements Terminal.ErrorListener, Serializable { */ private static final ThreadLocal<Application> currentApplication = new ThreadLocal<Application>(); - private boolean uiPreserved = false; - /** * Gets the currently used application. The current application is * automatically defined when processing requests to the server. In other @@ -2099,17 +1932,12 @@ public class Application implements Terminal.ErrorListener, Serializable { * @param request * the request for which a UI is desired * @return a UI belonging to the request - * @throws UIRequiresMoreInformationException - * if no existing UI could be found and creating a new UI - * requires additional information from the browser * - * @see #getUI(WrappedRequest) - * @see UIRequiresMoreInformationException + * @see #createUI(WrappedRequest) * * @since 7.0 */ - public UI getUIForRequest(WrappedRequest request) - throws UIRequiresMoreInformationException { + public UI getUIForRequest(WrappedRequest request) { UI uI = UI.getCurrent(); if (uI != null) { return uI; @@ -2122,69 +1950,75 @@ public class Application implements Terminal.ErrorListener, Serializable { && browserDetails.getUriFragment() != null; uI = uIs.get(uiId); + Class<? extends UI> uiClass = null; + + if (uI == null && hasBrowserDetails + && !retainOnRefreshUIs.isEmpty()) { + uiClass = getUIClass(request); - if (uI == null && isUiPreserved()) { // Check for a known UI - if (!retainOnRefreshUIs.isEmpty()) { - Integer retainedUIId; - if (!hasBrowserDetails) { - throw new UIRequiresMoreInformationException(); - } else { - String windowName = browserDetails.getWindowName(); - retainedUIId = retainOnRefreshUIs.get(windowName); - } + @SuppressWarnings("null") + String windowName = browserDetails.getWindowName(); + Integer retainedUIId = retainOnRefreshUIs.get(windowName); - if (retainedUIId != null) { + if (retainedUIId != null) { + UI retainedUI = uIs.get(retainedUIId); + // We've had the same UI instance in a window with this + // name, but should we still use it? + if (retainedUI.getClass() == uiClass) { uiId = retainedUIId; - uI = uIs.get(uiId); + uI = retainedUI; + } else { + getLogger().info( + "Not using retained UI in " + windowName + + " because retained UI was of type " + + retainedUIId.getClass() + " but " + + uiClass + + " is expected for the request."); } } } - if (uI == null) { - // Throws exception if UI can not yet be created - uI = getUI(request); + } // end synchronized block - // Initialize some fields for a newly created UI - if (uI.getApplication() == null) { - uI.setApplication(this); - } - if (uI.getUIId() < 0) { + UI.setCurrent(uI); - if (uiId == null) { - // Get the next id if none defined - uiId = Integer.valueOf(nextUIId++); - } - uI.setUIId(uiId.intValue()); - uIs.put(uiId, uI); - } - } + return uI; + } - // Set thread local here so it is available in init - UI.setCurrent(uI); + public UI createUI(WrappedRequest request) { + Class<? extends UI> uiClass = getUIClass(request); - if (!initedUIs.contains(uiId)) { - boolean initRequiresBrowserDetails = isUiPreserved() - || !uI.getClass().isAnnotationPresent(EagerInit.class); - if (!initRequiresBrowserDetails || hasBrowserDetails) { - uI.doInit(request); + UI ui = createUIInstance(request, uiClass); - // Remember that this UI has been initialized - initedUIs.add(uiId); + // Initialize some fields for a newly created UI + if (ui.getApplication() == null) { + ui.setApplication(this); + } + // Get the next id + Integer uiId = Integer.valueOf(nextUIId++); - // init() might turn on preserve so do this afterwards - if (isUiPreserved()) { - // Remember this UI - String windowName = request.getBrowserDetails() - .getWindowName(); - retainOnRefreshUIs.put(windowName, uiId); - } - } + uIs.put(uiId, ui); + + // Set thread local here so it is available in init + UI.setCurrent(ui); + + ui.doInit(request, uiId.intValue()); + + if (isUiPreserved(request, uiClass)) { + // Remember this UI + String windowName = request.getBrowserDetails().getWindowName(); + if (windowName == null) { + getLogger().warning( + "There is no window.name available for UI " + uiClass + + " that should be preserved."); + } else { + retainOnRefreshUIs.put(windowName, uiId); } - } // end synchronized block + } - return uI; + return ui; } /** @@ -2208,53 +2042,22 @@ public class Application implements Terminal.ErrorListener, Serializable { } /** - * Sets whether the same UI state should be reused if the framework can - * detect that the application is opened in a browser window where it has - * previously been open. The framework attempts to discover this by checking - * the value of window.name in the browser. - * <p> - * NOTE that you should avoid turning this feature on/off on-the-fly when - * the UI is already shown, as it might not be retained as intended. - * </p> - * - * @param uiPreserved - * <code>true</code>if the same UI instance should be reused e.g. - * when the browser window is refreshed. - */ - public void setUiPreserved(boolean uiPreserved) { - this.uiPreserved = uiPreserved; - if (!uiPreserved) { - retainOnRefreshUIs.clear(); - } - } - - /** * Checks whether the same UI state should be reused if the framework can * detect that the application is opened in a browser window where it has * previously been open. The framework attempts to discover this by checking * the value of window.name in the browser. * + * @param request + * @param uiClass + * * @return <code>true</code>if the same UI instance should be reused e.g. * when the browser window is refreshed. */ - public boolean isUiPreserved() { - return uiPreserved; - } - - /** - * Checks whether there's a pending initialization for the UI with the given - * id. - * - * @param uiId - * UI id to check for - * @return <code>true</code> of the initialization is pending, - * <code>false</code> if the UI id is not registered or if the UI - * has already been initialized - * - * @see #getUIForRequest(WrappedRequest) - */ - public boolean isUIInitPending(int uiId) { - return !initedUIs.contains(Integer.valueOf(uiId)); + public boolean isUiPreserved(WrappedRequest request, + Class<? extends UI> uiClass) { + PreserveOnRefresh preserveOnRefresh = getAnnotationFor(uiClass, + PreserveOnRefresh.class); + return preserveOnRefresh != null; } /** @@ -2473,4 +2276,14 @@ public class Application implements Terminal.ErrorListener, Serializable { return globalResourceHandler; } + + public String getPageTitleForUI(WrappedRequest request, + Class<? extends UI> uiClass) { + Title titleAnnotation = getAnnotationFor(uiClass, Title.class); + if (titleAnnotation == null) { + return null; + } else { + return titleAnnotation.value(); + } + } } diff --git a/server/src/com/vaadin/UIRequiresMoreInformationException.java b/server/src/com/vaadin/UIRequiresMoreInformationException.java deleted file mode 100644 index 76a31d88ef..0000000000 --- a/server/src/com/vaadin/UIRequiresMoreInformationException.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.server.WrappedRequest; -import com.vaadin.server.WrappedRequest.BrowserDetails; - -/** - * Exception that is thrown to indicate that creating or initializing the UI - * 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#getUI(WrappedRequest) - * @see WrappedRequest#getBrowserDetails() - * - * @since 7.0 - */ -public class UIRequiresMoreInformationException extends Exception { - // Nothing of interest here -} diff --git a/server/src/com/vaadin/annotations/PreserveOnRefresh.java b/server/src/com/vaadin/annotations/PreserveOnRefresh.java new file mode 100644 index 0000000000..59c4abb723 --- /dev/null +++ b/server/src/com/vaadin/annotations/PreserveOnRefresh.java @@ -0,0 +1,28 @@ +/* + * 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.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface PreserveOnRefresh { + +} diff --git a/server/src/com/vaadin/annotations/EagerInit.java b/server/src/com/vaadin/annotations/Title.java index f08d46b551..fcd5d986a8 100644 --- a/server/src/com/vaadin/annotations/EagerInit.java +++ b/server/src/com/vaadin/annotations/Title.java @@ -13,6 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ + package com.vaadin.annotations; import java.lang.annotation.ElementType; @@ -20,23 +21,18 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import com.vaadin.server.WrappedRequest; import com.vaadin.ui.UI; /** - * Indicates that the init method in a UI class can be called before full - * browser details ({@link WrappedRequest#getBrowserDetails()}) are available. - * This will make the UI appear more quickly, as ensuring the availability of - * this information typically requires an additional round trip to the client. - * - * @see UI#init(com.vaadin.server.WrappedRequest) - * @see WrappedRequest#getBrowserDetails() - * - * @since 7.0 - * + * Defines the HTML page title for a {@link UI}. */ -@Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) -public @interface EagerInit { - // No values +@Target(ElementType.TYPE) +public @interface Title { + /** + * Gets the HTML title that should be used if the UI is used on it's own. + * + * @return a page title string + */ + public String value(); } diff --git a/server/src/com/vaadin/data/Container.java b/server/src/com/vaadin/data/Container.java index 155dde87ef..28d6cad18d 100644 --- a/server/src/com/vaadin/data/Container.java +++ b/server/src/com/vaadin/data/Container.java @@ -18,6 +18,7 @@ package com.vaadin.data; import java.io.Serializable; import java.util.Collection; +import java.util.List; import com.vaadin.data.util.filter.SimpleStringFilter; import com.vaadin.data.util.filter.UnsupportedFilterException; @@ -484,16 +485,61 @@ public interface Container extends Serializable { public int indexOfId(Object itemId); /** - * Gets the ID of an Item by an index number. + * Get the item id for the item at the position given by + * <code>index</code>. <br> + * <br> + * <b>Throws:</b> {@link IndexOutOfBoundsException} if + * <code>index</code> is outside the range of the container. (i.e. + * <code>index < 0 || container.size()-1 < index</code>) * * @param index - * Index of the requested id in (the filtered and sorted view - * of) the Container - * @return ID of the Item in the given index + * the index of the requested item id + * @return the item id of the item at the given index */ public Object getIdByIndex(int index); /** + * Get <code>numberOfItems</code> consecutive item ids from the + * container, starting with the item id at <code>startIndex</code>. <br> + * <br> + * + * Implementations should return the exact number of item ids given by + * <code>numberOfItems</code>. The returned list must hence contain all + * of the item ids from the range: <br> + * <br> + * <code>startIndex</code> to + * <code>startIndex + (numberOfItems-1)</code>. <br> + * <br> + * + * The returned list must contain all of the requested item ids or throw + * a {@link RangeOutOfContainerBoundsException} to indicate that the + * container does not contain all the requested item ids.<br> + * <br> + * For quick migration to new API see: + * {@link ContainerHelpers#getItemIdsUsingGetIdByIndex(int, int, Indexed)} + * . <br> + * <br> + * <b>Throws:</b> {@link IllegalArgumentException} if + * <code>numberOfItems</code> is < 0 <br> + * <b>Throws:</b> {@link RangeOutOfContainerBoundsException} if all of + * the requested item ids cannot be fetched <br> + * <b>Throws:</b> {@link IndexOutOfBoundsException} if + * <code>startIndex</code> is outside the range of the container. (i.e. + * <code>startIndex < 0 || container.size()-1 < startIndex</code>) + * + * @param startIndex + * the index for the first item which id to include + * @param numberOfItems + * the number of consecutive item ids to get from the given + * start index, must be >= 0 + * @return List containing all of the requested item ids or empty list + * if <code>numberOfItems</code> == 0; not null + * + * @since 7.0 + */ + public List<?> getItemIds(int startIndex, int numberOfItems); + + /** * Adds a new item at given index (in the filtered view). * <p> * The indices of the item currently in the given position and all the diff --git a/server/src/com/vaadin/data/ContainerHelpers.java b/server/src/com/vaadin/data/ContainerHelpers.java new file mode 100644 index 0000000000..9ec2da4362 --- /dev/null +++ b/server/src/com/vaadin/data/ContainerHelpers.java @@ -0,0 +1,91 @@ +package com.vaadin.data; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import com.vaadin.data.Container.Indexed; + +/** + * Contains helper methods for containers that can be used to ease development + * of containers in Vaadin. + * + * @since 7.0 + */ +public class ContainerHelpers { + + /** + * Get a range of item ids from the container using + * {@link Indexed#getIdByIndex(int)}. This is just a helper method to aid + * developers to quickly add the required functionality to a Container + * during development. This should not be used in a "finished product" + * unless fetching an id for an index is very inexpensive because a separate + * request will be performed for each index in the range. + * + * @param startIndex + * index of the first item id to get + * @param numberOfIds + * the number of consecutive items whose ids should be returned + * @param container + * the container from which the items should be fetched + * @return A list of item ids in the range specified + */ + public static List<?> getItemIdsUsingGetIdByIndex(int startIndex, + int numberOfIds, Container.Indexed container) { + + if (container == null) { + throw new IllegalArgumentException( + "The given container cannot be null!"); + } + + if (startIndex < 0) { + throw new IndexOutOfBoundsException( + "Start index cannot be negative! startIndex=" + startIndex); + } + + if (startIndex > container.size()) { + throw new IndexOutOfBoundsException( + "Start index exceeds container size! startIndex=" + + startIndex + " containerLastItemIndex=" + + (container.size() - 1)); + } + + if (numberOfIds < 1) { + if (numberOfIds == 0) { + return Collections.emptyList(); + } + + throw new IllegalArgumentException( + "Cannot get negative amount of items! numberOfItems=" + + numberOfIds); + } + + // not included in the range + int endIndex = startIndex + numberOfIds; + + if (endIndex > container.size()) { + throw new RangeOutOfContainerBoundsException( + "Cannot get all requested item ids from container. " + + "Container size might have changed, recalculate numberOfIds " + + "based on the actual container size!", + startIndex, numberOfIds, container.size()); + } + + ArrayList<Object> rangeOfIds = new ArrayList<Object>(); + for (int i = startIndex; i < endIndex; i++) { + Object idByIndex = container.getIdByIndex(i); + if (idByIndex == null) { + throw new RuntimeException( + "Unable to get item id for index: " + + i + + " from container using Container.Indexed#getIdByIndex() " + + "even though container.size() > endIndex. " + + "Returned item id was null. " + + "Check your container implementation!"); + } + rangeOfIds.add(idByIndex); + } + + return Collections.unmodifiableList(rangeOfIds); + } +} diff --git a/server/src/com/vaadin/data/RangeOutOfContainerBoundsException.java b/server/src/com/vaadin/data/RangeOutOfContainerBoundsException.java new file mode 100644 index 0000000000..43058e45d8 --- /dev/null +++ b/server/src/com/vaadin/data/RangeOutOfContainerBoundsException.java @@ -0,0 +1,169 @@ +package com.vaadin.data; + +/** + * A exception that indicates that the container is unable to return all of the + * consecutive item ids requested by the caller. This can happen if the + * container size has changed since the input parameters for + * {@link Container.Indexed#getItemIds(int, int)} were computed or if the + * requested range exceeds the containers size due to some other factor.<br> + * <br> + * + * The exception can contain additional parameters for easier debugging. The + * additional parameters are the <code>startIndex</code> and + * <code>numberOfIds</code> which were given to + * {@link Container.Indexed#getItemIds(int, int)} as well as the size of the + * container when the fetch was executed. The container size can be retrieved + * with {@link #getContainerCurrentSize()}. <br> + * <br> + * + * The additional parameters are optional but the party that received the + * exception can check whether or not these were set by calling + * {@link #isAdditionalParametersSet()}. + * + * @since 7.0 + */ +public class RangeOutOfContainerBoundsException extends RuntimeException { + + private final int startIndex; + private final int numberOfIds; + private final int containerCurrentSize; + private final boolean additionalParametersSet; + + // Discourage users to create exceptions without at least some kind of + // message... + private RangeOutOfContainerBoundsException() { + super(); + startIndex = -1; + numberOfIds = -1; + containerCurrentSize = -1; + additionalParametersSet = false; + } + + public RangeOutOfContainerBoundsException(String message) { + super(message); + startIndex = -1; + numberOfIds = -1; + containerCurrentSize = -1; + additionalParametersSet = false; + } + + public RangeOutOfContainerBoundsException(String message, + Throwable throwable) { + super(message, throwable); + startIndex = -1; + numberOfIds = -1; + containerCurrentSize = -1; + additionalParametersSet = false; + } + + public RangeOutOfContainerBoundsException(Throwable throwable) { + super(throwable); + startIndex = -1; + numberOfIds = -1; + containerCurrentSize = -1; + additionalParametersSet = false; + } + + /** + * Create a new {@link RangeOutOfContainerBoundsException} with the + * additional parameters: + * <ul> + * <li>startIndex - start index for the query</li> + * <li>numberOfIds - the number of consecutive item ids to get</li> + * <li>containerCurrentSize - the size of the container during the execution + * of the query</li> + * </ul> + * given. + * + * @param message + * @param startIndex + * the given startIndex for the query + * @param numberOfIds + * the number of item ids requested + * @param containerCurrentSize + * the current size of the container + */ + public RangeOutOfContainerBoundsException(String message, int startIndex, + int numberOfIds, int containerCurrentSize) { + super(message); + + this.startIndex = startIndex; + this.numberOfIds = numberOfIds; + this.containerCurrentSize = containerCurrentSize; + additionalParametersSet = true; + } + + /** + * Create a new {@link RangeOutOfContainerBoundsException} with the given + * query parameters set in the exception along with the containers current + * size and a @link {@link Throwable}. + * + * @param message + * @param startIndex + * the given startIndex for the query + * @param numberOfIds + * the number of item ids queried for + * @param containerCurrentSize + * the current size of the container + * @param throwable + */ + public RangeOutOfContainerBoundsException(String message, int startIndex, + int numberOfIds, int containerCurrentSize, Throwable throwable) { + super(message, throwable); + + this.startIndex = startIndex; + this.numberOfIds = numberOfIds; + this.containerCurrentSize = containerCurrentSize; + additionalParametersSet = true; + } + + /** + * Get the given startIndex for the query. Remember to check if this + * parameter is set by calling {@link #isAdditionalParametersSet()} + * + * @return the startIndex given to the container + */ + public int getStartIndex() { + return startIndex; + } + + /** + * Get the number of item ids requested. Remember to check if this parameter + * is set with {@link #isAdditionalParametersSet()} + * + * @return the number of item ids the container was ordered to fetch + */ + public int getNumberOfIds() { + return numberOfIds; + } + + /** + * Get the container size when the query was actually executed. Remember to + * check if this parameter is set with {@link #isAdditionalParametersSet()} + */ + public int getContainerCurrentSize() { + return containerCurrentSize; + } + + /** + * Check whether or not the additional parameters for the exception were set + * during creation or not. + * + * The additional parameters can be retrieved with: <br> + * <ul> + * <li> {@link #getStartIndex()}</li> + * <li> {@link #getNumberOfIds()}</li> + * <li> {@link #getContainerCurrentSize()}</li> + * </ul> + * + * @return true if parameters are set, false otherwise. + * + * @see #RangeOutOfContainerBoundsException(String, int, int, int) + * RangeOutOfContainerBoundsException(String, int, int, int) for more + * details on the additional parameters + */ + public boolean isAdditionalParametersSet() { + return additionalParametersSet; + } + +} diff --git a/server/src/com/vaadin/data/util/AbstractInMemoryContainer.java b/server/src/com/vaadin/data/util/AbstractInMemoryContainer.java index 6eea9cb421..dbfcad3982 100644 --- a/server/src/com/vaadin/data/util/AbstractInMemoryContainer.java +++ b/server/src/com/vaadin/data/util/AbstractInMemoryContainer.java @@ -26,6 +26,7 @@ import java.util.Set; import com.vaadin.data.Container; import com.vaadin.data.Container.ItemSetChangeNotifier; import com.vaadin.data.Item; +import com.vaadin.data.RangeOutOfContainerBoundsException; import com.vaadin.data.util.filter.SimpleStringFilter; import com.vaadin.data.util.filter.UnsupportedFilterException; @@ -251,6 +252,45 @@ public abstract class AbstractInMemoryContainer<ITEMIDTYPE, PROPERTYIDCLASS, ITE } @Override + public List<ITEMIDTYPE> getItemIds(int startIndex, int numberOfIds) { + if (startIndex < 0) { + throw new IndexOutOfBoundsException( + "Start index cannot be negative! startIndex=" + startIndex); + } + + if (startIndex > getVisibleItemIds().size()) { + throw new IndexOutOfBoundsException( + "Start index exceeds container size! startIndex=" + + startIndex + " containerLastItemIndex=" + + (getVisibleItemIds().size() - 1)); + } + + if (numberOfIds < 1) { + if (numberOfIds == 0) { + return Collections.emptyList(); + } + + throw new IllegalArgumentException( + "Cannot get negative amount of items! numberOfItems=" + + numberOfIds); + } + + int endIndex = startIndex + numberOfIds; + + if (endIndex > getVisibleItemIds().size()) { + throw new RangeOutOfContainerBoundsException( + "Cannot get all requested item ids from container. " + + "Container size might have changed, recalculate numberOfIds " + + "based on the actual container size!", + startIndex, numberOfIds, getVisibleItemIds().size()); + } + + return Collections.unmodifiableList(getVisibleItemIds().subList( + startIndex, endIndex)); + + } + + @Override public int indexOfId(Object itemId) { return getVisibleItemIds().indexOf(itemId); } diff --git a/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java b/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java index a53f32b96e..7a63e8c6c2 100644 --- a/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java +++ b/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java @@ -33,6 +33,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import com.vaadin.data.Container; +import com.vaadin.data.ContainerHelpers; import com.vaadin.data.Item; import com.vaadin.data.Property; import com.vaadin.data.util.filter.Compare.Equal; @@ -656,9 +657,11 @@ public class SQLContainer implements Container, Container.Filterable, @Override public Object getIdByIndex(int index) { - if (index < 0 || index > size() - 1) { - return null; + if (index < 0) { + throw new IndexOutOfBoundsException("Index is negative! index=" + + index); } + if (index < size) { if (itemIndexes.keySet().contains(index)) { return itemIndexes.get(index); @@ -672,6 +675,13 @@ public class SQLContainer implements Container, Container.Filterable, } } + @Override + public List<Object> getItemIds(int startIndex, int numberOfIds) { + // TODO create a better implementation + return (List<Object>) ContainerHelpers.getItemIdsUsingGetIdByIndex( + startIndex, numberOfIds, this); + } + /**********************************************/ /** Methods from interface Container.Ordered **/ /**********************************************/ diff --git a/server/src/com/vaadin/navigator/FragmentManager.java b/server/src/com/vaadin/navigator/NavigationStateManager.java index a42456a163..cbbeb59c30 100644 --- a/server/src/com/vaadin/navigator/FragmentManager.java +++ b/server/src/com/vaadin/navigator/NavigationStateManager.java @@ -19,32 +19,34 @@ package com.vaadin.navigator; import java.io.Serializable; /** - * Fragment manager that handles interaction between Navigator and URI fragments - * or other similar view identification and bookmarking system. - * - * Alternative implementations can be created for HTML5 pushState, for portlet - * URL navigation and other similar systems. - * + * An interface for handling interaction between Navigator and the browser + * location URI or other similar view identification and bookmarking system. The + * state is limited to a single string because in the usual cases it forms a + * part of a URI. + * <p> + * Different implementations can be created for hashbang URIs, HTML5 pushState, + * portlet URL navigation and other similar systems. + * <p> * This interface is mostly for internal use by {@link Navigator}. * * @author Vaadin Ltd * @since 7.0 */ -public interface FragmentManager extends Serializable { +public interface NavigationStateManager extends Serializable { /** - * Return the current fragment (location string) including view name and any - * optional parameters. + * Returns the current navigation state including view name and any optional + * parameters. * * @return current view and parameter string, not null */ - public String getFragment(); + public String getState(); /** - * Set the current fragment (location string) in the application URL or - * similar location, including view name and any optional parameters. + * Set the current navigation state in the location URI or similar location, + * including view name and any optional parameters. * * @param fragment * new view and parameter string, not null */ - public void setFragment(String fragment); + public void setState(String state); }
\ No newline at end of file diff --git a/server/src/com/vaadin/navigator/Navigator.java b/server/src/com/vaadin/navigator/Navigator.java index cef27c221d..bda422379c 100644 --- a/server/src/com/vaadin/navigator/Navigator.java +++ b/server/src/com/vaadin/navigator/Navigator.java @@ -67,19 +67,24 @@ public class Navigator implements Serializable { } @Override - public void navigateTo(String fragmentParameters) { + public void enter(ViewChangeEvent event) { // nothing to do } } /** - * Fragment manager using URI fragments of a Page to track views and enable - * listening to view changes. - * + * A {@link NavigationStateManager} using hashbang fragments in the Page + * location URI to track views and enable listening to view changes. + * <p> + * A hashbang URI is one where the optional fragment or "hash" part - the + * part following a # sign - is used to encode navigation state in a web + * application. The advantage of this is that the fragment can be + * dynamically manipulated by javascript without causing page reloads. + * <p> * This class is mostly for internal use by Navigator, and is only public * and static to enable testing. */ - public static class UriFragmentManager implements FragmentManager, + public static class UriFragmentManager implements NavigationStateManager, FragmentChangedListener { private final Page page; private final Navigator navigator; @@ -102,18 +107,18 @@ public class Navigator implements Serializable { } @Override - public String getFragment() { + public String getState() { return page.getFragment(); } @Override - public void setFragment(String fragment) { - page.setFragment(fragment, false); + public void setState(String state) { + page.setFragment(state, false); } @Override public void fragmentChanged(FragmentChangedEvent event) { - UriFragmentManager.this.navigator.navigateTo(getFragment()); + UriFragmentManager.this.navigator.navigateTo(getState()); } } @@ -209,11 +214,11 @@ public class Navigator implements Serializable { } @Override - public String getViewName(String viewAndParameters) { - if (null == viewAndParameters) { + public String getViewName(String navigationState) { + if (null == navigationState) { return null; } - if (viewAndParameters.startsWith(viewName)) { + if (navigationState.startsWith(viewName)) { return viewName; } return null; @@ -271,12 +276,12 @@ public class Navigator implements Serializable { } @Override - public String getViewName(String viewAndParameters) { - if (null == viewAndParameters) { + public String getViewName(String navigationState) { + if (null == navigationState) { return null; } - if (viewAndParameters.equals(viewName) - || viewAndParameters.startsWith(viewName + "/")) { + if (navigationState.equals(viewName) + || navigationState.startsWith(viewName + "/")) { return viewName; } return null; @@ -318,7 +323,7 @@ public class Navigator implements Serializable { } } - private final FragmentManager fragmentManager; + private final NavigationStateManager stateManager; private final ViewDisplay display; private View currentView = null; private List<ViewChangeListener> listeners = new LinkedList<ViewChangeListener>(); @@ -352,7 +357,7 @@ public class Navigator implements Serializable { */ public Navigator(ComponentContainer container) { display = new ComponentContainerViewDisplay(container); - fragmentManager = new UriFragmentManager(Page.getCurrent(), this); + stateManager = new UriFragmentManager(Page.getCurrent(), this); } /** @@ -374,36 +379,37 @@ public class Navigator implements Serializable { */ public Navigator(Page page, ViewDisplay display) { this.display = display; - fragmentManager = new UriFragmentManager(page, this); + stateManager = new UriFragmentManager(page, this); } /** * Create a navigator. * - * When a custom fragment manager is not needed, use the constructor + * When a custom navigation state manager is not needed, use the constructor * {@link #Navigator(Page, ViewDisplay)} which uses a URI fragment based - * fragment manager. + * state manager. * * Note that navigation to the initial view must be performed explicitly by * the application after creating a Navigator using this constructor. * - * @param fragmentManager - * fragment manager keeping track of the active view and enabling - * bookmarking and direct navigation + * @param stateManager + * {@link NavigationStateManager} keeping track of the active + * view and enabling bookmarking and direct navigation * @param display - * where to display the views + * {@ViewDisplay} used to display the views handled + * by this navigator */ - public Navigator(FragmentManager fragmentManager, ViewDisplay display) { + public Navigator(NavigationStateManager stateManager, ViewDisplay display) { this.display = display; - this.fragmentManager = fragmentManager; + this.stateManager = stateManager; } /** * Navigate to a view and initialize the view with given parameters. * * The view string consists of a view name optionally followed by a slash - * and (fragment) parameters. ViewProviders are used to find and create the - * correct type of view. + * and a parameters part that is passed as-is to the view. ViewProviders are + * used to find and create the correct type of view. * * If multiple providers return a matching view, the view with the longest * name is selected. This way, e.g. hierarchies of subviews can be @@ -416,14 +422,14 @@ public class Navigator implements Serializable { * Registered {@link ViewChangeListener}s are called upon successful view * change. * - * @param viewAndParameters + * @param navigationState * view name and parameters */ - public void navigateTo(String viewAndParameters) { + public void navigateTo(String navigationState) { String longestViewName = null; View viewWithLongestName = null; for (ViewProvider provider : providers) { - String viewName = provider.getViewName(viewAndParameters); + String viewName = provider.getViewName(navigationState); if (null != viewName && (longestViewName == null || viewName.length() > longestViewName .length())) { @@ -436,9 +442,9 @@ public class Navigator implements Serializable { } if (viewWithLongestName != null) { String parameters = ""; - if (viewAndParameters.length() > longestViewName.length() + 1) { - parameters = viewAndParameters.substring(longestViewName - .length() + 1); + if (navigationState.length() > longestViewName.length() + 1) { + parameters = navigationState + .substring(longestViewName.length() + 1); } navigateTo(viewWithLongestName, longestViewName, parameters); } @@ -455,29 +461,29 @@ public class Navigator implements Serializable { * @param view * view to activate * @param viewName - * (optional) name of the view or null not to set the fragment - * @param fragmentParameters - * parameters passed in the fragment for the view + * (optional) name of the view or null not to change the + * navigation state + * @param parameters + * parameters passed in the navigation state to the view */ - protected void navigateTo(View view, String viewName, - String fragmentParameters) { + protected void navigateTo(View view, String viewName, String parameters) { ViewChangeEvent event = new ViewChangeEvent(this, currentView, view, - viewName, fragmentParameters); + viewName, parameters); if (!isViewChangeAllowed(event)) { return; } - if (null != viewName && getFragmentManager() != null) { - String currentFragment = viewName; - if (!fragmentParameters.equals("")) { - currentFragment += "/" + fragmentParameters; + if (null != viewName && getStateManager() != null) { + String navigationState = viewName; + if (!parameters.equals("")) { + navigationState += "/" + parameters; } - if (!currentFragment.equals(getFragmentManager().getFragment())) { - getFragmentManager().setFragment(currentFragment); + if (!navigationState.equals(getStateManager().getState())) { + getStateManager().setState(navigationState); } } - view.navigateTo(fragmentParameters); + view.enter(event); currentView = view; if (display != null) { @@ -512,17 +518,17 @@ public class Navigator implements Serializable { } /** - * Return the fragment manager that is used to get, listen to and manipulate - * the URI fragment or other source of navigation information. + * Returns the {@link NavigationStateManager} that is used to get, listen to + * and manipulate the navigation state used by this Navigator. * - * @return fragment manager in use + * @return NavigationStateManager in use */ - protected FragmentManager getFragmentManager() { - return fragmentManager; + protected NavigationStateManager getStateManager() { + return stateManager; } /** - * Returns the ViewDisplay used by the navigator. Unless another display is + * Return the ViewDisplay used by the navigator. Unless another display is * specified, a {@link SimpleViewDisplay} (which is a {@link Component}) is * used by default. * diff --git a/server/src/com/vaadin/navigator/View.java b/server/src/com/vaadin/navigator/View.java index caee801f0c..53dbf01319 100644 --- a/server/src/com/vaadin/navigator/View.java +++ b/server/src/com/vaadin/navigator/View.java @@ -18,6 +18,7 @@ package com.vaadin.navigator; import java.io.Serializable; +import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; import com.vaadin.ui.Component; /** @@ -34,13 +35,15 @@ public interface View extends Serializable { /** * This view is navigated to. * - * This method is always called before the view is shown on screen. If there - * is any additional id to data what should be shown in the view, it is also - * optionally passed as parameter. + * This method is always called before the view is shown on screen. + * {@link ViewChangeEvent#getParameters() event.getParameters()} may contain + * extra parameters relevant to the view. + * + * @param event + * ViewChangeEvent representing the view change that is + * occurring. {@link ViewChangeEvent#getNewView() + * event.getNewView()} returns <code>this</code>. * - * @param fragmentParameters - * parameters to the view or empty string if none given. This is - * the string that appears e.g. in URI after "viewname/" */ - public void navigateTo(String fragmentParameters); + public void enter(ViewChangeEvent event); }
\ No newline at end of file diff --git a/server/src/com/vaadin/navigator/ViewChangeListener.java b/server/src/com/vaadin/navigator/ViewChangeListener.java index d2d4a091c6..aa09f64ad8 100644 --- a/server/src/com/vaadin/navigator/ViewChangeListener.java +++ b/server/src/com/vaadin/navigator/ViewChangeListener.java @@ -37,7 +37,7 @@ public interface ViewChangeListener extends Serializable { private final View oldView; private final View newView; private final String viewName; - private final String fragmentParameters; + private final String parameters; /** * Create a new view change event. @@ -46,12 +46,12 @@ public interface ViewChangeListener extends Serializable { * Navigator that triggered the event, not null */ public ViewChangeEvent(Navigator navigator, View oldView, View newView, - String viewName, String fragmentParameters) { + String viewName, String parameters) { super(navigator); this.oldView = oldView; this.newView = newView; this.viewName = viewName; - this.fragmentParameters = fragmentParameters; + this.parameters = parameters; } /** @@ -93,11 +93,11 @@ public interface ViewChangeListener extends Serializable { /** * Returns the parameters for the view being activated. * - * @return fragment parameters (potentially bookmarkable) for the new + * @return navigation parameters (potentially bookmarkable) for the new * view */ - public String getFragmentParameters() { - return fragmentParameters; + public String getParameters() { + return parameters; } } diff --git a/server/src/com/vaadin/server/AbstractApplicationPortlet.java b/server/src/com/vaadin/server/AbstractApplicationPortlet.java index e47e00577b..e8151462aa 100644 --- a/server/src/com/vaadin/server/AbstractApplicationPortlet.java +++ b/server/src/com/vaadin/server/AbstractApplicationPortlet.java @@ -56,7 +56,6 @@ import com.liferay.portal.kernel.util.PropsUtil; import com.vaadin.Application; import com.vaadin.Application.ApplicationStartEvent; import com.vaadin.Application.SystemMessages; -import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.server.AbstractCommunicationManager.Callback; import com.vaadin.ui.UI; @@ -501,12 +500,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet // Both action requests and render requests are ok // without a UI as they render the initial HTML // and then do a second request - try { - uI = application - .getUIForRequest(wrappedRequest); - } catch (UIRequiresMoreInformationException e) { - // Ignore problem and continue without UI - } + uI = application.getUIForRequest(wrappedRequest); break; case BROWSER_DETAILS: // Should not try to find a UI here as the @@ -902,7 +896,6 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet throws PortletException { try { final Application application = getApplicationClass().newInstance(); - application.setUiPreserved(true); return application; } catch (final IllegalAccessException e) { throw new PortletException("getNewApplication failed", e); diff --git a/server/src/com/vaadin/server/AbstractCommunicationManager.java b/server/src/com/vaadin/server/AbstractCommunicationManager.java index 2655ee9a00..72406e629d 100644 --- a/server/src/com/vaadin/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/server/AbstractCommunicationManager.java @@ -60,13 +60,11 @@ import javax.servlet.http.HttpServletResponse; import com.vaadin.Application; import com.vaadin.Application.SystemMessages; -import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.annotations.JavaScript; import com.vaadin.annotations.StyleSheet; import com.vaadin.external.json.JSONArray; import com.vaadin.external.json.JSONException; import com.vaadin.external.json.JSONObject; -import com.vaadin.server.BootstrapHandler.BootstrapContext; import com.vaadin.server.ComponentSizeValidator.InvalidLayout; import com.vaadin.server.RpcManager.RpcInvocationException; import com.vaadin.server.StreamVariable.StreamingEndEvent; @@ -832,7 +830,6 @@ public abstract class AbstractCommunicationManager implements Serializable { .isClientSideInitialized(connector); connector.beforeClientResponse(!initialized); } - uiConnectorTracker.markAllConnectorsClean(); outWriter.print("\"changes\":["); @@ -943,6 +940,8 @@ public abstract class AbstractCommunicationManager implements Serializable { outWriter.append(hierarchyInfo.toString()); outWriter.print(", "); // close hierarchy + uiConnectorTracker.markAllConnectorsClean(); + // send server to client RPC calls for components in the UI, in call // order @@ -1233,6 +1232,8 @@ public abstract class AbstractCommunicationManager implements Serializable { uiConnectorTracker.markClientSideInitialized(connector); } + assert (uiConnectorTracker.getDirtyConnectors().isEmpty()) : "Connectors have been marked as dirty during the end of the paint phase. This is most certainly not intended."; + writePerformanceData(outWriter); } @@ -1509,7 +1510,7 @@ public abstract class AbstractCommunicationManager implements Serializable { } private String getTheme(UI uI) { - String themeName = uI.getApplication().getThemeForUI(uI); + String themeName = uI.getTheme(); String requestThemeName = getRequestTheme(); if (requestThemeName != null) { @@ -2407,36 +2408,22 @@ public abstract class AbstractCommunicationManager implements Serializable { WrappedResponse response, Application application) throws IOException { - // 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; + assert UI.getCurrent() == null; try { CombinedRequest combinedRequest = new CombinedRequest(request); - UI uI = application.getUIForRequest(combinedRequest); response.setContentType("application/json; charset=UTF-8"); - // Use the same logic as for determined UIs - BootstrapHandler bootstrapHandler = getBootstrapHandler(); - BootstrapContext context = bootstrapHandler.createContext( - combinedRequest, response, application, uI.getUIId()); - - String widgetset = context.getWidgetsetName(); - String theme = context.getThemeName(); - String themeUri = bootstrapHandler.getThemeUri(context, theme); + UI uI = application.getUIForRequest(combinedRequest); + if (uI == null) { + uI = application.createUI(combinedRequest); + } - // 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(UIConstants.UI_ID_PARAMETER, uI.getUIId()); - if (sendUIDL) { - String initialUIDL = getInitialUIDL(combinedRequest, uI); - params.put("uidl", initialUIDL); - } + String initialUIDL = getInitialUIDL(combinedRequest, uI); + params.put("uidl", initialUIDL); // NOTE! GateIn requires, for some weird reason, getOutputStream // to be used instead of getWriter() (it seems to interpret @@ -2449,10 +2436,6 @@ public abstract class AbstractCommunicationManager implements Serializable { // NOTE GateIn requires the buffers to be flushed to work outWriter.flush(); out.flush(); - } catch (UIRequiresMoreInformationException e) { - // Requiring more information at this point is not allowed - // TODO handle in a better way - throw new RuntimeException(e); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/server/src/com/vaadin/server/AbstractUIProvider.java b/server/src/com/vaadin/server/AbstractUIProvider.java index 07b95fc713..f383368d91 100644 --- a/server/src/com/vaadin/server/AbstractUIProvider.java +++ b/server/src/com/vaadin/server/AbstractUIProvider.java @@ -1,35 +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.server;
-
-import com.vaadin.Application;
-import com.vaadin.ui.UI;
-
-public abstract class AbstractUIProvider implements UIProvider {
-
- @Override
- public UI instantiateUI(Application application, Class<? extends UI> 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);
- }
- }
-}
+/* + * 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.server; + +import com.vaadin.Application; +import com.vaadin.ui.UI; + +public abstract class AbstractUIProvider implements UIProvider { + + @Override + public UI instantiateUI(Application application, Class<? extends UI> 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/server/BootstrapFragmentResponse.java b/server/src/com/vaadin/server/BootstrapFragmentResponse.java index 16f7bc653b..149f59e7a5 100644 --- a/server/src/com/vaadin/server/BootstrapFragmentResponse.java +++ b/server/src/com/vaadin/server/BootstrapFragmentResponse.java @@ -21,6 +21,7 @@ import java.util.List; import org.jsoup.nodes.Node; import com.vaadin.Application; +import com.vaadin.ui.UI; /** * A representation of a bootstrap fragment being generated. The bootstrap @@ -37,7 +38,7 @@ public class BootstrapFragmentResponse extends BootstrapResponse { * Crate a new bootstrap fragment response. * * @see BootstrapResponse#BootstrapResponse(BootstrapHandler, - * WrappedRequest, Application, Integer) + * WrappedRequest, Application, Class) * * @param handler * the bootstrap handler that is firing the event @@ -47,16 +48,16 @@ public class BootstrapFragmentResponse extends BootstrapResponse { * @param application * the application for which the bootstrap page should be * generated - * @param uiId - * the generated id of the UI that will be displayed on the page + * @param uiClass + * the class 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 uiId, - List<Node> fragmentNodes) { - super(handler, request, application, uiId); + WrappedRequest request, Application application, + Class<? extends UI> uiClass, List<Node> fragmentNodes) { + super(handler, request, application, uiClass); this.fragmentNodes = fragmentNodes; } diff --git a/server/src/com/vaadin/server/BootstrapHandler.java b/server/src/com/vaadin/server/BootstrapHandler.java index 280372a5e5..60ac40916c 100644 --- a/server/src/com/vaadin/server/BootstrapHandler.java +++ b/server/src/com/vaadin/server/BootstrapHandler.java @@ -37,12 +37,10 @@ import org.jsoup.nodes.Node; import org.jsoup.parser.Tag; import com.vaadin.Application; -import com.vaadin.UIRequiresMoreInformationException; 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.ui.UI; public abstract class BootstrapHandler implements RequestHandler { @@ -74,30 +72,20 @@ public abstract class BootstrapHandler implements RequestHandler { return bootstrapResponse.getApplication(); } - public Integer getUIId() { - return bootstrapResponse.getUIId(); - } - - public UI getUI() { - return bootstrapResponse.getUI(); + public Class<? extends UI> getUIClass() { + return bootstrapResponse.getUiClass(); } public String getWidgetsetName() { if (widgetsetName == null) { - UI uI = getUI(); - if (uI != null) { - widgetsetName = getWidgetsetForUI(this); - } + widgetsetName = getWidgetsetForUI(this); } return widgetsetName; } public String getThemeName() { if (themeName == null) { - UI uI = getUI(); - if (uI != null) { - themeName = findAndEscapeThemeName(this); - } + themeName = findAndEscapeThemeName(this); } return themeName; } @@ -120,23 +108,11 @@ public abstract class BootstrapHandler implements RequestHandler { WrappedRequest request, WrappedResponse response) throws IOException { - // TODO Should all urls be handled here? - Integer uiId = null; try { - UI uI = application.getUIForRequest(request); - if (uI == null) { - writeError(response, new Throwable("No UI found")); - return true; - } + Class<? extends UI> uiClass = application.getUIClass(request); - uiId = Integer.valueOf(uI.getUIId()); - } catch (UIRequiresMoreInformationException e) { - // Just keep going without uiId - } - - try { BootstrapContext context = createContext(request, response, - application, uiId); + application, uiClass); setupMainDiv(context); BootstrapFragmentResponse fragmentResponse = context @@ -166,8 +142,8 @@ public abstract class BootstrapHandler implements RequestHandler { Map<String, Object> headers = new LinkedHashMap<String, Object>(); Document document = Document.createShell(""); BootstrapPageResponse pageResponse = new BootstrapPageResponse( - this, request, context.getApplication(), context.getUIId(), - document, headers); + this, request, context.getApplication(), + context.getUIClass(), document, headers); List<Node> fragmentNodes = fragmentResponse.getFragmentNodes(); Element body = document.body(); for (Node node : fragmentNodes) { @@ -242,10 +218,11 @@ public abstract class BootstrapHandler implements RequestHandler { head.appendElement("meta").attr("http-equiv", "X-UA-Compatible") .attr("content", "chrome=1"); - UI uI = context.getUI(); - String title = ((uI == null || uI.getCaption() == null) ? "" : uI - .getCaption()); - head.appendElement("title").appendText(title); + String title = context.getApplication().getPageTitleForUI( + context.getRequest(), context.getUIClass()); + if (title != null) { + head.appendElement("title").appendText(title); + } head.appendElement("style").attr("type", "text/css") .appendText("html, body {height:100%;margin:0;}"); @@ -267,11 +244,12 @@ public abstract class BootstrapHandler implements RequestHandler { body.addClass(ApplicationConstants.GENERATED_BODY_CLASSNAME); } - public BootstrapContext createContext(WrappedRequest request, - WrappedResponse response, Application application, Integer uiId) { + private BootstrapContext createContext(WrappedRequest request, + WrappedResponse response, Application application, + Class<? extends UI> uiClass) { BootstrapContext context = new BootstrapContext(response, - new BootstrapFragmentResponse(this, request, application, uiId, - new ArrayList<Node>())); + new BootstrapFragmentResponse(this, request, application, + uiClass, new ArrayList<Node>())); return context; } @@ -290,10 +268,10 @@ public abstract class BootstrapHandler implements RequestHandler { protected abstract String getApplicationId(BootstrapContext context); public String getWidgetsetForUI(BootstrapContext context) { - UI uI = context.getUI(); WrappedRequest request = context.getRequest(); - String widgetset = uI.getApplication().getWidgetsetForUI(uI); + String widgetset = context.getApplication().getWidgetsetForUI( + context.getRequest(), context.getUIClass()); if (widgetset == null) { widgetset = request.getDeploymentConfiguration() .getConfiguredWidgetset(request); @@ -413,14 +391,9 @@ public abstract class BootstrapHandler implements RequestHandler { protected JSONObject getApplicationParameters(BootstrapContext context) throws JSONException, PaintException { Application application = context.getApplication(); - Integer uiId = context.getUIId(); JSONObject appConfig = new JSONObject(); - if (uiId != null) { - appConfig.put(UIConstants.UI_ID_PARAMETER, uiId); - } - if (context.getThemeName() != null) { appConfig.put("themeUri", getThemeUri(context, context.getThemeName())); @@ -433,18 +406,11 @@ public abstract class BootstrapHandler implements RequestHandler { appConfig.put("widgetset", context.getWidgetsetName()); - if (uiId == null || application.isUIInitPending(uiId.intValue())) { - appConfig.put("initialPath", context.getRequest() - .getRequestPathInfo()); + appConfig.put("initialPath", context.getRequest().getRequestPathInfo()); - Map<String, String[]> parameterMap = context.getRequest() - .getParameterMap(); - appConfig.put("initialParams", parameterMap); - } else { - // write the initial UIDL into the config - appConfig.put("uidl", - getInitialUIDL(context.getRequest(), context.getUI())); - } + Map<String, String[]> parameterMap = context.getRequest() + .getParameterMap(); + appConfig.put("initialParams", parameterMap); return appConfig; } @@ -532,7 +498,8 @@ public abstract class BootstrapHandler implements RequestHandler { * @return */ public String getThemeName(BootstrapContext context) { - return context.getApplication().getThemeForUI(context.getUI()); + return context.getApplication().getThemeForUI(context.getRequest(), + context.getUIClass()); } /** @@ -561,21 +528,4 @@ public abstract class BootstrapHandler implements RequestHandler { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getLocalizedMessage()); } - - /** - * Gets the initial UIDL message to send to the client. - * - * @param request - * the originating request - * @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) - throws PaintException, JSONException; - } diff --git a/server/src/com/vaadin/server/BootstrapPageResponse.java b/server/src/com/vaadin/server/BootstrapPageResponse.java index d6df145728..a5fdfe4707 100644 --- a/server/src/com/vaadin/server/BootstrapPageResponse.java +++ b/server/src/com/vaadin/server/BootstrapPageResponse.java @@ -21,6 +21,7 @@ import java.util.Map; import org.jsoup.nodes.Document; import com.vaadin.Application; +import com.vaadin.ui.UI; /** * A representation of a bootstrap page being generated. The bootstrap page @@ -39,7 +40,7 @@ public class BootstrapPageResponse extends BootstrapResponse { * Crate a new bootstrap page response. * * @see BootstrapResponse#BootstrapResponse(BootstrapHandler, - * WrappedRequest, Application, Integer) + * WrappedRequest, Application, Class) * * @param handler * the bootstrap handler that is firing the event @@ -49,17 +50,18 @@ public class BootstrapPageResponse extends BootstrapResponse { * @param application * the application for which the bootstrap page should be * generated - * @param uiId - * the generated id of the UI that will be displayed on the page + * @param uiClass + * the class of the UI that will be displayed on the page * @param document * the DOM document making up the HTML page * @param headers * a map into which header data can be added */ public BootstrapPageResponse(BootstrapHandler handler, - WrappedRequest request, Application application, Integer uiId, - Document document, Map<String, Object> headers) { - super(handler, request, application, uiId); + WrappedRequest request, Application application, + Class<? extends UI> uiClass, Document document, + Map<String, Object> headers) { + super(handler, request, application, uiClass); this.headers = headers; this.document = document; } diff --git a/server/src/com/vaadin/server/BootstrapResponse.java b/server/src/com/vaadin/server/BootstrapResponse.java index 962b48dc31..3173569059 100644 --- a/server/src/com/vaadin/server/BootstrapResponse.java +++ b/server/src/com/vaadin/server/BootstrapResponse.java @@ -19,7 +19,6 @@ package com.vaadin.server; import java.util.EventObject; import com.vaadin.Application; -import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.ui.UI; /** @@ -32,7 +31,7 @@ import com.vaadin.ui.UI; public abstract class BootstrapResponse extends EventObject { private final WrappedRequest request; private final Application application; - private final Integer uiId; + private final Class<? extends UI> uiClass; /** * Creates a new bootstrap event. @@ -45,15 +44,15 @@ public abstract class BootstrapResponse extends EventObject { * @param application * the application for which the bootstrap page should be * generated - * @param uiId - * the generated id of the UI that will be displayed on the page + * @param uiClass + * the class of the UI that will be displayed on the page */ public BootstrapResponse(BootstrapHandler handler, WrappedRequest request, - Application application, Integer uiId) { + Application application, Class<? extends UI> uiClass) { super(handler); this.request = request; this.application = application; - this.uiId = uiId; + this.uiClass = uiClass; } /** @@ -89,32 +88,13 @@ public abstract class BootstrapResponse extends EventObject { } /** - * 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. + * Gets the class of the UI that will be displayed on the generated + * bootstrap page. * - * @return the UI id + * @return the class of the UI */ - public Integer getUIId() { - return uiId; + public Class<? extends UI> getUiClass() { + return uiClass; } - /** - * 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 - * browser has been sent back. This method will return <code>null</code> if - * no UI instance is yet available. - * - * @see Application#isUiPreserved() - * @see Application#getUI(WrappedRequest) - * @see UIRequiresMoreInformationException - * - * @return The UI that will be displayed in the page being generated, or - * <code>null</code> if all required information is not yet - * available. - */ - public UI getUI() { - return UI.getCurrent(); - } } diff --git a/server/src/com/vaadin/server/CommunicationManager.java b/server/src/com/vaadin/server/CommunicationManager.java index 9b56e20fd4..3c594eaf02 100644 --- a/server/src/com/vaadin/server/CommunicationManager.java +++ b/server/src/com/vaadin/server/CommunicationManager.java @@ -22,7 +22,6 @@ import java.net.URL; import javax.servlet.ServletContext; import com.vaadin.Application; -import com.vaadin.external.json.JSONException; import com.vaadin.ui.UI; /** @@ -107,12 +106,6 @@ public class CommunicationManager extends AbstractCommunicationManager { } return themeName; } - - @Override - protected String getInitialUIDL(WrappedRequest request, UI uI) - throws PaintException, JSONException { - return CommunicationManager.this.getInitialUIDL(request, uI); - } }; } diff --git a/server/src/com/vaadin/server/DefaultUIProvider.java b/server/src/com/vaadin/server/DefaultUIProvider.java index 913402c89f..93128aad28 100644 --- a/server/src/com/vaadin/server/DefaultUIProvider.java +++ b/server/src/com/vaadin/server/DefaultUIProvider.java @@ -1,51 +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.server;
-
-import com.vaadin.Application;
-import com.vaadin.UIRequiresMoreInformationException;
-import com.vaadin.ui.UI;
-
-public class DefaultUIProvider extends AbstractUIProvider {
-
- @Override
- public Class<? extends UI> 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<? extends UI> 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;
- }
-}
+/* + * 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.server; + +import com.vaadin.Application; +import com.vaadin.ui.UI; + +public class DefaultUIProvider extends AbstractUIProvider { + + @Override + public Class<? extends UI> getUIClass(Application application, + WrappedRequest request) { + 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<? extends UI> 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/server/GlobalResourceHandler.java b/server/src/com/vaadin/server/GlobalResourceHandler.java index f3a72a0efc..441d884f58 100644 --- a/server/src/com/vaadin/server/GlobalResourceHandler.java +++ b/server/src/com/vaadin/server/GlobalResourceHandler.java @@ -123,8 +123,8 @@ public class GlobalResourceHandler implements RequestHandler { /** * Registers a resource to be served with a global URL. * <p> - * A {@link ConnectorResource} registered for a {@link Vaadin6Component} - * will be set to be served with a global URL. Other resource types will be + * A {@link ConnectorResource} registered for a {@link LegacyComponent} will + * be set to be served with a global URL. Other resource types will be * ignored and thus not served by this handler. * * @param resource diff --git a/server/src/com/vaadin/server/PortletCommunicationManager.java b/server/src/com/vaadin/server/PortletCommunicationManager.java index f7d9371022..697095d691 100644 --- a/server/src/com/vaadin/server/PortletCommunicationManager.java +++ b/server/src/com/vaadin/server/PortletCommunicationManager.java @@ -138,13 +138,6 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { } @Override - protected String getInitialUIDL(WrappedRequest request, UI uI) - throws PaintException, JSONException { - return PortletCommunicationManager.this.getInitialUIDL(request, - uI); - } - - @Override protected JSONObject getApplicationParameters( BootstrapContext context) throws JSONException, PaintException { diff --git a/server/src/com/vaadin/server/UIProvider.java b/server/src/com/vaadin/server/UIProvider.java index f262a3e225..36bb164845 100644 --- a/server/src/com/vaadin/server/UIProvider.java +++ b/server/src/com/vaadin/server/UIProvider.java @@ -1,29 +1,28 @@ -/*
- * 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.server;
-
-import com.vaadin.Application;
-import com.vaadin.UIRequiresMoreInformationException;
-import com.vaadin.ui.UI;
-
-public interface UIProvider {
- public Class<? extends UI> getUIClass(Application application,
- WrappedRequest request) throws UIRequiresMoreInformationException;
-
- public UI instantiateUI(Application application, Class<? extends UI> type,
- WrappedRequest request);
-}
+/* + * 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.server; + +import com.vaadin.Application; +import com.vaadin.ui.UI; + +public interface UIProvider { + public Class<? extends UI> getUIClass(Application application, + WrappedRequest request); + + public UI instantiateUI(Application application, Class<? extends UI> type, + WrappedRequest request); +} diff --git a/server/src/com/vaadin/server/WrappedRequest.java b/server/src/com/vaadin/server/WrappedRequest.java index 8ae5335763..0714f73cad 100644 --- a/server/src/com/vaadin/server/WrappedRequest.java +++ b/server/src/com/vaadin/server/WrappedRequest.java @@ -26,9 +26,6 @@ import javax.portlet.PortletRequest; import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; -import com.vaadin.Application; -import com.vaadin.UIRequiresMoreInformationException; -import com.vaadin.annotations.EagerInit; import com.vaadin.ui.UI; /** @@ -218,11 +215,7 @@ 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#getUIForRequest(WrappedRequest)} is called again after - * throwing {@link UIRequiresMoreInformationException} or in - * {@link UI#init(WrappedRequest)} for a UI class not annotated with - * {@link EagerInit} + * cases, for instance in {@link UI#init(WrappedRequest)}. * * @return the browser details, or <code>null</code> if details are not * available diff --git a/server/src/com/vaadin/ui/AbsoluteLayout.java b/server/src/com/vaadin/ui/AbsoluteLayout.java index 794de49671..e3eecaac12 100644 --- a/server/src/com/vaadin/ui/AbsoluteLayout.java +++ b/server/src/com/vaadin/ui/AbsoluteLayout.java @@ -182,7 +182,7 @@ public class AbsoluteLayout extends AbstractLayout implements connectorToPosition.put(c.getConnectorId(), getPosition(c) .getCSSString()); } - getState().setConnectorToCssPosition(connectorToPosition); + getState().connectorToCssPosition = connectorToPosition; } @@ -639,6 +639,7 @@ public class AbsoluteLayout extends AbstractLayout implements * @deprecated Since 7.0, replaced by * {@link #addLayoutClickListener(LayoutClickListener)} **/ + @Override @Deprecated public void addListener(LayoutClickListener listener) { addLayoutClickListener(listener); @@ -654,6 +655,7 @@ public class AbsoluteLayout extends AbstractLayout implements * @deprecated Since 7.0, replaced by * {@link #removeLayoutClickListener(LayoutClickListener)} **/ + @Override @Deprecated public void removeListener(LayoutClickListener listener) { removeLayoutClickListener(listener); diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java index 045173036e..97883b780f 100644 --- a/server/src/com/vaadin/ui/AbstractComponent.java +++ b/server/src/com/vaadin/ui/AbstractComponent.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -40,6 +40,7 @@ import com.vaadin.server.Resource; import com.vaadin.server.Terminal; import com.vaadin.shared.ComponentConstants; import com.vaadin.shared.ComponentState; +import com.vaadin.shared.ui.ComponentStateUtil; import com.vaadin.tools.ReflectTools; /** @@ -118,7 +119,7 @@ public abstract class AbstractComponent extends AbstractClientConnector */ @Override public void setId(String id) { - getState().setId(id); + getState().id = id; } /* @@ -128,7 +129,7 @@ public abstract class AbstractComponent extends AbstractClientConnector */ @Override public String getId() { - return getState().getId(); + return getState().id; } /** @@ -154,8 +155,8 @@ public abstract class AbstractComponent extends AbstractClientConnector @Override public String getStyleName() { String s = ""; - if (getState().getStyles() != null) { - for (final Iterator<String> it = getState().getStyles().iterator(); it + if (ComponentStateUtil.hasStyles(getState())) { + for (final Iterator<String> it = getState().styles.iterator(); it .hasNext();) { s += it.next(); if (it.hasNext()) { @@ -173,13 +174,13 @@ public abstract class AbstractComponent extends AbstractClientConnector @Override public void setStyleName(String style) { if (style == null || "".equals(style)) { - getState().setStyles(null); + getState().styles = null; return; } - if (getState().getStyles() == null) { - getState().setStyles(new ArrayList<String>()); + if (getState().styles == null) { + getState().styles = new ArrayList<String>(); } - List<String> styles = getState().getStyles(); + List<String> styles = getState().styles; styles.clear(); String[] styleParts = style.split(" +"); for (String part : styleParts) { @@ -202,10 +203,10 @@ public abstract class AbstractComponent extends AbstractClientConnector return; } - if (getState().getStyles() == null) { - getState().setStyles(new ArrayList<String>()); + if (getState().styles == null) { + getState().styles = new ArrayList<String>(); } - List<String> styles = getState().getStyles(); + List<String> styles = getState().styles; if (!styles.contains(style)) { styles.add(style); } @@ -213,11 +214,11 @@ public abstract class AbstractComponent extends AbstractClientConnector @Override public void removeStyleName(String style) { - if (getState().getStyles() != null) { + if (ComponentStateUtil.hasStyles(getState())) { String[] styleParts = style.split(" +"); for (String part : styleParts) { if (part.length() > 0) { - getState().getStyles().remove(part); + getState().styles.remove(part); } } } @@ -229,7 +230,7 @@ public abstract class AbstractComponent extends AbstractClientConnector */ @Override public String getCaption() { - return getState().getCaption(); + return getState().caption; } /** @@ -242,7 +243,7 @@ public abstract class AbstractComponent extends AbstractClientConnector */ @Override public void setCaption(String caption) { - getState().setCaption(caption); + getState().caption = caption; } /* @@ -319,7 +320,7 @@ public abstract class AbstractComponent extends AbstractClientConnector */ @Override public boolean isEnabled() { - return getState().isEnabled(); + return getState().enabled; } /* @@ -329,7 +330,7 @@ public abstract class AbstractComponent extends AbstractClientConnector */ @Override public void setEnabled(boolean enabled) { - getState().setEnabled(enabled); + getState().enabled = enabled; } /* @@ -358,7 +359,7 @@ public abstract class AbstractComponent extends AbstractClientConnector * interface. */ public boolean isImmediate() { - return getState().isImmediate(); + return getState().immediate; } /** @@ -371,7 +372,7 @@ public abstract class AbstractComponent extends AbstractClientConnector * @see Component#isImmediate() */ public void setImmediate(boolean immediate) { - getState().setImmediate(immediate); + getState().immediate = immediate; } /* @@ -381,7 +382,7 @@ public abstract class AbstractComponent extends AbstractClientConnector */ @Override public boolean isVisible() { - return getState().isVisible(); + return getState().visible; } /* @@ -391,11 +392,11 @@ public abstract class AbstractComponent extends AbstractClientConnector */ @Override public void setVisible(boolean visible) { - if (getState().isVisible() == visible) { + if (getState().visible == visible) { return; } - getState().setVisible(visible); + getState().visible = visible; if (getParent() != null) { // Must always repaint the parent (at least the hierarchy) when // visibility of a child component changes. @@ -461,7 +462,7 @@ public abstract class AbstractComponent extends AbstractClientConnector * @return component's description <code>String</code> */ public String getDescription() { - return getState().getDescription(); + return getState().description; } /** @@ -477,7 +478,7 @@ public abstract class AbstractComponent extends AbstractClientConnector * the new description string for the component. */ public void setDescription(String description) { - getState().setDescription(description); + getState().description = description; } /* @@ -570,7 +571,7 @@ public abstract class AbstractComponent extends AbstractClientConnector */ @Override public boolean isReadOnly() { - return getState().isReadOnly(); + return getState().readOnly; } /* @@ -579,7 +580,7 @@ public abstract class AbstractComponent extends AbstractClientConnector */ @Override public void setReadOnly(boolean readOnly) { - getState().setReadOnly(readOnly); + getState().readOnly = readOnly; } /* @@ -700,24 +701,24 @@ public abstract class AbstractComponent extends AbstractClientConnector if (getHeight() >= 0 && (getHeightUnits() != Unit.PERCENTAGE || ComponentSizeValidator .parentCanDefineHeight(this))) { - getState().setHeight("" + getCSSHeight()); + getState().height = "" + getCSSHeight(); } else { - getState().setHeight(""); + getState().height = ""; } if (getWidth() >= 0 && (getWidthUnits() != Unit.PERCENTAGE || ComponentSizeValidator .parentCanDefineWidth(this))) { - getState().setWidth("" + getCSSWidth()); + getState().width = "" + getCSSWidth(); } else { - getState().setWidth(""); + getState().width = ""; } ErrorMessage error = getErrorMessage(); if (null != error) { - getState().setErrorMessage(error.getFormattedHtmlMessage()); + getState().errorMessage = error.getFormattedHtmlMessage(); } else { - getState().setErrorMessage(null); + getState().errorMessage = null; } } @@ -766,7 +767,8 @@ public abstract class AbstractComponent extends AbstractClientConnector eventRouter.addListener(eventType, target, method); if (needRepaint) { - getState().addRegisteredEventListener(eventIdentifier); + ComponentStateUtil.addRegisteredEventListener(getState(), + eventIdentifier); } } @@ -814,7 +816,8 @@ public abstract class AbstractComponent extends AbstractClientConnector if (eventRouter != null) { eventRouter.removeListener(eventType, target); if (!eventRouter.hasListeners(eventType)) { - getState().removeRegisteredEventListener(eventIdentifier); + ComponentStateUtil.removeRegisteredEventListener(getState(), + eventIdentifier); } } } diff --git a/server/src/com/vaadin/ui/AbstractComponentContainer.java b/server/src/com/vaadin/ui/AbstractComponentContainer.java index cf3bf1d2b9..31529ca0d6 100644 --- a/server/src/com/vaadin/ui/AbstractComponentContainer.java +++ b/server/src/com/vaadin/ui/AbstractComponentContainer.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -115,6 +115,7 @@ public abstract class AbstractComponentContainer extends AbstractComponent * @deprecated Since 7.0, replaced by * {@link #addComponentAttachListener(com.vaadin.ui.ComponentContainer.ComponentAttachListener)} **/ + @Override @Deprecated public void addListener(ComponentAttachListener listener) { addComponentAttachListener(listener); @@ -131,6 +132,7 @@ public abstract class AbstractComponentContainer extends AbstractComponent * @deprecated Since 7.0, replaced by * {@link #addComponentDetachListener(com.vaadin.ui.ComponentContainer.ComponentDetachListener)} **/ + @Override @Deprecated public void addListener(ComponentDetachListener listener) { addComponentDetachListener(listener); @@ -147,6 +149,7 @@ public abstract class AbstractComponentContainer extends AbstractComponent * @deprecated Since 7.0, replaced by * {@link #removeComponentAttachListener(com.vaadin.ui.ComponentContainer.ComponentAttachListener)} **/ + @Override @Deprecated public void removeListener(ComponentAttachListener listener) { removeComponentAttachListener(listener); @@ -163,6 +166,7 @@ public abstract class AbstractComponentContainer extends AbstractComponent * @deprecated Since 7.0, replaced by * {@link #removeComponentDetachListener(com.vaadin.ui.ComponentContainer.ComponentDetachListener)} **/ + @Override @Deprecated public void removeListener(ComponentDetachListener listener) { removeComponentDetachListener(listener); @@ -240,7 +244,7 @@ public abstract class AbstractComponentContainer extends AbstractComponent @Override public void setVisible(boolean visible) { - if (getState().isVisible() == visible) { + if (getState().visible == visible) { return; } diff --git a/server/src/com/vaadin/ui/AbstractEmbedded.java b/server/src/com/vaadin/ui/AbstractEmbedded.java index d94f62120f..5c72141ef9 100644 --- a/server/src/com/vaadin/ui/AbstractEmbedded.java +++ b/server/src/com/vaadin/ui/AbstractEmbedded.java @@ -52,10 +52,10 @@ public abstract class AbstractEmbedded extends AbstractComponent { * content. */ public void setAlternateText(String altText) { - if (altText != getState().getAlternateText() - || (altText != null && !altText.equals(getState() - .getAlternateText()))) { - getState().setAlternateText(altText); + if (altText != getState().alternateText + || (altText != null && !altText + .equals(getState().alternateText))) { + getState().alternateText = altText; requestRepaint(); } } @@ -67,7 +67,7 @@ public abstract class AbstractEmbedded extends AbstractComponent { * @returns Alternate text */ public String getAlternateText() { - return getState().getAlternateText(); + return getState().alternateText; } } diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java index b1d45ae590..548cb06c8f 100644 --- a/server/src/com/vaadin/ui/AbstractField.java +++ b/server/src/com/vaadin/ui/AbstractField.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -355,11 +355,11 @@ public abstract class AbstractField<T> extends AbstractComponent implements */ @Override public boolean isModified() { - return getState().isModified(); + return getState().modified; } private void setModified(boolean modified) { - getState().setModified(modified); + getState().modified = modified; } /** @@ -632,8 +632,8 @@ public abstract class AbstractField<T> extends AbstractComponent implements // Sets the new data source dataSource = newDataSource; - getState().setPropertyReadOnly( - dataSource == null ? false : dataSource.isReadOnly()); + getState().propertyReadOnly = dataSource == null ? false : dataSource + .isReadOnly(); // Check if the current converter is compatible. if (newDataSource != null @@ -1056,6 +1056,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements * @deprecated Since 7.0, replaced by * {@link #addValueChangeListener(com.vaadin.data.Property.ValueChangeListener)} **/ + @Override @Deprecated public void addListener(Property.ValueChangeListener listener) { addValueChangeListener(listener); @@ -1076,6 +1077,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements * @deprecated Since 7.0, replaced by * {@link #removeValueChangeListener(com.vaadin.data.Property.ValueChangeListener)} **/ + @Override @Deprecated public void removeListener(Property.ValueChangeListener listener) { removeValueChangeListener(listener); @@ -1117,7 +1119,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements */ @Override public void readOnlyStatusChange(Property.ReadOnlyStatusChangeEvent event) { - getState().setPropertyReadOnly(event.getProperty().isReadOnly()); + getState().propertyReadOnly = event.getProperty().isReadOnly(); } /** @@ -1167,6 +1169,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements * @deprecated Since 7.0, replaced by * {@link #addReadOnlyStatusChangeListener(com.vaadin.data.Property.ReadOnlyStatusChangeListener)} **/ + @Override @Deprecated public void addListener(Property.ReadOnlyStatusChangeListener listener) { addReadOnlyStatusChangeListener(listener); @@ -1188,6 +1191,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements * @deprecated Since 7.0, replaced by * {@link #removeReadOnlyStatusChangeListener(com.vaadin.data.Property.ReadOnlyStatusChangeListener)} **/ + @Override @Deprecated public void removeListener(Property.ReadOnlyStatusChangeListener listener) { removeReadOnlyStatusChangeListener(listener); @@ -1258,7 +1262,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements */ @Override public int getTabIndex() { - return getState().getTabIndex(); + return getState().tabIndex; } /* @@ -1268,7 +1272,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements */ @Override public void setTabIndex(int tabIndex) { - getState().setTabIndex(tabIndex); + getState().tabIndex = tabIndex; } /** @@ -1350,7 +1354,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements */ @Override public boolean isRequired() { - return getState().isRequired(); + return getState().required; } /** @@ -1370,7 +1374,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements */ @Override public void setRequired(boolean required) { - getState().setRequired(required); + getState().required = required; } /** @@ -1569,7 +1573,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements super.beforeClientResponse(initial); // Hide the error indicator if needed - getState().setHideErrors(shouldHideErrors()); + getState().hideErrors = shouldHideErrors(); } /** diff --git a/server/src/com/vaadin/ui/AbstractMedia.java b/server/src/com/vaadin/ui/AbstractMedia.java index 3f59b070b7..219413974b 100644 --- a/server/src/com/vaadin/ui/AbstractMedia.java +++ b/server/src/com/vaadin/ui/AbstractMedia.java @@ -56,8 +56,8 @@ public abstract class AbstractMedia extends AbstractComponent { } private void clearSources() { - getState().getSources().clear(); - getState().getSourceTypes().clear(); + getState().sources.clear(); + getState().sourceTypes.clear(); } /** @@ -71,10 +71,10 @@ public abstract class AbstractMedia extends AbstractComponent { */ public void addSource(Resource source) { if (source != null) { - List<URLReference> sources = getState().getSources(); + List<URLReference> sources = getState().sources; sources.add(new ResourceReference(source, this, Integer .toString(sources.size()))); - getState().getSourceTypes().add(source.getMIMEType()); + getState().sourceTypes.add(source.getMIMEType()); } } @@ -83,7 +83,7 @@ public abstract class AbstractMedia extends AbstractComponent { WrappedResponse response, String path) throws IOException { Matcher matcher = Pattern.compile("(\\d+)(/.*)?").matcher(path); if (matcher.matches()) { - List<URLReference> sources = getState().getSources(); + List<URLReference> sources = getState().sources; int sourceIndex = Integer.parseInt(matcher.group(1)); @@ -128,7 +128,7 @@ public abstract class AbstractMedia extends AbstractComponent { */ public List<Resource> getSources() { ArrayList<Resource> sources = new ArrayList<Resource>(); - for (URLReference ref : getState().getSources()) { + for (URLReference ref : getState().sources) { sources.add(((ResourceReference) ref).getResource()); } return sources; @@ -140,14 +140,14 @@ public abstract class AbstractMedia extends AbstractComponent { * @param showControls */ public void setShowControls(boolean showControls) { - getState().setShowControls(showControls); + getState().showControls = showControls; } /** * @return true if the browser is to show native media controls. */ public boolean isShowControls() { - return getState().isShowControls(); + return getState().showControls; } /** @@ -162,7 +162,7 @@ public abstract class AbstractMedia extends AbstractComponent { * @param altText */ public void setAltText(String altText) { - getState().setAltText(altText); + getState().altText = altText; } /** @@ -170,7 +170,7 @@ public abstract class AbstractMedia extends AbstractComponent { * HTML5. */ public String getAltText() { - return getState().getAltText(); + return getState().altText; } /** @@ -180,7 +180,7 @@ public abstract class AbstractMedia extends AbstractComponent { * @param htmlContentAllowed */ public void setHtmlContentAllowed(boolean htmlContentAllowed) { - getState().setHtmlContentAllowed(htmlContentAllowed); + getState().htmlContentAllowed = htmlContentAllowed; } /** @@ -188,7 +188,7 @@ public abstract class AbstractMedia extends AbstractComponent { * be rendered as HTML. */ public boolean isHtmlContentAllowed() { - return getState().isHtmlContentAllowed(); + return getState().htmlContentAllowed; } /** @@ -198,14 +198,14 @@ public abstract class AbstractMedia extends AbstractComponent { * @param autoplay */ public void setAutoplay(boolean autoplay) { - getState().setAutoplay(autoplay); + getState().autoplay = autoplay; } /** * @return true if the media is set to automatically start playback. */ public boolean isAutoplay() { - return getState().isAutoplay(); + return getState().autoplay; } /** @@ -214,14 +214,14 @@ public abstract class AbstractMedia extends AbstractComponent { * @param muted */ public void setMuted(boolean muted) { - getState().setMuted(muted); + getState().muted = muted; } /** * @return true if the audio is muted. */ public boolean isMuted() { - return getState().isMuted(); + return getState().muted; } /** diff --git a/server/src/com/vaadin/ui/AbstractOrderedLayout.java b/server/src/com/vaadin/ui/AbstractOrderedLayout.java index 184f7c40f4..4e27dbb158 100644 --- a/server/src/com/vaadin/ui/AbstractOrderedLayout.java +++ b/server/src/com/vaadin/ui/AbstractOrderedLayout.java @@ -143,11 +143,11 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements } private void componentRemoved(Component c) { - getState().getChildData().remove(c); + getState().childData.remove(c); } private void componentAdded(Component c) { - getState().getChildData().put(c, new ChildComponentData()); + getState().childData.put(c, new ChildComponentData()); } /** @@ -232,11 +232,11 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements @Override public void setComponentAlignment(Component childComponent, Alignment alignment) { - ChildComponentData childData = getState().getChildData().get( + ChildComponentData childData = getState().childData.get( childComponent); if (childData != null) { // Alignments are bit masks - childData.setAlignmentBitmask(alignment.getBitMask()); + childData.alignmentBitmask = alignment.getBitMask(); } else { throw new IllegalArgumentException( "Component must be added to layout before using setComponentAlignment()"); @@ -252,14 +252,14 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements */ @Override public Alignment getComponentAlignment(Component childComponent) { - ChildComponentData childData = getState().getChildData().get( + ChildComponentData childData = getState().childData.get( childComponent); if (childData == null) { throw new IllegalArgumentException( "The given component is not a child of this layout"); } - return new Alignment(childData.getAlignmentBitmask()); + return new Alignment(childData.alignmentBitmask); } /* @@ -269,7 +269,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements */ @Override public void setSpacing(boolean spacing) { - getState().setSpacing(spacing); + getState().spacing = spacing; } /* @@ -279,7 +279,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements */ @Override public boolean isSpacing() { - return getState().isSpacing(); + return getState().spacing; } /** @@ -312,13 +312,13 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements * @param ratio */ public void setExpandRatio(Component component, float ratio) { - ChildComponentData childData = getState().getChildData().get(component); + ChildComponentData childData = getState().childData.get(component); if (childData == null) { throw new IllegalArgumentException( "The given component is not a child of this layout"); } - childData.setExpandRatio(ratio); + childData.expandRatio = ratio; } /** @@ -329,13 +329,13 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements * @return expand ratio of given component, 0.0f by default. */ public float getExpandRatio(Component component) { - ChildComponentData childData = getState().getChildData().get(component); + ChildComponentData childData = getState().childData.get(component); if (childData == null) { throw new IllegalArgumentException( "The given component is not a child of this layout"); } - return childData.getExpandRatio(); + return childData.expandRatio; } @Override @@ -349,6 +349,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements * @deprecated Since 7.0, replaced by * {@link #addLayoutClickListener(LayoutClickListener)} **/ + @Override @Deprecated public void addListener(LayoutClickListener listener) { addLayoutClickListener(listener); @@ -364,6 +365,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements * @deprecated Since 7.0, replaced by * {@link #removeLayoutClickListener(LayoutClickListener)} **/ + @Override @Deprecated public void removeListener(LayoutClickListener listener) { removeLayoutClickListener(listener); @@ -405,7 +407,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements */ @Override public MarginInfo getMargin() { - return new MarginInfo(getState().getMarginsBitmask()); + return new MarginInfo(getState().marginsBitmask); } /* @@ -415,6 +417,6 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements */ @Override public void setMargin(MarginInfo marginInfo) { - getState().setMarginsBitmask(marginInfo.getBitMask()); + getState().marginsBitmask = marginInfo.getBitMask(); } } diff --git a/server/src/com/vaadin/ui/AbstractSelect.java b/server/src/com/vaadin/ui/AbstractSelect.java index 3dba5088df..2fc3bf4080 100644 --- a/server/src/com/vaadin/ui/AbstractSelect.java +++ b/server/src/com/vaadin/ui/AbstractSelect.java @@ -40,12 +40,11 @@ import com.vaadin.event.dd.acceptcriteria.ClientSideCriterion; import com.vaadin.event.dd.acceptcriteria.ContainsDataFlavor; import com.vaadin.event.dd.acceptcriteria.TargetDetailIs; import com.vaadin.server.KeyMapper; +import com.vaadin.server.LegacyComponent; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.server.Resource; -import com.vaadin.server.LegacyComponent; import com.vaadin.shared.ui.dd.VerticalDropLocation; -import com.vaadin.ui.AbstractSelect.ItemCaptionMode; /** * <p> @@ -109,43 +108,44 @@ public abstract class AbstractSelect extends AbstractField<Object> implements } /** - * @deprecated from 7.0, use {@link ItemCaptionMode.ID} instead + * @deprecated from 7.0, use {@link ItemCaptionMode#ID} instead */ @Deprecated public static final ItemCaptionMode ITEM_CAPTION_MODE_ID = ItemCaptionMode.ID; /** - * @deprecated from 7.0, use {@link ItemCaptionMode.ID} instead + * @deprecated from 7.0, use {@link ItemCaptionMode#ITEM} instead */ @Deprecated public static final ItemCaptionMode ITEM_CAPTION_MODE_ITEM = ItemCaptionMode.ITEM; /** - * @deprecated from 7.0, use {@link ItemCaptionMode.ID} instead + * @deprecated from 7.0, use {@link ItemCaptionMode#INDEX} instead */ @Deprecated public static final ItemCaptionMode ITEM_CAPTION_MODE_INDEX = ItemCaptionMode.INDEX; /** - * @deprecated from 7.0, use {@link ItemCaptionMode.ID} instead + * @deprecated from 7.0, use {@link ItemCaptionMode#EXPLICIT_DEFAULTS_ID} + * instead */ @Deprecated public static final ItemCaptionMode ITEM_CAPTION_MODE_EXPLICIT_DEFAULTS_ID = ItemCaptionMode.EXPLICIT_DEFAULTS_ID; /** - * @deprecated from 7.0, use {@link ItemCaptionMode.ID} instead + * @deprecated from 7.0, use {@link ItemCaptionMode#EXPLICIT} instead */ @Deprecated public static final ItemCaptionMode ITEM_CAPTION_MODE_EXPLICIT = ItemCaptionMode.EXPLICIT; /** - * @deprecated from 7.0, use {@link ItemCaptionMode.ID} instead + * @deprecated from 7.0, use {@link ItemCaptionMode#ICON_ONLY} instead */ @Deprecated public static final ItemCaptionMode ITEM_CAPTION_MODE_ICON_ONLY = ItemCaptionMode.ICON_ONLY; /** - * @deprecated from 7.0, use {@link ItemCaptionMode.ID} instead + * @deprecated from 7.0, use {@link ItemCaptionMode#PROPERTY} instead */ @Deprecated public static final ItemCaptionMode ITEM_CAPTION_MODE_PROPERTY = ItemCaptionMode.PROPERTY; diff --git a/server/src/com/vaadin/ui/AbstractSplitPanel.java b/server/src/com/vaadin/ui/AbstractSplitPanel.java index f1452caacf..c5df57b36f 100644 --- a/server/src/com/vaadin/ui/AbstractSplitPanel.java +++ b/server/src/com/vaadin/ui/AbstractSplitPanel.java @@ -56,7 +56,7 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { @Override public void setSplitterPosition(float position) { - getSplitterState().setPosition(position); + getSplitterState().position = position; } }; @@ -150,7 +150,7 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { // detach old removeComponent(getFirstComponent()); } - getState().setFirstChild(c); + getState().firstChild = c; if (c != null) { super.addComponent(c); } @@ -173,7 +173,7 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { // detach old removeComponent(getSecondComponent()); } - getState().setSecondChild(c); + getState().secondChild = c; if (c != null) { super.addComponent(c); } @@ -186,7 +186,7 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { * @return the first component of this split panel */ public Component getFirstComponent() { - return (Component) getState().getFirstChild(); + return (Component) getState().firstChild; } /** @@ -196,7 +196,7 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { * @return the second component of this split panel */ public Component getSecondComponent() { - return (Component) getState().getSecondChild(); + return (Component) getState().secondChild; } /** @@ -210,9 +210,9 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { public void removeComponent(Component c) { super.removeComponent(c); if (c == getFirstComponent()) { - getState().setFirstChild(null); + getState().firstChild = null; } else if (c == getSecondComponent()) { - getState().setSecondChild(null); + getState().secondChild = null; } markAsDirty(); } @@ -322,9 +322,9 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { pos = Math.round(pos); } SplitterState splitterState = getSplitterState(); - splitterState.setPosition(pos); - splitterState.setPositionUnit(unit.getSymbol()); - splitterState.setPositionReversed(reverse); + splitterState.position = pos; + splitterState.positionUnit = unit.getSymbol(); + splitterState.positionReversed = reverse; posUnit = unit; } @@ -335,7 +335,7 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { * @return position of the splitter */ public float getSplitPosition() { - return getSplitterState().getPosition(); + return getSplitterState().position; } /** @@ -358,7 +358,7 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { * Allowed units are UNITS_PERCENTAGE and UNITS_PIXELS */ public void setMinSplitPosition(int pos, Unit unit) { - setSplitPositionLimits(pos, unit, getSplitterState().getMaxPosition(), + setSplitPositionLimits(pos, unit, getSplitterState().maxPosition, posMaxUnit); } @@ -369,7 +369,7 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { * @return the minimum position of the splitter */ public float getMinSplitPosition() { - return getSplitterState().getMinPosition(); + return getSplitterState().minPosition; } /** @@ -392,7 +392,7 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { * Allowed units are UNITS_PERCENTAGE and UNITS_PIXELS */ public void setMaxSplitPosition(float pos, Unit unit) { - setSplitPositionLimits(getSplitterState().getMinPosition(), posMinUnit, + setSplitPositionLimits(getSplitterState().minPosition, posMinUnit, pos, unit); } @@ -403,7 +403,7 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { * @return the maximum position of the splitter */ public float getMaxSplitPosition() { - return getSplitterState().getMaxPosition(); + return getSplitterState().maxPosition; } /** @@ -440,12 +440,12 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { SplitterState state = getSplitterState(); - state.setMinPosition(minPos); - state.setMinPositionUnit(minPosUnit.getSymbol()); + state.minPosition = minPos; + state.minPositionUnit = minPosUnit.getSymbol(); posMinUnit = minPosUnit; - state.setMaxPosition(maxPos); - state.setMaxPositionUnit(maxPosUnit.getSymbol()); + state.maxPosition = maxPos; + state.maxPositionUnit = maxPosUnit.getSymbol(); posMaxUnit = maxPosUnit; } @@ -457,7 +457,7 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { * Set <code>true</code> if locked, <code>false</code> otherwise. */ public void setLocked(boolean locked) { - getSplitterState().setLocked(locked); + getSplitterState().locked = locked; } /** @@ -467,7 +467,7 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { * @return <code>true</code> if locked, <code>false</code> otherwise. */ public boolean isLocked() { - return getSplitterState().isLocked(); + return getSplitterState().locked; } /** @@ -535,6 +535,6 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer { } private SplitterState getSplitterState() { - return getState().getSplitterState(); + return getState().splitterState; } } diff --git a/server/src/com/vaadin/ui/AbstractTextField.java b/server/src/com/vaadin/ui/AbstractTextField.java index c187d9e198..0cb74dae6d 100644 --- a/server/src/com/vaadin/ui/AbstractTextField.java +++ b/server/src/com/vaadin/ui/AbstractTextField.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -27,9 +27,9 @@ import com.vaadin.event.FieldEvents.FocusNotifier; import com.vaadin.event.FieldEvents.TextChangeEvent; import com.vaadin.event.FieldEvents.TextChangeListener; import com.vaadin.event.FieldEvents.TextChangeNotifier; +import com.vaadin.server.LegacyComponent; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; -import com.vaadin.server.LegacyComponent; import com.vaadin.shared.ui.textfield.AbstractTextFieldState; import com.vaadin.shared.ui.textfield.TextFieldConstants; @@ -104,7 +104,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements if (value == null) { value = getNullRepresentation(); } - getState().setText(value); + getState().text = value; } @Override @@ -312,7 +312,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements * @return the maxLength */ public int getMaxLength() { - return getState().getMaxLength(); + return getState().maxLength; } /** @@ -323,7 +323,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements * the maxLength to set */ public void setMaxLength(int maxLength) { - getState().setMaxLength(maxLength); + getState().maxLength = maxLength; } /** @@ -334,7 +334,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements * @return the number of columns in the editor. */ public int getColumns() { - return getState().getColumns(); + return getState().columns; } /** @@ -349,7 +349,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements if (columns < 0) { columns = 0; } - getState().setColumns(columns); + getState().columns = columns; } /** @@ -359,7 +359,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements * @return the current input prompt, or null if not enabled */ public String getInputPrompt() { - return getState().getInputPrompt(); + return getState().inputPrompt; } /** @@ -369,7 +369,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements * @param inputPrompt */ public void setInputPrompt(String inputPrompt) { - getState().setInputPrompt(inputPrompt); + getState().inputPrompt = inputPrompt; } /* ** Text Change Events ** */ @@ -521,6 +521,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements * @deprecated Since 7.0, replaced by * {@link #addTextChangeListener(TextChangeListener)} **/ + @Override @Deprecated public void addListener(TextChangeListener listener) { addTextChangeListener(listener); @@ -536,6 +537,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements * @deprecated Since 7.0, replaced by * {@link #removeTextChangeListener(TextChangeListener)} **/ + @Override @Deprecated public void removeListener(TextChangeListener listener) { removeTextChangeListener(listener); @@ -688,6 +690,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements * @deprecated Since 7.0, replaced by * {@link #addFocusListener(FocusListener)} **/ + @Override @Deprecated public void addListener(FocusListener listener) { addFocusListener(listener); @@ -702,6 +705,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements * @deprecated Since 7.0, replaced by * {@link #removeFocusListener(FocusListener)} **/ + @Override @Deprecated public void removeListener(FocusListener listener) { removeFocusListener(listener); @@ -716,6 +720,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements /** * @deprecated Since 7.0, replaced by {@link #addBlurListener(BlurListener)} **/ + @Override @Deprecated public void addListener(BlurListener listener) { addBlurListener(listener); @@ -730,6 +735,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements * @deprecated Since 7.0, replaced by * {@link #removeBlurListener(BlurListener)} **/ + @Override @Deprecated public void removeListener(BlurListener listener) { removeBlurListener(listener); diff --git a/server/src/com/vaadin/ui/Button.java b/server/src/com/vaadin/ui/Button.java index 2e026ebc52..bbed7d540f 100644 --- a/server/src/com/vaadin/ui/Button.java +++ b/server/src/com/vaadin/ui/Button.java @@ -367,6 +367,7 @@ public class Button extends AbstractComponent implements /** * @deprecated Since 7.0, replaced by {@link #addBlurListener(BlurListener)} **/ + @Override @Deprecated public void addListener(BlurListener listener) { addBlurListener(listener); @@ -381,6 +382,7 @@ public class Button extends AbstractComponent implements * @deprecated Since 7.0, replaced by * {@link #removeBlurListener(BlurListener)} **/ + @Override @Deprecated public void removeListener(BlurListener listener) { removeBlurListener(listener); @@ -396,6 +398,7 @@ public class Button extends AbstractComponent implements * @deprecated Since 7.0, replaced by * {@link #addFocusListener(FocusListener)} **/ + @Override @Deprecated public void addListener(FocusListener listener) { addFocusListener(listener); @@ -410,6 +413,7 @@ public class Button extends AbstractComponent implements * @deprecated Since 7.0, replaced by * {@link #removeFocusListener(FocusListener)} **/ + @Override @Deprecated public void removeListener(FocusListener listener) { removeFocusListener(listener); @@ -438,7 +442,7 @@ public class Button extends AbstractComponent implements } clickShortcut = new ClickShortcut(this, keyCode, modifiers); addShortcutListener(clickShortcut); - getState().setClickShortcutKeyCode(clickShortcut.getKeyCode()); + getState().clickShortcutKeyCode = clickShortcut.getKeyCode(); } /** @@ -449,7 +453,7 @@ public class Button extends AbstractComponent implements if (clickShortcut != null) { removeShortcutListener(clickShortcut); clickShortcut = null; - getState().setClickShortcutKeyCode(0); + getState().clickShortcutKeyCode = 0; } } @@ -517,7 +521,7 @@ public class Button extends AbstractComponent implements * @return true if the button is disabled when clicked, false otherwise */ public boolean isDisableOnClick() { - return getState().isDisableOnClick(); + return getState().disableOnClick; } /** @@ -533,7 +537,7 @@ public class Button extends AbstractComponent implements * true to disable button when it is clicked, false otherwise */ public void setDisableOnClick(boolean disableOnClick) { - getState().setDisableOnClick(disableOnClick); + getState().disableOnClick = disableOnClick; } /* @@ -543,7 +547,7 @@ public class Button extends AbstractComponent implements */ @Override public int getTabIndex() { - return getState().getTabIndex(); + return getState().tabIndex; } /* @@ -553,7 +557,7 @@ public class Button extends AbstractComponent implements */ @Override public void setTabIndex(int tabIndex) { - getState().setTabIndex(tabIndex); + getState().tabIndex = tabIndex; } @Override @@ -580,7 +584,7 @@ public class Button extends AbstractComponent implements * <code>false</code> otherwise */ public void setHtmlContentAllowed(boolean htmlContentAllowed) { - getState().setHtmlContentAllowed(htmlContentAllowed); + getState().htmlContentAllowed = htmlContentAllowed; } /** @@ -590,7 +594,7 @@ public class Button extends AbstractComponent implements * <code>false</code> otherwise */ public boolean isHtmlContentAllowed() { - return getState().isHtmlContentAllowed(); + return getState().htmlContentAllowed; } } diff --git a/server/src/com/vaadin/ui/CheckBox.java b/server/src/com/vaadin/ui/CheckBox.java index 149d4779d8..8a42182598 100644 --- a/server/src/com/vaadin/ui/CheckBox.java +++ b/server/src/com/vaadin/ui/CheckBox.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -116,7 +116,7 @@ public class CheckBox extends AbstractField<Boolean> { if (newValue == null) { newValue = false; } - getState().setChecked(newValue); + getState().checked = newValue; } public void addBlurListener(BlurListener listener) { diff --git a/server/src/com/vaadin/ui/ComboBox.java b/server/src/com/vaadin/ui/ComboBox.java index da3d2fd91d..2555aac339 100644 --- a/server/src/com/vaadin/ui/ComboBox.java +++ b/server/src/com/vaadin/ui/ComboBox.java @@ -358,39 +358,45 @@ public class ComboBox extends AbstractSelect implements filterable.addContainerFilter(filter); } - Indexed indexed = (Indexed) container; + // try-finally to ensure that the filter is removed from container even + // if a exception is thrown... + try { + Indexed indexed = (Indexed) container; - int indexToEnsureInView = -1; + int indexToEnsureInView = -1; - // if not an option request (item list when user changes page), go - // to page with the selected item after filtering if accepted by - // filter - Object selection = getValue(); - if (isScrollToSelectedItem() && !optionRequest && selection != null) { - // ensure proper page - indexToEnsureInView = indexed.indexOfId(selection); - } + // if not an option request (item list when user changes page), go + // to page with the selected item after filtering if accepted by + // filter + Object selection = getValue(); + if (isScrollToSelectedItem() && !optionRequest && selection != null) { + // ensure proper page + indexToEnsureInView = indexed.indexOfId(selection); + } - filteredSize = container.size(); - currentPage = adjustCurrentPage(currentPage, needNullSelectOption, - indexToEnsureInView, filteredSize); - int first = getFirstItemIndexOnCurrentPage(needNullSelectOption, - filteredSize); - int last = getLastItemIndexOnCurrentPage(needNullSelectOption, - filteredSize, first); - - List<Object> options = new ArrayList<Object>(); - for (int i = first; i <= last && i < filteredSize; ++i) { - options.add(indexed.getIdByIndex(i)); - } + filteredSize = container.size(); + currentPage = adjustCurrentPage(currentPage, needNullSelectOption, + indexToEnsureInView, filteredSize); + int first = getFirstItemIndexOnCurrentPage(needNullSelectOption, + filteredSize); + int last = getLastItemIndexOnCurrentPage(needNullSelectOption, + filteredSize, first); - // to the outside, filtering should not be visible - if (filter != null) { - filterable.removeContainerFilter(filter); - filteringContainer = false; - } + // Compute the number of items to fetch from the indexes given or + // based on the filtered size of the container + int lastItemToFetch = Math.min(last, filteredSize - 1); + int nrOfItemsToFetch = (lastItemToFetch + 1) - first; + + List<?> options = indexed.getItemIds(first, nrOfItemsToFetch); - return options; + return options; + } finally { + // to the outside, filtering should not be visible + if (filter != null) { + filterable.removeContainerFilter(filter); + filteringContainer = false; + } + } } /** diff --git a/server/src/com/vaadin/ui/CssLayout.java b/server/src/com/vaadin/ui/CssLayout.java index b63c8573ba..9ac29c4deb 100644 --- a/server/src/com/vaadin/ui/CssLayout.java +++ b/server/src/com/vaadin/ui/CssLayout.java @@ -199,12 +199,12 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier { @Override public void beforeClientResponse(boolean initial) { super.beforeClientResponse(initial); - getState().getChildCss().clear(); + getState().childCss.clear(); for (Iterator<Component> ci = getComponentIterator(); ci.hasNext();) { Component child = ci.next(); String componentCssString = getCss(child); if (componentCssString != null) { - getState().getChildCss().put(child, componentCssString); + getState().childCss.put(child, componentCssString); } } @@ -291,6 +291,7 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier { * @deprecated Since 7.0, replaced by * {@link #addLayoutClickListener(LayoutClickListener)} **/ + @Override @Deprecated public void addListener(LayoutClickListener listener) { addLayoutClickListener(listener); @@ -306,6 +307,7 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier { * @deprecated Since 7.0, replaced by * {@link #removeLayoutClickListener(LayoutClickListener)} **/ + @Override @Deprecated public void removeListener(LayoutClickListener listener) { removeLayoutClickListener(listener); diff --git a/server/src/com/vaadin/ui/CustomLayout.java b/server/src/com/vaadin/ui/CustomLayout.java index f747b6ff3b..828a1b91ad 100644 --- a/server/src/com/vaadin/ui/CustomLayout.java +++ b/server/src/com/vaadin/ui/CustomLayout.java @@ -25,9 +25,9 @@ import java.util.Map; import java.util.Set; import com.vaadin.server.JsonPaintTarget; +import com.vaadin.server.LegacyComponent; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; -import com.vaadin.server.LegacyComponent; import com.vaadin.shared.ui.customlayout.CustomLayoutState; /** @@ -142,7 +142,7 @@ public class CustomLayout extends AbstractLayout implements LegacyComponent { removeComponent(old); } slots.put(location, c); - getState().getChildLocations().put(c, location); + getState().childLocations.put(c, location); c.setParent(this); fireComponentAttachEvent(c); } @@ -173,7 +173,7 @@ public class CustomLayout extends AbstractLayout implements LegacyComponent { return; } slots.values().remove(c); - getState().getChildLocations().remove(c); + getState().childLocations.remove(c); super.removeComponent(c); } @@ -247,19 +247,19 @@ public class CustomLayout extends AbstractLayout implements LegacyComponent { } else { slots.put(newLocation, oldComponent); slots.put(oldLocation, newComponent); - getState().getChildLocations().put(newComponent, oldLocation); - getState().getChildLocations().put(oldComponent, newLocation); + getState().childLocations.put(newComponent, oldLocation); + getState().childLocations.put(oldComponent, newLocation); } } /** Get the name of the template */ public String getTemplateName() { - return getState().getTemplateName(); + return getState().templateName; } /** Get the contents of the template */ public String getTemplateContents() { - return getState().getTemplateContents(); + return getState().templateContents; } /** @@ -272,8 +272,8 @@ public class CustomLayout extends AbstractLayout implements LegacyComponent { * @param templateName */ public void setTemplateName(String templateName) { - getState().setTemplateName(templateName); - getState().setTemplateContents(null); + getState().templateName = templateName; + getState().templateContents = null; } /** @@ -282,8 +282,8 @@ public class CustomLayout extends AbstractLayout implements LegacyComponent { * @param templateContents */ public void setTemplateContents(String templateContents) { - getState().setTemplateContents(templateContents); - getState().setTemplateName(null); + getState().templateContents = templateContents; + getState().templateName = null; } @Override @@ -295,7 +295,7 @@ public class CustomLayout extends AbstractLayout implements LegacyComponent { public void paintContent(PaintTarget target) throws PaintException { // Workaround to make the CommunicationManager read the template file // and send it to the client - String templateName = getState().getTemplateName(); + String templateName = getState().templateName; if (templateName != null && templateName.length() != 0) { Set<Object> usedResources = ((JsonPaintTarget) target) .getUsedResources(); diff --git a/server/src/com/vaadin/ui/Flash.java b/server/src/com/vaadin/ui/Flash.java index 0e6cf63a91..d39f34634e 100644 --- a/server/src/com/vaadin/ui/Flash.java +++ b/server/src/com/vaadin/ui/Flash.java @@ -33,10 +33,10 @@ public class Flash extends AbstractEmbedded { * The base path */ public void setCodebase(String codebase) { - if (codebase != getState().getCodebase() + if (codebase != getState().codebase || (codebase != null && !codebase.equals(getState() - .getCodebase()))) { - getState().setCodebase(codebase); +.codebase))) { + getState().codebase = codebase; requestRepaint(); } } @@ -52,10 +52,10 @@ public class Flash extends AbstractEmbedded { * the codetype to set. */ public void setCodetype(String codetype) { - if (codetype != getState().getCodetype() + if (codetype != getState().codetype || (codetype != null && !codetype.equals(getState() - .getCodetype()))) { - getState().setCodetype(codetype); +.codetype))) { + getState().codetype = codetype; requestRepaint(); } } @@ -73,17 +73,17 @@ public class Flash extends AbstractEmbedded { * object */ public void setArchive(String archive) { - if (archive != getState().getArchive() - || (archive != null && !archive.equals(getState().getArchive()))) { - getState().setArchive(archive); + if (archive != getState().archive + || (archive != null && !archive.equals(getState().archive))) { + getState().archive = archive; requestRepaint(); } } public void setStandby(String standby) { - if (standby != getState().getStandby() - || (standby != null && !standby.equals(getState().getStandby()))) { - getState().setStandby(standby); + if (standby != getState().standby + || (standby != null && !standby.equals(getState().standby))) { + getState().standby = standby; requestRepaint(); } } @@ -100,10 +100,10 @@ public class Flash extends AbstractEmbedded { * the value of the parameter. */ public void setParameter(String name, String value) { - if (getState().getEmbedParams() == null) { - getState().setEmbedParams(new HashMap<String, String>()); + if (getState().embedParams == null) { + getState().embedParams = new HashMap<String, String>(); } - getState().getEmbedParams().put(name, value); + getState().embedParams.put(name, value); requestRepaint(); } @@ -115,8 +115,8 @@ public class Flash extends AbstractEmbedded { * @return the Value of parameter or null if not found. */ public String getParameter(String name) { - return getState().getEmbedParams() != null ? getState() - .getEmbedParams().get(name) : null; + return getState().embedParams != null ? getState().embedParams + .get(name) : null; } /** @@ -126,10 +126,10 @@ public class Flash extends AbstractEmbedded { * the name of the parameter to remove. */ public void removeParameter(String name) { - if (getState().getEmbedParams() == null) { + if (getState().embedParams == null) { return; } - getState().getEmbedParams().remove(name); + getState().embedParams.remove(name); requestRepaint(); } diff --git a/server/src/com/vaadin/ui/Form.java b/server/src/com/vaadin/ui/Form.java index 7e77117acb..dd804ef67a 100644 --- a/server/src/com/vaadin/ui/Form.java +++ b/server/src/com/vaadin/ui/Form.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -39,10 +39,10 @@ import com.vaadin.event.ActionManager; import com.vaadin.server.AbstractErrorMessage; import com.vaadin.server.CompositeErrorMessage; import com.vaadin.server.ErrorMessage; +import com.vaadin.server.LegacyComponent; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.server.UserError; -import com.vaadin.server.LegacyComponent; import com.vaadin.shared.ui.form.FormState; /** @@ -776,7 +776,7 @@ public class Form extends AbstractField<Object> implements Item.Editor, * @return the Layout of the form. */ public Layout getLayout() { - return (Layout) getState().getLayout(); + return (Layout) getState().layout; } /** @@ -819,7 +819,7 @@ public class Form extends AbstractField<Object> implements Item.Editor, // Replace the previous layout layout.setParent(this); - getState().setLayout(layout); + getState().layout = layout; } /** @@ -1214,7 +1214,7 @@ public class Form extends AbstractField<Object> implements Item.Editor, * @return layout rendered below normal form contents. */ public Layout getFooter() { - return (Layout) getState().getFooter(); + return (Layout) getState().footer; } /** @@ -1233,7 +1233,7 @@ public class Form extends AbstractField<Object> implements Item.Editor, footer = new HorizontalLayout(); } - getState().setFooter(footer); + getState().footer = footer; footer.setParent(this); } diff --git a/server/src/com/vaadin/ui/GridLayout.java b/server/src/com/vaadin/ui/GridLayout.java index 21602c6802..de167962e7 100644 --- a/server/src/com/vaadin/ui/GridLayout.java +++ b/server/src/com/vaadin/ui/GridLayout.java @@ -27,10 +27,10 @@ import java.util.Map.Entry; import com.vaadin.event.LayoutEvents.LayoutClickEvent; import com.vaadin.event.LayoutEvents.LayoutClickListener; import com.vaadin.event.LayoutEvents.LayoutClickNotifier; +import com.vaadin.server.LegacyComponent; import com.vaadin.server.LegacyPaint; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; -import com.vaadin.server.LegacyComponent; import com.vaadin.shared.Connector; import com.vaadin.shared.EventId; import com.vaadin.shared.MouseEventDetails; @@ -961,7 +961,7 @@ public class GridLayout extends AbstractLayout implements } } - getState().setColumns(columns); + getState().columns = columns; } /** @@ -970,7 +970,7 @@ public class GridLayout extends AbstractLayout implements * @return the number of columns in the grid. */ public int getColumns() { - return getState().getColumns(); + return getState().columns; } /** @@ -1003,7 +1003,7 @@ public class GridLayout extends AbstractLayout implements } } - getState().setRows(rows); + getState().rows = rows; } /** @@ -1012,7 +1012,7 @@ public class GridLayout extends AbstractLayout implements * @return the number of rows in the grid. */ public int getRows() { - return getState().getRows(); + return getState().rows; } /** @@ -1127,7 +1127,7 @@ public class GridLayout extends AbstractLayout implements */ @Override public void setSpacing(boolean spacing) { - getState().setSpacing(spacing); + getState().spacing = spacing; } /* @@ -1137,7 +1137,7 @@ public class GridLayout extends AbstractLayout implements */ @Override public boolean isSpacing() { - return getState().isSpacing(); + return getState().spacing; } /** @@ -1405,7 +1405,7 @@ public class GridLayout extends AbstractLayout implements */ @Override public void setMargin(MarginInfo marginInfo) { - getState().setMarginsBitmask(marginInfo.getBitMask()); + getState().marginsBitmask = marginInfo.getBitMask(); } /* @@ -1415,7 +1415,7 @@ public class GridLayout extends AbstractLayout implements */ @Override public MarginInfo getMargin() { - return new MarginInfo(getState().getMarginsBitmask()); + return new MarginInfo(getState().marginsBitmask); } } diff --git a/server/src/com/vaadin/ui/JavaScript.java b/server/src/com/vaadin/ui/JavaScript.java index f3e8564fab..f9324ba321 100644 --- a/server/src/com/vaadin/ui/JavaScript.java +++ b/server/src/com/vaadin/ui/JavaScript.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -93,7 +93,7 @@ public class JavaScript extends AbstractExtension { */ public void addFunction(String name, JavaScriptFunction function) { functions.put(name, function); - getState().getNames().add(name); + getState().names.add(name); } /** @@ -109,7 +109,7 @@ public class JavaScript extends AbstractExtension { */ public void removeFunction(String name) { functions.remove(name); - getState().getNames().remove(name); + getState().names.remove(name); } /** diff --git a/server/src/com/vaadin/ui/Panel.java b/server/src/com/vaadin/ui/Panel.java index 6f399bcc19..de34c0be2c 100644 --- a/server/src/com/vaadin/ui/Panel.java +++ b/server/src/com/vaadin/ui/Panel.java @@ -25,10 +25,10 @@ import com.vaadin.event.Action.Handler; import com.vaadin.event.ActionManager; import com.vaadin.event.MouseEvents.ClickEvent; import com.vaadin.event.MouseEvents.ClickListener; +import com.vaadin.server.LegacyComponent; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.server.Scrollable; -import com.vaadin.server.LegacyComponent; import com.vaadin.shared.EventId; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.panel.PanelServerRpc; @@ -83,7 +83,7 @@ public class Panel extends AbstractComponentContainer implements Scrollable, registerRpc(rpc); setContent(content); setWidth(100, Unit.PERCENTAGE); - getState().setTabIndex(-1); + getState().tabIndex = -1; } /** @@ -269,11 +269,11 @@ public class Panel extends AbstractComponentContainer implements Scrollable, final Integer newScrollY = (Integer) variables.get("scrollTop"); if (newScrollX != null && newScrollX.intValue() != getScrollLeft()) { // set internally, not to fire request repaint - getState().setScrollLeft(newScrollX.intValue()); + getState().scrollLeft = newScrollX.intValue(); } if (newScrollY != null && newScrollY.intValue() != getScrollTop()) { // set internally, not to fire request repaint - getState().setScrollTop(newScrollY.intValue()); + getState().scrollTop = newScrollY.intValue(); } // Actions @@ -292,7 +292,7 @@ public class Panel extends AbstractComponentContainer implements Scrollable, */ @Override public int getScrollLeft() { - return getState().getScrollLeft(); + return getState().scrollLeft; } /* @@ -302,7 +302,7 @@ public class Panel extends AbstractComponentContainer implements Scrollable, */ @Override public int getScrollTop() { - return getState().getScrollTop(); + return getState().scrollTop; } /* @@ -316,7 +316,7 @@ public class Panel extends AbstractComponentContainer implements Scrollable, throw new IllegalArgumentException( "Scroll offset must be at least 0"); } - getState().setScrollLeft(scrollLeft); + getState().scrollLeft = scrollLeft; } /* @@ -330,7 +330,7 @@ public class Panel extends AbstractComponentContainer implements Scrollable, throw new IllegalArgumentException( "Scroll offset must be at least 0"); } - getState().setScrollTop(scrollTop); + getState().scrollTop = scrollTop; } /* Documented in superclass */ @@ -471,7 +471,7 @@ public class Panel extends AbstractComponentContainer implements Scrollable, */ @Override public int getTabIndex() { - return getState().getTabIndex(); + return getState().tabIndex; } /** @@ -479,7 +479,7 @@ public class Panel extends AbstractComponentContainer implements Scrollable, */ @Override public void setTabIndex(int tabIndex) { - getState().setTabIndex(tabIndex); + getState().tabIndex = tabIndex; } /** diff --git a/server/src/com/vaadin/ui/Slider.java b/server/src/com/vaadin/ui/Slider.java index 660bf739ae..fe913f6b2c 100644 --- a/server/src/com/vaadin/ui/Slider.java +++ b/server/src/com/vaadin/ui/Slider.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -25,10 +25,10 @@ import com.vaadin.shared.ui.slider.SliderState; * * Example code: <code> * class MyPlayer extends CustomComponent implements ValueChangeListener { - * + * * Label volumeIndicator = new Label(); * Slider slider; - * + * * public MyPlayer() { * VerticalLayout vl = new VerticalLayout(); * setCompositionRoot(vl); @@ -68,11 +68,11 @@ public class Slider extends AbstractField<Double> { } catch (final ValueOutOfBoundsException e) { // Convert to nearest bound double out = e.getValue().doubleValue(); - if (out < getState().getMinValue()) { - out = getState().getMinValue(); + if (out < getState().minValue) { + out = getState().minValue; } - if (out > getState().getMaxValue()) { - out = getState().getMaxValue(); + if (out > getState().maxValue) { + out = getState().maxValue; } Slider.super.setValue(new Double(out), false); } @@ -88,7 +88,7 @@ public class Slider extends AbstractField<Double> { public Slider() { super(); registerRpc(rpc); - super.setValue(new Double(getState().getMinValue())); + super.setValue(new Double(getState().minValue)); } /** @@ -164,7 +164,7 @@ public class Slider extends AbstractField<Double> { * @return the largest value the slider can have */ public double getMax() { - return getState().getMaxValue(); + return getState().maxValue; } /** @@ -175,7 +175,7 @@ public class Slider extends AbstractField<Double> { * The new maximum slider value */ public void setMax(double max) { - getState().setMaxValue(max); + getState().maxValue = max; if (getValue() > max) { setValue(max); } @@ -187,7 +187,7 @@ public class Slider extends AbstractField<Double> { * @return the smallest value the slider can have */ public double getMin() { - return getState().getMinValue(); + return getState().minValue; } /** @@ -198,7 +198,7 @@ public class Slider extends AbstractField<Double> { * The new minimum slider value */ public void setMin(double min) { - getState().setMinValue(min); + getState().minValue = min; if (getValue() < min) { setValue(min); } @@ -211,7 +211,7 @@ public class Slider extends AbstractField<Double> { * {@link SliderOrientation#VERTICAL} */ public SliderOrientation getOrientation() { - return getState().getOrientation(); + return getState().orientation; } /** @@ -223,7 +223,7 @@ public class Slider extends AbstractField<Double> { * {@link SliderOrientation#VERTICAL} */ public void setOrientation(SliderOrientation orientation) { - getState().setOrientation(orientation); + getState().orientation = orientation; } /** @@ -233,7 +233,7 @@ public class Slider extends AbstractField<Double> { * @return resolution */ public int getResolution() { - return getState().getResolution(); + return getState().resolution; } /** @@ -250,7 +250,7 @@ public class Slider extends AbstractField<Double> { throw new IllegalArgumentException( "Cannot set a negative resolution to Slider"); } - getState().setResolution(resolution); + getState().resolution = resolution; } /** @@ -284,7 +284,7 @@ public class Slider extends AbstractField<Double> { } } - getState().setValue(newValue); + getState().value = newValue; super.setValue(newValue, repaintIsNotNeeded); } @@ -296,7 +296,7 @@ public class Slider extends AbstractField<Double> { } super.setValue(newFieldValue); // The cast is safe if the above call returned without throwing - getState().setValue((Double) newFieldValue); + getState().value = (Double) newFieldValue; } /** diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java index d1bdcdd708..5eb18ee61f 100644 --- a/server/src/com/vaadin/ui/Table.java +++ b/server/src/com/vaadin/ui/Table.java @@ -27,6 +27,7 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.StringTokenizer; @@ -1066,6 +1067,23 @@ public class Table extends AbstractSelect implements Action.Container, return currentPageFirstItemId; } + /** + * Returns the item ID for the item represented by the index given. Assumes + * that the current container implements {@link Container.Indexed}. + * + * See {@link Container.Indexed#getIdByIndex(int)} for more information + * about the exceptions that can be thrown. + * + * @param index + * the index for which the item ID should be fetched + * @return the item ID for the given index + * + * @throws ClassCastException + * if container does not implement {@link Container.Indexed} + * @throws IndexOutOfBoundsException + * thrown by {@link Container.Indexed#getIdByIndex(int)} if the + * index is invalid + */ protected Object getIdByIndex(int index) { return ((Container.Indexed) items).getIdByIndex(index); } @@ -1929,17 +1947,6 @@ public class Table extends AbstractSelect implements Action.Container, return cells; } - // Gets the first item id - Object id; - if (items instanceof Container.Indexed) { - id = getIdByIndex(firstIndex); - } else { - id = firstItemId(); - for (int i = 0; i < firstIndex; i++) { - id = nextItemId(id); - } - } - final RowHeaderMode headmode = getRowHeaderMode(); final boolean[] iscomponent = new boolean[cols]; for (int i = 0; i < cols; i++) { @@ -1956,120 +1963,41 @@ public class Table extends AbstractSelect implements Action.Container, // Creates the page contents int filledRows = 0; - for (int i = 0; i < rows && id != null; i++) { - cells[CELL_ITEMID][i] = id; - cells[CELL_KEY][i] = itemIdMapper.key(id); - if (headmode != ROW_HEADER_MODE_HIDDEN) { - switch (headmode) { - case INDEX: - cells[CELL_HEADER][i] = String.valueOf(i + firstIndex + 1); - break; - default: - cells[CELL_HEADER][i] = getItemCaption(id); - } - cells[CELL_ICON][i] = getItemIcon(id); + if (items instanceof Container.Indexed) { + // more efficient implementation for containers supporting access by + // index + + Container.Indexed indexed = ((Container.Indexed) items); + List<?> itemIds = indexed.getItemIds(firstIndex, rows); + for (int i = 0; i < rows && i < itemIds.size(); i++) { + Object id = itemIds.get(i); + // Start by parsing the values, id should already be set + parseItemIdToCells(cells, id, i, firstIndex, headmode, cols, + colids, firstIndexNotInCache, iscomponent, + oldListenedProperties); + + filledRows++; } + } else { + // slow back-up implementation for cases where the container does + // not support access by index - GeneratedRow generatedRow = rowGenerator != null ? rowGenerator - .generateRow(this, id) : null; - cells[CELL_GENERATED_ROW][i] = generatedRow; - - for (int j = 0; j < cols; j++) { - if (isColumnCollapsed(colids[j])) { - continue; - } - Property<?> p = null; - Object value = ""; - boolean isGeneratedRow = generatedRow != null; - boolean isGeneratedColumn = columnGenerators - .containsKey(colids[j]); - boolean isGenerated = isGeneratedRow || isGeneratedColumn; - - if (!isGenerated) { - p = getContainerProperty(id, colids[j]); - } - - if (isGeneratedRow) { - if (generatedRow.isSpanColumns() && j > 0) { - value = null; - } else if (generatedRow.isSpanColumns() && j == 0 - && generatedRow.getValue() instanceof Component) { - value = generatedRow.getValue(); - } else if (generatedRow.getText().length > j) { - value = generatedRow.getText()[j]; - } - } else { - // check in current pageBuffer already has row - int index = firstIndex + i; - if (p != null || isGenerated) { - int indexInOldBuffer = index - pageBufferFirstIndex; - if (index < firstIndexNotInCache - && index >= pageBufferFirstIndex - && pageBuffer[CELL_GENERATED_ROW][indexInOldBuffer] == null - && id.equals(pageBuffer[CELL_ITEMID][indexInOldBuffer])) { - // we already have data in our cache, - // recycle it instead of fetching it via - // getValue/getPropertyValue - value = pageBuffer[CELL_FIRSTCOL + j][indexInOldBuffer]; - if (!isGeneratedColumn && iscomponent[j] - || !(value instanceof Component)) { - listenProperty(p, oldListenedProperties); - } - } else { - if (isGeneratedColumn) { - ColumnGenerator cg = columnGenerators - .get(colids[j]); - value = cg.generateCell(this, id, colids[j]); - if (value != null - && !(value instanceof Component) - && !(value instanceof String)) { - // Avoid errors if a generator returns - // something - // other than a Component or a String - value = value.toString(); - } - } else if (iscomponent[j]) { - value = p.getValue(); - listenProperty(p, oldListenedProperties); - } else if (p != null) { - value = getPropertyValue(id, colids[j], p); - /* - * If returned value is Component (via - * fieldfactory or overridden getPropertyValue) - * we excpect it to listen property value - * changes. Otherwise if property emits value - * change events, table will start to listen - * them and refresh content when needed. - */ - if (!(value instanceof Component)) { - listenProperty(p, oldListenedProperties); - } - } else { - value = getPropertyValue(id, colids[j], null); - } - } - } - } - - if (value instanceof Component) { - registerComponent((Component) value); - } - cells[CELL_FIRSTCOL + j][i] = value; + // Gets the first item id + Object id = firstItemId(); + for (int i = 0; i < firstIndex; i++) { + id = nextItemId(id); } + for (int i = 0; i < rows && id != null; i++) { + // Start by parsing the values, id should already be set + parseItemIdToCells(cells, id, i, firstIndex, headmode, cols, + colids, firstIndexNotInCache, iscomponent, + oldListenedProperties); - // Gets the next item id - if (items instanceof Container.Indexed) { - int index = firstIndex + i + 1; - if (index < size()) { - id = getIdByIndex(index); - } else { - id = null; - } - } else { + // Gets the next item id for non indexed container id = nextItemId(id); - } - filledRows++; + filledRows++; + } } // Assures that all the rows of the cell-buffer are valid @@ -2089,6 +2017,117 @@ public class Table extends AbstractSelect implements Action.Container, return cells; } + /** + * Update a cache array for a row, register any relevant listeners etc. + * + * This is an internal method extracted from + * {@link #getVisibleCellsNoCache(int, int, boolean)} and should be removed + * when the Table is rewritten. + */ + private void parseItemIdToCells(Object[][] cells, Object id, int i, + int firstIndex, RowHeaderMode headmode, int cols, Object[] colids, + int firstIndexNotInCache, boolean[] iscomponent, + HashSet<Property<?>> oldListenedProperties) { + + cells[CELL_ITEMID][i] = id; + cells[CELL_KEY][i] = itemIdMapper.key(id); + if (headmode != ROW_HEADER_MODE_HIDDEN) { + switch (headmode) { + case INDEX: + cells[CELL_HEADER][i] = String.valueOf(i + firstIndex + 1); + break; + default: + cells[CELL_HEADER][i] = getItemCaption(id); + } + cells[CELL_ICON][i] = getItemIcon(id); + } + + GeneratedRow generatedRow = rowGenerator != null ? rowGenerator + .generateRow(this, id) : null; + cells[CELL_GENERATED_ROW][i] = generatedRow; + + for (int j = 0; j < cols; j++) { + if (isColumnCollapsed(colids[j])) { + continue; + } + Property<?> p = null; + Object value = ""; + boolean isGeneratedRow = generatedRow != null; + boolean isGeneratedColumn = columnGenerators.containsKey(colids[j]); + boolean isGenerated = isGeneratedRow || isGeneratedColumn; + + if (!isGenerated) { + p = getContainerProperty(id, colids[j]); + } + + if (isGeneratedRow) { + if (generatedRow.isSpanColumns() && j > 0) { + value = null; + } else if (generatedRow.isSpanColumns() && j == 0 + && generatedRow.getValue() instanceof Component) { + value = generatedRow.getValue(); + } else if (generatedRow.getText().length > j) { + value = generatedRow.getText()[j]; + } + } else { + // check in current pageBuffer already has row + int index = firstIndex + i; + if (p != null || isGenerated) { + int indexInOldBuffer = index - pageBufferFirstIndex; + if (index < firstIndexNotInCache + && index >= pageBufferFirstIndex + && pageBuffer[CELL_GENERATED_ROW][indexInOldBuffer] == null + && id.equals(pageBuffer[CELL_ITEMID][indexInOldBuffer])) { + // we already have data in our cache, + // recycle it instead of fetching it via + // getValue/getPropertyValue + value = pageBuffer[CELL_FIRSTCOL + j][indexInOldBuffer]; + if (!isGeneratedColumn && iscomponent[j] + || !(value instanceof Component)) { + listenProperty(p, oldListenedProperties); + } + } else { + if (isGeneratedColumn) { + ColumnGenerator cg = columnGenerators + .get(colids[j]); + value = cg.generateCell(this, id, colids[j]); + if (value != null && !(value instanceof Component) + && !(value instanceof String)) { + // Avoid errors if a generator returns + // something + // other than a Component or a String + value = value.toString(); + } + } else if (iscomponent[j]) { + value = p.getValue(); + listenProperty(p, oldListenedProperties); + } else if (p != null) { + value = getPropertyValue(id, colids[j], p); + /* + * If returned value is Component (via fieldfactory + * or overridden getPropertyValue) we expect it to + * listen property value changes. Otherwise if + * property emits value change events, table will + * start to listen them and refresh content when + * needed. + */ + if (!(value instanceof Component)) { + listenProperty(p, oldListenedProperties); + } + } else { + value = getPropertyValue(id, colids[j], null); + } + } + } + } + + if (value instanceof Component) { + registerComponent((Component) value); + } + cells[CELL_FIRSTCOL + j][i] = value; + } + } + protected void registerComponent(Component component) { getLogger().finest( "Registered " + component.getClass().getSimpleName() + ": " diff --git a/server/src/com/vaadin/ui/TextArea.java b/server/src/com/vaadin/ui/TextArea.java index 0dc9722eb3..cc8e947e24 100644 --- a/server/src/com/vaadin/ui/TextArea.java +++ b/server/src/com/vaadin/ui/TextArea.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -95,7 +95,7 @@ public class TextArea extends AbstractTextField { if (rows < 0) { rows = 0; } - getState().setRows(rows); + getState().rows = rows; } /** @@ -104,7 +104,7 @@ public class TextArea extends AbstractTextField { * @return number of explicitly set rows. */ public int getRows() { - return getState().getRows(); + return getState().rows; } /** @@ -115,7 +115,7 @@ public class TextArea extends AbstractTextField { * word-wrap mode. */ public void setWordwrap(boolean wordwrap) { - getState().setWordwrap(wordwrap); + getState().wordwrap = wordwrap; } /** @@ -125,7 +125,7 @@ public class TextArea extends AbstractTextField { * <code>false</code> if not. */ public boolean isWordwrap() { - return getState().isWordwrap(); + return getState().wordwrap; } } diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index a59b96d27a..d1ccaacde3 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -28,21 +28,20 @@ import java.util.LinkedHashSet; import java.util.Map; import com.vaadin.Application; -import com.vaadin.annotations.EagerInit; import com.vaadin.event.Action; import com.vaadin.event.Action.Handler; import com.vaadin.event.ActionManager; import com.vaadin.event.MouseEvents.ClickEvent; import com.vaadin.event.MouseEvents.ClickListener; import com.vaadin.server.AbstractApplicationServlet; +import com.vaadin.server.LegacyComponent; import com.vaadin.server.Page; +import com.vaadin.server.Page.BrowserWindowResizeEvent; +import com.vaadin.server.Page.BrowserWindowResizeListener; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.server.Resource; -import com.vaadin.server.LegacyComponent; import com.vaadin.server.WrappedRequest; -import com.vaadin.server.Page.BrowserWindowResizeEvent; -import com.vaadin.server.Page.BrowserWindowResizeListener; import com.vaadin.server.WrappedRequest.BrowserDetails; import com.vaadin.shared.EventId; import com.vaadin.shared.MouseEventDetails; @@ -77,15 +76,9 @@ import com.vaadin.tools.ReflectTools; * passing a {@link ComponentContainer} with the main layout of the view to * {@link #setContent(ComponentContainer)}. * </p> - * <p> - * If a {@link EagerInit} annotation is present on a class extending - * <code>UI</code>, the framework will use a faster initialization method which - * will not ensure that {@link BrowserDetails} are present in the - * {@link WrappedRequest} passed to the init method. - * </p> * * @see #init(WrappedRequest) - * @see Application#getUI(WrappedRequest) + * @see Application#createUI(WrappedRequest) * * @since 7.0 */ @@ -98,7 +91,6 @@ public abstract class UI extends AbstractComponentContainer implements * window in Vaadin 6 with {@link com.vaadin.Application.LegacyApplication} */ @Deprecated - @EagerInit public static class LegacyWindow extends UI { private String name; @@ -385,7 +377,7 @@ public abstract class UI extends AbstractComponentContainer implements @Override public void setCaption(String caption) { // Override to provide backwards compatibility - getState().setCaption(caption); + getState().caption = caption; getPage().setTitle(caption); } @@ -710,28 +702,6 @@ public abstract class UI extends AbstractComponentContainer implements } /** - * Sets the id of this UI within its application. The UI id is used to route - * requests to the right UI. - * <p> - * This method is mainly intended for internal use by the framework. - * </p> - * - * @param uiId - * the id of this UI - * - * @throws IllegalStateException - * if the UI id has already been set - * - * @see #getUIId() - */ - public void setUIId(int uiId) { - if (this.uiId != -1) { - throw new IllegalStateException("UI id has already been defined"); - } - this.uiId = uiId; - } - - /** * Gets the id of the UI, used to identify this UI within its application * when processing requests. The UI id should be present in every request to * the server that originates from this UI. @@ -748,8 +718,8 @@ public abstract class UI extends AbstractComponentContainer implements * Adds a window as a subwindow inside this UI. To open a new browser window * or tab, you should instead use {@link open(Resource)} with an url * pointing to this application and ensure - * {@link Application#getUI(WrappedRequest)} returns an appropriate UI for - * the request. + * {@link Application#createUI(WrappedRequest)} returns an appropriate UI + * for the request. * * @param window * @throws IllegalArgumentException @@ -831,6 +801,8 @@ public abstract class UI extends AbstractComponentContainer implements private boolean resizeLazy = false; + private String theme; + /** * This method is used by Component.Focusable objects to request focus to * themselves. Focus renders must be handled at window level (instead of @@ -879,7 +851,7 @@ public abstract class UI extends AbstractComponentContainer implements * @see #createDefaultLayout() */ public ComponentContainer getContent() { - return (ComponentContainer) getState().getContent(); + return (ComponentContainer) getState().content; } /** @@ -911,10 +883,10 @@ public abstract class UI extends AbstractComponentContainer implements content = createDefaultLayout(); } - if (getState().getContent() != null) { - super.removeComponent((Component) getState().getContent()); + if (getState().content != null) { + super.removeComponent((Component) getState().content); } - getState().setContent(content); + getState().content = content; if (content != null) { super.addComponent(content); } @@ -959,8 +931,16 @@ public abstract class UI extends AbstractComponentContainer implements * * @param request * the initialization request + * @param uiId + * the id of the new ui */ - public void doInit(WrappedRequest request) { + public void doInit(WrappedRequest request, int uiId) { + if (this.uiId != -1) { + throw new IllegalStateException("UI id has already been defined"); + } + this.uiId = uiId; + theme = getApplication().getThemeForUI(request, getClass()); + getPage().init(request); // Call the init overridden by the application developer @@ -974,11 +954,8 @@ public abstract class UI extends AbstractComponentContainer implements * state of the UI is not properly set up when the constructor is invoked. * <p> * The {@link WrappedRequest} can be used to get information about the - * request that caused this UI to be created. By default, the - * {@link BrowserDetails} will be available in the request. If the browser - * details are not required, loading the application in the browser can take - * some shortcuts giving a faster initial rendering. This can be indicated - * by adding the {@link EagerInit} annotation to the UI class. + * request that caused this UI to be created. {@link BrowserDetails} will be + * available in the request. * </p> * * @param request @@ -1352,4 +1329,13 @@ public abstract class UI extends AbstractComponentContainer implements public void setLastUidlRequestTime(long lastUidlRequest) { this.lastUidlRequest = lastUidlRequest; } + + /** + * Gets the theme that was used when the UI was initialized. + * + * @return the theme name + */ + public String getTheme() { + return theme; + } } diff --git a/server/src/com/vaadin/ui/Window.java b/server/src/com/vaadin/ui/Window.java index aaf0fbc492..5c94a4c929 100644 --- a/server/src/com/vaadin/ui/Window.java +++ b/server/src/com/vaadin/ui/Window.java @@ -31,9 +31,9 @@ import com.vaadin.event.ShortcutAction; import com.vaadin.event.ShortcutAction.KeyCode; import com.vaadin.event.ShortcutAction.ModifierKey; import com.vaadin.event.ShortcutListener; +import com.vaadin.server.LegacyComponent; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; -import com.vaadin.server.LegacyComponent; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.window.WindowServerRpc; import com.vaadin.shared.ui.window.WindowState; @@ -242,7 +242,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * @since 4.0.0 */ public int getPositionX() { - return getState().getPositionX(); + return getState().positionX; } /** @@ -255,8 +255,8 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * @since 4.0.0 */ public void setPositionX(int positionX) { - getState().setPositionX(positionX); - getState().setCentered(false); + getState().positionX = positionX; + getState().centered = false; } /** @@ -269,7 +269,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * @since 4.0.0 */ public int getPositionY() { - return getState().getPositionY(); + return getState().positionY; } /** @@ -283,8 +283,8 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * @since 4.0.0 */ public void setPositionY(int positionY) { - getState().setPositionY(positionY); - getState().setCentered(false); + getState().positionY = positionY; + getState().centered = false; } private static final Method WINDOW_CLOSE_METHOD; @@ -540,7 +540,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * true if modality is to be turned on */ public void setModal(boolean modal) { - getState().setModal(modal); + getState().modal = modal; center(); } @@ -548,7 +548,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * @return true if this window is modal. */ public boolean isModal() { - return getState().isModal(); + return getState().modal; } /** @@ -558,7 +558,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * true if resizability is to be turned on */ public void setResizable(boolean resizable) { - getState().setResizable(resizable); + getState().resizable = resizable; } /** @@ -566,7 +566,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * @return true if window is resizable by the end-user, otherwise false. */ public boolean isResizable() { - return getState().isResizable(); + return getState().resizable; } /** @@ -575,7 +575,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * sizes are recalculated immediately. */ public boolean isResizeLazy() { - return getState().isResizeLazy(); + return getState().resizeLazy; } /** @@ -591,7 +591,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * calculate immediately. */ public void setResizeLazy(boolean resizeLazy) { - getState().setResizeLazy(resizeLazy); + getState().resizeLazy = resizeLazy; } /** @@ -604,7 +604,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * Please refer to http://dev.vaadin.com/ticket/8971 for details. */ public void center() { - getState().setCentered(true); + getState().centered = true; } /** @@ -655,7 +655,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * true if the sub window can be dragged by the user */ public boolean isDraggable() { - return getState().isDraggable(); + return getState().draggable; } /** @@ -668,7 +668,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * true if the sub window can be dragged by the user */ public void setDraggable(boolean draggable) { - getState().setDraggable(draggable); + getState().draggable = draggable; } /* @@ -793,6 +793,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * @deprecated Since 7.0, replaced by * {@link #addFocusListener(FocusListener)} **/ + @Override @Deprecated public void addListener(FocusListener listener) { addFocusListener(listener); @@ -807,6 +808,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * @deprecated Since 7.0, replaced by * {@link #removeFocusListener(FocusListener)} **/ + @Override @Deprecated public void removeListener(FocusListener listener) { removeFocusListener(listener); @@ -829,6 +831,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, /** * @deprecated Since 7.0, replaced by {@link #addBlurListener(BlurListener)} **/ + @Override @Deprecated public void addListener(BlurListener listener) { addBlurListener(listener); @@ -843,6 +846,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * @deprecated Since 7.0, replaced by * {@link #removeBlurListener(BlurListener)} **/ + @Override @Deprecated public void removeListener(BlurListener listener) { removeBlurListener(listener); diff --git a/server/tests/src/com/vaadin/data/util/TestIndexedContainer.java b/server/tests/src/com/vaadin/data/util/TestIndexedContainer.java index 156ff83883..da2e2feac7 100644 --- a/server/tests/src/com/vaadin/data/util/TestIndexedContainer.java +++ b/server/tests/src/com/vaadin/data/util/TestIndexedContainer.java @@ -1,7 +1,9 @@ package com.vaadin.data.util; +import java.util.List; + import com.vaadin.data.Item; -import com.vaadin.data.util.IndexedContainer; +import com.vaadin.data.RangeOutOfContainerBoundsException; public class TestIndexedContainer extends AbstractInMemoryContainerTest { @@ -268,4 +270,122 @@ public class TestIndexedContainer extends AbstractInMemoryContainerTest { counter.assertNone(); } + // Ticket 8028 + public void testGetItemIdsRangeIndexOutOfBounds() { + IndexedContainer ic = new IndexedContainer(); + try { + ic.getItemIds(-1, 10); + fail("Container returned items starting from index -1, something very wrong here!"); + } catch (IndexOutOfBoundsException e) { + // This is expected... + } catch (Exception e) { + // Should not happen! + fail("Container threw unspecified exception when fetching a range of items and the range started from -1"); + } + + } + + // Ticket 8028 + public void testGetItemIdsRangeIndexOutOfBounds2() { + IndexedContainer ic = new IndexedContainer(); + ic.addItem(new Object()); + try { + ic.getItemIds(2, 1); + fail("Container returned items starting from index -1, something very wrong here!"); + } catch (IndexOutOfBoundsException e) { + // This is expected... + } catch (Exception e) { + // Should not happen! + fail("Container threw unspecified exception when fetching a out of bounds range of items"); + } + + } + + // Ticket 8028 + public void testGetItemIdsRangeZeroRange() { + IndexedContainer ic = new IndexedContainer(); + ic.addItem(new Object()); + try { + List<Object> itemIds = ic.getItemIds(1, 0); + + assertTrue( + "Container returned actual values when asking for 0 items...", + itemIds.isEmpty()); + } catch (Exception e) { + // Should not happen! + fail("Container threw unspecified exception when fetching 0 items..."); + } + + } + + // Ticket 8028 + public void testGetItemIdsRangeNegativeRange() { + IndexedContainer ic = new IndexedContainer(); + ic.addItem(new Object()); + try { + List<Object> itemIds = ic.getItemIds(1, -1); + + assertTrue( + "Container returned actual values when asking for -1 items...", + itemIds.isEmpty()); + } catch (IllegalArgumentException e) { + // this is expected + + } catch (Exception e) { + // Should not happen! + fail("Container threw unspecified exception when fetching -1 items..."); + } + + } + + // Ticket 8028 + public void testGetItemIdsRangeIndexOutOfBoundsDueToSizeChange() { + IndexedContainer ic = new IndexedContainer(); + ic.addItem(new Object()); + try { + ic.getItemIds(0, 10); + fail("Container returned items when the range was >> container size"); + } catch (RangeOutOfContainerBoundsException e) { + // This is expected... + assertTrue(e.isAdditionalParametersSet()); + assertEquals(0, e.getStartIndex()); + assertEquals(10, e.getNumberOfIds()); + assertEquals(1, e.getContainerCurrentSize()); + + } catch (IndexOutOfBoundsException e) { + fail("Container threw wrong exception when the range exceeded container size... "); + } catch (Exception e) { + // Should not happen! + fail("Container threw unspecified exception when fetching a range of items and the range started from -1"); + } + } + + // Ticket 8028 + public void testGetItemIdsRangeBaseCase() { + IndexedContainer ic = new IndexedContainer(); + String object1 = new String("Obj1"); + String object2 = new String("Obj2"); + String object3 = new String("Obj3"); + String object4 = new String("Obj4"); + String object5 = new String("Obj5"); + + ic.addItem(object1); + ic.addItem(object2); + ic.addItem(object3); + ic.addItem(object4); + ic.addItem(object5); + + try { + List<Object> itemIds = ic.getItemIds(1, 2); + + assertTrue(itemIds.contains(object2)); + assertTrue(itemIds.contains(object3)); + assertEquals(2, itemIds.size()); + + } catch (Exception e) { + // Should not happen! + fail("Container threw exception when fetching a range of items "); + } + } + } diff --git a/server/tests/src/com/vaadin/server/JSONSerializerTest.java b/server/tests/src/com/vaadin/server/JSONSerializerTest.java index 05139e6f1a..fc02c13781 100644 --- a/server/tests/src/com/vaadin/server/JSONSerializerTest.java +++ b/server/tests/src/com/vaadin/server/JSONSerializerTest.java @@ -42,10 +42,10 @@ public class JSONSerializerTest extends TestCase { stringToStateMap = new HashMap<String, AbstractSplitPanelState>(); AbstractSplitPanelState s = new AbstractSplitPanelState(); AbstractSplitPanelState s2 = new AbstractSplitPanelState(); - s.setCaption("State 1"); - s.setId("foo"); - s2.setCaption("State 2"); - s2.setId("bar"); + s.caption = "State 1"; + s.id = "foo"; + s2.caption = "State 2"; + s2.id = "bar"; stringToStateMap.put("string - state 1", s); stringToStateMap.put("String - state 2", s2); @@ -61,8 +61,8 @@ public class JSONSerializerTest extends TestCase { stateToStringMap = new HashMap<AbstractSplitPanelState, String>(); AbstractSplitPanelState s = new AbstractSplitPanelState(); AbstractSplitPanelState s2 = new AbstractSplitPanelState(); - s.setCaption("State 1"); - s2.setCaption("State 2"); + s.caption = "State 1"; + s2.caption = "State 2"; stateToStringMap.put(s, "string - state 1"); stateToStringMap.put(s2, "String - state 2"); diff --git a/server/tests/src/com/vaadin/tests/server/TestAssertionsEnabled.java b/server/tests/src/com/vaadin/tests/server/TestAssertionsEnabled.java new file mode 100644 index 0000000000..ee481c61f8 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/TestAssertionsEnabled.java @@ -0,0 +1,33 @@ +/* + * 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.server; + +import junit.framework.TestCase; + +public class TestAssertionsEnabled extends TestCase { + public void testAssertionsEnabled() { + boolean assertFailed = false; + try { + assert false; + } catch (AssertionError e) { + assertFailed = true; + } finally { + assertTrue("Unit tests should be run with assertions enabled", + assertFailed); + } + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java b/server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java index 906d6ccebd..89da55a31f 100644 --- a/server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java +++ b/server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java @@ -10,7 +10,6 @@ import org.easymock.EasyMock; import com.vaadin.Application; import com.vaadin.Application.ApplicationStartEvent; -import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.server.DefaultUIProvider; import com.vaadin.server.DeploymentConfiguration; import com.vaadin.server.WrappedRequest; @@ -56,8 +55,11 @@ public class CustomUIClassLoader extends TestCase { application.start(new ApplicationStartEvent(null, createConfigurationMock(), null)); - UI uI = application.getUIForRequest(createRequestMock(null)); - assertTrue(uI instanceof MyUI); + DefaultUIProvider uiProvider = new DefaultUIProvider(); + Class<? extends UI> uiClass = uiProvider.getUIClass(application, + createRequestMock(null)); + + assertEquals(MyUI.class, uiClass); } private static DeploymentConfiguration createConfigurationMock() { @@ -101,9 +103,11 @@ public class CustomUIClassLoader extends TestCase { application.start(new ApplicationStartEvent(null, createConfigurationMock(), null)); - UI uI = application - .getUIForRequest(createRequestMock(loggingClassLoader)); - assertTrue(uI instanceof MyUI); + DefaultUIProvider uiProvider = new DefaultUIProvider(); + Class<? extends UI> uiClass = uiProvider.getUIClass(application, + createRequestMock(loggingClassLoader)); + + assertEquals(MyUI.class, uiClass); assertEquals(1, loggingClassLoader.requestedClasses.size()); assertEquals(MyUI.class.getName(), loggingClassLoader.requestedClasses.get(0)); @@ -112,10 +116,6 @@ public class CustomUIClassLoader extends TestCase { private Application createStubApplication() { return new Application() { - { - addUIProvider(new DefaultUIProvider()); - } - @Override public String getProperty(String name) { if (name.equals(UI_PARAMETER)) { @@ -124,14 +124,6 @@ public class CustomUIClassLoader extends TestCase { return super.getProperty(name); } } - - @Override - public UI getUIForRequest(WrappedRequest request) - throws UIRequiresMoreInformationException { - // Always create a new root for testing (can't directly use - // getRoot as it's protected) - return getUI(request); - } }; } } diff --git a/server/tests/src/com/vaadin/tests/server/navigator/ClassBasedViewProviderTest.java b/server/tests/src/com/vaadin/tests/server/navigator/ClassBasedViewProviderTest.java index 5db0df4280..2b9d0e533d 100644 --- a/server/tests/src/com/vaadin/tests/server/navigator/ClassBasedViewProviderTest.java +++ b/server/tests/src/com/vaadin/tests/server/navigator/ClassBasedViewProviderTest.java @@ -20,6 +20,7 @@ import junit.framework.TestCase; import com.vaadin.navigator.Navigator.ClassBasedViewProvider; import com.vaadin.navigator.View; +import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; import com.vaadin.ui.Label; public class ClassBasedViewProviderTest extends TestCase { @@ -28,8 +29,8 @@ public class ClassBasedViewProviderTest extends TestCase { public String parameters = null; @Override - public void navigateTo(String parameters) { - this.parameters = parameters; + public void enter(ViewChangeEvent event) { + parameters = event.getParameters(); } } diff --git a/server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java b/server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java index 595ddb95db..fa48e4bff6 100644 --- a/server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java +++ b/server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java @@ -21,9 +21,10 @@ import java.util.LinkedList; import junit.framework.TestCase; import org.easymock.EasyMock; +import org.easymock.IArgumentMatcher; import org.easymock.IMocksControl; -import com.vaadin.navigator.FragmentManager; +import com.vaadin.navigator.NavigationStateManager; import com.vaadin.navigator.Navigator; import com.vaadin.navigator.View; import com.vaadin.navigator.ViewChangeListener; @@ -45,14 +46,14 @@ public class NavigatorTest extends TestCase { } } - public static class NullFragmentManager implements FragmentManager { + public static class NullFragmentManager implements NavigationStateManager { @Override - public String getFragment() { + public String getState() { return null; } @Override - public void setFragment(String fragment) { + public void setState(String fragment) { // do nothing } } @@ -119,8 +120,7 @@ public class NavigatorTest extends TestCase { if (!stringEquals(reference.getViewName(), event.getViewName())) { return false; } - if (!stringEquals(reference.getFragmentParameters(), - event.getFragmentParameters())) { + if (!stringEquals(reference.getParameters(), event.getParameters())) { return false; } return true; @@ -169,9 +169,27 @@ public class NavigatorTest extends TestCase { } } + public static ViewChangeEvent eventParametersEqual(final String expected) { + EasyMock.reportMatcher(new IArgumentMatcher() { + @Override + public void appendTo(StringBuffer buffer) { + buffer.append("paramsIs(\"" + expected + "\")"); + } + + @Override + public boolean matches(Object actual) { + return actual instanceof ViewChangeEvent + && expected.equals(((ViewChangeEvent) actual) + .getParameters()); + } + }); + return null; + } + public void testBasicNavigation() { IMocksControl control = EasyMock.createControl(); - FragmentManager manager = control.createMock(FragmentManager.class); + NavigationStateManager manager = control + .createMock(NavigationStateManager.class); ViewDisplay display = control.createMock(ViewDisplay.class); ViewProvider provider = control.createMock(ViewProvider.class); View view1 = control.createMock(View.class); @@ -180,25 +198,25 @@ public class NavigatorTest extends TestCase { // prepare mocks: what to expect EasyMock.expect(provider.getViewName("test1")).andReturn("test1"); EasyMock.expect(provider.getView("test1")).andReturn(view1); - EasyMock.expect(manager.getFragment()).andReturn(""); - view1.navigateTo(""); + EasyMock.expect(manager.getState()).andReturn(""); + view1.enter(eventParametersEqual("")); display.showView(view1); - manager.setFragment("test1"); + manager.setState("test1"); EasyMock.expect(provider.getViewName("test2/")).andReturn("test2"); EasyMock.expect(provider.getView("test2")).andReturn(view2); - EasyMock.expect(manager.getFragment()).andReturn("view1"); - view2.navigateTo(""); + EasyMock.expect(manager.getState()).andReturn("view1"); + view2.enter(eventParametersEqual("")); display.showView(view2); - manager.setFragment("test2"); + manager.setState("test2"); EasyMock.expect(provider.getViewName("test1/params")) .andReturn("test1"); EasyMock.expect(provider.getView("test1")).andReturn(view1); - EasyMock.expect(manager.getFragment()).andReturn("view2"); - view1.navigateTo("params"); + EasyMock.expect(manager.getState()).andReturn("view2"); + view1.enter(eventParametersEqual("params")); display.showView(view1); - manager.setFragment("test1/params"); + manager.setState("test1/params"); control.replay(); @@ -213,7 +231,8 @@ public class NavigatorTest extends TestCase { public void testMainView() { IMocksControl control = EasyMock.createControl(); - FragmentManager manager = control.createMock(FragmentManager.class); + NavigationStateManager manager = control + .createMock(NavigationStateManager.class); ViewDisplay display = control.createMock(ViewDisplay.class); ViewProvider provider = control.createMock(ViewProvider.class); View view1 = control.createMock(View.class); @@ -222,25 +241,25 @@ public class NavigatorTest extends TestCase { // prepare mocks: what to expect EasyMock.expect(provider.getViewName("test2")).andReturn("test2"); EasyMock.expect(provider.getView("test2")).andReturn(view2); - EasyMock.expect(manager.getFragment()).andReturn("view1"); - view2.navigateTo(""); + EasyMock.expect(manager.getState()).andReturn("view1"); + view2.enter(eventParametersEqual("")); display.showView(view2); - manager.setFragment("test2"); + manager.setState("test2"); EasyMock.expect(provider.getViewName("")).andReturn("test1"); EasyMock.expect(provider.getView("test1")).andReturn(view1); - EasyMock.expect(manager.getFragment()).andReturn(""); - view1.navigateTo(""); + EasyMock.expect(manager.getState()).andReturn(""); + view1.enter(eventParametersEqual("")); display.showView(view1); - manager.setFragment("test1"); + manager.setState("test1"); EasyMock.expect(provider.getViewName("test1/params")) .andReturn("test1"); EasyMock.expect(provider.getView("test1")).andReturn(view1); - EasyMock.expect(manager.getFragment()).andReturn("view2"); - view1.navigateTo("params"); + EasyMock.expect(manager.getState()).andReturn("view2"); + view1.enter(eventParametersEqual("params")); display.showView(view1); - manager.setFragment("test1/params"); + manager.setState("test1/params"); control.replay(); @@ -255,7 +274,8 @@ public class NavigatorTest extends TestCase { public void testListeners() { IMocksControl control = EasyMock.createControl(); - FragmentManager manager = control.createMock(FragmentManager.class); + NavigationStateManager manager = control + .createMock(NavigationStateManager.class); ViewDisplay display = control.createMock(ViewDisplay.class); ViewProvider provider = control.createMock(ViewProvider.class); View view1 = control.createMock(View.class); @@ -271,10 +291,10 @@ public class NavigatorTest extends TestCase { ViewChangeEvent event1 = new ViewChangeEvent(navigator, null, view1, "test1", ""); listener.addExpectedIsViewChangeAllowed(event1, true); - EasyMock.expect(manager.getFragment()).andReturn(""); - view1.navigateTo(""); + EasyMock.expect(manager.getState()).andReturn(""); + view1.enter(eventParametersEqual("")); display.showView(view1); - manager.setFragment("test1"); + manager.setState("test1"); listener.addExpectedNavigatorViewChange(event1); EasyMock.expect(provider.getViewName("test2")).andReturn("test2"); @@ -282,10 +302,10 @@ public class NavigatorTest extends TestCase { ViewChangeEvent event2 = new ViewChangeEvent(navigator, view1, view2, "test2", ""); listener.addExpectedIsViewChangeAllowed(event2, true); - EasyMock.expect(manager.getFragment()).andReturn("view1"); - view2.navigateTo(""); + EasyMock.expect(manager.getState()).andReturn("view1"); + view2.enter(eventParametersEqual("")); display.showView(view2); - manager.setFragment("test2"); + manager.setState("test2"); listener.addExpectedNavigatorViewChange(event2); control.replay(); @@ -304,7 +324,8 @@ public class NavigatorTest extends TestCase { public void testBlockNavigation() { IMocksControl control = EasyMock.createControl(); - FragmentManager manager = control.createMock(FragmentManager.class); + NavigationStateManager manager = control + .createMock(NavigationStateManager.class); ViewDisplay display = control.createMock(ViewDisplay.class); ViewProvider provider = control.createMock(ViewProvider.class); View view1 = control.createMock(View.class); @@ -318,7 +339,7 @@ public class NavigatorTest extends TestCase { // first listener blocks first view change EasyMock.expect(provider.getViewName("test1")).andReturn("test1"); EasyMock.expect(provider.getView("test1")).andReturn(view1); - EasyMock.expect(manager.getFragment()).andReturn(""); + EasyMock.expect(manager.getState()).andReturn(""); ViewChangeEvent event1 = new ViewChangeEvent(navigator, null, view1, "test1", ""); listener1.addExpectedIsViewChangeAllowed(event1, false); @@ -326,7 +347,7 @@ public class NavigatorTest extends TestCase { // second listener blocks second view change EasyMock.expect(provider.getViewName("test1/test")).andReturn("test1"); EasyMock.expect(provider.getView("test1")).andReturn(view1); - EasyMock.expect(manager.getFragment()).andReturn(""); + EasyMock.expect(manager.getState()).andReturn(""); ViewChangeEvent event2 = new ViewChangeEvent(navigator, null, view1, "test1", "test"); listener1.addExpectedIsViewChangeAllowed(event2, true); @@ -335,28 +356,28 @@ public class NavigatorTest extends TestCase { // both listeners allow view change EasyMock.expect(provider.getViewName("test1/bar")).andReturn("test1"); EasyMock.expect(provider.getView("test1")).andReturn(view1); - EasyMock.expect(manager.getFragment()).andReturn(""); + EasyMock.expect(manager.getState()).andReturn(""); ViewChangeEvent event3 = new ViewChangeEvent(navigator, null, view1, "test1", "bar"); listener1.addExpectedIsViewChangeAllowed(event3, true); listener2.addExpectedIsViewChangeAllowed(event3, true); - view1.navigateTo("bar"); + view1.enter(EasyMock.isA(ViewChangeEvent.class)); display.showView(view1); - manager.setFragment("test1/bar"); + manager.setState("test1/bar"); listener1.addExpectedNavigatorViewChange(event3); listener2.addExpectedNavigatorViewChange(event3); // both listeners allow view change from non-null view EasyMock.expect(provider.getViewName("test2")).andReturn("test2"); EasyMock.expect(provider.getView("test2")).andReturn(view2); - EasyMock.expect(manager.getFragment()).andReturn("view1"); + EasyMock.expect(manager.getState()).andReturn("view1"); ViewChangeEvent event4 = new ViewChangeEvent(navigator, view1, view2, "test2", ""); listener1.addExpectedIsViewChangeAllowed(event4, true); listener2.addExpectedIsViewChangeAllowed(event4, true); - view2.navigateTo(""); + view2.enter(EasyMock.isA(ViewChangeEvent.class)); display.showView(view2); - manager.setFragment("test2"); + manager.setState("test2"); listener1.addExpectedNavigatorViewChange(event4); listener2.addExpectedNavigatorViewChange(event4); diff --git a/server/tests/src/com/vaadin/tests/server/navigator/UriFragmentManagerTest.java b/server/tests/src/com/vaadin/tests/server/navigator/UriFragmentManagerTest.java index 18ed52cc2a..d58ff28b00 100644 --- a/server/tests/src/com/vaadin/tests/server/navigator/UriFragmentManagerTest.java +++ b/server/tests/src/com/vaadin/tests/server/navigator/UriFragmentManagerTest.java @@ -39,9 +39,9 @@ public class UriFragmentManagerTest extends TestCase { EasyMock.replay(page); // test manager using the mock - assertEquals("Incorrect fragment value", "", manager.getFragment()); - manager.setFragment("test"); - assertEquals("Incorrect fragment value", "test", manager.getFragment()); + assertEquals("Incorrect fragment value", "", manager.getState()); + manager.setState("test"); + assertEquals("Incorrect fragment value", "test", manager.getState()); } public void testListener() { diff --git a/shared/src/com/vaadin/shared/AbstractFieldState.java b/shared/src/com/vaadin/shared/AbstractFieldState.java index 02cbd16a6f..37f8599bbf 100644 --- a/shared/src/com/vaadin/shared/AbstractFieldState.java +++ b/shared/src/com/vaadin/shared/AbstractFieldState.java @@ -24,128 +24,9 @@ import com.vaadin.shared.ui.TabIndexState; * @since 7.0.0 * */ -public class AbstractFieldState extends ComponentState implements TabIndexState { - private boolean propertyReadOnly = false; - private boolean hideErrors = false; - private boolean required = false; - private boolean modified = false; - - /** - * The tab order number of this field. - */ - private int tabIndex = 0; - - /** - * Checks if the property data source for the Field is in read only mode. - * This affects the read only state of the field itself. - * - * @return true if there is a property data source and it is set to read - * only, false otherwise - */ - public boolean isPropertyReadOnly() { - return propertyReadOnly; - } - - /** - * Sets the read only state of the property data source. - * - * @param propertyReadOnly - * true if the property data source if read only, false otherwise - */ - public void setPropertyReadOnly(boolean propertyReadOnly) { - this.propertyReadOnly = propertyReadOnly; - } - - /** - * Returns true if the component will hide any errors even if the error - * message is set. - * - * @return true if error messages are disabled - */ - public boolean isHideErrors() { - return hideErrors; - } - - /** - * Sets whether the component should hide any errors even if the error - * message is set. - * - * This is used e.g. on forms to hide error messages for invalid fields - * before the first user actions. - * - * @param hideErrors - * true if error messages should be hidden - */ - public void setHideErrors(boolean hideErrors) { - this.hideErrors = hideErrors; - } - - /** - * Is the field required. Required fields must filled by the user. - * - * See {@link com.vaadin.ui.AbstractField#isRequired()} for more - * information. - * - * @return <code>true</code> if the field is required, otherwise - * <code>false</code>. - */ - public boolean isRequired() { - return required; - } - - /** - * Sets the field required. Required fields must filled by the user. - * - * See {@link com.vaadin.ui.AbstractField#setRequired(boolean)} for more - * information. - * - * @param required - * Is the field required. - */ - public void setRequired(boolean required) { - this.required = required; - } - - /** - * Has the contents of the field been modified, i.e. has the value been - * updated after it was read from the data source. - * - * @return true if the field has been modified, false otherwise - */ - public boolean isModified() { - return modified; - } - - /** - * Setter for the modified flag, toggled when the contents of the field is - * modified by the user. - * - * @param modified - * the new modified state - * - */ - public void setModified(boolean modified) { - this.modified = modified; - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.client.ComponentState#getTabIndex() - */ - @Override - public int getTabIndex() { - return tabIndex; - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.client.ui.TabIndexState#setTabIndex(int) - */ - @Override - public void setTabIndex(int tabIndex) { - this.tabIndex = tabIndex; - } - +public class AbstractFieldState extends TabIndexState { + public boolean propertyReadOnly = false; + public boolean hideErrors = false; + public boolean required = false; + public boolean modified = false; } diff --git a/shared/src/com/vaadin/shared/ComponentState.java b/shared/src/com/vaadin/shared/ComponentState.java index 06330a8604..86ae042f79 100644 --- a/shared/src/com/vaadin/shared/ComponentState.java +++ b/shared/src/com/vaadin/shared/ComponentState.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -16,7 +16,6 @@ package com.vaadin.shared; -import java.util.HashSet; import java.util.List; import java.util.Set; @@ -30,374 +29,25 @@ import com.vaadin.shared.communication.SharedState; * @since 7.0 */ public class ComponentState extends SharedState { - private String height = ""; - private String width = ""; - private boolean readOnly = false; - private boolean immediate = false; - private String description = ""; + public String height = ""; + public String width = ""; + public boolean readOnly = false; + public boolean immediate = false; + public String description = ""; // Note: for the caption, there is a difference between null and an empty // string! - private String caption = null; - private boolean visible = true; - private List<String> styles = null; - private String id = null; + public String caption = null; + public boolean visible = true; + public List<String> styles = null; + public String id = null; /** * A set of event identifiers with registered listeners. */ - private Set<String> registeredEventListeners = null; + public Set<String> registeredEventListeners = null; // HTML formatted error message for the component // TODO this could be an object with more information, but currently the UI // only uses the message - private String errorMessage = null; - - /** - * Returns the component height as set by the server. - * - * Can be relative (containing the percent sign) or absolute, or empty - * string for undefined height. - * - * @return component height as defined by the server, not null - */ - public String getHeight() { - if (height == null) { - return ""; - } - return height; - } - - /** - * Sets the height of the component in the server format. - * - * Can be relative (containing the percent sign) or absolute, or null or - * empty string for undefined height. - * - * @param height - * component height - */ - public void setHeight(String height) { - this.height = height; - } - - /** - * Returns true if the component height is undefined, false if defined - * (absolute or relative). - * - * @return true if component height is undefined - */ - public boolean isUndefinedHeight() { - return "".equals(getHeight()); - } - - /** - * Returns true if the component height is relative to the parent, i.e. - * percentage, false if it is fixed/auto. - * - * @return true if component height is relative (percentage) - */ - public boolean isRelativeHeight() { - return getHeight().endsWith("%"); - } - - /** - * Returns the component width as set by the server. - * - * Can be relative (containing the percent sign) or absolute, or empty - * string for undefined height. - * - * @return component width as defined by the server, not null - */ - public String getWidth() { - if (width == null) { - return ""; - } - return width; - } - - /** - * Sets the width of the component in the server format. - * - * Can be relative (containing the percent sign) or absolute, or null or - * empty string for undefined width. - * - * @param width - * component width - */ - public void setWidth(String width) { - this.width = width; - } - - /** - * Returns true if the component width is undefined, false if defined - * (absolute or relative). - * - * @return true if component width is undefined - */ - public boolean isUndefinedWidth() { - return "".equals(getWidth()); - } - - /** - * Returns true if the component width is relative to the parent, i.e. - * percentage, false if it is fixed/auto. - * - * @return true if component width is relative (percentage) - */ - public boolean isRelativeWidth() { - return getWidth().endsWith("%"); - } - - /** - * Returns true if the component is in read-only mode. - * - * @see com.vaadin.ui.Component#isReadOnly() - * - * @return true if the component is in read-only mode - */ - public boolean isReadOnly() { - return readOnly; - } - - /** - * Sets or resets the read-only mode for a component. - * - * @see com.vaadin.ui.Component#setReadOnly() - * - * @param readOnly - * new mode for the component - */ - public void setReadOnly(boolean readOnly) { - this.readOnly = readOnly; - } - - /** - * Returns true if the component is in immediate mode. - * - * @see com.vaadin.server.VariableOwner#isImmediate() - * - * @return true if the component is in immediate mode - */ - public boolean isImmediate() { - return immediate; - } - - /** - * Sets or resets the immediate mode for a component. - * - * @see com.vaadin.server.VariableOwner#setImmediate() - * - * @param immediate - * new mode for the component - */ - public void setImmediate(boolean immediate) { - this.immediate = immediate; - } - - /** - * Returns true if the component has user-defined styles. - * - * @return true if the component has user-defined styles - */ - public boolean hasStyles() { - return styles != null && !styles.isEmpty(); - } - - /** - * Gets the description of the component (typically shown as tooltip). - * - * @see com.vaadin.ui.AbstractComponent#getDescription() - * - * @return component description (not null, can be empty string) - */ - public String getDescription() { - return description; - } - - /** - * Sets the description of the component (typically shown as tooltip). - * - * @see com.vaadin.ui.AbstractComponent#setDescription(String) - * - * @param description - * new component description (can be null) - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * Returns true if the component has a description. - * - * @return true if the component has a description - */ - public boolean hasDescription() { - return getDescription() != null && !"".equals(getDescription()); - } - - /** - * Gets the caption of the component (typically shown by the containing - * layout). - * - * @see com.vaadin.ui.Component#getCaption() - * - * @return component caption - can be null (no caption) or empty string - * (reserve space for an empty caption) - */ - public String getCaption() { - return caption; - } - - /** - * Sets the caption of the component (typically shown by the containing - * layout). - * - * @see com.vaadin.ui.Component#setCaption(String) - * - * @param caption - * new component caption - can be null (no caption) or empty - * string (reserve space for an empty caption) - */ - public void setCaption(String caption) { - this.caption = caption; - } - - /** - * Returns the visibility state of the component. Note that this state is - * related to the component only, not its parent. This might differ from - * what {@link com.vaadin.ui.Component#isVisible()} returns as this takes - * the hierarchy into account. - * - * @return The visibility state. - */ - public boolean isVisible() { - return visible; - } - - /** - * Sets the visibility state of the component. - * - * @param visible - * The new visibility state. - */ - public void setVisible(boolean visible) { - this.visible = visible; - } - - /** - * Gets the style names for the component. - * - * @return A List of style names or null if no styles have been set. - */ - public List<String> getStyles() { - return styles; - } - - /** - * Sets the style names for the component. - * - * @param styles - * A list containing style names - */ - public void setStyles(List<String> styles) { - this.styles = styles; - } - - /** - * Gets the id for the component. The id is added as DOM id for the - * component. - * - * @return The id for the component or null if not set - */ - public String getId() { - return id; - } - - /** - * Sets the id for the component. The id is added as DOM id for the - * component. - * - * @param id - * The new id for the component or null for no id - * - */ - public void setId(String id) { - this.id = id; - } - - /** - * Gets the identifiers for the event listeners that have been registered - * for the component (using an event id) - * - * @return A set of event identifiers or null if no identifiers have been - * registered - */ - public Set<String> getRegisteredEventListeners() { - return registeredEventListeners; - } - - /** - * Sets the identifiers for the event listeners that have been registered - * for the component (using an event id) - * - * @param registeredEventListeners - * The new set of identifiers or null if no identifiers have been - * registered - */ - public void setRegisteredEventListeners(Set<String> registeredEventListeners) { - this.registeredEventListeners = registeredEventListeners; - } - - /** - * Adds an event listener id. - * - * @param eventListenerId - * The event identifier to add - */ - public void addRegisteredEventListener(String eventListenerId) { - if (registeredEventListeners == null) { - registeredEventListeners = new HashSet<String>(); - } - registeredEventListeners.add(eventListenerId); - - } - - /** - * Removes an event listener id. - * - * @param eventListenerId - * The event identifier to remove - */ - public void removeRegisteredEventListener(String eventIdentifier) { - if (registeredEventListeners == null) { - return; - } - registeredEventListeners.remove(eventIdentifier); - if (registeredEventListeners.size() == 0) { - registeredEventListeners = null; - } - } - - /** - * Returns the current error message for the component. - * - * @return HTML formatted error message to show for the component or null if - * none - */ - public String getErrorMessage() { - return errorMessage; - } - - /** - * Sets the current error message for the component. - * - * TODO this could use an object with more details about the error - * - * @param errorMessage - * HTML formatted error message to show for the component or null - * for none - */ - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - + public String errorMessage = null; } + diff --git a/shared/src/com/vaadin/shared/JavaScriptExtensionState.java b/shared/src/com/vaadin/shared/JavaScriptExtensionState.java index 3e97294f7d..fb864c6ee1 100644 --- a/shared/src/com/vaadin/shared/JavaScriptExtensionState.java +++ b/shared/src/com/vaadin/shared/JavaScriptExtensionState.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not diff --git a/shared/src/com/vaadin/shared/communication/SharedState.java b/shared/src/com/vaadin/shared/communication/SharedState.java index 09147ac97d..4473eba7a0 100644 --- a/shared/src/com/vaadin/shared/communication/SharedState.java +++ b/shared/src/com/vaadin/shared/communication/SharedState.java @@ -59,29 +59,5 @@ public class SharedState implements Serializable { */ public Map<String, URLReference> resources = new HashMap<String, URLReference>(); - private boolean enabled = true; - - /** - * Returns true if the component is enabled. - * - * @see com.vaadin.ui.Component#isEnabled() - * - * @return true if the component is enabled - */ - public boolean isEnabled() { - return enabled; - } - - /** - * Enables or disables the component. - * - * @see com.vaadin.ui.Component#setEnabled(boolean) - * - * @param enabled - * new mode for the component - */ - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - + public boolean enabled = true; } diff --git a/shared/src/com/vaadin/shared/extension/javascriptmanager/JavaScriptManagerState.java b/shared/src/com/vaadin/shared/extension/javascriptmanager/JavaScriptManagerState.java index 7d1938d735..71af5e9598 100644 --- a/shared/src/com/vaadin/shared/extension/javascriptmanager/JavaScriptManagerState.java +++ b/shared/src/com/vaadin/shared/extension/javascriptmanager/JavaScriptManagerState.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -22,13 +22,5 @@ import java.util.Set; import com.vaadin.shared.communication.SharedState; public class JavaScriptManagerState extends SharedState { - private Set<String> names = new HashSet<String>(); - - public Set<String> getNames() { - return names; - } - - public void setNames(Set<String> names) { - this.names = names; - } + public Set<String> names = new HashSet<String>(); } diff --git a/shared/src/com/vaadin/shared/ui/AbstractEmbeddedState.java b/shared/src/com/vaadin/shared/ui/AbstractEmbeddedState.java index 6422b643ad..608152cc54 100644 --- a/shared/src/com/vaadin/shared/ui/AbstractEmbeddedState.java +++ b/shared/src/com/vaadin/shared/ui/AbstractEmbeddedState.java @@ -6,14 +6,5 @@ public class AbstractEmbeddedState extends ComponentState { public static final String SOURCE_RESOURCE = "source"; - private String alternateText; - - public String getAlternateText() { - return alternateText; - } - - public void setAlternateText(String alternateText) { - this.alternateText = alternateText; - } - + public String alternateText; } diff --git a/shared/src/com/vaadin/shared/ui/AbstractMediaState.java b/shared/src/com/vaadin/shared/ui/AbstractMediaState.java index 80d41dd797..76d4e1b000 100644 --- a/shared/src/com/vaadin/shared/ui/AbstractMediaState.java +++ b/shared/src/com/vaadin/shared/ui/AbstractMediaState.java @@ -19,80 +19,20 @@ 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 { - private boolean showControls; + public boolean showControls; - private String altText; + public String altText; - private boolean htmlContentAllowed; + public boolean htmlContentAllowed; - private boolean autoplay; + public boolean autoplay; - private boolean muted; + public boolean muted; - private List<URLReference> sources = new ArrayList<URLReference>(); - private List<String> sourceTypes = new ArrayList<String>(); - - public boolean isShowControls() { - return showControls; - } - - @DelegateToWidget("setControls") - public void setShowControls(boolean showControls) { - this.showControls = showControls; - } - - public String getAltText() { - return altText; - } - - public void setAltText(String altText) { - this.altText = altText; - } - - public boolean isHtmlContentAllowed() { - return htmlContentAllowed; - } - - public void setHtmlContentAllowed(boolean htmlContentAllowed) { - this.htmlContentAllowed = htmlContentAllowed; - } - - public boolean isAutoplay() { - return autoplay; - } - - @DelegateToWidget - public void setAutoplay(boolean autoplay) { - this.autoplay = autoplay; - } - - public boolean isMuted() { - return muted; - } - - @DelegateToWidget - public void setMuted(boolean muted) { - this.muted = muted; - } - - public List<URLReference> getSources() { - return sources; - } - - public void setSources(List<URLReference> sources) { - this.sources = sources; - } - - public List<String> getSourceTypes() { - return sourceTypes; - } - - public void setSourceTypes(List<String> sourceTypes) { - this.sourceTypes = sourceTypes; - } + public List<URLReference> sources = new ArrayList<URLReference>(); + public List<String> sourceTypes = new ArrayList<String>(); } diff --git a/shared/src/com/vaadin/shared/ui/ComponentStateUtil.java b/shared/src/com/vaadin/shared/ui/ComponentStateUtil.java new file mode 100644 index 0000000000..dd2611f04b --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/ComponentStateUtil.java @@ -0,0 +1,60 @@ +package com.vaadin.shared.ui; + +import java.util.HashSet; + +import com.vaadin.shared.ComponentState; + +public final class ComponentStateUtil { + + private ComponentStateUtil() { + // Util class is not instantiable + } + + public static final boolean isUndefinedWidth(ComponentState state) { + return state.width == null || "".equals(state.width); + } + + public static final boolean isUndefinedHeight(ComponentState state) { + return state.height == null || "".equals(state.height); + } + + public static final boolean hasDescription(ComponentState state) { + return state.description != null && !"".equals(state.description); + } + + public static final boolean hasStyles(ComponentState state) { + return state.styles != null && !state.styles.isEmpty(); + } + + /** + * Removes an event listener id. + * + * @param eventListenerId + * The event identifier to remove + */ + public static final void removeRegisteredEventListener( + ComponentState state, + String eventIdentifier) { + if (state.registeredEventListeners == null) { + return; + } + state.registeredEventListeners.remove(eventIdentifier); + if (state.registeredEventListeners.size() == 0) { + state.registeredEventListeners = null; + } + } + + /** + * Adds an event listener id. + * + * @param eventListenerId + * The event identifier to add + */ + public static final void addRegisteredEventListener(ComponentState state, + String eventListenerId) { + if (state.registeredEventListeners == null) { + state.registeredEventListeners = new HashSet<String>(); + } + state.registeredEventListeners.add(eventListenerId); + } +} diff --git a/shared/src/com/vaadin/shared/ui/TabIndexState.java b/shared/src/com/vaadin/shared/ui/TabIndexState.java index 5f17b9b016..a9cb56e5ed 100644 --- a/shared/src/com/vaadin/shared/ui/TabIndexState.java +++ b/shared/src/com/vaadin/shared/ui/TabIndexState.java @@ -15,6 +15,8 @@ */ package com.vaadin.shared.ui; +import com.vaadin.shared.ComponentState; + /** * Interface implemented by state classes that support tab indexes. * @@ -22,19 +24,11 @@ package com.vaadin.shared.ui; * @since 7.0.0 * */ -public interface TabIndexState { - /** - * Gets the <i>tabulator index</i> of the field. - * - * @return the tab index for the Field - */ - public int getTabIndex(); +public class TabIndexState extends ComponentState { /** - * Sets the <i>tabulator index</i> of the field. - * - * @param tabIndex - * the tab index to set + * The <i>tabulator index</i> of the field. */ - public void setTabIndex(int tabIndex); + public int tabIndex = 0; + } diff --git a/shared/src/com/vaadin/shared/ui/absolutelayout/AbsoluteLayoutState.java b/shared/src/com/vaadin/shared/ui/absolutelayout/AbsoluteLayoutState.java index a0e0f4d3c7..283e827e6e 100644 --- a/shared/src/com/vaadin/shared/ui/absolutelayout/AbsoluteLayoutState.java +++ b/shared/src/com/vaadin/shared/ui/absolutelayout/AbsoluteLayoutState.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -18,24 +18,9 @@ package com.vaadin.shared.ui.absolutelayout; import java.util.HashMap; import java.util.Map; -import com.vaadin.shared.Connector; import com.vaadin.shared.ui.AbstractLayoutState; public class AbsoluteLayoutState extends AbstractLayoutState { // Maps each component to a position - private Map<String, String> connectorToCssPosition = new HashMap<String, String>(); - - public String getConnectorPosition(Connector connector) { - return connectorToCssPosition.get(connector.getConnectorId()); - } - - public Map<String, String> getConnectorToCssPosition() { - return connectorToCssPosition; - } - - public void setConnectorToCssPosition( - Map<String, String> componentToCssPosition) { - connectorToCssPosition = componentToCssPosition; - } - + public Map<String, String> connectorToCssPosition = new HashMap<String, String>(); }
\ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/button/ButtonState.java b/shared/src/com/vaadin/shared/ui/button/ButtonState.java index 2383b038bd..c144a8124f 100644 --- a/shared/src/com/vaadin/shared/ui/button/ButtonState.java +++ b/shared/src/com/vaadin/shared/ui/button/ButtonState.java @@ -27,108 +27,11 @@ import com.vaadin.shared.ui.TabIndexState; * * @since 7.0 */ -public class ButtonState extends ComponentState implements TabIndexState { - private boolean disableOnClick = false; - private int clickShortcutKeyCode = 0; - /** - * The tab order number of this field. - */ - private int tabIndex = 0; +public class ButtonState extends TabIndexState { + public boolean disableOnClick = false; + public int clickShortcutKeyCode = 0; /** * If caption should be rendered in HTML */ - private boolean htmlContentAllowed = false; - - /** - * Checks whether the button should be disabled on the client side on next - * click. - * - * @return true if the button should be disabled on click - */ - public boolean isDisableOnClick() { - return disableOnClick; - } - - /** - * Sets whether the button should be disabled on the client side on next - * click. - * - * @param disableOnClick - * true if the button should be disabled on click - */ - public void setDisableOnClick(boolean disableOnClick) { - this.disableOnClick = disableOnClick; - } - - /** - * Returns the key code for activating the button via a keyboard shortcut. - * - * See {@link com.vaadin.ui.Button#setClickShortcut(int, int...)} for more - * information. - * - * @return key code or 0 for none - */ - public int getClickShortcutKeyCode() { - return clickShortcutKeyCode; - } - - /** - * Sets the key code for activating the button via a keyboard shortcut. - * - * See {@link com.vaadin.ui.Button#setClickShortcut(int, int...)} for more - * information. - * - * @param clickShortcutKeyCode - * key code or 0 for none - */ - public void setClickShortcutKeyCode(int clickShortcutKeyCode) { - this.clickShortcutKeyCode = clickShortcutKeyCode; - } - - /** - * Set whether the caption text is rendered as HTML or not. You might need - * to retheme button to allow higher content than the original text style. - * - * If set to true, the captions are passed to the browser as html and the - * developer is responsible for ensuring no harmful html is used. If set to - * false, the content is passed to the browser as plain text. - * - * @param htmlContentAllowed - * <code>true</code> if caption is rendered as HTML, - * <code>false</code> otherwise - */ - public void setHtmlContentAllowed(boolean htmlContentAllowed) { - this.htmlContentAllowed = htmlContentAllowed; - } - - /** - * Return HTML rendering setting. - * - * @return <code>true</code> if the caption text is to be rendered as HTML, - * <code>false</code> otherwise - */ - public boolean isHtmlContentAllowed() { - return htmlContentAllowed; - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.client.ui.TabIndexState#getTabIndex() - */ - @Override - public int getTabIndex() { - return tabIndex; - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.client.ui.TabIndexState#setTabIndex(int) - */ - @Override - public void setTabIndex(int tabIndex) { - this.tabIndex = tabIndex; - } - + public boolean htmlContentAllowed = false; } diff --git a/shared/src/com/vaadin/shared/ui/checkbox/CheckBoxState.java b/shared/src/com/vaadin/shared/ui/checkbox/CheckBoxState.java index 1f48b8fe9e..b89270bee2 100644 --- a/shared/src/com/vaadin/shared/ui/checkbox/CheckBoxState.java +++ b/shared/src/com/vaadin/shared/ui/checkbox/CheckBoxState.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -18,14 +18,6 @@ package com.vaadin.shared.ui.checkbox; import com.vaadin.shared.AbstractFieldState; public class CheckBoxState extends AbstractFieldState { - private boolean checked = false; - - public boolean isChecked() { - return checked; - } - - public void setChecked(boolean checked) { - this.checked = checked; - } + public boolean checked = false; }
\ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/csslayout/CssLayoutState.java b/shared/src/com/vaadin/shared/ui/csslayout/CssLayoutState.java index fc230a8e2f..2fbc42ca0f 100644 --- a/shared/src/com/vaadin/shared/ui/csslayout/CssLayoutState.java +++ b/shared/src/com/vaadin/shared/ui/csslayout/CssLayoutState.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -22,14 +22,5 @@ import com.vaadin.shared.Connector; import com.vaadin.shared.ui.AbstractLayoutState; public class CssLayoutState extends AbstractLayoutState { - private Map<Connector, String> childCss = new HashMap<Connector, String>(); - - public Map<Connector, String> getChildCss() { - return childCss; - } - - public void setChildCss(Map<Connector, String> childCss) { - this.childCss = childCss; - } - + public Map<Connector, String> childCss = new HashMap<Connector, String>(); }
\ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/customlayout/CustomLayoutState.java b/shared/src/com/vaadin/shared/ui/customlayout/CustomLayoutState.java index 0c1aa24161..e77ea5c068 100644 --- a/shared/src/com/vaadin/shared/ui/customlayout/CustomLayoutState.java +++ b/shared/src/com/vaadin/shared/ui/customlayout/CustomLayoutState.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -22,32 +22,7 @@ import com.vaadin.shared.Connector; import com.vaadin.shared.ui.AbstractLayoutState; public class CustomLayoutState extends AbstractLayoutState { - Map<Connector, String> childLocations = new HashMap<Connector, String>(); - private String templateContents; - private String templateName; - - public String getTemplateContents() { - return templateContents; - } - - public void setTemplateContents(String templateContents) { - this.templateContents = templateContents; - } - - public String getTemplateName() { - return templateName; - } - - public void setTemplateName(String templateName) { - this.templateName = templateName; - } - - public Map<Connector, String> getChildLocations() { - return childLocations; - } - - public void setChildLocations(Map<Connector, String> childLocations) { - this.childLocations = childLocations; - } - + public Map<Connector, String> childLocations = new HashMap<Connector, String>(); + public String templateContents; + public String templateName; }
\ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/flash/FlashState.java b/shared/src/com/vaadin/shared/ui/flash/FlashState.java index 2d33d1a711..50f0d63733 100644 --- a/shared/src/com/vaadin/shared/ui/flash/FlashState.java +++ b/shared/src/com/vaadin/shared/ui/flash/FlashState.java @@ -6,63 +6,15 @@ import com.vaadin.shared.ui.AbstractEmbeddedState; public class FlashState extends AbstractEmbeddedState { - protected String classId; + public String classId; - protected String codebase; + public String codebase; - protected String codetype; + public String codetype; - protected String archive; + public String archive; - protected String standby; + public String standby; - protected Map<String, String> 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<String, String> getEmbedParams() { - return embedParams; - } - - public void setEmbedParams(Map<String, String> embedParams) { - this.embedParams = embedParams; - } + public Map<String, String> embedParams; } diff --git a/shared/src/com/vaadin/shared/ui/form/FormState.java b/shared/src/com/vaadin/shared/ui/form/FormState.java index 7e8b36707a..f0e79ad38f 100644 --- a/shared/src/com/vaadin/shared/ui/form/FormState.java +++ b/shared/src/com/vaadin/shared/ui/form/FormState.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -19,23 +19,6 @@ import com.vaadin.shared.AbstractFieldState; import com.vaadin.shared.Connector; public class FormState extends AbstractFieldState { - private Connector layout; - private Connector footer; - - public Connector getLayout() { - return layout; - } - - public void setLayout(Connector layout) { - this.layout = layout; - } - - public Connector getFooter() { - return footer; - } - - public void setFooter(Connector footer) { - this.footer = footer; - } - + public Connector layout; + public Connector footer; }
\ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/gridlayout/GridLayoutState.java b/shared/src/com/vaadin/shared/ui/gridlayout/GridLayoutState.java index 381a6a7f85..ae54dc3765 100644 --- a/shared/src/com/vaadin/shared/ui/gridlayout/GridLayoutState.java +++ b/shared/src/com/vaadin/shared/ui/gridlayout/GridLayoutState.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -18,41 +18,8 @@ package com.vaadin.shared.ui.gridlayout; import com.vaadin.shared.ui.AbstractLayoutState; public class GridLayoutState extends AbstractLayoutState { - private boolean spacing = false; - private int rows = 0; - private int columns = 0; - private int marginsBitmask = 0; - - public boolean isSpacing() { - return spacing; - } - - public void setSpacing(boolean spacing) { - this.spacing = spacing; - } - - public int getMarginsBitmask() { - return marginsBitmask; - } - - public void setMarginsBitmask(int marginsBitmask) { - this.marginsBitmask = marginsBitmask; - } - - public int getRows() { - return rows; - } - - public void setRows(int rows) { - this.rows = rows; - } - - public int getColumns() { - return columns; - } - - public void setColumns(int cols) { - columns = cols; - } - + public boolean spacing = false; + public int rows = 0; + public int columns = 0; + public int marginsBitmask = 0; }
\ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/orderedlayout/AbstractOrderedLayoutState.java b/shared/src/com/vaadin/shared/ui/orderedlayout/AbstractOrderedLayoutState.java index 35456ab9ac..27ab6ac8e0 100644 --- a/shared/src/com/vaadin/shared/ui/orderedlayout/AbstractOrderedLayoutState.java +++ b/shared/src/com/vaadin/shared/ui/orderedlayout/AbstractOrderedLayoutState.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -23,56 +23,16 @@ import com.vaadin.shared.ui.AbstractLayoutState; import com.vaadin.shared.ui.AlignmentInfo; public class AbstractOrderedLayoutState extends AbstractLayoutState { - private boolean spacing = false; + public boolean spacing = false; - private HashMap<Connector, ChildComponentData> childData = new HashMap<Connector, ChildComponentData>(); + public HashMap<Connector, ChildComponentData> childData = new HashMap<Connector, ChildComponentData>(); - private int marginsBitmask = 0; + public int marginsBitmask = 0; public static class ChildComponentData implements Serializable { - private int alignmentBitmask = AlignmentInfo.TOP_LEFT.getBitMask(); - private float expandRatio = 0.0f; - public int getAlignmentBitmask() { - return alignmentBitmask; - } + public int alignmentBitmask = AlignmentInfo.TOP_LEFT.getBitMask(); - public void setAlignmentBitmask(int alignmentBitmask) { - this.alignmentBitmask = alignmentBitmask; - } - - public float getExpandRatio() { - return expandRatio; - } - - public void setExpandRatio(float expandRatio) { - this.expandRatio = expandRatio; - } - - } - - public HashMap<Connector, ChildComponentData> getChildData() { - return childData; - } - - public void setChildData(HashMap<Connector, ChildComponentData> childData) { - this.childData = childData; - } - - public boolean isSpacing() { - return spacing; - } - - public void setSpacing(boolean spacing) { - this.spacing = spacing; - } - - public int getMarginsBitmask() { - return marginsBitmask; - } - - public void setMarginsBitmask(int marginsBitmask) { - this.marginsBitmask = marginsBitmask; + public float expandRatio = 0.0f; } - }
\ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/panel/PanelState.java b/shared/src/com/vaadin/shared/ui/panel/PanelState.java index d432de97ad..878b921d55 100644 --- a/shared/src/com/vaadin/shared/ui/panel/PanelState.java +++ b/shared/src/com/vaadin/shared/ui/panel/PanelState.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -18,31 +18,6 @@ package com.vaadin.shared.ui.panel; import com.vaadin.shared.ComponentState; public class PanelState extends ComponentState { - private int tabIndex; - private int scrollLeft, scrollTop; - - public int getTabIndex() { - return tabIndex; - } - - public void setTabIndex(int tabIndex) { - this.tabIndex = tabIndex; - } - - public int getScrollLeft() { - return scrollLeft; - } - - public void setScrollLeft(int scrollLeft) { - this.scrollLeft = scrollLeft; - } - - public int getScrollTop() { - return scrollTop; - } - - public void setScrollTop(int scrollTop) { - this.scrollTop = scrollTop; - } - + public int tabIndex; + public int scrollLeft, scrollTop; }
\ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/slider/SliderState.java b/shared/src/com/vaadin/shared/ui/slider/SliderState.java index 98168b80af..7236672b31 100644 --- a/shared/src/com/vaadin/shared/ui/slider/SliderState.java +++ b/shared/src/com/vaadin/shared/ui/slider/SliderState.java @@ -4,57 +4,17 @@ import com.vaadin.shared.AbstractFieldState; public class SliderState extends AbstractFieldState { - protected double value; + public double value; - protected double maxValue; - protected double minValue; + public double maxValue; + public double minValue; /** * The number of fractional digits that are considered significant. Must be * non-negative. */ - protected int resolution; + public 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; - } + public SliderOrientation orientation; } diff --git a/shared/src/com/vaadin/shared/ui/splitpanel/AbstractSplitPanelState.java b/shared/src/com/vaadin/shared/ui/splitpanel/AbstractSplitPanelState.java index 71f789b70d..41c51f998a 100644 --- a/shared/src/com/vaadin/shared/ui/splitpanel/AbstractSplitPanelState.java +++ b/shared/src/com/vaadin/shared/ui/splitpanel/AbstractSplitPanelState.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -23,117 +23,22 @@ import com.vaadin.shared.annotations.DelegateToWidget; public class AbstractSplitPanelState extends ComponentState { - private Connector firstChild = null; - private Connector secondChild = null; - private SplitterState splitterState = new SplitterState(); - - public boolean hasFirstChild() { - return firstChild != null; - } - - public boolean hasSecondChild() { - return secondChild != null; - } - - public Connector getFirstChild() { - return firstChild; - } - - public void setFirstChild(Connector firstChild) { - this.firstChild = firstChild; - } - - public Connector getSecondChild() { - return secondChild; - } - - public void setSecondChild(Connector secondChild) { - this.secondChild = secondChild; - } - - public SplitterState getSplitterState() { - return splitterState; - } - - public void setSplitterState(SplitterState splitterState) { - this.splitterState = splitterState; - } + public Connector firstChild = null; + public Connector secondChild = null; + public SplitterState splitterState = new SplitterState(); public static class SplitterState implements Serializable { - private float position; - private String positionUnit; - private float minPosition; - private String minPositionUnit; - private float maxPosition; - private String maxPositionUnit; - private boolean positionReversed = false; - private boolean locked = false; - - public float getPosition() { - return position; - } - - public void setPosition(float position) { - this.position = position; - } - - public String getPositionUnit() { - return positionUnit; - } - - public void setPositionUnit(String positionUnit) { - this.positionUnit = positionUnit; - } - - public float getMinPosition() { - return minPosition; - } - - public void setMinPosition(float minPosition) { - this.minPosition = minPosition; - } - - public String getMinPositionUnit() { - return minPositionUnit; - } - - public void setMinPositionUnit(String minPositionUnit) { - this.minPositionUnit = minPositionUnit; - } - - public float getMaxPosition() { - return maxPosition; - } - - public void setMaxPosition(float maxPosition) { - this.maxPosition = maxPosition; - } - - public String getMaxPositionUnit() { - return maxPositionUnit; - } - - public void setMaxPositionUnit(String maxPositionUnit) { - this.maxPositionUnit = maxPositionUnit; - } - - public boolean isPositionReversed() { - return positionReversed; - } - + public float position; + public String positionUnit; + public float minPosition; + public String minPositionUnit; + public float maxPosition; + public String maxPositionUnit; + @DelegateToWidget - public void setPositionReversed(boolean positionReversed) { - this.positionReversed = positionReversed; - } - - public boolean isLocked() { - return locked; - } + public boolean positionReversed = false; @DelegateToWidget - public void setLocked(boolean locked) { - this.locked = locked; - } - + public boolean locked = false; } }
\ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/textarea/TextAreaState.java b/shared/src/com/vaadin/shared/ui/textarea/TextAreaState.java index 50dc1393a3..a562c607b0 100644 --- a/shared/src/com/vaadin/shared/ui/textarea/TextAreaState.java +++ b/shared/src/com/vaadin/shared/ui/textarea/TextAreaState.java @@ -23,29 +23,13 @@ public class TextAreaState extends AbstractTextFieldState { /** * Number of visible rows in the text area. The default is 5. */ - private int rows = 5; + @DelegateToWidget + public int rows = 5; /** * Tells if word-wrapping should be used in the text area. */ - private boolean wordwrap = true; - - public int getRows() { - return rows; - } - - @DelegateToWidget - public void setRows(int rows) { - this.rows = rows; - } - - public boolean isWordwrap() { - return wordwrap; - } - @DelegateToWidget - public void setWordwrap(boolean wordwrap) { - this.wordwrap = wordwrap; - } + public boolean wordwrap = true; } diff --git a/shared/src/com/vaadin/shared/ui/textfield/AbstractTextFieldState.java b/shared/src/com/vaadin/shared/ui/textfield/AbstractTextFieldState.java index cd3562606d..39265c516f 100644 --- a/shared/src/com/vaadin/shared/ui/textfield/AbstractTextFieldState.java +++ b/shared/src/com/vaadin/shared/ui/textfield/AbstractTextFieldState.java @@ -21,53 +21,20 @@ public class AbstractTextFieldState extends AbstractFieldState { /** * Maximum character count in text field. */ - private int maxLength = -1; + public int maxLength = -1; /** * Number of visible columns in the TextField. */ - private int columns = 0; + public int columns = 0; /** * The prompt to display in an empty field. Null when disabled. */ - private String inputPrompt = null; + public String inputPrompt = null; /** * The text in the field */ - private String text = null; - - public int getMaxLength() { - return maxLength; - } - - public void setMaxLength(int maxLength) { - this.maxLength = maxLength; - } - - public int getColumns() { - return columns; - } - - public void setColumns(int columns) { - this.columns = columns; - } - - public String getInputPrompt() { - return inputPrompt; - } - - public void setInputPrompt(String inputPrompt) { - this.inputPrompt = inputPrompt; - } - - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } - + public String text = null; } diff --git a/shared/src/com/vaadin/shared/ui/ui/UIState.java b/shared/src/com/vaadin/shared/ui/ui/UIState.java index 01426bd8f3..6bbfeb18e1 100644 --- a/shared/src/com/vaadin/shared/ui/ui/UIState.java +++ b/shared/src/com/vaadin/shared/ui/ui/UIState.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -19,14 +19,5 @@ 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; - } - + public Connector content; }
\ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/window/WindowState.java b/shared/src/com/vaadin/shared/ui/window/WindowState.java index 526c5dacb0..c86b6cb187 100644 --- a/shared/src/com/vaadin/shared/ui/window/WindowState.java +++ b/shared/src/com/vaadin/shared/ui/window/WindowState.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -18,68 +18,11 @@ package com.vaadin.shared.ui.window; import com.vaadin.shared.ui.panel.PanelState; public class WindowState extends PanelState { - private boolean modal = false; - private boolean resizable = true; - private boolean resizeLazy = false; - private boolean draggable = true; - private boolean centered = false;; - private int positionX = -1; - private int positionY = -1; - - public boolean isModal() { - return modal; - } - - public void setModal(boolean modal) { - this.modal = modal; - } - - public boolean isResizable() { - return resizable; - } - - public void setResizable(boolean resizable) { - this.resizable = resizable; - } - - public boolean isResizeLazy() { - return resizeLazy; - } - - public void setResizeLazy(boolean resizeLazy) { - this.resizeLazy = resizeLazy; - } - - public boolean isDraggable() { - return draggable; - } - - public void setDraggable(boolean draggable) { - this.draggable = draggable; - } - - public boolean isCentered() { - return centered; - } - - public void setCentered(boolean centered) { - this.centered = centered; - } - - public int getPositionX() { - return positionX; - } - - public void setPositionX(int positionX) { - this.positionX = positionX; - } - - public int getPositionY() { - return positionY; - } - - public void setPositionY(int positionY) { - this.positionY = positionY; - } - + public boolean modal = false; + public boolean resizable = true; + public boolean resizeLazy = false; + public boolean draggable = true; + public boolean centered = false;; + public int positionX = -1; + public int positionY = -1; }
\ No newline at end of file diff --git a/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java index e05979ede0..bceecaf35a 100644 --- a/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java +++ b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java @@ -30,7 +30,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.vaadin.Application; -import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.server.AbstractApplicationServlet; import com.vaadin.server.AbstractUIProvider; import com.vaadin.server.WrappedHttpServletRequest; @@ -116,8 +115,7 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet { @Override public Class<? extends UI> getUIClass( - Application application, WrappedRequest request) - throws UIRequiresMoreInformationException { + Application application, WrappedRequest request) { return (Class<? extends UI>) classToRun; } }); diff --git a/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java b/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java index 6162820dac..f45aac8173 100644 --- a/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java +++ b/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java @@ -54,6 +54,8 @@ public class DevelopmentServerLauncher { public static void main(String[] args) { System.setProperty("java.awt.headless", "true"); + assertAssertionsEnabled(); + // Pass-through of arguments for Jetty final Map<String, String> serverArgs = parseArguments(args); @@ -88,6 +90,18 @@ public class DevelopmentServerLauncher { } } + private static void assertAssertionsEnabled() { + try { + assert false; + + throw new RuntimeException("You should run " + + DevelopmentServerLauncher.class.getSimpleName() + + " with assertions enabled. Add -ea as a VM argument."); + } catch (AssertionError e) { + // All is fine + } + } + /** * Run the server with specified arguments. * diff --git a/uitest/src/com/vaadin/tests/UpgradingSample.java b/uitest/src/com/vaadin/tests/UpgradingSample.java deleted file mode 100644 index 48e2222d7e..0000000000 --- a/uitest/src/com/vaadin/tests/UpgradingSample.java +++ /dev/null @@ -1,197 +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.tests; - -// -// Millstone imports were replaced -// -// import org.millstone.base.Application; -// import org.millstone.base.ui.*; -// import org.millstone.base.data.*; -// -import com.vaadin.Application; -import com.vaadin.data.Property; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.GridLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.Panel; -import com.vaadin.ui.UI.LegacyWindow; -import com.vaadin.ui.TextField; -import com.vaadin.ui.Tree; -import com.vaadin.ui.VerticalLayout; - -/** - * <p> - * Example application demonstrating simple user login. This example is from - * MillStone 3.1.1 examples section. Upgrading from 3.1.1 to 4.0.0 was done by - * updating imports, also setTheme("corporate") call was added to application - * init method. - * </p> - * - * @since 3.1.1 - * @author Vaadin Ltd. - */ -public class UpgradingSample extends Application.LegacyApplication implements - Property.ValueChangeListener { - - /* Menu for navigating inside the application. */ - private final Tree menu = new Tree(); - - /* Contents of the website */ - private final String[][] pages = { - { "Welcome", "Welcome to our website..." }, - { "Products", "Public product information." }, - { "Contact", "Public contact information." }, - { "CRM", "CRM Database requiring login." }, - { "Intranet", "Internal information database." } }; - - /* Application layout */ - private final GridLayout layout = new GridLayout(2, 1); - - /* Initialize the application */ - @Override - public void init() { - - // Create the main window of the application - final LegacyWindow main = new LegacyWindow("Login example", layout); - setMainWindow(main); - - // Add menu and loginbox to the application - final VerticalLayout l = new VerticalLayout(); - layout.addComponent(l, 0, 0); - l.addComponent(menu); - l.addComponent(new LoginBox()); - - // Setup menu - menu.setStyleName("menu"); - menu.addListener(this); - menu.setImmediate(true); - addToMenu(new String[] { "Welcome", "Products", "Contact" }); - } - - // Overriding usetUser method is a simple way of updating application - // privileges when the user is changed - @Override - public void setUser(Object user) { - super.setUser(user); - if (user != null) { - addToMenu(new String[] { "CRM", "Intranet" }); - } - } - - public void addToMenu(String[] items) { - for (int i = 0; i < items.length; i++) { - menu.addItem(items[i]); - menu.setChildrenAllowed(items[i], false); - } - if (menu.getValue() == null) { - menu.setValue(items[0]); - } - } - - // Handle menu selection and update visible page - @Override - public void valueChange(Property.ValueChangeEvent event) { - layout.removeComponent(1, 0); - final String title = (String) menu.getValue(); - for (int i = 0; i < pages.length; i++) { - if (pages[i][0].equals(title)) { - final Panel p = new Panel(pages[i][0]); - p.addComponent(new Label(pages[i][1])); - p.setStyleName("strong"); - layout.addComponent(p, 1, 0); - } - } - } - - // Simple loginbox component for the application - public class LoginBox extends CustomComponent implements - Application.UserChangeListener { - - // The components this loginbox is composed of - private final TextField loginName = new TextField("Name"); - - private final Button loginButton = new Button("Enter", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - login(); - } - }); - - private final Panel loginPanel = new Panel("Login"); - - private final Panel statusPanel = new Panel(); - - private final Button logoutButton = new Button("Logout", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - close(); - } - }); - - private final Label statusLabel = new Label(); - - // Initialize login component - public LoginBox() { - - // Initialize the component - loginPanel.addComponent(loginName); - loginPanel.addComponent(loginButton); - loginPanel.setStyleName("strong"); - loginName.setColumns(8); - statusPanel.addComponent(statusLabel); - statusPanel.addComponent(logoutButton); - - // Set the status of the loginbox and show correct - // components - updateStatus(); - - // Listen application user change events - UpgradingSample.this.addListener(this); - } - - // Login into application - public void login() { - final String name = loginName.getValue(); - if (name != null && name.length() > 0) { - setUser(name); - } - loginName.setValue(""); - } - - // Update login status on application user change events - @Override - public void applicationUserChanged(Application.UserChangeEvent event) { - updateStatus(); - } - - // Update login status of the component by exposing correct - // components - private void updateStatus() { - statusLabel.setValue("User: " + getUser()); - if (getUser() != null) { - setCompositionRoot(statusPanel); - } else { - setCompositionRoot(loginPanel); - } - } - } -} diff --git a/uitest/src/com/vaadin/tests/VerifyAssertionsEnabled.html b/uitest/src/com/vaadin/tests/VerifyAssertionsEnabled.html new file mode 100644 index 0000000000..40ac075d53 --- /dev/null +++ b/uitest/src/com/vaadin/tests/VerifyAssertionsEnabled.html @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head profile="http://selenium-ide.openqa.org/profiles/test-case"> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<link rel="selenium.base" href="" /> +<title>New Test</title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3">New Test</td></tr> +</thead><tbody> +<tr> + <td>open</td> + <td>/run/com.vaadin.tests.VerifyAssertionsEnabled?restartApplication</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>vaadin=runcomvaadintestsVerifyAssertionsEnabled::/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0]</td> + <td>Assertions are enabled</td> +</tr> +</tbody></table> +</body> +</html> diff --git a/uitest/src/com/vaadin/tests/VerifyAssertionsEnabled.java b/uitest/src/com/vaadin/tests/VerifyAssertionsEnabled.java new file mode 100644 index 0000000000..d812ea644a --- /dev/null +++ b/uitest/src/com/vaadin/tests/VerifyAssertionsEnabled.java @@ -0,0 +1,45 @@ +/* + * 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; + +import com.vaadin.server.WrappedRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Label; + +public class VerifyAssertionsEnabled extends AbstractTestUI { + + @Override + protected void setup(WrappedRequest request) { + try { + assert false; + addComponent(new Label("Assertions are not enabled")); + } catch (AssertionError e) { + addComponent(new Label("Assertions are enabled")); + } + } + + @Override + protected String getTestDescription() { + return "Tests whether the testing server is run with assertions enabled."; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(9450); + } + +} diff --git a/uitest/src/com/vaadin/tests/application/ErrorInUnloadEvent.java b/uitest/src/com/vaadin/tests/application/ErrorInUnloadEvent.java index d7e9155ded..1278032f3c 100644 --- a/uitest/src/com/vaadin/tests/application/ErrorInUnloadEvent.java +++ b/uitest/src/com/vaadin/tests/application/ErrorInUnloadEvent.java @@ -10,17 +10,18 @@ import com.vaadin.ui.FormLayout; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.PasswordField; -import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.TextField; +import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.VerticalLayout; public class ErrorInUnloadEvent extends AbstractTestCase { private LegacyWindow mainWindow; + private Object user = null; @Override public void init() { - if (getUser() == null) { + if (user == null) { showLoginWindow(); } else { showMainWindow(); @@ -55,7 +56,7 @@ public class ErrorInUnloadEvent extends AbstractTestCase { String username = userField.getValue(); String password = passwordField.getValue(); - setUser(username); + user = username; showMainWindow(); } }); @@ -84,7 +85,7 @@ public class ErrorInUnloadEvent extends AbstractTestCase { logout.addListener(new ClickListener() { @Override public void buttonClick(final ClickEvent event) { - setUser(null); + user = null; showLoginWindow(); } diff --git a/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java b/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java index 3013659ed7..8962f5de9a 100644 --- a/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java +++ b/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java @@ -1,7 +1,7 @@ package com.vaadin.tests.application; import com.vaadin.Application; -import com.vaadin.UIRequiresMoreInformationException; +import com.vaadin.annotations.PreserveOnRefresh; import com.vaadin.server.AbstractUIProvider; import com.vaadin.server.WrappedRequest; import com.vaadin.tests.components.AbstractTestApplication; @@ -9,6 +9,7 @@ import com.vaadin.ui.Label; import com.vaadin.ui.UI; public class RefreshStatePreserve extends AbstractTestApplication { + @PreserveOnRefresh public static class RefreshStateUI extends UI { @Override public void init(WrappedRequest request) { @@ -22,12 +23,10 @@ public class RefreshStatePreserve extends AbstractTestApplication { @Override public void init() { super.init(); - setUiPreserved(true); addUIProvider(new AbstractUIProvider() { @Override public Class<? extends UI> getUIClass(Application application, - WrappedRequest request) - throws UIRequiresMoreInformationException { + WrappedRequest request) { return RefreshStateUI.class; } }); diff --git a/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java b/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java index 0e7dd1b242..89cbf5d3ff 100644 --- a/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java +++ b/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java @@ -1,9 +1,9 @@ package com.vaadin.tests.application; import com.vaadin.Application; -import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.server.DownloadStream; import com.vaadin.server.PaintException; +import com.vaadin.server.UIProvider; import com.vaadin.server.WrappedRequest; import com.vaadin.tests.components.AbstractTestApplication; import com.vaadin.tests.integration.FlagSeResource; @@ -73,12 +73,19 @@ public class ThreadLocalInstances extends AbstractTestApplication { @Override public void init() { reportCurrentStatus("app init"); - } + addUIProvider(new UIProvider() { + @Override + public UI instantiateUI(Application application, + Class<? extends UI> type, WrappedRequest request) { + return mainWindow; + } - @Override - protected UI getUI(WrappedRequest request) - throws UIRequiresMoreInformationException { - return mainWindow; + @Override + public Class<? extends UI> getUIClass(Application application, + WrappedRequest request) { + return mainWindow.getClass(); + } + }); } @Override diff --git a/uitest/src/com/vaadin/tests/components/loginform/LoginFormUIInLoginHandler.java b/uitest/src/com/vaadin/tests/components/loginform/LoginFormUIInLoginHandler.java index b3ebb02751..58656cb7bf 100755 --- a/uitest/src/com/vaadin/tests/components/loginform/LoginFormUIInLoginHandler.java +++ b/uitest/src/com/vaadin/tests/components/loginform/LoginFormUIInLoginHandler.java @@ -1,52 +1,52 @@ -package com.vaadin.tests.components.loginform;
-
-import com.vaadin.tests.components.TestBase;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.LoginForm;
-import com.vaadin.ui.LoginForm.LoginEvent;
-import com.vaadin.ui.LoginForm.LoginListener;
-import com.vaadin.ui.UI;
-
-public class LoginFormUIInLoginHandler extends TestBase {
-
- @Override
- protected void setup() {
- LoginForm lf = new LoginForm();
- lf.addListener(new LoginListener() {
-
- @Override
- public void onLogin(LoginEvent event) {
- UI r1 = UI.getCurrent();
- if (r1 != null) {
- addComponent(new Label("UI.getCurrent().data: "
- + r1.getData()));
- } else {
- addComponent(new Label("UI.getCurrent() is null"));
- }
- UI r2 = ((LoginForm) event.getSource()).getUI();
- if (r2 != null) {
- addComponent(new Label("event.getSource().data: "
- + r2.getData()));
- } else {
- addComponent(new Label(
- "event.getSource().getRoot() is null"));
- }
- }
- });
- addComponent(lf);
- getLayout().getUI().setData("This UI");
- }
-
- @Override
- protected String getDescription() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- protected Integer getTicketNumber() {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
+package com.vaadin.tests.components.loginform; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Label; +import com.vaadin.ui.LoginForm; +import com.vaadin.ui.LoginForm.LoginEvent; +import com.vaadin.ui.LoginForm.LoginListener; +import com.vaadin.ui.UI; + +public class LoginFormUIInLoginHandler extends TestBase { + + @Override + protected void setup() { + LoginForm lf = new LoginForm(); + lf.addListener(new LoginListener() { + + @Override + public void onLogin(LoginEvent event) { + UI r1 = UI.getCurrent(); + if (r1 != null) { + addComponent(new Label("UI.getCurrent().data: " + + r1.getData())); + } else { + addComponent(new Label("UI.getCurrent() is null")); + } + UI r2 = ((LoginForm) event.getSource()).getUI(); + if (r2 != null) { + addComponent(new Label("event.getSource().data: " + + r2.getData())); + } else { + addComponent(new Label( + "event.getSource().getRoot() is null")); + } + } + }); + addComponent(lf); + getLayout().getUI().setData("This UI"); + } + + @Override + protected String getDescription() { + // TODO Auto-generated method stub + return null; + } + + @Override + protected Integer getTicketNumber() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java b/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java index ac4c3c8ea3..84c14763ab 100644 --- a/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java +++ b/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java @@ -1,6 +1,7 @@ package com.vaadin.tests.components.loginform; import com.vaadin.Application; +import com.vaadin.server.AbstractUIProvider; import com.vaadin.server.WrappedRequest; import com.vaadin.ui.LoginForm; import com.vaadin.ui.LoginForm.LoginEvent; @@ -12,11 +13,17 @@ import com.vaadin.ui.UI.LegacyWindow; public class LoginFormWithMultipleWindows extends Application { @Override - protected UI getUI(WrappedRequest request) { - return new LoginFormWindow(); + public void init() { + addUIProvider(new AbstractUIProvider() { + @Override + public Class<? extends UI> getUIClass(Application application, + WrappedRequest request) { + return LoginFormWindow.class; + } + }); } - public class LoginFormWindow extends LegacyWindow { + public static class LoginFormWindow extends LegacyWindow { public LoginFormWindow() { super(); diff --git a/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java b/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java index 34bf8f6715..18267e90b6 100644 --- a/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java +++ b/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java @@ -1,10 +1,9 @@ package com.vaadin.tests.components.ui; -import com.vaadin.UIRequiresMoreInformationException; -import com.vaadin.annotations.EagerInit; +import com.vaadin.Application; import com.vaadin.server.ExternalResource; +import com.vaadin.server.UIProvider; import com.vaadin.server.WrappedRequest; -import com.vaadin.server.WrappedRequest.BrowserDetails; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.tests.components.AbstractTestApplication; import com.vaadin.ui.Label; @@ -13,7 +12,7 @@ import com.vaadin.ui.UI; public class LazyInitUIs extends AbstractTestApplication { - @EagerInit + // @EagerInit private static class EagerInitUI extends UI { @Override public void init(WrappedRequest request) { @@ -22,23 +21,33 @@ public class LazyInitUIs extends AbstractTestApplication { } @Override - public UI getUI(WrappedRequest request) - throws UIRequiresMoreInformationException { + public void init() { + addUIProvider(new UIProvider() { + + @Override + public UI instantiateUI(Application application, + Class<? extends UI> type, WrappedRequest request) { + return getUI(request); + } + + @Override + public Class<? extends UI> getUIClass(Application application, + WrappedRequest request) { + return getUI(request).getClass(); + } + }); + } + + private UI getUI(WrappedRequest request) { if (request.getParameter("lazyCreate") != null) { // UI created on second request - BrowserDetails browserDetails = request.getBrowserDetails(); - if (browserDetails == null - || browserDetails.getUriFragment() == null) { - throw new UIRequiresMoreInformationException(); - } else { - UI uI = new UI() { - @Override - protected void init(WrappedRequest request) { - addComponent(getRequestInfo("LazyCreateUI", request)); - } - }; - return uI; - } + UI uI = new UI() { + @Override + protected void init(WrappedRequest request) { + addComponent(getRequestInfo("LazyCreateUI", request)); + } + }; + return uI; } else if (request.getParameter("eagerInit") != null) { // UI inited on first request return new EagerInitUI(); diff --git a/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java b/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java index 022db1bf3e..fe2fe16d93 100644 --- a/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java +++ b/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java @@ -1,7 +1,6 @@ package com.vaadin.tests.components.ui; import com.vaadin.Application; -import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.server.AbstractUIProvider; import com.vaadin.server.WrappedRequest; import com.vaadin.tests.components.AbstractTestApplication; @@ -26,8 +25,7 @@ public class UIsInMultipleTabs extends AbstractTestApplication { addUIProvider(new AbstractUIProvider() { @Override public Class<? extends UI> getUIClass(Application application, - WrappedRequest request) - throws UIRequiresMoreInformationException { + WrappedRequest request) { return TabUI.class; } }); diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java index a96b8957c6..cfb24c732f 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java @@ -16,9 +16,10 @@ package com.vaadin.tests.minitutorials.v7a1; +import com.vaadin.annotations.PreserveOnRefresh; import com.vaadin.server.WrappedRequest; -import com.vaadin.ui.UI; import com.vaadin.ui.TextField; +import com.vaadin.ui.UI; /** * Mini tutorial code for @@ -28,6 +29,7 @@ import com.vaadin.ui.TextField; * @author Vaadin Ltd * @since 7.0.0 */ +@PreserveOnRefresh public class CreatingPreserveState extends UI { private static int windowCounter = 0; @@ -36,7 +38,6 @@ public class CreatingPreserveState extends UI { TextField tf = new TextField("Window #" + (++windowCounter)); tf.setImmediate(true); getContent().addComponent(tf); - getApplication().setUiPreserved(true); } } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java index ba3042c48e..54cf8a94e0 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java @@ -17,10 +17,9 @@ package com.vaadin.tests.minitutorials.v7a1; import com.vaadin.Application; -import com.vaadin.UIRequiresMoreInformationException; +import com.vaadin.server.UIProvider; import com.vaadin.server.WebBrowser; import com.vaadin.server.WrappedRequest; -import com.vaadin.server.WrappedRequest.BrowserDetails; import com.vaadin.ui.Label; import com.vaadin.ui.UI; @@ -35,21 +34,32 @@ import com.vaadin.ui.UI; public class DifferentFeaturesForDifferentClients extends Application { @Override - protected UI getUI(WrappedRequest request) - 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 UIRequiresMoreInformationException(); - } + public void init() { + super.init(); + addUIProvider(new UIProvider() { + @Override + public Class<? extends UI> getUIClass(Application application, + WrappedRequest request) { + // could also use browser version etc. + if (request.getHeader("user-agent").contains("mobile")) { + return TouchRoot.class; + } else { + return DefaultRoot.class; + } + } - // could also use screen size, browser version etc. - if (browserDetails.getWebBrowser().isTouchDevice()) { - return new TouchRoot(); - } else { - return new DefaultRoot(); - } + // Must override as default implementation isn't allowed to + // instantiate our non-public classes + @Override + public UI instantiateUI(Application application, + Class<? extends UI> type, WrappedRequest request) { + try { + return type.newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }); } } diff --git a/uitest/src/com/vaadin/tests/vaadincontext/TestAddonContextListener.java b/uitest/src/com/vaadin/tests/vaadincontext/TestAddonContextListener.java index 9f3019b21c..1f50110330 100644 --- a/uitest/src/com/vaadin/tests/vaadincontext/TestAddonContextListener.java +++ b/uitest/src/com/vaadin/tests/vaadincontext/TestAddonContextListener.java @@ -42,9 +42,8 @@ public class TestAddonContextListener implements AddonContextListener { } private boolean shouldModify(BootstrapResponse response) { - UI uI = response.getUI(); - boolean shouldModify = uI != null - && uI.getClass() == BootstrapModifyUI.class; + Class<? extends UI> uiClass = response.getUiClass(); + boolean shouldModify = uiClass == BootstrapModifyUI.class; return shouldModify; } diff --git a/uitest/test.xml b/uitest/test.xml index 9b879ec789..b65926ff5b 100644 --- a/uitest/test.xml +++ b/uitest/test.xml @@ -49,9 +49,8 @@ <!-- fileset containing all TestBench tests to run --> <fileset dir=".." id="html-test-files"> - <include name="tests/**/**.html" /> - <include name="testbench/com/vaadin/tests/**/**.html" /> - <exclude name="tests/integration-testscripts/**" /> + <include name="uitest/**/**.html" /> + <exclude name="uitest/integration-testscripts/**" /> </fileset> <!-- This target converts HTML tests files to java junit tests. One test file for each browser is created. --> diff --git a/uitest/vaadin-server.xml b/uitest/vaadin-server.xml index d4d23581ec..5f2aa06303 100644 --- a/uitest/vaadin-server.xml +++ b/uitest/vaadin-server.xml @@ -41,6 +41,7 @@ </classpath> <jvmarg value="-Demma.coverage.out.file=${testing.testarea}/${package.name}/war.ec"/> <jvmarg value="-Djava.awt.headless=true"/> + <jvmarg value="-ea" /> </java> </target> |