]> source.dussan.org Git - vaadin-framework.git/commitdiff
Crude first implementation of getParentPaintable
authorArtur Signell <artur@vaadin.com>
Tue, 31 Jan 2012 07:56:14 +0000 (09:56 +0200)
committerArtur Signell <artur@vaadin.com>
Tue, 31 Jan 2012 08:00:06 +0000 (10:00 +0200)
Moved caption handling from Container to newly introduced
VPaintableWidgetContainer

src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
src/com/vaadin/terminal/gwt/client/Container.java
src/com/vaadin/terminal/gwt/client/VPaintableWidget.java
src/com/vaadin/terminal/gwt/client/VPaintableWidgetContainer.java [new file with mode: 0644]
src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java
src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidgetContainer.java [new file with mode: 0644]

index e659a18477cd82aef841e55e72ba931a042d67c8..796c13c1734c4c7d1a409743152983d34e4e1d1b 100644 (file)
@@ -39,6 +39,7 @@ import com.vaadin.terminal.gwt.client.RenderInformation.FloatSize;
 import com.vaadin.terminal.gwt.client.RenderInformation.Size;
 import com.vaadin.terminal.gwt.client.ui.Field;
 import com.vaadin.terminal.gwt.client.ui.VAbstractPaintableWidget;
+import com.vaadin.terminal.gwt.client.ui.VAbstractPaintableWidgetContainer;
 import com.vaadin.terminal.gwt.client.ui.VContextMenu;
 import com.vaadin.terminal.gwt.client.ui.VNotification;
 import com.vaadin.terminal.gwt.client.ui.VNotification.HideEvent;
@@ -1659,11 +1660,7 @@ public class ApplicationConnection {
             // Changed invisibile <-> visible
             if (wasVisible && manageCaption) {
                 // Must hide caption when component is hidden
-                final Container parent = Util.getLayout(component);
-                if (parent != null) {
-                    parent.updateCaption(paintable, uidl);
-                }
-
+                updateCaption(paintable, uidl);
             }
         }
 
@@ -1708,10 +1705,7 @@ public class ApplicationConnection {
 
         // Set captions
         if (manageCaption) {
-            final Container parent = Util.getLayout(component);
-            if (parent != null) {
-                parent.updateCaption(paintable, uidl);
-            }
+            updateCaption(paintable, uidl);
         }
 
         // add error classname to components w/ error
@@ -1721,13 +1715,6 @@ public class ApplicationConnection {
             tooltipInfo.setErrorUidl(null);
         }
 
-        // Set captions
-        if (manageCaption) {
-            final Container parent = Util.getLayout(component);
-            if (parent != null) {
-                parent.updateCaption(paintable, uidl);
-            }
-        }
         /*
          * updateComponentSize need to be after caption update so caption can be
          * taken into account
@@ -1738,6 +1725,25 @@ public class ApplicationConnection {
         return false;
     }
 
+    @Deprecated
+    private void updateCaption(VPaintableWidget paintable, UIDL uidl) {
+        if (paintable instanceof VAbstractPaintableWidget) {
+            VPaintableWidget parent = ((VAbstractPaintableWidget) paintable)
+                    .getParentPaintable();
+            if (parent instanceof VAbstractPaintableWidgetContainer) {
+                ((VPaintableWidgetContainer) parent).updateCaption(paintable,
+                        uidl);
+                return;
+            }
+        }
+
+        // Old Container interface
+        // FIXME: Remove
+        Util.getLayout(paintable.getWidgetForPaintable()).updateCaption(
+                paintable, uidl);
+
+    }
+
     /**
      * Generates the style name for the widget based on the given primary style
      * name (typically returned by Widget.getPrimaryStyleName()) and the UIDL.
index db6bbf0ee40c1aa58378197637ae59b9ec190b91..d78177f3f95b410c166218542f648df881c166cd 100644 (file)
@@ -8,6 +8,10 @@ import java.util.Set;
 
 import com.google.gwt.user.client.ui.Widget;
 
+/**
+ * @deprecated To be removed before 7.0.0
+ */
+@Deprecated
 public interface Container extends VPaintableWidget {
 
     /**
index 2f0cae1cc1eca9c0153fffb0ce89a6cab8edefd3..0c1556208e444a499d94b4b03268fddec2f2b079 100644 (file)
@@ -21,4 +21,11 @@ public interface VPaintableWidget extends VPaintable {
      */
     public Widget getWidgetForPaintable();
 
+    /**
+     * Returns the parent {@link VPaintableWidgetContainer}
+     * 
+     * @return
+     */
+    // FIXME: Rename to getParent()
+    // public VPaintableWidget getParentPaintable();
 }
diff --git a/src/com/vaadin/terminal/gwt/client/VPaintableWidgetContainer.java b/src/com/vaadin/terminal/gwt/client/VPaintableWidgetContainer.java
new file mode 100644 (file)
index 0000000..baf2665
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.terminal.gwt.client;
+
+import com.google.gwt.user.client.ui.HasWidgets;
+
+/**
+ * An interface used by client-side paintables whose widget is a component
+ * container (implements {@link HasWidgets}).
+ */
+public interface VPaintableWidgetContainer extends VPaintableWidget {
+
+    /**
+     * Update child components caption, description and error message.
+     * 
+     * <p>
+     * Each component is responsible for maintaining its caption, description
+     * and error message. In most cases components doesn't want to do that and
+     * those elements reside outside of the component. Because of this layouts
+     * must provide service for it's childen to show those elements for them.
+     * </p>
+     * 
+     * @param paintable
+     *            Child component for which service is requested.
+     * @param uidl
+     *            UIDL of the child component.
+     */
+    void updateCaption(VPaintableWidget paintable, UIDL uidl);
+
+    /**
+     * Returns the children for this paintable.
+     * <p>
+     * The children for this paintable are defined as all
+     * {@link VPaintableWidget}s whose parent is this
+     * {@link VPaintableWidgetContainer}.
+     * </p>
+     * 
+     * @return A collection of children for this paintable. An empty collection
+     *         if there are no children.
+     */
+    // public Collection<VPaintableWidget> getChildren();
+
+}
index 9a2e728454944d8122610bfe0c18ca143083d23f..7c82f39e6bf4484da386780d452e5ebc4655e47d 100644 (file)
@@ -5,15 +5,17 @@ package com.vaadin.terminal.gwt.client.ui;
 \r
 import com.google.gwt.user.client.ui.Widget;\r
 import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
+import com.vaadin.terminal.gwt.client.VPaintableMap;\r
 import com.vaadin.terminal.gwt.client.VPaintableWidget;\r
 \r
 public abstract class VAbstractPaintableWidget implements VPaintableWidget {\r
 \r
     private Widget widget;\r
     private ApplicationConnection connection;\r
+    private String id;\r
 \r
     /* State variables */\r
-    // private boolean enabled = true;\r
+    private boolean enabled = true;\r
 \r
     /**\r
      * Default constructor\r
@@ -69,7 +71,32 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget {
         this.connection = connection;\r
     }\r
 \r
-    // public boolean isEnabled() {\r
-    // return enabled;\r
-    // }\r
+    public boolean isEnabled() {\r
+        return enabled;\r
+    }\r
+\r
+    public String getId() {\r
+        return id;\r
+    }\r
+\r
+    public void setId(String id) {\r
+        this.id = id;\r
+    }\r
+\r
+    public VPaintableWidget getParentPaintable() {\r
+        // FIXME: Return VPaintableWidgetContainer\r
+        // FIXME: Store hierarchy instead of doing lookup every time\r
+\r
+        VPaintableMap paintableMap = VPaintableMap.get(getConnection());\r
+\r
+        Widget w = getWidgetForPaintable();\r
+        while (w != null) {\r
+            w = w.getParent();\r
+            if (paintableMap.isPaintable(w)) {\r
+                return paintableMap.getPaintable(w);\r
+            }\r
+        }\r
+\r
+        return null;\r
+    }\r
 }\r
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidgetContainer.java b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidgetContainer.java
new file mode 100644 (file)
index 0000000..b3e19f0
--- /dev/null
@@ -0,0 +1,17 @@
+/*\r
+@VaadinApache2LicenseForJavaFiles@\r
+ */\r
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import com.vaadin.terminal.gwt.client.VPaintableWidgetContainer;\r
+\r
+public abstract class VAbstractPaintableWidgetContainer extends\r
+        VAbstractPaintableWidget implements VPaintableWidgetContainer {\r
+\r
+    /**\r
+     * Default constructor\r
+     */\r
+    public VAbstractPaintableWidgetContainer() {\r
+    }\r
+\r
+}\r