Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/PessimisticProviderAction.java')
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/PessimisticProviderAction.java68
1 files changed, 35 insertions, 33 deletions
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/PessimisticProviderAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/PessimisticProviderAction.java
index 0c1b79a27..82258ab42 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/PessimisticProviderAction.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/PessimisticProviderAction.java
@@ -14,9 +14,16 @@
package org.eclipse.team.examples.pessimistic.ui;
import java.lang.reflect.InvocationTargetException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
-import org.eclipse.core.resources.*;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.IAction;
@@ -37,7 +44,7 @@ import org.eclipse.ui.IWorkbenchPart;
* Provides convenience methods an abstractions.
*/
public abstract class PessimisticProviderAction
- implements IObjectActionDelegate {
+implements IObjectActionDelegate {
/*
* The current selection.
@@ -48,31 +55,27 @@ public abstract class PessimisticProviderAction
*/
protected Shell fShell;
- /*
- * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
- */
+ @Override
public void selectionChanged(IAction action, ISelection selection) {
fSelection = selection;
-
+
boolean enabled= action.isEnabled();
if (enabled != checkEnablement()) {
action.setEnabled(!enabled);
}
}
-
- /*
- * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
- */
+
+ @Override
public void setActivePart(IAction action, IWorkbenchPart part) {
fShell= part.getSite().getShell();
- }
+ }
/**
* Answers <code>true</code> if this action should be enabled
* for the given <code>resource</code>.
*/
protected abstract boolean shouldEnableFor(IResource resource);
-
+
/*
* Checks to see if this action should be enabled.
*/
@@ -89,26 +92,26 @@ public abstract class PessimisticProviderAction
}
return enabled;
}
-
+
/**
* Convenience method to get an array of resources from the selection.
*/
protected IResource[] getSelectedResources() {
- ArrayList resources = null;
+ ArrayList<IResource> resources = null;
if (!fSelection.isEmpty()) {
- resources = new ArrayList();
+ resources = new ArrayList<>();
Iterator elements = ((IStructuredSelection) fSelection).iterator();
while (elements.hasNext()) {
Object next = elements.next();
if (next instanceof IResource) {
- resources.add(next);
+ resources.add((IResource) next);
continue;
}
if (next instanceof IAdaptable) {
IAdaptable a = (IAdaptable) next;
Object adapter = a.getAdapter(IResource.class);
if (adapter instanceof IResource) {
- resources.add(adapter);
+ resources.add((IResource) adapter);
continue;
}
}
@@ -119,9 +122,9 @@ public abstract class PessimisticProviderAction
resources.toArray(result);
return result;
}
- return new IResource[0];
+ return new IResource[0];
}
-
+
/**
* Convenience method which answers <code>true</code> if the
* resource is controlled by a <code>PessimisticFilesystemProvider</code>.
@@ -132,7 +135,7 @@ public abstract class PessimisticProviderAction
return false;
return provider.isControlled(resource);
}
-
+
/**
* Convenience method which answers <code>true</code> if and only if the
* resource is controlled by a <code>PessimisticFilesystemProvider</code>
@@ -159,7 +162,7 @@ public abstract class PessimisticProviderAction
/**
* Convenience method which answers the <code>PessimisticFilesystemProvider</code>
- * for the given <code>resource</code> or <code>null</code> if the
+ * for the given <code>resource</code> or <code>null</code> if the
* <code>resource</code> is not associated with a <code>PessimisticFilesystemProvider</code>.
*/
protected PessimisticFilesystemProvider getProvider(IResource resource) {
@@ -177,7 +180,7 @@ public abstract class PessimisticProviderAction
* Convenience method which walks a resource tree and collects the
* resources that this action would enable for.
*/
- protected void recursivelyAdd(IResource resource, Set resources) {
+ protected void recursivelyAdd(IResource resource, Set<IResource> resources) {
if (isControlled(resource) && !isIgnored(resource)) {
if (shouldEnableFor(resource)) {
resources.add(resource);
@@ -192,27 +195,26 @@ public abstract class PessimisticProviderAction
PessimisticFilesystemProviderPlugin.getInstance().logError(e, "Exception traversing members");
}
if (members != null) {
- for (int i = 0; i < members.length; i++) {
- recursivelyAdd(members[i], resources);
+ for (IResource member : members) {
+ recursivelyAdd(member, resources);
}
}
}
- }
+ }
}
/**
* Convenience method which sorts the given <code>resources</code>
* into a map of IProject -> Set of IResource objects.
*/
- protected Map sortByProject(Set resources) {
- Map byProject= new HashMap();
+ protected Map<IProject, Set<IResource>> sortByProject(Set<IResource> resources) {
+ Map<IProject, Set<IResource>> byProject = new HashMap<>();
if (resources != null) {
- for (Iterator i= resources.iterator(); i.hasNext();) {
- IResource resource= (IResource) i.next();
+ for (IResource resource : resources) {
IProject project= resource.getProject();
- Set set= (Set)byProject.get(project);
+ Set<IResource> set = byProject.get(project);
if (set == null) {
- set= new HashSet(1);
+ set = new HashSet<>(1);
byProject.put(project, set);
}
set.add(resource);
@@ -220,7 +222,7 @@ public abstract class PessimisticProviderAction
}
return byProject;
}
-
+
/**
* Convenience method for displaying runnable progress
* with a <code>ProgressMonitorDialog</code>.

Back to the top