From 15abf4ff4c9359c8a2c402a6fc156076045712b5 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 31 Jan 2012 13:58:13 +0200 Subject: [PATCH] #8324 Split split panel classes into widget and paintable --- ...litPanel.java => VAbstractSplitPanel.java} | 152 +++--------------- .../ui/VAbstractSplitPanelPaintable.java | 140 ++++++++++++++++ .../ui/VHorizontalSplitPanelPaintable.java | 13 ++ .../gwt/client/ui/VSplitPanelHorizontal.java | 4 +- .../gwt/client/ui/VSplitPanelVertical.java | 4 +- .../ui/VVerticalSplitPanelPaintable.java | 12 ++ src/com/vaadin/ui/AbstractSplitPanel.java | 4 +- src/com/vaadin/ui/HorizontalSplitPanel.java | 4 +- src/com/vaadin/ui/SplitPanel.java | 4 +- src/com/vaadin/ui/VerticalSplitPanel.java | 4 +- 10 files changed, 195 insertions(+), 146 deletions(-) rename src/com/vaadin/terminal/gwt/client/ui/{VSplitPanel.java => VAbstractSplitPanel.java} (82%) create mode 100644 src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java create mode 100644 src/com/vaadin/terminal/gwt/client/ui/VHorizontalSplitPanelPaintable.java create mode 100644 src/com/vaadin/terminal/gwt/client/ui/VVerticalSplitPanelPaintable.java diff --git a/src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java b/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanel.java similarity index 82% rename from src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java rename to src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanel.java index 0d44609bb0..1aa9d92770 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VSplitPanel.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanel.java @@ -6,9 +6,7 @@ package com.vaadin.terminal.gwt.client.ui; import java.util.Set; -import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.dom.client.Node; -import com.google.gwt.event.dom.client.DomEvent.Type; import com.google.gwt.event.dom.client.TouchCancelEvent; import com.google.gwt.event.dom.client.TouchCancelHandler; import com.google.gwt.event.dom.client.TouchEndEvent; @@ -17,8 +15,6 @@ import com.google.gwt.event.dom.client.TouchMoveEvent; import com.google.gwt.event.dom.client.TouchMoveHandler; import com.google.gwt.event.dom.client.TouchStartEvent; import com.google.gwt.event.dom.client.TouchStartHandler; -import com.google.gwt.event.shared.EventHandler; -import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; @@ -30,61 +26,16 @@ import com.vaadin.terminal.gwt.client.Container; import com.vaadin.terminal.gwt.client.ContainerResizedListener; import com.vaadin.terminal.gwt.client.RenderInformation; import com.vaadin.terminal.gwt.client.RenderSpace; -import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VConsole; -import com.vaadin.terminal.gwt.client.VPaintableMap; -import com.vaadin.terminal.gwt.client.VPaintableWidget; -public class VSplitPanel extends ComplexPanel implements Container, +public class VAbstractSplitPanel extends ComplexPanel implements Container, ContainerResizedListener { private boolean enabled = false; public static final String CLASSNAME = "v-splitpanel"; - public static final String SPLITTER_CLICK_EVENT_IDENTIFIER = "sp_click"; - - private ClickEventHandler clickEventHandler = new ClickEventHandler(this, - SPLITTER_CLICK_EVENT_IDENTIFIER) { - - @Override - protected HandlerRegistration registerHandler( - H handler, Type type) { - if ((Event.getEventsSunk(splitter) & Event.getTypeInt(type - .getName())) != 0) { - // If we are already sinking the event for the splitter we do - // not want to additionally sink it for the root element - return addHandler(handler, type); - } else { - return addDomHandler(handler, type); - } - } - - @Override - public void onContextMenu( - com.google.gwt.event.dom.client.ContextMenuEvent event) { - Element target = event.getNativeEvent().getEventTarget().cast(); - if (splitter.isOrHasChild(target)) { - super.onContextMenu(event); - } - }; - - @Override - protected void fireClick(NativeEvent event) { - Element target = event.getEventTarget().cast(); - if (splitter.isOrHasChild(target)) { - super.fireClick(event); - } - } - - @Override - protected Element getRelativeToElement() { - return null; - } - - }; - public static final int ORIENTATION_HORIZONTAL = 0; public static final int ORIENTATION_VERTICAL = 1; @@ -93,9 +44,9 @@ public class VSplitPanel extends ComplexPanel implements Container, private int orientation = ORIENTATION_HORIZONTAL; - private Widget firstChild; + Widget firstChild; - private Widget secondChild; + Widget secondChild; private final Element wrapper = DOM.createDiv(); @@ -103,7 +54,7 @@ public class VSplitPanel extends ComplexPanel implements Container, private final Element secondContainer = DOM.createDiv(); - private final Element splitter = DOM.createDiv(); + final Element splitter = DOM.createDiv(); private boolean resizing; @@ -121,11 +72,11 @@ public class VSplitPanel extends ComplexPanel implements Container, private boolean positionReversed = false; - private String[] componentStyleNames; + String[] componentStyleNames; private Element draggingCurtain; - private ApplicationConnection client; + ApplicationConnection client; private String width = ""; @@ -136,14 +87,14 @@ public class VSplitPanel extends ComplexPanel implements Container, RenderInformation renderInformation = new RenderInformation(); - private String id; + String id; - private boolean immediate; + boolean immediate; - private boolean rendering = false; + boolean rendering = false; /* The current position of the split handle in either percentages or pixels */ - private String position; + String position; protected Element scrolledContainer; @@ -151,11 +102,11 @@ public class VSplitPanel extends ComplexPanel implements Container, private TouchScrollDelegate touchScrollDelegate; - public VSplitPanel() { + public VAbstractSplitPanel() { this(ORIENTATION_HORIZONTAL); } - public VSplitPanel(int orientation) { + public VAbstractSplitPanel(int orientation) { setElement(DOM.createDiv()); switch (orientation) { case ORIENTATION_HORIZONTAL: @@ -255,69 +206,6 @@ public class VSplitPanel extends ComplexPanel implements Container, + "-second-container"); } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - this.client = client; - id = uidl.getId(); - rendering = true; - - immediate = uidl.hasAttribute("immediate"); - - if (client.updateComponent(this, uidl, true)) { - rendering = false; - return; - } - setEnabled(!uidl.getBooleanAttribute("disabled")); - - clickEventHandler.handleEventHandlerRegistration(client); - if (uidl.hasAttribute("style")) { - componentStyleNames = uidl.getStringAttribute("style").split(" "); - } else { - componentStyleNames = new String[0]; - } - - setLocked(uidl.getBooleanAttribute("locked")); - - setPositionReversed(uidl.getBooleanAttribute("reversed")); - - setStylenames(); - - position = uidl.getStringAttribute("position"); - setSplitPosition(position); - - final VPaintableWidget newFirstChildPaintable = client - .getPaintable(uidl.getChildUIDL(0)); - final VPaintableWidget newSecondChildPaintable = client - .getPaintable(uidl.getChildUIDL(1)); - Widget newFirstChild = newFirstChildPaintable.getWidgetForPaintable(); - Widget newSecondChild = newSecondChildPaintable.getWidgetForPaintable(); - - if (firstChild != newFirstChild) { - if (firstChild != null) { - client.unregisterPaintable(VPaintableMap.get(client) - .getPaintable(firstChild)); - } - setFirstWidget(newFirstChild); - } - if (secondChild != newSecondChild) { - if (secondChild != null) { - client.unregisterPaintable(VPaintableMap.get(client) - .getPaintable(secondChild)); - } - setSecondWidget(newSecondChild); - } - newFirstChildPaintable.updateFromUIDL(uidl.getChildUIDL(0), client); - newSecondChildPaintable.updateFromUIDL(uidl.getChildUIDL(1), client); - - renderInformation.updateSize(getElement()); - - // This is needed at least for cases like #3458 to take - // appearing/disappearing scrollbars into account. - client.runDescendentsLayout(this); - - rendering = false; - - } - @Override public boolean remove(Widget w) { boolean removed = super.remove(w); @@ -331,7 +219,7 @@ public class VSplitPanel extends ComplexPanel implements Container, return removed; } - private void setLocked(boolean newValue) { + void setLocked(boolean newValue) { if (locked != newValue) { locked = newValue; splitterSize = -1; @@ -339,7 +227,7 @@ public class VSplitPanel extends ComplexPanel implements Container, } } - private void setPositionReversed(boolean reversed) { + void setPositionReversed(boolean reversed) { if (positionReversed != reversed) { if (orientation == ORIENTATION_HORIZONTAL) { DOM.setStyleAttribute(splitter, "right", ""); @@ -353,7 +241,7 @@ public class VSplitPanel extends ComplexPanel implements Container, } } - private void setSplitPosition(String pos) { + void setSplitPosition(String pos) { if (pos == null) { return; } @@ -473,7 +361,7 @@ public class VSplitPanel extends ComplexPanel implements Container, } - private void setFirstWidget(Widget w) { + void setFirstWidget(Widget w) { if (firstChild != null) { firstChild.removeFromParent(); } @@ -481,7 +369,7 @@ public class VSplitPanel extends ComplexPanel implements Container, firstChild = w; } - private void setSecondWidget(Widget w) { + void setSecondWidget(Widget w) { if (secondChild != null) { secondChild.removeFromParent(); } @@ -791,10 +679,6 @@ public class VSplitPanel extends ComplexPanel implements Container, } - public void updateCaption(VPaintableWidget component, UIDL uidl) { - // TODO Implement caption handling - } - /** * Updates the new split position back to server. */ @@ -810,7 +694,7 @@ public class VSplitPanel extends ComplexPanel implements Container, client.updateVariable(id, "position", pos, immediate); } - private void setStylenames() { + void setStylenames() { final String splitterSuffix = (orientation == ORIENTATION_HORIZONTAL ? "-hsplitter" : "-vsplitter"); final String firstContainerSuffix = "-first-container"; diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java new file mode 100644 index 0000000000..1ff066d004 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java @@ -0,0 +1,140 @@ +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.dom.client.NativeEvent; +import com.google.gwt.event.dom.client.DomEvent.Type; +import com.google.gwt.event.shared.EventHandler; +import com.google.gwt.event.shared.HandlerRegistration; +import com.google.gwt.user.client.Element; +import com.google.gwt.user.client.Event; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.VPaintableMap; +import com.vaadin.terminal.gwt.client.VPaintableWidget; + +public abstract class VAbstractSplitPanelPaintable extends + VAbstractPaintableWidgetContainer { + + public static final String SPLITTER_CLICK_EVENT_IDENTIFIER = "sp_click"; + + public void updateCaption(VPaintableWidget component, UIDL uidl) { + // TODO Implement caption handling + } + + ClickEventHandler clickEventHandler = new ClickEventHandler(this, + SPLITTER_CLICK_EVENT_IDENTIFIER) { + + @Override + protected HandlerRegistration registerHandler( + H handler, Type type) { + if ((Event.getEventsSunk(getWidgetForPaintable().splitter) & Event + .getTypeInt(type.getName())) != 0) { + // If we are already sinking the event for the splitter we do + // not want to additionally sink it for the root element + return getWidgetForPaintable().addHandler(handler, type); + } else { + return getWidgetForPaintable().addDomHandler(handler, type); + } + } + + @Override + public void onContextMenu( + com.google.gwt.event.dom.client.ContextMenuEvent event) { + Element target = event.getNativeEvent().getEventTarget().cast(); + if (getWidgetForPaintable().splitter.isOrHasChild(target)) { + super.onContextMenu(event); + } + }; + + @Override + protected void fireClick(NativeEvent event) { + Element target = event.getEventTarget().cast(); + if (getWidgetForPaintable().splitter.isOrHasChild(target)) { + super.fireClick(event); + } + } + + @Override + protected Element getRelativeToElement() { + return null; + } + + }; + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + getWidgetForPaintable().client = client; + getWidgetForPaintable().id = uidl.getId(); + getWidgetForPaintable().rendering = true; + + getWidgetForPaintable().immediate = uidl.hasAttribute("immediate"); + + if (client.updateComponent(this, uidl, true)) { + getWidgetForPaintable().rendering = false; + return; + } + getWidgetForPaintable().setEnabled( + !uidl.getBooleanAttribute("disabled")); + + clickEventHandler.handleEventHandlerRegistration(client); + if (uidl.hasAttribute("style")) { + getWidgetForPaintable().componentStyleNames = uidl + .getStringAttribute("style").split(" "); + } else { + getWidgetForPaintable().componentStyleNames = new String[0]; + } + + getWidgetForPaintable().setLocked(uidl.getBooleanAttribute("locked")); + + getWidgetForPaintable().setPositionReversed( + uidl.getBooleanAttribute("reversed")); + + getWidgetForPaintable().setStylenames(); + + getWidgetForPaintable().position = uidl.getStringAttribute("position"); + getWidgetForPaintable().setSplitPosition( + getWidgetForPaintable().position); + + final VPaintableWidget newFirstChildPaintable = client + .getPaintable(uidl.getChildUIDL(0)); + final VPaintableWidget newSecondChildPaintable = client + .getPaintable(uidl.getChildUIDL(1)); + Widget newFirstChild = newFirstChildPaintable.getWidgetForPaintable(); + Widget newSecondChild = newSecondChildPaintable.getWidgetForPaintable(); + + if (getWidgetForPaintable().firstChild != newFirstChild) { + if (getWidgetForPaintable().firstChild != null) { + client.unregisterPaintable(VPaintableMap.get(client) + .getPaintable(getWidgetForPaintable().firstChild)); + } + getWidgetForPaintable().setFirstWidget(newFirstChild); + } + if (getWidgetForPaintable().secondChild != newSecondChild) { + if (getWidgetForPaintable().secondChild != null) { + client.unregisterPaintable(VPaintableMap.get(client) + .getPaintable(getWidgetForPaintable().secondChild)); + } + getWidgetForPaintable().setSecondWidget(newSecondChild); + } + newFirstChildPaintable.updateFromUIDL(uidl.getChildUIDL(0), client); + newSecondChildPaintable.updateFromUIDL(uidl.getChildUIDL(1), client); + + getWidgetForPaintable().renderInformation + .updateSize(getWidgetForPaintable().getElement()); + + // This is needed at least for cases like #3458 to take + // appearing/disappearing scrollbars into account. + client.runDescendentsLayout(getWidgetForPaintable()); + + getWidgetForPaintable().rendering = false; + + } + + @Override + public VAbstractSplitPanel getWidgetForPaintable() { + return (VAbstractSplitPanel) super.getWidgetForPaintable(); + } + + @Override + protected abstract VAbstractSplitPanel createWidget(); + +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VHorizontalSplitPanelPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VHorizontalSplitPanelPaintable.java new file mode 100644 index 0000000000..2340ceb0b6 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VHorizontalSplitPanelPaintable.java @@ -0,0 +1,13 @@ +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; + +public class VHorizontalSplitPanelPaintable extends + VAbstractSplitPanelPaintable { + + @Override + protected VAbstractSplitPanel createWidget() { + return GWT.create(VSplitPanelHorizontal.class); + } + +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VSplitPanelHorizontal.java b/src/com/vaadin/terminal/gwt/client/ui/VSplitPanelHorizontal.java index ff1e2e6b78..3902f064a5 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VSplitPanelHorizontal.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VSplitPanelHorizontal.java @@ -4,9 +4,9 @@ package com.vaadin.terminal.gwt.client.ui; -public class VSplitPanelHorizontal extends VSplitPanel { +public class VSplitPanelHorizontal extends VAbstractSplitPanel { public VSplitPanelHorizontal() { - super(VSplitPanel.ORIENTATION_HORIZONTAL); + super(VAbstractSplitPanel.ORIENTATION_HORIZONTAL); } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VSplitPanelVertical.java b/src/com/vaadin/terminal/gwt/client/ui/VSplitPanelVertical.java index dcf7622e50..e61f8cf5e5 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VSplitPanelVertical.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VSplitPanelVertical.java @@ -4,9 +4,9 @@ package com.vaadin.terminal.gwt.client.ui; -public class VSplitPanelVertical extends VSplitPanel { +public class VSplitPanelVertical extends VAbstractSplitPanel { public VSplitPanelVertical() { - super(VSplitPanel.ORIENTATION_VERTICAL); + super(VAbstractSplitPanel.ORIENTATION_VERTICAL); } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VVerticalSplitPanelPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VVerticalSplitPanelPaintable.java new file mode 100644 index 0000000000..d60a3185af --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/VVerticalSplitPanelPaintable.java @@ -0,0 +1,12 @@ +package com.vaadin.terminal.gwt.client.ui; + +import com.google.gwt.core.client.GWT; + +public class VVerticalSplitPanelPaintable extends VAbstractSplitPanelPaintable { + + @Override + protected VAbstractSplitPanel createWidget() { + return GWT.create(VSplitPanelVertical.class); + } + +} diff --git a/src/com/vaadin/ui/AbstractSplitPanel.java b/src/com/vaadin/ui/AbstractSplitPanel.java index e0a2d24aaa..e03e73a781 100644 --- a/src/com/vaadin/ui/AbstractSplitPanel.java +++ b/src/com/vaadin/ui/AbstractSplitPanel.java @@ -15,7 +15,7 @@ import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Sizeable; import com.vaadin.terminal.gwt.client.MouseEventDetails; -import com.vaadin.terminal.gwt.client.ui.VSplitPanel; +import com.vaadin.terminal.gwt.client.ui.VAbstractSplitPanelPaintable; import com.vaadin.tools.ReflectTools; /** @@ -43,7 +43,7 @@ public abstract class AbstractSplitPanel extends AbstractLayout { private boolean locked = false; - private static final String SPLITTER_CLICK_EVENT = VSplitPanel.SPLITTER_CLICK_EVENT_IDENTIFIER; + private static final String SPLITTER_CLICK_EVENT = VAbstractSplitPanelPaintable.SPLITTER_CLICK_EVENT_IDENTIFIER; /** * Modifiable and Serializable Iterator for the components, used by diff --git a/src/com/vaadin/ui/HorizontalSplitPanel.java b/src/com/vaadin/ui/HorizontalSplitPanel.java index d9368635df..d4a1e7cc0e 100644 --- a/src/com/vaadin/ui/HorizontalSplitPanel.java +++ b/src/com/vaadin/ui/HorizontalSplitPanel.java @@ -3,7 +3,7 @@ */ package com.vaadin.ui; -import com.vaadin.terminal.gwt.client.ui.VSplitPanelHorizontal; +import com.vaadin.terminal.gwt.client.ui.VHorizontalSplitPanelPaintable; import com.vaadin.ui.ClientWidget.LoadStyle; /** @@ -29,7 +29,7 @@ import com.vaadin.ui.ClientWidget.LoadStyle; * @VERSION@ * @since 6.5 */ -@ClientWidget(value = VSplitPanelHorizontal.class, loadStyle = LoadStyle.EAGER) +@ClientWidget(value = VHorizontalSplitPanelPaintable.class, loadStyle = LoadStyle.EAGER) public class HorizontalSplitPanel extends AbstractSplitPanel { public HorizontalSplitPanel() { super(); diff --git a/src/com/vaadin/ui/SplitPanel.java b/src/com/vaadin/ui/SplitPanel.java index bae1bf7ce0..f4c5b7e666 100644 --- a/src/com/vaadin/ui/SplitPanel.java +++ b/src/com/vaadin/ui/SplitPanel.java @@ -6,7 +6,7 @@ package com.vaadin.ui; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; -import com.vaadin.terminal.gwt.client.ui.VSplitPanelHorizontal; +import com.vaadin.terminal.gwt.client.ui.VHorizontalSplitPanelPaintable; import com.vaadin.ui.ClientWidget.LoadStyle; /** @@ -23,7 +23,7 @@ import com.vaadin.ui.ClientWidget.LoadStyle; * {@link VerticalSplitPanel} instead. */ @Deprecated -@ClientWidget(value = VSplitPanelHorizontal.class, loadStyle = LoadStyle.EAGER) +@ClientWidget(value = VHorizontalSplitPanelPaintable.class, loadStyle = LoadStyle.EAGER) public class SplitPanel extends AbstractSplitPanel { /* Predefined orientations */ diff --git a/src/com/vaadin/ui/VerticalSplitPanel.java b/src/com/vaadin/ui/VerticalSplitPanel.java index 699bd9287c..46e9d681e8 100644 --- a/src/com/vaadin/ui/VerticalSplitPanel.java +++ b/src/com/vaadin/ui/VerticalSplitPanel.java @@ -3,7 +3,7 @@ */ package com.vaadin.ui; -import com.vaadin.terminal.gwt.client.ui.VSplitPanelVertical; +import com.vaadin.terminal.gwt.client.ui.VVerticalSplitPanelPaintable; import com.vaadin.ui.ClientWidget.LoadStyle; /** @@ -23,7 +23,7 @@ import com.vaadin.ui.ClientWidget.LoadStyle; * * */ -@ClientWidget(value = VSplitPanelVertical.class, loadStyle = LoadStyle.EAGER) +@ClientWidget(value = VVerticalSplitPanelPaintable.class, loadStyle = LoadStyle.EAGER) public class VerticalSplitPanel extends AbstractSplitPanel { public VerticalSplitPanel() { -- 2.39.5