package com.vaadin.terminal.gwt.client;
import com.vaadin.terminal.gwt.client.communication.SharedState;
+import com.vaadin.ui.Component;
/**
* Default shared state implementation for UI components.
private boolean readOnly = false;
private boolean immediate = false;
private String style = "";
- private boolean disabled = false;
+ private boolean enabled = true;
private String description = "";
// Note: for the caption, there is a difference between null and an empty
// string!
private String caption = null;
+ private boolean visible = true;
/**
* Returns the component height as set by the server.
}
/**
- * Returns true if the component is disabled.
+ * Returns true if the component is enabled.
*
* @see com.vaadin.ui.Component#isEnabled()
*
- * @return true if the component is disabled
+ * @return true if the component is enabled
*/
- public boolean isDisabled() {
- return disabled;
+ public boolean isEnabled() {
+ return enabled;
}
/**
- * Disables or enables the component.
+ * Enables or disables the component.
*
* @see com.vaadin.ui.Component#setEnabled(boolean)
*
- * @param disabled
+ * @param enabled
* new mode for the component
*/
- public void setDisabled(boolean disabled) {
- this.disabled = disabled;
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
}
/**
this.caption = caption;
}
+ /**
+ * Returns the visibility state of the component. Note that this state is
+ * related to the component only, not its parent. This might differ from
+ * what {@link Component#isVisible()} returns as this takes the hierarchy
+ * into account.
+ *
+ * @return The visibility state.
+ */
+ public boolean isVisible() {
+ return visible;
+ }
+
+ /**
+ * Sets the visibility state of the component.
+ *
+ * @param visible
+ * The new visibility state.
+ */
+ public void setVisible(boolean visible) {
+ this.visible = visible;
+ }
+
}
*/
private ArrayList<String> styles;
- /**
- * Caption text.
- */
- private String caption;
-
/**
* Application specific data object. The component does not use or modify
* this.
*/
private Resource icon;
- /**
- * Is the component enabled (its normal usage is allowed).
- */
- private boolean enabled = true;
-
- /**
- * Is the component visible (it is rendered).
- */
- private boolean visible = true;
-
- /**
- * Is the component read-only ?
- */
- private boolean readOnly = false;
-
- /**
- * Description of the usage (XML).
- */
- private String description = null;
-
/**
* The container this component resides in.
*/
*/
private ErrorMessage componentError = null;
- /**
- * Immediate mode: if true, all variable changes are required to be sent
- * from the terminal immediately.
- */
- private boolean immediate = false;
-
/**
* Locale of this component.
*/
* the default documentation from implemented interface.
*/
public String getCaption() {
- return caption;
+ return getState().getCaption();
}
/**
* the new caption <code>String</code> for the component.
*/
public void setCaption(String caption) {
- this.caption = caption;
+ getState().setCaption(caption);
requestRepaint();
}
* here, we use the default documentation from implemented interface.
*/
public boolean isEnabled() {
- return enabled && (parent == null || parent.isEnabled()) && isVisible();
+ return getState().isEnabled()
+ && (getParent() == null || getParent().isEnabled());
}
/*
* use the default documentation from implemented interface.
*/
public void setEnabled(boolean enabled) {
- if (this.enabled != enabled) {
- boolean wasEnabled = this.enabled;
- boolean wasEnabledInContext = isEnabled();
-
- this.enabled = enabled;
-
- boolean isEnabled = enabled;
- boolean isEnabledInContext = isEnabled();
-
- // If the actual enabled state (as rendered, in context) has not
- // changed we do not need to repaint except if the parent is
- // invisible.
- // If the parent is invisible we must request a repaint so the
- // component is repainted with the new enabled state when the parent
- // is set visible again. This workaround is needed as isEnabled
- // checks isVisible.
- boolean needRepaint = (wasEnabledInContext != isEnabledInContext)
- || (wasEnabled != isEnabled && (getParent() == null || !getParent()
- .isVisible()));
-
- if (needRepaint) {
- requestRepaint();
- }
+ if (getState().isEnabled() != enabled) {
+ getState().setEnabled(enabled);
+ requestRepaint();
}
}
* interface.
*/
public boolean isImmediate() {
- return immediate;
+ return getState().isImmediate();
}
/**
* @see Component#isImmediate()
*/
public void setImmediate(boolean immediate) {
- this.immediate = immediate;
+ getState().setImmediate(immediate);
requestRepaint();
}
* @see com.vaadin.ui.Component#isVisible()
*/
public boolean isVisible() {
- return visible && (getParent() == null || getParent().isVisible());
+ return getState().isVisible()
+ && (getParent() == null || getParent().isVisible());
}
/*
*/
public void setVisible(boolean visible) {
- if (this.visible != visible) {
- this.visible = visible;
+ if (getState().isVisible() != visible) {
+ getState().setVisible(visible);
// Instead of requesting repaint normally we
// fire the event directly to assure that the
// event goes through event in the component might
* @return component's description <code>String</code>
*/
public String getDescription() {
- return description;
+ return getState().getDescription();
}
/**
* the new description string for the component.
*/
public void setDescription(String description) {
- this.description = description;
+ getState().setDescription(description);
requestRepaint();
}
* here, we use the default documentation from implemented interface.
*/
public boolean isReadOnly() {
- return readOnly;
+ return getState().isReadOnly();
}
/*
* use the default documentation from implemented interface.
*/
public void setReadOnly(boolean readOnly) {
- this.readOnly = readOnly;
+ getState().setReadOnly(readOnly);
requestRepaint();
}
*/
public void attach() {
requestRepaint();
- if (!visible) {
+ if (!getState().isVisible()) {
/*
* Bypass the repaint optimization in childRequestedRepaint method
* when attaching. When reattaching (possibly moving) -> must
}
// basic state: caption, size, enabled, ...
- if (!isVisible()) {
- return null;
- }
-
- // TODO for now, this superclass always recreates the state from
- // scratch, whereas subclasses should only modify it
-
+ // TODO This logic should be on the client side and the state should
+ // simply be a data object with "width" and "height".
if (getHeight() >= 0
&& (getHeightUnits() != Unit.PERCENTAGE || ComponentSizeValidator
.parentCanDefineHeight(this))) {
sharedState.setWidth("");
}
- sharedState.setImmediate(isImmediate());
- sharedState.setReadOnly(isReadOnly());
- sharedState.setDisabled(!isEnabled());
-
+ // TODO This should be an array in state and the logic for converting
+ // array -> class name should be on the client side
sharedState.setStyle(getStyleName());
- sharedState.setCaption(getCaption());
- sharedState.setDescription(getDescription());
-
// TODO icon also in shared state - how to convert Resource?
return sharedState;
Collection<RepaintRequestListener> alreadyNotified) {
// Invisible components (by flag in this particular component) do not
// need repaints
- if (!visible) {
+ if (!getState().isVisible()) {
return;
}