]> source.dussan.org Git - vaadin-framework.git/commitdiff
Splitted VLink into Widget and Paintable.
authorJens Jansson <peppe@vaadin.com>
Mon, 30 Jan 2012 13:23:53 +0000 (15:23 +0200)
committerJens Jansson <peppe@vaadin.com>
Mon, 30 Jan 2012 13:23:53 +0000 (15:23 +0200)
src/com/vaadin/terminal/gwt/client/ui/VLink.java
src/com/vaadin/terminal/gwt/client/ui/VLinkPaintable.java [new file with mode: 0644]
src/com/vaadin/ui/Link.java

index 0ade84aaf5e77174f2e4e76f8e430fd804c5f916..df651c0a4d7f617831402c721d7ee53f4c0a196f 100644 (file)
@@ -11,44 +11,41 @@ import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Event;
 import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.VPaintableWidget;
-import com.vaadin.terminal.gwt.client.UIDL;
 import com.vaadin.terminal.gwt.client.Util;
 import com.vaadin.terminal.gwt.client.VTooltip;
 
-public class VLink extends HTML implements VPaintableWidget, ClickHandler {
+public class VLink extends HTML implements ClickHandler {
 
     public static final String CLASSNAME = "v-link";
 
-    private static final int BORDER_STYLE_DEFAULT = 0;
-    private static final int BORDER_STYLE_MINIMAL = 1;
-    private static final int BORDER_STYLE_NONE = 2;
+    protected static final int BORDER_STYLE_DEFAULT = 0;
+    protected static final int BORDER_STYLE_MINIMAL = 1;
+    protected static final int BORDER_STYLE_NONE = 2;
 
-    private String src;
+    protected String src;
 
-    private String target;
+    protected String target;
 
-    private int borderStyle = BORDER_STYLE_DEFAULT;
+    protected int borderStyle = BORDER_STYLE_DEFAULT;
 
-    private boolean enabled;
+    protected boolean enabled;
 
-    private boolean readonly;
+    protected boolean readonly;
 
-    private int targetWidth;
+    protected int targetWidth;
 
-    private int targetHeight;
+    protected int targetHeight;
 
-    private Element errorIndicatorElement;
+    protected Element errorIndicatorElement;
 
-    private final Element anchor = DOM.createAnchor();
+    protected final Element anchor = DOM.createAnchor();
 
-    private final Element captionElement = DOM.createSpan();
+    protected final Element captionElement = DOM.createSpan();
 
-    private Icon icon;
+    protected Icon icon;
 
-    private ApplicationConnection client;
+    protected ApplicationConnection client;
 
     public VLink() {
         super();
@@ -59,68 +56,6 @@ public class VLink extends HTML implements VPaintableWidget, ClickHandler {
         setStyleName(CLASSNAME);
     }
 
-    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-
-        // Ensure correct implementation,
-        // but don't let container manage caption etc.
-        if (client.updateComponent(this, uidl, false)) {
-            return;
-        }
-
-        this.client = client;
-
-        enabled = uidl.hasAttribute("disabled") ? false : true;
-        readonly = uidl.hasAttribute("readonly") ? true : false;
-
-        if (uidl.hasAttribute("name")) {
-            target = uidl.getStringAttribute("name");
-            anchor.setAttribute("target", target);
-        }
-        if (uidl.hasAttribute("src")) {
-            src = client.translateVaadinUri(uidl.getStringAttribute("src"));
-            anchor.setAttribute("href", src);
-        }
-
-        if (uidl.hasAttribute("border")) {
-            if ("none".equals(uidl.getStringAttribute("border"))) {
-                borderStyle = BORDER_STYLE_NONE;
-            } else {
-                borderStyle = BORDER_STYLE_MINIMAL;
-            }
-        } else {
-            borderStyle = BORDER_STYLE_DEFAULT;
-        }
-
-        targetHeight = uidl.hasAttribute("targetHeight") ? uidl
-                .getIntAttribute("targetHeight") : -1;
-        targetWidth = uidl.hasAttribute("targetWidth") ? uidl
-                .getIntAttribute("targetWidth") : -1;
-
-        // Set link caption
-        captionElement.setInnerText(uidl.getStringAttribute("caption"));
-
-        // handle error
-        if (uidl.hasAttribute("error")) {
-            if (errorIndicatorElement == null) {
-                errorIndicatorElement = DOM.createDiv();
-                DOM.setElementProperty(errorIndicatorElement, "className",
-                        "v-errorindicator");
-            }
-            DOM.insertChild(getElement(), errorIndicatorElement, 0);
-        } else if (errorIndicatorElement != null) {
-            DOM.setStyleAttribute(errorIndicatorElement, "display", "none");
-        }
-
-        if (uidl.hasAttribute("icon")) {
-            if (icon == null) {
-                icon = new Icon(client);
-                anchor.insertBefore(icon.getElement(), captionElement);
-            }
-            icon.setUri(uidl.getStringAttribute("icon"));
-        }
-
-    }
-
     public void onClick(ClickEvent event) {
         if (enabled && !readonly) {
             if (target == null) {
@@ -168,7 +103,7 @@ public class VLink extends HTML implements VPaintableWidget, ClickHandler {
             Util.notifyParentOfSizeChange(this, true);
         }
         if (client != null) {
-            client.handleTooltipEvent(event, this);
+            client.handleWidgetTooltipEvent(event, this);
         }
         if (target == captionElement || target == anchor
                 || (icon != null && target == icon.getElement())) {
@@ -180,8 +115,4 @@ public class VLink extends HTML implements VPaintableWidget, ClickHandler {
 
     }
 
-    public Widget getWidgetForPaintable() {
-        return this;
-    }
-
 }
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VLinkPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VLinkPaintable.java
new file mode 100644 (file)
index 0000000..3fbd796
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+
+public class VLinkPaintable extends VAbstractPaintableWidget {
+
+    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+
+        // Ensure correct implementation,
+        // but don't let container manage caption etc.
+        if (client.updateComponent(this, uidl, false)) {
+            return;
+        }
+
+        getWidgetForPaintable().client = client;
+
+        getWidgetForPaintable().enabled = uidl.hasAttribute("disabled") ? false
+                : true;
+        getWidgetForPaintable().readonly = uidl.hasAttribute("readonly") ? true
+                : false;
+
+        if (uidl.hasAttribute("name")) {
+            getWidgetForPaintable().target = uidl.getStringAttribute("name");
+            getWidgetForPaintable().anchor.setAttribute("target",
+                    getWidgetForPaintable().target);
+        }
+        if (uidl.hasAttribute("src")) {
+            getWidgetForPaintable().src = client.translateVaadinUri(uidl
+                    .getStringAttribute("src"));
+            getWidgetForPaintable().anchor.setAttribute("href",
+                    getWidgetForPaintable().src);
+        }
+
+        if (uidl.hasAttribute("border")) {
+            if ("none".equals(uidl.getStringAttribute("border"))) {
+                getWidgetForPaintable().borderStyle = VLink.BORDER_STYLE_NONE;
+            } else {
+                getWidgetForPaintable().borderStyle = VLink.BORDER_STYLE_MINIMAL;
+            }
+        } else {
+            getWidgetForPaintable().borderStyle = VLink.BORDER_STYLE_DEFAULT;
+        }
+
+        getWidgetForPaintable().targetHeight = uidl
+                .hasAttribute("targetHeight") ? uidl
+                .getIntAttribute("targetHeight") : -1;
+        getWidgetForPaintable().targetWidth = uidl.hasAttribute("targetWidth") ? uidl
+                .getIntAttribute("targetWidth") : -1;
+
+        // Set link caption
+        getWidgetForPaintable().captionElement.setInnerText(uidl
+                .getStringAttribute("caption"));
+
+        // handle error
+        if (uidl.hasAttribute("error")) {
+            if (getWidgetForPaintable().errorIndicatorElement == null) {
+                getWidgetForPaintable().errorIndicatorElement = DOM.createDiv();
+                DOM.setElementProperty(
+                        getWidgetForPaintable().errorIndicatorElement,
+                        "className", "v-errorindicator");
+            }
+            DOM.insertChild(getWidgetForPaintable().getElement(),
+                    getWidgetForPaintable().errorIndicatorElement, 0);
+        } else if (getWidgetForPaintable().errorIndicatorElement != null) {
+            DOM.setStyleAttribute(
+                    getWidgetForPaintable().errorIndicatorElement, "display",
+                    "none");
+        }
+
+        if (uidl.hasAttribute("icon")) {
+            if (getWidgetForPaintable().icon == null) {
+                getWidgetForPaintable().icon = new Icon(client);
+                getWidgetForPaintable().anchor.insertBefore(
+                        getWidgetForPaintable().icon.getElement(),
+                        getWidgetForPaintable().captionElement);
+            }
+            getWidgetForPaintable().icon
+                    .setUri(uidl.getStringAttribute("icon"));
+        }
+
+    }
+
+    @Override
+    protected Widget createWidget() {
+        return GWT.create(VLink.class);
+    }
+
+    @Override
+    public VLink getWidgetForPaintable() {
+        return (VLink) super.getWidgetForPaintable();
+    }
+}
index 99d742ec1765eb141cc57efedcdb8c39ea778bf1..0b11151be7ccaecea9b3fbd858f9bea4c3fcfa19 100644 (file)
@@ -7,7 +7,7 @@ package com.vaadin.ui;
 import com.vaadin.terminal.PaintException;
 import com.vaadin.terminal.PaintTarget;
 import com.vaadin.terminal.Resource;
-import com.vaadin.terminal.gwt.client.ui.VLink;
+import com.vaadin.terminal.gwt.client.ui.VLinkPaintable;
 
 /**
  * Link is used to create external or internal URL links.
@@ -18,7 +18,7 @@ import com.vaadin.terminal.gwt.client.ui.VLink;
  * @since 3.0
  */
 @SuppressWarnings("serial")
-@ClientWidget(VLink.class)
+@ClientWidget(VLinkPaintable.class)
 public class Link extends AbstractComponent {
 
     /* Target window border type constant: No window border */