/** * Returns the design context menu currently bound to the component. * * @param component The CWF component of interest. * @return The associated design context menu, or null if none. */ public static Menupopup getDesignContextMenu(BaseComponent component) { return component == null ? null : (Menupopup) component.getAttribute(CONTEXT_MENU); }
CompositePosition position = composite.getCompositePosition(); Assert.notNull(position, () -> "A snippet must specify a position"); BaseComponent anchor = anchorName == null ? this : findByName(anchorName); Assert.notNull(anchor, () -> "Could not locate any anchor named " + anchorName); BaseComponent parent = position == CompositePosition.FIRST || position == CompositePosition.LAST ? anchor : anchor.getParent(); Assert.notNull(parent, () -> "Anchor must have a parent for position value of " + position); root.detach(); int index = anchor.getIndex(); parent.addChild(root, 0); break; parent.addChild(root, -1); break; anchor.detach(); parent.addChild(root, index); anchor.setParent(root); break; anchor.destroy(); parent.addChild(root, index); break; parent.addChild(root, index); break; parent.addChild(root, index + 1);
/** * Recursively remove empty menu container elements. This is done after removing menu items to * keep the menu structure lean. * * @param parent The starting menu container. */ public static void pruneMenus(BaseComponent parent) { while (parent != null && parent instanceof BaseMenuComponent) { if (parent.getChildren().isEmpty()) { BaseComponent newParent = parent.getParent(); parent.destroy(); parent = newParent; } else { break; } } }
/** * Returns the controller associated with the specified component, if any. * * @param comp The component whose controller is sought. * @param recurse If true, search up the parent chain until a controller is found. * @return The associated controller, or null if none found. */ public static Object getController(BaseComponent comp, boolean recurse) { return recurse ? comp.findAttribute(Constants.ATTR_COMPOSER) : comp.getAttribute(Constants.ATTR_COMPOSER); }
/** * Returns the sibling of this component at the specified offset. * * @param offset Offset from this component. For example, 2 would mean the second sibling * following this component. * @return The requested sibling, or null if none exists at the requested offset. */ private BaseComponent getRelativeSibling(int offset) { int i = getIndex(); i = i == -1 ? -1 : i + offset; return i < 0 || i >= getParent().getChildCount() ? null : getParent().getChildAt(i); }
@Override public void addChild(BaseComponent child, int index) { root.addChild(child, index); } }
/** * Searches for a drop renderer associated with the specified component or one of its ancestor * components. * * @param component BaseComponent whose drop renderer is sought. * @return The associated drop renderer, or null if none found. */ public static IDropRenderer getDropRenderer(BaseComponent component) { IDropRenderer dropRenderer = null; while (dropRenderer == null && component != null) { dropRenderer = (IDropRenderer) component.getAttribute(DROP_RENDERER_ATTR); component = component.getParent(); } return dropRenderer; }
/** * Remove this listener from its associated component. */ protected void removeAction() { component.removeEventListener(eventName, this); if (component.getAttribute(attrName) == this) { component.removeAttribute(attrName); } }
/** * Returns a value for the named object. If the name is "self", the component itself is * returned. If the name is "parent" the component's parent is returned. Otherwise, name * resolution is attempted from several sources in the following order: * <ol> * <li>Tag library prefixes</li> * <li>The argument map passed to the materializer</li> * <li>The component's attribute map</li> * <li>The component's namespace</li> * <li>All ancestor attribute maps</li> * </ol> * * @param name The object name. * @return The value of the named object, or null if not found. */ public Object getValue(String name) { Object result = "self".equals(name) ? component : null; result = result != null ? result : "parent".equals(name) ? parent : null; result = result != null ? result : element.getTagLibrary(name); result = result != null ? result : args == null ? null : args.get(name); result = result != null ? result : component == null ? null : component.getAttribute(name); result = result != null ? result : parent == null ? null : parent.findByName(name); result = result != null ? result : parent == null ? null : parent.findAttribute(name); return result; } }
/** * Returns the menu with the specified label, or creates one if it does not exist. * * @param parent The parent component under which to search. May be a Toolbar or a Menupopup * component. * @param label Label of menu to search. * @param insertBefore If not null, the new menu is inserted before this one. If null, the menu * is appended. * @return Menu or menu item with the specified label. */ public static BaseMenuComponent findMenu(BaseComponent parent, String label, BaseComponent insertBefore) { for (BaseMenuComponent child : parent.getChildren(BaseMenuComponent.class)) { if (label.equalsIgnoreCase(child.getLabel())) { return child; } } BaseMenuComponent cmp = createMenuOrMenuitem(parent); cmp.setLabel(label); parent.addChild(cmp, insertBefore); return cmp; }
/** * Returns an iterable of children of the specified type. * * @param <T> The desired type. * @param type The desired type. * @return An iterable of children of the specified type. Never null. */ public final <T extends BaseComponent> Iterable<T> getChildren(Class<T> type) { return MiscUtil.iterableForType(getChildren(), type); }
/** * Alphabetically sorts children under the specified parent. * * @param parent Parent whose child nodes (Treenode) are to be sorted. * @param recurse If true, sorting is recursed through all children. */ public static void sort(BaseComponent parent, boolean recurse) { if (parent == null || parent.getChildren().size() < 2) { return; } int i = 1; int size = parent.getChildren().size(); while (i < size) { Treenode item1 = (Treenode) parent.getChildren().get(i - 1); Treenode item2 = (Treenode) parent.getChildren().get(i); if (compare(item1, item2) > 0) { parent.swapChildren(i - 1, i); i = i == 1 ? 2 : i - 1; } else { i++; } } if (recurse) { for (BaseComponent child : parent.getChildren()) { sort(child, recurse); } } }
/** * Sets the component's parent. * * @param parent The new parent. * @exception ComponentException Thrown if the new parent is not a valid parent for this * component. */ public void setParent(BaseComponent parent) { if (parent != this.parent) { if (parent == null) { this.parent.removeChild(this); } else { parent.addChild(this); } } }
addEventListener(eventName, (IEventListener) value); return; addEventListener(eventName, (event) -> { if (script.getPage() == null) { script.setParent(getPage()); } else { script.validatePage(getPage()); variables.put("controller", findAttribute(ATTR_CONTROLLER)); variables.put("event", event); script.execute(variables);
protected void remove(BaseComponent child, boolean noSync, boolean destroy) { if (child instanceof IComposite) { BaseComponent root = ((IComposite) child).getCompositeRoot(); BaseComponent parent = root == null ? null : root.getParent(); if (parent != null) { parent.children.remove(root, noSync, destroy); } child.parent = null; modCount++; } else { int index = indexOf(child); ComponentException.assertTrue(index != -1, parent, "Child does not belong to this parent"); parent.beforeRemoveChild(child); parent.nameIndex.remove(child); child.parent = null; delegate.remove(child); modCount++; if (!noSync) { parent.invokeIfAttached("removeChild", child, destroy); } child.dead |= destroy; parent.afterRemoveChild(child); } }
private void test(BaseComponent root, String eventName, int eventData, int expectedSize) { String labelText = eventName + "." + eventData; EventManager.getInstance().fireLocalEvent(eventName, labelText); getMockEnvironment().flushEvents(); assertEquals(expectedSize, root.getChildren().size()); Label label = (Label) root.getChildren().get(expectedSize - 1).getFirstChild(); assertEquals(labelText, label.getLabel()); } }
@Override public void onEvent(Event event) { BaseComponent target = event.getCurrentTarget(); Event newEvent = new Event("showManifest", target.getAncestor(Grid.class), target.getData()); EventUtil.send(newEvent); }
/** * Destroys this component. */ public void destroy() { if (dead) { return; } onDestroy(); if (page != null) { page.registerComponent(this, false); } destroyChildren(); if (parent != null) { parent.children.remove(this, false, true); } else { invokeIfAttached("destroy"); } dead = true; fireEvent(new Event("destroy", this)); eventListeners.removeAll(); }