private static Hierarchical createHierarchicalContainer(BusinessServiceContainer newContainer) { final ContainerHierarchicalWrapper hierarchicalContainer = new ContainerHierarchicalWrapper(newContainer); // Set child/parent relation for(Map.Entry<Long, Long> eachEntry : newContainer.getRowIdToParentRowIdMapping().entrySet()) { hierarchicalContainer.setParent(eachEntry.getKey(), eachEntry.getValue()); } // Disable the collapse flag on items without any children for (Object itemId : hierarchicalContainer.getItemIds()) { hierarchicalContainer.setChildrenAllowed(itemId, hierarchicalContainer.hasChildren(itemId)); } return hierarchicalContainer; } }
/** * Creates a new Item into the Container, assigns it an automatic ID, and * adds it to the hierarchy. * * @return the autogenerated ID of the new Item or <code>null</code> if the * operation failed * @throws UnsupportedOperationException * if the addItem is not supported. */ @Override public Object addItem() throws UnsupportedOperationException { final Object id = container.addItem(); if (!hierarchical && id != null) { addToHierarchyWrapper(id); } return id; }
@Override public void containerItemSetChange(ItemSetChangeEvent event) { updateHierarchicalWrapper(); ((Container.ItemSetChangeListener) listener) .containerItemSetChange(event); }
removeFromHierarchyWrapper(id); for (final Object id : ids) { if (!s.contains(id)) { addToHierarchyWrapper(id); s.add(id);
/** * Removes the specified Item from the wrapper's internal hierarchy * structure. * <p> * Note : The Item is not removed from the underlying Container. * </p> * * @param itemId * the ID of the item to remove from the hierarchy. */ private void removeFromHierarchyWrapper(Object itemId) { LinkedList<Object> oprhanedChildren = children.remove(itemId); if (oprhanedChildren != null) { for (Object object : oprhanedChildren) { // make orphaned children root nodes setParent(object, null); } } roots.remove(itemId); final Object p = parent.get(itemId); if (p != null) { final LinkedList<Object> c = children.get(p); if (c != null) { c.remove(itemId); } } parent.remove(itemId); noChildrenAllowed.remove(itemId); }
@Override public void setContainerDataSource(Container newDataSource) { cStrategy = null; // FIXME: This disables partial updates until TreeTable is fixed so it // does not change component hierarchy during paint containerSupportsPartialUpdates = (newDataSource instanceof ItemSetChangeNotifier) && false; if (newDataSource != null && !(newDataSource instanceof Hierarchical)) { newDataSource = new ContainerHierarchicalWrapper(newDataSource); } if (newDataSource != null && !(newDataSource instanceof Ordered)) { newDataSource = new HierarchicalContainerOrderedWrapper( (Hierarchical) newDataSource); } super.setContainerDataSource(newDataSource); }
/** * Removes an Item specified by the itemId from the underlying container and * from the hierarchy. * * @param itemId * the ID of the Item to be removed. * @return <code>true</code> if the operation succeeded, <code>false</code> * if not * @throws UnsupportedOperationException * if the removeItem is not supported. */ @Override public boolean removeItem(Object itemId) throws UnsupportedOperationException { final boolean success = container.removeItem(itemId); if (!hierarchical && success) { removeFromHierarchyWrapper(itemId); } return success; }
if (!containsId(itemId)) { return false; fireItemSetChangeIfAbstractContainer(); if (!containsId(newParentId) || noChildrenAllowed.contains(newParentId)) { return false; fireItemSetChangeIfAbstractContainer();
@Override public boolean areChildrenAllowed(Object itemId) { // If the wrapped container implements the method directly, use it if (hierarchical) { return ((Container.Hierarchical) container) .areChildrenAllowed(itemId); } if (noChildrenAllowed.contains(itemId)) { return false; } return containsId(itemId); }
/** * @deprecated As of 7.0, replaced by * {@link #addItemSetChangeListener(Container.ItemSetChangeListener)} */ @Override @Deprecated public void addListener(Container.ItemSetChangeListener listener) { addItemSetChangeListener(listener); }
/** * @deprecated As of 7.0, replaced by * {@link #addPropertySetChangeListener(Container.PropertySetChangeListener)} */ @Override @Deprecated public void addListener(Container.PropertySetChangeListener listener) { addPropertySetChangeListener(listener); }
boolean b = super.setParent(itemId, newParentId); if (b) { LinkedList<Object> inlineList = new LinkedList<>();
} else { super.setContainerDataSource( new ContainerHierarchicalWrapper(newDataSource));
@Override protected void removeFromHierarchyWrapper(Object itemId) { boolean b = isFirstId(itemId); if (containsInline(itemId)) { List<Object> inlineChildren; if (areChildrenAllowed(itemId) && (inlineChildren = getInlineChildren(itemId)) != null) { inline.removeAll(inlineChildren); } inline.remove(itemId); } super.removeFromHierarchyWrapper(itemId); if (b) { updateFirst(); } }
@Override public boolean isRoot(Object itemId) { // If the wrapped container implements the method directly, use it if (hierarchical) { return ((Container.Hierarchical) container).isRoot(itemId); } if (parent.containsKey(itemId)) { return false; } return containsId(itemId); }
@Override public void containerPropertySetChange(PropertySetChangeEvent event) { updateHierarchicalWrapper(); ((Container.PropertySetChangeListener) listener) .containerPropertySetChange(event); }
/** * Adds a new Item by its ID to the underlying container and to the * hierarchy. * * @param itemId * the ID of the Item to be created. * @return the added Item or <code>null</code> if the operation failed. * @throws UnsupportedOperationException * if the addItem is not supported. */ @Override public Item addItem(Object itemId) throws UnsupportedOperationException { // Null ids are not accepted if (itemId == null) { return null; } final Item item = container.addItem(itemId); if (!hierarchical && item != null) { addToHierarchyWrapper(itemId); } return item; }
if (!containsId(itemId)) { return false;
/** * Constructs a new hierarchical wrapper for an existing Container. Works * even if the to-be-wrapped container already implements the * <code>Container.Hierarchical</code> interface. * * @param toBeWrapped * the container that needs to be accessed hierarchically * @see #updateHierarchicalWrapper() */ public ContainerHierarchicalWrapper(Container toBeWrapped) { container = toBeWrapped; hierarchical = container instanceof Container.Hierarchical; // Check arguments if (container == null) { throw new NullPointerException("Null can not be wrapped"); } // Create initial order if needed if (!hierarchical) { noChildrenAllowed = new HashSet<Object>(); parent = new Hashtable<Object, Object>(); children = new Hashtable<Object, LinkedList<Object>>(); roots = new LinkedHashSet<Object>(container.getItemIds()); } updateHierarchicalWrapper(); }
@Override protected void addToHierarchyWrapper(Object itemId) { super.addToHierarchyWrapper(itemId); // Add item to the end of the list if (!inline.contains(itemId)) { inline.add(itemId); if (areChildrenAllowed(itemId)) { makeInlineElements(inline, getChildren(itemId)); } } }