import java.util.LinkedList;
+import com.google.gwt.core.client.GWT;
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.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.ComponentConnector;
-import com.vaadin.terminal.gwt.client.ConnectorMap;
+import com.vaadin.terminal.gwt.client.ComponentState;
+import com.vaadin.terminal.gwt.client.Connector;
+import com.vaadin.terminal.gwt.client.ConnectorHierarchyChangedEvent;
import com.vaadin.terminal.gwt.client.UIDL;
public abstract class AbstractSplitPanelConnector extends
AbstractComponentContainerConnector implements SimpleManagedLayout {
+ public static class AbstractSplitPanelState extends ComponentState {
+ private Connector firstChild = null;
+ private Connector secondChild = null;
+
+ public boolean hasFirstChild() {
+ return firstChild != null;
+ }
+
+ public boolean hasSecondChild() {
+ return secondChild != null;
+ }
+
+ public Connector getFirstChild() {
+ return firstChild;
+ }
+
+ public void setFirstChild(Connector firstChild) {
+ this.firstChild = firstChild;
+ }
+
+ public Connector getSecondChild() {
+ return secondChild;
+ }
+
+ public void setSecondChild(Connector secondChild) {
+ this.secondChild = secondChild;
+ }
+
+ }
+
public static final String SPLITTER_CLICK_EVENT_IDENTIFIER = "sp_click";
public void updateCaption(ComponentConnector component, UIDL uidl) {
getWidget().position = uidl.getStringAttribute("position");
- final ComponentConnector newFirstChildPaintable = client
- .getPaintable(uidl.getChildUIDL(0));
- final ComponentConnector newSecondChildPaintable = client
- .getPaintable(uidl.getChildUIDL(1));
- Widget newFirstChild = newFirstChildPaintable.getWidget();
- Widget newSecondChild = newSecondChildPaintable.getWidget();
-
- if (getWidget().firstChild != newFirstChild) {
- if (getWidget().firstChild != null) {
- client.unregisterPaintable(ConnectorMap.get(client)
- .getConnector(getWidget().firstChild));
- }
- getWidget().setFirstWidget(newFirstChild);
- }
- if (getWidget().secondChild != newSecondChild) {
- if (getWidget().secondChild != null) {
- client.unregisterPaintable(ConnectorMap.get(client)
- .getConnector(getWidget().secondChild));
- }
- getWidget().setSecondWidget(newSecondChild);
+ for (int childIndex = 0; childIndex < getChildren().size(); childIndex++) {
+ getChildren().get(childIndex).updateFromUIDL(
+ uidl.getChildUIDL(childIndex++), client);
}
- newFirstChildPaintable.updateFromUIDL(uidl.getChildUIDL(0), client);
- newSecondChildPaintable.updateFromUIDL(uidl.getChildUIDL(1), client);
// This is needed at least for cases like #3458 to take
// appearing/disappearing scrollbars into account.
@Override
protected abstract VAbstractSplitPanel createWidget();
+ @Override
+ public AbstractSplitPanelState getState() {
+ return (AbstractSplitPanelState) super.getState();
+ }
+
+ @Override
+ protected AbstractSplitPanelState createState() {
+ return GWT.create(AbstractSplitPanelState.class);
+ }
+
+ private ComponentConnector getFirstChild() {
+ return (ComponentConnector) getState().getFirstChild();
+ }
+
+ private ComponentConnector getSecondChild() {
+ return (ComponentConnector) getState().getSecondChild();
+ }
+
+ @Override
+ public void connectorHierarchyChanged(ConnectorHierarchyChangedEvent event) {
+ super.connectorHierarchyChanged(event);
+
+ Widget newFirstChildWidget = null;
+ if (getFirstChild() != null) {
+ newFirstChildWidget = getFirstChild().getWidget();
+ }
+ getWidget().setFirstWidget(newFirstChildWidget);
+
+ Widget newSecondChildWidget = null;
+ if (getSecondChild() != null) {
+ newSecondChildWidget = getSecondChild().getWidget();
+ }
+ getWidget().setSecondWidget(newSecondChildWidget);
+ }
}
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.Sizeable;
+import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.terminal.gwt.client.ui.AbstractSplitPanelConnector;
+import com.vaadin.terminal.gwt.client.ui.AbstractSplitPanelConnector.AbstractSplitPanelState;
import com.vaadin.tools.ReflectTools;
/**
*/
public abstract class AbstractSplitPanel extends AbstractLayout {
- private Component firstComponent;
-
- private Component secondComponent;
-
private int pos = 50;
private Unit posUnit = Unit.PERCENTAGE;
return null;
}
i++;
+ AbstractSplitPanelState state = getState();
if (i == 1) {
- return firstComponent == null ? secondComponent
- : firstComponent;
+ return (getFirstComponent() == null ? getSecondComponent()
+ : getFirstComponent());
} else if (i == 2) {
- return secondComponent;
+ return (Component) state.getSecondChild();
}
return null;
}
public void remove() {
if (i == 1) {
- if (firstComponent != null) {
+ if (getFirstComponent() != null) {
setFirstComponent(null);
i = 0;
} else {
*/
@Override
public void addComponent(Component c) {
- if (firstComponent == null) {
- firstComponent = c;
- } else if (secondComponent == null) {
- secondComponent = c;
+ if (getFirstComponent() == null) {
+ setFirstComponent(c);
+ } else if (getSecondComponent() == null) {
+ setSecondComponent(c);
} else {
throw new UnsupportedOperationException(
"Split panel can contain only two components");
}
- super.addComponent(c);
- requestRepaint();
}
+ /**
+ * Sets the first component of this split panel. Depending on the direction
+ * the first component is shown at the top or to the left.
+ *
+ * @param c
+ * The component to use as first component
+ */
public void setFirstComponent(Component c) {
- if (firstComponent == c) {
+ if (getFirstComponent() == c) {
// Nothing to do
return;
}
- if (firstComponent != null) {
+ if (getFirstComponent() != null) {
// detach old
- removeComponent(firstComponent);
+ removeComponent(getFirstComponent());
+ }
+ getState().setFirstChild(c);
+ if (c != null) {
+ super.addComponent(c);
}
- firstComponent = c;
- super.addComponent(c);
+
requestRepaint();
}
+ /**
+ * Sets the second component of this split panel. Depending on the direction
+ * the second component is shown at the bottom or to the left.
+ *
+ * @param c
+ * The component to use as first component
+ */
public void setSecondComponent(Component c) {
- if (c == secondComponent) {
+ if (getSecondComponent() == c) {
// Nothing to do
return;
}
- if (secondComponent != null) {
+ if (getSecondComponent() != null) {
// detach old
- removeComponent(secondComponent);
+ removeComponent(getSecondComponent());
+ }
+ getState().setSecondChild(c);
+ if (c != null) {
+ super.addComponent(c);
}
- secondComponent = c;
- super.addComponent(c);
requestRepaint();
}
/**
- * @return the first component of this SplitPanel.
+ * Gets the first component of this split panel. Depending on the direction
+ * this is either the component shown at the top or to the left.
+ *
+ * @return the first component of this split panel
*/
public Component getFirstComponent() {
- return firstComponent;
+ return (Component) getState().getFirstChild();
}
/**
- * @return the second component of this SplitPanel.
+ * Gets the second component of this split panel. Depending on the direction
+ * this is either the component shown at the top or to the left.
+ *
+ * @return the second component of this split panel
*/
public Component getSecondComponent() {
- return secondComponent;
+ return (Component) getState().getSecondChild();
}
/**
@Override
public void removeComponent(Component c) {
super.removeComponent(c);
- if (c == firstComponent) {
- firstComponent = null;
- } else if (c == secondComponent) {
- secondComponent = null;
+ if (c == getFirstComponent()) {
+ getState().setFirstChild(null);
+ } else if (c == getSecondComponent()) {
+ getState().setSecondChild(null);
}
requestRepaint();
}
*/
public int getComponentCount() {
int count = 0;
- if (firstComponent != null) {
+ if (getFirstComponent() != null) {
count++;
}
- if (secondComponent != null) {
+ if (getSecondComponent() != null) {
count++;
}
return count;
target.addAttribute("reversed", posReversed);
- if (firstComponent != null) {
- firstComponent.paint(target);
- } else {
- VerticalLayout temporaryComponent = new VerticalLayout();
- temporaryComponent.setParent(this);
- temporaryComponent.paint(target);
+ if (getFirstComponent() != null) {
+ getFirstComponent().paint(target);
}
- if (secondComponent != null) {
- secondComponent.paint(target);
- } else {
- VerticalLayout temporaryComponent = new VerticalLayout();
- temporaryComponent.setParent(this);
- temporaryComponent.paint(target);
+ if (getSecondComponent() != null) {
+ getSecondComponent().paint(target);
}
}
/* Documented in superclass */
public void replaceComponent(Component oldComponent, Component newComponent) {
- if (oldComponent == firstComponent) {
+ if (oldComponent == getFirstComponent()) {
setFirstComponent(newComponent);
- } else if (oldComponent == secondComponent) {
+ } else if (oldComponent == getSecondComponent()) {
setSecondComponent(newComponent);
}
requestRepaint();
removeListener(SPLITTER_CLICK_EVENT, SplitterClickEvent.class, listener);
}
+ @Override
+ public AbstractSplitPanelState getState() {
+ return (AbstractSplitPanelState) super.getState();
+ }
+
+ @Override
+ protected ComponentState createState() {
+ return new AbstractSplitPanelState();
+ }
}