Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 124892 Details for
Bug 211065
[Palette] Cannot cancel changes made in Customize Palette dialog
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
I've created default save and restoreToSaved methods.
patch211065.txt (text/plain), 6.97 KB, created by
Brendan Curran-Johnson
on 2009-02-05 16:58:28 EST
(
hide
)
Description:
I've created default save and restoreToSaved methods.
Filename:
MIME Type:
Creator:
Brendan Curran-Johnson
Created:
2009-02-05 16:58:28 EST
Size:
6.97 KB
patch
obsolete
>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 @@ > > /** > * <code>PaletteCustomizer</code> is the <code>PaletteCustomizerDialog</code>'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()}). > * <p> > * This method will be invoked by <code>PaletteCustomizerDialog</code> 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 @@ > * <code>PaletteCustomizerDialog</code>. > * </p> > */ >-public abstract void revertToSaved(); >+public void revertToSaved(){ >+ if (saved) >+ { >+ List newElements = root.getChildren(); >+ >+ for (int index=0;index<elements.size();index++) >+ { >+ PaletteEntry entry = ((ElementData)elements.get(index)).getEntry(); >+ >+ newElements.remove(entry); >+ >+ if(entry instanceof PaletteContainer) >+ newElements.addAll(((PaletteContainer)entry).getChildren()); >+ } >+ >+ while(!newElements.isEmpty()) >+ { >+ PaletteEntry entry = (PaletteEntry)newElements.get(0); >+ newElements.remove(0); >+ entry.getParent().remove(entry); >+ } >+ >+ ElementData ed; >+ int index=0; >+ while (index<elements.size()) >+ { >+ ed = (ElementData)elements.get(index); >+ >+ if (changed(ed)) >+ { >+ for(;index<elements.size();index++) >+ { >+ ed = (ElementData)elements.get(index); >+ revert(ed); >+ } >+ } >+ index++; >+ } >+ } >+ >+ clearBackup(); >+} > > /** > * Persists the changes made to the model. >@@ -305,6 +379,90 @@ > * Called when "OK" or "Apply" are selected in the <code>PaletteCustomizerDialog</code>. > * </p> > */ >-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<children.size();i++) >+ { >+ ElementData ed = new ElementData((PaletteEntry)children.get(i)); >+ elements.add(ed); >+ >+ if (ed.entry instanceof PaletteContainer) >+ backupChildren((PaletteContainer)ed.entry); >+ } >+} >+ >+/** >+ * Tests whether the positioning of an element has changed since the palette was saved >+ * @param ed Data pertaining to the elements original location >+ * @return true if changed >+ * @since 3.2 >+ */ >+private boolean changed(ElementData ed){ >+ >+ return !((ed.entry.getParent()!=null)&&ed.parent.equals(ed.entry.getParent())&&ed.index==ed.parent.getChildren().indexOf(ed.entry)); >+} > >+/** >+ * moves an element back to its original location >+ * @param ed Data pertaining to the elements original location >+ * @since 3.2 >+ */ >+private void revert(ElementData ed){ >+ if (ed.entry.getParent()!=null) >+ performDelete(ed.entry); >+ ed.parent.add(ed.index,ed.entry); > } >+ >+ >+} >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 211065
: 124892