Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Multiple Selection Providers
Multiple Selection Providers [message #304910] Mon, 19 June 2006 07:52 Go to next message
Eclipse UserFriend
Originally posted by: jan.stamer.iao.fraunhofer.de

Hi,

I have a problem with using Selection Providers:

I have an editor (form based) with multiple viewers (table, tree, ...).
Each of them should be able to work as a selection provider to enable
the properties. view.

How can I do that? At the moment I am stuck because I can only set one
selection provider for the part and thats it...

Thanks,
Jan
Re: Multiple Selection Providers [message #305423 is a reply to message #304910] Tue, 04 July 2006 08:37 Go to previous messageGo to next message
Uta Sommerweiss is currently offline Uta SommerweissFriend
Messages: 4
Registered: July 2009
Junior Member
------=_Part_244_27860229.1152002391407
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi, we solved the problem this way:
1. create a SelectionProviderWrapper (see attachment)
2. set this as the selection provider to the part
3. add FocusListener to each of your viewer controls
4. whenever one of the viewer controls got the focus, the focus listener will set the viewers selection listener to the selection provider wrapper:
focusGained:
selectionProviderWrapper.setSelectionProvider(viewer.getSele ctionProvider());

This mechanism ensures, that the part has a fixed selection provider (the wrapper), but it can support multiple viewers.

Regards Uta
------=_Part_244_27860229.1152002391407
Content-Type: application/octet-stream; name=SelectionProviderWrapper.java
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=SelectionProviderWrapper.java

package com.rochade.metability.viewers.editor;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;

/**
* This class is used in EditorPart or ViewPart controls to manage
* multiple selection providers.
* @author <UL><LI> YO, 14.06.05, created</UL>
* @version 1.0.0
* @de.rochade.copyright@
*/
public class SelectionProviderWrapper implements ISelectionProvider{

private ISelectionProvider provider;
private List selectionListeners;
private ISelection sel = StructuredSelection.EMPTY;

public void addSelectionChangedListener(ISelectionChangedListener listener) {
if (selectionListeners == null) selectionListeners = new ArrayList(1);
selectionListeners.add(listener);
if (provider != null) provider.addSelectionChangedListener(listener);
}

public void removeSelectionChangedListener(ISelectionChangedListener listener) {
if (selectionListeners != null){
selectionListeners.remove(listener);
if (provider != null) provider.removeSelectionChangedListener(listener);
}
}

public ISelection getSelection() {
return provider != null ? provider.getSelection() : sel;
}

public void setSelection(ISelection selection) {
if (provider != null){
provider.setSelection(selection);
}else{
sel = selection;
if (selectionListeners != null){
SelectionChangedEvent event = new SelectionChangedEvent(this, selection);
for (Iterator it=selectionListeners.iterator(); it.hasNext();){
((ISelectionChangedListener)it.next()).selectionChanged(even t);
}
}

}
}

public void setSelectionProvider(ISelectionProvider provider){
if (this.provider != provider){
ISelection _sel = null;
if (selectionListeners != null){
int c = selectionListeners.size();
ISelectionChangedListener listener;
if (this.provider != null){
for (int i=0; i<c; i++){
listener = (ISelectionChangedListener) selectionListeners.get(i);
this.provider.removeSelectionChangedListener(listener);
}
}

if (provider != null){
for (int i=0; i<c; i++){
listener = (ISelectionChangedListener) selectionListeners.get(i);
provider.addSelectionChangedListener(listener);
}

_sel = provider.getSelection();
}else{
_sel = sel;
}
}
this.provider = provider;
if (_sel != null){
//force a selection change event propagation
setSelection(_sel);
}
}
}

public ISelectionProvider getSelectionProvider(){
return provider;
}
}

------=_Part_244_27860229.1152002391407--
Re: Multiple Selection Providers [message #690932 is a reply to message #305423] Thu, 30 June 2011 12:41 Go to previous messageGo to next message
Renaud C is currently offline Renaud CFriend
Messages: 19
Registered: May 2011
Junior Member
Hello!
Could you explain the code you have to use in your PartControl ?

Do we have to create a new SelectionProviderWrapper, and then add our SelectionProvider to it?

Thanks!
Re: Multiple Selection Providers [message #690939 is a reply to message #690932] Thu, 30 June 2011 12:54 Go to previous message
Renaud C is currently offline Renaud CFriend
Messages: 19
Registered: May 2011
Junior Member
I have the same problem, here is my situation :

I have 2 treeviewers containing elements with some properties. I want to display these properties when this element is selected, in the treeviewer or in the treeviewerTwo. For now,

		getSite().setSelectionProvider(treeviewer);
		getSite().getWorkbenchWindow().getSelectionService()
				.addSelectionListener(listener);


allows me to display properties of treeviewer elements. But I would like the same for the two treeviewers. So, it will be great if I could have more information about this topic =)

	public void createPartControl(Composite parent) {
		treeviewer = new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL);
		treeviewer.setContentProvider(new TreeContentProvider());
		treeviewer.setLabelProvider(new TreeLabelProvider());
		new Sash(parent, SWT.VERTICAL);
		treeviewerTwo = new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL);
		treeviewerTwo.setContentProvider(new TreeContentProviderTwo());
		treeviewerTwo.setLabelProvider(new TreeLabelProvider());

		createActions();
		createToolbar();
		getSite().setSelectionProvider(treeviewer);
		getSite().getWorkbenchWindow().getSelectionService()
				.addSelectionListener(listener);
	}


Do I have to create a new wrapper?
SelectionProviderWrapper spw = new SelectionProviderWrapper();


Thanks everybody!
Previous Topic:TableViewer refresh
Next Topic:After CVS import no C++ settings in properties
Goto Forum:
  


Current Time: Thu Nov 27 12:21:05 GMT 2014

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

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