From b378e3cdb4352bc8a359e63ffad935262c85f925 Mon Sep 17 00:00:00 2001 From: Max Schenkelberg Date: Thu, 28 Jun 2012 11:45:59 -0500 Subject: [PATCH] Issue #821 Fixed editor menu so plugin.xml action contribution items are created every time the menu is shown to make sure any submenus are recreated in the action. Change-Id: I9f2103b1e8fcddc5bc790d74753733a42f9e6382 Former-commit-id: 53fd2ec047b68a4931b7be05a6d2b869340f2af1 [formerly 84ae71756320767aab1ace1b782fc49ce711b498] [formerly 53fd2ec047b68a4931b7be05a6d2b869340f2af1 [formerly 84ae71756320767aab1ace1b782fc49ce711b498] [formerly 668838364d38c1f19642effe95fcad7e99a65cc0 [formerly 537240ee2e9dfb7c110f8d3a63566932b599dfdf]]] Former-commit-id: 668838364d38c1f19642effe95fcad7e99a65cc0 Former-commit-id: f1eb4b47137c31f57ae04768a1437e467cd4fc06 [formerly e3524fd4df353782b869a2c3088694b22909e1ab] Former-commit-id: d12df1af569dcb9a8467cae82f2be03a90ab6ee2 --- .../awips/VizEditorSystemMenu.java | 47 ++++++------------- .../AbstractVizPerspectiveManager.java | 2 +- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/VizEditorSystemMenu.java b/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/VizEditorSystemMenu.java index ceffe0cfad..c5ff639969 100644 --- a/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/VizEditorSystemMenu.java +++ b/cave/com.raytheon.viz.ui.personalities.awips/src/com/raytheon/viz/ui/personalities/awips/VizEditorSystemMenu.java @@ -9,10 +9,8 @@ import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.GroupMarker; -import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IContributionItem; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; @@ -162,6 +160,8 @@ public class VizEditorSystemMenu implements ISystemMenu { private ActionFactory.IWorkbenchAction openAgain; + private Menu lastShown; + /** * Create the standard view menu * @@ -231,10 +231,6 @@ public class VizEditorSystemMenu implements ISystemMenu { } } } - // loop through and add all the actions - for (Action act : userContributionActions) { - menuManager.add(act); - } } } @@ -251,6 +247,10 @@ public class VizEditorSystemMenu implements ISystemMenu { */ public void show(Control parent, Point displayCoordinates, IPresentablePart currentSelection) { + if (lastShown != null) { + lastShown.dispose(); + } + closeOthers.setTarget(currentSelection); closeAll.update(); restore.update(); @@ -260,38 +260,21 @@ public class VizEditorSystemMenu implements ISystemMenu { maximize.update(); close.setTarget(currentSelection); - // loop through all the contributed actions and update them as necessary - List shouldBeShown = new ArrayList(); - List shouldBeHidden = new ArrayList(); + MenuManager toShow = new MenuManager(menuManager.getMenuText(), + menuManager.getId()); + for (IContributionItem item : menuManager.getItems()) { + toShow.add(item); + } for (ContributedEditorMenuAction action : userContributionActions) { - action.setPart(currentSelection); if (action.shouldBeVisible()) { - shouldBeShown.add(action); - } else { - shouldBeHidden.add(action); + action.setPart(currentSelection); + toShow.add(new ActionContributionItem(action)); } } - for (IContributionItem item : menuManager.getItems()) { - if (item instanceof ActionContributionItem) { - IAction action = ((ActionContributionItem) item).getAction(); - if (shouldBeShown.contains(action)) { - shouldBeShown.remove(action); - } else if (shouldBeHidden.contains(action)) { - menuManager.remove(item); - } - } - } - - if (shouldBeShown.size() > 0) { - for (ContributedEditorMenuAction action : shouldBeShown) { - menuManager.add(action); - } - } - - Menu aMenu = menuManager.createContextMenu(parent); - menuManager.update(true); + Menu aMenu = lastShown = toShow.createContextMenu(parent); + toShow.update(true); aMenu.setLocation(displayCoordinates.x, displayCoordinates.y); aMenu.setVisible(true); } diff --git a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/perspectives/AbstractVizPerspectiveManager.java b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/perspectives/AbstractVizPerspectiveManager.java index df47fffc17..ad6665cf48 100644 --- a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/perspectives/AbstractVizPerspectiveManager.java +++ b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/perspectives/AbstractVizPerspectiveManager.java @@ -490,7 +490,7 @@ public abstract class AbstractVizPerspectiveManager implements protected void deactivateContexts(ContextManager manager) { manager.deactivateContexts(this); - if (page != null) { + if (page != null && page.getActivePart() != null) { manager.deactivateContexts(page.getActivePart()); } }