--- /dev/null
+package com.vaadin.terminal.gwt.client;
+
+import com.vaadin.ui.AbstractField;
+
+/**
+ * Shared state for {@link AbstractField}.
+ *
+ * @author Vaadin Ltd
+ * @version @VERSION@
+ * @since 7.0.0
+ *
+ */
+public class AbstractFieldState extends ComponentState {
+ private boolean propertyReadOnly = false;
+
+ /**
+ * Checks if the property data source for the Field is in read only mode.
+ * This affects the read only state of the field itself.
+ *
+ * @return true if there is a property data source and it is set to read
+ * only, false otherwise
+ */
+ public boolean isPropertyReadOnly() {
+ return propertyReadOnly;
+ }
+
+ /**
+ * Sets the read only state of the property data source.
+ *
+ * @param propertyReadOnly
+ * true if the property data source if read only, false otherwise
+ */
+ public void setPropertyReadOnly(boolean propertyReadOnly) {
+ this.propertyReadOnly = propertyReadOnly;
+ }
+
+}
* The new parent of the connector
*/
public void setParent(ComponentContainerConnector parent);
+
+ /**
+ * Checks if the connector is read only.
+ *
+ * @deprecated This belongs in AbstractFieldConnector, see #8514
+ * @return true
+ */
+ @Deprecated
+ public boolean isReadOnly();
}
style += " " + CLASSNAME + "-" + styles[i];
}
}
- if (!owner.getState().isEnabled()) {
+ if (!owner.isEnabled()) {
style += " " + ApplicationConnection.DISABLED_CLASSNAME;
}
setStyleName(style);
private Widget widget;
/* State variables */
- private boolean enabled = true;
private boolean visible = true;
// shared state from the server to the client
((Focusable) getWidget()).setTabIndex(uidl
.getIntAttribute("tabindex"));
}
- setEnabled(getState().isEnabled());
+
+ if (getWidget() instanceof FocusWidget) {
+ FocusWidget fw = (FocusWidget) getWidget();
+ fw.setEnabled(isEnabled());
+ }
// Style names
String styleName = getStyleNameFromUIDL(getWidget()
- .getStylePrimaryName(), uidl, getState(),
- getWidget() instanceof Field);
+ .getStylePrimaryName(), uidl, getWidget() instanceof Field,
+ this);
getWidget().setStyleName(styleName);
// Update tooltip
return declaredWidth;
}
- /**
- * Sets the enabled state of this paintable
+ /*
+ * (non-Javadoc)
*
- * @param enabled
- * true if the paintable is enabled, false otherwise
+ * @see com.vaadin.terminal.gwt.client.Connector#isEnabled()
*/
- protected void setEnabled(boolean enabled) {
- this.enabled = enabled;
-
- if (getWidget() instanceof FocusWidget) {
- FocusWidget fw = (FocusWidget) getWidget();
- fw.setEnabled(enabled);
+ public boolean isEnabled() {
+ if (!getState().isEnabled()) {
+ return false;
}
- }
-
- public boolean isEnabled() {
- return enabled;
+ if (getParent() == null) {
+ return true;
+ } else {
+ return getParent().isEnabled();
+ }
}
/**
* @return
*/
protected static String getStyleNameFromUIDL(String primaryStyleName,
- UIDL uidl, ComponentState state, boolean field) {
- boolean enabled = state.isEnabled();
+ UIDL uidl, boolean field, ComponentConnector connector) {
+ ComponentState state = connector.getState();
StringBuffer styleBuf = new StringBuffer();
styleBuf.append(primaryStyleName);
styleBuf.append(" v-paintable");
- // first disabling and read-only status
- if (!enabled) {
+ // Uses connector methods to enable connectors to take hierarchy or
+ // multiple state variables into account
+ if (!connector.isEnabled()) {
styleBuf.append(" ");
styleBuf.append(ApplicationConnection.DISABLED_CLASSNAME);
}
- if (state.isReadOnly()) {
+ if (connector.isReadOnly()) {
styleBuf.append(" ");
styleBuf.append("v-readonly");
}
}
}
+ // TODO Move to AbstractFieldConnector
// add modified classname to Fields
if (field && uidl.hasAttribute("modified")) {
styleBuf.append(" ");
return styleBuf.toString();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.terminal.gwt.client.ComponentConnector#isReadOnly()
+ */
+ @Deprecated
+ public boolean isReadOnly() {
+ return getState().isReadOnly();
+ }
+
/**
* Sets the shared state for the paintable widget.
*
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VConsole;
-public class AbstractDateFieldConnector extends AbstractComponentConnector {
+public class AbstractDateFieldConnector extends AbstractFieldConnector {
@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
getWidget().paintableId = uidl.getId();
getWidget().immediate = getState().isImmediate();
- getWidget().readonly = getState().isReadOnly();
- getWidget().enabled = getState().isEnabled();
+ getWidget().readonly = isReadOnly();
+ getWidget().enabled = isEnabled();
if (uidl.hasAttribute("locale")) {
final String locale = uidl.getStringAttribute("locale");
--- /dev/null
+package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.vaadin.terminal.gwt.client.AbstractFieldState;
+import com.vaadin.terminal.gwt.client.ComponentState;
+
+public abstract class AbstractFieldConnector extends AbstractComponentConnector {
+
+ @Override
+ public AbstractFieldState getState() {
+ return (AbstractFieldState) super.getState();
+ }
+
+ @Override
+ protected ComponentState createState() {
+ return GWT.create(AbstractFieldState.class);
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ return super.isReadOnly() || getState().isPropertyReadOnly();
+ }
+
+}
if (!isRealUpdate(uidl)) {
return;
}
- getWidget().setEnabled(getState().isEnabled());
+ getWidget().setEnabled(isEnabled());
clickEventHandler.handleEventHandlerRegistration(client);
if (getState().hasStyles()) {
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VTooltip;
-public class CheckBoxConnector extends AbstractComponentConnector {
+public class CheckBoxConnector extends AbstractFieldConnector {
@Override
protected boolean delegateCaptionHandling() {
"none");
}
- if (getState().isReadOnly()) {
+ if (isReadOnly()) {
getWidget().setEnabled(false);
}
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.ui.VFilterSelect.FilterSelectSuggestion;
-public class ComboBoxConnector extends AbstractComponentConnector implements
+public class ComboBoxConnector extends AbstractFieldConnector implements
SimpleManagedLayout {
/*
getWidget().client = client;
getWidget().paintableId = uidl.getId();
- getWidget().readonly = getState().isReadOnly();
- getWidget().enabled = getState().isEnabled();
+ getWidget().readonly = isReadOnly();
+ getWidget().enabled = isEnabled();
getWidget().tb.setEnabled(getWidget().enabled);
getWidget().updateReadOnly();
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.AbstractFieldState;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.ComponentConnector;
+import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.ConnectorMap;
import com.vaadin.terminal.gwt.client.UIDL;
form.footerContainer.getStyle().setMarginTop(-footerHeight, Unit.PX);
}
+ @Override
+ public boolean isReadOnly() {
+ return super.isReadOnly() || getState().isPropertyReadOnly();
+ }
+
+ @Override
+ public AbstractFieldState getState() {
+ return (AbstractFieldState) super.getState();
+ }
+
+ @Override
+ protected ComponentState createState() {
+ return GWT.create(AbstractFieldState.class);
+ }
+
}
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.ComponentConnector;
import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.ui.VFormLayout.Caption;
+import com.vaadin.terminal.gwt.client.ui.VFormLayout.ErrorFlag;
public class FormLayoutConnector extends AbstractComponentContainerConnector {
@Override
}
public void updateCaption(ComponentConnector component, UIDL uidl) {
- getWidget().table.updateCaption(component, uidl);
+ final Caption c = getWidget().table.widgetToCaption.get(component
+ .getWidget());
+ if (c != null) {
+ c.updateCaption(uidl, component.getState(), component.isEnabled());
+ }
+ final ErrorFlag e = getWidget().table.widgetToError.get(component
+ .getWidget());
+ if (e != null) {
+ e.updateFromUIDL(uidl, component);
+ }
}
@Override
getWidget().client = client;
- getWidget().enabled = getState().isEnabled();
- getWidget().readonly = getState().isReadOnly();
+ getWidget().enabled = isEnabled();
if (uidl.hasAttribute("name")) {
getWidget().target = uidl.getStringAttribute("name");
getWidget().openRootOnHover = uidl
.getBooleanAttribute(VMenuBar.OPEN_ROOT_MENU_ON_HOWER);
- getWidget().enabled = getState().isEnabled();
+ getWidget().enabled = isEnabled();
// For future connections
getWidget().client = client;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.UIDL;
-public abstract class OptionGroupBaseConnector extends
- AbstractComponentConnector {
+public abstract class OptionGroupBaseConnector extends AbstractFieldConnector {
@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
getWidget().selectedKeys = uidl.getStringArrayVariableAsSet("selected");
- getWidget().readonly = getState().isReadOnly();
- getWidget().disabled = !getState().isEnabled();
+ getWidget().readonly = isReadOnly();
+ getWidget().disabled = !isEnabled();
getWidget().multiselect = "multi".equals(uidl
.getStringAttribute("selectmode"));
getWidget().immediate = getState().isImmediate();
super.updateFromUIDL(uidl, client);
String popupStyleNames = getStyleNameFromUIDL(
- VPopupCalendar.POPUP_PRIMARY_STYLE_NAME, uidl, getState(),
- false);
+ VPopupCalendar.POPUP_PRIMARY_STYLE_NAME, uidl, false, this);
popupStyleNames += " "
+ VDateField.CLASSNAME
+ "-"
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.UIDL;
-public class ProgressIndicatorConnector extends AbstractComponentConnector {
+public class ProgressIndicatorConnector extends AbstractFieldConnector {
@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
if (getWidget().indeterminate) {
String basename = VProgressIndicator.CLASSNAME + "-indeterminate";
getWidget().addStyleName(basename);
- if (!getState().isEnabled()) {
+ if (!isEnabled()) {
getWidget().addStyleName(basename + "-disabled");
} else {
getWidget().removeStyleName(basename + "-disabled");
}
}
- if (getState().isEnabled()) {
+ if (isEnabled()) {
getWidget().interval = uidl.getIntAttribute("pollinginterval");
getWidget().poller.scheduleRepeating(getWidget().interval);
}
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.UIDL;
-public class SliderConnector extends AbstractComponentConnector {
+public class SliderConnector extends AbstractFieldConnector {
@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
}
getWidget().immediate = getState().isImmediate();
- getWidget().disabled = !getState().isEnabled();
- getWidget().readonly = getState().isReadOnly();
+ getWidget().disabled = !isEnabled();
+ getWidget().readonly = isReadOnly();
getWidget().vertical = uidl.hasAttribute("vertical");
import com.google.gwt.dom.client.Style.Position;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.AbstractFieldState;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.ComponentConnector;
+import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.DirectionalManagedLayout;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
return;
}
- getWidget().enabled = getState().isEnabled();
+ getWidget().enabled = isEnabled();
if (BrowserInfo.get().isIE8() && !getWidget().enabled) {
/*
getWidget().updateDragMode(uidl);
- getWidget().updateSelectionProperties(uidl, getState());
+ getWidget().updateSelectionProperties(uidl, getState(), isReadOnly());
if (uidl.hasAttribute("alb")) {
getWidget().bodyActionKeys = uidl.getStringArrayAttribute("alb");
public void postLayout() {
getWidget().sizeInit();
}
+
+ @Override
+ public boolean isReadOnly() {
+ return super.isReadOnly() || getState().isPropertyReadOnly();
+ }
+
+ @Override
+ public AbstractFieldState getState() {
+ return (AbstractFieldState) super.getState();
+ }
+
+ @Override
+ protected ComponentState createState() {
+ return GWT.create(AbstractFieldState.class);
+ }
+
}
// Update member references
getWidget().id = uidl.getId();
- getWidget().disabled = !getState().isEnabled();
+ getWidget().disabled = !isEnabled();
// Render content
final UIDL tabs = uidl.getChildUIDL(0);
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutActionListener;
-public class TextFieldConnector extends AbstractComponentConnector implements
+public class TextFieldConnector extends AbstractFieldConnector implements
BeforeShortcutActionListener {
@Override
return;
}
- getWidget().setReadOnly(getState().isReadOnly());
+ getWidget().setReadOnly(isReadOnly());
getWidget().inputPrompt = uidl
.getStringAttribute(VTextField.ATTR_INPUTPROMPT);
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.AbstractFieldState;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.TooltipInfo;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.ui.VTree.TreeNode;
getWidget().immediate = getState().isImmediate();
- getWidget().disabled = !getState().isEnabled();
- getWidget().readonly = getState().isReadOnly();
+ getWidget().disabled = !isEnabled();
+ getWidget().readonly = isReadOnly();
getWidget().dragMode = uidl.hasAttribute("dragMode") ? uidl
.getIntAttribute("dragMode") : 0;
}
containerNode.childrenLoaded = true;
}
+
+ @Override
+ public boolean isReadOnly() {
+ return super.isReadOnly() || getState().isPropertyReadOnly();
+ }
+
+ @Override
+ public AbstractFieldState getState() {
+ return (AbstractFieldState) super.getState();
+ }
+
+ @Override
+ protected ComponentState createState() {
+ return GWT.create(AbstractFieldState.class);
+ }
+
}
}
getWidget().fu.setName(getWidget().paintableId + "_file");
- if (!getState().isEnabled() || getState().isReadOnly()) {
+ if (!isEnabled() || isReadOnly()) {
getWidget().disableUpload();
} else if (!uidl.getBooleanAttribute("state")) {
// Enable the button only if an upload is not in progress
*
* @param state
* shared state of the component
+ * @param enabled
* @return An array of stylenames
*/
- private String[] getStylesFromState(ComponentState state) {
+ private String[] getStylesFromState(ComponentState state, boolean enabled) {
List<String> styles = new ArrayList<String>();
if (state.hasStyles()) {
String[] stylesnames = state.getStyle().split(" ");
}
}
- if (!state.isEnabled()) {
+ if (!enabled) {
styles.add(ApplicationConnection.DISABLED_CLASSNAME);
}
private static final int COLUMN_ERRORFLAG = 1;
private static final int COLUMN_WIDGET = 2;
- private HashMap<Widget, Caption> widgetToCaption = new HashMap<Widget, Caption>();
- private HashMap<Widget, ErrorFlag> widgetToError = new HashMap<Widget, ErrorFlag>();
+ HashMap<Widget, Caption> widgetToCaption = new HashMap<Widget, Caption>();
+ HashMap<Widget, ErrorFlag> widgetToError = new HashMap<Widget, ErrorFlag>();
public VFormLayoutTable() {
DOM.setElementProperty(getElement(), "cellPadding", "0");
}
}
- public void updateCaption(ComponentConnector paintable, UIDL uidl) {
- final Caption c = widgetToCaption.get(paintable.getWidget());
- if (c != null) {
- c.updateCaption(uidl, paintable.getState());
- }
- final ErrorFlag e = widgetToError.get(paintable.getWidget());
- if (e != null) {
- e.updateFromUIDL(uidl, paintable);
- }
-
- }
-
/*
* (non-Javadoc)
*
setStyleName(styleName);
}
- public void updateCaption(UIDL uidl, ComponentState state) {
+ public void updateCaption(UIDL uidl, ComponentState state,
+ boolean enabled) {
setVisible(!uidl.getBooleanAttribute("invisible"));
// Update styles as they might have changed when the caption changed
- setStyles(getStylesFromState(state));
+ setStyles(getStylesFromState(state, enabled));
boolean isEmpty = true;
}
}
- private class ErrorFlag extends HTML {
+ class ErrorFlag extends HTML {
private static final String CLASSNAME = VFormLayout.CLASSNAME
+ "-error-indicator";
Element errorIndicatorElement;
protected boolean enabled;
- protected boolean readonly;
-
protected int targetWidth;
protected int targetHeight;
}
public void onClick(ClickEvent event) {
- if (enabled && !readonly) {
+ if (enabled) {
if (target == null) {
target = "_self";
}
}
}
- void updateSelectionProperties(UIDL uidl, ComponentState state) {
+ void updateSelectionProperties(UIDL uidl, ComponentState state,
+ boolean readOnly) {
setMultiSelectMode(uidl.hasAttribute("multiselectmode") ? uidl
.getIntAttribute("multiselectmode") : MULTISELECT_MODE_DEFAULT);
.getBooleanAttribute("nsa") : true;
if (uidl.hasAttribute("selectmode")) {
- if (state.isReadOnly()) {
+ if (readOnly) {
selectMode = SelectMode.NONE;
} else if (uidl.getStringAttribute("selectmode").equals("multi")) {
selectMode = SelectMode.MULTI;
getWidget().immediate = getState().isImmediate();
- getWidget().setClosable(!getState().isReadOnly());
+ getWidget().setClosable(!isReadOnly());
// Initialize the position form UIDL
int positionx = uidl.getIntVariable("positionx");
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.UIDL;
-import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector;
+import com.vaadin.terminal.gwt.client.ui.AbstractFieldConnector;
import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutActionListener;
-public class RichTextAreaConnector extends AbstractComponentConnector implements
+public class RichTextAreaConnector extends AbstractFieldConnector implements
BeforeShortcutActionListener {
@Override
}
}
if (isRealUpdate(uidl)) {
- getWidget().setEnabled(getState().isEnabled());
+ getWidget().setEnabled(isEnabled());
}
super.updateFromUIDL(uidl, client);
return;
}
- getWidget().setReadOnly(getState().isReadOnly());
+ getWidget().setReadOnly(isReadOnly());
getWidget().immediate = getState().isImmediate();
int newMaxLength = uidl.hasAttribute("maxLength") ? uidl
.getIntAttribute("maxLength") : -1;
import com.vaadin.terminal.ErrorMessage;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
+import com.vaadin.terminal.gwt.client.AbstractFieldState;
import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector;
/**
// Sets the new data source
dataSource = newDataSource;
+ getState().setPropertyReadOnly(
+ dataSource == null ? false : dataSource.isReadOnly());
// Check if the current converter is compatible.
if (newDataSource != null
* @see Property.ReadOnlyStatusChangeListener
*/
public void readOnlyStatusChange(Property.ReadOnlyStatusChangeEvent event) {
+ getState().setPropertyReadOnly(event.getProperty().isReadOnly());
requestRepaint();
}
requestRepaint();
}
+ @Override
+ public AbstractFieldState getState() {
+ return (AbstractFieldState) super.getState();
+ }
+
+ @Override
+ protected AbstractFieldState createState() {
+ return new AbstractFieldState();
+ }
}