*/
package com.vaadin.terminal.gwt.client;
+import com.vaadin.terminal.gwt.client.ui.TabIndexState;
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.
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;
+ }
+
}
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 {
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());
* 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) {
}
// Style names
- String styleName = getStyleNameFromUIDL(getWidget()
- .getStylePrimaryName(), uidl, getWidget() instanceof Field,
+ String styleName = getStyleNames(getWidget().getStylePrimaryName(),
this);
getWidget().setStyleName(styleName);
updateComponentSize();
}
+ @Deprecated
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ // TODO Remove this method
+ }
+
private void updateComponentSize() {
String newWidth = getState().getWidth();
String newHeight = getState().getHeight();
* @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();
}
}
- // 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
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();
}
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;
.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));
}
return super.isReadOnly() || getState().isPropertyReadOnly();
}
+ public boolean isModified() {
+ return getState().isModified();
+ }
+
/**
* Checks whether the required indicator should be shown for the field.
*
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
+ "-"
--- /dev/null
+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);
+}
*/
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.
*/
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.
* 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
}
}
- 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
if (valueWasModifiedByDataSourceDuringCommit) {
valueWasModifiedByDataSourceDuringCommit = false;
fireValueChange(false);
- } else if (repaintNeeded) {
- requestRepaint();
}
}
* interface.
*/
public boolean isModified() {
- return modified;
+ return getState().isModified();
}
private void setModified(boolean modified) {
- this.modified = modified;
+ getState().setModified(modified);
+ requestRepaint();
}
/*
* @see com.vaadin.ui.Component.Focusable#getTabIndex()
*/
public int getTabIndex() {
- return tabIndex;
+ return getState().getTabIndex();
}
/*
* @see com.vaadin.ui.Component.Focusable#setTabIndex(int)
*/
public void setTabIndex(int tabIndex) {
- this.tabIndex = tabIndex;
+ getState().setTabIndex(tabIndex);
requestRepaint();
}