123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382 |
- /*
- @VaadinApache2LicenseForJavaFiles@
- */
-
- package com.vaadin.shared;
-
- import java.util.HashSet;
- import java.util.List;
- import java.util.Set;
-
- import com.vaadin.shared.communication.SharedState;
- import com.vaadin.shared.communication.URLReference;
- import com.vaadin.ui.Component;
-
- /**
- * Default shared state implementation for UI components.
- *
- * State classes of concrete components should extend this class.
- *
- * @since 7.0
- */
- public class ComponentState extends SharedState {
- private String height = "";
- private String width = "";
- private boolean readOnly = false;
- private boolean immediate = false;
- 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;
- private URLReference icon = null;
- private List<String> styles = null;
- private String debugId = null;
- /**
- * A set of event identifiers with registered listeners.
- */
- private Set<String> registeredEventListeners = null;
-
- // HTML formatted error message for the component
- // TODO this could be an object with more information, but currently the UI
- // only uses the message
- private String errorMessage = null;
-
- /**
- * Returns the component height as set by the server.
- *
- * Can be relative (containing the percent sign) or absolute, or empty
- * string for undefined height.
- *
- * @return component height as defined by the server, not null
- */
- public String getHeight() {
- if (height == null) {
- return "";
- }
- return height;
- }
-
- /**
- * Sets the height of the component in the server format.
- *
- * Can be relative (containing the percent sign) or absolute, or null or
- * empty string for undefined height.
- *
- * @param height
- * component height
- */
- public void setHeight(String height) {
- this.height = height;
- }
-
- /**
- * Returns true if the component height is undefined, false if defined
- * (absolute or relative).
- *
- * @return true if component height is undefined
- */
- public boolean isUndefinedHeight() {
- return "".equals(getHeight());
- }
-
- /**
- * Returns the component width as set by the server.
- *
- * Can be relative (containing the percent sign) or absolute, or empty
- * string for undefined height.
- *
- * @return component width as defined by the server, not null
- */
- public String getWidth() {
- if (width == null) {
- return "";
- }
- return width;
- }
-
- /**
- * Sets the width of the component in the server format.
- *
- * Can be relative (containing the percent sign) or absolute, or null or
- * empty string for undefined width.
- *
- * @param width
- * component width
- */
- public void setWidth(String width) {
- this.width = width;
- }
-
- /**
- * Returns true if the component width is undefined, false if defined
- * (absolute or relative).
- *
- * @return true if component width is undefined
- */
- public boolean isUndefinedWidth() {
- return "".equals(getWidth());
- }
-
- /**
- * Returns true if the component is in read-only mode.
- *
- * @see com.vaadin.ui.Component#isReadOnly()
- *
- * @return true if the component is in read-only mode
- */
- public boolean isReadOnly() {
- return readOnly;
- }
-
- /**
- * Sets or resets the read-only mode for a component.
- *
- * @see com.vaadin.ui.Component#setReadOnly()
- *
- * @param readOnly
- * new mode for the component
- */
- public void setReadOnly(boolean readOnly) {
- this.readOnly = readOnly;
- }
-
- /**
- * Returns true if the component is in immediate mode.
- *
- * @see com.vaadin.terminal.VariableOwner#isImmediate()
- *
- * @return true if the component is in immediate mode
- */
- public boolean isImmediate() {
- return immediate;
- }
-
- /**
- * Sets or resets the immediate mode for a component.
- *
- * @see com.vaadin.terminal.VariableOwner#setImmediate()
- *
- * @param immediate
- * new mode for the component
- */
- public void setImmediate(boolean immediate) {
- this.immediate = immediate;
- }
-
- /**
- * Returns true if the component has user-defined styles.
- *
- * @return true if the component has user-defined styles
- */
- public boolean hasStyles() {
- return styles != null && !styles.isEmpty();
- }
-
- /**
- * Gets the description of the component (typically shown as tooltip).
- *
- * @see com.vaadin.ui.AbstractComponent#getDescription()
- *
- * @return component description (not null, can be empty string)
- */
- public String getDescription() {
- return description;
- }
-
- /**
- * Sets the description of the component (typically shown as tooltip).
- *
- * @see com.vaadin.ui.AbstractComponent#setDescription(String)
- *
- * @param description
- * new component description (can be null)
- */
- public void setDescription(String description) {
- this.description = description;
- }
-
- /**
- * Returns true if the component has a description.
- *
- * @return true if the component has a description
- */
- public boolean hasDescription() {
- return getDescription() != null && !"".equals(getDescription());
- }
-
- /**
- * Gets the caption of the component (typically shown by the containing
- * layout).
- *
- * @see com.vaadin.ui.Component#getCaption()
- *
- * @return component caption - can be null (no caption) or empty string
- * (reserve space for an empty caption)
- */
- public String getCaption() {
- return caption;
- }
-
- /**
- * Sets the caption of the component (typically shown by the containing
- * layout).
- *
- * @see com.vaadin.ui.Component#setCaption(String)
- *
- * @param caption
- * new component caption - can be null (no caption) or empty
- * string (reserve space for an empty caption)
- */
- public void setCaption(String caption) {
- 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;
- }
-
- public URLReference getIcon() {
- return icon;
- }
-
- public void setIcon(URLReference icon) {
- this.icon = icon;
- }
-
- /**
- * Gets the style names for the component.
- *
- * @return A List of style names or null if no styles have been set.
- */
- public List<String> getStyles() {
- return styles;
- }
-
- /**
- * Sets the style names for the component.
- *
- * @param styles
- * A list containing style names
- */
- public void setStyles(List<String> styles) {
- this.styles = styles;
- }
-
- /**
- * Gets the debug id for the component. The debugId is added as DOM id for
- * the component.
- *
- * @return The debug id for the component or null if not set
- */
- public String getDebugId() {
- return debugId;
- }
-
- /**
- * Sets the debug id for the component. The debugId is added as DOM id for
- * the component.
- *
- * @param debugId
- * The new debugId for the component or null for no debug id
- *
- */
- public void setDebugId(String debugId) {
- this.debugId = debugId;
- }
-
- /**
- * Gets the identifiers for the event listeners that have been registered
- * for the component (using an event id)
- *
- * @return A set of event identifiers or null if no identifiers have been
- * registered
- */
- public Set<String> getRegisteredEventListeners() {
- return registeredEventListeners;
- }
-
- /**
- * Sets the identifiers for the event listeners that have been registered
- * for the component (using an event id)
- *
- * @param registeredEventListeners
- * The new set of identifiers or null if no identifiers have been
- * registered
- */
- public void setRegisteredEventListeners(Set<String> registeredEventListeners) {
- this.registeredEventListeners = registeredEventListeners;
- }
-
- /**
- * Adds an event listener id.
- *
- * @param eventListenerId
- * The event identifier to add
- */
- public void addRegisteredEventListener(String eventListenerId) {
- if (registeredEventListeners == null) {
- registeredEventListeners = new HashSet<String>();
- }
- registeredEventListeners.add(eventListenerId);
-
- }
-
- /**
- * Removes an event listener id.
- *
- * @param eventListenerId
- * The event identifier to remove
- */
- public void removeRegisteredEventListener(String eventIdentifier) {
- if (registeredEventListeners == null) {
- return;
- }
- registeredEventListeners.remove(eventIdentifier);
- if (registeredEventListeners.size() == 0) {
- registeredEventListeners = null;
- }
- }
-
- /**
- * Returns the current error message for the component.
- *
- * @return HTML formatted error message to show for the component or null if
- * none
- */
- public String getErrorMessage() {
- return errorMessage;
- }
-
- /**
- * Sets the current error message for the component.
- *
- * TODO this could use an object with more details about the error
- *
- * @param errorMessage
- * HTML formatted error message to show for the component or null
- * for none
- */
- public void setErrorMessage(String errorMessage) {
- this.errorMessage = errorMessage;
- }
-
- }
|