aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Besedin2012-09-21 10:15:24 (EDT)
committerOleg Besedin2012-09-21 10:16:15 (EDT)
commitc50d62e0e5dbd753e6560440392780b7fdcd6707 (patch)
tree9b73b3757c9a05d60b168202068e647cc00fd710
parent38339b33b6f1fb0b1abcef7d7bc0df7547ab46ab (diff)
downloadeclipse.platform.ui-c50d62e0e5dbd753e6560440392780b7fdcd6707.zip
eclipse.platform.ui-c50d62e0e5dbd753e6560440392780b7fdcd6707.tar.gz
eclipse.platform.ui-c50d62e0e5dbd753e6560440392780b7fdcd6707.tar.bz2
Bug 389335 - CommandContributionItem IBindingManagerListener leak
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ShowViewMenu.java19
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandService.java2
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/menus/CommandContributionItem.java131
3 files changed, 84 insertions, 68 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ShowViewMenu.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ShowViewMenu.java
index 83145aa..6ff4736 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ShowViewMenu.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ShowViewMenu.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,6 +11,7 @@
package org.eclipse.ui.internal;
+import com.ibm.icu.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -19,7 +20,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IParameter;
@@ -53,8 +53,6 @@ import org.eclipse.ui.services.IServiceLocator;
import org.eclipse.ui.views.IViewDescriptor;
import org.eclipse.ui.views.IViewRegistry;
-import com.ibm.icu.text.Collator;
-
/**
* A <code>ShowViewMenu</code> is used to populate a menu manager with Show
* View actions. The visible views are determined by user preference from the
@@ -93,6 +91,8 @@ public class ShowViewMenu extends ContributionItem {
// Maps pages to a list of opened views
private Map openedViews = new HashMap();
+ private MenuManager menuManager;
+
private IMenuListener menuListener = new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
manager.markDirty();
@@ -316,9 +316,14 @@ public class ShowViewMenu extends ContributionItem {
((MenuManager) getParent()).addMenuListener(menuListener);
}
- MenuManager manager = new MenuManager();
- fillMenu(manager);
- IContributionItem items[] = manager.getItems();
+ if (menuManager != null) {
+ menuManager.dispose();
+ menuManager = null;
+ }
+
+ menuManager = new MenuManager();
+ fillMenu(menuManager);
+ IContributionItem items[] = menuManager.getItems();
if (items.length == 0) {
MenuItem item = new MenuItem(menu, SWT.NONE, index++);
item.setText(NO_TARGETS_MSG);
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandService.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandService.java
index 59ff720..39a8b47 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandService.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/CommandService.java
@@ -328,6 +328,8 @@ public final class CommandService implements ICommandService, IUpdateService {
* @see org.eclipse.ui.commands.ICommandService#unregisterElement(org.eclipse.ui.commands.IElementReference)
*/
public void unregisterElement(IElementReference elementReference) {
+ if (commandCallbacks == null)
+ return;
List parameterizedCommands = (List) commandCallbacks
.get(elementReference.getCommandId());
if (parameterizedCommands != null) {
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/menus/CommandContributionItem.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/menus/CommandContributionItem.java
index 1ddf6f1..f946935 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/menus/CommandContributionItem.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/menus/CommandContributionItem.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 IBM Corporation and others.
+ * Copyright (c) 2006, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -216,41 +216,6 @@ public class CommandContributionItem extends ContributionItem {
contributionParameters.parameters);
if (command != null) {
- try {
- UIElement callback = new UIElement(
- contributionParameters.serviceLocator) {
-
- public void setChecked(boolean checked) {
- CommandContributionItem.this.setChecked(checked);
- }
-
- public void setDisabledIcon(ImageDescriptor desc) {
- CommandContributionItem.this.setDisabledIcon(desc);
- }
-
- public void setHoverIcon(ImageDescriptor desc) {
- CommandContributionItem.this.setHoverIcon(desc);
- }
-
- public void setIcon(ImageDescriptor desc) {
- CommandContributionItem.this.setIcon(desc);
- }
-
- public void setText(String text) {
- CommandContributionItem.this.setText(text);
- }
-
- public void setTooltip(String text) {
- CommandContributionItem.this.setTooltip(text);
- }
-
- public void setDropDownId(String id) {
- dropDownMenuOverride = id;
- }
- };
- elementRef = commandService.registerElementForCommand(command,
- callback);
- command.getCommand().addCommandListener(getCommandListener());
setImages(contributionParameters.serviceLocator,
contributionParameters.iconStyle);
@@ -268,17 +233,6 @@ public class CommandContributionItem extends ContributionItem {
if (workbench != null && helpContextId != null) {
this.workbenchHelpSystem = workbench.getHelpSystem();
}
- } catch (NotDefinedException e) {
- StatusManager
- .getManager()
- .handle(
- StatusUtil
- .newStatus(
- IStatus.ERROR,
- "Unable to register menu item \"" + getId() //$NON-NLS-1$
- + "\", command \"" + contributionParameters.commandId + "\" not defined", //$NON-NLS-1$ //$NON-NLS-2$
- null));
- }
}
}
@@ -490,8 +444,7 @@ public class CommandContributionItem extends ContributionItem {
update(null);
updateIcons();
- bindingService.addBindingManagerListener(bindingManagerListener);
-
+ establishReferences();
}
/* (non-Javadoc)
@@ -522,8 +475,7 @@ public class CommandContributionItem extends ContributionItem {
update(null);
updateIcons();
- bindingService.addBindingManagerListener(bindingManagerListener);
-
+ establishReferences();
}
/*
@@ -557,7 +509,7 @@ public class CommandContributionItem extends ContributionItem {
update(null);
updateIcons();
- bindingService.addBindingManagerListener(bindingManagerListener);
+ establishReferences();
}
/*
@@ -741,6 +693,7 @@ public class CommandContributionItem extends ContributionItem {
private void handleWidgetDispose(Event event) {
if (event.widget == widget) {
+ disconnectReferences();
widget.removeListener(SWT.Selection, getItemListener());
widget.removeListener(SWT.Dispose, getItemListener());
widget = null;
@@ -748,16 +701,58 @@ public class CommandContributionItem extends ContributionItem {
}
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.action.ContributionItem#dispose()
- */
- public void dispose() {
- if (widget != null) {
- widget.dispose();
- widget = null;
+ public void setParent(IContributionManager parent) {
+ super.setParent(parent);
+ if (parent == null)
+ disconnectReferences();
+ }
+
+ private void establishReferences() {
+ if (command != null) {
+ UIElement callback = new UIElement(serviceLocator) {
+
+ public void setChecked(boolean checked) {
+ CommandContributionItem.this.setChecked(checked);
+ }
+
+ public void setDisabledIcon(ImageDescriptor desc) {
+ CommandContributionItem.this.setDisabledIcon(desc);
+ }
+
+ public void setHoverIcon(ImageDescriptor desc) {
+ CommandContributionItem.this.setHoverIcon(desc);
+ }
+
+ public void setIcon(ImageDescriptor desc) {
+ CommandContributionItem.this.setIcon(desc);
+ }
+
+ public void setText(String text) {
+ CommandContributionItem.this.setText(text);
+ }
+
+ public void setTooltip(String text) {
+ CommandContributionItem.this.setTooltip(text);
+ }
+
+ public void setDropDownId(String id) {
+ dropDownMenuOverride = id;
+ }
+ };
+ try {
+ elementRef = commandService.registerElementForCommand(command, callback);
+ } catch (NotDefinedException e) {
+ StatusManager.getManager().handle(
+ StatusUtil.newStatus(IStatus.ERROR, "Unable to register menu item \"" + getId() //$NON-NLS-1$
+ + "\", command \"" + command.getId() + "\" not defined", //$NON-NLS-1$ //$NON-NLS-2$
+ null));
+ }
+ command.getCommand().addCommandListener(getCommandListener());
}
+ bindingService.addBindingManagerListener(bindingManagerListener);
+ }
+
+ private void disconnectReferences() {
if (elementRef != null) {
commandService.unregisterElement(elementRef);
elementRef = null;
@@ -770,6 +765,20 @@ public class CommandContributionItem extends ContributionItem {
if (bindingService != null) {
bindingService.removeBindingManagerListener(bindingManagerListener);
}
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.action.ContributionItem#dispose()
+ */
+ public void dispose() {
+ if (widget != null) {
+ widget.dispose();
+ widget = null;
+ }
+
+ disconnectReferences();
command = null;
commandService = null;