|
Lines 15-27
Link Here
|
| 15 |
import java.util.List; |
15 |
import java.util.List; |
| 16 |
import java.util.Set; |
16 |
import java.util.Set; |
| 17 |
|
17 |
|
|
|
18 |
import org.eclipse.core.resources.IResource; |
| 18 |
import org.eclipse.core.runtime.IExtension; |
19 |
import org.eclipse.core.runtime.IExtension; |
| 19 |
import org.eclipse.core.runtime.IPluginDescriptor; |
20 |
import org.eclipse.core.runtime.IPluginDescriptor; |
| 20 |
import org.eclipse.debug.internal.ui.DebugUIPlugin; |
21 |
import org.eclipse.debug.internal.ui.DebugUIPlugin; |
| 21 |
import org.eclipse.debug.internal.ui.Pair; |
22 |
import org.eclipse.debug.internal.ui.Pair; |
| 22 |
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager; |
23 |
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager; |
| 23 |
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension; |
|
|
| 24 |
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension; |
24 |
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension; |
|
|
25 |
import org.eclipse.debug.ui.ILaunchFilter; |
| 25 |
import org.eclipse.jface.action.Action; |
26 |
import org.eclipse.jface.action.Action; |
| 26 |
import org.eclipse.jface.action.ActionContributionItem; |
27 |
import org.eclipse.jface.action.ActionContributionItem; |
| 27 |
import org.eclipse.jface.action.IAction; |
28 |
import org.eclipse.jface.action.IAction; |
|
Lines 33-39
Link Here
|
| 33 |
import org.eclipse.swt.widgets.Control; |
34 |
import org.eclipse.swt.widgets.Control; |
| 34 |
import org.eclipse.swt.widgets.Menu; |
35 |
import org.eclipse.swt.widgets.Menu; |
| 35 |
import org.eclipse.swt.widgets.MenuItem; |
36 |
import org.eclipse.swt.widgets.MenuItem; |
| 36 |
import org.eclipse.ui.IActionFilter; |
|
|
| 37 |
import org.eclipse.ui.IObjectActionDelegate; |
37 |
import org.eclipse.ui.IObjectActionDelegate; |
| 38 |
import org.eclipse.ui.IPerspectiveDescriptor; |
38 |
import org.eclipse.ui.IPerspectiveDescriptor; |
| 39 |
import org.eclipse.ui.IWorkbenchPage; |
39 |
import org.eclipse.ui.IWorkbenchPage; |
|
Lines 54-98
Link Here
|
| 54 |
* (run, debug, profile, etc.) in the contextual launch sub-menu. The filterClass |
54 |
* (run, debug, profile, etc.) in the contextual launch sub-menu. The filterClass |
| 55 |
* is loaded and run over the list of "filter" elements to determine if the |
55 |
* is loaded and run over the list of "filter" elements to determine if the |
| 56 |
* shortcut extension item is appropriate for the selected resource. |
56 |
* shortcut extension item is appropriate for the selected resource. |
| 57 |
* <p> |
57 |
* </p> |
| 58 |
* An example is the JDT Java Applet extension, which is only applicable on files |
|
|
| 59 |
* of extension "*.java" and being a sub-class of type Applet. Note that it is up |
| 60 |
* to the filterClass to provide attributes and methods to implement the test. In |
| 61 |
* this example, we have extended the AppletShortcut to implement the IActionFilter |
| 62 |
* interface so that it can function as the filterClass, adding only a testAttribute() |
| 63 |
* method. |
| 64 |
* <p> |
| 65 |
* <pre> |
| 66 |
* <shortcut |
| 67 |
* label="%AppletShortcut.label" |
| 68 |
* icon="icons/full/ctool16/java_applet.gif" |
| 69 |
* helpContextId="org.eclipse.jdt.debug.ui.shortcut_java_applet" |
| 70 |
* modes="run, debug" |
| 71 |
* filterClass="org.eclipse.jdt.internal.debug.ui.launcher.JavaAppletLaunchShortcut" |
| 72 |
* class="org.eclipse.jdt.internal.debug.ui.launcher.JavaAppletLaunchShortcut" |
| 73 |
* id="org.eclipse.jdt.debug.ui.javaAppletShortcut"> |
| 74 |
* <filter |
| 75 |
* name="NameMatches" |
| 76 |
* value="*.java"/> |
| 77 |
* <filter |
| 78 |
* name="ContextualLaunchActionFilter" |
| 79 |
* value="supportsContextualLaunch"/> |
| 80 |
* <contextLabel |
| 81 |
* mode="run" |
| 82 |
* label="%RunJavaApplet.label"/> |
| 83 |
* <contextLabel |
| 84 |
* mode="debug" |
| 85 |
* label="%DebugJavaApplet.label"/> |
| 86 |
* ... |
| 87 |
* <shortcut> |
| 88 |
* </pre> |
| 89 |
*/ |
58 |
*/ |
| 90 |
public class ContextualLaunchObjectActionDelegate |
59 |
public class ContextualLaunchObjectActionDelegate |
| 91 |
implements |
60 |
implements |
| 92 |
IObjectActionDelegate, |
61 |
IObjectActionDelegate, |
| 93 |
IMenuCreator { |
62 |
IMenuCreator { |
| 94 |
|
63 |
|
| 95 |
private ISelection fSelection; |
64 |
private IResource fSelection; |
| 96 |
|
65 |
|
| 97 |
/* |
66 |
/* |
| 98 |
* @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) |
67 |
* @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) |
|
Lines 149-171
Link Here
|
| 149 |
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) |
118 |
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) |
| 150 |
*/ |
119 |
*/ |
| 151 |
public void selectionChanged(IAction action, ISelection selection) { |
120 |
public void selectionChanged(IAction action, ISelection selection) { |
| 152 |
if (((IStructuredSelection) selection).size() != 1) |
121 |
// if the selection is an IResource, save it and enable our action |
| 153 |
action.setEnabled(false); // Can only handle one resource at a time |
122 |
if (selection instanceof IStructuredSelection) { |
| 154 |
else { |
123 |
IStructuredSelection ss = (IStructuredSelection) selection; |
| 155 |
if (action instanceof Action) { |
124 |
if (ss.size() == 1 && action instanceof Action) { |
| 156 |
if (delegateAction != action) { |
125 |
if (delegateAction != action) { |
| 157 |
delegateAction = (Action) action; |
126 |
delegateAction = (Action) action; |
| 158 |
delegateAction.setMenuCreator(this); |
127 |
delegateAction.setMenuCreator(this); |
| 159 |
} |
128 |
} |
| 160 |
action.setEnabled(true); |
129 |
Object object = ss.getFirstElement(); // already tested size above |
| 161 |
fSelection = selection; |
130 |
if(object instanceof IResource) { |
| 162 |
} else { |
131 |
fSelection = (IResource)object; |
| 163 |
action.setEnabled(false); |
132 |
action.setEnabled(true); |
|
|
133 |
return; |
| 134 |
} |
| 164 |
} |
135 |
} |
| 165 |
} |
136 |
} |
|
|
137 |
action.setEnabled(false); |
| 166 |
} |
138 |
} |
| 167 |
|
139 |
|
| 168 |
private int fCount = 0; |
|
|
| 169 |
/** |
140 |
/** |
| 170 |
* Fill pull down menu with the pages of the JTabbedPane |
141 |
* Fill pull down menu with the pages of the JTabbedPane |
| 171 |
*/ |
142 |
*/ |
|
Lines 207-217
Link Here
|
| 207 |
} |
178 |
} |
| 208 |
} |
179 |
} |
| 209 |
|
180 |
|
| 210 |
private IActionFilter getFilterClassIfLoaded(LaunchShortcutExtension ext) { |
181 |
private ILaunchFilter getFilterClassIfLoaded(LaunchShortcutExtension ext) { |
| 211 |
IExtension extensionPoint = ext.getConfigurationElement().getDeclaringExtension(); |
182 |
IExtension extensionPoint = ext.getConfigurationElement().getDeclaringExtension(); |
| 212 |
IPluginDescriptor pluginDescriptor = extensionPoint.getDeclaringPluginDescriptor(); |
183 |
IPluginDescriptor pluginDescriptor = extensionPoint.getDeclaringPluginDescriptor(); |
| 213 |
if (pluginDescriptor.isPluginActivated()) { |
184 |
if (pluginDescriptor.isPluginActivated()) { |
| 214 |
IActionFilter filter = ext.getFilterClass(); |
185 |
ILaunchFilter filter = ext.getFilterClass(); |
| 215 |
return filter; |
186 |
return filter; |
| 216 |
} else { |
187 |
} else { |
| 217 |
return null; |
188 |
return null; |
|
Lines 225-233
Link Here
|
| 225 |
private boolean isApplicable(LaunchShortcutExtension ext) { |
196 |
private boolean isApplicable(LaunchShortcutExtension ext) { |
| 226 |
// boolean hasMode = ext.getModes().contains(getMode(launchGroupIdentifier)); |
197 |
// boolean hasMode = ext.getModes().contains(getMode(launchGroupIdentifier)); |
| 227 |
// return false if there isn't a filter class or there are no filters specified by the shortcut |
198 |
// return false if there isn't a filter class or there are no filters specified by the shortcut |
| 228 |
// Only loaded plugins will be used, so the actionFilter is null if the filterClass is not loaded |
199 |
// Only loaded plugins will be used, so the launchFilter is null if the filterClass is not loaded |
| 229 |
IActionFilter actionFilter = getFilterClassIfLoaded(ext); |
200 |
ILaunchFilter launchFilter = getFilterClassIfLoaded(ext); |
| 230 |
if (actionFilter == null) { |
201 |
if (launchFilter == null) { |
| 231 |
return false; |
202 |
return false; |
| 232 |
} |
203 |
} |
| 233 |
List filters = ext.getFilters(); |
204 |
List filters = ext.getFilters(); |
|
Lines 239-247
Link Here
|
| 239 |
Pair pair = (Pair) iter.next(); |
210 |
Pair pair = (Pair) iter.next(); |
| 240 |
String name = pair.firstAsString(); |
211 |
String name = pair.firstAsString(); |
| 241 |
String value= pair.secondAsString(); |
212 |
String value= pair.secondAsString(); |
| 242 |
Object target = fSelection; |
|
|
| 243 |
// any filter that returns false makes the shortcut non-visible |
213 |
// any filter that returns false makes the shortcut non-visible |
| 244 |
if (!actionFilter.testAttribute(target,name,value)) { |
214 |
if (!launchFilter.testAttribute(fSelection,name,value)) { |
| 245 |
return false; |
215 |
return false; |
| 246 |
} |
216 |
} |
| 247 |
} |
217 |
} |
|
Lines 264-277
Link Here
|
| 264 |
ActionContributionItem item= new ActionContributionItem(action); |
234 |
ActionContributionItem item= new ActionContributionItem(action); |
| 265 |
item.fill(menu, -1); |
235 |
item.fill(menu, -1); |
| 266 |
} |
236 |
} |
| 267 |
|
237 |
|
| 268 |
private class FakeAction extends Action { |
|
|
| 269 |
public FakeAction(String name) { |
| 270 |
super(name); |
| 271 |
} |
| 272 |
public void run() { |
| 273 |
} |
| 274 |
} |
| 275 |
/** |
238 |
/** |
| 276 |
* Return the ID of the currently active perspective. |
239 |
* Return the ID of the currently active perspective. |
| 277 |
* |
240 |
* |
|
Lines 296-327
Link Here
|
| 296 |
* @return launch configuration manager |
259 |
* @return launch configuration manager |
| 297 |
*/ |
260 |
*/ |
| 298 |
private LaunchConfigurationManager getLaunchConfigurationManager() { |
261 |
private LaunchConfigurationManager getLaunchConfigurationManager() { |
| 299 |
return DebugUIPlugin.getDefault().getLaunchConfigurationManager(); |
262 |
return DebugUIPlugin.getDefault().getLaunchConfigurationManager(); |
| 300 |
} |
|
|
| 301 |
/** |
| 302 |
* Returns the launch group associatd with this action. |
| 303 |
* |
| 304 |
* @return the launch group associatd with this action |
| 305 |
*/ |
| 306 |
private LaunchGroupExtension getLaunchGroup(String fLaunchGroupIdentifier) { |
| 307 |
return getLaunchConfigurationManager().getLaunchGroup(fLaunchGroupIdentifier); |
| 308 |
} |
| 309 |
/** |
| 310 |
* Returns the mode of this action - run or debug |
| 311 |
* |
| 312 |
* @return the mode of this action - run or debug |
| 313 |
*/ |
| 314 |
private String getMode(String fLaunchGroupIdentifier) { |
| 315 |
return getLaunchGroup(fLaunchGroupIdentifier).getMode(); |
| 316 |
} |
| 317 |
|
| 318 |
/** |
| 319 |
* Returns the category of this action - possibly <code>null</code> |
| 320 |
* |
| 321 |
* @return the category of this action - possibly <code>null</code> |
| 322 |
*/ |
| 323 |
private String getCategory(String fLaunchGroupIdentifier) { |
| 324 |
return getLaunchGroup(fLaunchGroupIdentifier).getCategory(); |
| 325 |
} |
263 |
} |
| 326 |
|
264 |
|
| 327 |
} |
265 |
} |