KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > participants > ResourceExtender


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.jdt.internal.corext.refactoring.participants;
12
13 import org.eclipse.core.runtime.Assert;
14 import org.eclipse.core.runtime.CoreException;
15
16 import org.eclipse.core.resources.IProject;
17 import org.eclipse.core.resources.IResource;
18
19 import org.eclipse.core.expressions.PropertyTester;
20
21
22 import org.eclipse.jdt.internal.ui.util.StringMatcher;
23
24
25 public class ResourceExtender extends PropertyTester {
26
27     private static final String JavaDoc PROPERTY_MATCHES_PATTERN= "matchesPattern"; //$NON-NLS-1$
28
private static final String JavaDoc PROJECT_NATURE = "projectNature"; //$NON-NLS-1$
29
private static final String JavaDoc CAN_DELETE= "canDelete"; //$NON-NLS-1$
30

31     /* (non-Javadoc)
32      * @see org.eclipse.jdt.internal.corext.refactoring.participants.properties.IPropertyEvaluator#test(java.lang.Object, java.lang.String, java.lang.String)
33      */

34     public boolean test(Object JavaDoc receiver, String JavaDoc method, Object JavaDoc[] args, Object JavaDoc expectedValue) {
35         IResource resource= (IResource)receiver;
36         if (PROPERTY_MATCHES_PATTERN.equals(method)) {
37             String JavaDoc fileName= resource.getName();
38             StringMatcher matcher= new StringMatcher((String JavaDoc)expectedValue, false, false);
39             return matcher.match(fileName);
40         } else if (PROJECT_NATURE.equals(method)) {
41             try {
42                 IProject proj = resource.getProject();
43                 return proj.isAccessible() && proj.hasNature((String JavaDoc)expectedValue);
44             } catch (CoreException e) {
45                 return false;
46             }
47         } else if (CAN_DELETE.equals(method)) {
48             return canDelete(resource);
49         }
50         Assert.isTrue(false);
51         return false;
52     }
53     
54     private boolean canDelete(IResource resource) {
55         if (!resource.exists() || resource.isPhantom())
56             return false;
57         if (resource.getType() == IResource.ROOT || resource.getType() == IResource.PROJECT)
58             return false;
59         return true;
60     }
61 }
62
Popular Tags