Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Good practices with selection listeners(Where to add selection listeners ?)
icon5.gif  Good practices with selection listeners [message #520829] Mon, 15 March 2010 14:05 Go to next message
Olivier Thierry is currently offline Olivier ThierryFriend
Messages: 11
Registered: January 2010
Location: Nantes, France
Junior Member
Hi,

I have a view part containing a tree. When the user selects a node in the tree, I want to display details for this node in three other views, depending on the node type (imagine a tree view with continent, country and cities). These three views are in a folder layout, and I use showView method on the page to send the right view to the front.

I could make it work by setting the view with the tree as a selection provider, then setting each of my three details views as a selection listener for the tree. I did this in the createPartControl method of the details views. It looks like this :

public void createPartControl(Composite parent) {
	PlanTransportView planTransportView = (PlanTransportView) getViewSite().getPage().findView(PlanTransportView.ID);
	if (planTransportView != null) {
		planTransportView.addSelectionListener(this);
	}
}


But I can see two problems here :

- The createPartControl method is executed only when the view is sent to front. But when it is added to a folder, the listeners for the hidden details views are not added until they are sent to front. So selection of corresponding elements in the tree has no effect until the details view is sent to front by the user, which I don't want to do Sad

- Imagine the selection provider (PlanTransportView here) doesn't exist when the listener is created (it has been closed in previous session for example). Since createPartControl method is called once, I see no way how the listener could be added Sad

So I ask myself about the good practices about where to add listeners :
- Is createPartControl method really the right place to do this ?
- Should the listeners be added outside the concerned views, in a application class ?
- Maybe there's a way to force createPartControl method to be called on app startup ?

I have plenty of such problems, when users close views, and open them again, so any help will be very welcome !

Thanks in advance,

Olivier
Re: Good practices with selection listeners [message #520850 is a reply to message #520829] Mon, 15 March 2010 15:23 Go to previous messageGo to next message
T. Wilhelm is currently offline T. WilhelmFriend
Messages: 129
Registered: July 2009
Senior Member
I think here you find what you want: You should register at the Selection Service, not on your view.

http://www.eclipse.org/articles/Article-WorkbenchSelections/ article.html

Hope that helps you.
Greetz
Thomas
Re: Good practices with selection listeners [message #521022 is a reply to message #520829] Tue, 16 March 2010 09:17 Go to previous messageGo to next message
Olivier Thierry is currently offline Olivier ThierryFriend
Messages: 11
Registered: January 2010
Location: Nantes, France
Junior Member
Tanks, it answers part of my problem (no more direct dependencies between the views). But I still have a problem with the place where a view should register as a selection listener : in all the examples I saw this is made in createPartControl method. But for what I saw this method is called only when the view is visible. Which means that when the view is part of a folder, the listener is not registered until the user sends the view to front. So is there a way to force createPartControl method to be called before user clicks on the view title bar to send it to front ?
Re: Good practices with selection listeners [message #521025 is a reply to message #520829] Tue, 16 March 2010 09:30 Go to previous messageGo to next message
Olivier Thierry is currently offline Olivier ThierryFriend
Messages: 11
Registered: January 2010
Location: Nantes, France
Junior Member
I answer to myself ... I could force createPartControl method to be called by trying to access the views in the postWindowOpen method of my WorkbenchWindowAdvisor class.

public void postWindowOpen() {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(DetailsTourView.ID);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(DetailsSequenceView.ID);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(DetailsPositionView.ID);
}


I am not sure it is a state of the art way to do this, but it works !
Re: Good practices with selection listeners [message #521045 is a reply to message #521025] Tue, 16 March 2010 10:25 Go to previous messageGo to next message
T. Wilhelm is currently offline T. WilhelmFriend
Messages: 129
Registered: July 2009
Senior Member
I dont know why you want to register the view before it is acutally shown. This turns off the lazy loading principle.

I think your problem is, that when you open the view, it shows nothing, because the selectionListener has just registered, and so it is not informed about the actual selection?!?

A proper solution would be to override the partOpened() method and get the actual selection there.

Or do you have another problem?

Greetz
Thomas
Re: Good practices with selection listeners [message #521049 is a reply to message #521045] Tue, 16 March 2010 10:37 Go to previous messageGo to next message
Olivier Thierry is currently offline Olivier ThierryFriend
Messages: 11
Registered: January 2010
Location: Nantes, France
Junior Member
T. Wilhelm wrote on Tue, 16 March 2010 06:25
I dont know why you want to register the view before it is acutally shown. This turns off the lazy loading principle.


Well, imagine you have a treeview with three kind of nodes : continent, country and city. Then you have three details views for each kind of node : continentDetails, countryDetails and cityDetails. All of these details views are in a folder, so only one is visible, the others are hidden. If you select a continent, I want to fill continentDetails view and show it. If you select a country, I want to fill countryDetails view and show it. And if you select a city I want to fill cityDetails view and show it.

This is done in selectionChanged method of the views with the following piece of code :

getSite().getPage().showView(ID, null, IWorkbenchPage.VIEW_VISIBLE);


But for this piece of code to run, I of course need listener to be started. These listeners are configured in createPartControl method, but this method is not called when the view is added to the workbench window but when it is shown. So if the user doesn't click on the view, it is not shown and the listener is not started. So I need to force call for createPartControl. Hope you understand what I mean Wink

[Updated on: Tue, 16 March 2010 10:40]

Report message to a moderator

Re: Good practices with selection listeners [message #521059 is a reply to message #521049] Tue, 16 March 2010 11:12 Go to previous messageGo to next message
T. Wilhelm is currently offline T. WilhelmFriend
Messages: 129
Registered: July 2009
Senior Member
Here is a code example for my advice before: Just override the partOpenend() Method, so the fist time you click on the part, it will get the actual selection and then you can show the details.

Afterwards your listener is registered and informs about changes.


@Override
public void partOpened( IWorkbenchPart part) {
ISelection selection = getSite().getWorkbenchWindow()
.getSelectionService()
.getSelection();

Country country = (Country) selection;
}

I think that is the better way then forcing the listener to be activated. If you still want to go that way, use an activator to register the listener.

Greetz
Thomas
Re: Good practices with selection listeners [message #635754 is a reply to message #521059] Thu, 28 October 2010 01:22 Go to previous messageGo to next message
ash is currently offline ashFriend
Messages: 142
Registered: July 2010
Senior Member
HI
even i am also facing the same issue . Can i know how did u resolve this issue.

Thanks
Ashok
Re: Good practices with selection listeners [message #635756 is a reply to message #520829] Thu, 28 October 2010 01:27 Go to previous message
ash is currently offline ashFriend
Messages: 142
Registered: July 2010
Senior Member
HI


Do u have any idea how to resolve this issue

http://www.eclipse.org/forums/index.php?t=msg&th=198943& amp;start=0&S=e7a5edde499711f85313219f77e2ec34

Thanks
Ashok
Previous Topic:Transfering data between views and action
Next Topic:problem exporting a product
Goto Forum:
  


Current Time: Tue Dec 03 03:47:17 GMT 2024

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

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

Back to the top