diff options
author | Jared Burns | 2004-05-04 00:03:29 +0000 |
---|---|---|
committer | Jared Burns | 2004-05-04 00:03:29 +0000 |
commit | 56aba18d545e54048920ff8139d86d3f7b729d28 (patch) | |
tree | 921f98e167a92664e07d2691dc9c1e62582f0931 /org.eclipse.debug.ui/ui | |
parent | 2b0ccede68c767790e6720e09ccf1d259e76b6fd (diff) | |
download | eclipse.platform.debug-56aba18d545e54048920ff8139d86d3f7b729d28.tar.gz eclipse.platform.debug-56aba18d545e54048920ff8139d86d3f7b729d28.tar.xz eclipse.platform.debug-56aba18d545e54048920ff8139d86d3f7b729d28.zip |
Bug 60838 - Support matchesContentType property test
Diffstat (limited to 'org.eclipse.debug.ui/ui')
-rw-r--r-- | org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ResourceExtender.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ResourceExtender.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ResourceExtender.java index 7b588cbe3..368975471 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ResourceExtender.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ResourceExtender.java @@ -11,9 +11,12 @@ package org.eclipse.debug.internal.ui; import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.content.IContentDescription; +import org.eclipse.core.runtime.content.IContentType; /** * ResourceExtender provides property testers for the XML expression @@ -27,6 +30,7 @@ public class ResourceExtender extends PropertyTester { private static final String PROPERTY_MATCHES_PATTERN= "matchesPattern"; //$NON-NLS-1$ private static final String PROJECT_NATURE = "projectNature"; //$NON-NLS-1$ private static final String CAN_DELETE= "canDelete"; //$NON-NLS-1$ + private static final String PROPERTY_MATCHES_CONTENT_TYPE= "matchesContentType"; //$NON-NLS-1$ /* (non-Javadoc) * @see org.eclipse.jdt.internal.corext.refactoring.participants.properties.IPropertyEvaluator#test(java.lang.Object, java.lang.String, java.lang.String) @@ -46,6 +50,34 @@ public class ResourceExtender extends PropertyTester { } } else if (CAN_DELETE.equals(method)) { return canDelete(resource); + } else if (PROPERTY_MATCHES_CONTENT_TYPE.equals(method)) { + return matchesContentType(resource, (String) expectedValue); + } + return false; + } + + /** + * Returns whether or not the given file's content type matches + * the specified content type. + * + * Content types are looked up in the content type registry. + * + * @return whether or not the given resource has the given content type + */ + private boolean matchesContentType(IResource resource, String contentType) { + if (resource == null || !(resource instanceof IFile) || !resource.exists()) { + return false; + } + IFile file= (IFile) resource; + IContentDescription description; + try { + description = file.getContentDescription(); + } catch (CoreException e) { + return false; + } + if (description != null) { + IContentType type= description.getContentType(); + return contentType.equals(type.getId()); } return false; } |