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 54117 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (+9 lines)
Lines 1729-1734 Link Here
1729
         </action>
1729
         </action>
1730
      </objectContribution>
1730
      </objectContribution>
1731
	</extension>
1731
	</extension>
1732
   <extension point="org.eclipse.core.expressions.propertyTesters">
1733
      <propertyTester
1734
      		namespace="org.eclipse.debug.ui"
1735
            properties="matchesPattern, projectNature, canDelete"
1736
            type="org.eclipse.core.resources.IResource"
1737
            class="org.eclipse.debug.internal.ui.ResourceExtender"
1738
            id="org.eclipse.debug.IResourceExtender">
1739
      </propertyTester>
1740
   </extension>
1732
<!-- End Contextual Run Menu (Work in Progress) -->
1741
<!-- End Contextual Run Menu (Work in Progress) -->
1733
<!-- Context extensions -->
1742
<!-- Context extensions -->
1734
  <extension
1743
  <extension
(-)schema/launchShortcuts.exsd (-42 / +15 lines)
Lines 49-56 Link Here
49
      <complexType>
49
      <complexType>
50
         <sequence>
50
         <sequence>
51
            <element ref="perspective" minOccurs="0" maxOccurs="unbounded"/>
51
            <element ref="perspective" minOccurs="0" maxOccurs="unbounded"/>
52
            <element ref="filter" minOccurs="0" maxOccurs="unbounded"/>
52
            <element ref="contextualLaunch" minOccurs="0" maxOccurs="1"/>
53
            <element ref="contextLabel" minOccurs="0" maxOccurs="unbounded"/>
54
         </sequence>
53
         </sequence>
55
         <attribute name="id" type="string" use="required">
54
         <attribute name="id" type="string" use="required">
56
            <annotation>
55
            <annotation>
Lines 108-137 Link Here
108
               </documentation>
107
               </documentation>
109
            </annotation>
108
            </annotation>
110
         </attribute>
109
         </attribute>
111
         <attribute name="contextLabel" type="string">
112
            <annotation>
113
               <documentation>
114
                  an optional attribute that specifies the label to appear in the contextual launch menu (if this shortcut is not filtered according to the rules described in the filterClass attribute). If unspecified, the &lt;samp&gt;label&lt;/samp&gt; attribute will be used instead.
115
               </documentation>
116
            </annotation>
117
         </attribute>
118
         <attribute name="filterClass" type="string">
119
            <annotation>
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.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>
123
               <appInfo>
124
                  <meta.attribute kind="java" basedOn="org.eclipse.debug.ui.ILaunchFilter"/>
125
               </appInfo>
126
            </annotation>
127
         </attribute>
128
         <attribute name="nameFilter" type="string">
129
            <annotation>
130
               <documentation>
131
                  An expression (* and ? wildcards supported), matched against the name of a selected resource. A match allows this launch shortcut to appear in the contextual launch popup menu for the selected resource, unless one of the filters fails in filterClass. If the filterClass is not yet loaded (lazy plugin), the result of the nameFilter test will decide inclusion in the context menu.
132
               </documentation>
133
            </annotation>
134
         </attribute>
135
      </complexType>
110
      </complexType>
136
   </element>
111
   </element>
137
112
Lines 147-173 Link Here
147
      </complexType>
122
      </complexType>
148
   </element>
123
   </element>
149
124
150
   <element name="filter">
125
   <element name="contextualLaunch">
151
      <annotation>
126
      <annotation>
152
         <documentation>
127
         <documentation>
153
            specifies the name/value pair that will be tested for boolean true/false by calling the &lt;samp&gt;org.eclipse.ui.IActionFilter:testAttribute()&lt;/samp&gt; method of the class specified by the &lt;samp&gt;filterClass&lt;/samp&gt; attribute of the parent &lt;samp&gt;shortcut&lt;/samp&gt; element. If all filters return a true value, the shortcut will be visible in the contextual launch menu.
128
            Holds all descriptions for adding shortcuts to the Run context menu (pop-up).
154
         </documentation>
129
         </documentation>
155
      </annotation>
130
      </annotation>
156
      <complexType>
131
      <complexType>
157
         <attribute name="name" type="string" use="required">
132
         <sequence>
158
            <annotation>
133
            <element ref="contextLabel" minOccurs="0" maxOccurs="unbounded"/>
159
               <documentation>
134
            <element ref="enablement" minOccurs="0" maxOccurs="1"/>
160
                  specifies the name of the filter property.
135
         </sequence>
161
               </documentation>
162
            </annotation>
163
         </attribute>
164
         <attribute name="value" type="string" use="required">
165
            <annotation>
166
               <documentation>
167
                  specifies the expected value of the filter property.
168
               </documentation>
169
            </annotation>
170
         </attribute>
171
      </complexType>
136
      </complexType>
172
   </element>
137
   </element>
173
138
Lines 203-208 Link Here
203
            </annotation>
168
            </annotation>
204
         </attribute>
169
         </attribute>
205
      </complexType>
170
      </complexType>
171
   </element>
172
173
   <element name="enablement" type="string">
174
      <annotation>
175
         <documentation>
176
            Enablement logic using XML expression language. This should use some kind of schema reference.
177
         </documentation>
178
      </annotation>
206
   </element>
179
   </element>
207
180
208
   <annotation>
181
   <annotation>
(-)ui/org/eclipse/debug/internal/ui/actions/ContextualLaunchObjectActionDelegate.java (-90 / +78 lines)
Lines 15-29 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.expressions.EvaluationContext;
19
import org.eclipse.core.expressions.Expression;
20
import org.eclipse.core.expressions.IEvaluationContext;
18
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.runtime.IExtension;
22
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IPluginDescriptor;
21
import org.eclipse.debug.internal.ui.DebugUIPlugin;
23
import org.eclipse.debug.internal.ui.DebugUIPlugin;
22
import org.eclipse.debug.internal.ui.Pair;
23
import org.eclipse.debug.internal.ui.StringMatcher;
24
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
24
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
25
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension;
25
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension;
26
import org.eclipse.debug.ui.ILaunchFilter;
27
import org.eclipse.jface.action.Action;
26
import org.eclipse.jface.action.Action;
28
import org.eclipse.jface.action.ActionContributionItem;
27
import org.eclipse.jface.action.ActionContributionItem;
29
import org.eclipse.jface.action.IAction;
28
import org.eclipse.jface.action.IAction;
Lines 62-68 Link Here
62
			IObjectActionDelegate,
61
			IObjectActionDelegate,
63
			IMenuCreator {
62
			IMenuCreator {
64
63
65
	private IResource fSelection;
64
	private IStructuredSelection fSelection;
66
	
65
	
67
	/*
66
	/*
68
	 * @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 121-140 Link Here
121
	public void selectionChanged(IAction action, ISelection selection) {
120
	public void selectionChanged(IAction action, ISelection selection) {
122
		// if the selection is an IResource, save it and enable our action
121
		// if the selection is an IResource, save it and enable our action
123
		if (selection instanceof IStructuredSelection) {
122
		if (selection instanceof IStructuredSelection) {
124
			IStructuredSelection ss = (IStructuredSelection) selection;
123
			if (action instanceof Action) {
125
			if (ss.size() == 1 && action instanceof Action) {
126
				if (delegateAction != action) {
124
				if (delegateAction != action) {
127
					delegateAction = (Action) action;
125
					delegateAction = (Action) action;
128
					delegateAction.setMenuCreator(this);
126
					delegateAction.setMenuCreator(this);
129
				}
127
				}
130
				Object object = ss.getFirstElement(); // already tested size above
128
				// save selection and enable our menu
131
				if(object instanceof IResource) {
129
				fSelection = (IStructuredSelection) selection;
132
					fSelection = (IResource)object;
130
				action.setEnabled(true);
133
					if (fSelection.getType() == IResource.FILE) {
131
				return;
134
						action.setEnabled(true);
135
						return;
136
					}
137
				}
138
			}
132
			}
139
		}
133
		}
140
		action.setEnabled(false);
134
		action.setEnabled(false);
Lines 153-158 Link Here
153
	 * Fill pull down menu with the pages of the JTabbedPane
147
	 * Fill pull down menu with the pages of the JTabbedPane
154
	 */
148
	 */
155
	protected void fillMenu(Menu menu) {
149
	protected void fillMenu(Menu menu) {
150
		IEvaluationContext context = createContext();
151
		
156
		// lookup appropriate launch config types and build launch actions for them.
152
		// lookup appropriate launch config types and build launch actions for them.
157
		// Retrieve the current perspective and the registered shortcuts
153
		// Retrieve the current perspective and the registered shortcuts
158
		String activePerspID = getActivePerspectiveID();
154
		String activePerspID = getActivePerspectiveID();
Lines 167-174 Link Here
167
		List filteredShortCuts = new ArrayList(10);
163
		List filteredShortCuts = new ArrayList(10);
168
		while (iter.hasNext()) {
164
		while (iter.hasNext()) {
169
			LaunchShortcutExtension ext = (LaunchShortcutExtension) iter.next();
165
			LaunchShortcutExtension ext = (LaunchShortcutExtension) iter.next();
170
			if (isApplicable(ext)) {
166
			try {
171
				filteredShortCuts.add(ext);
167
				if (isApplicable(ext, context)) {
168
					filteredShortCuts.add(ext);
169
				}
170
			} catch (CoreException e) {
171
				// bogus XML Expression Language provided.
172
				// TODO provide entry in the log?
172
			}
173
			}
173
		}
174
		}
174
		iter = filteredShortCuts.iterator();
175
		iter = filteredShortCuts.iterator();
Lines 189-247 Link Here
189
			item.fill(menu, -1);
190
			item.fill(menu, -1);
190
		}
191
		}
191
	}
192
	}
192
	
193
	private ILaunchFilter getFilterClassIfLoaded(LaunchShortcutExtension ext) {
194
		IExtension extensionPoint = ext.getConfigurationElement().getDeclaringExtension();
195
		IPluginDescriptor pluginDescriptor = extensionPoint.getDeclaringPluginDescriptor();
196
		if (pluginDescriptor.isPluginActivated()) {
197
			ILaunchFilter filter = ext.getFilterClass();
198
			return filter;
199
		} else {
200
			return null;
201
		}
202
	}
203
	/* (non-javadoc)
204
	 * Apply contextFilters for this extension to decide visibility. 
205
	 *
206
 	 * @return true if this shortcut should appear in the contextual launch menu
207
	 */
208
	private boolean isApplicable(LaunchShortcutExtension ext) {
209
		String nameFilterPattern = ext.getNameFilter();
210
		boolean nameMatches = false;
211
		if (nameFilterPattern != null) {
212
			StringMatcher sm = new StringMatcher(nameFilterPattern, true, false);
213
			nameMatches = sm.match(fSelection.getName());
214
			if (!nameMatches) {
215
				// return now to avoid loading the filterClass
216
				return false;
217
			}
218
		}
219
220
		// Only loaded plugins will be used, so the launchFilter is null if the filterClass is not loaded
221
		ILaunchFilter launchFilter = getFilterClassIfLoaded(ext);
222
		if (launchFilter == null) {
223
			// no launch filter available, just use nameMatches (see bug# 51420)
224
			return nameMatches;
225
		}
226
193
227
		List filters = ext.getFilters();
194
	/**
228
		if (filters.isEmpty()) {
195
	 * @return an Evaluation context with default variable = selection
229
			return false;
196
	 */
230
		}
197
	private IEvaluationContext createContext() {
231
		Iterator iter = filters.listIterator();
198
		// create a default evaluation context with default variable of the user selection
199
		List selection = getSelection();
200
		IEvaluationContext context = new EvaluationContext(null, selection);
201
		context.addVariable("selection", selection); //$NON-NLS-1$
202
		
203
		return context;
204
	}
205
	
206
	/**
207
	 * @return current selection as a List of IResource elements.
208
	 */
209
	private List getSelection() {
210
		ArrayList result = new ArrayList();
211
		Iterator iter = fSelection.iterator();
232
		while (iter.hasNext()) {
212
		while (iter.hasNext()) {
233
			Pair pair = (Pair) iter.next();
213
			IResource selection = (IResource) iter.next();
234
			String name = pair.firstAsString();
214
			result.add(selection);
235
			String value= pair.secondAsString();
236
			// any filter that returns false makes the shortcut non-visible
237
			if (!launchFilter.testAttribute(fSelection,name,value)) {
238
				return false;
239
			}
240
		}
215
		}
241
		return true;
216
		return result;
242
	}
217
	}
243
	/* Add the shortcut to the context menu's launch submenu.
218
	
244
	 * 
219
	/**
220
	 * Evaluate the enablement logic in the contextualLaunch
221
	 * element description. A true result means that we should
222
	 * include this shortcut in the context menu.
223
	 * @return true iff shortcut should appear in context menu
224
	 */
225
	private boolean isApplicable(LaunchShortcutExtension ext, IEvaluationContext context) throws CoreException {
226
		// evaluate the enablement logic in the contextual launch description
227
		Expression expr = ext.getContextualLaunchEnablementExpression();
228
		return ext.evalContextualLaunchEnablementExpression(context, expr);
229
	}
230
231
	/**
232
	 * Add the shortcut to the context menu's launch submenu.
245
	 */
233
	 */
246
	private void populateMenu(String mode, LaunchShortcutExtension ext, Menu menu) {
234
	private void populateMenu(String mode, LaunchShortcutExtension ext, Menu menu) {
247
		LaunchShortcutAction action = new LaunchShortcutAction(mode, ext);
235
		LaunchShortcutAction action = new LaunchShortcutAction(mode, ext);
Lines 258-288 Link Here
258
		item.fill(menu, -1);
246
		item.fill(menu, -1);
259
	}
247
	}
260
248
261
/**
249
	/**
262
 * Return the ID of the currently active perspective.
250
	 * Return the ID of the currently active perspective.
263
 * 
251
	 * 
264
 * @return the active perspective ID or <code>null</code> if there is none.
252
	 * @return the active perspective ID or <code>null</code> if there is none.
265
 */
253
	 */
266
private String getActivePerspectiveID() {
254
	private String getActivePerspectiveID() {
267
	IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow();
255
		IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow();
268
	if (window != null) {
256
		if (window != null) {
269
		IWorkbenchPage page = window.getActivePage();
257
			IWorkbenchPage page = window.getActivePage();
270
		if (page != null) {
258
			if (page != null) {
271
			IPerspectiveDescriptor persp = page.getPerspective();
259
				IPerspectiveDescriptor persp = page.getPerspective();
272
			if (persp != null) {
260
				if (persp != null) {
273
				return persp.getId();
261
					return persp.getId();
262
				}
274
			}
263
			}
275
		}
264
		}
265
		return null;
266
	}
267
	/**
268
	 * Returns the launch configuration manager.
269
	*
270
	* @return launch configuration manager
271
	*/
272
	private LaunchConfigurationManager getLaunchConfigurationManager() {
273
		return DebugUIPlugin.getDefault().getLaunchConfigurationManager();
276
	}
274
	}
277
	return null;
278
}
279
/**
280
 * Returns the launch configuration manager.
281
*
282
* @return launch configuration manager
283
*/
284
private LaunchConfigurationManager getLaunchConfigurationManager() {
285
	return DebugUIPlugin.getDefault().getLaunchConfigurationManager();
286
}
287
275
288
}
276
}
(-)ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutExtension.java (-49 / +87 lines)
Lines 20-30 Link Here
20
import java.util.Set;
20
import java.util.Set;
21
import java.util.StringTokenizer;
21
import java.util.StringTokenizer;
22
22
23
import org.eclipse.core.expressions.EvaluationResult;
24
import org.eclipse.core.expressions.Expression;
25
import org.eclipse.core.expressions.ExpressionConverter;
26
import org.eclipse.core.expressions.ExpressionTagNames;
27
import org.eclipse.core.expressions.IEvaluationContext;
23
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.IConfigurationElement;
29
import org.eclipse.core.runtime.IConfigurationElement;
25
import org.eclipse.debug.internal.ui.DebugUIPlugin;
30
import org.eclipse.debug.internal.ui.DebugUIPlugin;
26
import org.eclipse.debug.internal.ui.Pair;
31
import org.eclipse.debug.internal.ui.Pair;
27
import org.eclipse.debug.ui.ILaunchFilter;
28
import org.eclipse.debug.ui.ILaunchShortcut;
32
import org.eclipse.debug.ui.ILaunchShortcut;
29
import org.eclipse.jface.resource.ImageDescriptor;
33
import org.eclipse.jface.resource.ImageDescriptor;
30
import org.eclipse.jface.viewers.ISelection;
34
import org.eclipse.jface.viewers.ISelection;
Lines 40-47 Link Here
40
	private List fPerspectives = null;
44
	private List fPerspectives = null;
41
	private ILaunchShortcut fDelegate = null;
45
	private ILaunchShortcut fDelegate = null;
42
	private Set fModes = null;
46
	private Set fModes = null;
43
	private ILaunchFilter fLaunchFilter = null;
47
	private IConfigurationElement fContextualLaunchConfigurationElement = null;
44
	private /* <Pair> */ List fFilters = null;
48
	private Expression fContextualLaunchExpr = null;
45
	
49
	
46
	/**
50
	/**
47
	 * The configuration element defining this tab.
51
	 * The configuration element defining this tab.
Lines 93-109 Link Here
93
	}
97
	}
94
	
98
	
95
	/**
99
	/**
96
	 * Returns the name filter of this shortcut or <code>null</code>
100
	 * Returns the configuration element for the optional Contextual Launch
97
	 * 
101
	 * element of this Launch Configuration description.
98
	 * @return the name filter of this shortcut, or <code>null</code> if not
102
	 * @return contextualLaunch element
99
	 *  specified
103
	 */
100
	 */
104
	public IConfigurationElement getContextualLaunchConfigurationElement() {
101
	public String getNameFilter() {
105
		if (fContextualLaunchConfigurationElement == null) {
102
		return getConfigurationElement().getAttribute("nameFilter"); //$NON-NLS-1$
106
			IConfigurationElement[] elements = getConfigurationElement().getChildren("contextualLaunch"); //$NON-NLS-1$
107
			if (elements.length > 0) {
108
				// remember so we don't have to hunt again
109
				fContextualLaunchConfigurationElement = elements[0];
110
			}
111
		}
112
		return fContextualLaunchConfigurationElement;
103
	}
113
	}
104
	
105
	/**
114
	/**
106
	 * Returns the contextual launch label of this shortcut
115
	 * Returns the contextual launch label of this shortcut for the named mode.
116
	 * <p>
117
	 * <samp>
118
	 * <launchShortcut...>
119
	 *   <contextualLaunch>
120
	 *     <contextLabel mode="run" label="Run Java Application"/>
121
	 *     <contextLabel mode="debug" label="Debug Java Application"/>
122
	 *     ...
123
	 *   </contextualLaunch>
124
	 * </launchShortcut>
125
	 * </samp>
107
	 * 
126
	 * 
108
	 * @return the contextual label of this shortcut, or <code>null</code> if not
127
	 * @return the contextual label of this shortcut, or <code>null</code> if not
109
	 *  specified
128
	 *  specified
Lines 111-117 Link Here
111
	public String getContextLabel(String mode) {
130
	public String getContextLabel(String mode) {
112
		// remember the list of context labels for this shortcut
131
		// remember the list of context labels for this shortcut
113
		if (fContextLabels == null) {
132
		if (fContextLabels == null) {
114
			IConfigurationElement[] labels = getConfigurationElement().getChildren("contextLabel"); //$NON-NLS-1$
133
			IConfigurationElement context = getContextualLaunchConfigurationElement();
134
			if (context == null) {
135
				return null;
136
			}
137
			IConfigurationElement[] labels = context.getChildren("contextLabel"); //$NON-NLS-1$
115
			fContextLabels = new ArrayList(labels.length);
138
			fContextLabels = new ArrayList(labels.length);
116
			for (int i = 0; i < labels.length; i++) {
139
			for (int i = 0; i < labels.length; i++) {
117
				fContextLabels.add(new Pair(labels[i].getAttribute("mode"), //$NON-NLS-1$
140
				fContextLabels.add(new Pair(labels[i].getAttribute("mode"), //$NON-NLS-1$
Lines 130-176 Link Here
130
	}
153
	}
131
	
154
	
132
	/**
155
	/**
133
	 * Returns the filter class of this shortcut.
134
	 * 
156
	 * 
135
	 * @return the filter class of this shortcut., or <code>null</code> if not
157
	 * @param exp
136
	 *  specified
158
	 * @param context
137
	 */
159
	 * @return
138
	public ILaunchFilter getFilterClass() {
160
	 * @throws CoreException
139
		if (fLaunchFilter == null) {
161
	 */
140
			try {
162
	public boolean evalContextualLaunchEnablementExpression(IEvaluationContext context, Expression exp) throws CoreException {
141
				// The underlying code logs an error if the filterClass is missing,
163
		// return true if result is either TRUE or NOT_LOADED
142
				// even though the attribute is optional, so check for existence first.
164
		// This allows optimistic inclusion of shortcuts before plugins are loaded
143
				if (fConfig.getAttribute("filterClass") != null) { //$NON-NLS-1$
165
		return (exp != null) ? ((exp.evaluate(context)) != EvaluationResult.FALSE) : false;
144
					Object object = fConfig.createExecutableExtension("filterClass"); //$NON-NLS-1$
145
					if (object instanceof ILaunchFilter) {
146
						fLaunchFilter = (ILaunchFilter) object;
147
					}
148
				}
149
			} catch (CoreException e) {
150
				// silently ignore because filterClass is optional
151
				// 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$
152
			}
153
		}
154
		return fLaunchFilter;
155
	}
166
	}
156
	
167
	
157
	/**
168
	/**
158
	 * Returns all of the filter elements of this shortcut as a List of String Pairs.
169
	 * Returns an expression that represents the enablement logic for the
159
	 * 
170
	 * contextual launch element of this launch shortcut description.
160
	 * @return all of the filter elements of this shortcut, or <code>null</code> if not
171
	 * @return an evaluatable expression
161
	 *  specified
172
	 * @throws CoreException if the configuration element can't be
162
	 */
173
	 *  converted. Reasons include: (a) no handler is available to
163
	public /* <Pair> */ List getFilters() {
174
	 *  cope with a certain configuration element or (b) the XML
164
		if (fFilters == null) {
175
	 *  expression tree is malformed.
165
			IConfigurationElement[] filters = getConfigurationElement().getChildren("filter"); //$NON-NLS-1$
176
	 */
166
			fFilters = new ArrayList(filters.length);
177
	public Expression getContextualLaunchEnablementExpression() throws CoreException {
167
			for (int i = 0; i < filters.length; i++) {
178
		// all of this stuff is optional, so...tedius testing is required
168
				fFilters.add(new Pair(filters[i].getAttribute("name"), //$NON-NLS-1$
179
		if (fContextualLaunchExpr == null) {
169
						filters[i].getAttribute("value"))); //$NON-NLS-1$
180
			IConfigurationElement contextualLaunchElement = getContextualLaunchConfigurationElement();
181
			if (contextualLaunchElement == null) {
182
				// not available
183
				return null;
170
			}
184
			}
185
			IConfigurationElement[] elements = contextualLaunchElement.getChildren(ExpressionTagNames.ENABLEMENT);
186
			IConfigurationElement enablement = elements.length > 0 ? elements[0] : null; 
187
188
			if (enablement != null)
189
				fContextualLaunchExpr= ExpressionConverter.getDefault().perform(enablement);
171
		}
190
		}
172
		return fFilters;
191
		return fContextualLaunchExpr;
173
	}
192
	}
193
	
174
	/**
194
	/**
175
	 * Returns the id of this shortcut
195
	 * Returns the id of this shortcut
176
	 * 
196
	 * 
Lines 221-226 Link Here
221
	public ImageDescriptor getImageDescriptor() {
241
	public ImageDescriptor getImageDescriptor() {
222
		if (fImageDescriptor == null) {
242
		if (fImageDescriptor == null) {
223
			String iconPath = getIconPath();
243
			String iconPath = getIconPath();
244
<<<<<<< LaunchShortcutExtension.java
245
			// iconPath may be null becuase imageIcon is now optional in shortcut
246
			if (iconPath != null) {
247
				try {
248
					iconURL = new URL(iconURL, iconPath);
249
					fImageDescriptor = ImageDescriptor.createFromURL(iconURL);
250
				} catch (MalformedURLException e) {
251
					DebugUIPlugin.log(e);
252
				}
253
=======
224
			// iconPath may be null because imageIcon is optional
254
			// iconPath may be null because imageIcon is optional
225
			if (iconPath != null) {
255
			if (iconPath != null) {
226
				try {
256
				try {
Lines 230-235 Link Here
230
				} catch (MalformedURLException e) {
260
				} catch (MalformedURLException e) {
231
					DebugUIPlugin.log(e);
261
					DebugUIPlugin.log(e);
232
				}
262
				}
263
>>>>>>> 1.12
233
			}
264
			}
234
		}
265
		}
235
		return fImageDescriptor;
266
		return fImageDescriptor;
Lines 305-311 Link Here
305
			}
336
			}
306
		}
337
		}
307
		return fModes;
338
		return fModes;
308
	}	
339
	}
309
340
	
341
	/*
342
	 * Only for debugging
343
	 * @see java.lang.Object#toString()
344
	 */
345
	public String toString() {
346
		return getId();
347
	}
310
}
348
}
311
349
(-)ui/org/eclipse/debug/internal/ui/ResourceExtender.java (+57 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 International Business Machines Corp. and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v0.5 
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v05.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
package org.eclipse.debug.internal.ui;
12
13
import org.eclipse.core.expressions.PropertyTester;
14
import org.eclipse.core.resources.IProject;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.runtime.CoreException;
17
18
/**
19
 * ResourceExtender provides property testers for the XML expression
20
 * language evaluation. We provide a copy in Debug so that launch shortcuts
21
 * can add contextual launch enablement that does not require their plugins
22
 * to be loaded.
23
 */
24
public class ResourceExtender extends PropertyTester {
25
26
	private static final String PROPERTY_MATCHES_PATTERN= "matchesPattern";	 //$NON-NLS-1$
27
	private static final String PROJECT_NATURE = "projectNature";	 //$NON-NLS-1$
28
	private static final String CAN_DELETE= "canDelete"; //$NON-NLS-1$
29
	
30
	
31
	public boolean test(Object receiver, String method, Object[] args, Object expectedValue) {
32
		IResource resource= (IResource)receiver;
33
		if (PROPERTY_MATCHES_PATTERN.equals(method)) { //$NON-NLS-1$
34
			String fileName= resource.getName();
35
			StringMatcher matcher= new StringMatcher((String)expectedValue, false, false);
36
			return matcher.match(fileName);
37
		} else if (PROJECT_NATURE.equals(method)) {
38
			try {
39
				IProject proj = resource.getProject();
40
				return proj.isAccessible() && proj.hasNature((String)expectedValue);
41
			} catch (CoreException e) {
42
				return false;		
43
			}
44
		} else if (CAN_DELETE.equals(method)) {
45
			return canDelete(resource);
46
		}
47
		return false;
48
	}
49
	
50
	private boolean canDelete(IResource resource) {
51
		if (!resource.exists() || resource.isPhantom())
52
			return false;
53
		if (resource.getType() == IResource.ROOT || resource.getType() == IResource.PROJECT)
54
			return false;
55
		return true;
56
	}
57
}

Return to bug 54117