Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Using SelectionService in Commands
Using SelectionService in Commands [message #673479] Mon, 23 May 2011 14:45 Go to next message
Eclipse UserFriend
Hey,

I'm almost positive that what the title says is not the way the selection service is intended to be used, but here is the problem that i have.

I had a view that had a list of elements, and that list was a SelectionProvider.

Two other views were registered as a SelectionListener so when an element in the list got selected, the views got notified.

Now I want to get rid of the view and put everything into a ListDialog thingy. I used the menus extension to add a command to the main toolbar, and that command now opens the dialog that let's you select the element you wish.

But I can't use the selectionProvider mechanism from commands right ? how else would i tackle this problem?


Thanks

Sebastian
Re: Using SelectionService in Commands [message #673490 is a reply to message #673479] Mon, 23 May 2011 15:45 Go to previous messageGo to next message
Eclipse UserFriend
1. You can get the selection like this
ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
in the execute(ExecutionEvent event) of the command's handler.
See http://wiki.eclipse.org/index.php/Platform_Command_Framework for more details about the Command Framework.

2. I did not used ListDialog before but I see that it has a method getTableViewer() that " Returns: the TableViewer for the receiver.". And the table viewer can be used as valid SelectionProvider as far as I know.

3. http://www.eclipse.org/articles/Article-WorkbenchSelections/article.html is a good article about the selections.

4. You could try to get get the reference for the selection service like this:
ISelectionService selectionService = (ISelectionService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
Re: Using SelectionService in Commands [message #673695 is a reply to message #673479] Tue, 24 May 2011 09:46 Go to previous message
Eclipse UserFriend
Right, you can't use the ISelectionService, as the participants 1) are parts and 2) only supply their values when they are active (and your dialog will go away).

I would have your dialog find your 2 view parts. When you instantiate your dialog, you can pass in an IWorkbenchWindow. Then when you need to notify your parts (or when you open your dialog) you can get the views:

IViewReference ref = window.getActivePage().findViewReference(VIEW_ID1);
IWorkbenchPart part = ref.getPart(false); // can return null
if (part instanceof MyView1) {
    ((MyView1)part).setSelection(myObj);
}


PW
Previous Topic:Always show intro page
Next Topic:Drop down menu below main menu programmatically
Goto Forum:
  


Current Time: Tue Jul 08 05:44:57 EDT 2025

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

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

Back to the top