|
Lines 30-39
Link Here
|
| 30 |
import org.eclipse.core.runtime.Status; |
30 |
import org.eclipse.core.runtime.Status; |
| 31 |
import org.eclipse.jface.preference.PreferenceNode; |
31 |
import org.eclipse.jface.preference.PreferenceNode; |
| 32 |
import org.eclipse.jface.resource.ImageDescriptor; |
32 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
|
33 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 33 |
import org.eclipse.ui.IActionFilter; |
34 |
import org.eclipse.ui.IActionFilter; |
| 34 |
import org.eclipse.ui.IPluginContribution; |
35 |
import org.eclipse.ui.IPluginContribution; |
| 35 |
import org.eclipse.ui.IWorkbenchPropertyPage; |
36 |
import org.eclipse.ui.IWorkbenchPropertyPage; |
| 36 |
import org.eclipse.ui.SelectionEnabler; |
37 |
import org.eclipse.ui.SelectionEnabler; |
|
|
38 |
import org.eclipse.ui.dialogs.PropertyPage; |
| 37 |
import org.eclipse.ui.internal.IWorkbenchConstants; |
39 |
import org.eclipse.ui.internal.IWorkbenchConstants; |
| 38 |
import org.eclipse.ui.internal.LegacyResourceSupport; |
40 |
import org.eclipse.ui.internal.LegacyResourceSupport; |
| 39 |
import org.eclipse.ui.internal.WorkbenchPlugin; |
41 |
import org.eclipse.ui.internal.WorkbenchPlugin; |
|
Lines 66-71
Link Here
|
| 66 |
|
68 |
|
| 67 |
private boolean adaptable = false; |
69 |
private boolean adaptable = false; |
| 68 |
|
70 |
|
|
|
71 |
/** |
| 72 |
* Flag which indicates if this property page supports multiple selection |
| 73 |
* @since 3.6 |
| 74 |
*/ |
| 75 |
private final boolean supportsMultiSelect; |
| 76 |
|
| 69 |
private IConfigurationElement pageElement; |
77 |
private IConfigurationElement pageElement; |
| 70 |
|
78 |
|
| 71 |
private SoftReference filterProperties; |
79 |
private SoftReference filterProperties; |
|
Lines 88-93
Link Here
|
| 88 |
pageElement |
96 |
pageElement |
| 89 |
.getAttribute(PropertyPagesRegistryReader.ATT_ADAPTABLE)) |
97 |
.getAttribute(PropertyPagesRegistryReader.ATT_ADAPTABLE)) |
| 90 |
.booleanValue(); |
98 |
.booleanValue(); |
|
|
99 |
supportsMultiSelect = Boolean |
| 100 |
.valueOf( |
| 101 |
pageElement |
| 102 |
.getAttribute(PropertyPagesRegistryReader.ATT_MULTIPLE_SELECTION)) |
| 103 |
.booleanValue(); |
| 91 |
initializeEnablement(element); |
104 |
initializeEnablement(element); |
| 92 |
} |
105 |
} |
| 93 |
|
106 |
|
|
Lines 122-142
Link Here
|
| 122 |
|
135 |
|
| 123 |
ppage.setTitle(getPageName()); |
136 |
ppage.setTitle(getPageName()); |
| 124 |
|
137 |
|
| 125 |
Object adapted = element; |
138 |
Object[] elements = getObjects(element); |
| 126 |
if (adaptable) { |
139 |
IAdaptable[] adapt = new IAdaptable[elements.length]; |
| 127 |
adapted = getAdaptedElement(element); |
140 |
|
| 128 |
if (adapted == null) { |
141 |
for (int i = 0; i < elements.length; i++) { |
| 129 |
String message = "Error adapting selection to Property page " + pageId + " is being ignored"; //$NON-NLS-1$ //$NON-NLS-2$ |
142 |
Object adapted = elements[i]; |
| 130 |
throw new CoreException(new Status(IStatus.ERROR, |
143 |
if (adaptable) { |
| 131 |
WorkbenchPlugin.PI_WORKBENCH, IStatus.ERROR, message, |
144 |
adapted = getAdaptedElement(adapted); |
| 132 |
null)); |
145 |
if (adapted == null) { |
|
|
146 |
String message = "Error adapting selection to Property page " + pageId + " is being ignored"; //$NON-NLS-1$ //$NON-NLS-2$ |
| 147 |
throw new CoreException(new Status(IStatus.ERROR, |
| 148 |
WorkbenchPlugin.PI_WORKBENCH, IStatus.ERROR, |
| 149 |
message, null)); |
| 150 |
} |
| 133 |
} |
151 |
} |
|
|
152 |
adapt[i] = (IAdaptable) ((adapted instanceof IAdaptable) ? adapted |
| 153 |
: new AdaptableForwarder(adapted)); |
| 134 |
} |
154 |
} |
| 135 |
|
155 |
|
| 136 |
if (adapted instanceof IAdaptable) |
156 |
if (ppage instanceof PropertyPage) |
| 137 |
ppage.setElement((IAdaptable) adapted); |
157 |
((PropertyPage) ppage).setElements(adapt); |
|
|
158 |
else if (adapt.length > 1) |
| 159 |
// Throw exception - if propertPage supports multipleSelection |
| 160 |
// then it should extend PropertyPage |
| 161 |
throw new CoreException(new Status(IStatus.ERROR, |
| 162 |
WorkbenchPlugin.PI_WORKBENCH, |
| 163 |
IStatus.ERROR, |
| 164 |
"Error: selected element length > 0 but ppage not a PropertyPage", //$NON-NLS-1$ |
| 165 |
null)); |
| 138 |
else |
166 |
else |
| 139 |
ppage.setElement(new AdaptableForwarder(adapted)); |
167 |
ppage.setElement(adapt[0]); |
| 140 |
|
168 |
|
| 141 |
return ppage; |
169 |
return ppage; |
| 142 |
} |
170 |
} |
|
Lines 209-246
Link Here
|
| 209 |
if (failsEnablement(object)) |
237 |
if (failsEnablement(object)) |
| 210 |
return false; |
238 |
return false; |
| 211 |
|
239 |
|
|
|
240 |
Object[] objs = getObjects(object); |
| 241 |
|
| 212 |
// Test name filter |
242 |
// Test name filter |
| 213 |
String nameFilter = pageElement |
243 |
String nameFilter = pageElement |
| 214 |
.getAttribute(PropertyPagesRegistryReader.ATT_NAME_FILTER); |
244 |
.getAttribute(PropertyPagesRegistryReader.ATT_NAME_FILTER); |
| 215 |
if (nameFilter != null) { |
245 |
|
| 216 |
String objectName = object.toString(); |
246 |
for (int i = 0; i < objs.length; i++) { |
| 217 |
IWorkbenchAdapter adapter = (IWorkbenchAdapter) Util.getAdapter(object, |
247 |
object = objs[i]; |
| 218 |
IWorkbenchAdapter.class); |
248 |
if (nameFilter != null) { |
| 219 |
if (adapter != null) { |
249 |
String objectName = object.toString(); |
| 220 |
String elementName = adapter.getLabel(object); |
250 |
IWorkbenchAdapter adapter = (IWorkbenchAdapter) Util |
| 221 |
if (elementName != null) { |
251 |
.getAdapter(object, IWorkbenchAdapter.class); |
| 222 |
objectName = elementName; |
252 |
if (adapter != null) { |
|
|
253 |
String elementName = adapter.getLabel(object); |
| 254 |
if (elementName != null) { |
| 255 |
objectName = elementName; |
| 256 |
} |
| 223 |
} |
257 |
} |
|
|
258 |
if (!SelectionEnabler.verifyNameMatch(objectName, nameFilter)) |
| 259 |
return false; |
| 224 |
} |
260 |
} |
| 225 |
if (!SelectionEnabler.verifyNameMatch(objectName, nameFilter)) |
|
|
| 226 |
return false; |
| 227 |
} |
| 228 |
|
261 |
|
| 229 |
// Test custom filter |
262 |
// Test custom filter |
| 230 |
if (getFilterProperties() == null) |
263 |
if (getFilterProperties() == null) |
| 231 |
return true; |
264 |
return true; |
| 232 |
IActionFilter filter = null; |
265 |
IActionFilter filter = null; |
| 233 |
|
266 |
|
| 234 |
// Do the free IResource adapting |
267 |
// Do the free IResource adapting |
| 235 |
Object adaptedObject = LegacyResourceSupport.getAdaptedResource(object); |
268 |
Object adaptedObject = LegacyResourceSupport |
| 236 |
if (adaptedObject != null) { |
269 |
.getAdaptedResource(object); |
| 237 |
object = adaptedObject; |
270 |
if (adaptedObject != null) { |
| 238 |
} |
271 |
object = adaptedObject; |
|
|
272 |
} |
| 239 |
|
273 |
|
| 240 |
filter = (IActionFilter)Util.getAdapter(object, IActionFilter.class); |
274 |
filter = (IActionFilter) Util.getAdapter(object, |
|
|
275 |
IActionFilter.class); |
| 241 |
|
276 |
|
| 242 |
if (filter != null) |
277 |
if (filter != null && !testCustom(object, filter)) |
| 243 |
return testCustom(object, filter); |
278 |
return false; |
|
|
279 |
} |
| 244 |
|
280 |
|
| 245 |
return true; |
281 |
return true; |
| 246 |
} |
282 |
} |
|
Lines 252-269
Link Here
|
| 252 |
* @return boolean <code>true</code> if it fails the enablement test |
288 |
* @return boolean <code>true</code> if it fails the enablement test |
| 253 |
*/ |
289 |
*/ |
| 254 |
private boolean failsEnablement(Object object) { |
290 |
private boolean failsEnablement(Object object) { |
|
|
291 |
Object[] objs = getObjects(object); |
| 292 |
if (objs.length > 1 && !supportsMultiSelect) |
| 293 |
return true; |
| 255 |
if (enablementExpression == null) |
294 |
if (enablementExpression == null) |
| 256 |
return false; |
295 |
return false; |
| 257 |
try { |
296 |
try { |
| 258 |
EvaluationContext context = new EvaluationContext(null, object); |
297 |
for (int i = 0; i < objs.length; i++) { |
| 259 |
context.setAllowPluginActivation(true); |
298 |
EvaluationContext context = new EvaluationContext(null, objs[i]); |
| 260 |
return enablementExpression.evaluate( |
299 |
context.setAllowPluginActivation(true); |
| 261 |
context).equals( |
300 |
boolean fails = enablementExpression |
| 262 |
EvaluationResult.FALSE); |
301 |
.evaluate(context).equals(EvaluationResult.FALSE); |
|
|
302 |
if (fails) |
| 303 |
return true; |
| 304 |
} |
| 263 |
} catch (CoreException e) { |
305 |
} catch (CoreException e) { |
| 264 |
WorkbenchPlugin.log(e); |
306 |
WorkbenchPlugin.log(e); |
| 265 |
return false; |
|
|
| 266 |
} |
307 |
} |
|
|
308 |
return false; |
| 309 |
} |
| 310 |
|
| 311 |
/** |
| 312 |
* Returns an object array for the passed in object. If the object is an |
| 313 |
* IStructuredSelection, then return its array otherwise return a 1 element |
| 314 |
* Object[] containing the passed in object |
| 315 |
* |
| 316 |
* @param obj |
| 317 |
* @return an object array representing the passed in object |
| 318 |
*/ |
| 319 |
private Object[] getObjects(Object obj) { |
| 320 |
if (obj instanceof IStructuredSelection) |
| 321 |
return ((IStructuredSelection) obj).toArray(); |
| 322 |
return new Object[] { obj }; |
| 267 |
} |
323 |
} |
| 268 |
|
324 |
|
| 269 |
/** |
325 |
/** |
|
Lines 404-409
Link Here
|
| 404 |
} |
460 |
} |
| 405 |
|
461 |
|
| 406 |
/** |
462 |
/** |
|
|
463 |
* @return boolean indicating if this page supports multiple selection |
| 464 |
* @since 3.6 |
| 465 |
*/ |
| 466 |
boolean supportsMultipleSelection() { |
| 467 |
return supportsMultiSelect; |
| 468 |
} |
| 469 |
|
| 470 |
/** |
| 407 |
* @return the configuration element |
471 |
* @return the configuration element |
| 408 |
* @since 3.1 |
472 |
* @since 3.1 |
| 409 |
*/ |
473 |
*/ |