From: Artur Signell Date: Mon, 2 Apr 2012 08:54:45 +0000 (+0300) Subject: AbstractComponent.updateFromUIDL moved to state change (#8436) X-Git-Tag: 7.0.0.alpha2~159 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1c834dc864ca31f2c7020a7fc7345d7765def3fe;p=vaadin-framework.git AbstractComponent.updateFromUIDL moved to state change (#8436) --- diff --git a/src/com/vaadin/terminal/gwt/client/AbstractFieldState.java b/src/com/vaadin/terminal/gwt/client/AbstractFieldState.java index ba67902fae..3a66a01f23 100644 --- a/src/com/vaadin/terminal/gwt/client/AbstractFieldState.java +++ b/src/com/vaadin/terminal/gwt/client/AbstractFieldState.java @@ -3,6 +3,7 @@ */ package com.vaadin.terminal.gwt.client; +import com.vaadin.terminal.gwt.client.ui.TabIndexState; import com.vaadin.ui.AbstractField; /** @@ -13,10 +14,16 @@ import com.vaadin.ui.AbstractField; * @since 7.0.0 * */ -public class AbstractFieldState extends ComponentState { +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. @@ -87,4 +94,44 @@ public class AbstractFieldState extends ComponentState { 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.terminal.gwt.client.ComponentState#getTabIndex() + */ + public int getTabIndex() { + return tabIndex; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.terminal.gwt.client.ui.TabIndexState#setTabIndex(int) + */ + public void setTabIndex(int tabIndex) { + this.tabIndex = tabIndex; + } + } diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java index 2a9ac4ff62..cc357cf772 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java @@ -22,6 +22,7 @@ import com.vaadin.terminal.gwt.client.VConsole; import com.vaadin.terminal.gwt.client.communication.ServerRpc; import com.vaadin.terminal.gwt.client.communication.ServerRpc.InitializableClientToServerRpc; import com.vaadin.terminal.gwt.client.communication.SharedState; +import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; public abstract class AbstractComponentConnector extends AbstractConnector implements ComponentConnector { @@ -113,10 +114,9 @@ public abstract class AbstractComponentConnector extends AbstractConnector return !uidl.hasAttribute("cached"); } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - if (!isRealUpdate(uidl)) { - return; - } + @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + super.onStateChanged(stateChangeEvent); ConnectorMap paintableMap = ConnectorMap.get(getConnection()); @@ -131,9 +131,9 @@ public abstract class AbstractComponentConnector extends AbstractConnector * Disabled state may affect (override) tabindex so the order must be * first setting tabindex, then enabled state. */ - if (uidl.hasAttribute("tabindex") && getWidget() instanceof Focusable) { - ((Focusable) getWidget()).setTabIndex(uidl - .getIntAttribute("tabindex")); + if (state instanceof TabIndexState && getWidget() instanceof Focusable) { + ((Focusable) getWidget()).setTabIndex(((TabIndexState) state) + .getTabIndex()); } if (getWidget() instanceof FocusWidget) { @@ -142,8 +142,7 @@ public abstract class AbstractComponentConnector extends AbstractConnector } // Style names - String styleName = getStyleNameFromUIDL(getWidget() - .getStylePrimaryName(), uidl, getWidget() instanceof Field, + String styleName = getStyleNames(getWidget().getStylePrimaryName(), this); getWidget().setStyleName(styleName); @@ -179,6 +178,11 @@ public abstract class AbstractComponentConnector extends AbstractConnector updateComponentSize(); } + @Deprecated + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + // TODO Remove this method + } + private void updateComponentSize() { String newWidth = getState().getWidth(); String newHeight = getState().getHeight(); @@ -273,8 +277,8 @@ public abstract class AbstractComponentConnector extends AbstractConnector * @param field * @return */ - protected static String getStyleNameFromUIDL(String primaryStyleName, - UIDL uidl, boolean field, ComponentConnector connector) { + protected static String getStyleNames(String primaryStyleName, + ComponentConnector connector) { ComponentState state = connector.getState(); StringBuffer styleBuf = new StringBuffer(); @@ -305,11 +309,21 @@ public abstract class AbstractComponentConnector extends AbstractConnector } } - // TODO Move to AbstractFieldConnector - // add modified classname to Fields - if (field && uidl.hasAttribute("modified")) { - styleBuf.append(" "); - styleBuf.append(ApplicationConnection.MODIFIED_CLASSNAME); + if (connector instanceof AbstractFieldConnector) { + // TODO Move to AbstractFieldConnector + AbstractFieldConnector afc = ((AbstractFieldConnector) connector); + if (afc.isModified()) { + // add modified classname to Fields + styleBuf.append(" "); + styleBuf.append(ApplicationConnection.MODIFIED_CLASSNAME); + } + + if (afc.isRequired()) { + // add required classname to required fields + styleBuf.append(" "); + styleBuf.append(primaryStyleName); + styleBuf.append(ApplicationConnection.REQUIRED_CLASSNAME_EXT); + } } // add error classname to components w/ error @@ -318,13 +332,6 @@ public abstract class AbstractComponentConnector extends AbstractConnector styleBuf.append(primaryStyleName); styleBuf.append(ApplicationConnection.ERROR_CLASSNAME_EXT); } - // add required style to required components - if (connector instanceof AbstractFieldConnector - && ((AbstractFieldConnector) connector).isRequired()) { - styleBuf.append(" "); - styleBuf.append(primaryStyleName); - styleBuf.append(ApplicationConnection.REQUIRED_CLASSNAME_EXT); - } return styleBuf.toString(); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java index 667c23bc77..77065f248c 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java @@ -15,6 +15,7 @@ import com.google.gwt.event.shared.HandlerRegistration; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.ServerConnector; import com.vaadin.terminal.gwt.client.Util; +import com.vaadin.terminal.gwt.client.VConsole; import com.vaadin.terminal.gwt.client.communication.ClientRpc; import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; import com.vaadin.terminal.gwt.client.communication.StateChangeEvent.StateChangeHandler; @@ -161,9 +162,8 @@ public abstract class AbstractConnector implements ServerConnector, .addHandler(StateChangeEvent.TYPE, handler); } - // TODO Should be abstract as all connectors need it public void onStateChanged(StateChangeEvent stateChangeEvent) { - System.out.println("State change event for " + VConsole.log("State change event for " + Util.getConnectorString(stateChangeEvent.getConnector()) + " received by " + Util.getConnectorString(this)); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbstractFieldConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbstractFieldConnector.java index b2c7101c15..76f23c761a 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/AbstractFieldConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/AbstractFieldConnector.java @@ -24,6 +24,10 @@ public abstract class AbstractFieldConnector extends AbstractComponentConnector return super.isReadOnly() || getState().isPropertyReadOnly(); } + public boolean isModified() { + return getState().isModified(); + } + /** * Checks whether the required indicator should be shown for the field. * diff --git a/src/com/vaadin/terminal/gwt/client/ui/PopupDateFieldConnector.java b/src/com/vaadin/terminal/gwt/client/ui/PopupDateFieldConnector.java index 05cd0466a9..9a65513afd 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/PopupDateFieldConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/PopupDateFieldConnector.java @@ -36,8 +36,8 @@ public class PopupDateFieldConnector extends TextualDateConnector { super.updateFromUIDL(uidl, client); - String popupStyleNames = getStyleNameFromUIDL( - VPopupCalendar.POPUP_PRIMARY_STYLE_NAME, uidl, false, this); + String popupStyleNames = getStyleNames( + VPopupCalendar.POPUP_PRIMARY_STYLE_NAME, this); popupStyleNames += " " + VDateField.CLASSNAME + "-" diff --git a/src/com/vaadin/terminal/gwt/client/ui/TabIndexState.java b/src/com/vaadin/terminal/gwt/client/ui/TabIndexState.java new file mode 100644 index 0000000000..ab093f612f --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/TabIndexState.java @@ -0,0 +1,26 @@ +package com.vaadin.terminal.gwt.client.ui; + +/** + * Interface implemented by state classes that support tab indexes. + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0.0 + * + */ +public interface TabIndexState { + /** + * Gets the tabulator index of the field. + * + * @return the tab index for the Field + */ + public int getTabIndex(); + + /** + * Sets the tabulator index of the field. + * + * @param tabIndex + * the tab index to set + */ + public void setTabIndex(int tabIndex); +} diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java index 9f24bfb1d7..aecb07e108 100644 --- a/src/com/vaadin/ui/AbstractField.java +++ b/src/com/vaadin/ui/AbstractField.java @@ -99,11 +99,6 @@ public abstract class AbstractField extends AbstractComponent implements */ private boolean readThroughMode = true; - /** - * Is the field modified but not committed. - */ - private boolean modified = false; - /** * Flag to indicate that the field is currently committing its value to the * datasource. @@ -125,11 +120,6 @@ public abstract class AbstractField extends AbstractComponent implements */ private boolean invalidCommitted = false; - /** - * The tab order number of this field. - */ - private int tabIndex = 0; - /** * The error message for the exception that is thrown when the field is * required but empty. @@ -154,19 +144,6 @@ public abstract class AbstractField extends AbstractComponent implements * Paints the field. Don't add a JavaDoc comment here, we use the default * documentation from the implemented interface. */ - @Override - public void paintContent(PaintTarget target) throws PaintException { - - // The tab ordering number - if (getTabIndex() != 0) { - target.addAttribute("tabindex", getTabIndex()); - } - - // If the field is modified, but not committed, set modified attribute - if (isModified()) { - target.addAttribute("modified", true); - } - } /** * Returns true if the error indicator be hidden when painting the component @@ -266,12 +243,9 @@ public abstract class AbstractField extends AbstractComponent implements } } - boolean repaintNeeded = false; - // The abstract field is not modified anymore if (isModified()) { setModified(false); - repaintNeeded = true; } // If successful, remove set the buffering state to be ok @@ -282,8 +256,6 @@ public abstract class AbstractField extends AbstractComponent implements if (valueWasModifiedByDataSourceDuringCommit) { valueWasModifiedByDataSourceDuringCommit = false; fireValueChange(false); - } else if (repaintNeeded) { - requestRepaint(); } } @@ -365,11 +337,12 @@ public abstract class AbstractField extends AbstractComponent implements * interface. */ public boolean isModified() { - return modified; + return getState().isModified(); } private void setModified(boolean modified) { - this.modified = modified; + getState().setModified(modified); + requestRepaint(); } /* @@ -1334,7 +1307,7 @@ public abstract class AbstractField extends AbstractComponent implements * @see com.vaadin.ui.Component.Focusable#getTabIndex() */ public int getTabIndex() { - return tabIndex; + return getState().getTabIndex(); } /* @@ -1343,7 +1316,7 @@ public abstract class AbstractField extends AbstractComponent implements * @see com.vaadin.ui.Component.Focusable#setTabIndex(int) */ public void setTabIndex(int tabIndex) { - this.tabIndex = tabIndex; + getState().setTabIndex(tabIndex); requestRepaint(); }