summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-04-02 11:54:45 +0300
committerArtur Signell <artur@vaadin.com>2012-04-05 00:08:09 +0300
commit1c834dc864ca31f2c7020a7fc7345d7765def3fe (patch)
treef95c102aa0b70973ed3a6cd8e9968c50899191e1
parentc70ece28ea44c9e45b6ed8eff0c9c2fe8e0a797b (diff)
downloadvaadin-framework-1c834dc864ca31f2c7020a7fc7345d7765def3fe.tar.gz
vaadin-framework-1c834dc864ca31f2c7020a7fc7345d7765def3fe.zip
AbstractComponent.updateFromUIDL moved to state change (#8436)
-rw-r--r--src/com/vaadin/terminal/gwt/client/AbstractFieldState.java49
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java53
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java4
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/AbstractFieldConnector.java4
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/PopupDateFieldConnector.java4
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/TabIndexState.java26
-rw-r--r--src/com/vaadin/ui/AbstractField.java37
7 files changed, 117 insertions, 60 deletions
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 <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);
+}
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
@@ -100,11 +100,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.
*/
@@ -126,11 +121,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();
}