Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 18338 | Differences between
and this patch

Collapse All | Expand All

(-)schema/launchShortcuts.exsd (-1 / +4 lines)
Lines 118-125 Link Here
118
         <attribute name="filterClass" type="string">
118
         <attribute name="filterClass" type="string">
119
            <annotation>
119
            <annotation>
120
               <documentation>
120
               <documentation>
121
                  an optional attribute that specifies the fully qualified path of a Java class that implements the &lt;samp&gt;org.eclipse.ui.IActionFilter&lt;/samp&gt; interface. The testAttribute() method is called with the selected resource and the name/value pair specified by subsequent filter elements. If all return values of all filter elements are true, the shortcut will appear in the contextual launch menu of the selected resource. If the filterClass attribute is not specifies, the shortcut will not appear in the contextual launch menu. If the filterClass is specified, but no filter elements are found, the shortcut will appear in the menu.
121
                  an optional attribute that specifies the fully qualified path of a Java class that implements the &lt;samp&gt;org.eclipse.ui.ILaunchFilter&lt;/samp&gt; interface. The testAttribute() method is called with the selected resource and the name/value pair specified by subsequent filter elements. If all return values of all filter elements are true, the shortcut will appear in the contextual launch menu of the selected resource. If the filterClass attribute is not specifies, the shortcut will not appear in the contextual launch menu. If the filterClass is specified, but no filter elements are found, the shortcut will appear in the menu.
122
               </documentation>
122
               </documentation>
123
               <appInfo>
124
                  <meta.attribute kind="java" basedOn="org.eclipse.debug.ui.ILaunchFilter"/>
125
               </appInfo>
123
            </annotation>
126
            </annotation>
124
         </attribute>
127
         </attribute>
125
      </complexType>
128
      </complexType>
(-)ui/org/eclipse/debug/internal/ui/actions/ContextualLaunchObjectActionDelegate.java (-85 / +23 lines)
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
 * &lt;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"&gt;
74
 *        &lt;filter
75
 *           name="NameMatches"
76
 *           value="*.java"/&gt;
77
 *        &lt;filter
78
 *        	name="ContextualLaunchActionFilter"
79
 *        	value="supportsContextualLaunch"/&gt;
80
 *        &lt;contextLabel
81
 *        	mode="run"
82
 *        	label="%RunJavaApplet.label"/&gt;
83
 * 		 &lt;contextLabel
84
 * 		 	mode="debug"
85
 * 		 	label="%DebugJavaApplet.label"/&gt;
86
 * 		  ...
87
 *   &lt;shortcut&gt;
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
}
(-)ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutExtension.java (-6 / +13 lines)
Lines 24-33 Link Here
24
import org.eclipse.core.runtime.IConfigurationElement;
24
import org.eclipse.core.runtime.IConfigurationElement;
25
import org.eclipse.debug.internal.ui.DebugUIPlugin;
25
import org.eclipse.debug.internal.ui.DebugUIPlugin;
26
import org.eclipse.debug.internal.ui.Pair;
26
import org.eclipse.debug.internal.ui.Pair;
27
import org.eclipse.debug.ui.ILaunchFilter;
27
import org.eclipse.debug.ui.ILaunchShortcut;
28
import org.eclipse.debug.ui.ILaunchShortcut;
28
import org.eclipse.jface.resource.ImageDescriptor;
29
import org.eclipse.jface.resource.ImageDescriptor;
29
import org.eclipse.jface.viewers.ISelection;
30
import org.eclipse.jface.viewers.ISelection;
30
import org.eclipse.ui.IActionFilter;
31
import org.eclipse.ui.IEditorPart;
31
import org.eclipse.ui.IEditorPart;
32
32
33
33
Lines 40-46 Link Here
40
	private List fPerspectives = null;
40
	private List fPerspectives = null;
41
	private ILaunchShortcut fDelegate = null;
41
	private ILaunchShortcut fDelegate = null;
42
	private Set fModes = null;
42
	private Set fModes = null;
43
	private IActionFilter fActionFilter = null;
43
	private ILaunchFilter fLaunchFilter = null;
44
	private /* <Pair> */ List fFilters = null;
44
	private /* <Pair> */ List fFilters = null;
45
	
45
	
46
	/**
46
	/**
Lines 125-140 Link Here
125
	 * @return the filter class of this shortcut., or <code>null</code> if not
125
	 * @return the filter class of this shortcut., or <code>null</code> if not
126
	 *  specified
126
	 *  specified
127
	 */
127
	 */
128
	public IActionFilter getFilterClass() {
128
	public ILaunchFilter getFilterClass() {
129
		if (fActionFilter == null) {
129
		if (fLaunchFilter == null) {
130
			try {
130
			try {
131
				fActionFilter = (IActionFilter)fConfig.createExecutableExtension("filterClass"); //$NON-NLS-1$
131
				// The underlying code logs an error if the filterClass is missing,
132
				// even though the attribute is optional, so check for existence first.
133
				if (fConfig.getAttribute("filterClass") != null) { //$NON-NLS-1$
134
					Object object = fConfig.createExecutableExtension("filterClass"); //$NON-NLS-1$
135
					if (object instanceof ILaunchFilter) {
136
						fLaunchFilter = (ILaunchFilter) object;
137
					}
138
				}
132
			} catch (CoreException e) {
139
			} catch (CoreException e) {
133
				// silently ignore because filterClass is optional
140
				// silently ignore because filterClass is optional
134
				// DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(), LaunchConfigurationsMessages.getString("LaunchShortcutExtension.Error_4"), LaunchConfigurationsMessages.getString("LaunchShortcutExtension.Unable_to_use_launch_shortcut_5"), e.getStatus()); //$NON-NLS-1$ //$NON-NLS-2$
141
				// DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(), LaunchConfigurationsMessages.getString("LaunchShortcutExtension.Error_4"), LaunchConfigurationsMessages.getString("LaunchShortcutExtension.Unable_to_use_launch_shortcut_5"), e.getStatus()); //$NON-NLS-1$ //$NON-NLS-2$
135
			}
142
			}
136
		}
143
		}
137
		return fActionFilter;
144
		return fLaunchFilter;
138
	}
145
	}
139
	/**
146
	/**
140
	 * Returns all of the filter elements of this shortcut as a List of String Pairs.
147
	 * Returns all of the filter elements of this shortcut as a List of String Pairs.
(-)ui/org/eclipse/debug/ui/ILaunchShortcut.java (-3 / +29 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
2
 * Copyright (c) 2000, 2003, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 34-45 Link Here
34
 *   &lt;launchShortcut
34
 *   &lt;launchShortcut
35
 *      id="com.example.ExampleLaunchShortcut"
35
 *      id="com.example.ExampleLaunchShortcut"
36
 *      class="com.example.ExampleLaunchShortcutClass"
36
 *      class="com.example.ExampleLaunchShortcutClass"
37
 *      filterClass="com.example.ExampleLaunchShortcutFilterClass"
37
 * 		label="Example Label"
38
 * 		label="Example Label"
38
 * 		icon="\icons\exampleshortcut.gif"
39
 * 		icon="\icons\exampleshortcut.gif"
39
 * 		helpContextId="com.example.shortcut_context"
40
 * 		helpContextId="com.example.shortcut_context"
40
 * 		modes="run, debug"&gt;
41
 * 		modes="run, debug"&gt;
41
 * 		&lt;perspective id="com.example.perspectiveId1"/&gt;
42
 *      &lt;perspective id="com.example.perspectiveId1"/&gt;
42
 *      &lt;perspective id="com.example.perspectiveId2"/&gt;
43
 *      &lt;perspective id="com.example.perspectiveId2"/&gt;
44
 *      &lt;filter
45
 *           name="NameMatches"
46
 *           value="*.java"/&gt;
47
 *      &lt;filter
48
 *        	name="ContextualLaunchActionFilter"
49
 *        	value="supportsContextualLaunch"/&gt;
50
 *      &lt;contextLabel
51
 *        	mode="run"
52
 *        	label="%RunJavaApplet.label"/&gt;
53
 * 	    &lt;contextLabel
54
 * 		 	mode="debug"
55
 * 		 	label="%DebugJavaApplet.label"/&gt;
56
 * 		  ...
43
 *   &lt;/launchShortcut&gt;
57
 *   &lt;/launchShortcut&gt;
44
 * &lt;/extension&gt;
58
 * &lt;/extension&gt;
45
 * </pre>
59
 * </pre>
Lines 47-53 Link Here
47
 * <ul>
61
 * <ul>
48
 * <li><code>id</code> specifies a unique identifier for this launch shortcut.</li>
62
 * <li><code>id</code> specifies a unique identifier for this launch shortcut.</li>
49
 * <li><code>class</code> specifies a fully qualified name of a Java class
63
 * <li><code>class</code> specifies a fully qualified name of a Java class
50
 *  that implements <code>IlaunchShortcut</code>.</li>
64
 *  that implements <code>ILaunchShortcut</code>.</li><li>
65
 * <code>filterClass</code> optionally specifies a fully qualified name of a Java class
66
 *  that implements <code>ILaunchFilter</code> for context menu filtering.</li>
51
 * <li><code>label</code> specifies a label used to render this shortcut.</li>
67
 * <li><code>label</code> specifies a label used to render this shortcut.</li>
52
 * <li><code>icon</code> specifies a plug-in relative path to an icon used to
68
 * <li><code>icon</code> specifies a plug-in relative path to an icon used to
53
 * 	render this shortcut.</li>
69
 * 	render this shortcut.</li>
Lines 58-63 Link Here
58
 * <li><code>perspective</code> one or more perspective entries enumerate the
74
 * <li><code>perspective</code> one or more perspective entries enumerate the
59
 * 	perspectives that this shortcut is avilable in, from the run/debug cascade
75
 * 	perspectives that this shortcut is avilable in, from the run/debug cascade
60
 * 	menus.</li>
76
 * 	menus.</li>
77
 * <li><code>filter</code> zero or more filter entries specify the attribute
78
 * <code>name</code> and attribute <code>value</code> that will be supplied to
79
 * the <code>testAttribute</code> method implemented by the <code>filterClass</code>
80
 * Java Class. If all filters in this list return <code>true</code> when applied
81
 * to a selection target, the shortcut will be avilable in the run/debug context menu.
82
 * 	menu.</li>
83
 * <li><code>contextLabel</code> zero or more context menu labels. For
84
 * shortcuts that pass their filter tests, the specified label will appear
85
 * in the "Run ->" context menu and be bound to a launch action of the
86
 * specified mode (e.g. run,debug,profile).</li>
61
 * </ul>
87
 * </ul>
62
 * </p>
88
 * </p>
63
 * @since 2.0
89
 * @since 2.0
(-)ui/org/eclipse/debug/ui/ILaunchFilter.java (+41 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.ui;
12
13
import org.eclipse.core.resources.IResource;
14
15
/**
16
 * Interface for context-menu launch shortcut visibility.
17
 * <p>
18
 * An optional <code>filterClass</code> attribute in the <code>ILaunchShortcut</code>
19
 * extension allows a shortcut provider to specify a Java class that will
20
 * answer filtering questions. The shortcut extension point accepts a list
21
 * of "contextFilter" elements that specify tests. If the tests all return
22
 * <code>true</code>, the shortcut will appear on the context menu for the
23
 * selected resource.
24
 * </p><p>
25
 * Each <code>contextFilter</code> test receives an <code>IResource</code>
26
 * object, the name of a test attribute, and the expected attribute value.
27
 * </p>
28
 * @see org.eclipse.debug.ui.ILaunchShortcut
29
 */
30
public interface ILaunchFilter {
31
	/**
32
	 * Returns whether the specific attribute matches the state of the target
33
	 * resource object.
34
	 *
35
	 * @param target the target resource object
36
	 * @param name the attribute name
37
	 * @param value expected attribute value
38
	 * @return <code>true</code> if the attribute matches; <code>false</code> otherwise
39
	 */
40
	public boolean testAttribute(IResource target, String name, String value);
41
}

Return to bug 18338