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 |
} |