Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2002-06-19 16:02:32 +0000
committerMichael Valenta2002-06-19 16:02:32 +0000
commit09c2fe28fc16787e12cc0c0c9e960c8ebd0c858b (patch)
tree66ee6220f06c5009405d5d1ff6594e7190ebe13f
parent081cb4686993423b5ff6d2737cb3e3f3f2666ac3 (diff)
downloadeclipse.platform.team-09c2fe28fc16787e12cc0c0c9e960c8ebd0c858b.tar.gz
eclipse.platform.team-09c2fe28fc16787e12cc0c0c9e960c8ebd0c858b.tar.xz
eclipse.platform.team-09c2fe28fc16787e12cc0c0c9e960c8ebd0c858b.zip
Added validateSave/validateEdit
-rw-r--r--examples/org.eclipse.team.examples.filesystem/plugin.properties7
-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/FileModificationValidator.java89
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemProvider.java9
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemRemoteResource.java62
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemSimpleAccessOperations.java140
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/messages.properties6
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetAction.java2
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ReplaceAction.java82
9 files changed, 366 insertions, 38 deletions
diff --git a/examples/org.eclipse.team.examples.filesystem/plugin.properties b/examples/org.eclipse.team.examples.filesystem/plugin.properties
index c162efada..26f7fd8cb 100644
--- a/examples/org.eclipse.team.examples.filesystem/plugin.properties
+++ b/examples/org.eclipse.team.examples.filesystem/plugin.properties
@@ -1,4 +1,4 @@
-pluginName = Eclipse Team File System Examples
+pluginName = Eclipse Team File System Example
Put.name=Put
Put.tooltip=Copy resources to the shared file system location
@@ -6,6 +6,11 @@ Get.name=Get
Get.tooltip=Copy resources from the shared file system location to the workbench
Unmanage.name=Unmanage
Unmanage.tooltip=Mark resources as not-shared
+
+Replace.name=Replace with remote
+Replace.tooltip=Overwrites the local copy of this resource with the one in the repository
+
+
fspropertypage.name=FileSystem Provider
fspropertypage.tooltip=An example repository provider that uses the filesystem to provide storage.
fswizard.name=File System Example (Non-Versioning)
diff --git a/examples/org.eclipse.team.examples.filesystem/plugin.xml b/examples/org.eclipse.team.examples.filesystem/plugin.xml
index c6624ad48..0ab7063a1 100644
--- a/examples/org.eclipse.team.examples.filesystem/plugin.xml
+++ b/examples/org.eclipse.team.examples.filesystem/plugin.xml
@@ -51,6 +51,13 @@
menubarPath="team.main/group1"
id="org.eclipse.team.examples.filesystem.put">
</action>
+ <action
+ label="%Replace.name"
+ tooltip="%ReplaceAction.tooltip"
+ class="org.eclipse.team.examples.filesystem.ui.ReplaceAction"
+ menubarPath="replaceWithMenu/replaceWithGroup"
+ id="org.eclipse.team.examples.filesystem.replace">
+ </action>
</objectContribution>
<objectContribution
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileModificationValidator.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileModificationValidator.java
new file mode 100644
index 000000000..dc118f07c
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileModificationValidator.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2002 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ ******************************************************************************/
+package org.eclipse.team.examples.filesystem;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFileModificationValidator;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.team.core.RepositoryProvider;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.internal.core.simpleAccess.SimpleAccessOperations;
+import sun.security.action.GetPropertyAction;
+
+/**
+ * This class models a sentry that verifies whether resources are available for editing or overwriting.
+ * This has been made a separate clas for illustration purposes. It may have been more apporpriate
+ * to have FileSystemProvider implement IFileModificationValidator itself since the interface
+ * only has two methods and their implementation is straight forward.
+ */
+public final class FileModificationValidator implements IFileModificationValidator {
+ //Used to avoid creating multiple copies of the OK status:
+ private static final IStatus OK_STATUS = new Status(Status.OK, FileSystemPlugin.ID, Status.OK, Policy.bind("ok"), null);
+
+ private RepositoryProvider provider;
+ private SimpleAccessOperations operations;
+
+ /**
+ * Constructor for FileModificationValidator.
+ */
+ public FileModificationValidator(RepositoryProvider provider) {
+ this.provider = provider;
+ operations = provider.getSimpleAccess();
+ }
+
+ /**
+ * This method will convert any exceptions thrown by the SimpleAccessOperations.chechout() to a Status.
+ * @param resources the resources that are to be checked out
+ * @return IStatus a status indicator that reports whether the operation went smoothly or not.
+ * @see org.eclipse.team.internal.core.simpleAccess.SimpleAccessOperations#chechout(IResource[] resources, int depth, IProgressMonitor progress)
+ */
+ private IStatus checkout(IResource[] resources) {
+ try {
+ operations.checkout(resources, IResource.DEPTH_INFINITE, null);
+ } catch (TeamException e) {
+ return new Status(Status.ERROR, FileSystemPlugin.ID, Status.ERROR, e.getLocalizedMessage(), e);
+ }
+ return OK_STATUS;
+ }
+
+ /**
+ * This method will be called by the workbench/editor before it tries to edit one or more files.
+ * The idea is to prevent anyone from accidentally working on a file that they won't be able to check in changes to.
+ * @see org.eclipse.core.resources.IFileModificationValidator#validateEdit(IFile[], Object)
+ */
+ public IStatus validateEdit(IFile[] files, Object context) {
+ Collection toBeCheckedOut = new ArrayList();
+
+ //Make a list of all the files that need to be checked out:
+ for (int i = 0; i < files.length; i++) {
+ if (!operations.isCheckedOut(files[i])) {
+ toBeCheckedOut.add(files[i]);
+ }
+ }
+
+ return checkout((IResource[]) toBeCheckedOut.toArray(new IResource[toBeCheckedOut.size()]));
+ }
+
+ /**
+ * This method will be called by the workbench before it tries to save a file.
+ * It should not attempt to save any files that don't recieve an OK status here.
+ * @see org.eclipse.core.resources.IFileModificationValidator#validateSave(IFile)
+ */
+ public IStatus validateSave(IFile file) {
+ return checkout(new IResource[] { file });
+ }
+
+}
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 053ad5db1..e0666e517 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
@@ -15,8 +15,10 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.security.Provider;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFileModificationValidator;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ISynchronizer;
@@ -167,4 +169,11 @@ public class FileSystemProvider extends RepositoryProvider {
public SimpleAccessOperations getSimpleAccess() {
return new FileSystemSimpleAccessOperations(this);
}
+ /**
+ * @see org.eclipse.team.core.RepositoryProvider#getFileModificationValidator()
+ */
+ public IFileModificationValidator getFileModificationValidator() {
+ return new FileModificationValidator(this);
+ }
+
}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemRemoteResource.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemRemoteResource.java
index f183184d1..08f266c34 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemRemoteResource.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemRemoteResource.java
@@ -13,20 +13,26 @@ package org.eclipse.team.examples.filesystem;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.sync.IRemoteResource;
+import com.ibm.jvm.io.FileOutputStream;
+
/**
* Class represents a handle to a <code>java.io.File</code> that conforms to
* the <code>org.eclipse.team.core.IRemoteResource</code> interface.
*/
public class FileSystemRemoteResource implements IRemoteResource {
-
+
// the file object in which the data is stored on the disk
private File ioFile;
@@ -37,16 +43,16 @@ public class FileSystemRemoteResource implements IRemoteResource {
public FileSystemRemoteResource(IPath path) {
this(new File(path.toOSString()));
}
-
+
/**
* Create a remote resource handle from the given java.io.file
*
* @param ioFile the file
*/
- private FileSystemRemoteResource(File ioFile) {
+ FileSystemRemoteResource(File ioFile) {
this.ioFile = ioFile;
}
-
+
/**
* Adapters are used to ensure that the right menus will appear in differnet views.
*
@@ -71,7 +77,7 @@ public class FileSystemRemoteResource implements IRemoteResource {
throw FileSystemPlugin.wrapException(e);
}
}
-
+
/**
* Return the modification timestamp of the remote resource.
*
@@ -87,7 +93,7 @@ public class FileSystemRemoteResource implements IRemoteResource {
public String getName() {
return ioFile.getName();
}
-
+
/**
* @see org.eclipse.team.core.sync.IRemoteResource#isContainer()
*/
@@ -104,8 +110,8 @@ public class FileSystemRemoteResource implements IRemoteResource {
public IRemoteResource[] members(IProgressMonitor progress) throws TeamException {
// Make sure we have a container
if (!isContainer())
- throw new TeamException("This resource is a file so it cannot have entries.");
-
+ throw new TeamException(Policy.bind("RemoteResource.mustBeFolder", ioFile.getName()));
+
// convert the File children to remote resource children
File[] members = ioFile.listFiles();
IRemoteResource[] result = new IRemoteResource[members.length];
@@ -114,5 +120,43 @@ public class FileSystemRemoteResource implements IRemoteResource {
}
return result;
}
-
+
+ /**
+ * copies a single specified file to a specified location on the filesystem.
+ * @param dest The location on the filesystem to which the file is to be copied
+ * @param src The source file
+ */
+ static void copyFile(IPath dest, File src) {
+ File target = new File(dest.append(src.getName()).toOSString());
+ try {
+ InputStream in = ((IFile) src).getContents();
+ java.io.FileOutputStream out = new java.io.FileOutputStream(target);
+ StreamUtil.pipe(in, out, target.length(), null, target.getName());
+ } catch (FileNotFoundException e) {} catch (IOException e) {} catch (CoreException e) {}
+ }
+ /**
+ * Recursively copies an entire directory structure to a specified location on the filesystem
+ * @param dest The location on the filssystem to which the directory structure is to be written
+ * @param src The directory structure that is to be duplicated
+ */
+ static void copyFolder(IPath dest, File src) {
+ String children[] = src.list();
+ File current;
+ for (int i = 0; i < children.length; i++) {
+ current = new File(children[i]);
+ if (current.isFile())
+ copyFile(dest.append(src.getName()), current);
+ else if (current.isDirectory())
+ copyFolder(dest.append(src.getName()), current);
+ }
+ }
+
+ /**
+ * Creates a copy of the remote resource in the location specified
+ * @param location The destination for the copy of the remote resource
+ */
+ public void copyOver(IPath location) {
+ copyFolder(location, ioFile);
+ }
+
} \ No newline at end of file
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemSimpleAccessOperations.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemSimpleAccessOperations.java
index 6bc3b223b..9a8aff1d6 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemSimpleAccessOperations.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemSimpleAccessOperations.java
@@ -16,6 +16,7 @@ import java.io.IOException;
import java.io.InputStream;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@@ -33,7 +34,7 @@ import org.eclipse.team.internal.core.simpleAccess.SimpleAccessOperations;
* synchronizer (<code>ISynchronizer</code>).
*/
public class FileSystemSimpleAccessOperations implements SimpleAccessOperations {
-
+
// A reference to the provider
private FileSystemProvider provider;
@@ -44,7 +45,7 @@ public class FileSystemSimpleAccessOperations implements SimpleAccessOperations
FileSystemSimpleAccessOperations(FileSystemProvider provider) {
this.provider = provider;
}
-
+
/**
* Given a local resource, finds the remote counterpart.
* @param resource The local resource to lookup
@@ -60,11 +61,10 @@ public class FileSystemSimpleAccessOperations implements SimpleAccessOperations
public void get(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException {
// ensure the progress monitor is not null
progress = Policy.monitorFor(progress);
- progress.beginTask("Checking resources in...", resources.length);
+ progress.beginTask(Policy.bind("GetAction.working"), resources.length);
for (int i = 0; i < resources.length; i++) {
Policy.checkCanceled(progress);
IPath rootdir = provider.getRoot();
-
FileSystemRemoteResource remote = getRemoteResourceFor(resources[i]);
if (resources[i].getType() == IResource.FILE) {
//Copy the resource over to the other side:
@@ -76,7 +76,7 @@ public class FileSystemSimpleAccessOperations implements SimpleAccessOperations
InputStream source = null;
try {
// Get the remote file content.
- source = remote.getContents(progress); //new FileInputStream(diskFile);
+ source = remote.getContents(progress);
// Set the local file content to be the same as the remote file.
if (localFile.exists())
localFile.setContents(source, false, false, progress);
@@ -93,47 +93,100 @@ public class FileSystemSimpleAccessOperations implements SimpleAccessOperations
}
}
} else if (depth > 0) { //Assume that resources are either files or containers.
- //Recursively copy children, if any, over as well:
- try {
- IResource[] children;
- if (resources[i].getType() == IResource.PROJECT) {
- children = provider.getProject().members();
- } else {
- IRemoteResource[] estranged = remote.members(progress);
- children = new IResource[estranged.length];
- for (int j = 0; j < estranged.length; j++) {
+ //If the resource is a container, copy its children over.
+ IRemoteResource[] estranged = remote.members(progress);
+ IResource[] children = new IResource[estranged.length];
+
+ if (resources[i].getType() == IResource.PROJECT) {
+ for (int j = 0; j < estranged.length; j++) {
+ if (estranged[j].isContainer())
+ children[j] = provider.getProject().getFolder(estranged[j].getName());
+ else
children[j] = provider.getProject().getFile(estranged[j].getName());
+ }
+ } else if (resources[i].getType() == IResource.FOLDER) {
+ //Make sure that the folder exists before trying to put anything into it:
+ IFolder localFolder = (IFolder) resources[i];
+ if (!localFolder.exists()) {
+ try {
+ localFolder.create(false, true, progress);
+ } catch (CoreException e) {
+ throw FileSystemPlugin.wrapException(e);
}
}
- if (children.length > 0)
- get(children, depth - 1, null);
- } catch (CoreException e) {
- throw FileSystemPlugin.wrapException(e);
+
+ //Create placeholder local resources to place data into:
+ for (int j = 0; j < estranged.length; j++) {
+ if (estranged[j].isContainer())
+ children[j] = provider.getProject().getFolder(resources[i].getProjectRelativePath().append(estranged[j].getName()));
+ else
+ children[j] = provider.getProject().getFile(resources[i].getProjectRelativePath().append(estranged[j].getName()));
+ }
}
+
+ //Recurse into children:
+ if (children.length > 0)
+ get(children, depth - 1, null);
}
progress.worked(1);
}
- //TODO: release lock (i.e. diskFile should no longer be locked).
progress.done();
}
/**
+ * Simply make sure that the local resource is not read only.
+ *
* @see SimpleAccessOperations#checkout(IResource[], int, IProgressMonitor)
*/
- public void checkout(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException {}
+ public void checkout(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException {
+ progress = Policy.monitorFor(progress);
+ progress.beginTask("Checking resources out...", resources.length);
+ IPath rootdir = provider.getRoot();
+ for (int i = 0; i < resources.length; i++) {
+ Policy.checkCanceled(progress);
+
+ //Do the actual file locking:
+ FileSystemRemoteResource remote = getRemoteResourceFor(resources[i]);
+ File diskFile = new File(rootdir.append(resources[i].getProjectRelativePath()).toOSString());
+ if (resources[i].getType() == IResource.FILE) {
+ //TODO: lock the file on the 'server'.
+ resources[i].setReadOnly(false);
+ } else if (depth > 0) {
+ diskFile.mkdirs();
+ //Recursively checkout children too:
+ try {
+ IResource[] children;
+ if (resources[i].getType() == IResource.PROJECT)
+ children = provider.getProject().members();
+ else
+ children = provider.getProject().getFolder(resources[i].getName()).members();
+ if (children.length > 0)
+ checkout(children, depth - 1, null);
+ } catch (CoreException e) {
+ throw FileSystemPlugin.wrapException(e);
+ }
+ }
+ progress.worked(1);
+ }
+ progress.done();
+ }
/**
- * Checkin the resources to the given depth.
+ * Checkin the resources to the given depth. Mark all checked in resources as read only.
+ *
* @see org.eclipse.team.internal.core.simpleAccess.SimpleAccessOperations#checkin(IResource[], int, IProgressMonitor)
*/
public void checkin(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException {
// ensure the progress monitor is not null
progress = Policy.monitorFor(progress);
- progress.beginTask("Checking resources in...", resources.length);
+ progress.beginTask(Policy.bind("PutAction.working"), resources.length);
for (int i = 0; i < resources.length; i++) {
Policy.checkCanceled(progress);
- //TODO: verify that the resources are checked out.
IPath rootdir = provider.getRoot();
+ // Verify that the resources are checked out:
+ if (!isCheckedOut(resources[i]))
+ return;
+
File diskFile = new File(rootdir.append(resources[i].getProjectRelativePath()).toOSString());
if (resources[i].getType() == IResource.FILE) {
//Copy the resource over to the other side:
@@ -179,14 +232,47 @@ public class FileSystemSimpleAccessOperations implements SimpleAccessOperations
}
progress.worked(1);
}
- //TODO: release lock (i.e. diskFile should no longer be locked).
+ uncheckout(resources, depth, progress);
progress.done();
}
/**
+ * Mark all checked in resources as read only.
+ *
* @see org.eclipse.team.internal.core.simpleAccess.SimpleAccessOperations#uncheckout(IResource[], int, IProgressMonitor)
*/
- public void uncheckout(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException {}
+ public void uncheckout(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException {
+ progress = Policy.monitorFor(progress);
+ progress.beginTask("Re-locking resources...", resources.length);
+ IPath rootdir = provider.getRoot();
+ for (int i = 0; i < resources.length; i++) {
+ Policy.checkCanceled(progress);
+
+ //Do the actual file unlocking:
+ FileSystemRemoteResource remote = getRemoteResourceFor(resources[i]);
+ File diskFile = new File(rootdir.append(resources[i].getProjectRelativePath()).toOSString());
+ if (resources[i].getType() == IResource.FILE) {
+ //TODO: unlock the file on the 'server'.
+ resources[i].setReadOnly(true);
+ } else if (depth > 0) {
+ diskFile.mkdirs();
+ //Recursively uncheckout children too:
+ try {
+ IResource[] children;
+ if (resources[i].getType() == IResource.PROJECT)
+ children = provider.getProject().members();
+ else
+ children = provider.getProject().getFolder(resources[i].getName()).members();
+ if (children.length > 0)
+ uncheckout(children, depth - 1, null);
+ } catch (CoreException e) {
+ throw FileSystemPlugin.wrapException(e);
+ }
+ }
+ progress.worked(1);
+ }
+ progress.done();
+ }
/**
* @see org.eclipse.team.internal.core.simpleAccess.SimpleAccessOperations#delete(IResource[], IProgressMonitor)
@@ -199,10 +285,12 @@ public class FileSystemSimpleAccessOperations implements SimpleAccessOperations
public void moved(IPath source, IResource target, IProgressMonitor progress) throws TeamException {}
/**
+ * A resource is checked out if it is not read only.
+ *
* @see org.eclipse.team.internal.core.simpleAccess.SimpleAccessOperations#isCheckedOut(IResource)
*/
public boolean isCheckedOut(IResource resource) {
- return false;
+ return !resource.isReadOnly();
}
/**
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/messages.properties b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/messages.properties
index de45f75a2..2b40e5e27 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/messages.properties
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/messages.properties
@@ -21,4 +21,8 @@ PutAction.problemMessage=A problem occured putting the resources.
GetAction.working=Getting resources...
GetAction.problemMessage=A problem occured getting the resources.
-FileSystemProvider.mustBeFolder=Target location ''{0}'' is a file and must be a folder. \ No newline at end of file
+ReplaceAction.working=Replacing resources...
+ReplaceAction.problemMessage=A problem occured replacing the resources.
+
+FileSystemProvider.mustBeFolder=Target location ''{0}'' is a file and must be a folder.
+RemoteResource.mustBeFolder=Resource ''{0}'' is a file so it cannot have entries \ No newline at end of file
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 6b7519d3c..0661fc8fb 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
@@ -28,7 +28,7 @@ import org.eclipse.ui.actions.WorkspaceModifyOperation;
* Action for getting the contents of the selected resources
*/
public class GetAction extends FileSystemAction {
-
+
public void run(IAction action) {
run(new WorkspaceModifyOperation() {
public void execute(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ReplaceAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ReplaceAction.java
new file mode 100644
index 000000000..6af50943e
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ReplaceAction.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2002 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ ******************************************************************************/
+package org.eclipse.team.examples.filesystem.ui;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+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.core.sync.IRemoteResource;
+import org.eclipse.team.examples.filesystem.FileSystemProvider;
+import org.eclipse.team.examples.filesystem.FileSystemRemoteResource;
+import org.eclipse.team.examples.filesystem.Policy;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+
+/**
+ * Action for replacing the contents of the selected resources with whatever is in the repository
+ */
+public class ReplaceAction extends FileSystemAction {
+
+ public void run(IAction action) {
+ run(new WorkspaceModifyOperation() {
+ public void execute(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
+ try {
+ Map table = getRepositoryProviderMapping();
+ monitor.beginTask(null, table.size() * 1000);
+ monitor.setTaskName(Policy.bind("ReplaceAction.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()]);
+ //Grab the remote counterparts of 'providerResources':
+ FileSystemRemoteResource[] remote = new FileSystemRemoteResource[list.size()];
+ for (int i = 0; i < remote.length; i++) {
+ remote[i] = new FileSystemRemoteResource(provider.getRoot().append(providerResources[i].getProjectRelativePath()));
+ }
+ //copy the entire tree structure:
+ IPath dropSpot = null;
+ for (int i = 0; i < providerResources.length; i++) {
+ if (providerResources[i].getType() == IResource.FILE) {
+ IFile localFile = (IFile) providerResources[i];
+ dropSpot = localFile.getLocation().removeLastSegments(1);
+ } else if (providerResources[i].getType() == IResource.FOLDER||providerResources[i].getType() == IResource.PROJECT) {
+ IContainer localDir = (IContainer) providerResources[i];
+ dropSpot = localDir.getLocation().removeLastSegments(1);
+ }
+ if (remote[i].isContainer())
+ remote[i].copyOver(dropSpot);
+ else
+ provider.getSimpleAccess().get(new IResource[] { providerResources[i] }, IResource.DEPTH_ONE, subMonitor);
+ }
+ }
+ } catch (TeamException e) {
+ throw new InvocationTargetException(e);
+ } finally {
+ monitor.done();
+ }
+ }
+ }, Policy.bind("ReplaceAction.problemMessage"), this.PROGRESS_DIALOG); //$NON-NLS-1$
+ }
+} \ No newline at end of file

Back to the top