From cc3d673ad83b048a838a8db3198066cad7bd7ab1 Mon Sep 17 00:00:00 2001
From: Artur Signell
Date: Thu, 26 Jan 2012 14:33:28 +0200
Subject: [PATCH] Split VScrollTable, VTreeTable and VMenuBar into paintable
and widget classes. Improved VAbstractPaintable
---
.../gwt/client/ApplicationConnection.java | 41 +-
.../vaadin/terminal/gwt/client/Container.java | 4 +-
src/com/vaadin/terminal/gwt/client/Util.java | 18 +
.../terminal/gwt/client/VPaintable.java | 57 ++-
.../terminal/gwt/client/VPaintableMap.java | 11 +-
.../terminal/gwt/client/VPaintableWidget.java | 3 +-
.../gwt/client/ui/ShortcutActionHandler.java | 9 +-
.../client/ui/VAbstractPaintableWidget.java | 41 +-
.../gwt/client/ui/VDragAndDropWrapper.java | 11 +-
.../terminal/gwt/client/ui/VMenuBar.java | 145 +------
.../gwt/client/ui/VMenuBarPaintable.java | 161 ++++++++
.../terminal/gwt/client/ui/VScrollTable.java | 386 +++++-------------
.../gwt/client/ui/VScrollTablePaintable.java | 251 ++++++++++++
.../terminal/gwt/client/ui/VTreeTable.java | 92 +----
.../gwt/client/ui/VTreeTablePaintable.java | 98 +++++
.../terminal/gwt/client/ui/VUpload.java | 2 +-
.../terminal/gwt/client/ui/label/VLabel.java | 7 +-
.../gwt/client/ui/label/VLabelPaintable.java | 22 +-
src/com/vaadin/ui/MenuBar.java | 3 +-
src/com/vaadin/ui/Table.java | 3 +-
src/com/vaadin/ui/TreeTable.java | 7 +-
21 files changed, 809 insertions(+), 563 deletions(-)
create mode 100644 src/com/vaadin/terminal/gwt/client/ui/VMenuBarPaintable.java
create mode 100644 src/com/vaadin/terminal/gwt/client/ui/VScrollTablePaintable.java
create mode 100644 src/com/vaadin/terminal/gwt/client/ui/VTreeTablePaintable.java
diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
index f8ca0a6959..9b756382f3 100644
--- a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
+++ b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
@@ -36,6 +36,7 @@ import com.vaadin.terminal.gwt.client.ApplicationConfiguration.ErrorMessage;
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.VContextMenu;
import com.vaadin.terminal.gwt.client.ui.VNotification;
import com.vaadin.terminal.gwt.client.ui.VNotification.HideEvent;
@@ -1586,9 +1587,10 @@ public class ApplicationConnection {
*
* @return Returns true iff no further painting is needed by caller
*/
- public boolean updateComponent(Widget component, UIDL uidl,
+ @Deprecated
+ public boolean updateComponent(VPaintableWidget paintable, UIDL uidl,
boolean manageCaption) {
- VPaintableWidget paintable = paintableMap.getPaintable(component);
+ Widget component = paintable.getWidgetForPaintable();
String pid = paintableMap.getPid(paintable);
if (pid == null) {
@@ -2029,6 +2031,10 @@ public class ApplicationConnection {
if (!paintableMap.hasPaintable(pid)) {
// Create and register a new paintable if no old was found
VPaintableWidget p = widgetSet.createWidget(uidl, configuration);
+ if (p instanceof VAbstractPaintableWidget) {
+ ((VAbstractPaintableWidget) p).setConnection(this);
+ ((VAbstractPaintableWidget) p).init();
+ }
paintableMap.registerPaintable(pid, p);
}
return (VPaintableWidget) paintableMap.getPaintable(pid);
@@ -2192,7 +2198,7 @@ public class ApplicationConnection {
}
};
- private VPaintableMap paintableMap = new VPaintableMap();
+ private VPaintableMap paintableMap = GWT.create(VPaintableMap.class);
/**
* Components can call this function to run all layout functions. This is
@@ -2275,7 +2281,7 @@ public class ApplicationConnection {
* @return true if at least one listener has been registered on server side
* for the event identified by eventIdentifier.
*/
- public boolean hasEventListeners(VPaintable paintable,
+ public boolean hasEventListeners(VPaintableWidget paintable,
String eventIdentifier) {
return paintableMap.hasEventListeners(paintable, eventIdentifier);
}
@@ -2330,4 +2336,31 @@ public class ApplicationConnection {
paintableMap.unregisterPaintable(p);
}
+ public VTooltip getVTooltip() {
+ return tooltip;
+ }
+
+ @Deprecated
+ public void handleWidgetTooltipEvent(Event event, Widget owner, Object key) {
+ handleTooltipEvent(event, getPaintableMap().getPaintable(owner), key);
+
+ }
+
+ @Deprecated
+ public void handleWidgetTooltipEvent(Event event, Widget owner) {
+ handleTooltipEvent(event, getPaintableMap().getPaintable(owner));
+
+ }
+
+ @Deprecated
+ public void registerWidgetTooltip(Widget owner, Object key, TooltipInfo info) {
+ registerTooltip(getPaintableMap().getPaintable(owner), key, info);
+ }
+
+ @Deprecated
+ public boolean hasWidgetEventListeners(Widget widget, String eventIdentifier) {
+ return hasEventListeners(getPaintableMap().getPaintable(widget),
+ eventIdentifier);
+ }
+
}
diff --git a/src/com/vaadin/terminal/gwt/client/Container.java b/src/com/vaadin/terminal/gwt/client/Container.java
index 7c92bc261b..db6bbf0ee4 100644
--- a/src/com/vaadin/terminal/gwt/client/Container.java
+++ b/src/com/vaadin/terminal/gwt/client/Container.java
@@ -42,12 +42,12 @@ public interface Container extends VPaintableWidget {
* must provide service for it's childen to show those elements for them.
*
*
- * @param component
+ * @param paintable
* Child component for which service is requested.
* @param uidl
* UIDL of the child component.
*/
- void updateCaption(VPaintableWidget component, UIDL uidl);
+ void updateCaption(VPaintableWidget paintable, UIDL uidl);
/**
* Called when a child components size has been updated in the rendering
diff --git a/src/com/vaadin/terminal/gwt/client/Util.java b/src/com/vaadin/terminal/gwt/client/Util.java
index 597ca3d49c..2a3fc07195 100644
--- a/src/com/vaadin/terminal/gwt/client/Util.java
+++ b/src/com/vaadin/terminal/gwt/client/Util.java
@@ -829,6 +829,24 @@ public class Util {
}
}-*/;
+ /**
+ * Helper method to find the nearest parent paintable instance by traversing
+ * the DOM upwards from given element.
+ *
+ * @param element
+ * the element to start from
+ */
+ public static VPaintableWidget findPaintable(ApplicationConnection client,
+ Element element) {
+ Widget widget = Util.findWidget(element, null);
+ VPaintableMap vPaintableMap = VPaintableMap.get(client);
+ while (widget != null && !vPaintableMap.isPaintable(widget)) {
+ widget = widget.getParent();
+ }
+ return vPaintableMap.getPaintable(widget);
+
+ }
+
/**
* Helper method to find first instance of given Widget type found by
* traversing DOM upwards from given element.
diff --git a/src/com/vaadin/terminal/gwt/client/VPaintable.java b/src/com/vaadin/terminal/gwt/client/VPaintable.java
index 02b529b428..d85c6d33e2 100644
--- a/src/com/vaadin/terminal/gwt/client/VPaintable.java
+++ b/src/com/vaadin/terminal/gwt/client/VPaintable.java
@@ -4,8 +4,13 @@
package com.vaadin.terminal.gwt.client;
/**
- * TODO
+ * Interface implemented by all client side classes that can be communicate with
+ * the server. Classes implementing this interface are initialized by the
+ * framework when needed and have the ability to communicate with the server.
*
+ * @author Vaadin Ltd
+ * @version @VERSION@
+ * @since 7.0.0
*/
public interface VPaintable {
/**
@@ -16,4 +21,54 @@ public interface VPaintable {
*/
public void updateFromUIDL(UIDL uidl, ApplicationConnection client);
+ // /**
+ // * Returns the id for this VPaintable. This must always be what has been
+ // set
+ // * using {@link #setId(String)}.
+ // *
+ // * @return The id for the VPaintable.
+ // */
+ // public String getId();
+ //
+ // /**
+ // * Sets the id for the VPaintable. This method is called once by the
+ // * framework when the VPaintable is initialized and should never be called
+ // * otherwise.
+ // *
+ // * The VPaintable id is used to map the server and the client paintables
+ // * together. It is unique in this root and assigned by the framework.
+ // *
+ // *
+ // * @param id
+ // * The id of the paintable.
+ // */
+ // public void setId(String id);
+
+ /**
+ * Gets ApplicationConnection instance that created this VPaintable.
+ *
+ * @return The ApplicationConnection as set by
+ * {@link #setConnection(ApplicationConnection)}
+ */
+ // public ApplicationConnection getConnection();
+
+ /**
+ * Sets the reference to ApplicationConnection. This method is called by the
+ * framework when the VPaintable is created and should never be called
+ * otherwise.
+ *
+ * @param connection
+ * The ApplicationConnection that created this VPaintable
+ */
+ // public void setConnection(ApplicationConnection connection);
+
+ /**
+ * Tests whether the component is enabled or not. A user can not interact
+ * with disabled components. Disabled components are rendered in a style
+ * that indicates the status, usually in gray color. Children of a disabled
+ * component are also disabled.
+ *
+ * @return true if the component is enabled, false otherwise
+ */
+ // public boolean isEnabled();
}
diff --git a/src/com/vaadin/terminal/gwt/client/VPaintableMap.java b/src/com/vaadin/terminal/gwt/client/VPaintableMap.java
index ef355d3cad..f21d85558c 100644
--- a/src/com/vaadin/terminal/gwt/client/VPaintableMap.java
+++ b/src/com/vaadin/terminal/gwt/client/VPaintableMap.java
@@ -335,7 +335,7 @@ public class VPaintableMap {
}
- private ComponentDetail getComponentDetail(VPaintable paintable) {
+ private ComponentDetail getComponentDetail(VPaintableWidget paintable) {
return idToComponentDetail.get(getPid(paintable));
}
@@ -344,7 +344,7 @@ public class VPaintableMap {
}
/**
- * FIXME: Should not be here
+ * FIXME: Should be moved to VAbstractPaintableWidget
*
* @param paintable
* @return
@@ -354,6 +354,11 @@ public class VPaintableMap {
return getComponentDetail(paintable).getTooltipInfo(key);
}
+ @Deprecated
+ public TooltipInfo getWidgetTooltipInfo(Widget widget, Object key) {
+ return getTooltipInfo(getPaintable(widget), key);
+ }
+
public Collection extends VPaintable> getPaintables() {
return Collections.unmodifiableCollection(paintableToId.keySet());
}
@@ -378,7 +383,7 @@ public class VPaintableMap {
* @return
*/
@Deprecated
- public boolean hasEventListeners(VPaintable paintable,
+ public boolean hasEventListeners(VPaintableWidget paintable,
String eventIdentifier) {
return getComponentDetail(paintable).hasEventListeners(eventIdentifier);
}
diff --git a/src/com/vaadin/terminal/gwt/client/VPaintableWidget.java b/src/com/vaadin/terminal/gwt/client/VPaintableWidget.java
index 9171fdceda..2f0cae1cc1 100644
--- a/src/com/vaadin/terminal/gwt/client/VPaintableWidget.java
+++ b/src/com/vaadin/terminal/gwt/client/VPaintableWidget.java
@@ -17,7 +17,8 @@ import com.google.gwt.user.client.ui.Widget;
public interface VPaintableWidget extends VPaintable {
/**
- * TODO: Renamed to getWidget
+ * TODO: Rename to getWidget
*/
public Widget getWidgetForPaintable();
+
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/ShortcutActionHandler.java b/src/com/vaadin/terminal/gwt/client/ui/ShortcutActionHandler.java
index 38f7878ba4..2bd578a45d 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/ShortcutActionHandler.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/ShortcutActionHandler.java
@@ -15,13 +15,11 @@ import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.KeyboardListener;
import com.google.gwt.user.client.ui.KeyboardListenerCollection;
-import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.Container;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
-import com.vaadin.terminal.gwt.client.VPaintableMap;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
import com.vaadin.terminal.gwt.client.ui.richtextarea.VRichTextArea;
@@ -137,12 +135,7 @@ public class ShortcutActionHandler {
VPaintableWidget target) {
final Element et = DOM.eventGetTarget(event);
if (target == null) {
- Widget w = Util.findWidget(et, null);
- VPaintableMap paintableMap = VPaintableMap.get(client);
- while (w != null && !paintableMap.isPaintable(w)) {
- w = w.getParent();
- }
- target = paintableMap.getPaintable(w);
+ target = Util.findPaintable(client, et);
}
final VPaintableWidget finalTarget = target;
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java
index dff5a286ba..d4c8f79467 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java
@@ -1,12 +1,16 @@
package com.vaadin.terminal.gwt.client.ui;
-import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
public abstract class VAbstractPaintableWidget implements VPaintableWidget {
private Widget widget;
+ private ApplicationConnection connection;
+
+ /* State variables */
+// private boolean enabled = true;
/**
* Default constructor
@@ -14,15 +18,19 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget {
public VAbstractPaintableWidget() {
}
+ /**
+ * Called after the application connection reference has been set up
+ */
+ public void init() {
+ }
+
/**
* Creates and returns the widget for this VPaintableWidget. This method
* should only be called once when initializing the paintable.
*
* @return
*/
- protected Widget createWidget() {
- return GWT.create(getWidgetClass());
- }
+ protected abstract Widget createWidget();
/**
* Returns the widget associated with this paintable. The widget returned by
@@ -38,12 +46,27 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget {
return widget;
}
- /**
- * Returns the class of the widget for this paintable. Used to instansiate
- * the widget.
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.terminal.gwt.client.VPaintable#getConnection()
+ */
+ public final ApplicationConnection getConnection() {
+ return connection;
+ }
+
+ /*
+ * (non-Javadoc)
*
- * @return The widget class.
+ * @see
+ * com.vaadin.terminal.gwt.client.VPaintable#setConnection(com.vaadin.terminal
+ * .gwt.client.ApplicationConnection)
*/
- protected abstract Class extends Widget> getWidgetClass();
+ public final void setConnection(ApplicationConnection connection) {
+ this.connection = connection;
+ }
+// public boolean isEnabled() {
+// return enabled;
+// }
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java b/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java
index da916f262e..3251a03d6a 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VDragAndDropWrapper.java
@@ -113,14 +113,9 @@ public class VDragAndDropWrapper extends VCustomComponent implements
VTransferable transferable = new VTransferable();
transferable.setDragSource(VDragAndDropWrapper.this);
- Widget widget = Util.findWidget((Element) event.getEventTarget()
- .cast(), null);
- VPaintableMap vPaintableMap = VPaintableMap.get(client);
- while (widget != null && !vPaintableMap.isPaintable(widget)) {
- widget = widget.getParent();
- }
- VPaintableWidget paintable = vPaintableMap.getPaintable(widget);
-
+ VPaintableWidget paintable = Util.findPaintable(client,
+ (Element) event.getEventTarget().cast());
+ Widget widget = paintable.getWidgetForPaintable();
transferable.setData("component", paintable);
VDragEvent dragEvent = VDragAndDropManager.get().startDrag(
transferable, event, true);
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java b/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java
index 306086e357..372ddf25d2 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java
@@ -4,9 +4,7 @@
package com.vaadin.terminal.gwt.client.ui;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
-import java.util.Stack;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
@@ -35,14 +33,12 @@ import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.ContainerResizedListener;
-import com.vaadin.terminal.gwt.client.VPaintableMap;
import com.vaadin.terminal.gwt.client.TooltipInfo;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
-import com.vaadin.terminal.gwt.client.VPaintableWidget;
import com.vaadin.terminal.gwt.client.VTooltip;
-public class VMenuBar extends SimpleFocusablePanel implements VPaintableWidget,
+public class VMenuBar extends SimpleFocusablePanel implements
CloseHandler, ContainerResizedListener, KeyPressHandler,
KeyDownHandler, FocusHandler, SubPartAware {
@@ -82,7 +78,7 @@ public class VMenuBar extends SimpleFocusablePanel implements VPaintableWidget,
protected VMenuBar parentMenu;
protected CustomMenuItem selected;
- private boolean enabled = true;
+ boolean enabled = true;
private String width = "notinited";
@@ -94,9 +90,9 @@ public class VMenuBar extends SimpleFocusablePanel implements VPaintableWidget,
}
});
- private boolean openRootOnHover;
+ boolean openRootOnHover;
- private boolean htmlContentAllowed;
+ boolean htmlContentAllowed;
public VMenuBar() {
// Create an empty horizontal menubar
@@ -167,133 +163,6 @@ public class VMenuBar extends SimpleFocusablePanel implements VPaintableWidget,
}
}
- /**
- * This method must be implemented to update the client-side component from
- * UIDL data received from server.
- *
- * This method is called when the page is loaded for the first time, and
- * every time UI changes in the component are received from the server.
- */
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- // This call should be made first. Ensure correct implementation,
- // and let the containing layout manage caption, etc.
- if (client.updateComponent(this, uidl, true)) {
- return;
- }
-
- htmlContentAllowed = uidl.hasAttribute(HTML_CONTENT_ALLOWED);
-
- openRootOnHover = uidl.getBooleanAttribute(OPEN_ROOT_MENU_ON_HOWER);
-
- enabled = !uidl.getBooleanAttribute("disabled");
-
- // For future connections
- this.client = client;
- uidlId = uidl.getId();
-
- // Empty the menu every time it receives new information
- if (!getItems().isEmpty()) {
- clearItems();
- }
-
- UIDL options = uidl.getChildUIDL(0);
-
- if (uidl.hasAttribute("width")) {
- UIDL moreItemUIDL = options.getChildUIDL(0);
- StringBuffer itemHTML = new StringBuffer();
-
- if (moreItemUIDL.hasAttribute("icon")) {
- itemHTML.append("");
- }
-
- String moreItemText = moreItemUIDL.getStringAttribute("text");
- if ("".equals(moreItemText)) {
- moreItemText = "►";
- }
- itemHTML.append(moreItemText);
-
- moreItem = GWT.create(CustomMenuItem.class);
- moreItem.setHTML(itemHTML.toString());
- moreItem.setCommand(emptyCommand);
-
- collapsedRootItems = new VMenuBar(true, (VMenuBar) VPaintableMap
- .get(client).getPaintable(uidlId));
- moreItem.setSubMenu(collapsedRootItems);
- moreItem.addStyleName(CLASSNAME + "-more-menuitem");
- }
-
- UIDL uidlItems = uidl.getChildUIDL(1);
- Iterator