Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2004-06-15 16:22:35 -0400
committerMichael Valenta2004-06-15 16:22:35 -0400
commit9df2564d62f032730f5c2f09e248be463ce22185 (patch)
tree0582db917da7adcb1dfadf49c8d3b1d981b68369 /examples
parent69900eca5aac470ed37963d55c4d69c07d094e38 (diff)
downloadeclipse.platform.team-9df2564d62f032730f5c2f09e248be463ce22185.tar.gz
eclipse.platform.team-9df2564d62f032730f5c2f09e248be463ce22185.tar.xz
eclipse.platform.team-9df2564d62f032730f5c2f09e248be463ce22185.zip
Updating examplea
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.team.examples.filesystem/plugin.properties2
-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/FileSystemProvider.java1
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemSubscriber.java11
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemSyncInfo.java54
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemAction.java8
-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.java52
-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/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.java40
13 files changed, 511 insertions, 15 deletions
diff --git a/examples/org.eclipse.team.examples.filesystem/plugin.properties b/examples/org.eclipse.team.examples.filesystem/plugin.properties
index 95cd7e114..246f0c863 100644
--- a/examples/org.eclipse.team.examples.filesystem/plugin.properties
+++ b/examples/org.eclipse.team.examples.filesystem/plugin.properties
@@ -11,6 +11,8 @@
pluginName = Eclipse Team File System Example
providerName=Eclipse.org
+Synchronize.name=Synchronize
+Synchronize.tooltip=Synchronize the selected resources
Put.name=Put
Put.tooltip=Copy resources to the shared file system location
Get.name=Get
diff --git a/examples/org.eclipse.team.examples.filesystem/plugin.xml b/examples/org.eclipse.team.examples.filesystem/plugin.xml
index 1713f551e..fbbe41d5c 100644
--- a/examples/org.eclipse.team.examples.filesystem/plugin.xml
+++ b/examples/org.eclipse.team.examples.filesystem/plugin.xml
@@ -96,6 +96,13 @@
value="org.eclipse.team.core.repository=org.eclipse.team.examples.filesystem.FileSystemProvider">
</filter>
<action
+ label="%Synchronize.name"
+ tooltip="%Synchronize.tooltip"
+ class="org.eclipse.team.examples.filesystem.ui.SynchronizeAction"
+ menubarPath="team.main/group1"
+ id="org.eclipse.team.examples.filesystem.synchronize">
+ </action>
+ <action
label="%Get.name"
tooltip="%Get.tooltip"
class="org.eclipse.team.examples.filesystem.ui.GetAction"
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 a7596be7f..043b79033 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
@@ -172,6 +172,7 @@ public class FileSystemProvider extends RepositoryProvider {
* @return the resource variant handle
*/
public IResourceVariant getResourceVariant(IResource resource, byte[] bytes) {
+ if (bytes == null) return null;
File file = getFile(resource);
if (file == null) return null;
return new FileSystemResourceVariant(file, bytes);
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemSubscriber.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemSubscriber.java
index bcf8c8938..bc7f42a29 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemSubscriber.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemSubscriber.java
@@ -19,6 +19,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.team.core.RepositoryProvider;
import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.synchronize.SyncInfo;
import org.eclipse.team.core.variants.IResourceVariant;
import org.eclipse.team.core.variants.ThreeWayRemoteTree;
import org.eclipse.team.core.variants.ThreeWaySubscriber;
@@ -111,5 +112,15 @@ public class FileSystemSubscriber extends ThreeWaySubscriber {
// Override to allow FileSystemProvider to signal the addition and removal of roots
super.handleRootChanged(resource, added);
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.core.variants.ResourceVariantTreeSubscriber#getSyncInfo(org.eclipse.core.resources.IResource, org.eclipse.team.core.variants.IResourceVariant, org.eclipse.team.core.variants.IResourceVariant)
+ */
+ protected SyncInfo getSyncInfo(IResource local, IResourceVariant base, IResourceVariant remote) throws TeamException {
+ // Override to use a custom sync info
+ FileSystemSyncInfo info = new FileSystemSyncInfo(local, base, remote, this.getResourceComparator());
+ info.init();
+ return info;
+ }
}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemSyncInfo.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemSyncInfo.java
new file mode 100644
index 000000000..6f9f52d69
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemSyncInfo.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.examples.filesystem.subscriber;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.synchronize.SyncInfo;
+import org.eclipse.team.core.variants.IResourceVariant;
+import org.eclipse.team.core.variants.IResourceVariantComparator;
+
+/**
+ * Provide a custom sync info that will report files that exist both
+ * locally and remotely as in-sync and will return a null base if there
+ * is an incoming change.
+ */
+public class FileSystemSyncInfo extends SyncInfo {
+
+ public FileSystemSyncInfo(IResource local, IResourceVariant base, IResourceVariant remote, IResourceVariantComparator comparator) {
+ super(local, base, remote, comparator);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.core.subscribers.SyncInfo#calculateKind(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected int calculateKind() throws TeamException {
+ if (getLocal().getType() != IResource.FILE) {
+ if (getLocal().exists() && getRemote() != null) {
+ return IN_SYNC;
+ }
+ }
+ return super.calculateKind();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.core.synchronize.SyncInfo#getBase()
+ */
+ public IResourceVariant getBase() {
+ // If the kind has been set and there is an incoming change
+ // return null as the base since the server does not keep the
+ // base contents
+ if ((getKind() & INCOMING) > 0) {
+ return null;
+ }
+ return super.getBase();
+ }
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemAction.java
index e3a5da71f..2b407f203 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemAction.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemAction.java
@@ -10,14 +10,10 @@
*******************************************************************************/
package org.eclipse.team.examples.filesystem.ui;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import org.eclipse.core.resources.IResource;
import org.eclipse.team.core.RepositoryProvider;
-import org.eclipse.team.core.TeamException;
import org.eclipse.team.examples.filesystem.FileSystemPlugin;
import org.eclipse.team.internal.ui.actions.TeamAction;
@@ -47,7 +43,7 @@ public abstract class FileSystemAction extends TeamAction {
/**
* Split the resources into sets associated with their project/provider
*/
- protected Map getRepositoryProviderMapping() throws TeamException {
+ protected Map getRepositoryProviderMapping() {
HashMap result = new HashMap();
IResource[] resources = getSelectedResources();
for (int i = 0; i < resources.length; i++) {
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
new file mode 100644
index 000000000..2795419df
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemSynchronizeOperation.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-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 0dec4224c..f3003b0b0 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
@@ -21,11 +21,7 @@ import org.eclipse.team.core.synchronize.SyncInfo;
import org.eclipse.team.core.variants.IResourceVariant;
import org.eclipse.team.examples.filesystem.subscriber.FileSystemSubscriber;
import org.eclipse.team.ui.TeamUI;
-import org.eclipse.team.ui.synchronize.ISynchronizeModelElement;
-import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
-import org.eclipse.team.ui.synchronize.ISynchronizeParticipantDescriptor;
-import org.eclipse.team.ui.synchronize.ISynchronizeScope;
-import org.eclipse.team.ui.synchronize.SubscriberParticipant;
+import org.eclipse.team.ui.synchronize.*;
/**
@@ -37,18 +33,27 @@ import org.eclipse.team.ui.synchronize.SubscriberParticipant;
*/
public class FileSystemSynchronizeParticipant extends SubscriberParticipant {
- private static final String ID = "org.eclipse.team.examples.filesystem.participant"; //$NON-NLS-1$
+ /**
+ * The particpant ID as defined in the plugin manifest
+ */
+ public static final String ID = "org.eclipse.team.examples.filesystem.participant"; //$NON-NLS-1$
+
+ /**
+ * Contxt menu action group for synchronize view actions
+ */
+ public static final String CONTEXT_MENU_CONTRIBUTION_GROUP_1 = "context_group_1"; //$NON-NLS-1$
/**
* A custom label decorator that will show the remote mapped path for each
* file.
*/
private 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;
}
-
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelDecorator#decorateText(java.lang.String, java.lang.Object)
*/
@@ -56,7 +61,7 @@ public class FileSystemSynchronizeParticipant extends SubscriberParticipant {
try {
if (element instanceof ISynchronizeModelElement) {
IResource resource = ((ISynchronizeModelElement) element).getResource();
- if (resource != null) {
+ if (resource != null && resource.getType() == IResource.FILE) {
SyncInfo info = FileSystemSubscriber.getInstance().getSyncInfo(resource);
IResourceVariant variant = info.getRemote();
if (variant != null) {
@@ -70,6 +75,28 @@ 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 {
+ /* (non-Javadoc)
+ * @see org.eclipse.team.ui.synchronize.SynchronizePageActionGroup#initialize(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration)
+ */
+ public void initialize(ISynchronizePageConfiguration configuration) {
+ 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));
+ }
+
+ }
+
public FileSystemSynchronizeParticipant(ISynchronizeScope scope) {
super(scope);
setSubscriber(FileSystemSubscriber.getInstance());
@@ -101,5 +128,12 @@ public class FileSystemSynchronizeParticipant extends SubscriberParticipant {
// 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);
}
}
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
new file mode 100644
index 000000000..307598713
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeAction.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-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
new file mode 100644
index 000000000..067861739
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeOperation.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-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/PutSynchronizeAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutSynchronizeAction.java
new file mode 100644
index 000000000..d6234c606
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutSynchronizeAction.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-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
new file mode 100644
index 000000000..91fdf4db1
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutSynchronizeOperation.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-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
new file mode 100644
index 000000000..f19d9aa33
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeAction.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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 Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.examples.filesystem.ui;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.team.ui.TeamUI;
+import org.eclipse.team.ui.synchronize.*;
+
+/**
+ * Action to synchronize the selected resources. This results
+ * in a file-system participant being added to the synchronize view.
+ */
+public class SynchronizeAction extends FileSystemAction {
+
+ /* (non-Javadoc)
+ * @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, "Synchronizing", "Synchronizing " + participant.getName(), getTargetPart().getSite());
+
+ }
+
+}

Back to the top