Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/menus/CommandContributionItem.java')
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/menus/CommandContributionItem.java131
1 files changed, 70 insertions, 61 deletions
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 1ddf6f14e7c..f9469357b57 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;

Back to the top