public void updateConnectorHierarchy(List<ServerConnector> children) { Set<String> connectorIds = new HashSet<String>(); for (ServerConnector child : children) { if (child instanceof ComponentConnector) { connectorIds.add(child.getConnectorId()); idToDetailsMap.put(child.getConnectorId(), (ComponentConnector) child); } } Set<String> removedDetails = new HashSet<String>(); for (Entry<String, ComponentConnector> entry : idToDetailsMap.entrySet()) { ComponentConnector connector = entry.getValue(); String id = connector.getConnectorId(); if (!connectorIds.contains(id)) { removedDetails.add(entry.getKey()); if (idToRowIndex.containsKey(id)) { getWidget().setDetailsVisible(idToRowIndex.get(id), false); } } } for (String id : removedDetails) { idToDetailsMap.remove(id); idToRowIndex.remove(id); } }
@Override public void onConnectorHierarchyChange( final ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) { final List<ComponentConnector> children = getChildComponents(); final CRoom widget = getWidget(); for (final ComponentConnector connector : children) { widget.add(connector.getWidget()); } }
@Override public Widget getDetails(int rowIndex) { String id = getId(rowIndex); if (id == null) { return null; } ComponentConnector componentConnector = idToDetailsMap.get(id); idToRowIndex.put(id, rowIndex); return componentConnector.getWidget(); }
@Override public double getDetailsHeight(int rowIndex) { // Case of null is handled in the getDetails method and this method // will not called if it returns null. String id = getId(rowIndex); ComponentConnector componentConnector = idToDetailsMap.get(id); getLayoutManager().setNeedsMeasureRecursively(componentConnector); getLayoutManager().layoutNow(); return getLayoutManager().getOuterHeightDouble(componentConnector.getWidget().getElement()); }
static VDropHandler createMockedVDropHandler(String dropTargetId) { com.google.gwt.user.client.Element element = Mockito.mock(com.google.gwt.user.client.Element.class); when(element.getId()).thenReturn(dropTargetId); Widget widget = Mockito.mock(Widget.class); when(widget.getElement()).thenReturn(element); ComponentConnector connector = Mockito.mock(ComponentConnector.class); when(connector.getWidget()).thenReturn(widget); VDropHandler dropHandler = Mockito.mock(VDropHandler.class); when(dropHandler.getConnector()).thenReturn(connector); return dropHandler; }
static VDragEvent createMockedVDragEvent(String dragSourceId, Widget widget) { com.google.gwt.user.client.Element element = Mockito.mock(com.google.gwt.user.client.Element.class); when(element.getId()).thenReturn(dragSourceId); when(widget.getElement()).thenReturn(element); ComponentConnector dragSource = Mockito.mock(ComponentConnector.class); when(dragSource.getWidget()).thenReturn(widget); VTransferable transferable = Mockito.mock(VTransferable.class); when(transferable.getDragSource()).thenReturn(dragSource); VDragEvent dragEvent = Mockito.mock(VDragEvent.class); when(dragEvent.getTransferable()).thenReturn(transferable); return dragEvent; }
public void setPopupConnector(ComponentConnector newPopupComponent) { if (newPopupComponent != popupComponentConnector) { if (popupComponentConnector != null) { popupComponentConnector.removeStateChangeHandler(this); } Widget newWidget = newPopupComponent.getWidget(); setWidget(newWidget); popupComponentWidget = newWidget; popupComponentConnector = newPopupComponent; popupComponentConnector.addStateChangeHandler("height", this); popupComponentConnector.addStateChangeHandler("width", this); } }
private void clearPopupComponentConnector() { if (popupComponentConnector != null) { popupComponentConnector.removeStateChangeHandler(this); } popupComponentConnector = null; popupComponentWidget = null; captionWrapper = null; }
@Override public void onDrop(DragContext context) { super.onDrop(context); PortletChrome portletWidget = (PortletChrome) context.selectedWidgets.get(0); if (positionerSlot != null) { positionerSlot.setWidget(portletWidget); } Widget contentWidget = portletWidget.getContentWidget(); ComponentConnector contentConnector = Util.findConnectorFor(contentWidget); PortalLayoutConnector originalConnector = (PortalLayoutConnector) contentConnector.getParent(); if (originalConnector != portalConnector) { portalConnector.propagateHierarchyChangesToServer(); originalConnector.propagateHierarchyChangesToServer(); } else { portalConnector.updatePortletPositionOnServer(contentConnector); } }
private void updateFooterCellFromState(FooterCell cell, CellState cellState) { switch (cellState.type) { case TEXT: cell.setText(cellState.text); break; case HTML: cell.setHtml(cellState.html); break; case WIDGET: ComponentConnector connector = (ComponentConnector) cellState.connector; cell.setWidget(connector.getWidget()); break; default: throw new IllegalStateException("unexpected cell type: " + cellState.type); } cell.setStyleName(cellState.styleName); }
protected void onChildSizeChange() { ComponentConnector child = getContent(); if (child == null) { return; } Style childStyle = child.getWidget().getElement().getStyle(); /* * Must set absolute position if the child has relative height and * there's a chance of horizontal scrolling as some browsers will * otherwise not take the scrollbar into account when calculating the * height. Assuming v-ui does not have an undefined width for now, see * #8460. */ if (child.isRelativeHeight() && !BrowserInfo.get().isIE9()) { childStyle.setPosition(Position.ABSOLUTE); } else { childStyle.clearPosition(); } }
@Override public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) { ComponentConnector oldChild = null; ComponentConnector newChild = getContent(); for (ComponentConnector c : event.getOldChildren()) { if (!(c instanceof WindowConnector)) { oldChild = c; break; } } if (oldChild != newChild) { if (childStateChangeHandlerRegistration != null) { childStateChangeHandlerRegistration.removeHandler(); childStateChangeHandlerRegistration = null; } if (newChild != null) { getWidget().setWidget(newChild.getWidget()); childStateChangeHandlerRegistration = newChild.addStateChangeHandler(childStateChangeHandler); // Must handle new child here as state change events are already // fired onChildSizeChange(); } else { getWidget().setWidget(null); } } for (ComponentConnector c : getChildComponents()) { if (c instanceof WindowConnector) { WindowConnector wc = (WindowConnector) c; wc.setWindowOrderAndPosition(); } } // Close removed sub windows for (ComponentConnector c : event.getOldChildren()) { if (c.getParent() != this && c instanceof WindowConnector) { ((WindowConnector) c).getWidget().hide(); } } }
@Override public void setCaption(VCaption caption) { VCaption oldCaption = getCaption(); if (oldCaption != null) { getLayoutManager().unregisterDependency(layout, oldCaption.getElement()); } super.setCaption(caption); if (caption != null) { getLayoutManager() .registerDependency((ManagedLayout) child.getParent(), caption.getElement()); } }
@Override public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) { // super.onConnectorHierarchyChange(event); // Remove old children for (ComponentConnector child : event.getOldChildren()) { if (child.getParent() != this) { Widget widget = child.getWidget(); if (widget.isAttached()) { getWidget().remove(widget); } } } // Add or move children int index = 0; for (ComponentConnector child : getChildComponents()) { getWidget().addOrMove(child.getWidget(), index); ++index; } }
/** Update caption for given widget */ public void updateCaption(ComponentConnector paintable) { Widget widget = paintable.getWidget(); VCaptionWrapper wrapper = childWidgetToCaptionWrapper.get(widget); if (VCaption.isNeeded(paintable.getState())) { if (wrapper == null) { // Add a wrapper between the layout and the child widget final String loc = getLocation(widget); super.remove(widget); wrapper = new VCaptionWrapper(paintable, client); super.add(wrapper, locationToElement.get(loc)); childWidgetToCaptionWrapper.put(widget, wrapper); } wrapper.updateCaption(); } else { if (wrapper != null) { // Remove the wrapper and add the widget directly to the layout final String loc = getLocation(widget); super.remove(wrapper); super.add(widget, locationToElement.get(loc)); childWidgetToCaptionWrapper.remove(widget); } } }
@Override public boolean isRelativeHeight() { return child.isRelativeHeight(); }
@Override public boolean isUndefinedWidth() { return child.isUndefinedWidth(); }
@Override public boolean isUndefinedHeight() { return child.isUndefinedHeight(); }
@Override public int getWidgetWidth() { return getLayoutManager().getOuterWidth(child.getWidget().getElement()); }
public ComponentConnectorLayoutSlot( String baseClassName, ComponentConnector child, ManagedLayout layout) { super(baseClassName, child.getWidget()); this.child = child; this.layout = layout; }
@Override public boolean isRelativeWidth() { return child.isRelativeWidth(); }
/** * Called when the window or parent div might have been resized. * * <p>This immediately checks the sizes of the window and the parent div (if monitoring it) and * triggers layout recalculation if they have changed. * * @param newWindowWidth The new width of the window * @param newWindowHeight The new height of the window * @deprecated use {@link #performSizeCheck()} */ @Deprecated protected void windowSizeMaybeChanged(int newWindowWidth, int newWindowHeight) { if (connection == null) { // Connection is null if the timer fires before the first UIDL // update return; } boolean changed = false; ComponentConnector connector = ConnectorMap.get(connection).getConnector(this); if (windowWidth != newWindowWidth) { windowWidth = newWindowWidth; changed = true; connector.getLayoutManager().reportOuterWidth(connector, newWindowWidth); VConsole.log("New window width: " + windowWidth); } if (windowHeight != newWindowHeight) { windowHeight = newWindowHeight; changed = true; connector.getLayoutManager().reportOuterHeight(connector, newWindowHeight); VConsole.log("New window height: " + windowHeight); } Element parentElement = getElement().getParentElement(); if (isMonitoringParentSize() && parentElement != null) { // check also for parent size changes int newParentWidth = parentElement.getClientWidth(); int newParentHeight = parentElement.getClientHeight(); if (parentWidth != newParentWidth) { parentWidth = newParentWidth; changed = true; VConsole.log("New parent width: " + parentWidth); } if (parentHeight != newParentHeight) { parentHeight = newParentHeight; changed = true; VConsole.log("New parent height: " + parentHeight); } } if (changed) { /* * If the window size has changed, layout the VView again and send * new size to the server if the size changed. (Just checking VView * size would cause us to ignore cases when a relatively sized VView * should shrink as the content's size is fixed and would thus not * automatically shrink.) */ VConsole.log("Running layout functions due to window or parent resize"); // update size to avoid (most) redundant re-layout passes // there can still be an extra layout recalculation if webkit // overflow fix updates the size in a deferred block if (isMonitoringParentSize() && parentElement != null) { parentWidth = parentElement.getClientWidth(); parentHeight = parentElement.getClientHeight(); } sendClientResized(); LayoutManager layoutManager = connector.getLayoutManager(); if (layoutManager.isLayoutRunning()) { layoutManager.layoutLater(); } else { layoutManager.layoutNow(); } } }