Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2013-07-10 13:07:03 +0000
committerUwe Stieber2013-07-10 13:07:03 +0000
commit8f48d3c6f1d1d1b4d67afb9bd3eb8bc61c0b66f0 (patch)
treeb51970e55b32d108ae7e21bb75ebe5079e33c3ef /target_explorer
parentbff611df7503d073ee9611b38a6c2f6216d2003e (diff)
downloadorg.eclipse.tcf-8f48d3c6f1d1d1b4d67afb9bd3eb8bc61c0b66f0.tar.gz
org.eclipse.tcf-8f48d3c6f1d1d1b4d67afb9bd3eb8bc61c0b66f0.tar.xz
org.eclipse.tcf-8f48d3c6f1d1d1b4d67afb9bd3eb8bc61c0b66f0.zip
Target Explorer: Fix - Remote file change not detected
Diffstat (limited to 'target_explorer')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/utils/CacheManager.java408
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.properties10
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/NodeStateFilter.java156
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/OpenFileHandler.java256
4 files changed, 428 insertions, 402 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/utils/CacheManager.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/utils/CacheManager.java
index dae466ce6..2596edb43 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/utils/CacheManager.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.core/src/org/eclipse/tcf/te/tcf/filesystem/core/internal/utils/CacheManager.java
@@ -1,204 +1,204 @@
-/*******************************************************************************
- * 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
- * William Chen (Wind River)- [345387] Open the remote files with a proper editor
- * William Chen (Wind River)- [345552] Edit the remote files with a proper editor
- *******************************************************************************/
-package org.eclipse.tcf.te.tcf.filesystem.core.internal.utils;
-
-import java.io.File;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.ISafeRunnable;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.tcf.te.tcf.filesystem.core.activator.CorePlugin;
-import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
-import org.eclipse.tcf.te.tcf.filesystem.core.nls.Messages;
-
-/**
- * The local file system cache used to manage the temporary files downloaded
- * from a remote file system.
- */
-public class CacheManager {
- public static final char PATH_ESCAPE_CHAR = '$';
-
- /**
- * Get the local path of a node's cached file.
- * <p>
- * The preferred location is within the plugin's state location, in
- * example <code>&lt;state location&gt;agent_<hashcode_of_peerId>/remote/path/to/the/file...</code>.
- * <p>
- * If the plug-in is loaded in a RCP workspace-less environment, the
- * fall back strategy is to use the users home directory.
- *
- * @param node
- * The file/folder node.
- * @return The local path of the node's cached file.
- */
- public static IPath getCachePath(FSTreeNode node) {
- File location = getCacheRoot();
- String agentId = node.peerNode.getPeerId();
- // Use Math.abs to avoid negative hash value.
- String agent = agentId.replace(':', PATH_ESCAPE_CHAR);
- IPath agentDir = new Path(location.getAbsolutePath()).append(agent);
- File agentDirFile = agentDir.toFile();
- mkdirChecked(agentDirFile);
- return appendNodePath(agentDir, node);
- }
-
- /**
- * Check and make a directory if it does not exist. Record
- * the failure message if making fails.
- *
- * @param file The file to be deleted.
- */
- static void mkdirChecked(final File dir) {
- if(!dir.exists()) {
- SafeRunner.run(new ISafeRunnable(){
- @Override
- public void run() throws Exception {
- if (!dir.mkdir()) {
- throw new Exception(NLS.bind(Messages.CacheManager_MkdirFailed, dir.getAbsolutePath()));
- }
- }
-
- @Override
- public void handleException(Throwable exception) {
- // Ignore on purpose
- }});
- }
- }
-
- /**
- * Check if the file exists and delete if it does. Record
- * the failure message if deleting fails.
- *
- * @param file The file to be deleted.
- */
- static void deleteFileChecked(final File file) {
- if (file.exists()) {
- SafeRunner.run(new ISafeRunnable(){
- @Override
- public void run() throws Exception {
- if (!file.delete()) {
- throw new Exception(NLS.bind(Messages.Operation_DeletingFileFailed, file.getAbsolutePath()));
- }
- }
-
- @Override
- public void handleException(Throwable exception) {
- // Ignore on purpose
- }});
- }
- }
-
- /**
- * Check if the file exists and set its read-only attribute if it does. Record
- * the failure message if it fails.
- *
- * @param file The file to be set.
- */
- static void setReadOnlyChecked(final File file) {
- if (file.exists()) {
- SafeRunner.run(new ISafeRunnable(){
- @Override
- public void run() throws Exception {
- if (!file.setReadOnly()) {
- throw new Exception(NLS.bind(Messages.OpStreamOp_SetReadOnlyFailed, file.getAbsolutePath()));
- }
- }
-
- @Override
- public void handleException(Throwable exception) {
- // Ignore on purpose
- }});
- }
- }
-
- /**
- * Get the local file of the specified node.
- *
- * <p>
- * The preferred location is within the plugin's state location, in
- * example <code>&lt;state location&gt;agent_<hashcode_of_peerId>/remote/path/to/the/file...</code>.
- * <p>
- * If the plug-in is loaded in a RCP workspace-less environment, the
- * fall back strategy is to use the users home directory.
- *
- * @param node
- * The file/folder node.
- * @return The file object of the node's local cache.
- */
- public static File getCacheFile(FSTreeNode node){
- return getCachePath(node).toFile();
- }
-
- /**
- * Get the cache file system's root directory on the local host's
- * file system.
- *
- * @return The root folder's location of the cache file system.
- */
- public static File getCacheRoot() {
- File location;
- try {
- location = CorePlugin.getDefault().getStateLocation().toFile();
- }catch (IllegalStateException e) {
- // An RCP workspace-less environment (-data @none)
- location = new File(System.getProperty("user.home"), ".tcf"); //$NON-NLS-1$ //$NON-NLS-2$
- location = new File(location, "fs"); //$NON-NLS-1$
- }
-
- // Create the location if it not exist
- mkdirChecked(location);
- return location;
- }
-
- /**
- * Append the path with the specified node's context path.
- *
- * @param path
- * The path to be appended.
- * @param node
- * The file/folder node.
- * @return The path to the node.
- */
- private static IPath appendNodePath(IPath path, FSTreeNode node) {
- if (!node.isRoot() && node.getParent()!=null) {
- path = appendNodePath(path, node.getParent());
- return appendPathSegment(node, path, node.name);
- }
- if (node.isWindowsNode()) {
- String name = node.name;
- name = name.substring(0, name.length()-1);
- name = name.replace(':', PATH_ESCAPE_CHAR);
- return appendPathSegment(node, path, name);
- }
- return path;
- }
-
- /**
- * Append the path with the segment "name". Create a directory
- * if the node is a directory which does not yet exist.
- *
- * @param node The file/folder node.
- * @param path The path to appended.
- * @param name The segment's name.
- * @return The path with the segment "name" appended.
- */
- private static IPath appendPathSegment(FSTreeNode node, IPath path, String name) {
- IPath newPath = path.append(name);
- File newFile = newPath.toFile();
- if (node.isDirectory()) {
- mkdirChecked(newFile);
- }
- return newPath;
- }
-}
+/*******************************************************************************
+ * 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
+ * William Chen (Wind River)- [345387] Open the remote files with a proper editor
+ * William Chen (Wind River)- [345552] Edit the remote files with a proper editor
+ *******************************************************************************/
+package org.eclipse.tcf.te.tcf.filesystem.core.internal.utils;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.tcf.te.tcf.filesystem.core.activator.CorePlugin;
+import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
+import org.eclipse.tcf.te.tcf.filesystem.core.nls.Messages;
+
+/**
+ * The local file system cache used to manage the temporary files downloaded from a remote file
+ * system.
+ */
+public class CacheManager {
+ public static final char PATH_ESCAPE_CHAR = '$';
+
+ /**
+ * Get the local path of a node's cached file.
+ * <p>
+ * The preferred location is within the plugin's state location, in example
+ * <code>&lt;state location&gt;agent_<hashcode_of_peerId>/remote/path/to/the/file...</code>.
+ * <p>
+ * If the plug-in is loaded in a RCP workspace-less environment, the fall back strategy is to
+ * use the users home directory.
+ *
+ * @param node The file/folder node.
+ * @return The local path of the node's cached file.
+ */
+ public static IPath getCachePath(FSTreeNode node) {
+ File location = getCacheRoot();
+ String agentId = node.peerNode.getPeerId();
+ // Use Math.abs to avoid negative hash value.
+ String agent = agentId.replace(':', PATH_ESCAPE_CHAR);
+ IPath agentDir = new Path(location.getAbsolutePath()).append(agent);
+ File agentDirFile = agentDir.toFile();
+ mkdirChecked(agentDirFile);
+ return appendNodePath(agentDir, node);
+ }
+
+ /**
+ * Check and make a directory if it does not exist. Record the failure message if making fails.
+ *
+ * @param file The file to be deleted.
+ */
+ static void mkdirChecked(final File dir) {
+ if (!dir.exists()) {
+ SafeRunner.run(new ISafeRunnable() {
+ @Override
+ public void run() throws Exception {
+ if (!dir.mkdir()) {
+ throw new Exception(NLS.bind(Messages.CacheManager_MkdirFailed, dir
+ .getAbsolutePath()));
+ }
+ }
+
+ @Override
+ public void handleException(Throwable exception) {
+ // Ignore on purpose
+ }
+ });
+ }
+ }
+
+ /**
+ * Check if the file exists and delete if it does. Record the failure message if deleting fails.
+ *
+ * @param file The file to be deleted.
+ */
+ static void deleteFileChecked(final File file) {
+ if (file.exists()) {
+ SafeRunner.run(new ISafeRunnable() {
+ @Override
+ public void run() throws Exception {
+ if (!file.delete()) {
+ throw new Exception(NLS.bind(Messages.Operation_DeletingFileFailed, file
+ .getAbsolutePath()));
+ }
+ }
+
+ @Override
+ public void handleException(Throwable exception) {
+ // Ignore on purpose
+ }
+ });
+ }
+ }
+
+ /**
+ * Check if the file exists and set its read-only attribute if it does. Record the failure
+ * message if it fails.
+ *
+ * @param file The file to be set.
+ */
+ static void setReadOnlyChecked(final File file) {
+ if (file.exists()) {
+ SafeRunner.run(new ISafeRunnable() {
+ @Override
+ public void run() throws Exception {
+ if (!file.setReadOnly()) {
+ throw new Exception(NLS.bind(Messages.OpStreamOp_SetReadOnlyFailed, file
+ .getAbsolutePath()));
+ }
+ }
+
+ @Override
+ public void handleException(Throwable exception) {
+ // Ignore on purpose
+ }
+ });
+ }
+ }
+
+ /**
+ * Get the local file of the specified node.
+ *
+ * <p>
+ * The preferred location is within the plugin's state location, in example
+ * <code>&lt;state location&gt;agent_<hashcode_of_peerId>/remote/path/to/the/file...</code>.
+ * <p>
+ * If the plug-in is loaded in a RCP workspace-less environment, the fall back strategy is to
+ * use the users home directory.
+ *
+ * @param node The file/folder node.
+ * @return The file object of the node's local cache.
+ */
+ public static File getCacheFile(FSTreeNode node) {
+ return getCachePath(node).toFile();
+ }
+
+ /**
+ * Get the cache file system's root directory on the local host's file system.
+ *
+ * @return The root folder's location of the cache file system.
+ */
+ public static File getCacheRoot() {
+ File location;
+ try {
+ location = CorePlugin.getDefault().getStateLocation().toFile();
+ }
+ catch (IllegalStateException e) {
+ // An RCP workspace-less environment (-data @none)
+ location = new File(System.getProperty("user.home"), ".tcf"); //$NON-NLS-1$ //$NON-NLS-2$
+ location = new File(location, "fs"); //$NON-NLS-1$
+ }
+
+ // Create the location if it not exist
+ mkdirChecked(location);
+ return location;
+ }
+
+ /**
+ * Append the path with the specified node's context path.
+ *
+ * @param path The path to be appended.
+ * @param node The file/folder node.
+ * @return The path to the node.
+ */
+ private static IPath appendNodePath(IPath path, FSTreeNode node) {
+ if (!node.isRoot() && node.getParent() != null) {
+ path = appendNodePath(path, node.getParent());
+ return appendPathSegment(node, path, node.name);
+ }
+ if (node.isWindowsNode()) {
+ String name = node.name;
+ name = name.substring(0, name.length() - 1);
+ name = name.replace(':', PATH_ESCAPE_CHAR);
+ return appendPathSegment(node, path, name);
+ }
+ return path;
+ }
+
+ /**
+ * Append the path with the segment "name". Create a directory if the node is a directory which
+ * does not yet exist.
+ *
+ * @param node The file/folder node.
+ * @param path The path to appended.
+ * @param name The segment's name.
+ * @return The path with the segment "name" appended.
+ */
+ private static IPath appendPathSegment(FSTreeNode node, IPath path, String name) {
+ IPath newPath = path.append(name);
+ File newFile = newPath.toFile();
+ if (node.isDirectory()) {
+ mkdirChecked(newFile);
+ }
+ return newPath;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.properties
index fc729e6ba..7c9dcb987 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/plugin.properties
@@ -65,11 +65,11 @@ command.revert.name = Revert File
command.delete.label=Delete
command.delete.description=Delete the selected node
-decorator.modified.label = Modified Cache
-decorator.outdated.label = Outdated Cache
-decorator.conflict.label = Conflicting Cache
-decorator.label.cut = Cut File
-decorator.hidden.label = Hidden File
+decorator.modified.label = Remote File System Modified Cache Decorator
+decorator.outdated.label = Remote File System Outdated Cache Decorator
+decorator.conflict.label = Remote File System Conflicting Cache Decorator
+decorator.label.cut = Remote File System Cut File Decorator
+decorator.hidden.label = Remote File System Hidden File Decorator
menu.label.openwith = Open With
menu.new.label = &New
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/NodeStateFilter.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/NodeStateFilter.java
index 155dd565e..a0bce1bb5 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/NodeStateFilter.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/adapters/NodeStateFilter.java
@@ -1,78 +1,78 @@
-/*******************************************************************************
- * 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.ui.internal.adapters;
-
-import java.util.List;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpClipboard;
-import org.eclipse.tcf.te.tcf.filesystem.core.model.CacheState;
-import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
-import org.eclipse.tcf.te.tcf.filesystem.ui.activator.UIPlugin;
-import org.eclipse.ui.IActionFilter;
-
-/**
- * This action filter wraps an FSTreeNode and test its attribute of "cache.state".
- * It serves as the expression filter of decorations of Target Explorer.
- */
-public class NodeStateFilter implements IActionFilter {
- private FSTreeNode node;
-
- /**
- * Constructor.
- *
- * @param node
- * The wrapped tree node. Must not be <code>null</code>.
- */
- public NodeStateFilter(FSTreeNode node) {
- Assert.isNotNull(node);
- this.node = node;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.IActionFilter#testAttribute(java.lang.Object, java.lang.String, java.lang.String)
- */
- @Override
- public boolean testAttribute(Object target, String name, String value) {
- if (name.equals("cache.state") && node.isFile()) { //$NON-NLS-1$
- if(UIPlugin.isAutoSaving())
- return false;
- CacheState state = node.getCacheState();
- if (value == null)
- value = CacheState.consistent.name();
- return value.equals(state.name());
- }
- else if (name.equals("edit.cut")) { //$NON-NLS-1$
- OpClipboard cb = UIPlugin.getClipboard();
- if (!cb.isEmpty()) {
- if (cb.isCutOp()) {
- List<FSTreeNode> files = cb.getFiles();
- for (FSTreeNode file : files) {
- if (node == file) return true;
- }
- }
- }
- }
- else if (name.equals("hidden")) { //$NON-NLS-1$
- if (value == null) value = "true"; //$NON-NLS-1$
- boolean result = false;
- if (!node.isRoot()) {
- if (node.isWindowsNode()) {
- result = node.isHidden();
- }
- else {
- result = node.name.startsWith("."); //$NON-NLS-1$
- }
- }
- return Boolean.toString(result).equals(value);
- }
- return false;
- }
-}
+/*******************************************************************************
+ * 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.ui.internal.adapters;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpClipboard;
+import org.eclipse.tcf.te.tcf.filesystem.core.model.CacheState;
+import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
+import org.eclipse.tcf.te.tcf.filesystem.ui.activator.UIPlugin;
+import org.eclipse.ui.IActionFilter;
+
+/**
+ * This action filter wraps an FSTreeNode and test its attribute of "cache.state".
+ * It serves as the expression filter of decorations of Target Explorer.
+ */
+public class NodeStateFilter implements IActionFilter {
+ private FSTreeNode node;
+
+ /**
+ * Constructor.
+ *
+ * @param node
+ * The wrapped tree node. Must not be <code>null</code>.
+ */
+ public NodeStateFilter(FSTreeNode node) {
+ Assert.isNotNull(node);
+ this.node = node;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionFilter#testAttribute(java.lang.Object, java.lang.String, java.lang.String)
+ */
+ @Override
+ public boolean testAttribute(Object target, String name, String value) {
+ if (name.equals("cache.state") && node.isFile()) { //$NON-NLS-1$
+ if(UIPlugin.isAutoSaving())
+ return false;
+ CacheState state = node.getCacheState();
+ if (value == null)
+ value = CacheState.consistent.name();
+ return value.equals(state.name());
+ }
+ else if (name.equals("edit.cut")) { //$NON-NLS-1$
+ OpClipboard cb = UIPlugin.getClipboard();
+ if (!cb.isEmpty()) {
+ if (cb.isCutOp()) {
+ List<FSTreeNode> files = cb.getFiles();
+ for (FSTreeNode file : files) {
+ if (node == file) return true;
+ }
+ }
+ }
+ }
+ else if (name.equals("hidden")) { //$NON-NLS-1$
+ if (value == null) value = "true"; //$NON-NLS-1$
+ boolean result = false;
+ if (!node.isRoot()) {
+ if (node.isWindowsNode()) {
+ result = node.isHidden();
+ }
+ else {
+ result = node.name.startsWith("."); //$NON-NLS-1$
+ }
+ }
+ return Boolean.toString(result).equals(value);
+ }
+ return false;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/OpenFileHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/OpenFileHandler.java
index aa2540899..1687c171f 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/OpenFileHandler.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/OpenFileHandler.java
@@ -1,115 +1,141 @@
-/*******************************************************************************
- * 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:
- * William Chen (Wind River)- [345387]Open the remote files with a proper editor
- *******************************************************************************/
-package org.eclipse.tcf.te.tcf.filesystem.ui.internal.handlers;
-
-import java.io.File;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.filesystem.EFS;
-import org.eclipse.core.filesystem.IFileStore;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.IOpExecutor;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpCacheUpdate;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.utils.CacheManager;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.utils.ContentTypeHelper;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.utils.PersistenceManager;
-import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
-import org.eclipse.tcf.te.tcf.filesystem.ui.internal.operations.UiExecutor;
-import org.eclipse.tcf.te.tcf.filesystem.ui.nls.Messages;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.eclipse.ui.ide.FileStoreEditorInput;
-import org.eclipse.ui.ide.IDE;
-
-/**
- * The action handler to open a file on the remote file system.
- */
-public class OpenFileHandler extends AbstractHandler {
-
- /* (non-Javadoc)
- * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
- */
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
- final FSTreeNode node = (FSTreeNode) selection.getFirstElement();
- IWorkbenchPage page = HandlerUtil.getActiveSite(event).getPage();
- if (ContentTypeHelper.isBinaryFile(node)) {
- // If the file is a binary file.
- Shell parent = HandlerUtil.getActiveShell(event);
- MessageDialog.openWarning(parent, Messages.OpenFileHandler_Warning,
- Messages.OpenFileHandler_OpeningBinaryNotSupported);
- } else {
- // Open the file node.
- openFile(node, page);
- }
- return null;
- }
-
- /**
- * Open the file node in an editor of the specified workbench page. If the
- * local cache file of the node is stale, then download it. Then open its
- * local cache file.
- *
- * @param node
- * The file node to be opened.
- * @param page
- * The workbench page in which the editor is opened.
- */
- private void openFile(FSTreeNode node, IWorkbenchPage page) {
- File file = CacheManager.getCacheFile(node);
- if (!file.exists()) {
- // If the file node's local cache does not exist yet, download it.
- IOpExecutor executor = new UiExecutor();
- IStatus status = executor.execute(new OpCacheUpdate(node));
- if (!status.isOK()) {
- return;
- }
- }
- openEditor(page, node);
- }
-
- /**
- * Open the editor to display the file node in the UI thread.
- *
- * @param page
- * The workbench page in which the editor is opened.
- * @param node
- * The file node whose local cache file is opened.
- */
- private void openEditor(final IWorkbenchPage page, final FSTreeNode node) {
- Display display = page.getWorkbenchWindow().getWorkbench().getDisplay();
- display.asyncExec(new Runnable() {
- @Override
- public void run() {
- IPath path = CacheManager.getCachePath(node);
- IFileStore fileStore = EFS.getLocalFileSystem().getStore(path);
- String editorID = PersistenceManager.getInstance().getPersistentProperties(node).get(IDE.EDITOR_KEY);
- try {
- if(editorID!=null){
- FileStoreEditorInput input = new FileStoreEditorInput(fileStore);
- page.openEditor(input, editorID, true, IWorkbenchPage.MATCH_INPUT|IWorkbenchPage.MATCH_ID);
- }else{
- IDE.openEditorOnFileStore(page, fileStore);
- }
- } catch (PartInitException e) {
- }
- }
- });
- }
-}
+/*******************************************************************************
+ * 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:
+ * William Chen (Wind River)- [345387]Open the remote files with a proper editor
+ *******************************************************************************/
+package org.eclipse.tcf.te.tcf.filesystem.ui.internal.handlers;
+
+import java.io.File;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.tcf.te.runtime.callback.Callback;
+import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.IOpExecutor;
+import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpCacheUpdate;
+import org.eclipse.tcf.te.tcf.filesystem.core.internal.utils.CacheManager;
+import org.eclipse.tcf.te.tcf.filesystem.core.internal.utils.ContentTypeHelper;
+import org.eclipse.tcf.te.tcf.filesystem.core.internal.utils.PersistenceManager;
+import org.eclipse.tcf.te.tcf.filesystem.core.model.CacheState;
+import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
+import org.eclipse.tcf.te.tcf.filesystem.ui.activator.UIPlugin;
+import org.eclipse.tcf.te.tcf.filesystem.ui.internal.operations.UiExecutor;
+import org.eclipse.tcf.te.tcf.filesystem.ui.nls.Messages;
+import org.eclipse.tcf.te.ui.swt.DisplayUtil;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.ide.FileStoreEditorInput;
+import org.eclipse.ui.ide.IDE;
+
+/**
+ * The action handler to open a file on the remote file system.
+ */
+public class OpenFileHandler extends AbstractHandler {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
+ final FSTreeNode node = (FSTreeNode) selection.getFirstElement();
+ final IWorkbenchPage page = HandlerUtil.getActiveSite(event).getPage();
+ if (ContentTypeHelper.isBinaryFile(node)) {
+ // If the file is a binary file.
+ Shell parent = HandlerUtil.getActiveShell(event);
+ MessageDialog.openWarning(parent, Messages.OpenFileHandler_Warning,
+ Messages.OpenFileHandler_OpeningBinaryNotSupported);
+ } else {
+ if (UIPlugin.isAutoSaving()) {
+ // Refresh the node to determine the cache state correctly
+ node.refresh(new Callback() {
+ @Override
+ protected void internalDone(Object caller, IStatus status) {
+ File file = CacheManager.getCacheFile(node);
+ if (node.getCacheState() == CacheState.outdated) {
+ file.delete();
+ }
+
+ DisplayUtil.safeAsyncExec(new Runnable() {
+ @Override
+ public void run() {
+ // Open the file node.
+ openFile(node, page);
+ }
+ });
+ }
+ });
+ } else {
+ // Open the file node.
+ openFile(node, page);
+ }
+
+ }
+ return null;
+ }
+
+ /**
+ * Open the file node in an editor of the specified workbench page. If the
+ * local cache file of the node is stale, then download it. Then open its
+ * local cache file.
+ *
+ * @param node
+ * The file node to be opened.
+ * @param page
+ * The workbench page in which the editor is opened.
+ */
+ /* default */ void openFile(FSTreeNode node, IWorkbenchPage page) {
+ File file = CacheManager.getCacheFile(node);
+ if (!file.exists()) {
+ // If the file node's local cache does not exist yet, download it.
+ IOpExecutor executor = new UiExecutor();
+ IStatus status = executor.execute(new OpCacheUpdate(node));
+ if (!status.isOK()) {
+ return;
+ }
+ }
+ openEditor(page, node);
+ }
+
+ /**
+ * Open the editor to display the file node in the UI thread.
+ *
+ * @param page
+ * The workbench page in which the editor is opened.
+ * @param node
+ * The file node whose local cache file is opened.
+ */
+ private void openEditor(final IWorkbenchPage page, final FSTreeNode node) {
+ Display display = page.getWorkbenchWindow().getWorkbench().getDisplay();
+ display.asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ IPath path = CacheManager.getCachePath(node);
+ IFileStore fileStore = EFS.getLocalFileSystem().getStore(path);
+ String editorID = PersistenceManager.getInstance().getPersistentProperties(node).get(IDE.EDITOR_KEY);
+ try {
+ if(editorID!=null){
+ FileStoreEditorInput input = new FileStoreEditorInput(fileStore);
+ page.openEditor(input, editorID, true, IWorkbenchPage.MATCH_INPUT|IWorkbenchPage.MATCH_ID);
+ }else{
+ IDE.openEditorOnFileStore(page, fileStore);
+ }
+ } catch (PartInitException e) {
+ }
+ }
+ });
+ }
+}

Back to the top