From fd2bac83e1957a9fb02ff745811137daf62c0c74 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Fri, 11 Jul 2008 00:39:32 +0200 Subject: [PATCH] Create baseclasses for actions and operations on RevObjects Signed-off-by: Robin Rosenberg Signed-off-by: Shawn O. Pearce --- .../internal/actions/AbstractOperationAction.java | 15 ++++++++----- .../internal/actions/AbstractRevObjectAction.java | 26 ++++++++++++++++++++++ .../actions/AbstractRevObjectOperation.java | 21 +++++++++++++++++ 3 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/AbstractRevObjectAction.java create mode 100644 org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/AbstractRevObjectOperation.java diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/AbstractOperationAction.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/AbstractOperationAction.java index be6d0d59..52f60f52 100644 --- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/AbstractOperationAction.java +++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/AbstractOperationAction.java @@ -32,11 +32,20 @@ import org.spearce.egit.ui.UIText; * Common functionality for EGit operations. */ public abstract class AbstractOperationAction implements IObjectActionDelegate { - private IWorkbenchPart wp; + /** + * The active workbench part + */ + protected IWorkbenchPart wp; private IWorkspaceRunnable op; public void selectionChanged(final IAction act, final ISelection sel) { + // work performed in setActivePart + } + + public void setActivePart(final IAction act, final IWorkbenchPart part) { + wp = part; + ISelection sel = part.getSite().getPage().getSelection(); final List selection; if (sel instanceof IStructuredSelection && !sel.isEmpty()) { selection = ((IStructuredSelection) sel).toList(); @@ -47,10 +56,6 @@ public abstract class AbstractOperationAction implements IObjectActionDelegate { act.setEnabled(op != null && wp != null); } - public void setActivePart(final IAction act, final IWorkbenchPart part) { - wp = part; - } - /** * Instantiate an operation on an action on provided objects. * diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/AbstractRevObjectAction.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/AbstractRevObjectAction.java new file mode 100644 index 00000000..b7f42854 --- /dev/null +++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/AbstractRevObjectAction.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (C) 2008, Robin Rosenberg + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * See LICENSE for the full license text, also available. + *******************************************************************************/ +package org.spearce.egit.ui.internal.actions; + +import org.spearce.egit.ui.internal.history.RevObjectSelectionProvider; +import org.spearce.jgit.lib.Repository; + +abstract class AbstractRevObjectAction extends AbstractOperationAction { + + /** + * Find out which repository is involved here + * + * @return the Git repository associated with the selected RevObject + */ + protected Repository getActiveRepository() { + RevObjectSelectionProvider selectionProvider = (RevObjectSelectionProvider) wp + .getSite().getSelectionProvider(); + return selectionProvider.getActiveRepository(); + } + +} diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/AbstractRevObjectOperation.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/AbstractRevObjectOperation.java new file mode 100644 index 00000000..0c5d570a --- /dev/null +++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/AbstractRevObjectOperation.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (C) 2008, Robin Rosenberg + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * See LICENSE for the full license text, also available. + *******************************************************************************/ +package org.spearce.egit.ui.internal.actions; + +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.spearce.jgit.lib.Repository; + +abstract class AbstractRevObjectOperation implements IWorkspaceRunnable { + + Repository repository; + + AbstractRevObjectOperation(final Repository repository) { + this.repository = repository; + } + +} -- 2.11.4.GIT