Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2006-01-18 15:08:07 +0000
committerMichael Valenta2006-01-18 15:08:07 +0000
commitbb1d3ca1a48d5ffaa3232904c177044fe56f5b1b (patch)
tree8a96055e69a708ab8114de6f3f14cc43b46ff484
parentcbd85c44148c1db023872f98b53042df75ae2d71 (diff)
downloadeclipse.platform.team-bb1d3ca1a48d5ffaa3232904c177044fe56f5b1b.tar.gz
eclipse.platform.team-bb1d3ca1a48d5ffaa3232904c177044fe56f5b1b.tar.xz
eclipse.platform.team-bb1d3ca1a48d5ffaa3232904c177044fe56f5b1b.zip
Got it working
-rw-r--r--bundles/org.eclipse.team.ui/plugin.xml3
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/CommonMenuManager.java4
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/CommonViewerAdvisor.java9
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/MarkAsMergedAction.java3
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/MergeAction.java3
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/MergeActionHandler.java30
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceMarkAsMergedHandler.java127
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceMergeHandler.java77
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceModelActionProvider.java36
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceModelProviderOperation.java26
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/SynchronizationAction.java77
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/SynchronizationActionHandler.java132
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/mapping/ModelProviderOperation.java8
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/mapping/SynchronizationActionProvider.java (renamed from bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/mapping/SynchronizationActionGroup.java)32
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ModelSynchronizeParticipant.java146
15 files changed, 512 insertions, 201 deletions
diff --git a/bundles/org.eclipse.team.ui/plugin.xml b/bundles/org.eclipse.team.ui/plugin.xml
index 2f64c0d4f..1cfa61360 100644
--- a/bundles/org.eclipse.team.ui/plugin.xml
+++ b/bundles/org.eclipse.team.ui/plugin.xml
@@ -347,7 +347,7 @@
contentProvider="org.eclipse.team.internal.ui.mapping.ResourceTeamAwareContentProvider"
id="org.eclipse.team.ui.resourceContent"
labelProvider="org.eclipse.team.internal.ui.mapping.ResourceModelLabelProvider"
- name="Resource Mappings"
+ name="Resources Team Content"
sorter="org.eclipse.team.internal.ui.mapping.ResourceModelSorter">
<enablement>
<or>
@@ -357,6 +357,7 @@
<instanceof value="org.eclipse.team.core.mapping.ISynchronizationContext"/>
</or>
</enablement>
+ <actionProvider class="org.eclipse.team.internal.ui.mapping.ResourceModelActionProvider"/>
</navigatorContent>
</extension>
<extension
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/CommonMenuManager.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/CommonMenuManager.java
index a19c82ff8..b0e13fa3d 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/CommonMenuManager.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/CommonMenuManager.java
@@ -47,4 +47,8 @@ public class CommonMenuManager extends MenuManager {
handlers.put(actionId, handler);
}
+ public IHandler getHandler(String actionId) {
+ return (IHandler)handlers.get(actionId);
+ }
+
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/CommonViewerAdvisor.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/CommonViewerAdvisor.java
index 6a51d812a..c834101b7 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/CommonViewerAdvisor.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/CommonViewerAdvisor.java
@@ -208,6 +208,15 @@ public class CommonViewerAdvisor extends AbstractTreeViewerAdvisor implements IN
ISelection selection = getViewer().getSelection();
actionService.setContext(new ActionContext(selection));
actionService.fillContextMenu(manager);
+
+ if (manager instanceof CommonMenuManager) {
+ CommonMenuManager cmm = (CommonMenuManager) manager;
+ addMergeActions(manager, cmm);
+ }
+ }
+
+ private void addMergeActions(IMenuManager manager, CommonMenuManager cmm) {
+ ((ModelSynchronizeParticipant)getConfiguration().getParticipant()).addMergeActions(cmm);
}
/* (non-Javadoc)
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/MarkAsMergedAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/MarkAsMergedAction.java
index b290e74fe..637bfffbd 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/MarkAsMergedAction.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/MarkAsMergedAction.java
@@ -22,6 +22,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.team.core.diff.*;
import org.eclipse.team.core.mapping.IMergeContext;
import org.eclipse.team.internal.ui.Utils;
+import org.eclipse.team.ui.mapping.ModelProviderOperation;
import org.eclipse.team.ui.operations.*;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
@@ -42,7 +43,7 @@ public class MarkAsMergedAction extends ModelProviderAction {
public void run() {
final IMergeContext context = (IMergeContext)((ModelSynchronizeParticipant)getConfiguration().getParticipant()).getContext();
try {
- new AbstractResourceMappingOperation(getConfiguration()) {
+ new ModelProviderOperation(getConfiguration()) {
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
try {
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/MergeAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/MergeAction.java
index fdba27b48..69b64dd9f 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/MergeAction.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/MergeAction.java
@@ -17,6 +17,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.team.core.diff.*;
import org.eclipse.team.core.mapping.IMergeContext;
import org.eclipse.team.internal.ui.Utils;
+import org.eclipse.team.ui.mapping.ModelProviderOperation;
import org.eclipse.team.ui.operations.*;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
@@ -42,7 +43,7 @@ public class MergeAction extends ModelProviderAction {
public void run() {
final IMergeContext context = (IMergeContext)((ModelSynchronizeParticipant)getConfiguration().getParticipant()).getContext();
try {
- new AbstractResourceMappingOperation(getConfiguration()) {
+ new ModelProviderOperation(getConfiguration()) {
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
try {
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/MergeActionHandler.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/MergeActionHandler.java
deleted file mode 100644
index e8d531050..000000000
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/MergeActionHandler.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.team.internal.ui.mapping;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
-
-public abstract class MergeActionHandler extends AbstractHandler {
-
- protected ISynchronizePageConfiguration getConfiguration() {
- // TODO Auto-generated method stub
- return null;
- }
-
- protected IStructuredSelection getStructuredSelection(ExecutionEvent event) {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceMarkAsMergedHandler.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceMarkAsMergedHandler.java
index b0eff08c9..0cd68ea01 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceMarkAsMergedHandler.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceMarkAsMergedHandler.java
@@ -12,80 +12,95 @@ package org.eclipse.team.internal.ui.mapping;
import java.lang.reflect.InvocationTargetException;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.MultiRule;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.team.core.diff.*;
import org.eclipse.team.core.mapping.IMergeContext;
-import org.eclipse.team.internal.ui.Utils;
+import org.eclipse.team.ui.mapping.ModelProviderOperation;
+import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
+import org.eclipse.ui.navigator.IExtensionStateModel;
-public class ResourceMarkAsMergedHandler extends MergeActionHandler {
+public class ResourceMarkAsMergedHandler extends SynchronizationActionHandler {
- public Object execute(final ExecutionEvent event) throws ExecutionException {
- try {
- new ResourceModelProviderOperation(getConfiguration()) {
- public void run(IProgressMonitor monitor) throws InvocationTargetException,
- InterruptedException {
- try {
- final IMergeContext context = (IMergeContext)getContext();
- final IDiffNode[] deltas = getFileDeltas(getStructuredSelection(event));
- ISchedulingRule rule = getMergeRule(context, deltas);
- context.run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- markAsMerged(deltas, context, monitor);
- }
-
- }, rule, IResource.NONE, monitor);
-
- } catch (CoreException e) {
- throw new InvocationTargetException(e);
- }
+ public ResourceMarkAsMergedHandler(IExtensionStateModel model) {
+ super(model);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.mapping.MergeActionHandler#createOperation(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration, org.eclipse.jface.viewers.IStructuredSelection)
+ */
+ protected ModelProviderOperation createOperation(
+ ISynchronizePageConfiguration configuration,
+ IStructuredSelection structuredSelection) {
+ return new ResourceModelProviderOperation(configuration,
+ structuredSelection.toArray()) {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException, InterruptedException {
+ try {
+ final IMergeContext context = (IMergeContext) getContext();
+ final IDiffNode[] deltas = getFileDeltas(getElements());
+ ISchedulingRule rule = getMergeRule(context, deltas);
+ context.run(new IWorkspaceRunnable() {
+ public void run(IProgressMonitor monitor)
+ throws CoreException {
+ markAsMerged(deltas, context, monitor);
+ }
+
+ }, rule, IResource.NONE, monitor);
+
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
}
+ }
- private ISchedulingRule getMergeRule(IMergeContext context, IDiffNode[] deltas) {
- ISchedulingRule result = null;
- for (int i = 0; i < deltas.length; i++) {
- IDiffNode node = deltas[i];
- ISchedulingRule rule = context.getMergeRule(node);
- if (result == null) {
- result = rule;
- } else {
- result = MultiRule.combine(result, rule);
- }
+ private ISchedulingRule getMergeRule(IMergeContext context,
+ IDiffNode[] deltas) {
+ ISchedulingRule result = null;
+ for (int i = 0; i < deltas.length; i++) {
+ IDiffNode node = deltas[i];
+ ISchedulingRule rule = context.getMergeRule(node);
+ if (result == null) {
+ result = rule;
+ } else {
+ result = MultiRule.combine(result, rule);
}
- return result;
}
+ return result;
+ }
- private void markAsMerged(IDiffNode[] deltas, final IMergeContext context, IProgressMonitor monitor) throws CoreException {
- context.markAsMerged(deltas, false, monitor);
- }
+ private void markAsMerged(IDiffNode[] deltas,
+ final IMergeContext context, IProgressMonitor monitor)
+ throws CoreException {
+ context.markAsMerged(deltas, false, monitor);
+ }
- protected FastDiffNodeFilter getDiffFilter() {
- return new FastDiffNodeFilter() {
- public boolean select(IDiffNode node) {
- if (node instanceof IThreeWayDiff) {
- IThreeWayDiff twd = (IThreeWayDiff) node;
- if (twd.getDirection() == IThreeWayDiff.CONFLICTING || twd.getDirection() == IThreeWayDiff.INCOMING) {
- return true;
- }
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.mapping.ResourceModelProviderOperation#getDiffFilter()
+ */
+ protected FastDiffNodeFilter getDiffFilter() {
+ return new FastDiffNodeFilter() {
+ public boolean select(IDiffNode node) {
+ if (node instanceof IThreeWayDiff) {
+ IThreeWayDiff twd = (IThreeWayDiff) node;
+ if (twd.getDirection() == IThreeWayDiff.CONFLICTING
+ || twd.getDirection() == IThreeWayDiff.INCOMING) {
+ return true;
}
- return false;
}
- };
- }
-
- }.run();
- } catch (InvocationTargetException e) {
- Utils.handle(e);
- } catch (InterruptedException e) {
- // Ignore
- }
- return null;
+ return false;
+ }
+ };
+ }
+
+ };
}
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceMergeHandler.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceMergeHandler.java
index f2fdb6b11..5eba26610 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceMergeHandler.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceMergeHandler.java
@@ -12,58 +12,57 @@ package org.eclipse.team.internal.ui.mapping;
import java.lang.reflect.InvocationTargetException;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.*;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.team.core.diff.*;
import org.eclipse.team.core.mapping.IMergeContext;
-import org.eclipse.team.internal.ui.Utils;
+import org.eclipse.team.ui.mapping.ModelProviderOperation;
+import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
+import org.eclipse.ui.navigator.IExtensionStateModel;
-public class ResourceMergeHandler extends MergeActionHandler {
+public class ResourceMergeHandler extends SynchronizationActionHandler {
private final boolean overwrite;
- public ResourceMergeHandler(boolean overwrite) {
+ public ResourceMergeHandler(IExtensionStateModel model, boolean overwrite) {
+ super(model);
this.overwrite = overwrite;
}
- public Object execute(final ExecutionEvent event) throws ExecutionException {
- try {
- new ResourceModelProviderOperation(getConfiguration()) {
- public void run(IProgressMonitor monitor) throws InvocationTargetException,
- InterruptedException {
- try {
- IMergeContext context = (IMergeContext)getContext();
- IDiffNode[] diffs = getFileDeltas(getStructuredSelection(event));
- IStatus status = context.merge(diffs, overwrite, monitor);
- if (!status.isOK())
- throw new CoreException(status);
- } catch (CoreException e) {
- throw new InvocationTargetException(e);
- }
+ protected ModelProviderOperation createOperation(ISynchronizePageConfiguration configuration, IStructuredSelection structuredSelection) {
+ return new ResourceModelProviderOperation(configuration, structuredSelection.toArray()) {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void run(IProgressMonitor monitor) throws InvocationTargetException,
+ InterruptedException {
+ try {
+ IMergeContext context = (IMergeContext)getContext();
+ IDiffNode[] diffs = getFileDeltas(getElements());
+ IStatus status = context.merge(diffs, overwrite, monitor);
+ if (!status.isOK())
+ throw new CoreException(status);
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
}
-
- protected FastDiffNodeFilter getDiffFilter() {
- return new FastDiffNodeFilter() {
- public boolean select(IDiffNode node) {
- if (node instanceof IThreeWayDiff) {
- IThreeWayDiff twd = (IThreeWayDiff) node;
- if ((twd.getDirection() == IThreeWayDiff.OUTGOING && overwrite) || twd.getDirection() == IThreeWayDiff.CONFLICTING || twd.getDirection() == IThreeWayDiff.INCOMING) {
- return true;
- }
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.mapping.ResourceModelProviderOperation#getDiffFilter()
+ */
+ protected FastDiffNodeFilter getDiffFilter() {
+ return new FastDiffNodeFilter() {
+ public boolean select(IDiffNode node) {
+ if (node instanceof IThreeWayDiff) {
+ IThreeWayDiff twd = (IThreeWayDiff) node;
+ if ((twd.getDirection() == IThreeWayDiff.OUTGOING && overwrite) || twd.getDirection() == IThreeWayDiff.CONFLICTING || twd.getDirection() == IThreeWayDiff.INCOMING) {
+ return true;
}
- return false;
}
- };
- }
-
- }.run();
- } catch (InvocationTargetException e) {
- Utils.handle(e);
- } catch (InterruptedException e) {
- // Ignore
- }
- return null;
+ return false;
+ }
+ };
+ }
+ };
}
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceModelActionProvider.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceModelActionProvider.java
new file mode 100644
index 000000000..ef3164b2f
--- /dev/null
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceModelActionProvider.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ui.mapping;
+
+import org.eclipse.team.ui.mapping.SynchronizationActionProvider;
+
+/**
+ * This is the synchronization action handler for the resources model
+ */
+public class ResourceModelActionProvider extends SynchronizationActionProvider {
+
+ public ResourceModelActionProvider() {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.mapping.SynchronizationActionProvider#initialize()
+ */
+ protected void initialize() {
+ super.initialize();
+ // Register the merge, overwrite and mark-as-merged handlers
+ ResourceMergeHandler mergeHandler = new ResourceMergeHandler(getExtensionStateModel(), false /* overwrite */);
+ registerHandler(MERGE_ACTION_ID, mergeHandler);
+ ResourceMergeHandler overwriteHandler = new ResourceMergeHandler(getExtensionStateModel(), true /* overwrite */);
+ registerHandler(OVERWRITE_ACTION_ID, overwriteHandler);
+ ResourceMarkAsMergedHandler markAsMergedHandler = new ResourceMarkAsMergedHandler(getExtensionStateModel());
+ registerHandler(MARK_AS_MERGE_ACTION_ID, markAsMergedHandler);
+ }
+}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceModelProviderOperation.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceModelProviderOperation.java
index 68ebde467..40dea788e 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceModelProviderOperation.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ResourceModelProviderOperation.java
@@ -16,7 +16,6 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.mapping.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.team.core.diff.*;
import org.eclipse.team.core.mapping.IResourceDiffTree;
import org.eclipse.team.core.mapping.ISynchronizationContext;
@@ -27,21 +26,24 @@ import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
public abstract class ResourceModelProviderOperation extends ModelProviderOperation {
- protected ResourceModelProviderOperation(ISynchronizePageConfiguration configuration) {
+ private final Object[] elements;
+
+ protected ResourceModelProviderOperation(ISynchronizePageConfiguration configuration, Object[] elements) {
super(configuration);
+ this.elements = elements;
}
/**
* Return the file deltas that are either contained in the selection
* or are children of the selection and visible given the current
* mode of the page configuration.
- * @param selection the selected
+ * @param elements the selected elements
* @return the file deltas contained in or descended from the selection
*/
- protected IDiffNode[] getFileDeltas(IStructuredSelection selection) {
+ protected IDiffNode[] getFileDeltas(Object[] elements) {
Set result = new HashSet();
- for (Iterator iter = selection.iterator(); iter.hasNext();) {
- Object element = iter.next();
+ for (int j = 0; j < elements.length; j++) {
+ Object element = elements[j];
IDiffNode[] diffs = getFileDeltas(element);
for (int i = 0; i < diffs.length; i++) {
IDiffNode node = diffs[i];
@@ -136,4 +138,16 @@ public abstract class ResourceModelProviderOperation extends ModelProviderOperat
*/
protected abstract FastDiffNodeFilter getDiffFilter();
+ public Object[] getElements() {
+ return elements;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.mapping.ModelProviderOperation#shouldRun()
+ */
+ public boolean shouldRun() {
+ // TODO: may be too long for enablement
+ return getFileDeltas(getElements()).length > 0;
+ }
+
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/SynchronizationAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/SynchronizationAction.java
new file mode 100644
index 000000000..c6d03d0c4
--- /dev/null
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/SynchronizationAction.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ui.mapping;
+
+import java.util.Collections;
+
+import org.eclipse.core.commands.*;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.action.Action;
+import org.eclipse.swt.widgets.Event;
+
+/**
+ * An action that delegates to an appropriate handler when performing
+ * a merge opereration.
+ * <p>
+ * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
+ * part of a work in progress. There is a guarantee neither that this API will
+ * work nor that it will remain the same. Please do not use this API without
+ * consulting with the Platform/Team team.
+ * </p>
+ *
+ * @since 3.2
+ */
+public class SynchronizationAction extends Action {
+
+ private final String handlerId;
+ private final CommonMenuManager manager;
+
+ public SynchronizationAction(String handlerId, CommonMenuManager manager) {
+ Assert.isNotNull(handlerId);
+ Assert.isNotNull(manager);
+ this.handlerId = handlerId;
+ this.manager = manager;
+ }
+
+ public void runWithEvent(Event event) {
+ IHandler handler = getHandler();
+ if (handler != null && handler.isEnabled()) {
+ try {
+ handler.execute(new ExecutionEvent(null, Collections.EMPTY_MAP, event, null));
+ } catch (ExecutionException e) {
+ handle(e);
+ }
+ }
+ }
+
+ private void handle(Throwable e) {
+ if (e instanceof ExecutionException) {
+ ExecutionException ee = (ExecutionException) e;
+ if (ee.getCause() != null) {
+ handle(e.getCause());
+ }
+ }
+ //TODO: handle the exception
+ }
+
+ private IHandler getHandler() {
+ return manager.getHandler(handlerId);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#isEnabled()
+ */
+ public boolean isEnabled() {
+ IHandler handler = getHandler();
+ return handler != null && handler.isEnabled();
+ }
+
+}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/SynchronizationActionHandler.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/SynchronizationActionHandler.java
new file mode 100644
index 000000000..db00d27b7
--- /dev/null
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/SynchronizationActionHandler.java
@@ -0,0 +1,132 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ui.mapping;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.commands.*;
+import org.eclipse.jface.viewers.*;
+import org.eclipse.team.internal.ui.Utils;
+import org.eclipse.team.ui.TeamUI;
+import org.eclipse.team.ui.mapping.ModelProviderOperation;
+import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
+import org.eclipse.ui.navigator.IExtensionStateModel;
+
+/**
+ * An abstract superclass that enables models to create handlers
+ * for the basic merge operations (merge, overwrite and mark-as-merged).
+ * <p>
+ * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
+ * part of a work in progress. There is a guarantee neither that this API will
+ * work nor that it will remain the same. Please do not use this API without
+ * consulting with the Platform/Team team.
+ * </p>
+ *
+ * @since 3.2
+ */
+public abstract class SynchronizationActionHandler extends AbstractHandler {
+
+ private final IExtensionStateModel model;
+ private boolean enabled = false;
+
+ private ISelectionChangedListener listener = new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ updatedEnablement(event);
+ }
+ };
+
+ /**
+ * Create the handler.
+ * @param model the extension state model that contains the state
+ * provided by the synchronize page display the model.
+ */
+ public SynchronizationActionHandler(IExtensionStateModel model) {
+ this.model = model;
+ getSelectionProvider(null).addSelectionChangedListener(listener);
+ updateEnablement(getSelectionProvider(null).getSelection(), getConfiguration(null));
+ }
+
+ /* private */ void updatedEnablement(SelectionChangedEvent event) {
+ updateEnablement(event.getSelection(), getConfiguration(null));
+ }
+
+ private void updateEnablement(ISelection selection, ISynchronizePageConfiguration configuration) {
+ boolean isEnabled = isEnabled((IStructuredSelection)selection, configuration);
+ setEnabled(isEnabled);
+ }
+
+ private boolean isEnabled(IStructuredSelection selection, ISynchronizePageConfiguration configuration) {
+ ModelProviderOperation op = createOperation(configuration, selection);
+ return op.shouldRun();
+ }
+
+ private final ISynchronizePageConfiguration getConfiguration(ExecutionEvent event) {
+ return (ISynchronizePageConfiguration)model.getProperty(TeamUI.SYNCHRONIZATION_PAGE_CONFIGURATION);
+ }
+
+ private final IStructuredSelection getStructuredSelection(ExecutionEvent event) {
+ return (IStructuredSelection)getSelectionProvider(event).getSelection();
+ }
+
+ private ISelectionProvider getSelectionProvider(ExecutionEvent event) {
+ return getConfiguration(event).getSite().getSelectionProvider();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
+ */
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ /**
+ * Set the enablement of this handler.
+ * @param isEnabled whether the handelr is enabled
+ */
+ protected void setEnabled(boolean isEnabled) {
+ if (enabled != isEnabled) {
+ enabled = isEnabled;
+ fireHandlerChanged(new HandlerEvent(this, true, false));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(final ExecutionEvent event) throws ExecutionException {
+ try {
+ createOperation(event).run();
+ } catch (InvocationTargetException e) {
+ Utils.handle(e);
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ return null;
+ }
+
+ private ModelProviderOperation createOperation(ExecutionEvent event) {
+ ISynchronizePageConfiguration configuration = getConfiguration(event);
+ IStructuredSelection structuredSelection = getStructuredSelection(event);
+ return createOperation(configuration, structuredSelection);
+ }
+
+ /**
+ * Create and return a model provider operation that can perform
+ * the merge operaton.
+ * @param configuration the configuration of the page showing the model
+ * @param structuredSelection the selected elements
+ * @return a model provider operation that can perform
+ * the desired merge operaton
+ */
+ protected abstract ModelProviderOperation createOperation(
+ ISynchronizePageConfiguration configuration,
+ IStructuredSelection structuredSelection);
+}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/mapping/ModelProviderOperation.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/mapping/ModelProviderOperation.java
index b7eae0cc3..5ad8eaafb 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/mapping/ModelProviderOperation.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/mapping/ModelProviderOperation.java
@@ -50,6 +50,14 @@ public abstract class ModelProviderOperation extends AbstractResourceMappingOper
protected ISynchronizationContext getContext() {
return ((ModelSynchronizeParticipant)getConfiguration().getParticipant()).getContext();
}
+
+ /**
+ * Make <code>shouldRun</code> public so the result
+ * can be used to provide handler enablement
+ */
+ public boolean shouldRun() {
+ return super.shouldRun();
+ }
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/mapping/SynchronizationActionGroup.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/mapping/SynchronizationActionProvider.java
index 0181b3811..4fba05cf6 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/mapping/SynchronizationActionGroup.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/mapping/SynchronizationActionProvider.java
@@ -18,14 +18,13 @@ import org.eclipse.team.internal.ui.mapping.CommonMenuManager;
import org.eclipse.team.ui.TeamUI;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.navigator.CommonActionProvider;
-import org.eclipse.ui.navigator.CommonActionProviderConfig;
+import org.eclipse.ui.navigator.*;
/**
* An action group that can be used by models to contribute actions
* to a team synchronization viewer.
* <p>
- * This class is not intended to be subclasses by clients
+ * This class may be subclasses by clients
* <p>
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is a guarantee neither that this API will
@@ -35,7 +34,7 @@ import org.eclipse.ui.navigator.CommonActionProviderConfig;
*
* @since 3.2
*/
-public class SynchronizationActionGroup extends CommonActionProvider {
+public class SynchronizationActionProvider extends CommonActionProvider {
/**
* Action id constant for the merge action.
@@ -61,8 +60,19 @@ public class SynchronizationActionGroup extends CommonActionProvider {
/* (non-Javadoc)
* @see org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.CommonActionProviderConfig)
*/
- public void init(CommonActionProviderConfig aConfig) {
+ public final void init(CommonActionProviderConfig aConfig) {
config = aConfig;
+ initialize();
+ }
+
+ /**
+ * Method called during action provider initialization.
+ * It is invoked from the {@link #init(CommonActionProviderConfig)}
+ * after after the configuration has been recorded. Subclasses
+ * may override.
+ */
+ protected void initialize() {
+ // By deault, do nothing
}
/**
@@ -80,7 +90,17 @@ public class SynchronizationActionGroup extends CommonActionProvider {
* the common viewer
*/
public final ISynchronizePageConfiguration getSynchronizePageConfiguration() {
- return (ISynchronizePageConfiguration)config.getExtensionStateModel().getProperty(TeamUI.SYNCHRONIZATION_PAGE_CONFIGURATION);
+ return (ISynchronizePageConfiguration)getExtensionStateModel().getProperty(TeamUI.SYNCHRONIZATION_PAGE_CONFIGURATION);
+ }
+
+ /**
+ * Return the extension state model for the content provider associated with
+ * action provider.
+ * @return the extension state model for the content provider associated with
+ * action provider
+ */
+ protected IExtensionStateModel getExtensionStateModel() {
+ return config.getExtensionStateModel();
}
/**
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ModelSynchronizeParticipant.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ModelSynchronizeParticipant.java
index 3d67b5589..97fad98ca 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ModelSynchronizeParticipant.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ModelSynchronizeParticipant.java
@@ -14,6 +14,7 @@ import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.structuremergeviewer.ICompareInput;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.*;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.team.core.mapping.IMergeContext;
@@ -23,6 +24,7 @@ import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.internal.ui.mapping.*;
import org.eclipse.team.ui.TeamUI;
import org.eclipse.team.ui.mapping.ICompareAdapter;
+import org.eclipse.team.ui.mapping.SynchronizationActionProvider;
import org.eclipse.team.ui.synchronize.*;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.IPageBookViewPage;
@@ -46,13 +48,13 @@ public class ModelSynchronizeParticipant extends
* The id of the merge action group that determines where the merge
* actions (e.g. merge and overwrite) appear in the context menu or toolbar.
*/
- public static final String MERGE_ACTION_GROUP = "merge"; //$NON-NLS-1$
+ public static final String MERGE_ACTION_GROUP = "group.merge"; //$NON-NLS-1$
/**
* The id of the action group that determines where the other
* actions (e.g. mark-as-mered) appear in the context menu.
*/
- public static final String OTHER_ACTION_GROUP = "other"; //$NON-NLS-1$
+ public static final String OTHER_ACTION_GROUP = "group.other"; //$NON-NLS-1$
private ISynchronizationContext context;
@@ -74,66 +76,8 @@ public class ModelSynchronizeParticipant extends
ISynchronizePageConfiguration.P_TOOLBAR_MENU,
MERGE_ACTION_GROUP,
updateToolbarAction);
- appendToGroup(
- ISynchronizePageConfiguration.P_CONTEXT_MENU,
- MERGE_ACTION_GROUP,
- new MergeAction(configuration, false));
- appendToGroup(
- ISynchronizePageConfiguration.P_CONTEXT_MENU,
- MERGE_ACTION_GROUP,
- new MergeAction(configuration, true));
- appendToGroup(
- ISynchronizePageConfiguration.P_CONTEXT_MENU,
- OTHER_ACTION_GROUP,
- new MarkAsMergedAction(configuration));
+ // TODO: Should add a merge all to the context menu as well?
}
-
-// appendToGroup(
-// ISynchronizePageConfiguration.P_CONTEXT_MENU,
-// CONTEXT_MENU_CONTRIBUTION_GROUP_1,
-// new WorkspaceCommitAction(configuration));
-// appendToGroup(
-// ISynchronizePageConfiguration.P_CONTEXT_MENU,
-// CONTEXT_MENU_CONTRIBUTION_GROUP_2,
-// new OverrideAndUpdateAction(configuration));
-// appendToGroup(
-// ISynchronizePageConfiguration.P_CONTEXT_MENU,
-// CONTEXT_MENU_CONTRIBUTION_GROUP_2,
-// new OverrideAndCommitAction(configuration));
-// appendToGroup(
-// ISynchronizePageConfiguration.P_CONTEXT_MENU,
-// CONTEXT_MENU_CONTRIBUTION_GROUP_2,
-// new ConfirmMergedAction(configuration));
-// appendToGroup(
-// ISynchronizePageConfiguration.P_CONTEXT_MENU,
-// CONTEXT_MENU_CONTRIBUTION_GROUP_3,
-// new CVSActionDelegateWrapper(new IgnoreAction(), configuration));
-// if (!configuration.getSite().isModal()) {
-// appendToGroup(
-// ISynchronizePageConfiguration.P_CONTEXT_MENU,
-// CONTEXT_MENU_CONTRIBUTION_GROUP_3,
-// new CreatePatchAction(configuration));
-// appendToGroup(
-// ISynchronizePageConfiguration.P_CONTEXT_MENU,
-// CONTEXT_MENU_CONTRIBUTION_GROUP_3,
-// new CVSActionDelegateWrapper(new BranchAction(), configuration));
-// appendToGroup(
-// ISynchronizePageConfiguration.P_CONTEXT_MENU,
-// CONTEXT_MENU_CONTRIBUTION_GROUP_3,
-// new CVSActionDelegateWrapper(new ShowAnnotationAction(), configuration));
-// appendToGroup(
-// ISynchronizePageConfiguration.P_CONTEXT_MENU,
-// CONTEXT_MENU_CONTRIBUTION_GROUP_3,
-// new CVSActionDelegateWrapper(new ShowResourceInHistoryAction(), configuration));
-// appendToGroup(
-// ISynchronizePageConfiguration.P_CONTEXT_MENU,
-// CONTEXT_MENU_CONTRIBUTION_GROUP_3,
-// new CVSActionDelegateWrapper(new SetKeywordSubstitutionAction(), configuration));
-// }
-// appendToGroup(
-// ISynchronizePageConfiguration.P_CONTEXT_MENU,
-// CONTEXT_MENU_CONTRIBUTION_GROUP_4,
-// new RefreshDirtyStateAction(configuration));
}
}
@@ -283,11 +227,91 @@ public class ModelSynchronizeParticipant extends
return false;
}
+ /**
+ * Return whether merge capabilities are enabled for this participant.
+ * If merging is enabled, merge actions can be shown. If merging is disabled, no
+ * merge actions should be surfaced.
+ * @return whether merge capabilities should be enabled for this participant
+ */
public boolean isMergingEnabled() {
return mergingEnabled;
}
+ /**
+ * Set whether merge capabilities should be enabled for this participant.
+ * @param mergingEnabled whether merge capabilities should be enabled for this participant
+ */
public void setMergingEnabled(boolean mergingEnabled) {
this.mergingEnabled = mergingEnabled;
}
+
+ /**
+ * Method to add the merge actions to the contetx menu. This method
+ * is called by the internal synchronization framework and should not
+ * to be invoked by other clients. Subsclasses can configure the
+ * merge actions by overriding {@link #configureMergeAction(String, Action)}
+ * and can control where in the context menu the action appears by
+ * overriding {@link #addToContextMenu(String, Action, IMenuManager)}.
+ * @param cmm the menu manager
+ */
+ public final void addMergeActions(CommonMenuManager cmm) {
+ if (isMergingEnabled()) {
+ SynchronizationAction merge = new SynchronizationAction(SynchronizationActionProvider.MERGE_ACTION_ID, cmm);
+ configureMergeAction(SynchronizationActionProvider.MERGE_ACTION_ID, merge);
+ addToContextMenu(SynchronizationActionProvider.MERGE_ACTION_ID, merge, cmm);
+ SynchronizationAction overwrite = new SynchronizationAction(SynchronizationActionProvider.OVERWRITE_ACTION_ID, cmm);
+ configureMergeAction(SynchronizationActionProvider.OVERWRITE_ACTION_ID, overwrite);
+ addToContextMenu(SynchronizationActionProvider.OVERWRITE_ACTION_ID, overwrite, cmm);
+ SynchronizationAction markAsMerged = new SynchronizationAction(SynchronizationActionProvider.MARK_AS_MERGE_ACTION_ID, cmm);
+ configureMergeAction(SynchronizationActionProvider.MARK_AS_MERGE_ACTION_ID, markAsMerged);
+ addToContextMenu(SynchronizationActionProvider.MARK_AS_MERGE_ACTION_ID, markAsMerged, cmm);
+ }
+ }
+
+ /**
+ * Configure the merge action to have appropriate label, image, etc.
+ * Subclasses may override but should invoke the overridden
+ * method for unrecognized ids in order to support future additions.
+ * @param mergeActionId the id of the merge action (one of
+ * {@link SynchronizationActionProvider#MERGE_ACTION_ID},
+ * {@link SynchronizationActionProvider#OVERWRITE_ACTION_ID} or
+ * {@link SynchronizationActionProvider#MARK_AS_MERGE_ACTION_ID})
+ * @param action the action for the given id
+ */
+ protected void configureMergeAction(String mergeActionId, Action action) {
+ if (mergeActionId == SynchronizationActionProvider.MERGE_ACTION_ID) {
+ Utils.initAction(action, "action.merge."); //$NON-NLS-1$
+ } else if (mergeActionId == SynchronizationActionProvider.OVERWRITE_ACTION_ID) {
+ Utils.initAction(action, "action.overwrite."); //$NON-NLS-1$
+ } else if (mergeActionId == SynchronizationActionProvider.MARK_AS_MERGE_ACTION_ID) {
+ Utils.initAction(action, "action.markAsMerged."); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Add the merge action to the context menu manager.
+ * Subclasses may override but should invoke the overridden
+ * method for unrecognized ids in order to support future additions.
+ * @param id the id of the merge action (one of
+ * {@link SynchronizationActionProvider#MERGE_ACTION_ID},
+ * {@link SynchronizationActionProvider#OVERWRITE_ACTION_ID} or
+ * {@link SynchronizationActionProvider#MARK_AS_MERGE_ACTION_ID})
+ * @param action the action for the given id
+ * @param manager the context menu manager
+ */
+ protected void addToContextMenu(String mergeActionId, Action action, IMenuManager manager) {
+ IContributionItem group = null;;
+ if (mergeActionId == SynchronizationActionProvider.MERGE_ACTION_ID) {
+ group = manager.find(MERGE_ACTION_GROUP);
+ } else if (mergeActionId == SynchronizationActionProvider.OVERWRITE_ACTION_ID) {
+ group = manager.find(MERGE_ACTION_GROUP);
+ } else if (mergeActionId == SynchronizationActionProvider.MARK_AS_MERGE_ACTION_ID) {
+ group = manager.find(OTHER_ACTION_GROUP);
+ }
+ if (group != null) {
+ manager.appendToGroup(group.getId(), action);
+ } else {
+ manager.add(action);
+ }
+ }
}

Back to the top