Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2006-06-13 14:40:23 +0000
committerMichael Valenta2006-06-13 14:40:23 +0000
commit2e9fe14242d5642bc0467a3bf916592a5ad30e92 (patch)
tree1a1c4e80419b1993e03f402af1547b9602d5de93 /examples
parentbcdc3624547e394c8478701600f27f6b557145ed (diff)
downloadeclipse.platform.team-2e9fe14242d5642bc0467a3bf916592a5ad30e92.tar.gz
eclipse.platform.team-2e9fe14242d5642bc0467a3bf916592a5ad30e92.tar.xz
eclipse.platform.team-2e9fe14242d5642bc0467a3bf916592a5ad30e92.zip
Updated example
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.team.examples.filesystem/plugin.xml7
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemMergeContext.java27
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/MergeAction.java48
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NoSyncModelMergePage.java311
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncMergeDialog.java67
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncMergePart.java138
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncModelMergeOperation.java106
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SyncDialogModelMergeOperation.java37
8 files changed, 738 insertions, 3 deletions
diff --git a/examples/org.eclipse.team.examples.filesystem/plugin.xml b/examples/org.eclipse.team.examples.filesystem/plugin.xml
index c2ea9ad54..694a38930 100644
--- a/examples/org.eclipse.team.examples.filesystem/plugin.xml
+++ b/examples/org.eclipse.team.examples.filesystem/plugin.xml
@@ -174,6 +174,13 @@
id="org.eclipse.team.examples.filesystem.get">
</action>
<action
+ label="Merge"
+ tooltip="Merge"
+ class="org.eclipse.team.examples.filesystem.ui.MergeAction"
+ menubarPath="team.main/group1"
+ id="org.eclipse.team.examples.filesystem.merge">
+ </action>
+ <action
label="%Synchronize.name"
tooltip="%Synchronize.tooltip"
class="org.eclipse.team.examples.filesystem.ui.SynchronizeAction"
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemMergeContext.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemMergeContext.java
index 35bacf4f0..1c72e3acc 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemMergeContext.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemMergeContext.java
@@ -10,14 +10,17 @@
*******************************************************************************/
package org.eclipse.team.examples.filesystem.subscriber;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.team.core.diff.IDiff;
+import org.eclipse.team.core.diff.IThreeWayDiff;
import org.eclipse.team.core.mapping.ISynchronizationScopeManager;
+import org.eclipse.team.core.mapping.provider.MergeStatus;
import org.eclipse.team.core.mapping.provider.ResourceDiffTree;
import org.eclipse.team.core.subscribers.SubscriberMergeContext;
+import org.eclipse.team.examples.filesystem.FileSystemPlugin;
/**
* A merge context for merging file system changes.
@@ -67,5 +70,23 @@ public class FileSystemMergeContext extends SubscriberMergeContext {
return ResourceDiffTree.getResourceFor(node).getProject();
}
-
+ /* (non-Javadoc)
+ * @see org.eclipse.team.core.mapping.provider.MergeContext#merge(org.eclipse.team.core.diff.IDiff, boolean, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public IStatus merge(IDiff diff, boolean ignoreLocalChanges, IProgressMonitor monitor) throws CoreException {
+ // Only attempt the merge for non-conflicts. The reason we do this
+ // is because the file system provider doesn't really have the proper base
+ // so merging conflicts doesn't work properly
+ if (!ignoreLocalChanges) {
+ IResource resource = ResourceDiffTree.getResourceFor(diff);
+ if (diff instanceof IThreeWayDiff && resource instanceof IFile) {
+ IThreeWayDiff twd = (IThreeWayDiff) diff;
+ if (twd.getDirection() == IThreeWayDiff.CONFLICTING) {
+ return new MergeStatus(FileSystemPlugin.ID, "Cannot merge conflicting files", new IFile[] { (IFile)resource });
+ }
+ }
+ }
+ return super.merge(diff, ignoreLocalChanges, monitor);
+ }
+
}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/MergeAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/MergeAction.java
new file mode 100644
index 000000000..fcf4f49f7
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/MergeAction.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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.examples.filesystem.ui;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.team.ui.synchronize.ModelMergeOperation;
+
+/**
+ * This merge action is contributed as a a popupmenu objectContribution in
+ * the plugin.xml. You can change the value return from {@link #isUseSyncFramework()}
+ * to try out different dialogs.
+ *
+ * @since 3.2
+ */
+public class MergeAction extends FileSystemAction {
+
+ public void run(IAction action) {
+ try {
+ ModelMergeOperation operation;
+ if (isUseSyncFramework()) {
+ operation = new SyncDialogModelMergeOperation(getTargetPart(),
+ FileSystemOperation.createScopeManager("Merging", getSelectedMappings()));
+ } else {
+ operation = new NonSyncModelMergeOperation(getTargetPart(),
+ FileSystemOperation.createScopeManager("Merging", getSelectedMappings()));
+ }
+ operation.run();
+ } catch (InvocationTargetException e) {
+ handle(e, null, "Errors occurred while merging");
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ }
+
+ private boolean isUseSyncFramework() {
+ return true;
+ }
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NoSyncModelMergePage.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NoSyncModelMergePage.java
new file mode 100644
index 000000000..0dd22bfba
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NoSyncModelMergePage.java
@@ -0,0 +1,311 @@
+/*******************************************************************************
+ * 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.examples.filesystem.ui;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.*;
+import java.util.List;
+
+import org.eclipse.compare.structuremergeviewer.ICompareInput;
+import org.eclipse.core.resources.*;
+import org.eclipse.core.resources.mapping.*;
+import org.eclipse.core.runtime.*;
+import org.eclipse.jface.action.*;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.*;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.team.core.diff.IDiff;
+import org.eclipse.team.core.mapping.IMergeContext;
+import org.eclipse.team.core.mapping.provider.ResourceDiffTree;
+import org.eclipse.team.examples.filesystem.FileSystemPlugin;
+import org.eclipse.team.internal.ui.mapping.SynchronizationResourceMappingContext;
+import org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter;
+import org.eclipse.team.ui.synchronize.ModelMergeOperation;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.Page;
+
+/**
+ * This class provides the page for the {@link NonSyncMergePart}.
+ */
+public class NoSyncModelMergePage extends Page {
+
+ IMergeContext context;
+ private TreeViewer viewer;
+ List mappings;
+
+ /*
+ * Content provider that returns the list of conflicting mappings
+ */
+ class PageContentProvider implements ITreeContentProvider {
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof IMergeContext) {
+ if (mappings == null)
+ // TODO: should be using a real progress monitor
+ computeMappings(new NullProgressMonitor());
+ return mappings.toArray();
+ }
+ return new Object[0];
+ }
+ public Object getParent(Object element) {
+ if (element instanceof ResourceMapping) {
+ return context;
+ }
+ return null;
+ }
+ public boolean hasChildren(Object element) {
+ if (element instanceof IMergeContext) {
+ return true;
+ }
+ return false;
+ }
+ public Object[] getElements(Object inputElement) {
+ return getChildren(inputElement);
+ }
+ public void dispose() {
+ // Nothing to do
+ }
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ // Nothing to do
+ }
+ }
+
+ /*
+ * Label provider that provides a label and image for conflicting resource mappings
+ */
+ class PageLabelProvider extends LabelProvider {
+ public String getText(Object element) {
+ if (element instanceof ResourceMapping) {
+ ResourceMapping mapping = (ResourceMapping) element;
+ ISynchronizationCompareAdapter adapter = NonSyncMergePart.getCompareAdapter(mapping);
+ if (adapter != null)
+ return adapter.getPathString(mapping) + "(" + mapping.getModelProvider().getDescriptor().getLabel() + ")";
+ }
+ if (element instanceof ICompareInput) {
+ ICompareInput ci = (ICompareInput) element;
+ ci.getName();
+ }
+ return super.getText(element);
+ }
+ public Image getImage(Object element) {
+ if (element instanceof ICompareInput) {
+ ICompareInput ci = (ICompareInput) element;
+ ci.getImage();
+ }
+ if (element instanceof ResourceMapping) {
+ ResourceMapping mapping = (ResourceMapping) element;
+ ISynchronizationCompareAdapter adapter = NonSyncMergePart.getCompareAdapter(mapping);
+ ICompareInput input = adapter.asCompareInput(context, mapping.getModelObject());
+ if (input != null)
+ return input.getImage();
+ }
+ return super.getImage(element);
+ }
+ }
+
+ /*
+ * Sorter that sorts mappings by model and then name
+ */
+ class PageSorter extends ViewerSorter {
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ if (e1 instanceof ResourceMapping && e2 instanceof ResourceMapping) {
+ ResourceMapping m1 = (ResourceMapping) e1;
+ ResourceMapping m2 = (ResourceMapping) e2;
+ if (m1.getModelProvider() == m2.getModelProvider()) {
+ return getLabel(m1).compareTo(getLabel(m2));
+ }
+ return compare(m1, m2);
+ }
+ return super.compare(viewer, e1, e2);
+ }
+ private int compare(ResourceMapping m1, ResourceMapping m2) {
+ ModelProvider[] sorted = ModelMergeOperation.sortByExtension(new ModelProvider[] { m1.getModelProvider(), m2.getModelProvider() });
+ return sorted[0] == m1.getModelProvider() ? -1 : 1;
+ }
+ private String getLabel(ResourceMapping mapping) {
+ ISynchronizationCompareAdapter adapter = NonSyncMergePart.getCompareAdapter(mapping);
+ if (adapter != null)
+ return adapter.getPathString(mapping);
+ return "";
+ }
+ }
+
+ public NoSyncModelMergePage(IMergeContext context) {
+ super();
+ this.context = context;
+ }
+
+ /**
+ * Create the list of all mappings that overlap with the out-of-sync files.
+ */
+ public void computeMappings(IProgressMonitor monitor) {
+ IModelProviderDescriptor[] descriptors = ModelProvider.getModelProviderDescriptors();
+ mappings = new ArrayList();
+ for (int i = 0; i < descriptors.length; i++) {
+ IModelProviderDescriptor descriptor = descriptors[i];
+ // Get the subset of files that this model provider cares about
+ try {
+ IResource[] resources = descriptor.getMatchingResources(getOutOfSyncFiles());
+ if (resources.length > 0) {
+ ModelProvider provider = descriptor.getModelProvider();
+ // Get the mappings for those resources
+ ResourceMapping[] mappings = provider.getMappings(resources, new SynchronizationResourceMappingContext(context), monitor);
+ this.mappings.addAll(Arrays.asList(mappings ));
+ }
+ } catch (CoreException e) {
+ FileSystemPlugin.log(e.getStatus());
+ }
+ }
+ }
+
+ private IResource[] getOutOfSyncFiles() {
+ IDiff[] diffs = getContext().getDiffTree().getDiffs(ResourcesPlugin.getWorkspace().getRoot(), IResource.DEPTH_INFINITE);
+ List result = new ArrayList();
+ for (int i = 0; i < diffs.length; i++) {
+ IDiff diff = diffs[i];
+ IResource resource = ResourceDiffTree.getResourceFor(diff);
+ if (resource.getType() == IResource.FILE)
+ result.add(resource);
+ }
+ return (IResource[]) result.toArray(new IResource[result.size()]);
+ }
+
+ /**
+ * Return the merge context.
+ * @return the merge context
+ */
+ public IMergeContext getContext() {
+ return context;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.Page#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createControl(Composite parent) {
+ viewer = new TreeViewer(parent);
+ viewer.setContentProvider(new PageContentProvider());
+ viewer.setLabelProvider(new PageLabelProvider());
+ viewer.setSorter(new PageSorter());
+ hookContextMenu(viewer);
+ viewer.setInput(context);
+ }
+
+ /*
+ * Hook the context menu to display the Overwrite and Mark-as-merged actions
+ */
+ private void hookContextMenu(final TreeViewer viewer) {
+ final MenuManager menuMgr = new MenuManager();
+ menuMgr.setRemoveAllWhenShown(true);
+ menuMgr.addMenuListener(new IMenuListener() {
+ public void menuAboutToShow(IMenuManager manager) {
+ fillContextMenu(manager);
+ }
+ });
+ Menu menu = menuMgr.createContextMenu(viewer.getControl());
+ viewer.getControl().setMenu(menu);
+ }
+
+ /**
+ * Fill the context menu.
+ * @param manager the context menu manager
+ */
+ protected void fillContextMenu(IMenuManager manager) {
+ /*
+ * Add a mark as merged action. Because we are not using the
+ * Synchronization framework and, more specifically, the
+ * Common Navigator content provider for the model providers,
+ * we do not have access to the merge handlers of the model.
+ * Therefore, we are writing are action to detect whether there
+ * are files that overlap between the selected model elements and
+ * unselected model elements.
+ */
+ Action markAsMerged = new Action("Mark as Merged") {
+ public void run() {
+ try {
+ final IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+ PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException {
+ IDiff[] diffs = getSelectedDiffs(selection, monitor);
+ if (!checkForModelOverlap(diffs, monitor)) {
+ return;
+ }
+ try {
+ context.markAsMerged(diffs, false, monitor);
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+ });
+ } catch (InvocationTargetException e) {
+ FileSystemPlugin.log(new Status(IStatus.ERROR, FileSystemPlugin.ID, 0, e.getTargetException().getMessage(), e.getTargetException()));
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ }
+ };
+ manager.add(markAsMerged);
+ }
+
+ protected IDiff[] getSelectedDiffs(IStructuredSelection selection, IProgressMonitor monitor) {
+ Object[] elements = selection.toArray();
+ return getDiffs(elements, monitor);
+ }
+
+ private IDiff[] getDiffs(Object[] elements, IProgressMonitor monitor) {
+ Set result = new HashSet();
+ for (int i = 0; i < elements.length; i++) {
+ Object element = elements[i];
+ try {
+ if (element instanceof ResourceMapping) {
+ ResourceMapping mapping = (ResourceMapping) element;
+ ResourceTraversal[] traversals = mapping.getTraversals(new SynchronizationResourceMappingContext(context), monitor);
+ result.addAll(Arrays.asList(context.getDiffTree().getDiffs(traversals)));
+ }
+ } catch (CoreException e) {
+ FileSystemPlugin.log(e.getStatus());
+ }
+ }
+ return (IDiff[]) result.toArray(new IDiff[result.size()]);
+ }
+
+ /**
+ * Check whether any of the diffs overlap with mappings that are not selected
+ * @param diffs
+ * @return
+ */
+ protected boolean checkForModelOverlap(IDiff[] diffs, IProgressMonitor monitor) {
+ // TODO: This check should see if the diffs are also part of mappings
+ // that are not included in the selection.
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.Page#getControl()
+ */
+ public Control getControl() {
+ if (viewer != null)
+ return viewer.getControl();
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.Page#setFocus()
+ */
+ public void setFocus() {
+ if (viewer != null)
+ viewer.getControl().setFocus();
+ }
+
+ public ISelectionProvider getViewer() {
+ return viewer;
+ }
+
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncMergeDialog.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncMergeDialog.java
new file mode 100644
index 000000000..69d84c433
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncMergeDialog.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * 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.examples.filesystem.ui;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.team.core.diff.*;
+import org.eclipse.team.core.mapping.IMergeContext;
+import org.eclipse.team.ui.ISaveableWorkbenchPart;
+import org.eclipse.team.ui.SaveablePartDialog;
+
+/**
+ * A dialog that can be used to merge conflicting model elements without
+ * using the Synchronization framework. This is experimental.
+ * See {@link NonSyncModelMergeOperation}
+ * for a description of this work flow and its shortcomings.
+ */
+public class NonSyncMergeDialog extends SaveablePartDialog {
+
+ public static void openFor(NonSyncModelMergeOperation operation) {
+ NoSyncModelMergePage page = new NoSyncModelMergePage((IMergeContext) operation.getContext());
+ NonSyncMergePart part = new NonSyncMergePart(operation.getShell(), new CompareConfiguration(), page);
+ NonSyncMergeDialog dialog = new NonSyncMergeDialog(operation.getShell(), part);
+ dialog.open();
+ }
+
+ public NonSyncMergeDialog(Shell shell, ISaveableWorkbenchPart input) {
+ super(shell, input);
+ }
+
+ protected void buttonPressed(int buttonId) {
+ if (buttonId == OK) {
+ NonSyncMergePart part = (NonSyncMergePart)getInput();
+ IMergeContext context = part.getContext();
+ if (hasUnmergedChanges(context)) {
+ if (!MessageDialog.openQuestion(getShell(), "Unmerged Changes", "There are still unmerged changes. Are you sure you want to close the dialog?"))
+ return;
+ }
+ }
+ super.buttonPressed(buttonId);
+ }
+
+ private boolean hasUnmergedChanges(IMergeContext context) {
+ return context.getDiffTree().hasMatchingDiffs(
+ ResourcesPlugin.getWorkspace().getRoot().getFullPath(),
+ new FastDiffFilter() {
+ public boolean select(IDiff diff) {
+ if (diff instanceof IThreeWayDiff) {
+ IThreeWayDiff twd = (IThreeWayDiff) diff;
+ return twd.getDirection() == IThreeWayDiff.INCOMING || twd.getDirection() == IThreeWayDiff.CONFLICTING;
+ }
+ return false;
+ }
+ });
+ }
+
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncMergePart.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncMergePart.java
new file mode 100644
index 000000000..b24ea3e75
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncMergePart.java
@@ -0,0 +1,138 @@
+/*******************************************************************************
+ * 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.examples.filesystem.ui;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.IContentChangeNotifier;
+import org.eclipse.compare.structuremergeviewer.ICompareInput;
+import org.eclipse.core.resources.mapping.ModelProvider;
+import org.eclipse.core.resources.mapping.ResourceMapping;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.ToolBarManager;
+import org.eclipse.jface.viewers.*;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.team.core.mapping.IMergeContext;
+import org.eclipse.team.internal.ui.Policy;
+import org.eclipse.team.internal.ui.Utils;
+import org.eclipse.team.ui.PageSaveablePart;
+import org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter;
+import org.eclipse.team.ui.mapping.ISynchronizationCompareInput;
+
+
+/**
+ * This class is the compare container used by the {@link NonSyncModelMergeOperation}
+ * to show a manual merge.
+ */
+public class NonSyncMergePart extends PageSaveablePart {
+
+ private final NoSyncModelMergePage page;
+
+ protected NonSyncMergePart(Shell shell, CompareConfiguration compareConfiguration, NoSyncModelMergePage page) {
+ super(shell, compareConfiguration);
+ this.page = page;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.PageSaveablePart#createPage(org.eclipse.swt.widgets.Composite, org.eclipse.jface.action.ToolBarManager)
+ */
+ protected Control createPage(Composite parent, ToolBarManager toolBarManager) {
+ page.createControl(parent);
+ return page.getControl();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.PageSaveablePart#getSelectionProvider()
+ */
+ protected ISelectionProvider getSelectionProvider() {
+ return page.getViewer();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.PageSaveablePart#getCompareInput(org.eclipse.jface.viewers.ISelection)
+ */
+ protected ICompareInput getCompareInput(ISelection selection) {
+ ICompareInput compareInput = super.getCompareInput(selection);
+ if (compareInput != null)
+ return compareInput;
+ Object element = ((IStructuredSelection)selection).getFirstElement();
+ ISynchronizationCompareAdapter compareAdapter = getCompareAdapter(element);
+ if (element instanceof ResourceMapping) {
+ element = ((ResourceMapping) element).getModelObject();
+ }
+ if (compareAdapter != null){
+ return compareAdapter.asCompareInput(page.getContext(), element);
+ }
+ return null;
+ }
+
+ protected static ISynchronizationCompareAdapter getCompareAdapter(Object element) {
+ if (element instanceof ResourceMapping) {
+ ResourceMapping mapping = (ResourceMapping) element;
+ ModelProvider provider = mapping.getModelProvider();
+ Object adapter = provider.getAdapter(ISynchronizationCompareAdapter.class);
+ if (adapter instanceof ISynchronizationCompareAdapter) {
+ return (ISynchronizationCompareAdapter) adapter;
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.PageSaveablePart#prepareInput(org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.compare.CompareConfiguration, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void prepareInput(ICompareInput input,
+ CompareConfiguration configuration, IProgressMonitor monitor)
+ throws InvocationTargetException {
+ try {
+ ISynchronizationCompareInput adapter = asSynchronizationCompareInput(input);
+ if (adapter != null) {
+ adapter.prepareInput(configuration, Policy.subMonitorFor(monitor, 90));
+ }
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+
+ /*
+ * Convert the compare input to a synchronize compare input.
+ */
+ private ISynchronizationCompareInput asSynchronizationCompareInput(ICompareInput input) {
+ return (ISynchronizationCompareInput)Utils.getAdapter(input, ISynchronizationCompareInput.class);
+ }
+
+ public void contentChanged(IContentChangeNotifier source) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWorkbenchPart#getTitle()
+ */
+ public String getTitle() {
+ return "File System Provider Merge";
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWorkbenchPart#getTitleImage()
+ */
+ public Image getTitleImage() {
+ return null;
+ }
+
+ public IMergeContext getContext() {
+ return page.getContext();
+ }
+
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncModelMergeOperation.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncModelMergeOperation.java
new file mode 100644
index 000000000..272e16f51
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncModelMergeOperation.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * 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.examples.filesystem.ui;
+
+import org.eclipse.core.resources.mapping.RemoteResourceMappingContext;
+import org.eclipse.core.runtime.*;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.team.core.mapping.ISynchronizationContext;
+import org.eclipse.team.core.mapping.ISynchronizationScopeManager;
+import org.eclipse.team.examples.filesystem.subscriber.FileSystemMergeContext;
+import org.eclipse.team.ui.synchronize.ModelMergeOperation;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * This operation shows an example of how a repository tool could
+ * perform the Preview (manual merge) phase of the merge operation
+ * without using the Synchronize view. It will do so by showing the
+ * user a flat list of all model elements that require a manual merge.
+ * <p>
+ * There are a couple of open issues here:
+ * <ol>
+ * <li>All the model provider UI is Common Navigator based so there is no model
+ * provider contributed actions available to overwrite and mark-as-merged. This will
+ * be a problem for models that have multiple resource mappings within a single file.
+ * <li>The order in which model elements are merged may matter. There is currently
+ * no Team API to determine this order.</li>
+ * <li>This operation assumes that a compare input will be available for the
+ * model objects that are obtained from the model provider. Although this
+ * is a reasonable assumption, it is not enforced by the API specification.</li>
+ * </ol>
+ */
+public class NonSyncModelMergeOperation extends ModelMergeOperation {
+
+ private FileSystemMergeContext context;
+
+ /**
+ * Create the operation
+ * @param part the part from which the operation was launched
+ * @param manager the scope of the operation
+ */
+ protected NonSyncModelMergeOperation(IWorkbenchPart part, ISynchronizationScopeManager manager) {
+ super(part, manager);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.synchronize.ModelMergeOperation#initializeContext(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void initializeContext(IProgressMonitor monitor) throws CoreException {
+ try {
+ monitor.beginTask(null, 100);
+ // Create the context
+ context = new FileSystemMergeContext(getScopeManager());
+ // Refresh the context to get the latest remote state
+ context.refresh(getScope().getTraversals(),
+ RemoteResourceMappingContext.FILE_CONTENTS_REQUIRED, new SubProgressMonitor(monitor, 75));
+ // What for the context to asynchronously update the diff tree
+ try {
+ Platform.getJobManager().join(context, new SubProgressMonitor(monitor, 25));
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ } finally {
+ monitor.done();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.synchronize.ModelOperation#getContext()
+ */
+ protected ISynchronizationContext getContext() {
+ return context;
+ }
+
+ /**
+ * Handle the preview request by opening a dialog that allows the user to manually merge
+ * any changes.
+ * @see org.eclipse.team.ui.synchronize.ModelMergeOperation#handlePreviewRequest()
+ */
+ protected void handlePreviewRequest() {
+ // We perform a syncExec so that the job will dispose of the scope manager
+ // after the dialog closes
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ NonSyncMergeDialog.openFor(NonSyncModelMergeOperation.this);
+ }
+ });
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.TeamOperation#getShell()
+ */
+ public Shell getShell() {
+ // Change method to public
+ return super.getShell();
+ }
+
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SyncDialogModelMergeOperation.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SyncDialogModelMergeOperation.java
new file mode 100644
index 000000000..e820c5471
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SyncDialogModelMergeOperation.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * 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.examples.filesystem.ui;
+
+import org.eclipse.team.core.mapping.ISynchronizationScopeManager;
+import org.eclipse.team.core.mapping.provider.SynchronizationContext;
+import org.eclipse.team.examples.filesystem.subscriber.FileSystemMergeContext;
+import org.eclipse.team.ui.synchronize.ModelParticipantMergeOperation;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * This merge operation will attempt a headless merge and then prompt
+ * the user with a dialog if conflicts exist.
+ */
+public class SyncDialogModelMergeOperation extends
+ ModelParticipantMergeOperation {
+
+ public SyncDialogModelMergeOperation(IWorkbenchPart part, ISynchronizationScopeManager manager) {
+ super(part, manager);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.synchronize.ModelParticipantMergeOperation#createMergeContext()
+ */
+ protected SynchronizationContext createMergeContext() {
+ return new FileSystemMergeContext(getScopeManager());
+ }
+
+}

Back to the top