diff options
author | Henri Sara <hesara@vaadin.com> | 2015-09-16 17:12:48 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-09-17 14:34:08 +0000 |
commit | e71f6cfd817ffddb7c9cc4a7855d248a859d837f (patch) | |
tree | b8122060088b46386f5ed63ce6d392c6961cf595 /client | |
parent | be5c159ee995ad619f5cdd68695db59ea3cd6fee (diff) | |
download | vaadin-framework-e71f6cfd817ffddb7c9cc4a7855d248a859d837f.tar.gz vaadin-framework-e71f6cfd817ffddb7c9cc4a7855d248a859d837f.zip |
Make ordered layout Slot customizable (#18703)
Change-Id: If425d7196e9393f87659462d5b4488549988ee0d
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/ui/orderedlayout/Slot.java | 35 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java | 39 |
2 files changed, 69 insertions, 5 deletions
diff --git a/client/src/com/vaadin/client/ui/orderedlayout/Slot.java b/client/src/com/vaadin/client/ui/orderedlayout/Slot.java index b97cf73989..5ecda3dca4 100644 --- a/client/src/com/vaadin/client/ui/orderedlayout/Slot.java +++ b/client/src/com/vaadin/client/ui/orderedlayout/Slot.java @@ -41,11 +41,12 @@ import com.vaadin.shared.ui.AlignmentInfo; /** * Represents a slot which contains the actual widget in the layout. */ -public final class Slot extends SimplePanel { +public class Slot extends SimplePanel { private static final String ALIGN_CLASS_PREFIX = "v-align-"; - private final VAbstractOrderedLayout layout; + // this must be set at construction time and not changed afterwards + private VAbstractOrderedLayout layout; public static final String SLOT_CLASSNAME = "v-slot"; @@ -90,13 +91,41 @@ public final class Slot extends SimplePanel { /** * Constructs a slot. * + * When using this constructor, the layout and widget must be set before any + * other operations are performed on the slot. + */ + public Slot() { + setStyleName(SLOT_CLASSNAME); + } + + /** + * Set the layout in which this slot is. This method must be called exactly + * once at slot construction time when using the default constructor. + * + * The method should normally only be called by + * {@link VAbstractOrderedLayout#createSlot(Widget)}. + * + * @since + * @param layout + * the layout containing the slot + */ + public void setLayout(VAbstractOrderedLayout layout) { + this.layout = layout; + } + + /** + * Constructs a slot. + * * @param layout * The layout to which this slot belongs * @param widget * The widget to put in the slot + * @deprecated use {@link GWT#create(Class)}, {@link #setWidget(Widget)} and + * {@link #setLayout(VAbstractOrderedLayout)} instead */ + @Deprecated public Slot(VAbstractOrderedLayout layout, Widget widget) { - this.layout = layout; + setLayout(layout); setStyleName(SLOT_CLASSNAME); setWidget(widget); } diff --git a/client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java b/client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java index 2e6d4cf5c8..53ba9ddb28 100644 --- a/client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java +++ b/client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java @@ -18,6 +18,7 @@ package com.vaadin.client.ui.orderedlayout; import java.util.HashMap; import java.util.Map; +import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.Style; @@ -209,8 +210,23 @@ public class VAbstractOrderedLayout extends FlowPanel { */ public void removeWidget(Widget widget) { Slot slot = widgetToSlot.get(widget); + removeSlot(slot); + } + + /** + * Remove a slot from the layout. + * + * This method is called automatically by {@link #removeWidget(Widget)} and + * should not be called directly by the user. When overridden, the super + * method must be called. + * + * @since + * @param Slot + * to remove + */ + protected void removeSlot(Slot slot) { remove(slot); - widgetToSlot.remove(widget); + widgetToSlot.remove(slot.getWidget()); } /** @@ -225,13 +241,32 @@ public class VAbstractOrderedLayout extends FlowPanel { public Slot getSlot(Widget widget) { Slot slot = widgetToSlot.get(widget); if (slot == null) { - slot = new Slot(this, widget); + slot = createSlot(widget); widgetToSlot.put(widget, slot); } return slot; } /** + * Create a slot to be added to the layout. + * + * This method is called automatically by {@link #getSlot(Widget)} when a + * new slot is needed. It should not be called directly by the user, but can + * be overridden to customize slot creation. + * + * @since + * @param widget + * the widget for which a slot is being created + * @return created Slot + */ + protected Slot createSlot(Widget widget) { + Slot slot = GWT.create(Slot.class); + slot.setLayout(this); + slot.setWidget(widget); + return slot; + } + + /** * Gets a slot based on the widget element. If no slot is found then null is * returned. * |