Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2006-05-15 19:05:48 +0000
committerMichael Valenta2006-05-15 19:05:48 +0000
commitd5c1567423e9ee1ecfb18b851f6b8e7d6e80aeb0 (patch)
tree23996ff9d1a09bdfbd3884b54a904511b5b47841 /examples/org.eclipse.team.examples.filesystem
parentbdb667cfbe9ef8fa054556dec9b0207685bd075a (diff)
downloadeclipse.platform.team-d5c1567423e9ee1ecfb18b851f6b8e7d6e80aeb0.tar.gz
eclipse.platform.team-d5c1567423e9ee1ecfb18b851f6b8e7d6e80aeb0.tar.xz
eclipse.platform.team-d5c1567423e9ee1ecfb18b851f6b8e7d6e80aeb0.zip
Working on synchronization example
Diffstat (limited to 'examples/org.eclipse.team.examples.filesystem')
-rw-r--r--examples/org.eclipse.team.examples.filesystem/plugin.xml41
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemProvider.java31
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemMergeContext.java25
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemSubscriber.java41
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemSyncInfo.java6
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemSynchronizeParticipant.java10
6 files changed, 118 insertions, 36 deletions
diff --git a/examples/org.eclipse.team.examples.filesystem/plugin.xml b/examples/org.eclipse.team.examples.filesystem/plugin.xml
index 968451ae6..d93fd146a 100644
--- a/examples/org.eclipse.team.examples.filesystem/plugin.xml
+++ b/examples/org.eclipse.team.examples.filesystem/plugin.xml
@@ -102,6 +102,47 @@
</extension>
<!-- =================================================================================== -->
+<!-- Common Navigator viewer for the file systen synchronizations -->
+<!-- =================================================================================== -->
+ <extension
+ point="org.eclipse.ui.navigator.viewer">
+ <viewer
+ viewerId="org.eclipse.team.examples.filesystem.syncViewer">
+ <popupMenu
+ allowsPlatformContributions="false"
+ id="org.eclipse.team.examples.filesystem.syncViewer#PopupMenu">
+ <insertionPoint name="file"/>
+ <insertionPoint name="edit"/>
+ <insertionPoint name="synchronize"/>
+ <insertionPoint
+ name="navigate"
+ separator="true"/>
+ <insertionPoint
+ name="merge"
+ separator="true"/>
+ <insertionPoint
+ name="put"
+ separator="false"/>
+ <insertionPoint
+ name="overwrite"
+ separator="true"/>
+ <insertionPoint
+ name="other"
+ separator="true"/>
+ <insertionPoint
+ name="sort"
+ separator="true"/>
+ <insertionPoint
+ name="additions"
+ separator="true"/>
+ <insertionPoint
+ name="properties"
+ separator="true"/>
+ </popupMenu>
+ </viewer>
+ </extension>
+
+<!-- =================================================================================== -->
<!-- Menus for File System Example -->
<!-- =================================================================================== -->
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 f75016dda..102c0dbcc 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
@@ -12,12 +12,9 @@ package org.eclipse.team.examples.filesystem;
import java.io.File;
-import org.eclipse.core.resources.IFileModificationValidator;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.core.resources.*;
+import org.eclipse.core.resources.team.ResourceRuleFactory;
+import org.eclipse.core.runtime.*;
import org.eclipse.team.core.RepositoryProvider;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.variants.IResourceVariant;
@@ -28,21 +25,21 @@ import org.eclipse.team.examples.filesystem.subscriber.FileSystemSubscriber;
* This example illustrates how to create a concrete implementation of a <code>RepositoryProvider</code>
* that uses the file system to act as the repository. See the plugin.xml file for the xml required
* to register this provider with the Team extension point <code>org.eclipse.team.core.repository</code>.
- * The plugin.xml file also contains examples of how to filter menu items using a repsitory provider's
+ * The plugin.xml file also contains examples of how to filter menu items using a repository provider's
* ID.
*
* <p>
* This example provider illustrates the following:
* <ol>
* <li>simple working implementation of <code>RepositoyProvider</code>
- * <li>storage of a persistant property with the project (which provides the target location for the provider)
+ * <li>storage of a persistent property with the project (which provides the target location for the provider)
* <li>access to an instance of <code>SimpleAccessOperations</code> for performing simple file operations
* </ol>
*
* <p>
* Additional functionality that will be illustrated in the future include:
* <ol>
- * <li>Validate Save/Validat Edit
+ * <li>Validate Save/Validate Edit
* <li>Move/Delete Hook
* <li>Project Sets
* <li>Use of the workspace synchronizer (ISynchronizer)
@@ -53,10 +50,17 @@ import org.eclipse.team.examples.filesystem.subscriber.FileSystemSubscriber;
*/
public class FileSystemProvider extends RepositoryProvider {
+ /*
+ * Create a custom rule factory to allow more optimistic concurrency
+ */
+ private static final ResourceRuleFactory RESOURCE_RULE_FACTORY = new ResourceRuleFactory() {
+ // Just need a subclass to instantiate
+ };
+
// The location of the folder on file system where the repository is stored.
private IPath root;
- // The QualifiedName that is used to persist the location accross workspace as a persistant property on a resource
+ // The QualifiedName that is used to persist the location across workspace as a persistent property on a resource
private static QualifiedName FILESYSTEM_REPO_LOC = new QualifiedName(FileSystemPlugin.ID, "disk_location"); //$NON-NLS-1$
/**
@@ -203,5 +207,12 @@ public class FileSystemProvider extends RepositoryProvider {
}
return null;
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.core.RepositoryProvider#getRuleFactory()
+ */
+ public IResourceRuleFactory getRuleFactory() {
+ return RESOURCE_RULE_FACTORY;
+ }
}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemMergeContext.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemMergeContext.java
index b4e9a5ba4..35bacf4f0 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemMergeContext.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemMergeContext.java
@@ -10,10 +10,13 @@
*******************************************************************************/
package org.eclipse.team.examples.filesystem.subscriber;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.team.core.diff.IDiff;
import org.eclipse.team.core.mapping.ISynchronizationScopeManager;
+import org.eclipse.team.core.mapping.provider.ResourceDiffTree;
import org.eclipse.team.core.subscribers.SubscriberMergeContext;
/**
@@ -35,17 +38,18 @@ public class FileSystemMergeContext extends SubscriberMergeContext {
*/
protected void makeInSync(IDiff diff, IProgressMonitor monitor)
throws CoreException {
- // TODO Auto-generated method stub
-
+ IResource resource = ResourceDiffTree.getResourceFor(diff);
+ FileSystemSubscriber.getInstance().makeInSync(resource);
}
/* (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,
+ public void markAsMerged(IDiff diff, boolean inSyncHint,
IProgressMonitor monitor) throws CoreException {
- // TODO Auto-generated method stub
-
+ // TODO if inSyncHint is true, we should test to see if the contents match
+ IResource resource = ResourceDiffTree.getResourceFor(diff);
+ FileSystemSubscriber.getInstance().markAsMerged(resource, monitor);
}
/* (non-Javadoc)
@@ -53,8 +57,15 @@ public class FileSystemMergeContext extends SubscriberMergeContext {
*/
public void reject(IDiff diff, IProgressMonitor monitor)
throws CoreException {
- // TODO Auto-generated method stub
-
+ markAsMerged(diff, false, monitor);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.core.mapping.provider.MergeContext#getMergeRule(org.eclipse.team.core.diff.IDiff)
+ */
+ public ISchedulingRule getMergeRule(IDiff node) {
+ return ResourceDiffTree.getResourceFor(node).getProject();
}
+
}
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 ed8ff1ce1..482a57d35 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
@@ -13,17 +13,12 @@ package org.eclipse.team.examples.filesystem.subscriber;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.core.resources.*;
+import org.eclipse.core.runtime.*;
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;
-import org.eclipse.team.core.variants.ThreeWaySynchronizer;
+import org.eclipse.team.core.variants.*;
import org.eclipse.team.examples.filesystem.FileSystemPlugin;
import org.eclipse.team.examples.filesystem.FileSystemProvider;
@@ -123,4 +118,34 @@ public class FileSystemSubscriber extends ThreeWaySubscriber {
return info;
}
+ /**
+ * Make the resource in-sync.
+ * @param resource the resource
+ * @throws TeamException
+ */
+ public void makeInSync(IResource resource) throws TeamException {
+ ThreeWaySynchronizer synchronizer = getSynchronizer();
+ byte[] remoteBytes = synchronizer.getRemoteBytes(resource);
+ if (remoteBytes == null) {
+ if (!resource.exists())
+ synchronizer.flush(resource, IResource.DEPTH_ZERO);
+ } else {
+ synchronizer.setBaseBytes(resource, remoteBytes);
+ }
+ }
+
+ /**
+ * Make the change an outgoing change
+ * @param resource
+ * @throws TeamException
+ */
+ public void markAsMerged(IResource resource, IProgressMonitor monitor) throws TeamException {
+ makeInSync(resource);
+ try {
+ resource.touch(monitor);
+ } catch (CoreException e) {
+ throw TeamException.asTeamException(e);
+ }
+ }
+
}
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
index 38f7d9d0f..b330bedd1 100644
--- 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
@@ -46,9 +46,9 @@ public class FileSystemSyncInfo extends SyncInfo {
// 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;
- }
+// 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/FileSystemSynchronizeParticipant.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemSynchronizeParticipant.java
index b9fafceb9..ac8eafd39 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
@@ -55,7 +55,7 @@ public class FileSystemSynchronizeParticipant extends ModelSynchronizeParticipan
* 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$
+ public static final String CONTEXT_MENU_OVERWRITE_GROUP_1 = "overwrite"; //$NON-NLS-1$
/**
* A custom label decorator that will show the remote mapped path for each
@@ -111,17 +111,11 @@ public class FileSystemSynchronizeParticipant extends ModelSynchronizeParticipan
*/
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);
}
@@ -134,7 +128,7 @@ public class FileSystemSynchronizeParticipant extends ModelSynchronizeParticipan
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);
+ group = manager.find(CONTEXT_MENU_OVERWRITE_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);

Back to the top