Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 259048 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse (+183 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.ui.internal.menus;
13
14
import org.eclipse.core.runtime.IConfigurationElement;
15
import org.eclipse.jface.action.IContributionItem;
16
import org.eclipse.jface.action.IContributionManager;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Control;
19
import org.eclipse.swt.widgets.CoolBar;
20
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
21
import org.eclipse.ui.internal.util.Util;
22
import org.eclipse.ui.menus.IWorkbenchContribution;
23
import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
24
import org.eclipse.ui.services.IServiceLocator;
25
26
/**
27
 * A contribution item which proxies a dynamic tool contribution.
28
 * <p>
29
 * It currently supports placement in menus.
30
 * </p>
31
 * <p>
32
 * 
33
 * @author Prakash G.R.
34
 * 
35
 * @since 3.6
36
 * 
37
 */
38
public class DynamicToolBarContributionItem extends WorkbenchWindowControlContribution {
39
40
	private final IConfigurationElement dynamicAddition;
41
	private final IServiceLocator locator;
42
	private boolean alreadyFailed;
43
	private WorkbenchWindowControlContribution loadedDynamicContribution;
44
45
	/**
46
	 * Creates a DynamicToolBarContributionItem
47
	 * 
48
	 * @param id
49
	 *            - Id of the menu item
50
	 * @param locator
51
	 *            - The Service Locator
52
	 * @param dynamicAddition
53
	 *            - The Configuration Element defined in the plugin.xml
54
	 * 
55
	 */
56
	public DynamicToolBarContributionItem(String id, IServiceLocator locator,
57
			IConfigurationElement dynamicAddition) {
58
		super(id);
59
60
		this.locator = locator;
61
		this.dynamicAddition = dynamicAddition;
62
	}
63
64
	/*
65
	 * (non-Javadoc)
66
	 * 
67
	 * @see org.eclipse.jface.action.ContributionItem#isDynamic()
68
	 */
69
	public boolean isDynamic() {
70
		if (loadedDynamicContribution != null) {
71
			return loadedDynamicContribution.isDynamic();
72
		}
73
		return true;
74
	}
75
76
	/*
77
	 * (non-Javadoc)
78
	 * 
79
	 * @see org.eclipse.jface.action.ContributionItem#isDirty()
80
	 */
81
	public boolean isDirty() {
82
		if (loadedDynamicContribution != null) {
83
			return loadedDynamicContribution.isDirty();
84
		}
85
		return super.isDirty();
86
	}
87
88
	/*
89
	 * (non-Javadoc)
90
	 * 
91
	 * @see
92
	 * org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets
93
	 * .CoolBar, int)
94
	 */
95
	public void fill(CoolBar parent, int index) {
96
		IContributionItem contributionItem = getContributionItem();
97
		if (contributionItem != null)
98
			contributionItem.fill(parent, index);
99
	}
100
101
	private WorkbenchWindowControlContribution getContributionItem() {
102
		if (loadedDynamicContribution == null && !alreadyFailed)
103
			createContributionItem();
104
		return loadedDynamicContribution;
105
	}
106
107
	private void createContributionItem() {
108
109
		loadedDynamicContribution = (WorkbenchWindowControlContribution) Util
110
				.safeLoadExecutableExtension(dynamicAddition,
111
						IWorkbenchRegistryConstants.ATT_CLASS,
112
						WorkbenchWindowControlContribution.class);
113
114
		if (loadedDynamicContribution == null) {
115
			alreadyFailed = true;
116
			return;
117
		}
118
119
		loadedDynamicContribution.setId(getId());
120
		loadedDynamicContribution.setParent(getParent());
121
		if (loadedDynamicContribution instanceof IWorkbenchContribution) {
122
			((IWorkbenchContribution) loadedDynamicContribution)
123
					.initialize(locator);
124
		}
125
	}
126
127
	/*
128
	 * (non-Javadoc)
129
	 * 
130
	 * @see org.eclipse.jface.action.ContributionItem#dispose()
131
	 */
132
	public void dispose() {
133
		if (loadedDynamicContribution != null) {
134
			loadedDynamicContribution.dispose();
135
			loadedDynamicContribution = null;
136
		}
137
		super.dispose();
138
	}
139
140
	/*
141
	 * (non-Javadoc)
142
	 * 
143
	 * @see org.eclipse.jface.action.ContributionItem#update()
144
	 */
145
	public void update() {
146
		if (loadedDynamicContribution != null) {
147
			loadedDynamicContribution.update();
148
		}
149
	}
150
151
	public void update(String id) {
152
		if (loadedDynamicContribution != null) {
153
			loadedDynamicContribution.update(id);
154
		}
155
	}
156
157
	/*
158
	 * (non-Javadoc)
159
	 * 
160
	 * @see
161
	 * org.eclipse.jface.action.ContributionItem#setParent(org.eclipse.jface
162
	 * .action.IContributionManager)
163
	 */
164
	public void setParent(IContributionManager parent) {
165
		super.setParent(parent);
166
		if (loadedDynamicContribution != null) {
167
			loadedDynamicContribution.setParent(parent);
168
		}
169
	}
170
171
	/* 
172
	 * (non-Javadoc)
173
	 * @see org.eclipse.jface.action.ControlContribution#createControl(org.eclipse.swt.widgets.Composite)
174
	 */
175
	public Control createControl(Composite parent) {
176
		
177
		WorkbenchWindowControlContribution contributionItem = getContributionItem();
178
		if (contributionItem != null)
179
			return contributionItem.delegateCreateControl(parent);
180
		return null;
181
	}
182
183
}
(-)Eclipse UI/org/eclipse/ui/internal/menus/MenuAdditionCacheEntry.java (-41 / +6 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2008 IBM Corporation and others.
2
 * Copyright (c) 2006, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 14-23 Link Here
14
14
15
import java.util.ArrayList;
15
import java.util.ArrayList;
16
import java.util.HashMap;
16
import java.util.HashMap;
17
import java.util.HashSet;
18
import java.util.List;
17
import java.util.List;
19
import java.util.Map;
18
import java.util.Map;
20
import java.util.Set;
21
19
22
import org.eclipse.core.expressions.Expression;
20
import org.eclipse.core.expressions.Expression;
23
import org.eclipse.core.expressions.ExpressionConverter;
21
import org.eclipse.core.expressions.ExpressionConverter;
Lines 37-49 Link Here
37
import org.eclipse.ui.internal.provisional.presentations.IActionBarPresentationFactory;
35
import org.eclipse.ui.internal.provisional.presentations.IActionBarPresentationFactory;
38
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
36
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
39
import org.eclipse.ui.internal.services.IWorkbenchLocationService;
37
import org.eclipse.ui.internal.services.IWorkbenchLocationService;
40
import org.eclipse.ui.internal.util.Util;
41
import org.eclipse.ui.menus.CommandContributionItem;
38
import org.eclipse.ui.menus.CommandContributionItem;
42
import org.eclipse.ui.menus.CommandContributionItemParameter;
39
import org.eclipse.ui.menus.CommandContributionItemParameter;
43
import org.eclipse.ui.menus.IContributionRoot;
40
import org.eclipse.ui.menus.IContributionRoot;
44
import org.eclipse.ui.menus.IMenuService;
41
import org.eclipse.ui.menus.IMenuService;
45
import org.eclipse.ui.menus.IWorkbenchContribution;
46
import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
47
import org.eclipse.ui.plugin.AbstractUIPlugin;
42
import org.eclipse.ui.plugin.AbstractUIPlugin;
48
import org.eclipse.ui.services.IServiceLocator;
43
import org.eclipse.ui.services.IServiceLocator;
49
44
Lines 53-68 Link Here
53
 */
48
 */
54
public class MenuAdditionCacheEntry extends AbstractMenuAdditionCacheEntry {
49
public class MenuAdditionCacheEntry extends AbstractMenuAdditionCacheEntry {
55
	
50
	
56
	// Caches
57
	
58
	/**
59
	 * If an {@link IConfigurationElement} is in the Set then we have already
60
	 * tried (and failed) to load the associated ExecutableExtension.
61
	 * 
62
	 * This is used to prevent multiple retries which would spam the Log.
63
	 */
64
	Set failedLoads = new HashSet();
65
66
	/**
51
	/**
67
	 * Maps an IConfigurationElement to its parsed Expression
52
	 * Maps an IConfigurationElement to its parsed Expression
68
	 */
53
	 */
Lines 284-316 Link Here
284
	private IContributionItem createControlAdditionContribution(
269
	private IContributionItem createControlAdditionContribution(
285
			final IServiceLocator locator,
270
			final IServiceLocator locator,
286
			final IConfigurationElement widgetAddition) {
271
			final IConfigurationElement widgetAddition) {
287
		if (!inToolbar()) {
288
			return null;
289
		}
290
		// If we've already tried (and failed) to load the
291
		// executable extension then skip this addirion.
292
		if (failedLoads.contains(widgetAddition))
293
			return null;
294
272
295
		// Attempt to load the addition's EE (creates a new instance)
273
		if (inToolbar()) {
296
		final WorkbenchWindowControlContribution loadedWidget = (WorkbenchWindowControlContribution) Util
274
			return new DynamicToolBarContributionItem(getId(widgetAddition), locator, widgetAddition);
297
				.safeLoadExecutableExtension(widgetAddition,
298
						IWorkbenchRegistryConstants.ATT_CLASS,
299
						WorkbenchWindowControlContribution.class);
300
301
		// Cache failures
302
		if (loadedWidget == null) {
303
			failedLoads.add(widgetAddition);
304
			return null;
305
		}
306
307
		// explicitly set the id
308
		loadedWidget.setId(getId(widgetAddition));
309
		if (loadedWidget instanceof IWorkbenchContribution) {
310
			((IWorkbenchContribution)loadedWidget).initialize(locator);
311
		}
275
		}
312
276
		
313
		return loadedWidget;
277
		return null;
278
		
314
	}
279
	}
315
280
316
	private IContributionItem createCommandAdditionContribution(
281
	private IContributionItem createCommandAdditionContribution(
(-)Eclipse UI/org/eclipse/ui/menus/WorkbenchWindowControlContribution.java (-1 / +20 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
2
 * Copyright (c) 2007 - 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 13-18 Link Here
13
13
14
import org.eclipse.jface.action.ControlContribution;
14
import org.eclipse.jface.action.ControlContribution;
15
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Control;
16
import org.eclipse.ui.IWorkbenchWindow;
18
import org.eclipse.ui.IWorkbenchWindow;
17
import org.eclipse.ui.internal.menus.InternalControlContribution;
19
import org.eclipse.ui.internal.menus.InternalControlContribution;
18
20
Lines 82-85 Link Here
82
		
84
		
83
		return SWT.HORIZONTAL;
85
		return SWT.HORIZONTAL;
84
	}
86
	}
87
88
	/**
89
	 * Important: This method is *NOT* to be used/extended by clients. This is
90
	 * for the internal use inside Workbench
91
	 * 
92
	 * @param parent
93
	 *            the parent composite
94
	 * @return newly created Control
95
	 * @since 3.6
96
	 * 
97
	 * @noreference This method is not intended to be referenced by clients.
98
	 * @nooverride This method is not intended to be re-implemented or extended
99
	 *             by clients.
100
	 */
101
	public Control delegateCreateControl(Composite parent) {
102
		return createControl(parent);
103
	}
85
}
104
}

Return to bug 259048