diff options
author | Uwe Stieber | 2012-11-22 08:56:16 +0000 |
---|---|---|
committer | Uwe Stieber | 2012-11-22 08:56:16 +0000 |
commit | f2de62a27c6056b824cf5f73671e44a311c38617 (patch) | |
tree | c775d6058d9a3fa4560cb4eb13d8bcede561c65b /target_explorer | |
parent | 34a4a88c1a97ec9df6bec63dd5d3f3ef72779983 (diff) | |
download | org.eclipse.tcf-f2de62a27c6056b824cf5f73671e44a311c38617.tar.gz org.eclipse.tcf-f2de62a27c6056b824cf5f73671e44a311c38617.tar.xz org.eclipse.tcf-f2de62a27c6056b824cf5f73671e44a311c38617.zip |
Target Explorer: Remote FS open dialog can have a initial selection to reveal
Diffstat (limited to 'target_explorer')
2 files changed, 130 insertions, 1 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/dialogs/FSOpenFileDialog.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/dialogs/FSOpenFileDialog.java index 0800a95f1..23ed94811 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/dialogs/FSOpenFileDialog.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/dialogs/FSOpenFileDialog.java @@ -9,16 +9,23 @@ *******************************************************************************/ package org.eclipse.tcf.te.tcf.filesystem.ui.dialogs; +import java.util.concurrent.atomic.AtomicInteger; + import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.jface.viewers.DecoratingLabelProvider; import org.eclipse.jface.viewers.ILabelDecorator; import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Shell; +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.ui.activator.UIPlugin; import org.eclipse.tcf.te.tcf.filesystem.ui.controls.FSTreeContentProvider; @@ -26,7 +33,9 @@ import org.eclipse.tcf.te.tcf.filesystem.ui.controls.FSTreeViewerSorter; import org.eclipse.tcf.te.tcf.filesystem.ui.interfaces.IFSConstants; import org.eclipse.tcf.te.tcf.filesystem.ui.internal.columns.FSTreeElementLabelProvider; import org.eclipse.tcf.te.tcf.filesystem.ui.nls.Messages; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; import org.eclipse.tcf.te.ui.trees.FilterDescriptor; +import org.eclipse.tcf.te.ui.trees.Pending; import org.eclipse.tcf.te.ui.trees.ViewerStateManager; import org.eclipse.ui.IDecoratorManager; import org.eclipse.ui.IWorkbench; @@ -39,6 +48,9 @@ import org.eclipse.ui.dialogs.ISelectionStatusValidator; * File system open file dialog. */ public class FSOpenFileDialog extends ElementTreeSelectionDialog { + private String filterPath = null; + /* default */ TreeViewer viewer = null; + /** * Create an FSFolderSelectionDialog using the specified shell as the parent. * @@ -71,6 +83,15 @@ public class FSOpenFileDialog extends ElementTreeSelectionDialog { }); } + /** + * Sets the filter path. + * + * @param filterPath The filter path or <code>null</code>. + */ + public void setFilterPath(String filterPath) { + this.filterPath = filterPath; + } + /* * (non-Javadoc) * @see org.eclipse.ui.dialogs.ElementTreeSelectionDialog#setInput(java.lang.Object) @@ -87,6 +108,113 @@ public class FSOpenFileDialog extends ElementTreeSelectionDialog { } } + /* (non-Javadoc) + * @see org.eclipse.ui.dialogs.ElementTreeSelectionDialog#create() + */ + @Override + public void create() { + super.create(); + + if (filterPath != null && !"".equals(filterPath.trim())) { //$NON-NLS-1$ + IPath path = new Path(filterPath); + if (viewer.getInput() instanceof IPeerModel) { + Object element = null; + FSModel model = FSModel.getFSModel((IPeerModel)viewer.getInput()); + if (model != null) { + FSTreeNode root = model.getRoot(); + ITreeContentProvider contentProvider = (ITreeContentProvider)viewer.getContentProvider(); + Object[] elements = contentProvider.getElements(root); + String segment = path.getDevice() != null ? path.getDevice() : path.segmentCount() > 0 ? path.segment(0) : null; + if (segment != null) { + for (Object elem : elements) { + if (!(elem instanceof FSTreeNode)) break; + FSTreeNode child = (FSTreeNode)elem; + String name = child.name; + if (name.endsWith("\\") || name.endsWith("/")) name = name.substring(0, name.length() - 1); //$NON-NLS-1$ //$NON-NLS-2$ + boolean matches = child.isWindowsNode() ? name.equalsIgnoreCase(segment) : name.equals(segment); + if (matches) { + if (path.segmentCount() > (path.getDevice() != null ? 0 : 1)) { + // Have to drill down a bit further + element = findRecursive(child, path, path.getDevice() != null ? 0 : 1); + if (element != null) break; + } else { + element = child; + break; + } + } + } + } + } + + if (element != null) { + final ISelection selection = new StructuredSelection(element); + final AtomicInteger counter = new AtomicInteger(); + + Runnable runnable = new Runnable() { + @Override + public void run() { + viewer.setSelection(selection, true); + if (!selection.equals(viewer.getSelection())) { + if (counter.incrementAndGet() <= 10) { + viewer.getControl().getDisplay().asyncExec(this); + } + } + } + }; + + viewer.getControl().getDisplay().asyncExec(runnable); + } + } + } + } + + /** + * Finds the given path within the file system hierarchy. + * + * @param parent The parent file system node. Must not be <code>null</code>. + * @param path The path. Must not be <code>null</code>. + * @param index The segment index. + * + * @return The matching file system node or <code>null</code>. + */ + private FSTreeNode findRecursive(FSTreeNode parent, IPath path, int index) { + Assert.isNotNull(parent); + Assert.isNotNull(path); + + FSTreeNode node = null; + + ITreeContentProvider contentProvider = (ITreeContentProvider)viewer.getContentProvider(); + Object[] elements = contentProvider.getElements(parent); + while (elements.length == 1 && elements[0] instanceof Pending) { + try { + Thread.sleep(100); + } catch (InterruptedException e) {} + elements = contentProvider.getElements(parent); + } + + String segment = path.segment(index); + + for (Object element : elements) { + if (!(element instanceof FSTreeNode)) break; + FSTreeNode child = (FSTreeNode)element; + String name = child.name; + if (name.endsWith("\\") || name.endsWith("/")) name = name.substring(0, name.length() - 1); //$NON-NLS-1$ //$NON-NLS-2$ + boolean matches = child.isWindowsNode() ? name.equalsIgnoreCase(segment) : name.equals(segment); + if (matches) { + if (path.segmentCount() > index + 1) { + // Have to drill down a bit further + node = findRecursive(child, path, index + 1); + if (node != null) break; + } else { + node = child; + break; + } + } + } + + return node; + } + /** * Create a decorating label provider using the specified label provider. * @@ -105,7 +233,7 @@ public class FSOpenFileDialog extends ElementTreeSelectionDialog { */ @Override protected TreeViewer doCreateTreeViewer(Composite parent, int style) { - TreeViewer viewer = super.doCreateTreeViewer(parent, style); + viewer = super.doCreateTreeViewer(parent, style); viewer.getTree().setLinesVisible(false); return viewer; } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/LaunchConfigurationMainTabSection.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/LaunchConfigurationMainTabSection.java index 3710b8ce5..320ea83aa 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/LaunchConfigurationMainTabSection.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.ui/src/org/eclipse/tcf/te/tcf/launch/ui/remote/app/LaunchConfigurationMainTabSection.java @@ -95,6 +95,7 @@ public class LaunchConfigurationMainTabSection extends AbstractSection implement protected void onButtonControlSelected() { if (firstSelection != null) { FSOpenFileDialog dialog = new FSOpenFileDialog(section.getShell()); + dialog.setFilterPath(getEditFieldControlText()); dialog.setInput(firstSelection); if (dialog.open() == Window.OK) { Object candidate = dialog.getFirstResult(); |