Index: src/org/eclipse/gef/ui/palette/PaletteCustomizer.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.gef/src/org/eclipse/gef/ui/palette/PaletteCustomizer.java,v retrieving revision 1.21 diff -u -r1.21 PaletteCustomizer.java --- src/org/eclipse/gef/ui/palette/PaletteCustomizer.java 30 Mar 2005 21:27:02 -0000 1.21 +++ src/org/eclipse/gef/ui/palette/PaletteCustomizer.java 5 Feb 2009 21:54:01 -0000 @@ -16,6 +16,7 @@ import org.eclipse.gef.palette.PaletteContainer; import org.eclipse.gef.palette.PaletteDrawer; import org.eclipse.gef.palette.PaletteEntry; +import org.eclipse.gef.palette.PaletteRoot; import org.eclipse.gef.ui.palette.customize.DefaultEntryPage; import org.eclipse.gef.ui.palette.customize.DrawerEntryPage; import org.eclipse.gef.ui.palette.customize.EntryPage; @@ -25,7 +26,7 @@ /** * PaletteCustomizer is the PaletteCustomizerDialog's interface - * to the model. This class is responsible for propogating to the model changes made in + * to the model. This class is responsible for propagating to the model changes made in * the dialog. * * @author Pratik Shah @@ -33,6 +34,35 @@ public abstract class PaletteCustomizer { /** + * Fix 211065 + * ElementData keeps track of the important info about + * about the PaletteElements in order to check whether + * any changes to the palette have been made. information + * about children isn't stored, since all original elements + * are being stored, and can be compared against. + */ +class ElementData{ + private PaletteEntry entry; + private PaletteContainer parent; + private int index; + + private ElementData(PaletteEntry entry) + { + this.entry = entry; + parent = entry.getParent(); + index = parent.getChildren().indexOf(entry); + } + + PaletteEntry getEntry(){return entry;} + PaletteContainer getParent(){return parent;} + int getIndex(){return index;} +} + +private PaletteRoot root = null; +private List elements = null; +private boolean saved = false; + +/** * Return true if this container can accept this entry as a new child. By default, this * method checks to see first if the container has full permissions, then checks * to see if this container can accept the type of the entry. @@ -47,7 +77,7 @@ /** * Indicates whether the given entry can be deleted from the model or not. Whether or not - * an entry can be deleted depends on its permsission + * an entry can be deleted depends on its permission * ({@link PaletteEntry#getUserModificationPermission()}). *

* This method will be invoked by PaletteCustomizerDialog to determine @@ -207,6 +237,7 @@ * @see #canDelete(PaletteEntry) */ public void performDelete(PaletteEntry entry) { + backupPalette(entry); entry.getParent().remove(entry); } @@ -220,6 +251,7 @@ * @see #canMoveDown(PaletteEntry) */ public void performMoveDown(PaletteEntry entry) { + backupPalette(entry); PaletteContainer parent = entry.getParent(); if (!parent.moveDown(entry)) { // This is the case of a PaletteEntry that is its parent's last child @@ -259,6 +291,7 @@ * @see #canMoveUp(PaletteEntry) */ public void performMoveUp(PaletteEntry entry) { + backupPalette(entry); PaletteContainer parent = entry.getParent(); if (!parent.moveUp(entry)) { //This is the case of a PaletteEntry that is its parent's first child @@ -297,7 +330,48 @@ * PaletteCustomizerDialog. *

*/ -public abstract void revertToSaved(); +public void revertToSaved(){ + if (saved) + { + List newElements = root.getChildren(); + + for (int index=0;indexPaletteCustomizerDialog. *

*/ -public abstract void save(); +public void save(){ + clearBackup(); +} + +/** + * Backs up the palette. This involves recording what elements are on the palette and their location + * @param entry An entry in the palette + * @since 3.2 + */ +protected void backupPalette(PaletteEntry entry){ + if (!saved) + { + root = findRoot(entry); + elements = new ArrayList(); + backupChildren(root); + } + + saved = true; +} + +/** + * Clears the stored backup and makes a new one + * @since 3.2 + */ +protected void clearBackup(){ + saved = false; + + if (root!=null) + backupPalette(root); +} + +/** + * Finds the paletteRoot for a given PaletteEntry + * @param entry the provided entry + * @return entry's PaletteRoot (or itself, if entry is a PaletteRoot, or null if entry is not connected with any paletteRoot + * @since 3.2 + */ +protected PaletteRoot findRoot(PaletteEntry entry){ + if (entry==null||((!(entry instanceof PaletteRoot))&&entry.getParent()==null)) + return null; + else + return (entry instanceof PaletteRoot? (PaletteRoot)entry:findRoot(entry.getParent())); +} + +/** + * Recursively adds all children, grandchildren, etc of a parent to the saved elements + * @param parent the parent who's children are being backed up + * @since 3.2 + */ +protected void backupChildren(PaletteContainer parent) +{ + List children = parent.getChildren(); + + for(int i=0;i