import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractLayoutConnector;
import com.vaadin.client.ui.LayoutClickEventHandler;
-import com.vaadin.client.ui.csslayout.VCssLayout.FlowPane;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.LayoutClickRpc;
import com.vaadin.shared.ui.csslayout.CssLayoutServerRpc;
import com.vaadin.shared.ui.csslayout.CssLayoutState;
import com.vaadin.ui.CssLayout;
+/**
+ * Connects the server side widget {@link CssLayout} with the client side
+ * counterpart {@link VCssLayout}
+ */
@Connect(CssLayout.class)
public class CssLayoutConnector extends AbstractLayoutConnector {
private Map<ComponentConnector, VCaption> childToCaption = new HashMap<ComponentConnector, VCaption>();
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.client.ui.AbstractComponentConnector#init()
+ */
@Override
protected void init() {
super.init();
rpc = RpcProxy.create(CssLayoutServerRpc.class, this);
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.client.ui.AbstractLayoutConnector#getState()
+ */
@Override
public CssLayoutState getState() {
return (CssLayoutState) super.getState();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.client.ui.AbstractComponentConnector#onStateChanged(com.vaadin
+ * .client.communication.StateChangeEvent)
+ */
@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
super.onStateChanged(stateChangeEvent);
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.client.ui.AbstractComponentContainerConnector#
+ * onConnectorHierarchyChange
+ * (com.vaadin.client.ConnectorHierarchyChangeEvent)
+ */
@Override
public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) {
super.onConnectorHierarchyChange(event);
clickEventHandler.handleEventHandlerRegistration();
int index = 0;
- FlowPane cssLayoutWidgetContainer = getWidget().panel;
for (ComponentConnector child : getChildComponents()) {
VCaption childCaption = childToCaption.get(child);
if (childCaption != null) {
- cssLayoutWidgetContainer.addOrMove(childCaption, index++);
+ getWidget().addOrMove(childCaption, index++);
}
- cssLayoutWidgetContainer.addOrMove(child.getWidget(), index++);
+ getWidget().addOrMove(child.getWidget(), index++);
}
// Detach old child widgets and possibly their caption
// Skip current children
continue;
}
- cssLayoutWidgetContainer.remove(child.getWidget());
+ getWidget().remove(child.getWidget());
VCaption vCaption = childToCaption.remove(child);
if (vCaption != null) {
- cssLayoutWidgetContainer.remove(vCaption);
+ getWidget().remove(vCaption);
}
}
}
+ /**
+ * Converts a css property string to CamelCase
+ *
+ * @param cssProperty
+ * The property string
+ * @return A string converted to camelcase
+ */
private static final String makeCamelCase(String cssProperty) {
// TODO this might be cleaner to implement with regexp
while (cssProperty.contains("-")) {
return cssProperty;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.client.ui.AbstractComponentConnector#getWidget()
+ */
@Override
public VCssLayout getWidget() {
return (VCssLayout) super.getWidget();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.client.ComponentContainerConnector#updateCaption(com.vaadin
+ * .client.ComponentConnector)
+ */
@Override
public void updateCaption(ComponentConnector child) {
Widget childWidget = child.getWidget();
- FlowPane cssLayoutWidgetContainer = getWidget().panel;
- int widgetPosition = cssLayoutWidgetContainer
- .getWidgetIndex(childWidget);
+ int widgetPosition = getWidget().getWidgetIndex(childWidget);
VCaption caption = childToCaption.get(child);
if (VCaption.isNeeded(child.getState())) {
}
if (!caption.isAttached()) {
// Insert caption at widget index == before widget
- cssLayoutWidgetContainer.insert(caption, widgetPosition);
+ getWidget().insert(caption, widgetPosition);
}
caption.updateCaption();
} else if (caption != null) {
childToCaption.remove(child);
- cssLayoutWidgetContainer.remove(caption);
+ getWidget().remove(caption);
}
}
-
}
package com.vaadin.client.ui.csslayout;
-import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.FlowPanel;
-import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.ui.themes.BaseTheme;
-public class VCssLayout extends SimplePanel {
- public static final String TAGNAME = "csslayout";
- public static final String CLASSNAME = "v-" + TAGNAME;
-
- FlowPane panel = new FlowPane();
+/**
+ * VCCSlayout is a layout which supports configuring it's children with CSS
+ * selectors
+ */
+public class VCssLayout extends FlowPanel {
- Element margin = DOM.createDiv();
+ public static final String CLASSNAME = "v-csslayout";
+ /**
+ * Default constructor
+ */
public VCssLayout() {
super();
- getElement().appendChild(margin);
setStyleName(BaseTheme.UI_LAYOUT);
addStyleName(CLASSNAME);
- margin.setClassName(CLASSNAME + "-margin");
- setWidget(panel);
}
- @Override
- protected Element getContainerElement() {
- return margin;
- }
-
- public class FlowPane extends FlowPanel {
-
- public FlowPane() {
- super();
- setStyleName(CLASSNAME + "-container");
- }
-
- void addOrMove(Widget child, int index) {
- if (child.getParent() == this) {
- int currentIndex = getWidgetIndex(child);
- if (index == currentIndex) {
- return;
- }
+ /**
+ * Add or move a child in the
+ *
+ * @param child
+ * @param index
+ */
+ void addOrMove(Widget child, int index) {
+ if (child.getParent() == this) {
+ int currentIndex = getWidgetIndex(child);
+ if (index == currentIndex) {
+ return;
}
- insert(child, index);
}
-
+ insert(child, index);
}
-
}