Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Using SelectionService in Commands
Using SelectionService in Commands [message #673479] Mon, 23 May 2011 18:45 Go to next message
Sebastian  is currently offline Sebastian Friend
Messages: 22
Registered: September 2010
Junior Member
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 19:45 Go to previous messageGo to next message
Catalin Gerea is currently offline Catalin GereaFriend
Messages: 89
Registered: July 2009
Location: Bucharest, Romania
Member

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();


Time is what you make of it.
Re: Using SelectionService in Commands [message #673695 is a reply to message #673479] Tue, 24 May 2011 13:46 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

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: Fri Mar 29 02:19:25 GMT 2024

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

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

Back to the top