VConsole.log(oldChildren);
String newChildren = "* New children: ";
- ComponentContainerConnector parent = (ComponentContainerConnector) event
+ HasComponentsConnector parent = (HasComponentsConnector) event
.getConnector();
for (ComponentConnector child : parent.getChildComponents()) {
newChildren += Util.getConnectorString(child) + " ";
continue;
}
- if (parentConnector instanceof ComponentContainerConnector) {
- ComponentContainerConnector ccc = (ComponentContainerConnector) parentConnector;
+ if (parentConnector instanceof HasComponentsConnector) {
+ HasComponentsConnector ccc = (HasComponentsConnector) parentConnector;
List<ComponentConnector> oldComponents = ccc
.getChildComponents();
if (!Util.collectionsEquals(oldComponents,
} else if (!newComponents.isEmpty()) {
VConsole.error("Hierachy claims "
+ Util.getConnectorString(parentConnector)
- + " has component children even though it isn't a ComponentContainerConnector");
+ + " has component children even though it isn't a HasComponentsConnector");
}
parentConnector.setChildren(newChildren);
* Create an artificial hierarchy event for containers to give
* it a chance to clean up after its children if it has any
*/
- if (connector instanceof ComponentContainerConnector) {
- ComponentContainerConnector ccc = (ComponentContainerConnector) connector;
+ if (connector instanceof HasComponentsConnector) {
+ HasComponentsConnector ccc = (HasComponentsConnector) connector;
List<ComponentConnector> oldChildren = ccc
.getChildComponents();
if (!oldChildren.isEmpty()) {
/*
- * ComponentContainerConnector has a separate child
+ * HasComponentsConnector has a separate child
* component list that should also be cleared
*/
ccc.setChildComponents(Collections
+++ /dev/null
-/*
- * Copyright 2011 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.client;
-
-import java.util.List;
-
-import com.google.gwt.event.shared.HandlerRegistration;
-import com.google.gwt.user.client.ui.HasWidgets;
-import com.vaadin.client.ConnectorHierarchyChangeEvent.ConnectorHierarchyChangeHandler;
-
-/**
- * An interface used by client-side connectors whose widget is a component
- * container (implements {@link HasWidgets}).
- */
-public interface ComponentContainerConnector extends ServerConnector {
-
- /**
- * 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 connector
- * Child component for which service is requested.
- */
- void updateCaption(ComponentConnector connector);
-
- /**
- * Returns the children for this connector.
- * <p>
- * The children for this connector are defined as all
- * {@link ComponentConnector}s whose parent is this
- * {@link ComponentContainerConnector}.
- * </p>
- *
- * @return A collection of children for this connector. An empty collection
- * if there are no children. Never returns null.
- */
- public List<ComponentConnector> getChildComponents();
-
- /**
- * Sets the children for this connector. This method should only be called
- * by the framework to ensure that the connector hierarchy on the client
- * side and the server side are in sync.
- * <p>
- * Note that calling this method does not call
- * {@link ConnectorHierarchyChangeHandler#onConnectorHierarchyChange(ConnectorHierarchyChangeEvent)}
- * . The event method is called only when the hierarchy has been updated for
- * all connectors.
- *
- * @param children
- * The new child connectors
- */
- public void setChildComponents(List<ComponentConnector> children);
-
- /**
- * Adds a handler that is called whenever the child hierarchy of this
- * connector has been updated by the server.
- *
- * @param handler
- * The handler that should be added.
- * @return A handler registration reference that can be used to unregister
- * the handler
- */
- public HandlerRegistration addConnectorHierarchyChangeHandler(
- ConnectorHierarchyChangeHandler handler);
-
-}
public static final Type<ConnectorHierarchyChangeHandler> TYPE = new Type<ConnectorHierarchyChangeHandler>();
List<ComponentConnector> oldChildren;
- private ComponentContainerConnector parent;
+ private HasComponentsConnector parent;
public ConnectorHierarchyChangeEvent() {
}
}
/**
- * Returns the {@link ComponentContainerConnector} for which this event
+ * Returns the {@link HasComponentsConnector} for which this event
* occurred.
*
- * @return The {@link ComponentContainerConnector} whose child collection
+ * @return The {@link HasComponentsConnector} whose child collection
* has changed. Never returns null.
*/
- public ComponentContainerConnector getParent() {
+ public HasComponentsConnector getParent() {
return parent;
}
/**
- * Sets the {@link ComponentContainerConnector} for which this event
+ * Sets the {@link HasComponentsConnector} for which this event
* occurred.
*
* @param The
- * {@link ComponentContainerConnector} whose child collection has
+ * {@link HasComponentsConnector} whose child collection has
* changed.
*/
- public void setParent(ComponentContainerConnector parent) {
+ public void setParent(HasComponentsConnector parent) {
this.parent = parent;
}
--- /dev/null
+/*
+ * Copyright 2011 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.client;
+
+import java.util.List;
+
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.user.client.ui.HasWidgets;
+import com.vaadin.client.ConnectorHierarchyChangeEvent.ConnectorHierarchyChangeHandler;
+
+/**
+ * An interface used by client-side connectors whose widget is a component
+ * container (implements {@link HasWidgets}).
+ */
+public interface HasComponentsConnector extends ServerConnector {
+
+ /**
+ * 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 connector
+ * Child component for which service is requested.
+ */
+ void updateCaption(ComponentConnector connector);
+
+ /**
+ * Returns the children for this connector.
+ * <p>
+ * The children for this connector are defined as all {@link HasComponents}s
+ * whose parent is this {@link HasComponentsConnector}.
+ * </p>
+ *
+ * @return A collection of children for this connector. An empty collection
+ * if there are no children. Never returns null.
+ */
+ public List<ComponentConnector> getChildComponents();
+
+ /**
+ * Sets the children for this connector. This method should only be called
+ * by the framework to ensure that the connector hierarchy on the client
+ * side and the server side are in sync.
+ * <p>
+ * Note that calling this method does not call
+ * {@link ConnectorHierarchyChangeHandler#onConnectorHierarchyChange(ConnectorHierarchyChangeEvent)}
+ * . The event method is called only when the hierarchy has been updated for
+ * all connectors.
+ *
+ * @param children
+ * The new child connectors
+ */
+ public void setChildComponents(List<ComponentConnector> children);
+
+ /**
+ * Adds a handler that is called whenever the child hierarchy of this
+ * connector has been updated by the server.
+ *
+ * @param handler
+ * The handler that should be added.
+ * @return A handler registration reference that can be used to unregister
+ * the handler
+ */
+ public HandlerRegistration addConnectorHierarchyChangeHandler(
+ ConnectorHierarchyChangeHandler handler);
+
+}
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.ComponentConnector;
-import com.vaadin.client.ComponentContainerConnector;
+import com.vaadin.client.HasComponentsConnector;
import com.vaadin.client.ConnectorMap;
import com.vaadin.client.LayoutManager;
import com.vaadin.client.ServerConnector;
// Set captions
if (delegateCaptionHandling()) {
ServerConnector parent = getParent();
- if (parent instanceof ComponentContainerConnector) {
- ((ComponentContainerConnector) parent).updateCaption(this);
+ if (parent instanceof HasComponentsConnector) {
+ ((HasComponentsConnector) parent).updateCaption(this);
} else if (parent == null && !(this instanceof UIConnector)) {
VConsole.error("Parent of connector "
+ Util.getConnectorString(this)
// make sure the caption has or has not v-disabled style
if (delegateCaptionHandling()) {
ServerConnector parent = getParent();
- if (parent instanceof ComponentContainerConnector) {
- ((ComponentContainerConnector) parent).updateCaption(this);
+ if (parent instanceof HasComponentsConnector) {
+ ((HasComponentsConnector) parent).updateCaption(this);
} else if (parent == null && !(this instanceof UIConnector)) {
VConsole.error("Parent of connector "
+ Util.getConnectorString(this)
/*
- * Copyright 2011 Vaadin Ltd.
+ * Copyright 2012 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
*/
package com.vaadin.client.ui;
-import java.util.Collections;
-import java.util.List;
-
-import com.google.gwt.event.shared.HandlerRegistration;
-import com.vaadin.client.ComponentConnector;
-import com.vaadin.client.ComponentContainerConnector;
-import com.vaadin.client.ConnectorHierarchyChangeEvent;
-import com.vaadin.client.ConnectorHierarchyChangeEvent.ConnectorHierarchyChangeHandler;
-
+/**
+ * Client side connector for subclasses of AbstractComponentConnector.
+ *
+ * @since 7.0
+ */
public abstract class AbstractComponentContainerConnector extends
- AbstractComponentConnector implements ComponentContainerConnector,
- ConnectorHierarchyChangeHandler {
-
- List<ComponentConnector> childComponents;
-
- private final boolean debugLogging = false;
-
- /**
- * Default constructor
- */
- public AbstractComponentContainerConnector() {
- addConnectorHierarchyChangeHandler(this);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.client.ComponentContainerConnector#getChildren()
- */
- @Override
- public List<ComponentConnector> getChildComponents() {
- if (childComponents == null) {
- return Collections.emptyList();
- }
-
- return childComponents;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.client.ComponentContainerConnector#setChildren
- * (java.util.Collection)
- */
- @Override
- public void setChildComponents(List<ComponentConnector> childComponents) {
- this.childComponents = childComponents;
- }
+ AbstractHasComponentsConnector {
- @Override
- public HandlerRegistration addConnectorHierarchyChangeHandler(
- ConnectorHierarchyChangeHandler handler) {
- return ensureHandlerManager().addHandler(
- ConnectorHierarchyChangeEvent.TYPE, handler);
- }
}
--- /dev/null
+/*
+ * Copyright 2011 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.client.ui;
+
+import java.util.Collections;
+import java.util.List;
+
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.vaadin.client.ComponentConnector;
+import com.vaadin.client.HasComponentsConnector;
+import com.vaadin.client.ConnectorHierarchyChangeEvent;
+import com.vaadin.client.ConnectorHierarchyChangeEvent.ConnectorHierarchyChangeHandler;
+
+public abstract class AbstractHasComponentsConnector extends
+ AbstractComponentConnector implements HasComponentsConnector,
+ ConnectorHierarchyChangeHandler {
+
+ List<ComponentConnector> childComponents;
+
+ /**
+ * Default constructor
+ */
+ public AbstractHasComponentsConnector() {
+ addConnectorHierarchyChangeHandler(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.client.HasComponentsConnector#getChildren()
+ */
+ @Override
+ public List<ComponentConnector> getChildComponents() {
+ if (childComponents == null) {
+ return Collections.emptyList();
+ }
+
+ return childComponents;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.client.HasComponentsConnector#setChildren
+ * (java.util.Collection)
+ */
+ @Override
+ public void setChildComponents(List<ComponentConnector> childComponents) {
+ this.childComponents = childComponents;
+ }
+
+ @Override
+ public HandlerRegistration addConnectorHierarchyChangeHandler(
+ ConnectorHierarchyChangeHandler handler) {
+ return ensureHandlerManager().addHandler(
+ ConnectorHierarchyChangeEvent.TYPE, handler);
+ }
+}
--- /dev/null
+/*
+ * Copyright 2012 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.client.ui;
+
+import java.util.List;
+
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.client.ComponentConnector;
+
+/**
+ * Client side connector for subclasses of AbstractSingleComponentConnector.
+ *
+ * @since 7.0
+ */
+public abstract class AbstractSingleComponentContainerConnector extends
+ AbstractHasComponentsConnector {
+
+ /**
+ * Returns the content (only/first child) of the container.
+ *
+ * @return child connector or null if none (e.g. invisible or not set on
+ * server)
+ */
+ protected ComponentConnector getContent() {
+ List<ComponentConnector> children = getChildComponents();
+ if (children.isEmpty()) {
+ return null;
+ } else {
+ return children.get(0);
+ }
+ }
+
+ /**
+ * Returns the widget (if any) of the content of the container.
+ *
+ * @return widget of the only/first connector of the container, null if no
+ * content or if there is no widget for the connector
+ */
+ protected Widget getContentWidget() {
+ ComponentConnector content = getContent();
+ if (null != content) {
+ return content.getWidget();
+ } else {
+ return null;
+ }
+ }
+
+}
* (non-Javadoc)
*
* @see
- * com.vaadin.client.ComponentContainerConnector#updateCaption(com.vaadin
+ * com.vaadin.client.HasComponentsConnector#updateCaption(com.vaadin
* .client.ComponentConnector)
*/
@Override
}
private void setChildWidgetPosition(ComponentConnector child) {
- getWidget().setWidgetPosition(
- child.getWidget(),
- getState().connectorToCssPosition.get(child
- .getConnectorId()));
+ getWidget().setWidgetPosition(child.getWidget(),
+ getState().connectorToCssPosition.get(child.getConnectorId()));
};
/*
* (non-Javadoc)
*
* @see
- * com.vaadin.client.ComponentContainerConnector#updateCaption(com.vaadin
+ * com.vaadin.client.HasComponentsConnector#updateCaption(com.vaadin
* .client.ComponentConnector)
*/
@Override
import java.util.Set;
import com.vaadin.client.ComponentConnector;
-import com.vaadin.client.ComponentContainerConnector;
+import com.vaadin.client.HasComponentsConnector;
import com.vaadin.client.ServerConnector;
import com.vaadin.client.Util;
import com.vaadin.client.VConsole;
resized.add(connector);
}
- if (connector instanceof ComponentContainerConnector) {
- ComponentContainerConnector container = (ComponentContainerConnector) connector;
+ if (connector instanceof HasComponentsConnector) {
+ HasComponentsConnector container = (HasComponentsConnector) connector;
for (ComponentConnector child : container.getChildComponents()) {
if (isRelativeInDirection(child, direction)) {
resized.add(child);
*/
package com.vaadin.client.ui.layout;
-import com.vaadin.client.ComponentContainerConnector;
+import com.vaadin.client.HasComponentsConnector;
-public interface MayScrollChildren extends ComponentContainerConnector {
+public interface MayScrollChildren extends HasComponentsConnector {
}
* (non-Javadoc)
*
* @see
- * com.vaadin.client.ComponentContainerConnector#updateCaption(com.vaadin
+ * com.vaadin.client.HasComponentsConnector#updateCaption(com.vaadin
* .client.ComponentConnector)
*/
@Override
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.Style.Unit;
-import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorHierarchyChangeEvent;
import com.vaadin.client.LayoutManager;
import com.vaadin.client.Paintable;
import com.vaadin.client.UIDL;
-import com.vaadin.client.ui.AbstractComponentContainerConnector;
+import com.vaadin.client.ui.AbstractSingleComponentContainerConnector;
import com.vaadin.client.ui.ClickEventHandler;
import com.vaadin.client.ui.PostLayoutListener;
import com.vaadin.client.ui.ShortcutActionHandler;
import com.vaadin.ui.Panel;
@Connect(Panel.class)
-public class PanelConnector extends AbstractComponentContainerConnector
+public class PanelConnector extends AbstractSingleComponentContainerConnector
implements Paintable, SimpleManagedLayout, PostLayoutListener,
MayScrollChildren {
@Override
public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) {
// We always have 1 child, unless the child is hidden
- Widget newChildWidget = null;
- if (getChildComponents().size() == 1) {
- ComponentConnector newChild = getChildComponents().get(0);
- newChildWidget = newChild.getWidget();
- }
-
- getWidget().setWidget(newChildWidget);
+ getWidget().setWidget(getContentWidget());
}
}
@Override
protected void init() {
super.init();
-
- handlerRegistration.add(getWidget().addVisibilityChangeHandler(
- this));
+
+ handlerRegistration.add(getWidget().addVisibilityChangeHandler(this));
}
@Override
import com.vaadin.client.TooltipInfo;
import com.vaadin.client.UIDL;
import com.vaadin.client.Util;
-import com.vaadin.client.ui.AbstractComponentContainerConnector;
+import com.vaadin.client.ui.AbstractHasComponentsConnector;
import com.vaadin.client.ui.PostLayoutListener;
import com.vaadin.client.ui.VScrollTable;
import com.vaadin.client.ui.VScrollTable.ContextMenuDetails;
import com.vaadin.shared.ui.table.TableState;
@Connect(com.vaadin.ui.Table.class)
-public class TableConnector extends AbstractComponentContainerConnector
+public class TableConnector extends AbstractHasComponentsConnector
implements Paintable, DirectionalManagedLayout, PostLayoutListener {
@Override
import com.vaadin.client.VConsole;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler;
-import com.vaadin.client.ui.AbstractComponentContainerConnector;
+import com.vaadin.client.ui.AbstractSingleComponentContainerConnector;
import com.vaadin.client.ui.ClickEventHandler;
import com.vaadin.client.ui.ShortcutActionHandler;
import com.vaadin.client.ui.VNotification;
import com.vaadin.ui.UI;
@Connect(value = UI.class, loadStyle = LoadStyle.EAGER)
-public class UIConnector extends AbstractComponentContainerConnector implements
- Paintable, MayScrollChildren {
+public class UIConnector extends AbstractSingleComponentContainerConnector
+ implements Paintable, MayScrollChildren {
private HandlerRegistration childStateChangeHandlerRegistration;
return (VUI) super.getWidget();
}
- protected ComponentConnector getContent() {
- List<ComponentConnector> children = getChildComponents();
- if (children.isEmpty()) {
- return null;
- } else {
- return children.get(0);
- }
- }
-
protected void onChildSizeChange() {
ComponentConnector child = getContent();
if (child == null) {
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
-import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.BrowserInfo;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.LayoutManager;
import com.vaadin.client.Paintable;
import com.vaadin.client.UIDL;
-import com.vaadin.client.ui.AbstractComponentContainerConnector;
+import com.vaadin.client.ui.AbstractSingleComponentContainerConnector;
import com.vaadin.client.ui.ClickEventHandler;
import com.vaadin.client.ui.PostLayoutListener;
import com.vaadin.client.ui.ShortcutActionHandler;
-import com.vaadin.client.ui.VWindow;
import com.vaadin.client.ui.ShortcutActionHandler.BeforeShortcutActionListener;
import com.vaadin.client.ui.SimpleManagedLayout;
+import com.vaadin.client.ui.VWindow;
import com.vaadin.client.ui.layout.MayScrollChildren;
import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.window.WindowState;
@Connect(value = com.vaadin.ui.Window.class)
-public class WindowConnector extends AbstractComponentContainerConnector
+public class WindowConnector extends AbstractSingleComponentContainerConnector
implements Paintable, BeforeShortcutActionListener,
SimpleManagedLayout, PostLayoutListener, MayScrollChildren {
@Override
public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) {
// We always have 1 child, unless the child is hidden
- Widget newChildWidget = null;
- ComponentConnector newChild = null;
- if (getChildComponents().size() == 1) {
- newChild = getChildComponents().get(0);
- newChildWidget = newChild.getWidget();
- }
-
- getWidget().layout = newChild;
- getWidget().contentPanel.setWidget(newChildWidget);
+ getWidget().layout = getContent();
+ getWidget().contentPanel.setWidget(getContentWidget());
}
@Override