private void sortByHierarchy(List<Component> paintables) { // Vaadin 6 requires parents to be painted before children as component // containers rely on that their updateFromUIDL method has been called // before children start calling e.g. updateCaption Collections.sort(paintables, (Component c1, Component c2) -> { int depth1 = 0; while (c1.getParent() != null) { depth1++; c1 = c1.getParent(); } int depth2 = 0; while (c2.getParent() != null) { depth2++; c2 = c2.getParent(); } if (depth1 < depth2) { return -1; } if (depth1 > depth2) { return 1; } return 0; }); }
public static LayoutClickEvent createEvent(ComponentContainer layout, MouseEventDetails mouseDetails, Connector clickedConnector) { Component clickedComponent = (Component) clickedConnector; Component childComponent = clickedComponent; while (childComponent != null && childComponent.getParent() != layout) { childComponent = childComponent.getParent(); } return new LayoutClickEvent(layout, mouseDetails, clickedComponent, childComponent); } }
/** * Determine whether a <code>content</code> component is equal to, or the * ancestor of this component. * * @param content * the potential ancestor element * @return <code>true</code> if the relationship holds */ protected boolean isOrHasAncestor(Component content) { if (content instanceof HasComponents) { for (Component parent = this; parent != null; parent = parent .getParent()) { if (parent.equals(content)) { return true; } } } return false; }
private static Deque<ComponentInfo> getHeightAttributes( Component component) { Deque<ComponentInfo> attributes = new ArrayDeque<>(); attributes .add(new ComponentInfo(component, getHeightString(component))); Component parent = component.getParent(); attributes.add(new ComponentInfo(parent, getHeightString(parent))); while ((parent = parent.getParent()) != null) { attributes.add(new ComponentInfo(parent, getHeightString(parent))); } return attributes; }
private static Deque<ComponentInfo> getWidthAttributes( Component component) { final Deque<ComponentInfo> attributes = new ArrayDeque<>(); attributes.add(new ComponentInfo(component, getWidthString(component))); Component parent = component.getParent(); attributes.add(new ComponentInfo(parent, getWidthString(parent))); while ((parent = parent.getParent()) != null) { attributes.add(new ComponentInfo(parent, getWidthString(parent))); } return attributes; }
@Override public void generateData(T item, JsonObject jsonObject) { if (generator == null || !visibleDetails.contains(item)) { return; } if (!components.containsKey(item)) { Component detailsComponent = generator.apply(item); Objects.requireNonNull(detailsComponent, "Details generator can't create null components"); if (detailsComponent.getParent() != null) { throw new IllegalStateException( "Details component was already attached"); } addComponentToGrid(detailsComponent); components.put(item, detailsComponent); } jsonObject.put(GridState.JSONKEY_DETAILS_VISIBLE, components.get(item).getConnectorId()); }
/** * Adds a component into this container. The component is added to the left * or on top of the other components. * * @param c * the component to be added. */ public void addComponentAsFirst(Component c) { // If c is already in this, we must remove it before proceeding // see ticket #7668 if (equals(c.getParent())) { removeComponent(c); } components.addFirst(c); try { super.addComponent(c); } catch (IllegalArgumentException e) { components.remove(c); throw e; } }
public static boolean checkWidths(Component component) { try { if (!hasRelativeWidth(component)) { return true; } if (component instanceof Window) { return true; } if (component.getParent() == null) { return true; } return parentCanDefineWidth(component); } catch (Exception e) { getLogger().log(Level.FINER, "An exception occurred while validating sizes.", e); return true; } }
public static boolean checkHeights(Component component) { try { if (!hasRelativeHeight(component)) { return true; } if (component instanceof Window) { return true; } if (component.getParent() == null) { return true; } return parentCanDefineHeight(component); } catch (Exception e) { getLogger().log(Level.FINER, "An exception occurred while validating sizes.", e); return true; } }
/** * Sets the component contained in the composite. * <p> * You must set the composition root to a non-null value before the * component can be used. It cannot be changed. * </p> * * @param compositionRoot * the root of the composition component tree. */ protected void setCompositionRoot(Component compositionRoot) { if (root != null) { throw new IllegalStateException( "Composition root cannot be changed"); } if (compositionRoot == null) { throw new IllegalArgumentException( "Composition root cannot be null"); } // set new component if (compositionRoot.getParent() != null) { // If the component already has a parent, try to remove it AbstractSingleComponentContainer.removeFromParent(compositionRoot); } compositionRoot.setParent(this); root = compositionRoot; markAsDirty(); }
/** * Adds a component into this container. The component is added to the left * or on top of the other components. * * @param c * the component to be added. */ public void addComponentAsFirst(Component c) { // If c is already in this, we must remove it before proceeding // see ticket #7668 if (equals(c.getParent())) { removeComponent(c); } components.addFirst(c); try { super.addComponent(c); } catch (IllegalArgumentException e) { components.remove(c); throw e; } componentAdded(c); }
/** * Adds a component into indexed position in this container. * * @param c * the component to be added. * @param index * the index of the component position. The components currently * in and after the position are shifted forwards. */ public void addComponent(Component c, int index) { // If c is already in this, we must remove it before proceeding // see ticket #7668 if (equals(c.getParent())) { // When c is removed, all components after it are shifted down if (index > getComponentIndex(c)) { index--; } removeComponent(c); } components.add(index, c); try { super.addComponent(c); } catch (IllegalArgumentException e) { components.remove(c); throw e; } }
/** * Sets the composition root for the component. * * <p> * You must set the composition root to a non-null value before the * component can be used. You can change it later. * </p> * * @param compositionRoot * the root of the composition component tree. */ protected void setCompositionRoot(Component compositionRoot) { if (compositionRoot != root) { if (root != null && equals(root.getParent())) { // remove old component root.setParent(null); } if (compositionRoot != null) { // set new component if (compositionRoot.getParent() != null) { // If the component already has a parent, try to remove it AbstractSingleComponentContainer .removeFromParent(compositionRoot); } compositionRoot.setParent(this); } root = compositionRoot; markAsDirty(); } }
/** * Adds a component into indexed position in this container. * * @param c * the component to be added. * @param index * the index of the component position. The components currently * in and after the position are shifted forwards. */ public void addComponent(Component c, int index) { // If c is already in this, we must remove it before proceeding // see ticket #7668 if (equals(c.getParent())) { // When c is removed, all components after it are shifted down if (index > getComponentIndex(c)) { index--; } removeComponent(c); } components.add(index, c); try { super.addComponent(c); } catch (IllegalArgumentException e) { components.remove(c); throw e; } componentAdded(c); }
/** * This only implements the events and component parent calls. The extending * classes must implement component list maintenance and call this method * before component list maintenance. * * @see com.vaadin.ui.ComponentContainer#removeComponent(Component) */ @Override public void removeComponent(Component c) { if (equals(c.getParent())) { c.setParent(null); fireComponentDetachEvent(c); markAsDirty(); } }
/** * This only implements the events and component parent calls. The extending * classes must implement component list maintenance and call this method * after component list maintenance. * * @see com.vaadin.ui.ComponentContainer#addComponent(Component) */ @Override public void addComponent(Component c) { // Make sure we're not adding the component inside it's own content if (isOrHasAncestor(c)) { throw new IllegalArgumentException( "Component cannot be added inside it's own content"); } if (c.getParent() != null) { // If the component already has a parent, try to remove it AbstractSingleComponentContainer.removeFromParent(c); } c.setParent(this); fireComponentAttachEvent(c); markAsDirty(); }
/** * Set the visibility of the popup. Does not hide the minimal * representation. * * @param visible */ public void setPopupVisible(boolean visible) { if (isPopupVisible() != visible) { if (visible) { visibleComponent = content.getPopupComponent(); if (visibleComponent == null) { throw new IllegalStateException( "PopupView.Content did not return Component to set visible"); } if (visibleComponent.getParent() != null) { // If the component already has a parent, try to remove it AbstractSingleComponentContainer .removeFromParent(visibleComponent); } visibleComponent.setParent(this); } else { if (equals(visibleComponent.getParent())) { visibleComponent.setParent(null); } visibleComponent = null; } fireEvent(new PopupVisibilityEvent(this)); markAsDirty(); } }
private static String getWidthString(Component component) { String width = "width: "; if (hasRelativeWidth(component)) { width += "RELATIVE, " + component.getWidth() + " %"; } else if (component instanceof Window && component.getParent() == null) { width += "MAIN WINDOW"; } else if (component.getWidth() >= 0) { width += "ABSOLUTE, " + component.getWidth() + " " + component.getWidthUnits().getSymbol(); } else { width += "UNDEFINED"; } return width; }
private static String getHeightString(Component component) { String height = "height: "; if (hasRelativeHeight(component)) { height += "RELATIVE, " + component.getHeight() + " %"; } else if (component instanceof Window && component.getParent() == null) { height += "MAIN WINDOW"; } else if (component.getHeight() > 0) { height += "ABSOLUTE, " + component.getHeight() + " " + component.getHeightUnits().getSymbol(); } else { height += "UNDEFINED"; } return height; }
/** * Adds the component using the given position. Ensures the position is only * set if the component is added correctly. * * @param c * The component to add * @param position * The position info for the component. Must not be null. * @throws IllegalArgumentException * If adding the component failed */ private void addComponent(Component c, ComponentPosition position) throws IllegalArgumentException { if (equals(c.getParent())) { removeComponent(c); } /* * Create position instance and add it to componentToCoordinates map. We * need to do this before we call addComponent so the attachListeners * can access this position. #6368 */ internalSetPosition(c, position); try { super.addComponent(c); } catch (IllegalArgumentException e) { internalRemoveComponent(c); throw e; } }