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/OpCreate.java')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCreate.java184
1 files changed, 35 insertions, 149 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCreate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCreate.java
index ad9460869..4709535d4 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCreate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCreate.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2014 Wind River Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2011, 2015 Wind River Systems, Inc. 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
@@ -9,184 +9,70 @@
*******************************************************************************/
package org.eclipse.tcf.te.tcf.filesystem.core.internal.operations;
-import java.lang.reflect.InvocationTargetException;
+import static java.text.MessageFormat.format;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.osgi.util.NLS;
-import org.eclipse.tcf.protocol.IChannel;
-import org.eclipse.tcf.protocol.IToken;
import org.eclipse.tcf.protocol.Protocol;
-import org.eclipse.tcf.services.IFileSystem;
-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.Tcf;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.exceptions.TCFException;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.exceptions.TCFFileSystemException;
-import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
+import org.eclipse.tcf.te.tcf.filesystem.core.interfaces.IResultOperation;
+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 base operation class for creating a file or a folder in the file system of Target
* Explorer.
*/
-public abstract class OpCreate extends Operation {
- // The folder in which a file/folder is going to be created.
- final protected FSTreeNode folder;
- // The node that is created after the operation.
- protected FSTreeNode node;
- // The name of the node to be created.
- final protected String name;
+public abstract class OpCreate extends AbstractOperation implements IResultOperation<IFSTreeNode> {
+ final protected FSTreeNode fDestination;
+ final protected String fName;
+ protected FSTreeNode fResult;
- /**
- * Create an FSCreate instance with the specified folder and the name of the new node.
- *
- * @param folder The folder in which the new node is going to be created. Must not be <code>null</code>.
- * @param name The new node's name. Must not be <code>null</code>.
- */
public OpCreate(FSTreeNode folder, String name) {
Assert.isNotNull(folder);
- this.folder = folder;
Assert.isNotNull(name);
- this.name = name;
+ fDestination = folder;
+ fName = name;
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.Operation#run(org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- super.run(monitor);
- IChannel channel = null;
- try {
- channel = openChannel(folder.peerNode.getPeer());
- monitor.worked(1);
- IFileSystem service = getBlockingFileSystem(channel);
- if (service != null) {
- if (!folder.childrenQueried) {
- // If the children of folder is not queried, load it first.
- loadChildren(folder, service);
- monitor.worked(1);
- }
- monitor.worked(1);
- create(service);
- monitor.worked(1);
- addNode(service);
- monitor.worked(1);
- refresh(service);
- monitor.worked(1);
- }
- else {
- String message = NLS.bind(Messages.Operation_NoFileSystemError, folder.peerNode.getPeerId());
- throw new TCFFileSystemException(IStatus.ERROR, message);
- }
+ protected IStatus doRun(IProgressMonitor monitor) {
+ if (fDestination.getChildren() == null) {
+ IStatus status = fDestination.operationRefresh(false).run(new SubProgressMonitor(monitor, 0));
+ if (!status.isOK())
+ return status;
}
- catch (TCFException e) {
- throw new InvocationTargetException(e, e.getMessage());
+ FSTreeNode existing = fDestination.findChild(fName);
+ if (existing != null) {
+ return StatusHelper.createStatus(format(Messages.OpCreate_error_existingFile, existing.getLocation()), null);
}
- finally {
- if (channel != null) Tcf.getChannelManager().closeChannel(channel);
- monitor.done();
- }
- }
- /**
- * Refresh new node's stat using the file system service.
- *
- * @param service The file system service.
- * @throws TCFFileSystemException Thrown when refreshing the new node's stat.
- */
- void refresh(final IFileSystem service) throws TCFFileSystemException {
- if (node != null) {
- final TCFFileSystemException[] errors = new TCFFileSystemException[1];
- String path = node.getLocation(true);
- service.stat(path, new DoneStat() {
- @Override
- public void doneStat(IToken token, FileSystemException error, FileAttrs attrs) {
- if (error == null) {
- if (node != null) node.setAttributes(attrs);
- }
- else {
- errors[0] = newTCFException(IStatus.WARNING, error);
- }
- }
- });
- if (errors[0] != null) {
- throw errors[0];
+ final TCFResult<FSTreeNode> result = new TCFResult<FSTreeNode>();
+ Protocol.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ tcfCreate(fDestination, fName, result);
}
- }
- }
+ });
- /**
- * Add the new node to the folder and its RuntimeModel.
- *
- * @param service The file system service to be used.
- * @throws TCFFileSystemException Thrown when adding.
- */
- void addNode(final IFileSystem service) throws TCFFileSystemException {
- if (Protocol.isDispatchThread()) {
- node = newTreeNode();
- folder.addChild(node);
- }
- else {
- final TCFFileSystemException[] errors = new TCFFileSystemException[1];
- Protocol.invokeAndWait(new Runnable() {
- @Override
- public void run() {
- try {
- addNode(service);
- }
- catch (TCFFileSystemException e) {
- errors[0] = e;
- }
- }
- });
- if (errors[0] != null) throw errors[0];
- }
+ IStatus status = result.waitDone(monitor);
+ fResult = result.getValue();
+ return status;
}
- /**
- * Create the new node, either a directory node or a file node.
- *
- * @return The new node.
- */
- protected abstract FSTreeNode newTreeNode();
-
- /**
- * Create the node in the target system.
- *
- * @param service The file system service used to create the new node.
- * @throws TCFFileSystemException Thrown when creating the node.
- */
- protected abstract void create(IFileSystem service) throws TCFFileSystemException;
-
- /**
- * Get the node that is created by this operation.
- *
- * @return the node created.
- */
- public FSTreeNode getNode() {
- return node;
- }
+ protected abstract void tcfCreate(FSTreeNode destination, String name, TCFResult<FSTreeNode> result);
- /*
- * (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.core.interfaces.IOperation#getName()
- */
@Override
public String getName() {
- return NLS.bind(Messages.OpCreate_TaskName, name);
+ return NLS.bind(Messages.OpCreate_TaskName, fName);
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.core.interfaces.IOperation#getTotalWork()
- */
@Override
- public int getTotalWork() {
- return folder.childrenQueried ? 5 : 6;
- }
+ public FSTreeNode getResult() {
+ return fResult;
+ }
}

Back to the top