diff options
author | Uwe Stieber | 2012-08-07 12:38:32 +0000 |
---|---|---|
committer | Uwe Stieber | 2012-08-07 12:38:32 +0000 |
commit | afd68306e73cc544329c98f3d617ea319e4f7922 (patch) | |
tree | 7d3596d89eb8aeced4e4ffe9ddd86121126df2e4 /target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core | |
parent | 1a205b7cc6dd9157a1c7ab3957b05a621af61817 (diff) | |
download | org.eclipse.tcf-afd68306e73cc544329c98f3d617ea319e4f7922.tar.gz org.eclipse.tcf-afd68306e73cc544329c98f3d617ea319e4f7922.tar.xz org.eclipse.tcf-afd68306e73cc544329c98f3d617ea319e4f7922.zip |
Target Explorer: Start adding some assertions to file system operations
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core')
3 files changed, 345 insertions, 342 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 5734cfe2c..d5a9e856d 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,189 +1,192 @@ -/*******************************************************************************
- * Copyright (c) 2011, 2012 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
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.tcf.filesystem.core.internal.operations;
-
-import java.lang.reflect.InvocationTargetException;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-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.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.
- protected FSTreeNode folder;
- // The node that is created after the operation.
- protected FSTreeNode node;
- // The name of the node to be created.
- protected String name;
-
- /**
- * 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.
- * @param name The new node's name.
- */
- public OpCreate(FSTreeNode folder, String name) {
- this.folder = folder;
- this.name = 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);
- }
- }
- catch (TCFException e) {
- throw new InvocationTargetException(e, e.getMessage());
- }
- 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];
- }
- }
- }
-
- /**
- * Add the new node to the folder and its FSModel.
- *
- * @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];
- }
- }
-
- /**
- * 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;
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.core.interfaces.IOperation#getName()
- */
- @Override
- public String getName() {
- return NLS.bind(Messages.OpCreate_TaskName, name);
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.core.interfaces.IOperation#getTotalWork()
- */
- @Override
- public int getTotalWork() {
- return folder.childrenQueried ? 5 : 6;
- }
-}
+/******************************************************************************* + * Copyright (c) 2011, 2012 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 + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.tcf.filesystem.core.internal.operations; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +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.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; + + /** + * 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; + } + + /* + * (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); + } + } + catch (TCFException e) { + throw new InvocationTargetException(e, e.getMessage()); + } + 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]; + } + } + } + + /** + * Add the new node to the folder and its FSModel. + * + * @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]; + } + } + + /** + * 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; + } + + /* + * (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.filesystem.core.interfaces.IOperation#getName() + */ + @Override + public String getName() { + return NLS.bind(Messages.OpCreate_TaskName, name); + } + + /* + * (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.filesystem.core.interfaces.IOperation#getTotalWork() + */ + @Override + public int getTotalWork() { + return folder.childrenQueried ? 5 : 6; + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCreateFile.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCreateFile.java index a532181a3..58ee9a1d6 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCreateFile.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCreateFile.java @@ -1,81 +1,81 @@ -/*******************************************************************************
- * Copyright (c) 2011, 2012 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
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.tcf.filesystem.core.internal.operations;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.tcf.protocol.IToken;
-import org.eclipse.tcf.services.IFileSystem;
-import org.eclipse.tcf.services.IFileSystem.DoneClose;
-import org.eclipse.tcf.services.IFileSystem.DoneOpen;
-import org.eclipse.tcf.services.IFileSystem.FileSystemException;
-import org.eclipse.tcf.services.IFileSystem.IFileHandle;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.exceptions.TCFFileSystemException;
-import org.eclipse.tcf.te.tcf.filesystem.core.model.FSModel;
-import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
-import org.eclipse.tcf.te.tcf.filesystem.core.nls.Messages;
-
-/**
- * The file operation class to create a file in the file system of Target Explorer.
- */
-public class OpCreateFile extends OpCreate {
-
- /**
- * Create an instance to create a file with the name in the folder.
- *
- * @param folder The folder in which the file is to be created.
- * @param name The new file's name.
- */
- public OpCreateFile(FSTreeNode folder, String name) {
- super(folder, name);
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpCreate#create(org.eclipse.tcf.services.IFileSystem)
- */
- @Override
- protected void create(IFileSystem service) throws TCFFileSystemException {
- String path = folder.getLocation(true);
- if (!path.endsWith("/")) path += "/"; //$NON-NLS-1$ //$NON-NLS-2$
- path += name;
- final FileSystemException[] errors = new FileSystemException[1];
- // Open the file.
- final IFileHandle[] handles = new IFileHandle[1];
- service.open(path, IFileSystem.TCF_O_WRITE | IFileSystem.TCF_O_CREAT | IFileSystem.TCF_O_TRUNC, null, new DoneOpen() {
- @Override
- public void doneOpen(IToken token, FileSystemException error, IFileHandle hdl) {
- errors[0] = error;
- handles[0] = hdl;
- }
- });
- if (errors[0] != null) {
- TCFFileSystemException exception = new TCFFileSystemException(IStatus.ERROR, errors[0].toString());
- exception.initCause(errors[0]);
- throw exception;
- }
- if (handles[0] == null) {
- throw new TCFFileSystemException(IStatus.ERROR, Messages.TcfURLConnection_NoFileHandleReturned);
- }
- service.close(handles[0], new DoneClose() {
- @Override
- public void doneClose(IToken token, FileSystemException error) {
- }
- });
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpCreate#newTreeNode()
- */
- @Override
- protected FSTreeNode newTreeNode() {
- return FSModel.createFileNode(name, folder);
- }
-}
+/******************************************************************************* + * Copyright (c) 2011, 2012 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 + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.tcf.filesystem.core.internal.operations; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.tcf.protocol.IToken; +import org.eclipse.tcf.services.IFileSystem; +import org.eclipse.tcf.services.IFileSystem.DoneClose; +import org.eclipse.tcf.services.IFileSystem.DoneOpen; +import org.eclipse.tcf.services.IFileSystem.FileSystemException; +import org.eclipse.tcf.services.IFileSystem.IFileHandle; +import org.eclipse.tcf.te.tcf.filesystem.core.internal.exceptions.TCFFileSystemException; +import org.eclipse.tcf.te.tcf.filesystem.core.model.FSModel; +import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode; +import org.eclipse.tcf.te.tcf.filesystem.core.nls.Messages; + +/** + * The file operation class to create a file in the file system of Target Explorer. + */ +public class OpCreateFile extends OpCreate { + + /** + * Create an instance to create a file with the name in the folder. + * + * @param folder The folder in which the file is to be created. Must not be <code>null</code>. + * @param name The new file's name. Must not be <code>null</code>. + */ + public OpCreateFile(FSTreeNode folder, String name) { + super(folder, name); + } + + /* + * (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpCreate#create(org.eclipse.tcf.services.IFileSystem) + */ + @Override + protected void create(IFileSystem service) throws TCFFileSystemException { + String path = folder.getLocation(true); + if (!path.endsWith("/")) path += "/"; //$NON-NLS-1$ //$NON-NLS-2$ + path += name; + final FileSystemException[] errors = new FileSystemException[1]; + // Open the file. + final IFileHandle[] handles = new IFileHandle[1]; + service.open(path, IFileSystem.TCF_O_WRITE | IFileSystem.TCF_O_CREAT | IFileSystem.TCF_O_TRUNC, null, new DoneOpen() { + @Override + public void doneOpen(IToken token, FileSystemException error, IFileHandle hdl) { + errors[0] = error; + handles[0] = hdl; + } + }); + if (errors[0] != null) { + TCFFileSystemException exception = new TCFFileSystemException(IStatus.ERROR, errors[0].toString()); + exception.initCause(errors[0]); + throw exception; + } + if (handles[0] == null) { + throw new TCFFileSystemException(IStatus.ERROR, Messages.TcfURLConnection_NoFileHandleReturned); + } + service.close(handles[0], new DoneClose() { + @Override + public void doneClose(IToken token, FileSystemException error) { + } + }); + } + + /* + * (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpCreate#newTreeNode() + */ + @Override + protected FSTreeNode newTreeNode() { + return FSModel.createFileNode(name, folder); + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCreateFolder.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCreateFolder.java index 8dbe1707a..1f3f86b9e 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCreateFolder.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/operations/OpCreateFolder.java @@ -1,72 +1,72 @@ -/*******************************************************************************
- * Copyright (c) 2011, 2012 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
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.tcf.filesystem.core.internal.operations;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.tcf.protocol.IToken;
-import org.eclipse.tcf.services.IFileSystem;
-import org.eclipse.tcf.services.IFileSystem.DoneMkDir;
-import org.eclipse.tcf.services.IFileSystem.FileSystemException;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.exceptions.TCFFileSystemException;
-import org.eclipse.tcf.te.tcf.filesystem.core.model.FSModel;
-import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
-
-/**
- * The file operation class to create a folder in the file system of Target Explorer.
- */
-public class OpCreateFolder extends OpCreate {
-
- /**
- * Create an instance to create a folder with the name in the folder.
- *
- * @param folder The folder in which the new folder is to be created.
- * @param name The name of the new folder.
- */
- public OpCreateFolder(FSTreeNode folder, String name) {
- super(folder, name);
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpCreate#create(org.eclipse.tcf.services.IFileSystem)
- */
- @Override
- protected void create(IFileSystem service) throws TCFFileSystemException {
- String path = folder.getLocation(true);
- if (!path.endsWith("/")) path += "/"; //$NON-NLS-1$ //$NON-NLS-2$
- path += name;
- final FileSystemException[] errors = new FileSystemException[1];
- service.mkdir(path, null, new DoneMkDir() {
- @Override
- public void doneMkDir(IToken token, FileSystemException error) {
- if (error != null) {
- errors[0] = error;
- }
- }
- });
- if (errors[0] != null) {
- TCFFileSystemException exception = new TCFFileSystemException(IStatus.ERROR, errors[0].toString());
- exception.initCause(errors[0]);
- throw exception;
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpCreate#newTreeNode()
- */
- @Override
- protected FSTreeNode newTreeNode() {
- FSTreeNode node = FSModel.createFolderNode(name, folder);
- // Newly created folder does not have any children. Mark it as queried.
- node.queryDone();
- return node;
- }
-}
+/******************************************************************************* + * Copyright (c) 2011, 2012 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 + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.tcf.filesystem.core.internal.operations; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.tcf.protocol.IToken; +import org.eclipse.tcf.services.IFileSystem; +import org.eclipse.tcf.services.IFileSystem.DoneMkDir; +import org.eclipse.tcf.services.IFileSystem.FileSystemException; +import org.eclipse.tcf.te.tcf.filesystem.core.internal.exceptions.TCFFileSystemException; +import org.eclipse.tcf.te.tcf.filesystem.core.model.FSModel; +import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode; + +/** + * The file operation class to create a folder in the file system of Target Explorer. + */ +public class OpCreateFolder extends OpCreate { + + /** + * Create an instance to create a folder with the name in the folder. + * + * @param folder The folder in which the new folder is to be created. Must not be <code>null</code>. + * @param name The name of the new folder. Must not be <code>null</code>. + */ + public OpCreateFolder(FSTreeNode folder, String name) { + super(folder, name); + } + + /* + * (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpCreate#create(org.eclipse.tcf.services.IFileSystem) + */ + @Override + protected void create(IFileSystem service) throws TCFFileSystemException { + String path = folder.getLocation(true); + if (!path.endsWith("/")) path += "/"; //$NON-NLS-1$ //$NON-NLS-2$ + path += name; + final FileSystemException[] errors = new FileSystemException[1]; + service.mkdir(path, null, new DoneMkDir() { + @Override + public void doneMkDir(IToken token, FileSystemException error) { + if (error != null) { + errors[0] = error; + } + } + }); + if (errors[0] != null) { + TCFFileSystemException exception = new TCFFileSystemException(IStatus.ERROR, errors[0].toString()); + exception.initCause(errors[0]); + throw exception; + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpCreate#newTreeNode() + */ + @Override + protected FSTreeNode newTreeNode() { + FSTreeNode node = FSModel.createFolderNode(name, folder); + // Newly created folder does not have any children. Mark it as queried. + node.queryDone(); + return node; + } +} |