Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2006-05-12 21:00:48 +0000
committerMichael Valenta2006-05-12 21:00:48 +0000
commitd9c982419d71f29d654a52924ef65fa4c1675160 (patch)
tree3826c07e759c864ad1ab92fd98e13912ef51fc21
parentfef3428bee4b8fd4adb6d36be2031023874ddef4 (diff)
downloadeclipse.platform.team-d9c982419d71f29d654a52924ef65fa4c1675160.tar.gz
eclipse.platform.team-d9c982419d71f29d654a52924ef65fa4c1675160.tar.xz
eclipse.platform.team-d9c982419d71f29d654a52924ef65fa4c1675160.zip
Working on synchronize example
-rw-r--r--examples/org.eclipse.team.examples.filesystem/.settings/org.eclipse.jdt.core.prefs4
-rw-r--r--examples/org.eclipse.team.examples.filesystem/plugin.xml1
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemOperations.java60
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemProvider.java2
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemMergeContext.java60
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemResourceVariant.java3
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemOperation.java11
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemSynchronizeOperation.java103
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemSynchronizeParticipant.java151
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetAction.java6
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetOperation.java32
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeAction.java42
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeOperation.java82
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ModelPutAction.java78
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutAction.java39
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutOperation.java98
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutSynchronizeAction.java42
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutSynchronizeOperation.java82
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeAction.java25
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeWizard.java74
20 files changed, 507 insertions, 488 deletions
diff --git a/examples/org.eclipse.team.examples.filesystem/.settings/org.eclipse.jdt.core.prefs b/examples/org.eclipse.team.examples.filesystem/.settings/org.eclipse.jdt.core.prefs
index 09c4e961c..82f0a71ca 100644
--- a/examples/org.eclipse.team.examples.filesystem/.settings/org.eclipse.jdt.core.prefs
+++ b/examples/org.eclipse.team.examples.filesystem/.settings/org.eclipse.jdt.core.prefs
@@ -1,4 +1,4 @@
-#Wed Mar 15 21:17:48 EST 2006
+#Thu May 11 13:20:53 EDT 2006
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
@@ -32,7 +32,7 @@ org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=error
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=error
-org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=error
org.eclipse.jdt.core.compiler.problem.parameterAssignment=warning
diff --git a/examples/org.eclipse.team.examples.filesystem/plugin.xml b/examples/org.eclipse.team.examples.filesystem/plugin.xml
index 50c052ed5..968451ae6 100644
--- a/examples/org.eclipse.team.examples.filesystem/plugin.xml
+++ b/examples/org.eclipse.team.examples.filesystem/plugin.xml
@@ -36,6 +36,7 @@
<import plugin="org.eclipse.team.ui"/>
<import plugin="org.eclipse.compare"/>
<import plugin="org.eclipse.ui"/>
+ <import plugin="org.eclipse.core.filesystem"/>
</requires>
<!-- =================================================================================== -->
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemOperations.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemOperations.java
index 00d659027..240ca08c1 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemOperations.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemOperations.java
@@ -147,6 +147,28 @@ public class FileSystemOperations {
}
/**
+ * Check-in the given resources to the given depth by replacing the remote (i.e. file system)
+ * contents with the local workspace contents.
+ * @param traversals the traversals that cover the resources to check in
+ * @param overrideIncoming indicate whether incoming remote changes should be replaced
+ * @param progress a progress monitor
+ * @throws TeamException
+ */
+ public void checkin(ResourceTraversal[] traversals, boolean overrideIncoming, IProgressMonitor monitor) throws TeamException {
+ try {
+ // ensure the progress monitor is not null
+ monitor = Policy.monitorFor(monitor);
+ monitor.beginTask(null, 100* traversals.length);
+ for (int i = 0; i < traversals.length; i++) {
+ ResourceTraversal traversal = traversals[i];
+ checkin(traversal.getResources(), traversal.getDepth(), overrideIncoming, new SubProgressMonitor(monitor, 100));
+ }
+ } finally {
+ monitor.done();
+ }
+ }
+
+ /**
* Return whether the local resource is checked out. A resource
* is checked out if it is a file that is not read-only. Folders
* are always checked out.
@@ -230,7 +252,7 @@ public class FileSystemOperations {
byte[] baseBytes = synchronizer.getBaseBytes(localFile);
IResourceVariant base = provider.getResourceVariant(localFile, baseBytes);
if (!synchronizer.hasSyncBytes(localFile)
- || (synchronizer.isLocallyModified(localFile) && !overrideOutgoing)) {
+ || (isLocallyModified(localFile) && !overrideOutgoing)) {
// Do not overwrite the local modification
return;
}
@@ -243,7 +265,10 @@ public class FileSystemOperations {
throw TeamException.asTeamException(e);
}
}
- if (!synchronizer.isLocallyModified(localFile) && comparator.compare(base, remote)) {
+ if (!synchronizer.isLocallyModified(localFile)
+ && base != null
+ && remote != null
+ && comparator.compare(base, remote)) {
// The base and remote are the same and there's no local changes
// so nothing needs to be done
}
@@ -288,10 +313,15 @@ public class FileSystemOperations {
progress.done();
}
- /*
- * Get the file if it is out-of-sync.
+ /**
+ * Put the file if the sync state allows it.
+ * @param localFile the local file
+ * @param overrideIncoming whether incoming changs shoudl be overwritten
+ * @param progress a progress monitor
+ * @return whether the put succeeded (i.e. the local matches the remote)
+ * @throws TeamException
*/
- private void internalPut(IFile localFile, boolean overrideIncoming, IProgressMonitor progress) throws TeamException {
+ private boolean internalPut(IFile localFile, boolean overrideIncoming, IProgressMonitor progress) throws TeamException {
ThreeWaySynchronizer synchronizer = FileSystemSubscriber.getInstance().getSynchronizer();
IResourceVariantComparator comparator = FileSystemSubscriber.getInstance().getResourceComparator();
FileSystemResourceVariant remote = getResourceVariant(localFile);
@@ -302,7 +332,7 @@ public class FileSystemOperations {
if (base == null && remote != null && !overrideIncoming) {
// The remote is an incoming (or conflicting) addition.
// Do not replace unless we are overriding
- return;
+ return false;
} else if (base != null && remote == null) {
// The remote is an incoming deletion
if (!localFile.exists()) {
@@ -310,18 +340,18 @@ public class FileSystemOperations {
synchronizer.flush(localFile, IResource.DEPTH_ZERO);
} else if (!overrideIncoming) {
// Do not override the incoming deletion
- return;
+ return false;
}
} else if (base != null && remote != null) {
boolean same = comparator.compare(base, remote);
- if (!synchronizer.isLocallyModified(localFile) && same) {
+ if (!isLocallyModified(localFile) && same) {
// The base and remote are the same and there's no local changes
// so nothing needs to be done
- return;
+ return true;
}
if (!same && !overrideIncoming) {
// The remote has changed. Only override if specified
- return;
+ return false;
}
}
@@ -361,8 +391,18 @@ public class FileSystemOperations {
throw FileSystemPlugin.wrapException(e);
}
}
+ return true;
}
+ private boolean isLocallyModified(IFile localFile) throws TeamException {
+ ThreeWaySynchronizer synchronizer = FileSystemSubscriber.getInstance().getSynchronizer();
+ if (!localFile.exists()) {
+ // Extra check for bug 141415
+ return synchronizer.getBaseBytes(localFile) != null;
+ }
+ return synchronizer.isLocallyModified(localFile);
+ }
+
/*
* Get the folder and its children to the depth specified.
*/
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemProvider.java
index e9ae07185..f75016dda 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemProvider.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemProvider.java
@@ -185,7 +185,7 @@ public class FileSystemProvider extends RepositoryProvider {
*/
public IResourceVariant getResourceVariant(IResource resource) {
File file = getFile(resource);
- if (file == null) return null;
+ if (file == null || !file.exists()) return null;
return new FileSystemResourceVariant(file);
}
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
new file mode 100644
index 000000000..b4e9a5ba4
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemMergeContext.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * 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.subscriber;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.core.diff.IDiff;
+import org.eclipse.team.core.mapping.ISynchronizationScopeManager;
+import org.eclipse.team.core.subscribers.SubscriberMergeContext;
+
+/**
+ * A merge context for merging file system changes.
+ */
+public class FileSystemMergeContext extends SubscriberMergeContext {
+
+ /**
+ * Create the file system merge context for the given scope manager.
+ * @param manager the scope manager
+ */
+ public FileSystemMergeContext(ISynchronizationScopeManager manager) {
+ super(FileSystemSubscriber.getInstance(), manager);
+ initialize();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.core.mapping.provider.MergeContext#makeInSync(org.eclipse.team.core.diff.IDiff, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void makeInSync(IDiff diff, IProgressMonitor monitor)
+ throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.core.mapping.IMergeContext#markAsMerged(org.eclipse.team.core.diff.IDiff, boolean, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void markAsMerged(IDiff node, boolean inSyncHint,
+ IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.core.mapping.IMergeContext#reject(org.eclipse.team.core.diff.IDiff, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void reject(IDiff diff, IProgressMonitor monitor)
+ throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemResourceVariant.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemResourceVariant.java
index 6b6d486fd..632f937e6 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemResourceVariant.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemResourceVariant.java
@@ -132,9 +132,8 @@ public class FileSystemResourceVariant extends CachedResourceVariant {
result[i] = new FileSystemResourceVariant(members[i]);
}
return result;
- } else {
- return new FileSystemResourceVariant[0];
}
+ return new FileSystemResourceVariant[0];
}
/**
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemOperation.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemOperation.java
index d88020289..2991cf679 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemOperation.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemOperation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation and others.
+ * 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
@@ -134,12 +134,19 @@ public abstract class FileSystemOperation extends ModelOperation {
* @param monitor a progress monitor
* @throws CoreException
*/
- protected abstract void execute(FileSystemProvider provider, ResourceTraversal[] traversals, SubProgressMonitor monitor) throws CoreException;
+ protected abstract void execute(FileSystemProvider provider, ResourceTraversal[] traversals, IProgressMonitor monitor) throws CoreException;
/**
* Return the task name for this operation.
* @return the task name for this operation
*/
protected abstract String getTaskName();
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.TeamOperation#canRunAsJob()
+ */
+ protected boolean canRunAsJob() {
+ return true;
+ }
}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemSynchronizeOperation.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemSynchronizeOperation.java
deleted file mode 100644
index b7a2ab82b..000000000
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemSynchronizeOperation.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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 org.eclipse.compare.structuremergeviewer.IDiffElement;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.team.core.RepositoryProvider;
-import org.eclipse.team.core.TeamException;
-import org.eclipse.team.core.synchronize.SyncInfo;
-import org.eclipse.team.core.synchronize.SyncInfoSet;
-import org.eclipse.team.examples.filesystem.FileSystemPlugin;
-import org.eclipse.team.examples.filesystem.FileSystemProvider;
-import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
-import org.eclipse.team.ui.synchronize.SynchronizeModelOperation;
-
-/**
- * Override SynchronizeModelOperation in order to delegate the operation to each file system
- * provider instance (i.e. each project). Also, prompt to prune conflicts from the set of
- * selected resources.
- */
-public abstract class FileSystemSynchronizeOperation extends SynchronizeModelOperation {
-
- protected FileSystemSynchronizeOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) {
- super(configuration, elements);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
- */
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- // First, ask the user if they want to include conflicts
- SyncInfoSet syncSet = getSyncInfoSet();
- if (!promptForConflictHandling(getShell(), syncSet)) return;
- // Divide the sync info by project
- final Map projectSyncInfos = getProjectSyncInfoSetMap(syncSet);
- monitor.beginTask(null, projectSyncInfos.size() * 100);
- for (Iterator iter = projectSyncInfos.keySet().iterator(); iter.hasNext(); ) {
- final IProject project = (IProject) iter.next();
- try {
- // Pass the scheduling rule to the synchronizer so that sync change events
- // and cache commits to disk are batched
- FileSystemProvider provider = (FileSystemProvider)RepositoryProvider.getProvider(project, FileSystemPlugin.PROVIDER_ID);
- if (provider != null) {
- run(provider, (SyncInfoSet)projectSyncInfos.get(project), monitor);
- }
- } catch (TeamException e) {
- throw new InvocationTargetException(e);
- }
- }
- monitor.done();
- }
-
- /**
- * Prompt the user to include conflicts. If the user choses not to include
- * conflicts, they will be removed from the passed set. If the user cancels,
- * <code>false</code> is returned.
- * @param shell a shell
- * @param syncSet the set of selected resources
- * @return whether the operation should proceed.
- */
- protected abstract boolean promptForConflictHandling(Shell shell, SyncInfoSet syncSet);
-
- /*
- * Divide the sync info for the operation by project
- */
- private Map getProjectSyncInfoSetMap(SyncInfoSet syncSet) {
- Map map = new HashMap();
- SyncInfo[] infos = syncSet.getSyncInfos();
- for (int i = 0; i < infos.length; i++) {
- SyncInfo info = infos[i];
- IProject project = info.getLocal().getProject();
- SyncInfoSet set = (SyncInfoSet)map.get(project);
- if (set == null) {
- set = new SyncInfoSet();
- map.put(project, set);
- }
- set.add(info);
- }
- return map;
- }
-
- /**
- * Run the operation on the sync info in the given set. The sync info will be all
- * from the same project.
- * @param provider
- * @param set the sync info set
- * @param monitor a progress monitor
- */
- protected abstract void run(FileSystemProvider provider, SyncInfoSet set, IProgressMonitor monitor) throws TeamException;
-}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemSynchronizeParticipant.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemSynchronizeParticipant.java
index 47fee7d2b..b9fafceb9 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemSynchronizeParticipant.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemSynchronizeParticipant.java
@@ -11,16 +11,24 @@
package org.eclipse.team.examples.filesystem.ui;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.action.*;
import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.team.core.TeamException;
-import org.eclipse.team.core.subscribers.Subscriber;
+import org.eclipse.team.core.mapping.ISynchronizationScopeManager;
+import org.eclipse.team.core.mapping.provider.MergeContext;
+import org.eclipse.team.core.mapping.provider.SynchronizationContext;
import org.eclipse.team.core.synchronize.SyncInfo;
import org.eclipse.team.core.variants.IResourceVariant;
+import org.eclipse.team.examples.filesystem.FileSystemPlugin;
+import org.eclipse.team.examples.filesystem.subscriber.FileSystemMergeContext;
import org.eclipse.team.examples.filesystem.subscriber.FileSystemSubscriber;
+import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.ui.TeamUI;
+import org.eclipse.team.ui.mapping.SynchronizationActionProvider;
import org.eclipse.team.ui.synchronize.*;
@@ -31,28 +39,34 @@ import org.eclipse.team.ui.synchronize.*;
*
* @since 3.0
*/
-public class FileSystemSynchronizeParticipant extends SubscriberParticipant {
+public class FileSystemSynchronizeParticipant extends ModelSynchronizeParticipant {
/**
- * The particpant ID as defined in the plugin manifest
+ * The participant id for the org.eclipse.team.ui.synchronizeParticipant extension point.
*/
public static final String ID = "org.eclipse.team.examples.filesystem.participant"; //$NON-NLS-1$
/**
- * Contxt menu action group for synchronize view actions
+ * The viewer id for the org.eclipse.ui.navigator.viewer extension point.
*/
- public static final String CONTEXT_MENU_CONTRIBUTION_GROUP_1 = "context_group_1"; //$NON-NLS-1$
+ public static final String VIEWER_ID = "org.eclipse.team.examples.filesystem.syncViewer"; //$NON-NLS-1$
+
+ /**
+ * Custom menu groups included in the viewer definition in the plugin.xml.
+ */
+ public static final String CONTEXT_MENU_PUT_GROUP_1 = "put"; //$NON-NLS-1$
+ public static final String CONTEXT_MENU_GET_GROUP_1 = "get"; //$NON-NLS-1$
/**
* A custom label decorator that will show the remote mapped path for each
* file.
*/
- private class FileSystemParticipantLabelDecorator extends LabelProvider implements ILabelDecorator {
+ public class FileSystemParticipantLabelDecorator extends LabelProvider implements ILabelDecorator {
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelDecorator#decorateImage(org.eclipse.swt.graphics.Image, java.lang.Object)
*/
public Image decorateImage(Image image, Object element) {
- return null;
+ return image;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelDecorator#decorateText(java.lang.String, java.lang.Object)
@@ -70,6 +84,7 @@ public class FileSystemSynchronizeParticipant extends SubscriberParticipant {
}
}
} catch (TeamException e) {
+ FileSystemPlugin.log(e.getStatus());
}
return null;
}
@@ -79,7 +94,7 @@ public class FileSystemSynchronizeParticipant extends SubscriberParticipant {
* Action group that contributes the get an put menus to the context menu
* in the synchronize view
*/
- private class FileSystemParticipantActionGroup extends SynchronizePageActionGroup {
+ public class FileSystemParticipantActionGroup extends ModelSynchronizeParticipantActionGroup {
/* (non-Javadoc)
* @see org.eclipse.team.ui.synchronize.SynchronizePageActionGroup#initialize(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration)
*/
@@ -87,33 +102,82 @@ public class FileSystemSynchronizeParticipant extends SubscriberParticipant {
super.initialize(configuration);
appendToGroup(
ISynchronizePageConfiguration.P_CONTEXT_MENU,
- CONTEXT_MENU_CONTRIBUTION_GROUP_1,
- new GetSynchronizeAction("Get", configuration));
- appendToGroup(
- ISynchronizePageConfiguration.P_CONTEXT_MENU,
- CONTEXT_MENU_CONTRIBUTION_GROUP_1,
- new PutSynchronizeAction("Put", configuration));
+ CONTEXT_MENU_PUT_GROUP_1,
+ new ModelPutAction("Put", configuration));
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.operations.MergeActionGroup#configureMergeAction(java.lang.String, org.eclipse.jface.action.Action)
+ */
+ protected void configureMergeAction(String mergeActionId, Action action) {
+ if (mergeActionId == SynchronizationActionProvider.MERGE_ACTION_ID) {
+ // This is the default label so this line could be left out but it is here for illustration
+ action.setText("Merge");
+ } else if (mergeActionId == SynchronizationActionProvider.OVERWRITE_ACTION_ID) {
+ // Custom label for overwrite
+ action.setText("Get");
+ } else if (mergeActionId == SynchronizationActionProvider.MARK_AS_MERGE_ACTION_ID) {
+ // Custom label for mark-as-merged
+ action.setText("Ignore Remote");
+ } else if (mergeActionId == MERGE_ALL_ACTION_ID) {
+ // This is the default label so this line could be left out but it is here for illustration
+ action.setText("Merge All");
+ } else {
+ super.configureMergeAction(mergeActionId, action);
+ }
+ }
+
+ protected void addToContextMenu(String mergeActionId, Action action, IMenuManager manager) {
+ IContributionItem group = null;
+ if (mergeActionId == SynchronizationActionProvider.MERGE_ACTION_ID) {
+ // This could be left out since this is the default group but it is here for illustration
+ group = manager.find(MERGE_ACTION_GROUP);
+ } else if (mergeActionId == SynchronizationActionProvider.OVERWRITE_ACTION_ID) {
+ // This is a custom group for the overwrite command
+ group = manager.find(CONTEXT_MENU_GET_GROUP_1);
+ } else if (mergeActionId == SynchronizationActionProvider.MARK_AS_MERGE_ACTION_ID) {
+ // This could be left out since this is the default group but it is here for illustration
+ group = manager.find(OTHER_ACTION_GROUP);
+ } else {
+ super.addToContextMenu(mergeActionId, action, manager);
+ return;
+ }
+ if (group != null) {
+ manager.appendToGroup(group.getId(), action);
+ } else {
+ manager.add(action);
+ }
}
}
- public FileSystemSynchronizeParticipant(ISynchronizeScope scope) {
- super(scope);
- setSubscriber(FileSystemSubscriber.getInstance());
+ /**
+ * Create a file system participant. This method is invoked by the
+ * Synchronize view when a persisted participant is being restored.
+ * Participants that are persisted must override the
+ * {@link #restoreContext(ISynchronizationScopeManager)} method to recreate
+ * the context and may also need to override the
+ * {@link #createScopeManager(ResourceMapping[])} method if they require a
+ * custom scope manager.
+ */
+ public FileSystemSynchronizeParticipant() {
+ super();
}
- /* (non-Javadoc)
- * @see org.eclipse.team.ui.synchronize.SubscriberParticipant#setSubscriber(org.eclipse.team.core.subscribers.Subscriber)
+ /**
+ * Create the participant for the given context. This method is used
+ * by the file system plugin to create a participant and then add it to
+ * the sync view (or show it is some other container).
+ * @param context the synchronization context
*/
- protected void setSubscriber(Subscriber subscriber) {
- super.setSubscriber(subscriber);
+ public FileSystemSynchronizeParticipant(SynchronizationContext context) {
+ super(context);
try {
- ISynchronizeParticipantDescriptor descriptor = TeamUI.getSynchronizeManager().getParticipantDescriptor(ID);
- setInitializationData(descriptor);
- setSecondaryId(Long.toString(System.currentTimeMillis()));
+ setInitializationData(TeamUI.getSynchronizeManager().getParticipantDescriptor(ID));
} catch (CoreException e) {
- // ignore
+ TeamUIPlugin.log(e);
}
+ setSecondaryId(Long.toString(System.currentTimeMillis()));
}
/* (non-Javadoc)
@@ -121,19 +185,30 @@ public class FileSystemSynchronizeParticipant extends SubscriberParticipant {
*/
protected void initializeConfiguration(ISynchronizePageConfiguration configuration) {
super.initializeConfiguration(configuration);
+ configuration.setProperty(ISynchronizePageConfiguration.P_VIEWER_ID, VIEWER_ID);
- ILabelDecorator labelDecorator = new FileSystemParticipantLabelDecorator();
- configuration.addLabelDecorator(labelDecorator);
-
- // Add support for showing mode buttons
- configuration.setSupportedModes(ISynchronizePageConfiguration.ALL_MODES);
- configuration.setMode(ISynchronizePageConfiguration.BOTH_MODE);
-
- // Create the action group that contributes the get and put actions
- configuration.addActionContribution(new FileSystemParticipantActionGroup());
- // Add the get and put group to the context menu
- configuration.addMenuGroup(
- ISynchronizePageConfiguration.P_CONTEXT_MENU,
- CONTEXT_MENU_CONTRIBUTION_GROUP_1);
+ // Add the label decorator
+ configuration.addLabelDecorator(new FileSystemParticipantLabelDecorator());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant#createMergeActionGroup()
+ */
+ protected ModelSynchronizeParticipantActionGroup createMergeActionGroup() {
+ return new FileSystemParticipantActionGroup();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant#restoreContext(org.eclipse.team.core.mapping.ISynchronizationScopeManager)
+ */
+ protected MergeContext restoreContext(ISynchronizationScopeManager manager) {
+ return new FileSystemMergeContext(manager);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant#createScopeManager(org.eclipse.core.resources.mapping.ResourceMapping[])
+ */
+ protected ISynchronizationScopeManager createScopeManager(ResourceMapping[] mappings) {
+ return FileSystemOperation.createScopeManager(getName(), mappings);
}
}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetAction.java
index 3b6e6ea0a..b8bc5eb81 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetAction.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetAction.java
@@ -22,8 +22,10 @@ public class GetAction extends FileSystemAction {
public void run(IAction action) {
try {
- new GetOperation(getTargetPart(),
- FileSystemOperation.createScopeManager(Policy.bind("GetAction.working"), getSelectedMappings())).run(); //$NON-NLS-1$
+ GetOperation operation = new GetOperation(getTargetPart(),
+ FileSystemOperation.createScopeManager(Policy.bind("GetAction.working"), getSelectedMappings())); //$NON-NLS-1$
+ operation.setOverwriteOutgoing(isOverwriteOutgoing());
+ operation.run();
} catch (InvocationTargetException e) {
handle(e, null, Policy.bind("GetAction.problemMessage")); //$NON-NLS-1$
} catch (InterruptedException e) {
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetOperation.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetOperation.java
index 19bf9dd88..76efd577f 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetOperation.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetOperation.java
@@ -12,10 +12,13 @@ package org.eclipse.team.examples.filesystem.ui;
import org.eclipse.core.resources.mapping.ResourceTraversal;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.team.core.diff.*;
import org.eclipse.team.core.subscribers.SubscriberScopeManager;
import org.eclipse.team.examples.filesystem.FileSystemProvider;
import org.eclipse.team.examples.filesystem.Policy;
+import org.eclipse.team.examples.filesystem.subscriber.FileSystemSubscriber;
import org.eclipse.ui.IWorkbenchPart;
/**
@@ -33,12 +36,37 @@ public class GetOperation extends FileSystemOperation {
* @see org.eclipse.team.examples.filesystem.ui.FileSystemOperation#execute(org.eclipse.team.examples.filesystem.FileSystemProvider, org.eclipse.core.resources.mapping.ResourceTraversal[], org.eclipse.core.runtime.SubProgressMonitor)
*/
protected void execute(FileSystemProvider provider,
- ResourceTraversal[] traversals, SubProgressMonitor monitor)
+ ResourceTraversal[] traversals, IProgressMonitor monitor)
throws CoreException {
provider.getOperations().get(traversals, isOverwriteOutgoing(), monitor);
+ if (!isOverwriteOutgoing() && hasIncomingChanges(traversals)) {
+ MessageDialog.openInformation(getShell(), "Conflicts", "Could not get all changes due to conflicts.");
+ }
}
+ private boolean hasIncomingChanges(ResourceTraversal[] traversals) throws CoreException {
+ final RuntimeException found = new RuntimeException();
+ try {
+ FileSystemSubscriber.getInstance().accept(traversals, new IDiffVisitor() {
+ public boolean visit(IDiff diff) {
+ if (diff instanceof IThreeWayDiff) {
+ IThreeWayDiff twd = (IThreeWayDiff) diff;
+ if (twd.getDirection() == IThreeWayDiff.INCOMING || twd.getDirection() == IThreeWayDiff.CONFLICTING) {
+ throw found;
+ }
+ }
+ return false;
+ }
+ });
+ } catch (RuntimeException e) {
+ if (e == found)
+ return true;
+ throw e;
+ }
+ return false;
+ }
+
/**
* Indicate whether the operation should overwrite outgoing changes.
* By default, the get operation does not override local modifications.
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeAction.java
deleted file mode 100644
index 8b8b3f003..000000000
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeAction.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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.structuremergeviewer.IDiffElement;
-import org.eclipse.team.core.synchronize.FastSyncInfoFilter;
-import org.eclipse.team.core.synchronize.SyncInfo;
-import org.eclipse.team.core.synchronize.FastSyncInfoFilter.SyncInfoDirectionFilter;
-import org.eclipse.team.ui.synchronize.*;
-
-/**
- * Get action that appears in the synchronize view. It's main purpose is
- * to filter the selection and delegate its execution to the get operation.
- */
-public class GetSynchronizeAction extends SynchronizeModelAction {
-
- protected GetSynchronizeAction(String text, ISynchronizePageConfiguration configuration) {
- super(text, configuration);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#getSubscriberOperation(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration, org.eclipse.compare.structuremergeviewer.IDiffElement[])
- */
- protected SynchronizeModelOperation getSubscriberOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) {
- return new GetSynchronizeOperation(configuration, elements);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.ui.sync.SubscriberAction#getSyncInfoFilter()
- */
- protected FastSyncInfoFilter getSyncInfoFilter() {
- return new SyncInfoDirectionFilter(new int[] {SyncInfo.INCOMING, SyncInfo.CONFLICTING});
- }
-}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeOperation.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeOperation.java
deleted file mode 100644
index 9bbb09a44..000000000
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeOperation.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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.structuremergeviewer.IDiffElement;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.team.core.TeamException;
-import org.eclipse.team.core.synchronize.SyncInfoSet;
-import org.eclipse.team.examples.filesystem.FileSystemProvider;
-import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
-
-/**
- * Sync view operation for getting file system resources
- */
-public class GetSynchronizeOperation extends FileSystemSynchronizeOperation {
-
- protected GetSynchronizeOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) {
- super(configuration, elements);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.examples.filesystem.ui.FileSystemSynchronizeOperation#promptForConflictHandling(org.eclipse.swt.widgets.Shell, org.eclipse.team.core.synchronize.SyncInfoSet)
- */
- protected boolean promptForConflictHandling(Shell shell, SyncInfoSet syncSet) {
- // If there is a conflict in the syncSet, we need to prompt the user before proceeding.
- if (syncSet.hasConflicts() || syncSet.hasOutgoingChanges()) {
- switch (promptForConflicts(shell, syncSet)) {
- case 0:
- // Yes, synchronize conflicts as well
- break;
- case 1:
- // No, remove outgoing
- syncSet.removeConflictingNodes();
- syncSet.removeOutgoingNodes();
- break;
- case 2:
- default:
- // Cancel
- return false;
- }
- }
- return true;
- }
-
- /**
- * Prompts the user to determine how conflicting changes should be handled.
- * Note: This method is designed to be overridden by test cases.
- * @return 0 to sync conflicts, 1 to sync all non-conflicts, 2 to cancel
- */
- private int promptForConflicts(Shell shell, SyncInfoSet syncSet) {
- String[] buttons = new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL};
- String title = "Confirm Overwrite"; //$NON-NLS-1$
- String question = "You have changes that conflict with the server. Overwrite those changes?"; //$NON-NLS-1$
- final MessageDialog dialog = new MessageDialog(shell, title, null, question, MessageDialog.QUESTION, buttons, 0);
- shell.getDisplay().syncExec(new Runnable() {
- public void run() {
- dialog.open();
- }
- });
- return dialog.getReturnCode();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.examples.filesystem.ui.FileSystemSynchronizeOperation#run(org.eclipse.team.examples.filesystem.FileSystemProvider, org.eclipse.team.core.synchronize.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
- */
- protected void run(FileSystemProvider provider, SyncInfoSet set, IProgressMonitor monitor) throws TeamException {
- provider.getOperations().get(set.getResources(), IResource.DEPTH_INFINITE, true, monitor);
- }
-
-}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ModelPutAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ModelPutAction.java
new file mode 100644
index 000000000..2eddf4662
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ModelPutAction.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * 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 org.eclipse.core.resources.mapping.ResourceMapping;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.team.core.subscribers.SubscriberScopeManager;
+import org.eclipse.team.examples.filesystem.FileSystemPlugin;
+import org.eclipse.team.internal.ui.Utils;
+import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
+import org.eclipse.team.ui.synchronize.ModelParticipantAction;
+
+/**
+ * A put action for use in the file system synchronize participant.
+ */
+public class ModelPutAction extends ModelParticipantAction {
+
+ public ModelPutAction(String text, ISynchronizePageConfiguration configuration) {
+ super(text, configuration);
+ }
+
+ protected boolean isEnabledForSelection(IStructuredSelection selection) {
+ // Only enable the put in outgoing or both modes
+ int mode = getConfiguration().getMode();
+ if (mode == ISynchronizePageConfiguration.OUTGOING_MODE || mode == ISynchronizePageConfiguration.BOTH_MODE) {
+ return getResourceMappings(selection).length > 0;
+ }
+ return false;
+ }
+
+ private ResourceMapping[] getResourceMappings(IStructuredSelection selection) {
+ List mappings = new ArrayList();
+ for (Iterator iter = selection.iterator(); iter.hasNext();) {
+ Object element = iter.next();
+ ResourceMapping mapping = Utils.getResourceMapping(element);
+ if (mapping != null)
+ mappings.add(mapping);
+ }
+ return (ResourceMapping[]) mappings.toArray(new ResourceMapping[mappings.size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ public void run() {
+ ResourceMapping[] resourceMappings = getResourceMappings(getStructuredSelection());
+ SubscriberScopeManager manager = FileSystemOperation.createScopeManager("Put", resourceMappings);
+ try {
+ new PutOperation(getConfiguration().getSite().getPart(), manager).run();
+ } catch (InvocationTargetException e) {
+ IStatus status = getStatus(e);
+ ErrorDialog.openError(getConfiguration().getSite().getShell(), null, null, status);
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ }
+
+ private IStatus getStatus(Throwable throwable) {
+ if (throwable instanceof InvocationTargetException) {
+ return getStatus(((InvocationTargetException) throwable).getCause());
+ }
+ return new Status(IStatus.ERROR, FileSystemPlugin.ID, 0, "An error occurred during the put.", throwable);
+ }
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutAction.java
index f39104392..fe6936a27 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutAction.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutAction.java
@@ -11,18 +11,9 @@
package org.eclipse.team.examples.filesystem.ui;
import java.lang.reflect.InvocationTargetException;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jface.action.IAction;
-import org.eclipse.team.core.TeamException;
-import org.eclipse.team.examples.filesystem.FileSystemProvider;
import org.eclipse.team.examples.filesystem.Policy;
-import org.eclipse.ui.actions.WorkspaceModifyOperation;
/**
* Action for checking in the selected resources
@@ -33,26 +24,16 @@ public class PutAction extends FileSystemAction {
* Method declared on IActionDelegate.
*/
public void run(IAction action) {
- run(new WorkspaceModifyOperation(null) {
- public void execute(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
- try {
- Map table = getRepositoryProviderMapping();
- monitor.beginTask(null, table.size() * 1000);
- monitor.setTaskName(Policy.bind("PutAction.working")); //$NON-NLS-1$
- for (Iterator iter = table.keySet().iterator(); iter.hasNext();) {
- IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1000);
- FileSystemProvider provider = (FileSystemProvider) iter.next();
- List list = (List) table.get(provider);
- IResource[] providerResources = (IResource[]) list.toArray(new IResource[list.size()]);
- provider.getOperations().checkin(providerResources, IResource.DEPTH_INFINITE, isOverrideIncoming(), subMonitor);
- }
- } catch (TeamException e) {
- throw new InvocationTargetException(e);
- } finally {
- monitor.done();
- }
- }
- }, Policy.bind("PutAction.problemMessage"), PROGRESS_DIALOG); //$NON-NLS-1$
+ try {
+ PutOperation operation = new PutOperation(getTargetPart(),
+ FileSystemOperation.createScopeManager(Policy.bind("PutAction.working"), getSelectedMappings())); //$NON-NLS-1$
+ operation.setOverwriteIncoming(isOverrideIncoming());
+ operation.run();
+ } catch (InvocationTargetException e) {
+ handle(e, null, Policy.bind("PutAction.problemMessage")); //$NON-NLS-1$
+ } catch (InterruptedException e) {
+ // Ignore
+ }
}
/**
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutOperation.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutOperation.java
new file mode 100644
index 000000000..032c4d1be
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutOperation.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2005 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.ResourceTraversal;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.team.core.diff.*;
+import org.eclipse.team.core.subscribers.SubscriberScopeManager;
+import org.eclipse.team.examples.filesystem.FileSystemProvider;
+import org.eclipse.team.examples.filesystem.Policy;
+import org.eclipse.team.examples.filesystem.subscriber.FileSystemSubscriber;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * Operation for copying the selected resources to the file system location
+ */
+public class PutOperation extends FileSystemOperation {
+
+ private boolean overwriteIncoming;
+
+ /**
+ * Create the put operation
+ * @param part the originating part
+ * @param manager the scope manager
+ */
+ protected PutOperation(IWorkbenchPart part, SubscriberScopeManager manager) {
+ super(part, manager);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.examples.filesystem.ui.FileSystemOperation#execute(org.eclipse.team.examples.filesystem.FileSystemProvider, org.eclipse.core.resources.mapping.ResourceTraversal[], org.eclipse.core.runtime.SubProgressMonitor)
+ */
+ protected void execute(FileSystemProvider provider,
+ ResourceTraversal[] traversals, IProgressMonitor monitor)
+ throws CoreException {
+ provider.getOperations().checkin(traversals, isOverwriteIncoming(), monitor);
+ if (!isOverwriteIncoming() && hasOutgoingChanges(traversals)) {
+ MessageDialog.openInformation(getShell(), "Conflicts", "Could not put all changes due to conflicts.");
+ }
+
+ }
+
+ private boolean hasOutgoingChanges(ResourceTraversal[] traversals) throws CoreException {
+ final RuntimeException found = new RuntimeException();
+ try {
+ FileSystemSubscriber.getInstance().accept(traversals, new IDiffVisitor() {
+ public boolean visit(IDiff diff) {
+ if (diff instanceof IThreeWayDiff) {
+ IThreeWayDiff twd = (IThreeWayDiff) diff;
+ if (twd.getDirection() == IThreeWayDiff.OUTGOING || twd.getDirection() == IThreeWayDiff.CONFLICTING) {
+ throw found;
+ }
+ }
+ return false;
+ }
+ });
+ } catch (RuntimeException e) {
+ if (e == found)
+ return true;
+ throw e;
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.examples.filesystem.ui.FileSystemOperation#getTaskName()
+ */
+ protected String getTaskName() {
+ return Policy.bind("PutAction.working"); //$NON-NLS-1$
+ }
+
+ /**
+ * Return whether incoming changes should be overwritten.
+ * @return whether incoming changes should be overwritten
+ */
+ public boolean isOverwriteIncoming() {
+ return overwriteIncoming;
+ }
+
+ /**
+ * Set whether incoming changes should be overwritten.
+ * @param overwriteIncoming whether incoming changes should be overwritten
+ */
+ public void setOverwriteIncoming(boolean overwriteIncoming) {
+ this.overwriteIncoming = overwriteIncoming;
+ }
+
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutSynchronizeAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutSynchronizeAction.java
deleted file mode 100644
index 6b27f23f1..000000000
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutSynchronizeAction.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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.structuremergeviewer.IDiffElement;
-import org.eclipse.team.core.synchronize.FastSyncInfoFilter;
-import org.eclipse.team.core.synchronize.SyncInfo;
-import org.eclipse.team.core.synchronize.FastSyncInfoFilter.SyncInfoDirectionFilter;
-import org.eclipse.team.ui.synchronize.*;
-
-/**
- * Put action that appears in the synchronize view. It's main purpose is
- * to filter the selection and delegate its execution to the put operation.
- */
-public class PutSynchronizeAction extends SynchronizeModelAction {
-
- public PutSynchronizeAction(String text, ISynchronizePageConfiguration configuration) {
- super(text, configuration);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#getSyncInfoFilter()
- */
- protected FastSyncInfoFilter getSyncInfoFilter() {
- return new SyncInfoDirectionFilter(new int[] {SyncInfo.OUTGOING, SyncInfo.CONFLICTING});
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#getSubscriberOperation(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration, org.eclipse.compare.structuremergeviewer.IDiffElement[])
- */
- protected SynchronizeModelOperation getSubscriberOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) {
- return new PutSynchronizeOperation(configuration, elements);
- }
-}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutSynchronizeOperation.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutSynchronizeOperation.java
deleted file mode 100644
index 18aafdcaf..000000000
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutSynchronizeOperation.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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.structuremergeviewer.IDiffElement;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.team.core.TeamException;
-import org.eclipse.team.core.synchronize.SyncInfoSet;
-import org.eclipse.team.examples.filesystem.FileSystemProvider;
-import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
-
-/**
- * Sync view operation for putting file system resources
- */
-public class PutSynchronizeOperation extends FileSystemSynchronizeOperation {
-
- protected PutSynchronizeOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) {
- super(configuration, elements);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.examples.filesystem.ui.FileSystemSynchronizeOperation#promptForConflictHandling(org.eclipse.swt.widgets.Shell, org.eclipse.team.core.synchronize.SyncInfoSet)
- */
- protected boolean promptForConflictHandling(Shell shell, SyncInfoSet syncSet) {
- // If there is a conflict in the syncSet, we need to prompt the user before proceeding.
- if (syncSet.hasConflicts() || syncSet.hasIncomingChanges()) {
- switch (promptForConflicts(shell, syncSet)) {
- case 0:
- // Yes, synchronize conflicts as well
- break;
- case 1:
- // No, stop here
- syncSet.removeConflictingNodes();
- syncSet.removeIncomingNodes();
- break;
- case 2:
- default:
- // Cancel
- return false;
- }
- }
- return true;
- }
-
- /**
- * Prompts the user to determine how conflicting changes should be handled.
- * Note: This method is designed to be overridden by test cases.
- * @return 0 to sync conflicts, 1 to sync all non-conflicts, 2 to cancel
- */
- private int promptForConflicts(Shell shell, SyncInfoSet syncSet) {
- String[] buttons = new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL};
- String title = "Confirm Overwrite"; //$NON-NLS-1$
- String question = "You have changes that conflict with the server. Release those changes?"; //$NON-NLS-1$
- final MessageDialog dialog = new MessageDialog(shell, title, null, question, MessageDialog.QUESTION, buttons, 0);
- shell.getDisplay().syncExec(new Runnable() {
- public void run() {
- dialog.open();
- }
- });
- return dialog.getReturnCode();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.examples.filesystem.ui.FileSystemSynchronizeOperation#run(org.eclipse.team.examples.filesystem.FileSystemProvider, org.eclipse.team.core.synchronize.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
- */
- protected void run(FileSystemProvider provider, SyncInfoSet set, IProgressMonitor monitor) throws TeamException {
- provider.getOperations().checkin(set.getResources(), IResource.DEPTH_INFINITE, true, monitor);
- }
-
-}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeAction.java
index 0f609b5d2..5bdfa4328 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeAction.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeAction.java
@@ -10,10 +10,13 @@
*******************************************************************************/
package org.eclipse.team.examples.filesystem.ui;
-import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.jface.action.IAction;
+import org.eclipse.team.core.subscribers.SubscriberScopeManager;
+import org.eclipse.team.examples.filesystem.subscriber.FileSystemMergeContext;
+import org.eclipse.team.examples.filesystem.subscriber.FileSystemSubscriber;
import org.eclipse.team.ui.TeamUI;
-import org.eclipse.team.ui.synchronize.*;
+import org.eclipse.team.ui.synchronize.ISynchronizeParticipant;
/**
* Action to synchronize the selected resources. This results
@@ -25,16 +28,14 @@ public class SynchronizeAction extends FileSystemAction {
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
public void run(IAction action) {
- IResource[] resources = getSelectedResources();
- // First check if there is an existing matching participant
- FileSystemSynchronizeParticipant participant = (FileSystemSynchronizeParticipant)SubscriberParticipant.getMatchingParticipant(FileSystemSynchronizeParticipant.ID, resources);
- // If there isn't, create one and add to the manager
- if (participant == null) {
- participant = new FileSystemSynchronizeParticipant(new ResourceScope(resources));
- TeamUI.getSynchronizeManager().addSynchronizeParticipants(new ISynchronizeParticipant[] {participant});
- }
- participant.refresh(resources, null, null, getTargetPart().getSite());
-
+ ResourceMapping[] mappings = getSelectedMappings();
+ if (mappings.length == 0)
+ return;
+ SubscriberScopeManager manager = FileSystemOperation.createScopeManager(FileSystemSubscriber.getInstance().getName(), mappings);
+ FileSystemMergeContext context = new FileSystemMergeContext(manager);
+ FileSystemSynchronizeParticipant participant = new FileSystemSynchronizeParticipant(context);
+ TeamUI.getSynchronizeManager().addSynchronizeParticipants(new ISynchronizeParticipant[] {participant});
+ participant.run(getTargetPart());
}
}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeWizard.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeWizard.java
index d86eb92f7..4950efb80 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeWizard.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeWizard.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * Copyright (c) 2000, 20046 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
@@ -11,58 +11,58 @@
package org.eclipse.team.examples.filesystem.ui;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.jface.wizard.IWizard;
-import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.team.core.subscribers.SubscriberScopeManager;
+import org.eclipse.team.examples.filesystem.subscriber.FileSystemMergeContext;
import org.eclipse.team.examples.filesystem.subscriber.FileSystemSubscriber;
-import org.eclipse.team.internal.ui.ITeamUIImages;
-import org.eclipse.team.internal.ui.TeamUIMessages;
-import org.eclipse.team.internal.ui.synchronize.GlobalRefreshResourceSelectionPage;
-import org.eclipse.team.ui.TeamImages;
-import org.eclipse.team.ui.TeamUI;
import org.eclipse.team.ui.synchronize.ISynchronizeParticipant;
-import org.eclipse.team.ui.synchronize.SubscriberParticipant;
+import org.eclipse.team.ui.synchronize.ModelParticipantWizard;
-public class SynchronizeWizard extends Wizard {
- private GlobalRefreshResourceSelectionPage selectionPage;
+/**
+ * This class is registered as the file system synchronization wizard.
+ */
+public class SynchronizeWizard extends ModelParticipantWizard {
private IWizard importWizard;
+ /*
+ * Default no-arg constructor
+ */
public SynchronizeWizard() {
- setDefaultPageImageDescriptor(TeamImages.getImageDescriptor(ITeamUIImages.IMG_WIZBAN_SHARE));
- setNeedsProgressMonitor(false);
+ super();
}
-
+
/* (non-Javadoc)
- * @see org.eclipse.jface.wizard.Wizard#getWindowTitle()
+ * @see org.eclipse.team.ui.synchronize.ModelParticipantWizard#createParticipant(org.eclipse.core.resources.mapping.ResourceMapping[])
*/
- public String getWindowTitle() {
- return TeamUIMessages.GlobalRefreshSubscriberPage_0;
+ protected ISynchronizeParticipant createParticipant(ResourceMapping[] selectedMappings) {
+ SubscriberScopeManager manager = FileSystemOperation.createScopeManager(FileSystemSubscriber.getInstance().getName(), selectedMappings);
+ FileSystemMergeContext context = new FileSystemMergeContext(manager);
+ FileSystemSynchronizeParticipant participant = new FileSystemSynchronizeParticipant(context);
+ return participant;
}
-
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.synchronize.ParticipantSynchronizeWizard#getImportWizard()
+ */
+ protected IWizard getImportWizard() {
+ // We don't have an import wizard for the file system example but
+ // if we did, we could return it here and it would be used if the
+ // getRoots method returned an empty array.
+ return importWizard;
+ }
+
/* (non-Javadoc)
- * @see org.eclipse.jface.wizard.Wizard#addPages()
+ * @see org.eclipse.team.ui.synchronize.ParticipantSynchronizeWizard#getPageTitle()
*/
- public void addPages() {
- selectionPage = new GlobalRefreshResourceSelectionPage(FileSystemSubscriber.getInstance().roots());
- selectionPage.setTitle("Synchronize File System Example");
- selectionPage.setMessage("Synchronize File System Example");
- addPage(selectionPage);
+ protected String getPageTitle() {
+ return "Synchronize File System Example";
}
/* (non-Javadoc)
- * @see org.eclipse.jface.wizard.IWizard#performFinish()
+ * @see org.eclipse.team.ui.synchronize.ParticipantSynchronizeWizard#getRootResources()
*/
- public boolean performFinish() {
- if (importWizard != null) {
- return importWizard.performFinish();
- } else {
- IResource[] resources = selectionPage.getRootResources();
- if (resources != null && resources.length > 0) {
- SubscriberParticipant participant = new FileSystemSynchronizeParticipant(selectionPage.getSynchronizeScope());
- TeamUI.getSynchronizeManager().addSynchronizeParticipants(new ISynchronizeParticipant[]{participant});
- // We don't know in which site to show progress because a participant could actually be shown in multiple sites.
- participant.run(null /* no site */);
- }
- return true;
- }
+ protected IResource[] getRootResources() {
+ return FileSystemSubscriber.getInstance().roots();
}
}

Back to the top