Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Baumgart2010-08-19 11:43:33 +0000
committerJens Baumgart2010-08-19 11:43:33 +0000
commit25add621623a5eb15c26bd623510e862b1ef2b2f (patch)
tree084162826ba86e1f66a6b7f171ac433bd4976eb5
parent4786efe5c5e6aad165f11b2dd72b7dc7f3758e94 (diff)
downloadegit-25add621623a5eb15c26bd623510e862b1ef2b2f.tar.gz
egit-25add621623a5eb15c26bd623510e862b1ef2b2f.tar.xz
egit-25add621623a5eb15c26bd623510e862b1ef2b2f.zip
Fix ClassCastException exception in isEnabled
Code was refactored in order to retrieve the selection in a robust way for the isEnabled methods of the team handlers. Bug: 322722 Bug: 322963 Change-Id: Iad49fd3335a225da00850ff0a03514584960898d Signed-off-by: Jens Baumgart <jens.baumgart@sap.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/BranchActionHandler.java7
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java7
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithHeadActionHandler.java21
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithIndexActionHandler.java21
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithRevisionActionHandler.java8
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/DiscardChangesActionHandler.java24
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/FetchActionHandler.java7
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/IgnoreActionHandler.java25
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeActionHandler.java7
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/PushActionHandler.java7
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/RepositoryActionHandler.java169
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetActionHandler.java7
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/TagActionHandler.java7
13 files changed, 172 insertions, 145 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/BranchActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/BranchActionHandler.java
index 99ed3572c6..1fe4b1892a 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/BranchActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/BranchActionHandler.java
@@ -77,11 +77,6 @@ public class BranchActionHandler extends RepositoryActionHandler {
@Override
public boolean isEnabled() {
- try {
- return getRepository(false, null) != null;
- } catch (ExecutionException e) {
- Activator.handleError(e.getMessage(), e, false);
- return false;
- }
+ return getRepository() != null;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java
index 9321f31ba1..de831b0bbe 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java
@@ -337,12 +337,7 @@ public class CommitActionHandler extends RepositoryActionHandler {
@Override
public boolean isEnabled() {
- try {
- return getProjectsInRepositoryOfSelectedResources(null).length > 0;
- } catch (ExecutionException e) {
- Activator.handleError(e.getMessage(), e, false);
- return false;
- }
+ return getProjectsInRepositoryOfSelectedResources().length > 0;
}
private String getMergeResolveMessage(Repository mergeRepository,
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithHeadActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithHeadActionHandler.java
index ecd24b86ac..521672e061 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithHeadActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithHeadActionHandler.java
@@ -65,22 +65,17 @@ public class CompareWithHeadActionHandler extends RepositoryActionHandler {
@Override
public boolean isEnabled() {
- try {
- final IResource[] selectedResources = getSelectedResources(null);
- if (selectedResources.length != 1)
- return false;
+ final IResource[] selectedResources = getSelectedResources();
+ if (selectedResources.length != 1)
+ return false;
- final IResource resource = selectedResources[0];
- if (!(resource instanceof IFile)) {
- return false;
- }
- final RepositoryMapping mapping = RepositoryMapping
- .getMapping(resource.getProject());
- return mapping != null;
- } catch (ExecutionException e) {
- Activator.handleError(e.getMessage(), e, false);
+ final IResource resource = selectedResources[0];
+ if (!(resource instanceof IFile)) {
return false;
}
+ final RepositoryMapping mapping = RepositoryMapping.getMapping(resource
+ .getProject());
+ return mapping != null;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithIndexActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithIndexActionHandler.java
index febe47358f..a6058e68ae 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithIndexActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithIndexActionHandler.java
@@ -102,22 +102,17 @@ public class CompareWithIndexActionHandler extends RepositoryActionHandler {
@Override
public boolean isEnabled() {
- try {
- final IResource[] selectedResources = getSelectedResources(null);
- if (selectedResources.length != 1)
- return false;
+ final IResource[] selectedResources = getSelectedResources();
+ if (selectedResources.length != 1)
+ return false;
- final IResource resource = selectedResources[0];
- if (!(resource instanceof IFile)) {
- return false;
- }
- final RepositoryMapping mapping = RepositoryMapping
- .getMapping(resource.getProject());
- return mapping != null;
- } catch (ExecutionException e) {
- Activator.handleError(e.getMessage(), e, false);
+ final IResource resource = selectedResources[0];
+ if (!(resource instanceof IFile)) {
return false;
}
+ final RepositoryMapping mapping = RepositoryMapping.getMapping(resource
+ .getProject());
+ return mapping != null;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithRevisionActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithRevisionActionHandler.java
index 1a7f48ccf9..3e84890baf 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithRevisionActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CompareWithRevisionActionHandler.java
@@ -12,7 +12,6 @@ package org.eclipse.egit.ui.internal.actions;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.internal.history.GitHistoryPage;
import org.eclipse.team.ui.TeamUI;
import org.eclipse.team.ui.history.IHistoryPage;
@@ -37,11 +36,6 @@ public class CompareWithRevisionActionHandler extends RepositoryActionHandler {
}
public boolean isEnabled() {
- try {
- return !getSelection(null).isEmpty();
- } catch (ExecutionException e) {
- Activator.handleError(e.getMessage(), e, false);
- return false;
- }
+ return !getSelection().isEmpty();
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/DiscardChangesActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/DiscardChangesActionHandler.java
index e62c6693bb..c892eadeb0 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/DiscardChangesActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/DiscardChangesActionHandler.java
@@ -59,23 +59,17 @@ public class DiscardChangesActionHandler extends RepositoryActionHandler {
@Override
public boolean isEnabled() {
- try {
- for (IResource res : getSelectedResources(null)) {
- IProject[] proj = new IProject[] { res.getProject() };
- Repository[] repositories = getRepositoriesFor(proj);
- if (repositories.length == 0)
- return false;
- Repository repository = repositories[0];
- if (!repository.getRepositoryState().equals(
- RepositoryState.SAFE)) {
- return false;
- }
+ for (IResource res : getSelectedResources()) {
+ IProject[] proj = new IProject[] { res.getProject() };
+ Repository[] repositories = getRepositoriesFor(proj);
+ if (repositories.length == 0)
+ return false;
+ Repository repository = repositories[0];
+ if (!repository.getRepositoryState().equals(RepositoryState.SAFE)) {
+ return false;
}
- return true;
- } catch (ExecutionException e) {
- Activator.handleError(e.getMessage(), e, false);
- return false;
}
+ return true;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/FetchActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/FetchActionHandler.java
index ba1e0eedb3..a4537f8d3f 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/FetchActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/FetchActionHandler.java
@@ -48,11 +48,6 @@ public class FetchActionHandler extends RepositoryActionHandler {
}
public boolean isEnabled() {
- try {
- return getRepository(false, null) != null;
- } catch (ExecutionException e) {
- Activator.handleError(e.getMessage(), e, false);
- return false;
- }
+ return getRepository() != null;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/IgnoreActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/IgnoreActionHandler.java
index b549300605..04ee74dda7 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/IgnoreActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/IgnoreActionHandler.java
@@ -53,22 +53,17 @@ public class IgnoreActionHandler extends RepositoryActionHandler {
@Override
public boolean isEnabled() {
- try {
- if (getProjectsInRepositoryOfSelectedResources(null).length == 0)
- return false;
-
- IResource[] resources = getSelectedResources(null);
- for (IResource resource : resources) {
- // NB This does the same thing in DecoratableResourceAdapter,
- // but
- // neither currently consult .gitignore
- if (!Team.isIgnoredHint(resource))
- return true;
- }
- return false;
- } catch (ExecutionException e) {
- Activator.handleError(e.getMessage(), e, false);
+ if (getProjectsInRepositoryOfSelectedResources().length == 0)
return false;
+
+ IResource[] resources = getSelectedResources();
+ for (IResource resource : resources) {
+ // NB This does the same thing in DecoratableResourceAdapter,
+ // but
+ // neither currently consult .gitignore
+ if (!Team.isIgnoredHint(resource))
+ return true;
}
+ return false;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeActionHandler.java
index cce9afbc76..0dbce0f177 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeActionHandler.java
@@ -140,12 +140,7 @@ public class MergeActionHandler extends RepositoryActionHandler {
@Override
public boolean isEnabled() {
- try {
- return getRepository(false, null) != null;
- } catch (ExecutionException e) {
- Activator.handleError(e.getMessage(), e, false);
- return false;
- }
+ return getRepository() != null;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/PushActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/PushActionHandler.java
index ab51d0dc26..5133457360 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/PushActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/PushActionHandler.java
@@ -49,11 +49,6 @@ public class PushActionHandler extends RepositoryActionHandler {
@Override
public boolean isEnabled() {
- try {
- return getRepository(false, null) != null;
- } catch (ExecutionException e) {
- Activator.handleError(e.getMessage(), e, false);
- return false;
- }
+ return getRepository() != null;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/RepositoryActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/RepositoryActionHandler.java
index fd18db5142..db25af8c2d 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/RepositoryActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/RepositoryActionHandler.java
@@ -36,10 +36,8 @@ import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.Tag;
-import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.team.ui.history.IHistoryView;
import org.eclipse.ui.ISources;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
@@ -54,20 +52,30 @@ import org.eclipse.ui.handlers.IHandlerService;
abstract class RepositoryActionHandler extends AbstractHandler {
/**
- * @param event
+ * @param selection
* @return the projects hosting the selected resources
- * @throws ExecutionException
*/
- protected IProject[] getProjectsForSelectedResources(ExecutionEvent event)
- throws ExecutionException {
+ private IProject[] getProjectsForSelectedResources(IStructuredSelection selection) {
Set<IProject> ret = new HashSet<IProject>();
for (IResource resource : (IResource[]) getSelectedAdaptables(
- getSelection(event), IResource.class, event))
+ selection, IResource.class))
ret.add(resource.getProject());
return ret.toArray(new IProject[ret.size()]);
}
/**
+ * @param event
+ * @return the projects hosting the selected resources
+ * @throws ExecutionException
+ */
+ protected IProject[] getProjectsForSelectedResources(ExecutionEvent event)
+ throws ExecutionException {
+ IStructuredSelection selection = getSelection(event);
+ return getProjectsForSelectedResources(selection);
+ }
+
+
+ /**
* @param projects
* a list of projects
* @return the repositories that projects map to iff all projects are mapped
@@ -95,8 +103,34 @@ abstract class RepositoryActionHandler extends AbstractHandler {
*/
protected IProject[] getProjectsInRepositoryOfSelectedResources(
ExecutionEvent event) throws ExecutionException {
+ IStructuredSelection selection = getSelection(event);
+ return getProjectsInRepositoryOfSelectedResources(selection);
+ }
+
+ /**
+ * List the projects with selected resources, if all projects are connected
+ * to a Git repository.
+ *
+ * @return the tracked projects affected by the current resource selection
+ */
+ protected IProject[] getProjectsInRepositoryOfSelectedResources() {
+ IStructuredSelection selection = getSelection();
+ return getProjectsInRepositoryOfSelectedResources(selection);
+ }
+
+
+ /**
+ * List the projects with selected resources, if all projects are connected
+ * to a Git repository.
+ *
+ * @param selection
+ *
+ * @return the tracked projects affected by the current resource selection
+ */
+ private IProject[] getProjectsInRepositoryOfSelectedResources(
+ IStructuredSelection selection) {
Set<IProject> ret = new HashSet<IProject>();
- Repository[] repositories = getRepositoriesFor(getProjectsForSelectedResources(event));
+ Repository[] repositories = getRepositoriesFor(getProjectsForSelectedResources(selection));
final IProject[] projects = ResourcesPlugin.getWorkspace().getRoot()
.getProjects();
for (IProject project : projects) {
@@ -111,6 +145,7 @@ abstract class RepositoryActionHandler extends AbstractHandler {
return ret.toArray(new IProject[ret.size()]);
}
+
/**
* Figure out which repository to use. All selected resources must map to
* the same Git repository.
@@ -124,8 +159,37 @@ abstract class RepositoryActionHandler extends AbstractHandler {
*/
protected Repository getRepository(boolean warn, ExecutionEvent event)
throws ExecutionException {
+ IStructuredSelection selection = getSelection(event);
+ Shell shell = getShell(event);
+ return getRepository(warn, selection, shell);
+ }
+
+ /**
+ * Figure out which repository to use. All selected resources must map to
+ * the same Git repository.
+ *
+ * @return repository for current project, or null
+ */
+ protected Repository getRepository() {
+ IStructuredSelection selection = getSelection();
+ return getRepository(false, selection, null);
+ }
+
+ /**
+ * Figure out which repository to use. All selected resources must map to
+ * the same Git repository.
+ *
+ * @param warn
+ * Put up a message dialog to warn why a resource was not
+ * selected
+ * @param selection
+ * @param shell
+ * must be provided if warn = true
+ * @return repository for current project, or null
+ */
+ private Repository getRepository(boolean warn, IStructuredSelection selection, Shell shell) {
RepositoryMapping mapping = null;
- for (IProject project : getSelectedProjects(event)) {
+ for (IProject project : getSelectedProjects(selection)) {
RepositoryMapping repositoryMapping = RepositoryMapping
.getMapping(project);
if (mapping == null)
@@ -134,7 +198,7 @@ abstract class RepositoryActionHandler extends AbstractHandler {
return null;
if (mapping.getRepository() != repositoryMapping.getRepository()) {
if (warn)
- MessageDialog.openError(getShell(event),
+ MessageDialog.openError(shell,
UIText.RepositoryAction_multiRepoSelectionTitle,
UIText.RepositoryAction_multiRepoSelection);
return null;
@@ -142,7 +206,7 @@ abstract class RepositoryActionHandler extends AbstractHandler {
}
if (mapping == null) {
if (warn)
- MessageDialog.openError(getShell(event),
+ MessageDialog.openError(shell,
UIText.RepositoryAction_errorFindingRepoTitle,
UIText.RepositoryAction_errorFindingRepo);
return null;
@@ -152,6 +216,9 @@ abstract class RepositoryActionHandler extends AbstractHandler {
return repository;
}
+
+
+
/**
* Figure out which repositories to use. All selected resources must map to
* a Git repository.
@@ -177,31 +244,38 @@ abstract class RepositoryActionHandler extends AbstractHandler {
/**
* @param event
- * the execution event, may be null
+ * the execution event, must not be null
* @return the current selection
* @throws ExecutionException
* if the selection can't be determined
*/
protected IStructuredSelection getSelection(ExecutionEvent event)
throws ExecutionException {
+ if (event == null)
+ throw new IllegalArgumentException("event must not be NULL"); //$NON-NLS-1$
ISelection selection;
- if (event != null)
- selection = HandlerUtil.getCurrentSelectionChecked(event);
- else {
- IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- if (activeWorkbenchWindow == null) // During Eclipse shutdown there is no active window
- return new StructuredSelection();
- IHandlerService hsr = (IHandlerService) activeWorkbenchWindow.getService(IHandlerService.class);
- IEvaluationContext ctx = hsr.getCurrentState();
- selection = (ISelection) ctx.getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
- if (selection == null)
- throw new ExecutionException(
- UIText.RepositoryActionHandler_CouldNotGetSelection_message);
+ selection = HandlerUtil.getCurrentSelectionChecked(event);
+ if (selection instanceof IStructuredSelection)
+ return (IStructuredSelection) selection;
+ return StructuredSelection.EMPTY;
+ }
- }
+ /**
+ * @return the current selection
+ */
+ protected IStructuredSelection getSelection() {
+ IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow();
+ if (activeWorkbenchWindow == null) // During Eclipse shutdown there is
+ // no active window
+ return StructuredSelection.EMPTY;
+ IHandlerService hsr = (IHandlerService) activeWorkbenchWindow
+ .getService(IHandlerService.class);
+ IEvaluationContext ctx = hsr.getCurrentState();
+ Object selection = ctx.getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
if (selection instanceof IStructuredSelection)
return (IStructuredSelection) selection;
- return new StructuredSelection();
+ return StructuredSelection.EMPTY;
}
/**
@@ -210,19 +284,16 @@ abstract class RepositoryActionHandler extends AbstractHandler {
*
* @param selection
* @param c
- * @param event
* @return the selected adaptables
- * @throws ExecutionException
*/
@SuppressWarnings("unchecked")
- protected Object[] getSelectedAdaptables(ISelection selection, Class c,
- ExecutionEvent event) throws ExecutionException {
+ private Object[] getSelectedAdaptables(ISelection selection, Class c) {
ArrayList result = null;
if (selection != null && !selection.isEmpty()) {
result = new ArrayList();
Iterator elements = ((IStructuredSelection) selection).iterator();
while (elements.hasNext()) {
- Object adapter = getAdapter(elements.next(), c, event);
+ Object adapter = getAdapter(elements.next(), c);
if (c.isInstance(adapter)) {
result.add(adapter);
}
@@ -235,8 +306,7 @@ abstract class RepositoryActionHandler extends AbstractHandler {
return (Object[]) Array.newInstance(c, 0);
}
- private Object getAdapter(Object adaptable, Class c, ExecutionEvent event)
- throws ExecutionException {
+ private Object getAdapter(Object adaptable, Class c) {
if (c.isInstance(adaptable)) {
return adaptable;
}
@@ -247,16 +317,17 @@ abstract class RepositoryActionHandler extends AbstractHandler {
return adapter;
}
}
- if (adaptable instanceof RevCommit) {
- IHistoryView view = (IHistoryView) getPart(event);
- return getAdapter(view.getHistoryPage().getInput(), c, event);
- }
return null;
}
private IProject[] getSelectedProjects(ExecutionEvent event)
throws ExecutionException {
- IResource[] selectedResources = getSelectedResources(event);
+ IStructuredSelection selection = getSelection(event);
+ return getSelectedProjects(selection);
+ }
+
+ private IProject[] getSelectedProjects(IStructuredSelection selection) {
+ IResource[] selectedResources = getSelectedResources(selection);
if (selectedResources.length == 0)
return new IProject[0];
ArrayList<IProject> projects = new ArrayList<IProject>();
@@ -276,15 +347,33 @@ abstract class RepositoryActionHandler extends AbstractHandler {
*/
protected IResource[] getSelectedResources(ExecutionEvent event)
throws ExecutionException {
+ IStructuredSelection selection = getSelection(event);
+ return getSelectedResources(selection);
+ }
+
+ /**
+ * @return the resources in the selection
+ */
+ protected IResource[] getSelectedResources() {
+ IStructuredSelection selection = getSelection();
+ return getSelectedResources(selection);
+ }
+
+ /**
+ * @param selection
+ * @return the resources in the selection
+ */
+ private IResource[] getSelectedResources(IStructuredSelection selection) {
Set<IResource> result = new HashSet<IResource>();
- for (Object o : getSelection(event).toList()) {
- IResource resource = (IResource) getAdapter(o, IResource.class, event);
+ for (Object o : selection.toList()) {
+ IResource resource = (IResource) getAdapter(o, IResource.class);
if (resource != null)
result.add(resource);
}
return result.toArray(new IResource[result.size()]);
}
+
/**
* @param event
* @return the shell
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetActionHandler.java
index 055e430910..0f51288ab8 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetActionHandler.java
@@ -76,11 +76,6 @@ public class ResetActionHandler extends RepositoryActionHandler {
@Override
public boolean isEnabled() {
- try {
- return getRepository(false, null) != null;
- } catch (ExecutionException e) {
- Activator.handleError(e.getMessage(), e, false);
- return false;
- }
+ return getRepository() != null;
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/TagActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/TagActionHandler.java
index 771978b4fb..83b16f1bf0 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/TagActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/TagActionHandler.java
@@ -128,12 +128,7 @@ public class TagActionHandler extends RepositoryActionHandler {
@Override
public boolean isEnabled() {
- try {
- return getRepository(false, null) != null;
- } catch (ExecutionException e) {
- Activator.handleError(e.getMessage(), e, false);
- return false;
- }
+ return getRepository() != null;
}
private RevWalk getRevCommits(ExecutionEvent event)

Back to the top