From: Artur Signell Date: Fri, 9 Mar 2012 13:16:37 +0000 (+0200) Subject: Fixed readonly handling for fields (depends on property readonly X-Git-Tag: 7.0.0.alpha2~355 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6548c896ea4a0a7bc516db9ea5dc200bc5796408;p=vaadin-framework.git Fixed readonly handling for fields (depends on property readonly status) and enable state handling for components on client side (depend on parent) --- diff --git a/src/com/vaadin/terminal/gwt/client/AbstractFieldState.java b/src/com/vaadin/terminal/gwt/client/AbstractFieldState.java new file mode 100644 index 0000000000..20d96c9aee --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/AbstractFieldState.java @@ -0,0 +1,37 @@ +package com.vaadin.terminal.gwt.client; + +import com.vaadin.ui.AbstractField; + +/** + * Shared state for {@link AbstractField}. + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0.0 + * + */ +public class AbstractFieldState extends ComponentState { + private boolean propertyReadOnly = false; + + /** + * 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; + } + +} diff --git a/src/com/vaadin/terminal/gwt/client/ComponentConnector.java b/src/com/vaadin/terminal/gwt/client/ComponentConnector.java index a083da0dff..65cbbcaf06 100644 --- a/src/com/vaadin/terminal/gwt/client/ComponentConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ComponentConnector.java @@ -106,4 +106,13 @@ public interface ComponentConnector extends Connector { * The new parent of the connector */ public void setParent(ComponentContainerConnector parent); + + /** + * Checks if the connector is read only. + * + * @deprecated This belongs in AbstractFieldConnector, see #8514 + * @return true + */ + @Deprecated + public boolean isReadOnly(); } diff --git a/src/com/vaadin/terminal/gwt/client/VCaption.java b/src/com/vaadin/terminal/gwt/client/VCaption.java index e639da9502..086a2c7de3 100644 --- a/src/com/vaadin/terminal/gwt/client/VCaption.java +++ b/src/com/vaadin/terminal/gwt/client/VCaption.java @@ -113,7 +113,7 @@ public class VCaption extends HTML { style += " " + CLASSNAME + "-" + styles[i]; } } - if (!owner.getState().isEnabled()) { + if (!owner.isEnabled()) { style += " " + ApplicationConnection.DISABLED_CLASSNAME; } setStyleName(style); diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java index 24baa22940..d5a27d7abf 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java @@ -40,7 +40,6 @@ public abstract class AbstractComponentConnector extends AbstractConnector private Widget widget; /* State variables */ - private boolean enabled = true; private boolean visible = true; // shared state from the server to the client @@ -157,12 +156,16 @@ public abstract class AbstractComponentConnector extends AbstractConnector ((Focusable) getWidget()).setTabIndex(uidl .getIntAttribute("tabindex")); } - setEnabled(getState().isEnabled()); + + if (getWidget() instanceof FocusWidget) { + FocusWidget fw = (FocusWidget) getWidget(); + fw.setEnabled(isEnabled()); + } // Style names String styleName = getStyleNameFromUIDL(getWidget() - .getStylePrimaryName(), uidl, getState(), - getWidget() instanceof Field); + .getStylePrimaryName(), uidl, getWidget() instanceof Field, + this); getWidget().setStyleName(styleName); // Update tooltip @@ -264,24 +267,21 @@ public abstract class AbstractComponentConnector extends AbstractConnector return declaredWidth; } - /** - * Sets the enabled state of this paintable + /* + * (non-Javadoc) * - * @param enabled - * true if the paintable is enabled, false otherwise + * @see com.vaadin.terminal.gwt.client.Connector#isEnabled() */ - protected void setEnabled(boolean enabled) { - this.enabled = enabled; - - if (getWidget() instanceof FocusWidget) { - FocusWidget fw = (FocusWidget) getWidget(); - fw.setEnabled(enabled); + public boolean isEnabled() { + if (!getState().isEnabled()) { + return false; } - } - - public boolean isEnabled() { - return enabled; + if (getParent() == null) { + return true; + } else { + return getParent().isEnabled(); + } } /** @@ -341,19 +341,20 @@ public abstract class AbstractComponentConnector extends AbstractConnector * @return */ protected static String getStyleNameFromUIDL(String primaryStyleName, - UIDL uidl, ComponentState state, boolean field) { - boolean enabled = state.isEnabled(); + UIDL uidl, boolean field, ComponentConnector connector) { + ComponentState state = connector.getState(); StringBuffer styleBuf = new StringBuffer(); styleBuf.append(primaryStyleName); styleBuf.append(" v-paintable"); - // first disabling and read-only status - if (!enabled) { + // Uses connector methods to enable connectors to take hierarchy or + // multiple state variables into account + if (!connector.isEnabled()) { styleBuf.append(" "); styleBuf.append(ApplicationConnection.DISABLED_CLASSNAME); } - if (state.isReadOnly()) { + if (connector.isReadOnly()) { styleBuf.append(" "); styleBuf.append("v-readonly"); } @@ -372,6 +373,7 @@ public abstract class AbstractComponentConnector extends AbstractConnector } } + // TODO Move to AbstractFieldConnector // add modified classname to Fields if (field && uidl.hasAttribute("modified")) { styleBuf.append(" "); @@ -394,6 +396,16 @@ public abstract class AbstractComponentConnector extends AbstractConnector return styleBuf.toString(); } + /* + * (non-Javadoc) + * + * @see com.vaadin.terminal.gwt.client.ComponentConnector#isReadOnly() + */ + @Deprecated + public boolean isReadOnly() { + return getState().isReadOnly(); + } + /** * Sets the shared state for the paintable widget. * diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbstractDateFieldConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbstractDateFieldConnector.java index 0068eb8960..6aa5bf2fff 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/AbstractDateFieldConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/AbstractDateFieldConnector.java @@ -12,7 +12,7 @@ import com.vaadin.terminal.gwt.client.LocaleNotLoadedException; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.VConsole; -public class AbstractDateFieldConnector extends AbstractComponentConnector { +public class AbstractDateFieldConnector extends AbstractFieldConnector { @Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { @@ -27,8 +27,8 @@ public class AbstractDateFieldConnector extends AbstractComponentConnector { getWidget().paintableId = uidl.getId(); getWidget().immediate = getState().isImmediate(); - getWidget().readonly = getState().isReadOnly(); - getWidget().enabled = getState().isEnabled(); + getWidget().readonly = isReadOnly(); + getWidget().enabled = isEnabled(); if (uidl.hasAttribute("locale")) { final String locale = uidl.getStringAttribute("locale"); diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbstractFieldConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbstractFieldConnector.java new file mode 100644 index 0000000000..8ef11a5f7d --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/AbstractFieldConnector.java @@ -0,0 +1,24 @@ +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; +import com.vaadin.terminal.gwt.client.AbstractFieldState; +import com.vaadin.terminal.gwt.client.ComponentState; + +public abstract class AbstractFieldConnector extends AbstractComponentConnector { + + @Override + public AbstractFieldState getState() { + return (AbstractFieldState) super.getState(); + } + + @Override + protected ComponentState createState() { + return GWT.create(AbstractFieldState.class); + } + + @Override + public boolean isReadOnly() { + return super.isReadOnly() || getState().isPropertyReadOnly(); + } + +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbstractSplitPanelConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbstractSplitPanelConnector.java index 2f0674b58d..ce2820b56d 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/AbstractSplitPanelConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/AbstractSplitPanelConnector.java @@ -75,7 +75,7 @@ public abstract class AbstractSplitPanelConnector extends if (!isRealUpdate(uidl)) { return; } - getWidget().setEnabled(getState().isEnabled()); + getWidget().setEnabled(isEnabled()); clickEventHandler.handleEventHandlerRegistration(client); if (getState().hasStyles()) { diff --git a/src/com/vaadin/terminal/gwt/client/ui/CheckBoxConnector.java b/src/com/vaadin/terminal/gwt/client/ui/CheckBoxConnector.java index e59777ef31..d842104fab 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/CheckBoxConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/CheckBoxConnector.java @@ -12,7 +12,7 @@ import com.vaadin.terminal.gwt.client.EventHelper; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.VTooltip; -public class CheckBoxConnector extends AbstractComponentConnector { +public class CheckBoxConnector extends AbstractFieldConnector { @Override protected boolean delegateCaptionHandling() { @@ -55,7 +55,7 @@ public class CheckBoxConnector extends AbstractComponentConnector { "none"); } - if (getState().isReadOnly()) { + if (isReadOnly()) { getWidget().setEnabled(false); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/ComboBoxConnector.java b/src/com/vaadin/terminal/gwt/client/ui/ComboBoxConnector.java index d8fb48dc8d..529046a307 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/ComboBoxConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/ComboBoxConnector.java @@ -12,7 +12,7 @@ import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.ui.VFilterSelect.FilterSelectSuggestion; -public class ComboBoxConnector extends AbstractComponentConnector implements +public class ComboBoxConnector extends AbstractFieldConnector implements SimpleManagedLayout { /* @@ -29,8 +29,8 @@ public class ComboBoxConnector extends AbstractComponentConnector implements getWidget().client = client; getWidget().paintableId = uidl.getId(); - getWidget().readonly = getState().isReadOnly(); - getWidget().enabled = getState().isEnabled(); + getWidget().readonly = isReadOnly(); + getWidget().enabled = isEnabled(); getWidget().tb.setEnabled(getWidget().enabled); getWidget().updateReadOnly(); diff --git a/src/com/vaadin/terminal/gwt/client/ui/FormConnector.java b/src/com/vaadin/terminal/gwt/client/ui/FormConnector.java index 9ff7a38ccf..3107780d59 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/FormConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/FormConnector.java @@ -7,8 +7,10 @@ import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.dom.client.KeyDownEvent; import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.AbstractFieldState; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.ComponentConnector; +import com.vaadin.terminal.gwt.client.ComponentState; import com.vaadin.terminal.gwt.client.ConnectorMap; import com.vaadin.terminal.gwt.client.UIDL; @@ -176,4 +178,19 @@ public class FormConnector extends AbstractComponentContainerConnector form.footerContainer.getStyle().setMarginTop(-footerHeight, Unit.PX); } + @Override + public boolean isReadOnly() { + return super.isReadOnly() || getState().isPropertyReadOnly(); + } + + @Override + public AbstractFieldState getState() { + return (AbstractFieldState) super.getState(); + } + + @Override + protected ComponentState createState() { + return GWT.create(AbstractFieldState.class); + } + } diff --git a/src/com/vaadin/terminal/gwt/client/ui/FormLayoutConnector.java b/src/com/vaadin/terminal/gwt/client/ui/FormLayoutConnector.java index 598c8023de..52eb4c9826 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/FormLayoutConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/FormLayoutConnector.java @@ -8,6 +8,8 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.ComponentConnector; import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.ui.VFormLayout.Caption; +import com.vaadin.terminal.gwt.client.ui.VFormLayout.ErrorFlag; public class FormLayoutConnector extends AbstractComponentContainerConnector { @Override @@ -23,7 +25,16 @@ public class FormLayoutConnector extends AbstractComponentContainerConnector { } public void updateCaption(ComponentConnector component, UIDL uidl) { - getWidget().table.updateCaption(component, uidl); + final Caption c = getWidget().table.widgetToCaption.get(component + .getWidget()); + if (c != null) { + c.updateCaption(uidl, component.getState(), component.isEnabled()); + } + final ErrorFlag e = getWidget().table.widgetToError.get(component + .getWidget()); + if (e != null) { + e.updateFromUIDL(uidl, component); + } } @Override diff --git a/src/com/vaadin/terminal/gwt/client/ui/LinkConnector.java b/src/com/vaadin/terminal/gwt/client/ui/LinkConnector.java index 7d6e7e04ce..21172becff 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/LinkConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/LinkConnector.java @@ -29,8 +29,7 @@ public class LinkConnector extends AbstractComponentConnector { getWidget().client = client; - getWidget().enabled = getState().isEnabled(); - getWidget().readonly = getState().isReadOnly(); + getWidget().enabled = isEnabled(); if (uidl.hasAttribute("name")) { getWidget().target = uidl.getStringAttribute("name"); diff --git a/src/com/vaadin/terminal/gwt/client/ui/MenuBarConnector.java b/src/com/vaadin/terminal/gwt/client/ui/MenuBarConnector.java index 62b1cb69a7..60d25c5509 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/MenuBarConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/MenuBarConnector.java @@ -38,7 +38,7 @@ public class MenuBarConnector extends AbstractComponentConnector implements getWidget().openRootOnHover = uidl .getBooleanAttribute(VMenuBar.OPEN_ROOT_MENU_ON_HOWER); - getWidget().enabled = getState().isEnabled(); + getWidget().enabled = isEnabled(); // For future connections getWidget().client = client; diff --git a/src/com/vaadin/terminal/gwt/client/ui/OptionGroupBaseConnector.java b/src/com/vaadin/terminal/gwt/client/ui/OptionGroupBaseConnector.java index 41844da348..fe7abce18c 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/OptionGroupBaseConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/OptionGroupBaseConnector.java @@ -7,8 +7,7 @@ package com.vaadin.terminal.gwt.client.ui; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.UIDL; -public abstract class OptionGroupBaseConnector extends - AbstractComponentConnector { +public abstract class OptionGroupBaseConnector extends AbstractFieldConnector { @Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { @@ -24,8 +23,8 @@ public abstract class OptionGroupBaseConnector extends getWidget().selectedKeys = uidl.getStringArrayVariableAsSet("selected"); - getWidget().readonly = getState().isReadOnly(); - getWidget().disabled = !getState().isEnabled(); + getWidget().readonly = isReadOnly(); + getWidget().disabled = !isEnabled(); getWidget().multiselect = "multi".equals(uidl .getStringAttribute("selectmode")); getWidget().immediate = getState().isImmediate(); diff --git a/src/com/vaadin/terminal/gwt/client/ui/PopupDateFieldConnector.java b/src/com/vaadin/terminal/gwt/client/ui/PopupDateFieldConnector.java index 4c315046aa..0e4afde99a 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/PopupDateFieldConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/PopupDateFieldConnector.java @@ -35,8 +35,7 @@ public class PopupDateFieldConnector extends TextualDateConnector { super.updateFromUIDL(uidl, client); String popupStyleNames = getStyleNameFromUIDL( - VPopupCalendar.POPUP_PRIMARY_STYLE_NAME, uidl, getState(), - false); + VPopupCalendar.POPUP_PRIMARY_STYLE_NAME, uidl, false, this); popupStyleNames += " " + VDateField.CLASSNAME + "-" diff --git a/src/com/vaadin/terminal/gwt/client/ui/ProgressIndicatorConnector.java b/src/com/vaadin/terminal/gwt/client/ui/ProgressIndicatorConnector.java index e5cd8f6d4d..21c6a06a36 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/ProgressIndicatorConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/ProgressIndicatorConnector.java @@ -10,7 +10,7 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.UIDL; -public class ProgressIndicatorConnector extends AbstractComponentConnector { +public class ProgressIndicatorConnector extends AbstractFieldConnector { @Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { @@ -30,7 +30,7 @@ public class ProgressIndicatorConnector extends AbstractComponentConnector { if (getWidget().indeterminate) { String basename = VProgressIndicator.CLASSNAME + "-indeterminate"; getWidget().addStyleName(basename); - if (!getState().isEnabled()) { + if (!isEnabled()) { getWidget().addStyleName(basename + "-disabled"); } else { getWidget().removeStyleName(basename + "-disabled"); @@ -46,7 +46,7 @@ public class ProgressIndicatorConnector extends AbstractComponentConnector { } } - if (getState().isEnabled()) { + if (isEnabled()) { getWidget().interval = uidl.getIntAttribute("pollinginterval"); getWidget().poller.scheduleRepeating(getWidget().interval); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/SliderConnector.java b/src/com/vaadin/terminal/gwt/client/ui/SliderConnector.java index 900e3af633..dcea66ca94 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/SliderConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/SliderConnector.java @@ -10,7 +10,7 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.UIDL; -public class SliderConnector extends AbstractComponentConnector { +public class SliderConnector extends AbstractFieldConnector { @Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { @@ -25,8 +25,8 @@ public class SliderConnector extends AbstractComponentConnector { } getWidget().immediate = getState().isImmediate(); - getWidget().disabled = !getState().isEnabled(); - getWidget().readonly = getState().isReadOnly(); + getWidget().disabled = !isEnabled(); + getWidget().readonly = isReadOnly(); getWidget().vertical = uidl.hasAttribute("vertical"); diff --git a/src/com/vaadin/terminal/gwt/client/ui/TableConnector.java b/src/com/vaadin/terminal/gwt/client/ui/TableConnector.java index eadefc94b3..0d17a7ccc2 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/TableConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/TableConnector.java @@ -8,9 +8,11 @@ import com.google.gwt.core.client.Scheduler; import com.google.gwt.dom.client.Style.Position; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.AbstractFieldState; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.ComponentConnector; +import com.vaadin.terminal.gwt.client.ComponentState; import com.vaadin.terminal.gwt.client.DirectionalManagedLayout; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; @@ -55,7 +57,7 @@ public class TableConnector extends AbstractComponentContainerConnector return; } - getWidget().enabled = getState().isEnabled(); + getWidget().enabled = isEnabled(); if (BrowserInfo.get().isIE8() && !getWidget().enabled) { /* @@ -79,7 +81,7 @@ public class TableConnector extends AbstractComponentContainerConnector getWidget().updateDragMode(uidl); - getWidget().updateSelectionProperties(uidl, getState()); + getWidget().updateSelectionProperties(uidl, getState(), isReadOnly()); if (uidl.hasAttribute("alb")) { getWidget().bodyActionKeys = uidl.getStringArrayAttribute("alb"); @@ -262,4 +264,20 @@ public class TableConnector extends AbstractComponentContainerConnector public void postLayout() { getWidget().sizeInit(); } + + @Override + public boolean isReadOnly() { + return super.isReadOnly() || getState().isPropertyReadOnly(); + } + + @Override + public AbstractFieldState getState() { + return (AbstractFieldState) super.getState(); + } + + @Override + protected ComponentState createState() { + return GWT.create(AbstractFieldState.class); + } + } diff --git a/src/com/vaadin/terminal/gwt/client/ui/TabsheetBaseConnector.java b/src/com/vaadin/terminal/gwt/client/ui/TabsheetBaseConnector.java index 1840ac159e..0c44068cf5 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/TabsheetBaseConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/TabsheetBaseConnector.java @@ -32,7 +32,7 @@ public abstract class TabsheetBaseConnector extends // Update member references getWidget().id = uidl.getId(); - getWidget().disabled = !getState().isEnabled(); + getWidget().disabled = !isEnabled(); // Render content final UIDL tabs = uidl.getChildUIDL(0); diff --git a/src/com/vaadin/terminal/gwt/client/ui/TextFieldConnector.java b/src/com/vaadin/terminal/gwt/client/ui/TextFieldConnector.java index 598bc05e19..e1fb3a56a8 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/TextFieldConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/TextFieldConnector.java @@ -13,7 +13,7 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutActionListener; -public class TextFieldConnector extends AbstractComponentConnector implements +public class TextFieldConnector extends AbstractFieldConnector implements BeforeShortcutActionListener { @Override @@ -27,7 +27,7 @@ public class TextFieldConnector extends AbstractComponentConnector implements return; } - getWidget().setReadOnly(getState().isReadOnly()); + getWidget().setReadOnly(isReadOnly()); getWidget().inputPrompt = uidl .getStringAttribute(VTextField.ATTR_INPUTPROMPT); diff --git a/src/com/vaadin/terminal/gwt/client/ui/TreeConnector.java b/src/com/vaadin/terminal/gwt/client/ui/TreeConnector.java index b6e6095ef2..9e670e46df 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/TreeConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/TreeConnector.java @@ -7,7 +7,9 @@ import java.util.Iterator; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.AbstractFieldState; import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.ComponentState; import com.vaadin.terminal.gwt.client.TooltipInfo; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.ui.VTree.TreeNode; @@ -43,8 +45,8 @@ public class TreeConnector extends AbstractComponentConnector { getWidget().immediate = getState().isImmediate(); - getWidget().disabled = !getState().isEnabled(); - getWidget().readonly = getState().isReadOnly(); + getWidget().disabled = !isEnabled(); + getWidget().readonly = isReadOnly(); getWidget().dragMode = uidl.hasAttribute("dragMode") ? uidl .getIntAttribute("dragMode") : 0; @@ -235,4 +237,20 @@ public class TreeConnector extends AbstractComponentConnector { } containerNode.childrenLoaded = true; } + + @Override + public boolean isReadOnly() { + return super.isReadOnly() || getState().isPropertyReadOnly(); + } + + @Override + public AbstractFieldState getState() { + return (AbstractFieldState) super.getState(); + } + + @Override + protected ComponentState createState() { + return GWT.create(AbstractFieldState.class); + } + } diff --git a/src/com/vaadin/terminal/gwt/client/ui/UploadConnector.java b/src/com/vaadin/terminal/gwt/client/ui/UploadConnector.java index 05a5e7d73d..182156d0e4 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/UploadConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/UploadConnector.java @@ -41,7 +41,7 @@ public class UploadConnector extends AbstractComponentConnector { } getWidget().fu.setName(getWidget().paintableId + "_file"); - if (!getState().isEnabled() || getState().isReadOnly()) { + if (!isEnabled() || isReadOnly()) { getWidget().disableUpload(); } else if (!uidl.getBooleanAttribute("state")) { // Enable the button only if an upload is not in progress diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java index cf9f35dc8d..9beef5d2df 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java @@ -50,9 +50,10 @@ public class VFormLayout extends SimplePanel { * * @param state * shared state of the component + * @param enabled * @return An array of stylenames */ - private String[] getStylesFromState(ComponentState state) { + private String[] getStylesFromState(ComponentState state, boolean enabled) { List styles = new ArrayList(); if (state.hasStyles()) { String[] stylesnames = state.getStyle().split(" "); @@ -61,7 +62,7 @@ public class VFormLayout extends SimplePanel { } } - if (!state.isEnabled()) { + if (!enabled) { styles.add(ApplicationConnection.DISABLED_CLASSNAME); } @@ -74,8 +75,8 @@ public class VFormLayout extends SimplePanel { private static final int COLUMN_ERRORFLAG = 1; private static final int COLUMN_WIDGET = 2; - private HashMap widgetToCaption = new HashMap(); - private HashMap widgetToError = new HashMap(); + HashMap widgetToCaption = new HashMap(); + HashMap widgetToError = new HashMap(); public VFormLayoutTable() { DOM.setElementProperty(getElement(), "cellPadding", "0"); @@ -178,18 +179,6 @@ public class VFormLayout extends SimplePanel { } } - public void updateCaption(ComponentConnector paintable, UIDL uidl) { - final Caption c = widgetToCaption.get(paintable.getWidget()); - if (c != null) { - c.updateCaption(uidl, paintable.getState()); - } - final ErrorFlag e = widgetToError.get(paintable.getWidget()); - if (e != null) { - e.updateFromUIDL(uidl, paintable); - } - - } - /* * (non-Javadoc) * @@ -259,11 +248,12 @@ public class VFormLayout extends SimplePanel { setStyleName(styleName); } - public void updateCaption(UIDL uidl, ComponentState state) { + public void updateCaption(UIDL uidl, ComponentState state, + boolean enabled) { setVisible(!uidl.getBooleanAttribute("invisible")); // Update styles as they might have changed when the caption changed - setStyles(getStylesFromState(state)); + setStyles(getStylesFromState(state, enabled)); boolean isEmpty = true; @@ -356,7 +346,7 @@ public class VFormLayout extends SimplePanel { } } - private class ErrorFlag extends HTML { + class ErrorFlag extends HTML { private static final String CLASSNAME = VFormLayout.CLASSNAME + "-error-indicator"; Element errorIndicatorElement; diff --git a/src/com/vaadin/terminal/gwt/client/ui/VLink.java b/src/com/vaadin/terminal/gwt/client/ui/VLink.java index 674153b716..22c3d10657 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VLink.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VLink.java @@ -31,8 +31,6 @@ public class VLink extends HTML implements ClickHandler { protected boolean enabled; - protected boolean readonly; - protected int targetWidth; protected int targetHeight; @@ -57,7 +55,7 @@ public class VLink extends HTML implements ClickHandler { } public void onClick(ClickEvent event) { - if (enabled && !readonly) { + if (enabled) { if (target == null) { target = "_self"; } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java index 809a4dcb72..9166ffdf9f 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java @@ -969,7 +969,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } } - void updateSelectionProperties(UIDL uidl, ComponentState state) { + void updateSelectionProperties(UIDL uidl, ComponentState state, + boolean readOnly) { setMultiSelectMode(uidl.hasAttribute("multiselectmode") ? uidl .getIntAttribute("multiselectmode") : MULTISELECT_MODE_DEFAULT); @@ -977,7 +978,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, .getBooleanAttribute("nsa") : true; if (uidl.hasAttribute("selectmode")) { - if (state.isReadOnly()) { + if (readOnly) { selectMode = SelectMode.NONE; } else if (uidl.getStringAttribute("selectmode").equals("multi")) { selectMode = SelectMode.MULTI; diff --git a/src/com/vaadin/terminal/gwt/client/ui/WindowConnector.java b/src/com/vaadin/terminal/gwt/client/ui/WindowConnector.java index 5a00950a48..7775766689 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/WindowConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/WindowConnector.java @@ -104,7 +104,7 @@ public class WindowConnector extends AbstractComponentContainerConnector getWidget().immediate = getState().isImmediate(); - getWidget().setClosable(!getState().isReadOnly()); + getWidget().setClosable(!isReadOnly()); // Initialize the position form UIDL int positionx = uidl.getIntVariable("positionx"); diff --git a/src/com/vaadin/terminal/gwt/client/ui/richtextarea/RichTextAreaConnector.java b/src/com/vaadin/terminal/gwt/client/ui/richtextarea/RichTextAreaConnector.java index f60ed53813..77835236a5 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/richtextarea/RichTextAreaConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/richtextarea/RichTextAreaConnector.java @@ -8,10 +8,10 @@ import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.UIDL; -import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; +import com.vaadin.terminal.gwt.client.ui.AbstractFieldConnector; import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutActionListener; -public class RichTextAreaConnector extends AbstractComponentConnector implements +public class RichTextAreaConnector extends AbstractFieldConnector implements BeforeShortcutActionListener { @Override @@ -28,7 +28,7 @@ public class RichTextAreaConnector extends AbstractComponentConnector implements } } if (isRealUpdate(uidl)) { - getWidget().setEnabled(getState().isEnabled()); + getWidget().setEnabled(isEnabled()); } super.updateFromUIDL(uidl, client); @@ -36,7 +36,7 @@ public class RichTextAreaConnector extends AbstractComponentConnector implements return; } - getWidget().setReadOnly(getState().isReadOnly()); + getWidget().setReadOnly(isReadOnly()); getWidget().immediate = getState().isImmediate(); int newMaxLength = uidl.hasAttribute("maxLength") ? uidl .getIntAttribute("maxLength") : -1; diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java index 109c202909..82d3d2af19 100644 --- a/src/com/vaadin/ui/AbstractField.java +++ b/src/com/vaadin/ui/AbstractField.java @@ -30,6 +30,7 @@ import com.vaadin.terminal.CompositeErrorMessage; import com.vaadin.terminal.ErrorMessage; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; +import com.vaadin.terminal.gwt.client.AbstractFieldState; import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; /** @@ -730,6 +731,8 @@ public abstract class AbstractField extends AbstractComponent implements // Sets the new data source dataSource = newDataSource; + getState().setPropertyReadOnly( + dataSource == null ? false : dataSource.isReadOnly()); // Check if the current converter is compatible. if (newDataSource != null @@ -1218,6 +1221,7 @@ public abstract class AbstractField extends AbstractComponent implements * @see Property.ReadOnlyStatusChangeListener */ public void readOnlyStatusChange(Property.ReadOnlyStatusChangeEvent event) { + getState().setPropertyReadOnly(event.getProperty().isReadOnly()); requestRepaint(); } @@ -1613,4 +1617,13 @@ public abstract class AbstractField extends AbstractComponent implements requestRepaint(); } + @Override + public AbstractFieldState getState() { + return (AbstractFieldState) super.getState(); + } + + @Override + protected AbstractFieldState createState() { + return new AbstractFieldState(); + } }