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

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/incubator/CtrlEAction.java (-330 / +82 lines)
Lines 1-41 Link Here
1
package org.eclipse.ui.internal.incubator;
1
package org.eclipse.ui.internal.incubator;
2
2
3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.HashMap;
3
import java.util.HashMap;
6
import java.util.HashSet;
7
import java.util.LinkedList;
4
import java.util.LinkedList;
8
import java.util.List;
9
import java.util.Map;
5
import java.util.Map;
10
import java.util.Set;
11
import java.util.SortedSet;
12
import java.util.TreeSet;
13
6
14
import org.eclipse.core.commands.AbstractHandler;
7
import org.eclipse.core.commands.AbstractHandler;
15
import org.eclipse.core.commands.Command;
16
import org.eclipse.core.commands.ExecutionEvent;
8
import org.eclipse.core.commands.ExecutionEvent;
17
import org.eclipse.core.commands.ExecutionException;
18
import org.eclipse.core.commands.NotEnabledException;
19
import org.eclipse.core.commands.NotHandledException;
20
import org.eclipse.core.commands.ParameterizedCommand;
21
import org.eclipse.core.commands.common.NotDefinedException;
22
import org.eclipse.jface.action.ActionContributionItem;
23
import org.eclipse.jface.action.IAction;
24
import org.eclipse.jface.action.IContributionItem;
25
import org.eclipse.jface.action.LegacyActionTools;
26
import org.eclipse.jface.action.MenuManager;
27
import org.eclipse.jface.action.SubContributionItem;
28
import org.eclipse.jface.bindings.Binding;
29
import org.eclipse.jface.dialogs.IDialogSettings;
9
import org.eclipse.jface.dialogs.IDialogSettings;
30
import org.eclipse.jface.preference.IPreferenceNode;
31
import org.eclipse.jface.preference.IPreferencePage;
32
import org.eclipse.jface.preference.PreferenceManager;
33
import org.eclipse.jface.preference.PreferenceNode;
34
import org.eclipse.jface.resource.DeviceResourceException;
10
import org.eclipse.jface.resource.DeviceResourceException;
35
import org.eclipse.jface.resource.ImageDescriptor;
11
import org.eclipse.jface.resource.ImageDescriptor;
36
import org.eclipse.jface.resource.JFaceResources;
12
import org.eclipse.jface.resource.JFaceResources;
37
import org.eclipse.jface.resource.LocalResourceManager;
13
import org.eclipse.jface.resource.LocalResourceManager;
38
import org.eclipse.jface.viewers.ILabelProvider;
39
import org.eclipse.jface.viewers.ITreeContentProvider;
14
import org.eclipse.jface.viewers.ITreeContentProvider;
40
import org.eclipse.jface.viewers.LabelProvider;
15
import org.eclipse.jface.viewers.LabelProvider;
41
import org.eclipse.jface.viewers.StructuredSelection;
16
import org.eclipse.jface.viewers.StructuredSelection;
Lines 51-76 Link Here
51
import org.eclipse.swt.widgets.Shell;
26
import org.eclipse.swt.widgets.Shell;
52
import org.eclipse.swt.widgets.Tree;
27
import org.eclipse.swt.widgets.Tree;
53
import org.eclipse.swt.widgets.TreeItem;
28
import org.eclipse.swt.widgets.TreeItem;
54
import org.eclipse.ui.IEditorReference;
55
import org.eclipse.ui.IPerspectiveDescriptor;
56
import org.eclipse.ui.IWorkbenchPage;
29
import org.eclipse.ui.IWorkbenchPage;
57
import org.eclipse.ui.IWorkbenchPart;
58
import org.eclipse.ui.IWorkbenchWindow;
30
import org.eclipse.ui.IWorkbenchWindow;
59
import org.eclipse.ui.PartInitException;
60
import org.eclipse.ui.PlatformUI;
31
import org.eclipse.ui.PlatformUI;
61
import org.eclipse.ui.handlers.IHandlerService;
62
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
32
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
63
import org.eclipse.ui.internal.WorkbenchImages;
33
import org.eclipse.ui.internal.WorkbenchImages;
64
import org.eclipse.ui.internal.WorkbenchPlugin;
34
import org.eclipse.ui.internal.WorkbenchPlugin;
65
import org.eclipse.ui.internal.WorkbenchWindow;
66
import org.eclipse.ui.internal.actions.NewWizardShortcutAction;
67
import org.eclipse.ui.internal.dialogs.WorkbenchPreferenceDialog;
68
import org.eclipse.ui.internal.keys.BindingService;
69
import org.eclipse.ui.internal.progress.ProgressManagerUtil;
35
import org.eclipse.ui.internal.progress.ProgressManagerUtil;
70
import org.eclipse.ui.keys.IBindingService;
71
import org.eclipse.ui.views.IViewDescriptor;
72
import org.eclipse.ui.wizards.IWizardCategory;
73
import org.eclipse.ui.wizards.IWizardDescriptor;
74
36
75
/**
37
/**
76
 * Experimental Action for search-based navigation to UI elements such as
38
 * Experimental Action for search-based navigation to UI elements such as
Lines 79-90 Link Here
79
 */
41
 */
80
public class CtrlEAction extends AbstractHandler {
42
public class CtrlEAction extends AbstractHandler {
81
43
82
	private static final String DIRTY_MARK = "*"; //$NON-NLS-1$
83
84
	private IWorkbenchWindow window;
44
	private IWorkbenchWindow window;
85
45
86
	protected String rememberedText;
46
	protected String rememberedText;
87
	
47
88
	protected Map previousPicksMap = new HashMap();
48
	protected Map previousPicksMap = new HashMap();
89
49
90
	private LinkedList previousPicksList = new LinkedList();
50
	private LinkedList previousPicksList = new LinkedList();
Lines 98-120 Link Here
98
	public Object execute(ExecutionEvent executionEvent) {
58
	public Object execute(ExecutionEvent executionEvent) {
99
		// need to get commands here because opening the popup changes which
59
		// need to get commands here because opening the popup changes which
100
		// commands are "handled"
60
		// commands are "handled"
101
		BindingService bindingService = (BindingService) PlatformUI
61
102
				.getWorkbench().getService(IBindingService.class);
62
		AbstractProvider[] providers = { new PreviousPicksProvider(),
103
		Binding[] bindings = bindingService.getBindings();
63
				new EditorProvider(), new ViewProvider(),
104
		SortedSet commands = new TreeSet();
64
				new PerspectiveProvider(), new CommandProvider(),
105
		for (int i = 0; i < bindings.length; i++) {
65
				new ActionProvider(), new WizardProvider(),
106
			Binding binding = bindings[i];
66
				new PreferenceProvider() };
107
			ParameterizedCommand command = binding.getParameterizedCommand();
108
			if (command != null && command.getCommand().isHandled()) {
109
				commands.add(command);
110
			}
111
		}
112
67
113
		window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
68
		window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
114
		if (window == null) {
69
		if (window == null) {
115
			return null;
70
			return null;
116
		}
71
		}
117
		FilteringInfoPopup popup = new MyInfoPopup(ProgressManagerUtil.getDefaultParent(), commands);
72
		FilteringInfoPopup popup = new MyInfoPopup(ProgressManagerUtil
73
				.getDefaultParent(), providers);
118
		popup.setInput(new Object());
74
		popup.setInput(new Object());
119
		TreeItem[] rootItems = ((Tree) popup.getTreeViewer().getControl())
75
		TreeItem[] rootItems = ((Tree) popup.getTreeViewer().getControl())
120
				.getItems();
76
				.getItems();
Lines 128-137 Link Here
128
	private final static class QuickAccessTreeSorter extends
84
	private final static class QuickAccessTreeSorter extends
129
			TreePathViewerSorter {
85
			TreePathViewerSorter {
130
		public int compare(Viewer viewer, Object e1, Object e2) {
86
		public int compare(Viewer viewer, Object e1, Object e2) {
131
			ILabelProvider labelProvider = (ILabelProvider) ((TreeViewer) viewer)
87
			AbstractElement element1 = (AbstractElement) e1;
132
					.getLabelProvider();
88
			AbstractElement element2 = (AbstractElement) e2;
133
			String name1 = stripDirtyIndicator(labelProvider.getText(e1));
89
			String name1 = element1.getSortLabel();
134
			String name2 = stripDirtyIndicator(labelProvider.getText(e2));
90
			String name2 = element2.getSortLabel();
135
			return getComparator().compare(name1, name2);
91
			return getComparator().compare(name1, name2);
136
		}
92
		}
137
93
Lines 140-149 Link Here
140
				return;
96
				return;
141
			}
97
			}
142
			Object parent = parentPath.getLastSegment();
98
			Object parent = parentPath.getLastSegment();
143
			if (parent instanceof Node) {
99
			if (parent instanceof AbstractProvider) {
144
				Node node = (Node) parent;
100
				AbstractProvider provider = (AbstractProvider) parent;
145
				// TODO replace with a proper check
101
				if (provider instanceof PreviousPicksProvider) {
146
				if (node.name.equals(IncubatorMessages.CtrlEAction_Previous)) {
147
					return;
102
					return;
148
				}
103
				}
149
			}
104
			}
Lines 156-173 Link Here
156
	 * 
111
	 * 
157
	 */
112
	 */
158
	private final class MyInfoPopup extends FilteringInfoPopup {
113
	private final class MyInfoPopup extends FilteringInfoPopup {
159
		private SortedSet commands;
160
114
161
		/**
115
		/**
162
		 * @param shell
116
		 * @param shell
163
		 * @param commands
117
		 * @param providers
164
		 */
118
		 */
165
		public MyInfoPopup(Shell shell, SortedSet commands) {
119
		public MyInfoPopup(Shell shell, AbstractProvider[] providers) {
166
			super(shell, SWT.RESIZE, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE,
120
			super(shell, SWT.RESIZE, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE,
167
					false);
121
					false);
168
			MyInfoPopup.this.commands = commands;
122
			getTreeViewer()
169
			getTreeViewer().setContentProvider(
123
					.setContentProvider(new MyContentProvider(providers));
170
					new MyContentProvider(MyInfoPopup.this.commands));
171
		}
124
		}
172
125
173
		protected TreeViewer createTreeViewer(Composite parent, int style) {
126
		protected TreeViewer createTreeViewer(Composite parent, int style) {
Lines 176-182 Link Here
176
			viewer.setComparator(new QuickAccessTreeSorter());
129
			viewer.setComparator(new QuickAccessTreeSorter());
177
			return viewer;
130
			return viewer;
178
		}
131
		}
179
				
132
180
		protected void selectFirstMatch() {
133
		protected void selectFirstMatch() {
181
			String text = getFilterText().getText();
134
			String text = getFilterText().getText();
182
			Object element = previousPicksMap.get(text);
135
			Object element = previousPicksMap.get(text);
Lines 187-196 Link Here
187
			}
140
			}
188
			super.selectFirstMatch();
141
			super.selectFirstMatch();
189
		}
142
		}
190
		
143
191
		protected String getMatchName(Object element) {
144
		protected String getMatchName(Object element) {
192
			String name = ((ILabelProvider) getTreeViewer().getLabelProvider()).getText(element);
145
			if (element instanceof AbstractProvider) {
193
			return stripDirtyIndicator(name);
146
				AbstractProvider provider = (AbstractProvider) element;
147
				return provider.getName();
148
			} else if (element instanceof AbstractElement) {
149
				AbstractElement abstractElement = (AbstractElement) element;
150
				return abstractElement.getSortLabel();
151
			}
152
			return ""; //$NON-NLS-1$
194
		}
153
		}
195
154
196
		protected Point getInitialSize() {
155
		protected Point getInitialSize() {
Lines 236-297 Link Here
236
			addPreviousPick(selectedElement);
195
			addPreviousPick(selectedElement);
237
			IWorkbenchPage activePage = window.getActivePage();
196
			IWorkbenchPage activePage = window.getActivePage();
238
			if (activePage != null) {
197
			if (activePage != null) {
239
				if (selectedElement instanceof IViewDescriptor) {
198
				if (selectedElement instanceof AbstractElement) {
240
					IViewDescriptor viewDescriptor = (IViewDescriptor) selectedElement;
199
					AbstractElement element = (AbstractElement) selectedElement;
241
					try {
200
					element.execute();
242
						activePage.showView(viewDescriptor.getId());
243
						return;
244
					} catch (PartInitException e) {
245
					}
246
				}
247
				if (selectedElement instanceof IPerspectiveDescriptor) {
248
					IPerspectiveDescriptor perspectiveDescriptor = (IPerspectiveDescriptor) selectedElement;
249
					activePage.setPerspective(perspectiveDescriptor);
250
				}
251
				if (selectedElement instanceof IEditorReference) {
252
					IEditorReference editorReference = (IEditorReference) selectedElement;
253
					IWorkbenchPart part = editorReference.getPart(true);
254
					if (part != null) {
255
						activePage.activate(part);
256
					}
257
					return;
258
				}
259
				if (selectedElement instanceof PreferenceNode) {
260
					PreferenceNode preferenceNode = (PreferenceNode) selectedElement;
261
					WorkbenchPreferenceDialog dialog = WorkbenchPreferenceDialog
262
							.createDialogOn(window.getShell(), preferenceNode
263
									.getId());
264
					dialog.open();
265
					return;
266
				}
267
				if (selectedElement instanceof IWizardDescriptor) {
268
					IWizardDescriptor wizardDescriptor = (IWizardDescriptor) selectedElement;
269
					NewWizardShortcutAction wizardAction = new NewWizardShortcutAction(
270
							window, wizardDescriptor);
271
					wizardAction.run();
272
					return;
273
				}
274
				if (selectedElement instanceof ParameterizedCommand) {
275
					IHandlerService handlerService = (IHandlerService) window
276
							.getWorkbench().getService(IHandlerService.class);
277
					ParameterizedCommand command = (ParameterizedCommand) selectedElement;
278
					try {
279
						handlerService.executeCommand(command, null);
280
					} catch (ExecutionException e) {
281
						e.printStackTrace();
282
					} catch (NotDefinedException e) {
283
						e.printStackTrace();
284
					} catch (NotEnabledException e) {
285
						e.printStackTrace();
286
					} catch (NotHandledException e) {
287
						e.printStackTrace();
288
					}
289
					return;
290
				}
291
				if (selectedElement instanceof ActionContributionItem) {
292
					ActionContributionItem item = (ActionContributionItem) selectedElement;
293
					item.getAction().run();
294
					return;
295
				}
201
				}
296
			}
202
			}
297
		}
203
		}
Lines 302-432 Link Here
302
		}
208
		}
303
	}
209
	}
304
210
305
	private static class Node {
306
		private String name;
307
308
		private String imageId;
309
310
		Node(String name, String imageId) {
311
			this.name = name;
312
			this.imageId = imageId;
313
		}
314
315
		public String toString() {
316
			return name;
317
		}
318
319
		/**
320
		 * @return
321
		 */
322
		public String getImageId() {
323
			return imageId;
324
		}
325
	}
326
327
	private final class MyContentProvider implements ITreeContentProvider {
211
	private final class MyContentProvider implements ITreeContentProvider {
328
		private Object input;
212
		private Object input;
329
213
		private final AbstractProvider[] providers;
330
		private Node previousNode = new Node(
214
		private HashMap elementMap;
331
				IncubatorMessages.CtrlEAction_Previous, IWorkbenchGraphicConstants.IMG_OBJ_NODE);
332
333
		private Node editorNode = new Node(
334
				IncubatorMessages.CtrlEAction_Editors, IWorkbenchGraphicConstants.IMG_OBJ_NODE);
335
336
		private Node viewNode = new Node(IncubatorMessages.CtrlEAction_Views,
337
				IWorkbenchGraphicConstants.IMG_VIEW_DEFAULTVIEW_MISC);
338
339
		private Node perspectiveNode = new Node(
340
				IncubatorMessages.CtrlEAction_Perspectives,
341
				IWorkbenchGraphicConstants.IMG_ETOOL_DEF_PERSPECTIVE);
342
343
		private Node commandNode = new Node(
344
				IncubatorMessages.CtrlEAction_Commands, IWorkbenchGraphicConstants.IMG_OBJ_NODE);
345
346
		private Node menusNode = new Node(IncubatorMessages.CtrlEAction_Menus,
347
				IWorkbenchGraphicConstants.IMG_OBJ_NODE);
348
349
		private Node newNode = new Node(IncubatorMessages.CtrlEAction_New, IWorkbenchGraphicConstants.IMG_OBJ_NODE);
350
351
		private Node preferencesNode = new Node(
352
				IncubatorMessages.CtrlEAction_Preferences, IWorkbenchGraphicConstants.IMG_OBJ_NODE);
353
354
		private SortedSet commands;
355
215
356
		/**
216
		/**
357
		 * @param commands
217
		 * @param providers
358
		 */
218
		 */
359
		public MyContentProvider(SortedSet commands) {
219
		public MyContentProvider(AbstractProvider[] providers) {
360
			MyContentProvider.this.commands = commands;
220
			this.providers = providers;
221
			this.elementMap = new HashMap();
222
			for (int i = 0; i < providers.length; i++) {
223
				elementMap.put(providers[i], providers[i].getElements());
224
			}
361
		}
225
		}
362
226
363
		public Object[] getChildren(Object parentElement) {
227
		public Object[] getChildren(Object parentElement) {
364
			if (parentElement instanceof Node) {
228
			if (parentElement instanceof AbstractProvider) {
365
				if (previousNode.equals(parentElement)) {
229
				return (Object[]) elementMap.get(parentElement);
366
					return getPreviousPicks();
367
				} else if (editorNode.equals(parentElement)) {
368
					if(window.getActivePage() != null) {
369
						return window.getActivePage().getEditorReferences();
370
					}
371
				} else if (viewNode.equals(parentElement)) {
372
					return PlatformUI.getWorkbench().getViewRegistry()
373
							.getViews();
374
				} else if (perspectiveNode.equals(parentElement)) {
375
					return PlatformUI.getWorkbench().getPerspectiveRegistry()
376
							.getPerspectives();
377
				} else if (commandNode.equals(parentElement)) {
378
					return commands.toArray();
379
				} else if (preferencesNode.equals(parentElement)) {
380
					List elements = PlatformUI.getWorkbench()
381
							.getPreferenceManager().getElements(
382
									PreferenceManager.PRE_ORDER);
383
					Set uniqueElements = new HashSet(elements);
384
					return uniqueElements.toArray();
385
				} else if (menusNode.equals(parentElement)) {
386
					MenuManager menu = ((WorkbenchWindow) window)
387
							.getMenuBarManager();
388
					Set result = new HashSet();
389
					collectContributions(menu, result);
390
					return result.toArray();
391
				} else if (newNode.equals(parentElement)) {
392
					IWizardCategory rootCategory = WorkbenchPlugin.getDefault()
393
							.getNewWizardRegistry().getRootCategory();
394
					List result = new ArrayList();
395
					collectWizards(rootCategory, result);
396
					return result.toArray();
397
				}
398
			}
230
			}
399
			if (parentElement == input) {
231
			if (parentElement == input) {
400
				return new Node[] { previousNode, editorNode, viewNode,
232
				return providers;
401
						perspectiveNode, commandNode, menusNode, newNode,
402
						preferencesNode };
403
			}
233
			}
404
			return new Object[0];
234
			return new Object[0];
405
		}
235
		}
406
236
407
		private void collectContributions(MenuManager menu, Set result) {
408
			IContributionItem[] items = menu.getItems();
409
			for (int i = 0; i < items.length; i++) {
410
				IContributionItem item = items[i];
411
				if (item instanceof SubContributionItem) {
412
					item = ((SubContributionItem) item).getInnerItem();
413
				}
414
				if (item instanceof MenuManager) {
415
					collectContributions((MenuManager) item, result);
416
				} else if (item instanceof ActionContributionItem) {
417
					result.add(item);
418
				}
419
			}
420
		}
421
422
		private void collectWizards(IWizardCategory category, List result) {
423
			result.addAll(Arrays.asList(category.getWizards()));
424
			IWizardCategory[] childCategories = category.getCategories();
425
			for (int i = 0; i < childCategories.length; i++) {
426
				collectWizards(childCategories[i], result);
427
			}
428
		}
429
430
		public Object getParent(Object element) {
237
		public Object getParent(Object element) {
431
			return null;
238
			return null;
432
		}
239
		}
Lines 453-486 Link Here
453
260
454
		public Image getImage(Object element) {
261
		public Image getImage(Object element) {
455
			Image image = null;
262
			Image image = null;
456
			if (element instanceof Node) {
263
			if (element instanceof AbstractProvider) {
457
				Node node = (Node) element;
264
				AbstractProvider provider = (AbstractProvider) element;
458
				image = findOrCreateImage(WorkbenchImages
265
				image = findOrCreateImage(provider.getImageDescriptor());
459
						.getImageDescriptor(node.getImageId()));
266
			} else if (element instanceof AbstractElement) {
460
			}
267
				image = findOrCreateImage(((AbstractElement) element)
461
			else if (element instanceof IEditorReference) {
462
				IEditorReference editorReference = (IEditorReference) element;
463
				image = editorReference.getTitleImage();
464
			}
465
			else if (element instanceof IViewDescriptor) {
466
				IViewDescriptor viewDescriptor = (IViewDescriptor) element;
467
				image = findOrCreateImage(viewDescriptor.getImageDescriptor());
468
			}
469
			else if (element instanceof IPerspectiveDescriptor) {
470
				IPerspectiveDescriptor perspectiveDescriptor = (IPerspectiveDescriptor) element;
471
				image = findOrCreateImage(perspectiveDescriptor
472
						.getImageDescriptor());
268
						.getImageDescriptor());
473
			}
269
			}
474
			else if (element instanceof IPreferenceNode) {
475
				IPreferenceNode preferenceNode = (IPreferenceNode) element;
476
				image = preferenceNode.getLabelImage();
477
			}
478
			else if (element instanceof IWizardDescriptor) {
479
				IWizardDescriptor wizardDescriptor = (IWizardDescriptor) element;
480
				image = findOrCreateImage(wizardDescriptor.getDescriptionImage());
481
			}
482
			if (image == null) {
270
			if (image == null) {
483
				image = WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_OBJ_ELEMENT);
271
				image = WorkbenchImages
272
						.getImage(IWorkbenchGraphicConstants.IMG_OBJ_ELEMENT);
484
			}
273
			}
485
			return image;
274
			return image;
486
		}
275
		}
Lines 512-581 Link Here
512
		}
301
		}
513
302
514
		public String getText(Object element) {
303
		public String getText(Object element) {
515
			String separator = " - "; //$NON-NLS-1$
304
			if (element instanceof AbstractProvider) {
516
			if (element instanceof IEditorReference) {
305
				AbstractProvider provider = (AbstractProvider) element;
517
				IEditorReference editorReference = (IEditorReference) element;
306
				return provider.getName();
518
				StringBuffer result = new StringBuffer();
307
			} else if (element instanceof AbstractElement) {
519
				if (editorReference.isDirty()) {
308
				AbstractElement abstractElement = (AbstractElement) element;
520
					result.append(DIRTY_MARK);
309
				return abstractElement.getLabel();
521
				}
522
				result.append(editorReference.getName());
523
				result.append(separator);
524
				result.append(editorReference.getTitleToolTip());
525
				return result.toString();
526
			}
527
			if (element instanceof IViewDescriptor) {
528
				IViewDescriptor viewDescriptor = (IViewDescriptor) element;
529
				return viewDescriptor.getLabel();
530
			}
531
			if (element instanceof IPerspectiveDescriptor) {
532
				IPerspectiveDescriptor perspectiveDescriptor = (IPerspectiveDescriptor) element;
533
				return perspectiveDescriptor.getLabel();
534
			}
535
			if (element instanceof IPreferenceNode) {
536
				IPreferenceNode preferenceNode = (IPreferenceNode) element;
537
				IPreferencePage page = preferenceNode.getPage();
538
				if (page != null && page.getDescription() != null
539
						&& page.getDescription().length() != 0) {
540
					return preferenceNode.getLabelText() + separator
541
							+ page.getDescription();
542
				}
543
				return preferenceNode.getLabelText();
544
			}
545
			if (element instanceof IWizardDescriptor) {
546
				IWizardDescriptor wizardDescriptor = (IWizardDescriptor) element;
547
				return wizardDescriptor.getLabel() + separator
548
						+ wizardDescriptor.getDescription();
549
			}
550
			if (element instanceof ActionContributionItem) {
551
				ActionContributionItem item = (ActionContributionItem) element;
552
				IAction action = item.getAction();
553
				if (action.getToolTipText() != null
554
						&& action.getToolTipText().length() != 0) {
555
					return LegacyActionTools.removeMnemonics(action.getText())
556
							+ separator + action.getToolTipText();
557
				}
558
				return LegacyActionTools.removeMnemonics(action.getText());
559
			}
560
			if (element instanceof ParameterizedCommand) {
561
				ParameterizedCommand command = (ParameterizedCommand) element;
562
				try {
563
					Command nestedCommand = command.getCommand();
564
					if (nestedCommand != null
565
							&& nestedCommand.getDescription() != null
566
							&& nestedCommand.getDescription().length() != 0) {
567
						return command.getName() + separator
568
								+ nestedCommand.getDescription();
569
					}
570
					return command.getName();
571
				} catch (NotDefinedException e) {
572
					return command.toString();
573
				}
574
			}
310
			}
575
			return super.getText(element);
311
			return super.getText(element);
576
		}
312
		}
577
	}
313
	}
578
	
314
579
	/**
315
	/**
580
	 * @param element
316
	 * @param element
581
	 */
317
	 */
Lines 588-603 Link Here
588
	/**
324
	/**
589
	 * @return
325
	 * @return
590
	 */
326
	 */
591
	private Object[] getPreviousPicks() {
327
	private AbstractElement[] getPreviousPicks() {
592
		return previousPicksList.toArray();
328
		return (AbstractElement[]) previousPicksList
329
				.toArray(new AbstractElement[previousPicksList.size()]);
593
	}
330
	}
594
331
595
	private static String stripDirtyIndicator(String elementName) {
332
	private class PreviousPicksProvider extends AbstractProvider {
596
		if (elementName.startsWith(DIRTY_MARK)) {
333
597
			elementName = elementName.substring(1);
334
		public AbstractElement getElementForId(String id) {
335
			return null;
336
		}
337
338
		public AbstractElement[] getElements() {
339
			return getPreviousPicks();
340
		}
341
342
		public String getId() {
343
			return "org.eclipse.ui.previousPicks"; //$NON-NLS-1$
598
		}
344
		}
599
		return elementName;
600
	}
601
345
346
		public ImageDescriptor getImageDescriptor() {
347
			return WorkbenchImages
348
					.getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJ_NODE);
349
		}
602
350
351
		public String getName() {
352
			return IncubatorMessages.CtrlEAction_Previous;
353
		}
354
	}
603
}
355
}
(-)Eclipse (+91 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.incubator;
13
14
import java.util.HashMap;
15
import java.util.HashSet;
16
import java.util.Map;
17
import java.util.Set;
18
19
import org.eclipse.jface.action.ActionContributionItem;
20
import org.eclipse.jface.action.IContributionItem;
21
import org.eclipse.jface.action.MenuManager;
22
import org.eclipse.jface.action.SubContributionItem;
23
import org.eclipse.jface.resource.ImageDescriptor;
24
import org.eclipse.ui.PlatformUI;
25
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
26
import org.eclipse.ui.internal.WorkbenchImages;
27
import org.eclipse.ui.internal.WorkbenchWindow;
28
29
/**
30
 * @since 3.3
31
 * 
32
 */
33
public class ActionProvider extends AbstractProvider {
34
35
	private AbstractElement[] cachedElements;
36
	private Map idToElement = new HashMap();
37
38
	public String getId() {
39
		return "org.eclipse.ui.actions"; //$NON-NLS-1$
40
	}
41
42
	public AbstractElement getElementForId(String id) {
43
		getElements();
44
		return (ActionElement) idToElement.get(id);
45
	}
46
47
	public AbstractElement[] getElements() {
48
		if (cachedElements == null) {
49
			WorkbenchWindow window = (WorkbenchWindow) PlatformUI
50
					.getWorkbench().getActiveWorkbenchWindow();
51
			if (window != null) {
52
				MenuManager menu = window.getMenuManager();
53
				Set result = new HashSet();
54
				collectContributions(menu, result);
55
				ActionContributionItem[] actions = (ActionContributionItem[]) result
56
						.toArray(new ActionContributionItem[result.size()]);
57
				cachedElements = new AbstractElement[actions.length];
58
				for (int i = 0; i < actions.length; i++) {
59
					ActionElement actionElement = new ActionElement(actions[i]);
60
					cachedElements[i] = actionElement;
61
					idToElement.put(actionElement.getId(), actionElement);
62
				}
63
			}
64
		}
65
		return cachedElements;
66
	}
67
68
	private void collectContributions(MenuManager menu, Set result) {
69
		IContributionItem[] items = menu.getItems();
70
		for (int i = 0; i < items.length; i++) {
71
			IContributionItem item = items[i];
72
			if (item instanceof SubContributionItem) {
73
				item = ((SubContributionItem) item).getInnerItem();
74
			}
75
			if (item instanceof MenuManager) {
76
				collectContributions((MenuManager) item, result);
77
			} else if (item instanceof ActionContributionItem) {
78
				result.add(item);
79
			}
80
		}
81
	}
82
83
	public ImageDescriptor getImageDescriptor() {
84
		return WorkbenchImages
85
				.getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJ_NODE);
86
	}
87
88
	public String getName() {
89
		return IncubatorMessages.CtrlEAction_Menus;
90
	}
91
}
(-)Eclipse (+79 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.incubator;
13
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.HashMap;
17
import java.util.List;
18
import java.util.Map;
19
20
import org.eclipse.jface.resource.ImageDescriptor;
21
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
22
import org.eclipse.ui.internal.WorkbenchImages;
23
import org.eclipse.ui.internal.WorkbenchPlugin;
24
import org.eclipse.ui.wizards.IWizardCategory;
25
import org.eclipse.ui.wizards.IWizardDescriptor;
26
27
/**
28
 * @since 3.3
29
 * 
30
 */
31
public class WizardProvider extends AbstractProvider {
32
33
	private AbstractElement[] cachedElements;
34
	private Map idToElement = new HashMap();
35
36
	public AbstractElement getElementForId(String id) {
37
		getElements();
38
		return (WizardElement) idToElement.get(id);
39
	}
40
41
	public AbstractElement[] getElements() {
42
		if (cachedElements == null) {
43
			IWizardCategory rootCategory = WorkbenchPlugin.getDefault()
44
					.getNewWizardRegistry().getRootCategory();
45
			List result = new ArrayList();
46
			collectWizards(rootCategory, result);
47
			IWizardDescriptor[] wizards = (IWizardDescriptor[]) result
48
					.toArray(new IWizardDescriptor[result.size()]);
49
			cachedElements = new AbstractElement[wizards.length];
50
			for (int i = 0; i < wizards.length; i++) {
51
				WizardElement wizardElement = new WizardElement(wizards[i]);
52
				cachedElements[i] = wizardElement;
53
				idToElement.put(wizardElement.getId(), wizardElement);
54
			}
55
		}
56
		return cachedElements;
57
	}
58
59
	private void collectWizards(IWizardCategory category, List result) {
60
		result.addAll(Arrays.asList(category.getWizards()));
61
		IWizardCategory[] childCategories = category.getCategories();
62
		for (int i = 0; i < childCategories.length; i++) {
63
			collectWizards(childCategories[i], result);
64
		}
65
	}
66
67
	public String getId() {
68
		return "org.eclipse.ui.wizards"; //$NON-NLS-1$
69
	}
70
71
	public ImageDescriptor getImageDescriptor() {
72
		return WorkbenchImages
73
				.getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJ_NODE);
74
	}
75
76
	public String getName() {
77
		return IncubatorMessages.CtrlEAction_New;
78
	}
79
}
(-)Eclipse (+64 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.incubator;
13
14
import java.util.HashMap;
15
import java.util.Map;
16
17
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.ui.IPerspectiveDescriptor;
19
import org.eclipse.ui.PlatformUI;
20
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
21
import org.eclipse.ui.internal.WorkbenchImages;
22
23
/**
24
 * @since 3.3
25
 * 
26
 */
27
public class PerspectiveProvider extends AbstractProvider {
28
29
	private AbstractElement[] cachedElements;
30
	private Map idToElement = new HashMap();
31
32
	public String getId() {
33
		return "org.eclipse.ui.perspectives"; //$NON-NLS-1$
34
	}
35
36
	public AbstractElement getElementForId(String id) {
37
		getElements();
38
		return (PerspectiveElement) idToElement.get(id);
39
	}
40
41
	public AbstractElement[] getElements() {
42
		if (cachedElements == null) {
43
			IPerspectiveDescriptor[] perspectives = PlatformUI.getWorkbench()
44
					.getPerspectiveRegistry().getPerspectives();
45
			cachedElements = new AbstractElement[perspectives.length];
46
			for (int i = 0; i < perspectives.length; i++) {
47
				PerspectiveElement perspectiveElement = new PerspectiveElement(
48
						perspectives[i]);
49
				cachedElements[i] = perspectiveElement;
50
				idToElement.put(perspectiveElement.getId(), perspectiveElement);
51
			}
52
		}
53
		return cachedElements;
54
	}
55
56
	public ImageDescriptor getImageDescriptor() {
57
		return WorkbenchImages
58
				.getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_DEF_PERSPECTIVE);
59
	}
60
61
	public String getName() {
62
		return IncubatorMessages.CtrlEAction_Perspectives;
63
	}
64
}
(-)Eclipse (+31 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.incubator;
13
14
import org.eclipse.jface.resource.ImageDescriptor;
15
16
/**
17
 * @since 3.3
18
 * 
19
 */
20
public abstract class AbstractProvider {
21
22
	public abstract String getId();
23
24
	public abstract String getName();
25
26
	public abstract ImageDescriptor getImageDescriptor();
27
28
	public abstract AbstractElement[] getElements();
29
30
	public abstract AbstractElement getElementForId(String id);
31
}
(-)Eclipse (+54 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.incubator;
13
14
import org.eclipse.jface.resource.ImageDescriptor;
15
import org.eclipse.ui.IWorkbenchWindow;
16
import org.eclipse.ui.PlatformUI;
17
import org.eclipse.ui.internal.actions.NewWizardShortcutAction;
18
import org.eclipse.ui.wizards.IWizardDescriptor;
19
20
/**
21
 * @since 3.3
22
 *
23
 */
24
public class WizardElement extends AbstractElement {
25
26
	private static final String separator = " - "; //$NON-NLS-1$
27
	
28
	private IWizardDescriptor wizardDescriptor;
29
	
30
	public WizardElement(IWizardDescriptor wizardDescriptor) {
31
		this.wizardDescriptor = wizardDescriptor;
32
	}
33
	
34
	public void execute() {
35
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
36
		if(window != null) {
37
			NewWizardShortcutAction wizardAction = new NewWizardShortcutAction(window, wizardDescriptor);
38
			wizardAction.run();
39
		}
40
	}
41
42
	public String getId() {
43
		return wizardDescriptor.getId();
44
	}
45
46
	public ImageDescriptor getImageDescriptor() {
47
		return wizardDescriptor.getImageDescriptor();
48
	}
49
50
	public String getLabel() {
51
		return wizardDescriptor.getLabel() + separator
52
		+ wizardDescriptor.getDescription();
53
	}
54
}
(-)Eclipse (+80 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.incubator;
13
14
import org.eclipse.core.commands.Command;
15
import org.eclipse.core.commands.ExecutionException;
16
import org.eclipse.core.commands.NotEnabledException;
17
import org.eclipse.core.commands.NotHandledException;
18
import org.eclipse.core.commands.ParameterizedCommand;
19
import org.eclipse.core.commands.common.NotDefinedException;
20
import org.eclipse.jface.resource.ImageDescriptor;
21
import org.eclipse.ui.IWorkbenchWindow;
22
import org.eclipse.ui.PlatformUI;
23
import org.eclipse.ui.handlers.IHandlerService;
24
25
/**
26
 * @since 3.3
27
 *
28
 */
29
public class CommandElement extends AbstractElement {
30
31
	private static final String separator = " - "; //$NON-NLS-1$
32
	
33
	private ParameterizedCommand command;
34
	
35
	public CommandElement(ParameterizedCommand command) {
36
		this.command = command;
37
	}
38
	
39
	public void execute() {
40
		IWorkbenchWindow window = PlatformUI.getWorkbench()
41
				.getActiveWorkbenchWindow();
42
		if (window != null) {
43
			IHandlerService handlerService = (IHandlerService) window
44
					.getWorkbench().getService(IHandlerService.class);
45
			try {
46
				handlerService.executeCommand(command, null);
47
			} catch (ExecutionException e) {
48
				e.printStackTrace();
49
			} catch (NotDefinedException e) {
50
				e.printStackTrace();
51
			} catch (NotEnabledException e) {
52
				e.printStackTrace();
53
			} catch (NotHandledException e) {
54
				e.printStackTrace();
55
			}
56
		}
57
	}
58
59
	public String getId() {
60
		return command.getId();
61
	}
62
63
	public ImageDescriptor getImageDescriptor() {
64
		return null;
65
	}
66
67
	public String getLabel() {
68
		try {
69
			Command nestedCommand = command.getCommand();
70
			if (nestedCommand != null
71
					&& nestedCommand.getDescription() != null
72
					&& nestedCommand.getDescription().length() != 0) {
73
				return command.getName() + separator + nestedCommand.getDescription();
74
			}
75
			return command.getName();
76
		} catch (NotDefinedException e) {
77
			return command.toString();
78
		}	
79
	}
80
}
(-)Eclipse (+63 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.incubator;
13
14
import org.eclipse.jface.resource.ImageDescriptor;
15
import org.eclipse.ui.IEditorReference;
16
import org.eclipse.ui.IWorkbenchPage;
17
import org.eclipse.ui.IWorkbenchPart;
18
import org.eclipse.ui.PlatformUI;
19
20
/**
21
 * @since 3.3
22
 * 
23
 */
24
public class EditorElement extends AbstractElement {
25
26
	private static final String DIRTY_MARK = "*"; //$NON-NLS-1$
27
28
	private static final String separator = " - "; //$NON-NLS-1$
29
30
	private IEditorReference editorReference;
31
32
	public EditorElement(IEditorReference editorReference) {
33
		this.editorReference = editorReference;
34
	}
35
36
	public void execute() {
37
		IWorkbenchPart part = editorReference.getPart(true);
38
		if (part != null) {
39
			IWorkbenchPage activePage = PlatformUI.getWorkbench()
40
					.getActiveWorkbenchWindow().getActivePage();
41
			if (activePage != null) {
42
				activePage.activate(part);
43
			}
44
		}
45
	}
46
47
	public String getId() {
48
		return editorReference.getId();
49
	}
50
51
	public ImageDescriptor getImageDescriptor() {
52
		return ImageDescriptor.createFromImage(editorReference.getTitleImage());
53
	}
54
55
	public String getLabel() {
56
		boolean dirty = editorReference.isDirty();
57
		return (dirty ? DIRTY_MARK : "") + editorReference.getName() + separator + editorReference.getTitleToolTip(); //$NON-NLS-1$
58
	}
59
60
	public String getSortLabel() {
61
		return editorReference.getTitle();
62
	}
63
}
(-)Eclipse (+69 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.incubator;
13
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.HashMap;
17
import java.util.Map;
18
import java.util.Set;
19
20
import org.eclipse.jface.preference.IPreferenceNode;
21
import org.eclipse.jface.preference.PreferenceManager;
22
import org.eclipse.jface.resource.ImageDescriptor;
23
import org.eclipse.ui.PlatformUI;
24
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
25
import org.eclipse.ui.internal.WorkbenchImages;
26
27
/**
28
 * @since 3.3
29
 * 
30
 */
31
public class PreferenceProvider extends AbstractProvider {
32
33
	private AbstractElement[] cachedElements;
34
	private Map idToElement = new HashMap();
35
36
	public String getId() {
37
		return "org.eclipse.ui.preferences"; //$NON-NLS-1$
38
	}
39
40
	public AbstractElement getElementForId(String id) {
41
		getElements();
42
		return (PreferenceElement) idToElement.get(id);
43
	}
44
45
	public AbstractElement[] getElements() {
46
		if (cachedElements == null) {
47
			List list = PlatformUI.getWorkbench().getPreferenceManager().getElements(PreferenceManager.PRE_ORDER);
48
			Set uniqueElements = new HashSet(list);
49
			IPreferenceNode[] preferences = (IPreferenceNode[]) uniqueElements.toArray(new IPreferenceNode[uniqueElements.size()]);
50
			cachedElements = new AbstractElement[preferences.length];
51
			for (int i = 0; i < preferences.length; i++) {
52
				PreferenceElement preferenceElement = new PreferenceElement(
53
						preferences[i]);
54
				cachedElements[i] = preferenceElement;
55
				idToElement.put(preferenceElement.getId(), preferenceElement);
56
			}
57
		}
58
		return cachedElements;
59
	}
60
61
	public ImageDescriptor getImageDescriptor() {
62
		return WorkbenchImages
63
				.getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJ_NODE);
64
	}
65
66
	public String getName() {
67
		return IncubatorMessages.CtrlEAction_Preferences;
68
	}
69
}
(-)Eclipse (+68 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.incubator;
13
14
import org.eclipse.jface.preference.IPreferenceNode;
15
import org.eclipse.jface.preference.IPreferencePage;
16
import org.eclipse.jface.resource.ImageDescriptor;
17
import org.eclipse.swt.graphics.Image;
18
import org.eclipse.ui.IWorkbenchWindow;
19
import org.eclipse.ui.PlatformUI;
20
import org.eclipse.ui.internal.dialogs.WorkbenchPreferenceDialog;
21
22
/**
23
 * @since 3.3
24
 *
25
 */
26
public class PreferenceElement extends AbstractElement {
27
28
	private static final String separator = " - "; //$NON-NLS-1$
29
	
30
	private IPreferenceNode preferenceNode;
31
	
32
	public PreferenceElement(IPreferenceNode preferenceNode) {
33
		this.preferenceNode = preferenceNode;
34
	}
35
	
36
	public void execute() {
37
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
38
		if(window != null) {
39
			WorkbenchPreferenceDialog dialog = WorkbenchPreferenceDialog
40
				.createDialogOn(window.getShell(), preferenceNode
41
						.getId());
42
		dialog.open();
43
		}
44
	}
45
46
	public String getId() {
47
		return preferenceNode.getId();
48
	}
49
50
	public ImageDescriptor getImageDescriptor() {
51
		Image image = preferenceNode.getLabelImage();
52
		if(image != null) {
53
			ImageDescriptor descriptor = ImageDescriptor.createFromImage(image);
54
			return descriptor;
55
		}
56
		return null;
57
	}
58
59
	public String getLabel() {
60
		IPreferencePage page = preferenceNode.getPage();
61
		if (page != null && page.getDescription() != null
62
				&& page.getDescription().length() != 0) {
63
			return preferenceNode.getLabelText() + separator
64
					+ page.getDescription();
65
		}
66
		return preferenceNode.getLabelText();
67
	}
68
}
(-)Eclipse (+80 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.incubator;
13
14
import java.util.HashMap;
15
import java.util.Map;
16
import java.util.SortedSet;
17
import java.util.TreeSet;
18
19
import org.eclipse.core.commands.ParameterizedCommand;
20
import org.eclipse.jface.bindings.Binding;
21
import org.eclipse.jface.resource.ImageDescriptor;
22
import org.eclipse.ui.PlatformUI;
23
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
24
import org.eclipse.ui.internal.WorkbenchImages;
25
import org.eclipse.ui.internal.keys.BindingService;
26
import org.eclipse.ui.keys.IBindingService;
27
28
/**
29
 * @since 3.3
30
 * 
31
 */
32
public class CommandProvider extends AbstractProvider {
33
34
	private AbstractElement[] cachedElements;
35
	private Map idToElement = new HashMap();
36
37
	public String getId() {
38
		return "org.eclipse.ui.commands"; //$NON-NLS-1$
39
	}
40
41
	public AbstractElement getElementForId(String id) {
42
		getElements();
43
		return (CommandElement) idToElement.get(id);
44
	}
45
46
	public AbstractElement[] getElements() {
47
		if (cachedElements == null) {
48
			BindingService bindingService = (BindingService) PlatformUI
49
					.getWorkbench().getService(IBindingService.class);
50
			Binding[] bindings = bindingService.getBindings();
51
			SortedSet commandSet = new TreeSet();
52
			for (int i = 0; i < bindings.length; i++) {
53
				Binding binding = bindings[i];
54
				ParameterizedCommand command = binding
55
						.getParameterizedCommand();
56
				if (command != null && command.getCommand().isHandled()) {
57
					commandSet.add(command);
58
				}
59
			}
60
			ParameterizedCommand[] commands = (ParameterizedCommand[]) commandSet
61
					.toArray(new ParameterizedCommand[commandSet.size()]);
62
			cachedElements = new AbstractElement[commands.length];
63
			for (int i = 0; i < commands.length; i++) {
64
				CommandElement commandElement = new CommandElement(commands[i]);
65
				cachedElements[i] = commandElement;
66
				idToElement.put(commandElement.getId(), commandElement);
67
			}
68
		}
69
		return cachedElements;
70
	}
71
72
	public ImageDescriptor getImageDescriptor() {
73
		return WorkbenchImages
74
				.getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJ_NODE);
75
	}
76
77
	public String getName() {
78
		return IncubatorMessages.CtrlEAction_Commands;
79
	}
80
}
(-)Eclipse (+49 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.incubator;
13
14
import org.eclipse.jface.resource.ImageDescriptor;
15
import org.eclipse.ui.IPerspectiveDescriptor;
16
import org.eclipse.ui.IWorkbenchPage;
17
import org.eclipse.ui.PlatformUI;
18
19
/**
20
 * @since 3.3
21
 *
22
 */
23
public class PerspectiveElement extends AbstractElement {
24
25
	private final IPerspectiveDescriptor descriptor;
26
	
27
	public PerspectiveElement(IPerspectiveDescriptor descriptor) {
28
		this.descriptor = descriptor;
29
	}
30
	
31
	public void execute() {
32
		IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
33
		if(activePage != null) {
34
			activePage.setPerspective(descriptor);
35
		}
36
	}
37
	
38
	public String getId() {
39
		return descriptor.getId();
40
	}
41
	
42
	public ImageDescriptor getImageDescriptor() {
43
		return descriptor.getImageDescriptor();
44
	}
45
	
46
	public String getLabel() {
47
		return descriptor.getLabel();
48
	}
49
}
(-)Eclipse (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.incubator;
13
14
import org.eclipse.jface.resource.ImageDescriptor;
15
16
/**
17
 * @since 3.3
18
 * 
19
 */
20
public abstract class AbstractElement {
21
22
	public abstract String getLabel();
23
24
	public abstract ImageDescriptor getImageDescriptor();
25
26
	public abstract String getId();
27
28
	public abstract void execute();
29
	
30
	public String getSortLabel() {
31
		return getLabel();
32
	}
33
}
(-)Eclipse (+65 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.incubator;
13
14
import java.util.HashMap;
15
import java.util.Map;
16
17
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.ui.IEditorReference;
19
import org.eclipse.ui.IWorkbenchPage;
20
import org.eclipse.ui.PlatformUI;
21
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
22
import org.eclipse.ui.internal.WorkbenchImages;
23
24
/**
25
 * @since 3.3
26
 * 
27
 */
28
public class EditorProvider extends AbstractProvider {
29
30
	private AbstractElement[] cachedElements;
31
	private Map idToElement = new HashMap();
32
33
	public AbstractElement getElementForId(String id) {
34
		getElements();
35
		return (EditorElement) idToElement.get(id);
36
	}
37
38
	public AbstractElement[] getElements() {
39
		if (cachedElements == null) {
40
			IWorkbenchPage activePage = PlatformUI.getWorkbench()
41
					.getActiveWorkbenchWindow().getActivePage();
42
			IEditorReference[] editors = activePage.getEditorReferences();
43
			cachedElements = new AbstractElement[editors.length];
44
			for (int i = 0; i < editors.length; i++) {
45
				EditorElement editorElement = new EditorElement(editors[i]);
46
				cachedElements[i] = editorElement;
47
				idToElement.put(editorElement.getId(), editorElement);
48
			}
49
		}
50
		return cachedElements;
51
	}
52
53
	public String getId() {
54
		return "org.eclipse.ui.editors"; //$NON-NLS-1$
55
	}
56
57
	public ImageDescriptor getImageDescriptor() {
58
		return WorkbenchImages
59
				.getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJ_NODE);
60
	}
61
62
	public String getName() {
63
		return IncubatorMessages.CtrlEAction_Editors;
64
	}
65
}
(-)Eclipse (+63 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.incubator;
13
14
import java.util.HashMap;
15
import java.util.Map;
16
17
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.ui.PlatformUI;
19
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
20
import org.eclipse.ui.internal.WorkbenchImages;
21
import org.eclipse.ui.views.IViewDescriptor;
22
23
/**
24
 * @since 3.3
25
 * 
26
 */
27
public class ViewProvider extends AbstractProvider {
28
29
	private AbstractElement[] cachedElements;
30
	private Map idToElement = new HashMap();
31
32
	public String getId() {
33
		return "org.eclipse.ui.views"; //$NON-NLS-1$
34
	}
35
36
	public AbstractElement getElementForId(String id) {
37
		getElements();
38
		return (ViewElement) idToElement.get(id);
39
	}
40
41
	public AbstractElement[] getElements() {
42
		if (cachedElements == null) {
43
			IViewDescriptor[] views = PlatformUI.getWorkbench()
44
					.getViewRegistry().getViews();
45
			cachedElements = new AbstractElement[views.length];
46
			for (int i = 0; i < views.length; i++) {
47
				ViewElement viewElement = new ViewElement(views[i]);
48
				cachedElements[i] = viewElement;
49
				idToElement.put(viewElement.getId(), viewElement);
50
			}
51
		}
52
		return cachedElements;
53
	}
54
55
	public ImageDescriptor getImageDescriptor() {
56
		return WorkbenchImages
57
				.getImageDescriptor(IWorkbenchGraphicConstants.IMG_VIEW_DEFAULTVIEW_MISC);
58
	}
59
60
	public String getName() {
61
		return IncubatorMessages.CtrlEAction_Views;
62
	}
63
}
(-)Eclipse (+57 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.incubator;
13
14
import org.eclipse.jface.action.ActionContributionItem;
15
import org.eclipse.jface.action.IAction;
16
import org.eclipse.jface.action.LegacyActionTools;
17
import org.eclipse.jface.resource.ImageDescriptor;
18
19
/**
20
 * @since 3.3
21
 *
22
 */
23
public class ActionElement extends AbstractElement {
24
25
	private static final String separator = " - "; //$NON-NLS-1$
26
	
27
	private ActionContributionItem item;
28
	
29
	public ActionElement(ActionContributionItem item) {
30
		this.item = item;
31
	}
32
	
33
	public void execute() {
34
		item.getAction().run();
35
	}
36
37
	public String getId() {
38
		return item.getId();
39
	}
40
41
	public ImageDescriptor getImageDescriptor() {
42
		return item.getAction().getImageDescriptor();
43
	}
44
45
	public String getLabel() {
46
		IAction action = item.getAction();
47
		if (action.getToolTipText() != null
48
				&& action.getToolTipText().length() != 0) {
49
			return LegacyActionTools.removeMnemonics(action.getText())
50
					+ separator + action.getToolTipText();
51
		}
52
		return LegacyActionTools.removeMnemonics(action.getText());
53
	}
54
}
55
56
57
(-)Eclipse (+53 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.incubator;
13
14
import org.eclipse.jface.resource.ImageDescriptor;
15
import org.eclipse.ui.IWorkbenchPage;
16
import org.eclipse.ui.PartInitException;
17
import org.eclipse.ui.PlatformUI;
18
import org.eclipse.ui.views.IViewDescriptor;
19
20
/**
21
 * @since 3.3
22
 *
23
 */
24
public class ViewElement extends AbstractElement {
25
26
	private final IViewDescriptor viewDescriptor;
27
	
28
	public ViewElement(IViewDescriptor viewDescriptor) {
29
		this.viewDescriptor = viewDescriptor;
30
	}
31
	
32
	public void execute() {
33
		IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
34
		if(activePage != null) {
35
			try {
36
				activePage.showView(viewDescriptor.getId());
37
			} catch (PartInitException e) {
38
			}
39
		}
40
	}
41
42
	public String getId() {
43
		return viewDescriptor.getId();
44
	}
45
46
	public ImageDescriptor getImageDescriptor() {
47
		return viewDescriptor.getImageDescriptor();
48
	}
49
50
	public String getLabel() {
51
		return viewDescriptor.getLabel();
52
	}
53
}

Return to bug 162006