KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > ResourceExtender


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core;
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 import org.eclipse.core.runtime.IAdaptable;
18
19 /**
20  * ResourceExtender provides property testers for the XML expression language
21  * evaluation. We provide a copy in PDE so that launch shortcuts can add
22  * contextual launch enablement that does not require their plugins to be
23  * loaded.
24  */

25 public class ResourceExtender extends PropertyTester {
26
27     private static final String JavaDoc PDE_NATURE = "PluginNature"; //$NON-NLS-1$
28

29     /*
30      * (non-Javadoc)
31      *
32      * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object,
33      * java.lang.String, java.lang.Object[], java.lang.Object)
34      */

35     public boolean test(Object JavaDoc receiver, String JavaDoc method, Object JavaDoc[] args,
36             Object JavaDoc expectedValue) {
37         IResource resource = (IResource) ((IAdaptable) receiver)
38                 .getAdapter(IResource.class);
39         if (resource != null) {
40             if (PDE_NATURE.equals(method)) {
41                 try {
42                     IProject proj = resource.getProject();
43                     return proj.isAccessible()
44                             && proj.hasNature("org.eclipse.pde.PluginNature"); //$NON-NLS-1$
45
} catch (CoreException e) {
46                     return true;
47                 }
48             }
49         }
50         return true;
51     }
52
53 }
54
Popular Tags