From 8f48d3c6f1d1d1b4d67afb9bd3eb8bc61c0b66f0 Mon Sep 17 00:00:00 2001 From: Uwe Stieber Date: Wed, 10 Jul 2013 15:07:03 +0200 Subject: Target Explorer: Fix - Remote file change not detected --- .../plugin.properties | 10 +- .../ui/internal/adapters/NodeStateFilter.java | 156 ++++++------- .../ui/internal/handlers/OpenFileHandler.java | 256 ++++++++++++--------- 3 files changed, 224 insertions(+), 198 deletions(-) (limited to 'target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui') 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 null. - */ - 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 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 null. + */ + 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 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) { + } + } + }); + } +} -- cgit v1.2.3