Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » [newbie] Getting the selected resource in a popup menu action
[newbie] Getting the selected resource in a popup menu action [message #251304] Wed, 09 June 2004 21:28 Go to next message
Eclipse UserFriend
Originally posted by: kapland.uci.edu

It seems like every single pop-up menu action in the documentation always
creates a dialog box. But what I would like to do is do something with the
file that I just right-clicked on to make that pop-up menu show up in the
first place.

How do I do this? Is there a method called getSelectedResource() or
something? Thanks.
Re: [newbie] Getting the selected resource in a popup menu action [message #251452 is a reply to message #251304] Thu, 10 June 2004 10:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.NO.SPAM.us.ibm.com

If your action was contributed through the plugin.xml, then it must
implement IActionDelegate. If so, then it is told what was selected via
the setSelection method.


--
Thanks, Rich Kulp

Re: [newbie] Getting the selected resource in a popup menu action [message #251541 is a reply to message #251452] Thu, 10 June 2004 13:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kapland.uci.edu

I've checked the API and i see no existence of setSelection method in an
IActionDelegate

Would you mind being a little more detailed in how to do it? This is how i
currently do it:

package MenuSample.popup.actions;

import org.eclipse.jface.action.IAction;

import org.eclipse.jface.dialogs.MessageDialog;

import org.eclipse.jface.viewers.ISelection;

import org.eclipse.swt.widgets.Shell;

import org.eclipse.ui.IObjectActionDelegate;

import org.eclipse.ui.IWorkbenchPart;

import org.eclipse.ui.IWorkbenchWindow;

import org.eclipse.jface.viewers.IStructuredSelection;

import org.eclipse.core.resources.IResource;



public class NewAction implements IObjectActionDelegate {

private String title;

private IResource resource;

private IStructuredSelection sSelection;

private IWorkbenchPart part;

private IWorkbenchWindow window;

/**

* Constructor for Action1.

*/

public NewAction() {

super();

}

/**

* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)

*/

public void setActivePart(IAction action, IWorkbenchPart targetPart) {

part = targetPart;


}

/**

* @see IActionDelegate#run(IAction)

*/

public void run(IAction action) {




sSelection = (IStructuredSelection)
part.getSite().getSelectionProvider().getSelection();

resource = (IResource) sSelection.getFirstElement();

title = resource.getName();

Shell shell = new Shell();

MessageDialog.openInformation(

shell,

"MenuSample Plug-in",

title);

}


"Rich Kulp" <richkulp@NO.SPAM.us.ibm.com> wrote in message
news:ca9qle$bp5$2@eclipse.org...
> If your action was contributed through the plugin.xml, then it must
> implement IActionDelegate. If so, then it is told what was selected via
> the setSelection method.
>
>
> --
> Thanks, Rich Kulp
> 
>
Re: [newbie] Getting the selected resource in a popup menu action [message #251623 is a reply to message #251541] Thu, 10 June 2004 17:54 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.NO.SPAM.us.ibm.com

It's called selectionChanged(Selection). It is called when the selection
has changed.



--
Thanks, Rich Kulp

Previous Topic:Sharing bookmarks/tasks?
Next Topic:[rc1] binary project w/linked content: no source available
Goto Forum:
  


Current Time: Sun Jul 27 01:53:59 EDT 2025

Powered by FUDForum. Page generated in 0.04771 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top