@@ -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; | |||
} | |||
} |
@@ -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(); | |||
} |
@@ -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)); | |||
} |
@@ -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. | |||
* |
@@ -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 | |||
+ "-" |
@@ -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); | |||
} |
@@ -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(); | |||
} | |||