View | Details | Raw Unified | Return to bug 366528 | Differences between
and this patch

Collapse All | Expand All

(-)a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ToolBarManagerRenderer.java (-1 / +1 lines)
Lines 289-295 public class ToolBarManagerRenderer extends SWTPartRenderer { Link Here
289
	/**
289
	/**
290
	 * @param element
290
	 * @param element
291
	 */
291
	 */
292
	private void processContribution(MToolBar toolbarModel) {
292
	public void processContribution(MToolBar toolbarModel) {
293
		final ArrayList<MToolBarContribution> toContribute = new ArrayList<MToolBarContribution>();
293
		final ArrayList<MToolBarContribution> toContribute = new ArrayList<MToolBarContribution>();
294
		ContributionsAnalyzer.XXXgatherToolBarContributions(toolbarModel,
294
		ContributionsAnalyzer.XXXgatherToolBarContributions(toolbarModel,
295
				application.getToolBarContributions(),
295
				application.getToolBarContributions(),
(-)a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java (+1 lines)
Lines 2687-2692 UIEvents.Context.TOPIC_CONTEXT, Link Here
2687
		cancelEarlyStartup();
2687
		cancelEarlyStartup();
2688
		if (workbenchService != null)
2688
		if (workbenchService != null)
2689
			workbenchService.unregister();
2689
			workbenchService.unregister();
2690
		workbenchService = null;
2690
2691
2691
		// for dynamic UI
2692
		// for dynamic UI
2692
		Platform.getExtensionRegistry().removeRegistryChangeListener(extensionEventHandler);
2693
		Platform.getExtensionRegistry().removeRegistryChangeListener(extensionEventHandler);
(-)a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/WorkbenchMenuService.java (-20 / +255 lines)
Lines 11-17 Link Here
11
11
12
package org.eclipse.ui.internal.menus;
12
package org.eclipse.ui.internal.menus;
13
13
14
import java.util.ArrayList;
14
import java.util.HashMap;
15
import java.util.HashMap;
16
import java.util.List;
15
import java.util.Map;
17
import java.util.Map;
16
import java.util.Set;
18
import java.util.Set;
17
import org.eclipse.core.expressions.Expression;
19
import org.eclipse.core.expressions.Expression;
Lines 19-79 import org.eclipse.core.expressions.IEvaluationContext; Link Here
19
import org.eclipse.e4.core.contexts.ContextFunction;
21
import org.eclipse.e4.core.contexts.ContextFunction;
20
import org.eclipse.e4.core.contexts.IEclipseContext;
22
import org.eclipse.e4.core.contexts.IEclipseContext;
21
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer;
23
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer;
24
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
22
import org.eclipse.e4.ui.model.application.MApplication;
25
import org.eclipse.e4.ui.model.application.MApplication;
26
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
27
import org.eclipse.e4.ui.model.application.ui.MUIElement;
28
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
29
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
30
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
23
import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution;
31
import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution;
32
import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
24
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarContribution;
33
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarContribution;
25
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl;
34
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl;
26
import org.eclipse.e4.ui.workbench.modeling.ExpressionContext;
35
import org.eclipse.e4.ui.workbench.modeling.ExpressionContext;
27
import org.eclipse.e4.ui.workbench.renderers.swt.ContributionRecord;
36
import org.eclipse.e4.ui.workbench.renderers.swt.ContributionRecord;
37
import org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer;
28
import org.eclipse.e4.ui.workbench.renderers.swt.ToolBarContributionRecord;
38
import org.eclipse.e4.ui.workbench.renderers.swt.ToolBarContributionRecord;
39
import org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer;
40
import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory;
29
import org.eclipse.jface.action.ContributionManager;
41
import org.eclipse.jface.action.ContributionManager;
30
import org.eclipse.jface.action.IContributionItem;
42
import org.eclipse.jface.action.IContributionItem;
43
import org.eclipse.jface.action.MenuManager;
44
import org.eclipse.jface.action.ToolBarManager;
45
import org.eclipse.swt.widgets.Control;
46
import org.eclipse.swt.widgets.Menu;
31
import org.eclipse.ui.ISourceProvider;
47
import org.eclipse.ui.ISourceProvider;
48
import org.eclipse.ui.IWorkbench;
49
import org.eclipse.ui.IWorkbenchWindow;
50
import org.eclipse.ui.internal.WorkbenchWindow;
32
import org.eclipse.ui.internal.e4.compatibility.E4Util;
51
import org.eclipse.ui.internal.e4.compatibility.E4Util;
52
import org.eclipse.ui.internal.services.IWorkbenchLocationService;
33
import org.eclipse.ui.internal.services.ServiceLocator;
53
import org.eclipse.ui.internal.services.ServiceLocator;
34
import org.eclipse.ui.menus.AbstractContributionFactory;
54
import org.eclipse.ui.menus.AbstractContributionFactory;
35
import org.eclipse.ui.menus.IMenuService;
55
import org.eclipse.ui.menus.IMenuService;
36
56
37
/**
57
/**
38
 * @since 3.5
58
 * @since 3.5
39
 *
59
 * 
40
 */
60
 */
41
public class WorkbenchMenuService implements IMenuService {
61
public class WorkbenchMenuService implements IMenuService {
42
62
43
	private IEclipseContext e4Context;
63
	private IEclipseContext e4Context;
44
	// private ServiceLocator serviceLocator;
64
	private ServiceLocator serviceLocator;
45
	private ExpressionContext legacyContext;
65
	private ExpressionContext legacyContext;
46
	private MenuPersistence persistence;
66
	private MenuPersistence persistence;
47
	private Map<AbstractContributionFactory, Object> factoriesToContributions = new HashMap<AbstractContributionFactory, Object>();
67
	private Map<AbstractContributionFactory, Object> factoriesToContributions = new HashMap<AbstractContributionFactory, Object>();
68
	private IWorkbenchWindow window;
69
70
	private Map<ContributionManager, MenuLocationURI> managers = new HashMap<ContributionManager, MenuLocationURI>();
48
71
49
	/**
72
	/**
50
	 * @param serviceLocator
73
	 * @param serviceLocator
51
	 * @param e4Context
74
	 * @param e4Context
52
	 */
75
	 */
53
	public WorkbenchMenuService(ServiceLocator serviceLocator, IEclipseContext e4Context) {
76
	public WorkbenchMenuService(ServiceLocator serviceLocator, IEclipseContext e4Context) {
54
		// this.serviceLocator = serviceLocator;
77
		this.serviceLocator = serviceLocator;
55
		this.e4Context = e4Context;
78
		this.e4Context = e4Context;
56
79
57
		persistence = new MenuPersistence(e4Context.get(MApplication.class), e4Context);
80
		persistence = new MenuPersistence(e4Context.get(MApplication.class), e4Context);
58
	}
81
	}
59
82
60
	/* (non-Javadoc)
83
	/*
61
	 * @see org.eclipse.ui.services.IServiceWithSources#addSourceProvider(org.eclipse.ui.ISourceProvider)
84
	 * (non-Javadoc)
85
	 * 
86
	 * @see
87
	 * org.eclipse.ui.services.IServiceWithSources#addSourceProvider(org.eclipse
88
	 * .ui.ISourceProvider)
62
	 */
89
	 */
63
	public void addSourceProvider(ISourceProvider provider) {
90
	public void addSourceProvider(ISourceProvider provider) {
64
		// TODO Auto-generated method stub
91
		// TODO Auto-generated method stub
65
92
66
	}
93
	}
67
94
68
	/* (non-Javadoc)
95
	/*
69
	 * @see org.eclipse.ui.services.IServiceWithSources#removeSourceProvider(org.eclipse.ui.ISourceProvider)
96
	 * (non-Javadoc)
97
	 * 
98
	 * @see
99
	 * org.eclipse.ui.services.IServiceWithSources#removeSourceProvider(org.
100
	 * eclipse.ui.ISourceProvider)
70
	 */
101
	 */
71
	public void removeSourceProvider(ISourceProvider provider) {
102
	public void removeSourceProvider(ISourceProvider provider) {
72
		// TODO Auto-generated method stub
103
		// TODO Auto-generated method stub
73
104
74
	}
105
	}
75
106
76
	/* (non-Javadoc)
107
	/*
108
	 * (non-Javadoc)
109
	 * 
77
	 * @see org.eclipse.ui.services.IDisposable#dispose()
110
	 * @see org.eclipse.ui.services.IDisposable#dispose()
78
	 */
111
	 */
79
	public void dispose() {
112
	public void dispose() {
Lines 84-91 public class WorkbenchMenuService implements IMenuService { Link Here
84
		return location.getScheme().startsWith("toolbar"); //$NON-NLS-1$
117
		return location.getScheme().startsWith("toolbar"); //$NON-NLS-1$
85
	}
118
	}
86
119
87
	/* (non-Javadoc)
120
	/*
88
	 * @see org.eclipse.ui.menus.IMenuService#addContributionFactory(org.eclipse.ui.menus.AbstractContributionFactory)
121
	 * (non-Javadoc)
122
	 * 
123
	 * @see
124
	 * org.eclipse.ui.menus.IMenuService#addContributionFactory(org.eclipse.
125
	 * ui.menus.AbstractContributionFactory)
89
	 */
126
	 */
90
	public void addContributionFactory(final AbstractContributionFactory factory) {
127
	public void addContributionFactory(final AbstractContributionFactory factory) {
91
		MenuLocationURI location = new MenuLocationURI(factory.getLocation());
128
		MenuLocationURI location = new MenuLocationURI(factory.getLocation());
Lines 133-138 public class WorkbenchMenuService implements IMenuService { Link Here
133
		factoriesToContributions.put(factory, menuContribution);
170
		factoriesToContributions.put(factory, menuContribution);
134
		MApplication app = e4Context.get(MApplication.class);
171
		MApplication app = e4Context.get(MApplication.class);
135
		app.getMenuContributions().add(menuContribution);
172
		app.getMenuContributions().add(menuContribution);
173
174
		// OK, now update any managers that use this uri
175
		for (Map.Entry<ContributionManager, MenuLocationURI> entry : managers.entrySet()) {
176
			MenuLocationURI mgrURI = entry.getValue();
177
			if (mgrURI.getScheme().equals(location.getScheme())
178
					&& mgrURI.getPath().equals(location.getPath())) {
179
				ContributionManager mgr = entry.getKey();
180
				populateContributionManager(mgr, mgrURI.toString());
181
				mgr.update(true);
182
			}
183
		}
136
	}
184
	}
137
185
138
	private void processToolbarChildren(AbstractContributionFactory factory,
186
	private void processToolbarChildren(AbstractContributionFactory factory,
Lines 151-158 public class WorkbenchMenuService implements IMenuService { Link Here
151
		app.getToolBarContributions().add(toolBarContribution);
199
		app.getToolBarContributions().add(toolBarContribution);
152
	}
200
	}
153
201
154
	/* (non-Javadoc)
202
	/*
155
	 * @see org.eclipse.ui.menus.IMenuService#removeContributionFactory(org.eclipse.ui.menus.AbstractContributionFactory)
203
	 * (non-Javadoc)
204
	 * 
205
	 * @see
206
	 * org.eclipse.ui.menus.IMenuService#removeContributionFactory(org.eclipse
207
	 * .ui.menus.AbstractContributionFactory)
156
	 */
208
	 */
157
	public void removeContributionFactory(AbstractContributionFactory factory) {
209
	public void removeContributionFactory(AbstractContributionFactory factory) {
158
		Object contribution;
210
		Object contribution;
Lines 166-190 public class WorkbenchMenuService implements IMenuService { Link Here
166
				app.getToolBarContributions().remove(contribution);
218
				app.getToolBarContributions().remove(contribution);
167
			}
219
			}
168
		}
220
		}
221
222
		// OK, now remove any managers that use this uri
223
		MenuLocationURI location = new MenuLocationURI(factory.getLocation());
224
		List<ContributionManager> toRemove = new ArrayList<ContributionManager>();
225
		for (Map.Entry<ContributionManager, MenuLocationURI> entry : managers.entrySet()) {
226
			MenuLocationURI mgrURI = entry.getValue();
227
			if (mgrURI.getScheme().equals(location.getScheme())
228
					&& mgrURI.getPath().equals(location.getPath())) {
229
				toRemove.add(entry.getKey());
230
			}
231
		}
232
		for (ContributionManager mgr : toRemove) {
233
			mgr.removeAll();
234
			managers.remove(mgr);
235
		}
169
	}
236
	}
170
237
171
	/* (non-Javadoc)
238
	protected IWorkbenchWindow getWindow() {
172
	 * @see org.eclipse.ui.menus.IMenuService#populateContributionManager(org.eclipse.jface.action.ContributionManager, java.lang.String)
239
		if (serviceLocator == null)
240
			return null;
241
242
		IWorkbenchLocationService wls = (IWorkbenchLocationService) serviceLocator
243
				.getService(IWorkbenchLocationService.class);
244
245
		if (window == null) {
246
			window = wls.getWorkbenchWindow();
247
		}
248
		if (window == null) {
249
			IWorkbench wb = wls.getWorkbench();
250
			if (wb != null) {
251
				window = wb.getActiveWorkbenchWindow();
252
			}
253
		}
254
		return window;
255
	}
256
257
	/*
258
	 * (non-Javadoc)
259
	 * 
260
	 * @see
261
	 * org.eclipse.ui.menus.IMenuService#populateContributionManager(org.eclipse
262
	 * .jface.action.ContributionManager, java.lang.String)
173
	 */
263
	 */
174
	public void populateContributionManager(ContributionManager mgr, String location) {
264
	public void populateContributionManager(ContributionManager mgr, String location) {
175
		// TODO Auto-generated method stub
265
		MenuLocationURI uri = new MenuLocationURI(location);
266
		// Track this call by recording the manager and location!
267
		// if (!managers.containsKey(mgr)) {
268
		// managers.put(mgr, uri);
269
		// }
270
271
		// Now handle registering dynamic additions by querying E4 model
272
		if (mgr instanceof MenuManager) {
273
			MenuManager menu = (MenuManager) mgr;
274
			MMenu mMenu = getMenuModel(menu, uri);
275
276
			IRendererFactory factory = e4Context.get(IRendererFactory.class);
277
			AbstractPartRenderer obj = factory.getRenderer(mMenu, null);
278
			if (obj instanceof MenuManagerRenderer) {
279
				MenuManagerRenderer renderer = (MenuManagerRenderer) obj;
280
				mMenu.setRenderer(renderer);
281
				renderer.reconcileManagerToModel(menu, mMenu);
282
				renderer.processContributions(mMenu, false, false);
283
				// double cast because we're bad people
284
				renderer.processContents((MElementContainer<MUIElement>) ((Object) mMenu));
285
			}
286
		} else if (mgr instanceof ToolBarManager) {
287
			ToolBarManager toolbar = (ToolBarManager) mgr;
288
			MToolBar mToolBar = getToolbarModel(toolbar, uri);
289
290
			IRendererFactory factory = e4Context.get(IRendererFactory.class);
291
			AbstractPartRenderer obj = factory.getRenderer(mToolBar, null);
292
			if (obj instanceof ToolBarManagerRenderer) {
293
				ToolBarManagerRenderer renderer = (ToolBarManagerRenderer) obj;
294
				mToolBar.setRenderer(renderer);
295
				renderer.reconcileManagerToModel(toolbar, mToolBar);
296
				renderer.processContribution(mToolBar);
297
				// double cast because we're bad people
298
				renderer.processContents((MElementContainer<MUIElement>) ((Object) mToolBar));
299
			}
300
		} else {
301
			System.err.println("Unhandled manager: " + mgr); //$NON-NLS-1$
302
		}
303
	}
304
305
	protected MToolBar getToolbarModel(ToolBarManager toolbarManager, MenuLocationURI location) {
306
		MToolBar mToolBar = null;
307
308
		MPart modelPart = getPartToExtend(toolbarManager.getControl());
309
		if (modelPart != null) {
310
			mToolBar = modelPart.getToolbar();
311
		} else {
312
			System.err.println("Can not register a ToolBarManager without a MPart"); //$NON-NLS-1$
313
		}
314
		if (mToolBar == null) {
315
			mToolBar = MenuFactoryImpl.eINSTANCE.createToolBar();
316
			mToolBar.setElementId(location.getPath());
317
		}
318
		if (modelPart != null) {
319
			modelPart.setToolbar(mToolBar);
320
		}
321
322
		IRendererFactory factory = e4Context.get(IRendererFactory.class);
323
		AbstractPartRenderer obj = factory.getRenderer(mToolBar, null);
324
		if (obj instanceof ToolBarManagerRenderer) {
325
			ToolBarManagerRenderer renderer = (ToolBarManagerRenderer) obj;
326
			renderer.linkModelToManager(mToolBar, toolbarManager);
327
		}
176
328
329
		return mToolBar;
177
	}
330
	}
178
331
179
	/* (non-Javadoc)
332
	protected MMenu getMenuModel(MenuManager menuManager, MenuLocationURI location) {
180
	 * @see org.eclipse.ui.menus.IMenuService#releaseContributions(org.eclipse.jface.action.ContributionManager)
333
		// FIXME See if we can find the already existing matching menu with this
334
		// id?
335
		if ("org.eclipse.ui.main.menu".equals(location.getPath())) //$NON-NLS-1$
336
		{
337
			WorkbenchWindow workbenchWindow = (WorkbenchWindow) getWindow();
338
			MWindow window = workbenchWindow.getModel();
339
			return window.getMainMenu();
340
		}
341
	
342
		MMenu mMenu = null;
343
344
		Menu menu = menuManager.getMenu();
345
		final MPart mPart = getPartToExtend(menu == null ? null : menu.getParent());
346
		if (mPart != null) {
347
			for (MMenu mMenuIt : mPart.getMenus()) {
348
				if (mMenuIt.getElementId().equals(menuManager.getId())) {
349
					mMenu = mMenuIt;
350
				}
351
			}
352
		} else {
353
			System.err.println("Can not register a MenuManager without a MPart"); //$NON-NLS-1$
354
		}
355
		if (mMenu == null) {
356
			mMenu = MenuFactoryImpl.eINSTANCE.createMenu();
357
			mMenu.setElementId(menuManager.getId());
358
			if (mMenu.getElementId() == null) {
359
				mMenu.setElementId(location.getPath());
360
			}
361
			mMenu.getTags().add(ContributionsAnalyzer.MC_MENU);
362
			mMenu.setLabel(menuManager.getMenuText());
363
		}
364
365
		if (mPart != null) {
366
			mPart.getMenus().add(mMenu);
367
		}
368
369
		// TODO Otherwise create one
370
		//		if ("popup".equals(location.getScheme())) { //$NON-NLS-1$
371
		// menuModel = MenuFactoryImpl.eINSTANCE.createPopupMenu();
372
		// menuModel.getTags().add(ContributionsAnalyzer.MC_POPUP);
373
		// } else {
374
375
		// }
376
	
377
		IRendererFactory factory = e4Context.get(IRendererFactory.class);
378
		AbstractPartRenderer obj = factory.getRenderer(mMenu, null);
379
		if (obj instanceof MenuManagerRenderer) {
380
			MenuManagerRenderer renderer = (MenuManagerRenderer) obj;
381
			renderer.linkModelToManager(mMenu, menuManager);
382
		}
383
	
384
		return mMenu;
385
	}
386
387
	private MPart getOwnerPart(Control control) {
388
		return (MPart) control
389
				.getData(org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer.OWNING_ME);
390
	}
391
392
	private MPart getPartToExtend(Control control) {
393
		MPart part = null;
394
		if (control == null) {
395
			// part = (MPart) e4Context.get(IServiceConstants.ACTIVE_PART);
396
		} else {
397
			Control currentControl = control;
398
			MPart ownerPart = getOwnerPart(currentControl);
399
			while (currentControl != null && ownerPart == null) {
400
				currentControl = currentControl.getParent();
401
				ownerPart = getOwnerPart(currentControl);
402
			}
403
			part = ownerPart;
404
		}
405
		return part;
406
	}
407
408
	/*
409
	 * (non-Javadoc)
410
	 * 
411
	 * @see
412
	 * org.eclipse.ui.menus.IMenuService#releaseContributions(org.eclipse.jface
413
	 * .action.ContributionManager)
181
	 */
414
	 */
182
	public void releaseContributions(ContributionManager mgr) {
415
	public void releaseContributions(ContributionManager mgr) {
183
		// TODO Auto-generated method stub
416
		// TODO Auto-generated method stub
184
417
185
	}
418
	}
186
419
187
	/* (non-Javadoc)
420
	/*
421
	 * (non-Javadoc)
422
	 * 
188
	 * @see org.eclipse.ui.menus.IMenuService#getCurrentState()
423
	 * @see org.eclipse.ui.menus.IMenuService#getCurrentState()
189
	 */
424
	 */
190
	public IEvaluationContext getCurrentState() {
425
	public IEvaluationContext getCurrentState() {
Lines 214-220 public class WorkbenchMenuService implements IMenuService { Link Here
214
	 */
449
	 */
215
	public void registerVisibleWhen(IContributionItem item, Expression visibleWhen,
450
	public void registerVisibleWhen(IContributionItem item, Expression visibleWhen,
216
			Set restriction, String createIdentifierId) {
451
			Set restriction, String createIdentifierId) {
217
		// TODO Auto-generated method stub
452
		// TODO Remove - no longer used
218
453
219
	}
454
	}
220
455
Lines 223-229 public class WorkbenchMenuService implements IMenuService { Link Here
223
	 * @param restriction
458
	 * @param restriction
224
	 */
459
	 */
225
	public void unregisterVisibleWhen(IContributionItem item, Set restriction) {
460
	public void unregisterVisibleWhen(IContributionItem item, Set restriction) {
226
		// TODO Auto-generated method stub
461
		// TODO Remove - no longer used
227
462
228
	}
463
	}
229
464

Return to bug 366528