summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-05-04 00:33:09 +0300
committerArtur Signell <artur@vaadin.com>2012-05-11 22:18:29 +0300
commitd78656c8d59c3b27bcf1ecb0d008a033b794beb1 (patch)
tree94edc5190750c854c398dc2d59543542dc58dfa0 /src/com/vaadin
parent43794ef1b830047e6a5d8270efb86abde56c0e0c (diff)
downloadvaadin-framework-d78656c8d59c3b27bcf1ecb0d008a033b794beb1.tar.gz
vaadin-framework-d78656c8d59c3b27bcf1ecb0d008a033b794beb1.zip
Updated Label to use shared state
Diffstat (limited to 'src/com/vaadin')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/label/ContentMode.java46
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/label/LabelConnector.java62
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/label/LabelState.java25
-rw-r--r--src/com/vaadin/ui/Label.java175
4 files changed, 126 insertions, 182 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/label/ContentMode.java b/src/com/vaadin/terminal/gwt/client/ui/label/ContentMode.java
new file mode 100644
index 0000000000..44fd1b7683
--- /dev/null
+++ b/src/com/vaadin/terminal/gwt/client/ui/label/ContentMode.java
@@ -0,0 +1,46 @@
+package com.vaadin.terminal.gwt.client.ui.label;
+
+
+/**
+ * Content modes defining how the client should interpret a Label's value.
+ *
+ * @sine 7.0
+ */
+public enum ContentMode {
+ /**
+ * Content mode, where the label contains only plain text. The getValue()
+ * result is coded to XML when painting.
+ */
+ TEXT,
+
+ /**
+ * Content mode, where the label contains preformatted text.
+ */
+ PREFORMATTED,
+
+ /**
+ * Content mode, where the label contains XHTML.
+ */
+ XHTML,
+
+ /**
+ * Content mode, where the label contains well-formed or well-balanced XML.
+ * Each of the root elements must have their default namespace specified.
+ *
+ * @deprecated Use {@link #XHTML}
+ */
+ @Deprecated
+ XML,
+
+ /**
+ * Content mode, where the label contains RAW output. Output is not required
+ * to comply to with XML. In Web Adapter output is inserted inside the
+ * resulting HTML document as-is. This is useful for some specific purposes
+ * where possibly broken HTML content needs to be shown, but in most cases
+ * XHTML mode should be preferred.
+ *
+ * @deprecated Use {@link #XHTML}, {@link #TEXT} or {@link #PREFORMATTED}.
+ */
+ @Deprecated
+ RAW;
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/label/LabelConnector.java b/src/com/vaadin/terminal/gwt/client/ui/label/LabelConnector.java
index 308a4860b5..2285fca267 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/label/LabelConnector.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/label/LabelConnector.java
@@ -7,54 +7,54 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.PreElement;
import com.google.gwt.user.client.ui.Widget;
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.Paintable;
-import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
+import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector;
import com.vaadin.terminal.gwt.client.ui.Connect;
import com.vaadin.terminal.gwt.client.ui.Connect.LoadStyle;
import com.vaadin.ui.Label;
@Connect(value = Label.class, loadStyle = LoadStyle.EAGER)
-public class LabelConnector extends AbstractComponentConnector implements
- Paintable {
+public class LabelConnector extends AbstractComponentConnector {
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- getWidget().setConnection(client);
- if (!isRealUpdate(uidl)) {
- return;
- }
+ public LabelState getState() {
+ return (LabelState) super.getState();
+ }
- boolean sinkOnloads = false;
+ @Override
+ protected void init() {
+ super.init();
+ getWidget().setConnection(getConnection());
+ }
- final String mode = uidl.getStringAttribute("mode");
- if (mode == null || "text".equals(mode)) {
- getWidget().setText(uidl.getChildString(0));
- } else if ("pre".equals(mode)) {
+ @Override
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+ super.onStateChanged(stateChangeEvent);
+ boolean sinkOnloads = false;
+ switch (getState().getContentMode()) {
+ case PREFORMATTED:
PreElement preElement = Document.get().createPreElement();
- preElement.setInnerText(uidl.getChildUIDL(0).getChildString(0));
+ preElement.setInnerText(getState().getText());
// clear existing content
getWidget().setHTML("");
// add preformatted text to dom
getWidget().getElement().appendChild(preElement);
- } else if ("uidl".equals(mode)) {
- getWidget().setHTML(uidl.getChildrenAsXML());
- } else if ("xhtml".equals(mode)) {
- UIDL content = uidl.getChildUIDL(0).getChildUIDL(0);
- if (content.getChildCount() > 0) {
- getWidget().setHTML(content.getChildString(0));
- } else {
- getWidget().setHTML("");
- }
- sinkOnloads = true;
- } else if ("xml".equals(mode)) {
- getWidget().setHTML(uidl.getChildUIDL(0).getChildString(0));
- } else if ("raw".equals(mode)) {
- getWidget().setHTML(uidl.getChildUIDL(0).getChildString(0));
+ break;
+
+ case TEXT:
+ getWidget().setText(getState().getText());
+ break;
+
+ case XHTML:
+ case RAW:
sinkOnloads = true;
- } else {
+ case XML:
+ getWidget().setHTML(getState().getText());
+ break;
+ default:
getWidget().setText("");
+ break;
+
}
if (sinkOnloads) {
Util.sinkOnloadForImages(getWidget().getElement());
diff --git a/src/com/vaadin/terminal/gwt/client/ui/label/LabelState.java b/src/com/vaadin/terminal/gwt/client/ui/label/LabelState.java
new file mode 100644
index 0000000000..ef73a01d2a
--- /dev/null
+++ b/src/com/vaadin/terminal/gwt/client/ui/label/LabelState.java
@@ -0,0 +1,25 @@
+package com.vaadin.terminal.gwt.client.ui.label;
+
+import com.vaadin.terminal.gwt.client.ComponentState;
+
+public class LabelState extends ComponentState {
+ private ContentMode contentMode = ContentMode.TEXT;
+ private String text = "";
+
+ public ContentMode getContentMode() {
+ return contentMode;
+ }
+
+ public void setContentMode(ContentMode contentMode) {
+ this.contentMode = contentMode;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+}
diff --git a/src/com/vaadin/ui/Label.java b/src/com/vaadin/ui/Label.java
index e52090aa5f..99a0f89e5c 100644
--- a/src/com/vaadin/ui/Label.java
+++ b/src/com/vaadin/ui/Label.java
@@ -5,13 +5,11 @@
package com.vaadin.ui;
import java.lang.reflect.Method;
-import java.util.Map;
import com.vaadin.data.Property;
import com.vaadin.data.util.ObjectProperty;
-import com.vaadin.terminal.PaintException;
-import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.Vaadin6Component;
+import com.vaadin.terminal.gwt.client.ui.label.ContentMode;
+import com.vaadin.terminal.gwt.client.ui.label.LabelState;
/**
* Label component for showing non-editable short texts.
@@ -41,120 +39,7 @@ import com.vaadin.terminal.Vaadin6Component;
// TODO generics for interface Property
public class Label extends AbstractComponent implements Property,
Property.Viewer, Property.ValueChangeListener,
- Property.ValueChangeNotifier, Comparable<Object>, Vaadin6Component {
-
- /**
- * Content modes defining how the client should interpret a Label's value.
- *
- * @sine 7.0
- */
- public enum ContentMode {
- /**
- * Content mode, where the label contains only plain text. The
- * getValue() result is coded to XML when painting.
- */
- TEXT(null) {
- @Override
- public void paintText(String text, PaintTarget target)
- throws PaintException {
- target.addText(text);
- }
- },
-
- /**
- * Content mode, where the label contains preformatted text.
- */
- PREFORMATTED("pre") {
- @Override
- public void paintText(String text, PaintTarget target)
- throws PaintException {
- target.startTag("pre");
- target.addText(text);
- target.endTag("pre");
- }
- },
-
- /**
- * Content mode, where the label contains XHTML. Contents is then
- * enclosed in DIV elements having namespace of
- * "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd".
- */
- XHTML("xhtml") {
- @Override
- public void paintText(String text, PaintTarget target)
- throws PaintException {
- target.startTag("data");
- target.addXMLSection("div", text,
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd");
- target.endTag("data");
- }
- },
-
- /**
- * Content mode, where the label contains well-formed or well-balanced
- * XML. Each of the root elements must have their default namespace
- * specified.
- */
- XML("xml") {
- @Override
- public void paintText(String text, PaintTarget target)
- throws PaintException {
- target.addXMLSection("data", text, null);
- }
- },
-
- /**
- * Content mode, where the label contains RAW output. Output is not
- * required to comply to with XML. In Web Adapter output is inserted
- * inside the resulting HTML document as-is. This is useful for some
- * specific purposes where possibly broken HTML content needs to be
- * shown, but in most cases XHTML mode should be preferred.
- */
- RAW("raw") {
- @Override
- public void paintText(String text, PaintTarget target)
- throws PaintException {
- target.startTag("data");
- target.addAttribute("escape", false);
- target.addText(text);
- target.endTag("data");
- }
- };
-
- private final String uidlName;
-
- /**
- * The default content mode is text
- */
- public static ContentMode DEFAULT = TEXT;
-
- private ContentMode(String uidlName) {
- this.uidlName = uidlName;
- }
-
- /**
- * Gets the name representing this content mode in UIDL messages
- *
- * @return the UIDL name of this content mode
- */
- public String getUidlName() {
- return uidlName;
- }
-
- /**
- * Adds the text value to a {@link PaintTarget} according to this
- * content mode
- *
- * @param text
- * the text to add
- * @param target
- * the paint target to add the value to
- * @throws PaintException
- * if the paint operation failed
- */
- public abstract void paintText(String text, PaintTarget target)
- throws PaintException;
- }
+ Property.ValueChangeNotifier, Comparable<Object> {
/**
* @deprecated From 7.0, use {@link ContentMode#TEXT} instead
@@ -187,17 +72,15 @@ public class Label extends AbstractComponent implements Property,
public static final ContentMode CONTENT_RAW = ContentMode.RAW;
/**
- * @deprecated From 7.0, use {@link ContentMode#DEFAULT} instead
+ * @deprecated From 7.0, use {@link ContentMode#TEXT} instead
*/
@Deprecated
- public static final ContentMode CONTENT_DEFAULT = ContentMode.DEFAULT;
+ public static final ContentMode CONTENT_DEFAULT = ContentMode.TEXT;
private static final String DATASOURCE_MUST_BE_SET = "Datasource must be set";
private Property dataSource;
- private ContentMode contentMode = ContentMode.DEFAULT;
-
/**
* Creates an empty Label.
*/
@@ -211,7 +94,7 @@ public class Label extends AbstractComponent implements Property,
* @param content
*/
public Label(String content) {
- this(content, ContentMode.DEFAULT);
+ this(content, ContentMode.TEXT);
}
/**
@@ -221,7 +104,7 @@ public class Label extends AbstractComponent implements Property,
* @param contentSource
*/
public Label(Property contentSource) {
- this(contentSource, ContentMode.DEFAULT);
+ this(contentSource, ContentMode.TEXT);
}
/**
@@ -243,27 +126,21 @@ public class Label extends AbstractComponent implements Property,
*/
public Label(Property contentSource, ContentMode contentMode) {
setPropertyDataSource(contentSource);
- if (contentMode != ContentMode.DEFAULT) {
- setContentMode(contentMode);
- }
+ setContentMode(contentMode);
setWidth(100, UNITS_PERCENTAGE);
}
- /**
- * Paints the content of this component.
- *
- * @param target
- * the Paint Event.
- * @throws PaintException
- * if the Paint Operation fails.
- */
- public void paintContent(PaintTarget target) throws PaintException {
- String uidlName = contentMode.getUidlName();
- if (uidlName != null) {
- target.addAttribute("mode", uidlName);
- }
- contentMode.paintText(getStringValue(), target);
+ @Override
+ public void updateState() {
+ super.updateState();
+ // We don't know when the text is updated so update it here before
+ // sending the state to the client
+ getState().setText(getStringValue());
+ }
+ @Override
+ public LabelState getState() {
+ return (LabelState) super.getState();
}
/**
@@ -381,7 +258,7 @@ public class Label extends AbstractComponent implements Property,
* @see ContentMode
*/
public ContentMode getContentMode() {
- return contentMode;
+ return getState().getContentMode();
}
/**
@@ -396,10 +273,9 @@ public class Label extends AbstractComponent implements Property,
if (contentMode == null) {
throw new IllegalArgumentException("Content mode can not be null");
}
- if (contentMode != this.contentMode) {
- this.contentMode = contentMode;
- requestRepaint();
- }
+
+ getState().setContentMode(contentMode);
+ requestRepaint();
}
/* Value change events */
@@ -516,7 +392,8 @@ public class Label extends AbstractComponent implements Property,
String thisValue;
String otherValue;
- if (contentMode == ContentMode.XML || contentMode == ContentMode.XHTML) {
+ if (getContentMode() == ContentMode.XML
+ || getContentMode() == ContentMode.XHTML) {
thisValue = stripTags(getStringValue());
} else {
thisValue = getStringValue();
@@ -566,8 +443,4 @@ public class Label extends AbstractComponent implements Property,
return res.toString();
}
- public void changeVariables(Object source, Map<String, Object> variables) {
- // TODO Remove once Vaadin6Component is no longer implemented
- }
-
}