Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCopy.java')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCopy.java156
1 files changed, 31 insertions, 125 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCopy.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCopy.java
index 76c486811..e25eba432 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCopy.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCopy.java
@@ -11,12 +11,10 @@ package org.eclipse.tcf.te.tcf.filesystem.core.internal.operations;
import static java.text.MessageFormat.format;
-import java.util.LinkedList;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
import org.eclipse.tcf.protocol.IToken;
import org.eclipse.tcf.protocol.Protocol;
@@ -26,150 +24,58 @@ import org.eclipse.tcf.services.IFileSystem.DoneMkDir;
import org.eclipse.tcf.services.IFileSystem.DoneStat;
import org.eclipse.tcf.services.IFileSystem.FileAttrs;
import org.eclipse.tcf.services.IFileSystem.FileSystemException;
+import org.eclipse.tcf.te.tcf.core.concurrent.TCFOperationMonitor;
import org.eclipse.tcf.te.tcf.filesystem.core.interfaces.IConfirmCallback;
import org.eclipse.tcf.te.tcf.filesystem.core.interfaces.runtime.IFSTreeNode;
import org.eclipse.tcf.te.tcf.filesystem.core.internal.FSTreeNode;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.utils.StatusHelper;
import org.eclipse.tcf.te.tcf.filesystem.core.nls.Messages;
/**
* The operation class that copies selected FSTreeNodes to a specify destination folder.
*/
-public class OpCopy extends AbstractOperation {
- private static class WorkItem {
- final boolean fTop;
- final FSTreeNode fDestination;
- final FSTreeNode[] fSources;
- WorkItem(FSTreeNode[] sources, FSTreeNode destination, boolean top) {
- fSources = sources;
- fDestination = destination;
- fTop = top;
- }
- }
-
- IConfirmCallback fConfirmCallback;
- boolean fCopyPermissions;
- boolean fCopyOwnership;
-
- LinkedList<WorkItem> fWork = new LinkedList<WorkItem>();
- private long fStartTime;
+public class OpCopy extends OpCopyBase<FSTreeNode> {
+ private final boolean fCopyPermissions;
+ private final boolean fCopyOwnership;
- /**
- * Create a copy operation using the specified nodes and destination folder,
- * using the specified flags of copying permissions and ownership and a callback
- * to confirm to overwrite existing files.
- *
- * @param nodes The file/folder nodes to be copied.
- * @param dest The destination folder to be copied to.
- */
public OpCopy(List<? extends IFSTreeNode> nodes, FSTreeNode dest, boolean cpPerm, boolean cpOwn, IConfirmCallback confirmCallback) {
- super();
+ super(nodes, dest, confirmCallback);
fCopyOwnership = cpOwn;
fCopyPermissions = cpPerm;
- fConfirmCallback = confirmCallback;
- nodes = dropNestedNodes(nodes);
- fWork.add(new WorkItem(nodes.toArray(new FSTreeNode[nodes.size()]), dest, true));
}
@Override
- public IStatus doRun(IProgressMonitor monitor) {
- fStartTime = System.currentTimeMillis();
- monitor.beginTask(getName(), IProgressMonitor.UNKNOWN);
- WorkItem lastTop = null;
- while (!fWork.isEmpty()) {
- WorkItem item = fWork.remove();
- if (item.fTop) {
- if (lastTop != null)
- lastTop.fDestination.notifyChange();
- lastTop = item;
- }
- IStatus s = runWorkItem(item, monitor);
- if (!s.isOK()) {
- lastTop.fDestination.notifyChange();
- return s;
- }
- }
- if (lastTop != null)
- lastTop.fDestination.notifyChange();
- return Status.OK_STATUS;
+ protected FSTreeNode findChild(FSTreeNode destination, String name) {
+ return destination.findChild(name);
}
- protected IStatus runWorkItem(final WorkItem item, IProgressMonitor monitor) {
- final FSTreeNode destination = item.fDestination;
- IStatus status = refresh(destination, fStartTime, monitor);
- if (!status.isOK()) {
- return status;
- }
-
- for (FSTreeNode source : item.fSources) {
- status = refresh(source, fStartTime, monitor);
- if (!status.isOK()) {
- return status;
- }
-
- status = performCopy(source, destination, monitor);
- if (!status.isOK())
- return status;
- }
- return Status.OK_STATUS;
+ @Override
+ protected void notifyChange(FSTreeNode destination) {
+ destination.notifyChange();
}
- private IStatus performCopy(FSTreeNode source, FSTreeNode destination, IProgressMonitor monitor) {
- String newName = source.getName();
- FSTreeNode existing = destination.findChild(newName);
- if (existing != null) {
- if (source == existing) {
- newName = createNewNameForCopy(destination, newName);
- existing = null;
- } else if (source.isDirectory()) {
- if (!existing.isDirectory()) {
- return StatusHelper.createStatus(format(Messages.OpCopy_error_noDirectory, existing.getLocation()), null);
- }
- int replace = confirmCallback(existing, fConfirmCallback);
- if (replace == IConfirmCallback.NO) {
- return Status.OK_STATUS;
- }
- if (replace != IConfirmCallback.YES) {
- return Status.CANCEL_STATUS;
- }
+ @Override
+ protected IStatus refreshDestination(FSTreeNode destination, long startTime, IProgressMonitor monitor) {
+ return refresh(destination, startTime, monitor);
+ }
- fWork.addFirst(new WorkItem(source.getChildren(), existing, false));
- return Status.OK_STATUS;
- } else if (source.isFile()) {
- if (!existing.isFile()) {
- return StatusHelper.createStatus(format(Messages.OpCopy_error_noFile, existing.getLocation()), null);
- }
- int replace = confirmCallback(existing, fConfirmCallback);
- if (replace == IConfirmCallback.NO) {
- return Status.OK_STATUS;
- }
- if (replace != IConfirmCallback.YES) {
- return Status.CANCEL_STATUS;
- }
- } else {
- return Status.OK_STATUS;
- }
- }
- return performCopy(source, destination, newName, existing, monitor);
+ @Override
+ protected boolean isDirectory(FSTreeNode node) {
+ return node.isDirectory();
}
+ @Override
+ protected boolean isFile(FSTreeNode node) {
+ return node.isFile();
+ }
- private String createNewNameForCopy(FSTreeNode node, String origName) {
- String name = origName;
- int n = 0;
- while (node.findChild(name) != null) {
- if (n > 0) {
- name = NLS.bind(Messages.Operation_CopyNOfFile, Integer.valueOf(n), origName);
- } else {
- name = NLS.bind(Messages.Operation_CopyOfFile, origName);
- }
- n++;
- }
- return name;
+ @Override
+ protected String getLocation(FSTreeNode node) {
+ return node.getLocation();
}
- private IStatus performCopy(final FSTreeNode source, final FSTreeNode destination, final String newName, final FSTreeNode existing, IProgressMonitor monitor) {
- final TCFResult<?> result = new TCFResult<Object>();
+ @Override
+ protected IStatus performCopy(final FSTreeNode source, final FSTreeNode destination, final String newName, final FSTreeNode existing, IProgressMonitor monitor) {
+ final TCFOperationMonitor<?> result = new TCFOperationMonitor<Object>();
monitor.subTask(NLS.bind(Messages.OpCopy_Copying, source.getLocation()));
Protocol.invokeLater(new Runnable() {
@Override
@@ -181,7 +87,7 @@ public class OpCopy extends AbstractOperation {
}
- protected void tcfPerformCopy(FSTreeNode source, FSTreeNode destination, String newName, FSTreeNode existing, TCFResult<?> result) {
+ protected void tcfPerformCopy(FSTreeNode source, FSTreeNode destination, String newName, FSTreeNode existing, TCFOperationMonitor<?> result) {
if (result.checkCancelled())
return;
@@ -194,7 +100,7 @@ public class OpCopy extends AbstractOperation {
}
}
- private void tcfCopyFolder(final FSTreeNode source, final FSTreeNode dest, final String newName, final TCFResult<?> result) {
+ private void tcfCopyFolder(final FSTreeNode source, final FSTreeNode dest, final String newName, final TCFOperationMonitor<?> result) {
final IFileSystem fileSystem = dest.getRuntimeModel().getFileSystem();
if (fileSystem == null) {
result.setCancelled();
@@ -217,7 +123,7 @@ public class OpCopy extends AbstractOperation {
FSTreeNode copy = new FSTreeNode(dest, newName, false, attrs);
copy.setContent(new FSTreeNode[0], false);
dest.addNode(copy, false);
- fWork.addFirst(new WorkItem(source.getChildren(), copy, false));
+ addWorkItem(source.getChildren(), copy);
result.setDone(null);
}
}
@@ -227,7 +133,7 @@ public class OpCopy extends AbstractOperation {
});
}
- private void tcfCopyFile(final FSTreeNode source, final FSTreeNode dest, final String newName, final FSTreeNode existing, final TCFResult<?> result) {
+ private void tcfCopyFile(final FSTreeNode source, final FSTreeNode dest, final String newName, final FSTreeNode existing, final TCFOperationMonitor<?> result) {
final IFileSystem fileSystem = dest.getRuntimeModel().getFileSystem();
if (fileSystem == null) {
result.setCancelled();

Back to the top