/** * Adds the list of {@link PaletteEntry} objects to this PaletteContainer. * * @param list a list of PaletteEntry objects to add to this PaletteContainer */ public void addAll(List list) { ArrayList oldChildren = new ArrayList(getChildren()); for (int i = 0; i < list.size(); i++) { PaletteEntry child = (PaletteEntry) list.get(i); if (!acceptsType(child.getType())) throw new IllegalArgumentException( "This container can not contain this type of child: " //$NON-NLS-1$ + child.getType()); getChildren().add(child); child.setParent(this); } listeners.firePropertyChange(PROPERTY_CHILDREN, oldChildren, getChildren()); }
/** * Adds the given PaletteEntry at position <code>index</code>. * * @param index position to add the PaletteEntry * @param entry the PaletteEntry to add */ public void add(int index, PaletteEntry entry) { if (!acceptsType(entry.getType())) throw new IllegalArgumentException( "This container can not contain this type of child: " //$NON-NLS-1$ + entry.getType()); List oldChildren = new ArrayList(getChildren()); int actualIndex = index < 0 ? getChildren().size() : index; getChildren().add(actualIndex, entry); entry.setParent(this); listeners.firePropertyChange(PROPERTY_CHILDREN, oldChildren, getChildren()); }
/** * Sets the children of this PaletteContainer to the given list of {@link PaletteEntry} objects. * * @param list the list of children */ public void setChildren(List list) { List oldChildren = children; for (int i = 0; i < oldChildren.size(); i++) { PaletteEntry entry = (PaletteEntry) oldChildren.get(i); entry.setParent(null); } children = list; for (int i = 0; i < children.size(); i++) { PaletteEntry entry = (PaletteEntry) children.get(i); entry.setParent(this); } listeners.firePropertyChange(PROPERTY_CHILDREN, oldChildren, getChildren()); }
/** * Appends the given entry after the entry with the given id, but before the next separator. * * @param id the id of the entry to append after * @param entry the entry to add */ public void appendToSection(String id, PaletteEntry entry) { // find the entry with the given id boolean found = false; for (int i = 0; i < getChildren().size(); i++) { PaletteEntry currEntry = (PaletteEntry) getChildren().get(i); if (currEntry.getId().equals(id)) found = true; else if (found && currEntry instanceof PaletteSeparator) { add(i, entry); return; } } if (found) add(entry); else throw new IllegalArgumentException("Section not found: " + id); // $NON-NLS-1$ }
/** * Sets the "active" child entry to the given PaletteEntry. This entry will be shown on the * palette and will be checked in the menu. * * @param entry the entry to show on the palette. */ public void setActiveEntry(PaletteEntry entry) { PaletteEntry oldEntry = activeEntry; if (activeEntry != null && (activeEntry.equals(entry) || !getChildren().contains(entry))) return; activeEntry = entry; listeners.firePropertyChange(PROPERTY_ACTIVE_ENTRY, oldEntry, activeEntry); }
/** * Removes the given PaletteEntry from this PaletteContainer * * @param entry the PaletteEntry to remove */ public void remove(PaletteEntry entry) { List oldChildren = new ArrayList(getChildren()); if (getChildren().remove(entry)) { entry.setParent(null); listeners.firePropertyChange(PROPERTY_CHILDREN, oldChildren, getChildren()); } }
private boolean move(PaletteEntry entry, boolean up) { int index = getChildren().indexOf(entry); if (index < 0) { // This container does not contain the given palette entry return false; } index = up ? index - 1 : index + 1; if (index < 0 || index >= getChildren().size()) { // Performing the move operation will give the child an invalid index return false; } if (getChildren().get(index) instanceof PaletteContainer && getUserModificationPermission() == PaletteEntry.PERMISSION_FULL_MODIFICATION) { // move it into a container if we have full permission PaletteContainer container = (PaletteContainer) getChildren().get(index); if (container.acceptsType(entry.getType()) && container.getUserModificationPermission() == PaletteEntry.PERMISSION_FULL_MODIFICATION) { remove(entry); if (up) container.add(entry); else container.add(0, entry); return true; } } List oldChildren = new ArrayList(getChildren()); getChildren().remove(entry); getChildren().add(index, entry); listeners.firePropertyChange(PROPERTY_CHILDREN, oldChildren, getChildren()); return true; }