public class ComponentState extends SharedState {
private String height = "";
private String width = "";
+ private boolean readOnly = false;
+ private boolean immediate = false;
/**
* Returns the component height as set by the server.
return "".equals(getWidth());
}
- // TODO more fields to move here: style, readonly, immediate, disabled,
- // caption and description
+ public boolean isReadOnly() {
+ return readOnly;
+ }
+
+ public void setReadOnly(boolean readOnly) {
+ this.readOnly = readOnly;
+ }
+
+ public boolean isImmediate() {
+ return immediate;
+ }
+
+ public void setImmediate(boolean immediate) {
+ this.immediate = immediate;
+ }
+
+ // TODO more fields to move here: style, disabled, caption and description
}
public static final String ATTRIBUTE_REQUIRED = "required";
public static final String ATTRIBUTE_ERROR = "error";
public static final String ATTRIBUTE_HIDEERRORS = "hideErrors";
- public static final String ATTRIBUTE_READONLY = "readonly";
- public static final String ATTRIBUTE_IMMEDIATE = "immediate";
public static final String ATTRIBUTE_DISABLED = "disabled";
public static final String ATTRIBUTE_STYLE = "style";
// Style names
String styleName = getStyleNameFromUIDL(getWidgetForPaintable()
- .getStylePrimaryName(), uidl,
+ .getStylePrimaryName(), uidl, getState(),
getWidgetForPaintable() instanceof Field);
getWidgetForPaintable().setStyleName(styleName);
/**
* Generates the style name for the widget based on the given primary style
- * name (typically returned by Widget.getPrimaryStyleName()) and the UIDL.
- * An additional "modified" style name can be added if the field parameter
- * is set to true.
+ * name (typically returned by Widget.getPrimaryStyleName()) and the UIDL
+ * and shared state of the component. An additional "modified" style name
+ * can be added if the field parameter is set to true.
*
* @param primaryStyleName
* @param uidl
- * @param isField
+ * @param state
+ * component shared state
+ * @param field
* @return
*/
protected static String getStyleNameFromUIDL(String primaryStyleName,
- UIDL uidl, boolean field) {
+ UIDL uidl, ComponentState state, boolean field) {
boolean enabled = !uidl.getBooleanAttribute(ATTRIBUTE_DISABLED);
StringBuffer styleBuf = new StringBuffer();
styleBuf.append(" ");
styleBuf.append(ApplicationConnection.DISABLED_CLASSNAME);
}
- if (uidl.getBooleanAttribute(ATTRIBUTE_READONLY)) {
+ if (state.isReadOnly()) {
styleBuf.append(" ");
styleBuf.append("v-readonly");
}
getWidgetForPaintable().id = uidl.getId();
getWidgetForPaintable().rendering = true;
- getWidgetForPaintable().immediate = uidl
- .hasAttribute(ATTRIBUTE_IMMEDIATE);
+ getWidgetForPaintable().immediate = getState().isImmediate();
super.updateFromUIDL(uidl, client);
if (!isRealUpdate(uidl)) {
"none");
}
- if (uidl.hasAttribute(ATTRIBUTE_READONLY)) {
+ if (getState().isReadOnly()) {
getWidgetForPaintable().setEnabled(false);
}
getWidgetForPaintable()
.setValue(
uidl.getBooleanVariable(getWidgetForPaintable().VARIABLE_STATE));
- getWidgetForPaintable().immediate = uidl
- .getBooleanAttribute(VAbstractPaintableWidget.ATTRIBUTE_IMMEDIATE);
+ getWidgetForPaintable().immediate = getState().isImmediate();
}
@Override
// Save details
getWidgetForPaintable().client = client;
getWidgetForPaintable().paintableId = uidl.getId();
- getWidgetForPaintable().immediate = uidl
- .getBooleanAttribute(ATTRIBUTE_IMMEDIATE);
+ getWidgetForPaintable().immediate = getState().isImmediate();
- getWidgetForPaintable().readonly = uidl
- .getBooleanAttribute(ATTRIBUTE_READONLY);
+ getWidgetForPaintable().readonly = getState().isReadOnly();
getWidgetForPaintable().enabled = !uidl
.getBooleanAttribute(ATTRIBUTE_DISABLED);
getWidgetForPaintable().client = client;
getWidgetForPaintable().paintableId = uidl.getId();
- getWidgetForPaintable().readonly = uidl
- .hasAttribute(ATTRIBUTE_READONLY);
+ getWidgetForPaintable().readonly = getState().isReadOnly();
getWidgetForPaintable().enabled = !uidl
.hasAttribute(ATTRIBUTE_DISABLED);
.getIntAttribute("filteringmode");
}
- getWidgetForPaintable().immediate = uidl
- .hasAttribute(ATTRIBUTE_IMMEDIATE);
+ getWidgetForPaintable().immediate = getState().isImmediate();
getWidgetForPaintable().nullSelectionAllowed = uidl
.hasAttribute("nullselect");
getWidgetForPaintable().enabled = uidl.hasAttribute(ATTRIBUTE_DISABLED) ? false
: true;
- getWidgetForPaintable().readonly = uidl
- .hasAttribute(ATTRIBUTE_READONLY) ? true : false;
+ getWidgetForPaintable().readonly = getState().isReadOnly();
if (uidl.hasAttribute("name")) {
getWidgetForPaintable().target = uidl.getStringAttribute("name");
getWidgetForPaintable().selectedKeys = uidl
.getStringArrayVariableAsSet("selected");
- getWidgetForPaintable().readonly = uidl
- .getBooleanAttribute(ATTRIBUTE_READONLY);
+ getWidgetForPaintable().readonly = getState().isReadOnly();
getWidgetForPaintable().disabled = uidl
.getBooleanAttribute(ATTRIBUTE_DISABLED);
getWidgetForPaintable().multiselect = "multi".equals(uidl
.getStringAttribute("selectmode"));
- getWidgetForPaintable().immediate = uidl
- .getBooleanAttribute(ATTRIBUTE_IMMEDIATE);
+ getWidgetForPaintable().immediate = getState().isImmediate();
getWidgetForPaintable().nullSelectionAllowed = uidl
.getBooleanAttribute("nullselect");
getWidgetForPaintable().nullSelectionItemAvailable = uidl
super.updateFromUIDL(uidl, client);
String popupStyleNames = getStyleNameFromUIDL(
- VPopupCalendar.POPUP_PRIMARY_STYLE_NAME, uidl, false);
+ VPopupCalendar.POPUP_PRIMARY_STYLE_NAME, uidl, getState(),
+ false);
popupStyleNames += " "
+ VDateField.CLASSNAME
+ "-"
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
+import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.Container;
import com.vaadin.terminal.gwt.client.Focusable;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
}
}
- void updateSelectionProperties(UIDL uidl) {
+ void updateSelectionProperties(UIDL uidl, ComponentState state) {
setMultiSelectMode(uidl.hasAttribute("multiselectmode") ? uidl
.getIntAttribute("multiselectmode") : MULTISELECT_MODE_DEFAULT);
.getBooleanAttribute("nsa") : true;
if (uidl.hasAttribute("selectmode")) {
- if (uidl.getBooleanAttribute(VAbstractPaintableWidget.ATTRIBUTE_READONLY)) {
+ if (state.isReadOnly()) {
selectMode = SelectMode.NONE;
} else if (uidl.getStringAttribute("selectmode").equals("multi")) {
selectMode = SelectMode.MULTI;
getWidgetForPaintable().client = client;
getWidgetForPaintable().paintableId = uidl.getStringAttribute("id");
- getWidgetForPaintable().immediate = uidl
- .getBooleanAttribute(ATTRIBUTE_IMMEDIATE);
+ getWidgetForPaintable().immediate = getState().isImmediate();
int previousTotalRows = getWidgetForPaintable().totalRows;
getWidgetForPaintable().updateTotalRows(uidl);
getWidgetForPaintable().updateDragMode(uidl);
- getWidgetForPaintable().updateSelectionProperties(uidl);
+ getWidgetForPaintable().updateSelectionProperties(uidl, getState());
if (uidl.hasAttribute("alb")) {
getWidgetForPaintable().bodyActionKeys = uidl
return;
}
- getWidgetForPaintable().immediate = uidl
- .getBooleanAttribute(ATTRIBUTE_IMMEDIATE);
+ getWidgetForPaintable().immediate = getState().isImmediate();
getWidgetForPaintable().disabled = uidl
.getBooleanAttribute(ATTRIBUTE_DISABLED);
- getWidgetForPaintable().readonly = uidl
- .getBooleanAttribute(ATTRIBUTE_READONLY);
+ getWidgetForPaintable().readonly = getState().isReadOnly();
getWidgetForPaintable().vertical = uidl.hasAttribute("vertical");
+ // TODO should these style names be used?
String style = "";
if (uidl.hasAttribute(ATTRIBUTE_STYLE)) {
style = uidl.getStringAttribute(ATTRIBUTE_STYLE);
return;
}
- if (uidl.getBooleanAttribute(ATTRIBUTE_READONLY)) {
- getWidgetForPaintable().setReadOnly(true);
- } else {
- getWidgetForPaintable().setReadOnly(false);
- }
+ getWidgetForPaintable().setReadOnly(getState().isReadOnly());
getWidgetForPaintable().inputPrompt = uidl
.getStringAttribute(VTextField.ATTR_INPUTPROMPT);
uidl.hasAttribute("maxLength") ? uidl
.getIntAttribute("maxLength") : -1);
- getWidgetForPaintable().immediate = uidl
- .getBooleanAttribute(ATTRIBUTE_IMMEDIATE);
+ getWidgetForPaintable().immediate = getState().isImmediate();
getWidgetForPaintable().listenTextChangeEvents = client
.hasEventListeners(this, "ie");
getWidgetForPaintable().paintableId = uidl.getId();
- getWidgetForPaintable().immediate = uidl
- .hasAttribute(ATTRIBUTE_IMMEDIATE);
+ getWidgetForPaintable().immediate = getState().isImmediate();
getWidgetForPaintable().disabled = uidl
.getBooleanAttribute(ATTRIBUTE_DISABLED);
- getWidgetForPaintable().readonly = uidl
- .getBooleanAttribute(ATTRIBUTE_READONLY);
+ getWidgetForPaintable().readonly = getState().isReadOnly();
getWidgetForPaintable().dragMode = uidl.hasAttribute("dragMode") ? uidl
.getIntAttribute("dragMode") : 0;
getWidgetForPaintable().submit();
return;
}
- getWidgetForPaintable().setImmediate(
- uidl.getBooleanAttribute(ATTRIBUTE_IMMEDIATE));
+ getWidgetForPaintable().setImmediate(getState().isImmediate());
getWidgetForPaintable().client = client;
getWidgetForPaintable().paintableId = uidl.getId();
getWidgetForPaintable().nextUploadId = uidl.getIntAttribute("nextid");
getWidgetForPaintable().fu.setName(getWidgetForPaintable().paintableId
+ "_file");
- if (uidl.hasAttribute(ATTRIBUTE_DISABLED)
- || uidl.hasAttribute(ATTRIBUTE_READONLY)) {
+ if (uidl.hasAttribute(ATTRIBUTE_DISABLED) || getState().isReadOnly()) {
getWidgetForPaintable().disableUpload();
} else if (!uidl.getBooleanAttribute("state")) {
// Enable the button only if an upload is not in progress
boolean firstPaint = getWidgetForPaintable().connection == null;
getWidgetForPaintable().connection = client;
- getWidgetForPaintable().immediate = uidl
- .hasAttribute(ATTRIBUTE_IMMEDIATE);
+ getWidgetForPaintable().immediate = getState().isImmediate();
getWidgetForPaintable().resizeLazy = uidl
.hasAttribute(VView.RESIZE_LAZY);
String newTheme = uidl.getStringAttribute("theme");
clickEventHandler.handleEventHandlerRegistration(client);
- getWidgetForPaintable().immediate = uidl
- .hasAttribute(ATTRIBUTE_IMMEDIATE);
+ getWidgetForPaintable().immediate = getState().isImmediate();
- getWidgetForPaintable().setClosable(
- !uidl.getBooleanAttribute(ATTRIBUTE_READONLY));
+ getWidgetForPaintable().setClosable(!getState().isReadOnly());
// Initialize the position form UIDL
int positionx = uidl.getIntVariable("positionx");
return;
}
- getWidgetForPaintable().setReadOnly(
- uidl.getBooleanAttribute(ATTRIBUTE_READONLY));
- getWidgetForPaintable().immediate = uidl
- .getBooleanAttribute(ATTRIBUTE_IMMEDIATE);
+ getWidgetForPaintable().setReadOnly(getState().isReadOnly());
+ getWidgetForPaintable().immediate = getState().isImmediate();
int newMaxLength = uidl.hasAttribute("maxLength") ? uidl
.getIntAttribute("maxLength") : -1;
if (newMaxLength >= 0) {
VAbstractPaintableWidget.ATTRIBUTE_STYLE,
getStyle());
}
- if (isReadOnly()) {
- target.addAttribute(
- VAbstractPaintableWidget.ATTRIBUTE_READONLY, true);
- }
-
- if (isImmediate()) {
- target.addAttribute(
- VAbstractPaintableWidget.ATTRIBUTE_IMMEDIATE, true);
- }
if (!isEnabled()) {
target.addAttribute(
VAbstractPaintableWidget.ATTRIBUTE_DISABLED, true);
sharedState.setWidth("" + getCSSWidth());
}
+ sharedState.setImmediate(isImmediate());
+ sharedState.setReadOnly(isReadOnly());
+
// if (getCaption() != null) {
// state.put(ComponentState.STATE_CAPTION, getCaption());
// }
// if (styles != null && styles.size() > 0) {
// state.put(ComponentState.STATE_STYLE, getStyle());
// }
- // if (isReadOnly()) {
- // state.put(ComponentState.STATE_READONLY, true);
- // }
- //
- // if (isImmediate()) {
- // state.put(ComponentState.STATE_IMMEDIATE, true);
- // }
// if (!isEnabled()) {
// state.put(ComponentState.STATE_DISABLED, true);
// }