From a921481a0bf6cb61be87a179e5fbeec342da9154 Mon Sep 17 00:00:00 2001 From: David McKnight Date: Mon, 26 Jan 2009 20:20:06 +0000 Subject: [PATCH] [218227][usability] Contribute a "Show in RSE" action to Resource Navigator and Project Explorer --- .../plugin.properties | 7 ++ .../org.eclipse.rse.files.ui/plugin.xml | 17 ++++ .../ShowResourceInSystemsViewDelegate.java | 91 +++++++++++++++++++ .../ui/actions/ShowInSystemsViewDelegate.java | 17 ++-- 4 files changed, 124 insertions(+), 8 deletions(-) create mode 100644 rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/ShowResourceInSystemsViewDelegate.java diff --git a/rse/plugins/org.eclipse.rse.files.ui/plugin.properties b/rse/plugins/org.eclipse.rse.files.ui/plugin.properties index 22623b1110d..e9b6f0628b8 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/plugin.properties +++ b/rse/plugins/org.eclipse.rse.files.ui/plugin.properties @@ -15,6 +15,7 @@ # Willian Mitsuda - [184824] added a Remote action set item # David McKnight (IBM) - [187711] Link with Editor action for System View # David McKnight (IBM) - [209593] [api] add support for "file permissions" and "owner" properties for unix files +# David McKnight (IBM) - [218227][usability] Contribute a "Show in RSE" action to Resource Navigator and Project Explorer ############################################################################### # NLS_MESSAGEFORMAT_NONE @@ -55,3 +56,9 @@ Remote.Search = &Remote... Remote.Search.tooltip = Opens Remote Search dialog page for text and file searching on remote systems LinkWithSystemView.label = Link with Editor + +# Show in RSE View +ShowInRSEView.label = Show in Remote Systems view +ShowInRSEView.tooltip = Display the selected resource in the Remote Systems view + + diff --git a/rse/plugins/org.eclipse.rse.files.ui/plugin.xml b/rse/plugins/org.eclipse.rse.files.ui/plugin.xml index cce62093066..19cada87b28 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/plugin.xml +++ b/rse/plugins/org.eclipse.rse.files.ui/plugin.xml @@ -13,6 +13,7 @@ Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. Contributors: David McKnight (IBM) - [261019] New File/Folder actions available in Work Offline mode +David McKnight (IBM) - [218227][usability] Contribute a "Show in RSE" action to Resource Navigator and Project Explorer --> @@ -474,5 +475,21 @@ David McKnight (IBM) - [261019] New File/Folder actions available in Wo + + + + + menubarPath="group.goto" + enablesFor="1" + id="showResourceInSystemsView"> + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/ShowResourceInSystemsViewDelegate.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/ShowResourceInSystemsViewDelegate.java new file mode 100644 index 00000000000..eef0da36224 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/ShowResourceInSystemsViewDelegate.java @@ -0,0 +1,91 @@ +/******************************************************************************** + * Copyright (c) 2009 IBM Corporation. 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 + * + * Initial Contributors: + * The following IBM employees contributed to the Remote System Explorer + * component that contains this file: David McKnight. + * + * Contributors: + * David McKnight (IBM) - [218227][usability] Contribute a "Show in RSE" action to Resource Navigator and Project Explorer + ********************************************************************************/ +package org.eclipse.rse.internal.files.ui.actions; + +import java.net.URI; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.action.IAction; +import org.eclipse.rse.core.RSECorePlugin; +import org.eclipse.rse.core.model.IHost; +import org.eclipse.rse.core.model.ISystemProfile; +import org.eclipse.rse.core.model.ISystemRegistry; +import org.eclipse.rse.internal.ui.actions.ShowInSystemsViewDelegate; +import org.eclipse.rse.subsystems.files.core.model.RemoteFileUtility; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; + +public class ShowResourceInSystemsViewDelegate extends + ShowInSystemsViewDelegate { + + public void run(IAction action) { + + if (_selectedObject instanceof IResource){ + Object remoteObject = null; + IResource resource = (IResource)_selectedObject; + ISystemRegistry sr = RSECorePlugin.getTheSystemRegistry(); + // need to find the remote equivalent of this + IPath location = resource.getLocation(); + + if (location != null){ + String fullPath = location.toOSString(); + + IHost localHost = sr.getLocalHost(); + if (localHost != null){ + IRemoteFileSubSystem ss = RemoteFileUtility.getFileSubSystem(localHost); + try { + remoteObject = ss.getRemoteFileObject(fullPath, new NullProgressMonitor()); + } + catch (Exception e) { + } + } + } + else { + URI uri = resource.getLocationURI(); + + String hostName = uri.getHost(); + String fullPath = uri.getPath(); + + IHost host = null; + + // find the host + ISystemProfile[] profiles = sr.getSystemProfileManager().getActiveSystemProfiles(); + for (int i = 0; i < profiles.length && host == null; i++){ + ISystemProfile profile = profiles[i]; + host = sr.getHost(profile, hostName); + } + + if (host != null){ + IRemoteFileSubSystem ss = RemoteFileUtility.getFileSubSystem(host); + try { + remoteObject = ss.getRemoteFileObject(fullPath, new NullProgressMonitor()); + } + catch (Exception e) { + } + } + + } + + if (remoteObject != null){ + _selectedObject = remoteObject; + } + else { + //unable to find remote object equivalent so returning + return; + } + } + super.run(action); + } +} diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/actions/ShowInSystemsViewDelegate.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/actions/ShowInSystemsViewDelegate.java index b816692f4d0..bce67adb7f7 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/actions/ShowInSystemsViewDelegate.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/actions/ShowInSystemsViewDelegate.java @@ -10,6 +10,7 @@ * * Contributors: * David McKnight (IBM) - [160105] [usability] Universal action needed to locate a resource in the Remote Systems View + * David McKnight (IBM) - [218227][usability] Contribute a "Show in RSE" action to Resource Navigator and Project Explorer ********************************************************************************/ package org.eclipse.rse.internal.ui.actions; @@ -318,7 +319,7 @@ public class ShowInSystemsViewDelegate implements IViewActionDelegate { } private IAction _action; - private Object _remoteObject; + protected Object _selectedObject; private SystemViewPart _systemViewPart; public void init(IViewPart view) { @@ -330,19 +331,19 @@ public class ShowInSystemsViewDelegate implements IViewActionDelegate { SystemView systemTree = viewPart.getSystemView(); // now we've got to show the object in this view part - TreeItem item = (TreeItem)systemTree.findFirstRemoteItemReference(_remoteObject, null); + TreeItem item = (TreeItem)systemTree.findFirstRemoteItemReference(_selectedObject, null); if (item != null){ systemTree.getTree().setSelection(item); } - else if (_remoteObject instanceof IAdaptable) + else if (_selectedObject instanceof IAdaptable) { - ISystemViewElementAdapter adapter = (ISystemViewElementAdapter)((IAdaptable)_remoteObject).getAdapter(ISystemViewElementAdapter.class); + ISystemViewElementAdapter adapter = getAdapter((IAdaptable)_selectedObject); if (adapter != null){ - ISubSystem subSystem = adapter.getSubSystem(_remoteObject); + ISubSystem subSystem = adapter.getSubSystem(_selectedObject); if (subSystem.getSubSystemConfiguration().supportsFilters()){ // no match, so we will expand from filter // query matching filter in a job (to avoid main thread) - LinkFromFilterJob job = new LinkFromFilterJob((IAdaptable)_remoteObject, systemTree); + LinkFromFilterJob job = new LinkFromFilterJob((IAdaptable)_selectedObject, systemTree); job.schedule(); } else { @@ -351,7 +352,7 @@ public class ShowInSystemsViewDelegate implements IViewActionDelegate { // put these items in the tree and look for remote object // if we can't find the remote object under this, the ShowChildrenInTree will recurse - Display.getDefault().asyncExec(new ShowChildrenInTree(subSystem, children, null, systemTree, (IAdaptable)_remoteObject)); + Display.getDefault().asyncExec(new ShowChildrenInTree(subSystem, children, null, systemTree, (IAdaptable)_selectedObject)); } } } @@ -381,7 +382,7 @@ public class ShowInSystemsViewDelegate implements IViewActionDelegate { IStructuredSelection sel = (IStructuredSelection)selection; if (sel.size() == 1){ _action.setEnabled(true); - _remoteObject = sel.getFirstElement(); + _selectedObject = sel.getFirstElement(); } else { _action.setEnabled(false);