Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Weinand2003-08-25 21:53:38 +0000
committerAndre Weinand2003-08-25 21:53:38 +0000
commit2c322db36babbb31e8c2e189dfbe4c8c1dc67738 (patch)
treec42812909a47e6787f98dd0c557bb7253d378128 /bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
parent8aa00f18f3b5e1c53c2aceaa5fd5ee8e8587ec03 (diff)
downloadeclipse.platform.team-2c322db36babbb31e8c2e189dfbe4c8c1dc67738.tar.gz
eclipse.platform.team-2c322db36babbb31e8c2e189dfbe4c8c1dc67738.tar.xz
eclipse.platform.team-2c322db36babbb31e8c2e189dfbe4c8c1dc67738.zip
fixed #39757
Diffstat (limited to 'bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java')
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java46
1 files changed, 33 insertions, 13 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
index 11f9c7828..a31e28cd9 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
@@ -16,6 +16,7 @@ import java.util.*;
import org.eclipse.swt.widgets.*;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.action.IAction;
@@ -100,11 +101,7 @@ public class Utilities {
return widget != null && !widget.isDisposed();
}
- /**
- * Convenience method: extract all <code>IResources</code> from given selection.
- * Never returns null.
- */
- public static IResource[] getResources(ISelection selection) {
+ private static ArrayList internalGetResources(ISelection selection, Class type) {
ArrayList tmp= new ArrayList();
@@ -113,22 +110,45 @@ public class Utilities {
Object[] s= ((IStructuredSelection)selection).toArray();
for (int i= 0; i < s.length; i++) {
+
+ IResource resource= null;
+
Object o= s[i];
- if (o instanceof IResource) {
- tmp.add(o);
- continue;
- }
- if (o instanceof IAdaptable) {
+ if (type.isInstance(o)) {
+ resource= (IResource) o;
+
+ } else if (o instanceof IAdaptable) {
IAdaptable a= (IAdaptable) o;
Object adapter= a.getAdapter(IResource.class);
- if (adapter instanceof IResource)
- tmp.add(adapter);
- continue;
+ if (type.isInstance(adapter))
+ resource= (IResource) adapter;
}
+
+ if (resource != null && resource.isAccessible())
+ tmp.add(resource);
}
}
+
+ return tmp;
+ }
+
+ /**
+ * Convenience method: extract all accessible <code>IResources</code> from given selection.
+ * Never returns null.
+ */
+ public static IResource[] getResources(ISelection selection) {
+ ArrayList tmp= internalGetResources(selection, IResource.class);
return (IResource[]) tmp.toArray(new IResource[tmp.size()]);
}
+
+ /**
+ * Convenience method: extract all accessible <code>IFiles</code> from given selection.
+ * Never returns null.
+ */
+ public static IFile[] getFiles(ISelection selection) {
+ ArrayList tmp= internalGetResources(selection, IFile.class);
+ return (IFile[]) tmp.toArray(new IFile[tmp.size()]);
+ }
public static byte[] readBytes(InputStream in) {
ByteArrayOutputStream bos= new ByteArrayOutputStream();

Back to the top