Link Here
|
11 |
|
11 |
|
12 |
package org.eclipse.ui.internal; |
12 |
package org.eclipse.ui.internal; |
13 |
|
13 |
|
|
|
14 |
import com.ibm.icu.text.Collator; |
14 |
import java.util.ArrayList; |
15 |
import java.util.ArrayList; |
15 |
import java.util.Arrays; |
|
|
16 |
import java.util.Collections; |
16 |
import java.util.Collections; |
17 |
import java.util.Comparator; |
17 |
import java.util.Comparator; |
18 |
import java.util.HashMap; |
18 |
import java.util.HashMap; |
19 |
import java.util.Iterator; |
19 |
import java.util.Iterator; |
20 |
import java.util.List; |
20 |
import java.util.List; |
21 |
import java.util.Map; |
21 |
import java.util.Map; |
22 |
|
|
|
23 |
import org.eclipse.core.commands.Command; |
22 |
import org.eclipse.core.commands.Command; |
24 |
import org.eclipse.core.commands.ExecutionException; |
23 |
import org.eclipse.core.commands.ExecutionException; |
25 |
import org.eclipse.core.commands.IParameter; |
24 |
import org.eclipse.core.commands.IParameter; |
Link Here
|
39 |
import org.eclipse.swt.widgets.Menu; |
38 |
import org.eclipse.swt.widgets.Menu; |
40 |
import org.eclipse.swt.widgets.MenuItem; |
39 |
import org.eclipse.swt.widgets.MenuItem; |
41 |
import org.eclipse.ui.IPluginContribution; |
40 |
import org.eclipse.ui.IPluginContribution; |
|
|
41 |
import org.eclipse.ui.IViewReference; |
42 |
import org.eclipse.ui.IWorkbenchCommandConstants; |
42 |
import org.eclipse.ui.IWorkbenchCommandConstants; |
43 |
import org.eclipse.ui.IWorkbenchPage; |
43 |
import org.eclipse.ui.IWorkbenchPage; |
44 |
import org.eclipse.ui.IWorkbenchWindow; |
44 |
import org.eclipse.ui.IWorkbenchWindow; |
Link Here
|
53 |
import org.eclipse.ui.views.IViewDescriptor; |
53 |
import org.eclipse.ui.views.IViewDescriptor; |
54 |
import org.eclipse.ui.views.IViewRegistry; |
54 |
import org.eclipse.ui.views.IViewRegistry; |
55 |
|
55 |
|
56 |
import com.ibm.icu.text.Collator; |
|
|
57 |
|
58 |
/** |
56 |
/** |
59 |
* A <code>ShowViewMenu</code> is used to populate a menu manager with Show |
57 |
* A <code>ShowViewMenu</code> is used to populate a menu manager with Show |
60 |
* View actions. The visible views are determined by user preference from the |
58 |
* View actions. The visible views are determined by user preference from the |
Link Here
|
66 |
*/ |
64 |
*/ |
67 |
public static final String SHOW_VIEW_ID= IWorkbenchCommandConstants.VIEWS_SHOW_VIEW; |
65 |
public static final String SHOW_VIEW_ID= IWorkbenchCommandConstants.VIEWS_SHOW_VIEW; |
68 |
public static final String VIEW_ID_PARM = "org.eclipse.ui.views.showView.viewId"; //$NON-NLS-1$ |
66 |
public static final String VIEW_ID_PARM = "org.eclipse.ui.views.showView.viewId"; //$NON-NLS-1$ |
|
|
67 |
private static final String PARAMETER_SECONDARY_ID = "org.eclipse.ui.views.showView.secondaryId"; //$NON-NLS-1$ |
69 |
private static final String PARAMETER_MAKE_FAST = "org.eclipse.ui.views.showView.makeFast"; //$NON-NLS-1$ |
68 |
private static final String PARAMETER_MAKE_FAST = "org.eclipse.ui.views.showView.makeFast"; //$NON-NLS-1$ |
70 |
|
69 |
|
|
|
70 |
static class Pair { |
71 |
public final Object a; |
72 |
public final Object b; |
73 |
int hashCode = -1; |
74 |
|
75 |
/** |
76 |
* @param a |
77 |
* must not be <code>null</code> |
78 |
* @param b |
79 |
* can be <code>null</code> |
80 |
*/ |
81 |
public Pair(Object a, Object b) { |
82 |
this.a = a; |
83 |
this.b = b; |
84 |
} |
85 |
|
86 |
/* |
87 |
* (non-Javadoc) |
88 |
* |
89 |
* @see java.lang.Object#hashCode() |
90 |
*/ |
91 |
public int hashCode() { |
92 |
if (hashCode == -1) { |
93 |
final int prime = 31; |
94 |
hashCode = 1; |
95 |
hashCode = prime * hashCode + ((a == null) ? 0 : a.hashCode()); |
96 |
hashCode = prime * hashCode + ((b == null) ? 0 : b.hashCode()); |
97 |
if (hashCode == -1) { |
98 |
hashCode = a.hashCode(); |
99 |
} |
100 |
} |
101 |
return hashCode; |
102 |
} |
103 |
|
104 |
/* |
105 |
* (non-Javadoc) |
106 |
* |
107 |
* @see java.lang.Object#equals(java.lang.Object) |
108 |
*/ |
109 |
public boolean equals(Object obj) { |
110 |
if (this == obj) { |
111 |
return true; |
112 |
} |
113 |
Pair p = (Pair) obj; |
114 |
if (!a.equals(p.a)) { |
115 |
return false; |
116 |
} |
117 |
if (b == p.b) { |
118 |
return true; |
119 |
} |
120 |
if (b == null || p.b == null) { |
121 |
return false; |
122 |
} |
123 |
return b.equals(p.b); |
124 |
} |
125 |
} |
126 |
|
71 |
private IWorkbenchWindow window; |
127 |
private IWorkbenchWindow window; |
72 |
|
128 |
|
73 |
private static final String NO_TARGETS_MSG = WorkbenchMessages.Workbench_showInNoTargets; |
129 |
private static final String NO_TARGETS_MSG = WorkbenchMessages.Workbench_showInNoTargets; |
Link Here
|
87 |
|
143 |
|
88 |
private Map actions = new HashMap(21); |
144 |
private Map actions = new HashMap(21); |
89 |
|
145 |
|
90 |
// Maps pages to a list of opened views |
|
|
91 |
private Map openedViews = new HashMap(); |
92 |
|
93 |
protected boolean dirty = true; |
146 |
protected boolean dirty = true; |
94 |
|
147 |
|
95 |
private IMenuListener menuListener = new IMenuListener() { |
148 |
private IMenuListener menuListener = new IMenuListener() { |
Link Here
|
193 |
} |
246 |
} |
194 |
|
247 |
|
195 |
// Get visible actions. |
248 |
// Get visible actions. |
196 |
List viewIds = Arrays.asList(page.getShowViewShortcuts()); |
249 |
List viewIds = getShortcuts(page); |
197 |
|
250 |
|
198 |
// add all open views |
251 |
// add all open views |
199 |
viewIds = addOpenedViews(page, viewIds); |
252 |
viewIds = addOpenedViews(page, viewIds); |
200 |
|
253 |
|
201 |
List actions = new ArrayList(viewIds.size()); |
254 |
List actions = new ArrayList(viewIds.size()); |
202 |
for (Iterator i = viewIds.iterator(); i.hasNext();) { |
255 |
for (Iterator i = viewIds.iterator(); i.hasNext();) { |
203 |
String id = (String) i.next(); |
256 |
Pair id = (Pair) i.next(); |
204 |
if (id.equals(IIntroConstants.INTRO_VIEW_ID)) { |
257 |
if (id.a.equals(IIntroConstants.INTRO_VIEW_ID)) { |
205 |
continue; |
258 |
continue; |
206 |
} |
259 |
} |
207 |
CommandContributionItemParameter item = getItem(id); |
260 |
CommandContributionItemParameter item = getItem((String) id.a, (String) id.b); |
208 |
if (item != null) { |
261 |
if (item != null) { |
209 |
actions.add(item); |
262 |
actions.add(item); |
210 |
} |
263 |
} |
Link Here
|
230 |
innerMgr.add(showDlgAction); |
283 |
innerMgr.add(showDlgAction); |
231 |
} |
284 |
} |
232 |
|
285 |
|
|
|
286 |
/** |
287 |
* @param page |
288 |
* @return |
289 |
*/ |
290 |
private List getShortcuts(IWorkbenchPage page) { |
291 |
ArrayList list = new ArrayList(); |
292 |
String[] shortcuts = page.getShowViewShortcuts(); |
293 |
for (int i = 0; i < shortcuts.length; i++) { |
294 |
list.add(new Pair(shortcuts[i], null)); |
295 |
} |
296 |
return list; |
297 |
} |
298 |
|
233 |
static class PluginCCIP extends CommandContributionItemParameter implements |
299 |
static class PluginCCIP extends CommandContributionItemParameter implements |
234 |
IPluginContribution { |
300 |
IPluginContribution { |
235 |
|
301 |
|
Link Here
|
263 |
|
329 |
|
264 |
} |
330 |
} |
265 |
|
331 |
|
266 |
private CommandContributionItemParameter getItem(String viewId) { |
332 |
private CommandContributionItemParameter getItem(String viewId, String secondaryId) { |
267 |
IViewRegistry reg = WorkbenchPlugin.getDefault().getViewRegistry(); |
333 |
IViewRegistry reg = WorkbenchPlugin.getDefault().getViewRegistry(); |
268 |
IViewDescriptor desc = reg.find(viewId); |
334 |
IViewDescriptor desc = reg.find(viewId); |
269 |
if (desc==null) { |
335 |
if (desc==null) { |
Link Here
|
282 |
if (makeFast) { |
348 |
if (makeFast) { |
283 |
parms.parameters.put(PARAMETER_MAKE_FAST, "true"); //$NON-NLS-1$ |
349 |
parms.parameters.put(PARAMETER_MAKE_FAST, "true"); //$NON-NLS-1$ |
284 |
} |
350 |
} |
|
|
351 |
if (secondaryId != null) { |
352 |
parms.parameters.put(PARAMETER_SECONDARY_ID, secondaryId); |
353 |
} |
285 |
return parms; |
354 |
return parms; |
286 |
} |
355 |
} |
287 |
|
356 |
|
Link Here
|
305 |
} |
374 |
} |
306 |
|
375 |
|
307 |
private ArrayList getParts(IWorkbenchPage page) { |
376 |
private ArrayList getParts(IWorkbenchPage page) { |
308 |
ArrayList parts = (ArrayList) openedViews.get(page); |
377 |
ArrayList parts = new ArrayList(); |
309 |
if (parts == null) { |
378 |
IViewReference[] refs = page.getViewReferences(); |
310 |
parts = new ArrayList(); |
379 |
for (int i = 0; i < refs.length; i++) { |
311 |
openedViews.put(page, parts); |
380 |
parts.add(new Pair(refs[i].getId(), refs[i].getSecondaryId())); |
312 |
} |
381 |
} |
313 |
return parts; |
382 |
return parts; |
314 |
} |
383 |
} |