]> source.dussan.org Git - vaadin-framework.git/commitdiff
AbstractComponent.updateFromUIDL moved to state change (#8436)
authorArtur Signell <artur@vaadin.com>
Mon, 2 Apr 2012 08:54:45 +0000 (11:54 +0300)
committerArtur Signell <artur@vaadin.com>
Wed, 4 Apr 2012 21:08:09 +0000 (00:08 +0300)
src/com/vaadin/terminal/gwt/client/AbstractFieldState.java
src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java
src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java
src/com/vaadin/terminal/gwt/client/ui/AbstractFieldConnector.java
src/com/vaadin/terminal/gwt/client/ui/PopupDateFieldConnector.java
src/com/vaadin/terminal/gwt/client/ui/TabIndexState.java [new file with mode: 0644]
src/com/vaadin/ui/AbstractField.java

index ba67902fae2f8d8b64fae77b40e65e76deba20a6..3a66a01f231ac32ee758d184428b4470a6b5d3d7 100644 (file)
@@ -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;
+    }
+
 }
index 2a9ac4ff621ace2a940312677fd60996967372e8..cc357cf77280096d641fd2ded7969078ff4e31c3 100644 (file)
@@ -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();
     }
index 667c23bc77679a9e16fc8f68c591ced9bc70117b..77065f248c8ca111eec7ece12f530083cf438209 100644 (file)
@@ -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));
     }
index b2c7101c1594d9a82e4436fe349335cb56ade326..76f23c761a56a0a5a1e2c2fd3f57673c7b6860c0 100644 (file)
@@ -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.
      * 
index 05cd0466a9e8adebcd0442457275ae9c42babe4e..9a65513afd7abdbbda5818f637a4b43ee68fe812 100644 (file)
@@ -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 (file)
index 0000000..ab093f6
--- /dev/null
@@ -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 <i>tabulator index</i> of the field.
+     * 
+     * @return the tab index for the Field
+     */
+    public int getTabIndex();
+
+    /**
+     * Sets the <i>tabulator index</i> of the field.
+     * 
+     * @param tabIndex
+     *            the tab index to set
+     */
+    public void setTabIndex(int tabIndex);
+}
index 9f24bfb1d703f8e354c7679db5def98f224189c2..aecb07e108e28880e9e328e4b0b1b8369113464c 100644 (file)
@@ -99,11 +99,6 @@ public abstract class AbstractField<T> 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<T> 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<T> 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<T> 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<T> extends AbstractComponent implements
         if (valueWasModifiedByDataSourceDuringCommit) {
             valueWasModifiedByDataSourceDuringCommit = false;
             fireValueChange(false);
-        } else if (repaintNeeded) {
-            requestRepaint();
         }
 
     }
@@ -365,11 +337,12 @@ public abstract class AbstractField<T> 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<T> 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<T> extends AbstractComponent implements
      * @see com.vaadin.ui.Component.Focusable#setTabIndex(int)
      */
     public void setTabIndex(int tabIndex) {
-        this.tabIndex = tabIndex;
+        getState().setTabIndex(tabIndex);
         requestRepaint();
     }