Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » ISelectionProvider question
ISelectionProvider question [message #436728] Thu, 15 September 2005 15:42
Nick is currently offline NickFriend
Messages: 34
Registered: July 2009
Member
hi,

i'm currently working on an rcp applikation which needs a
file explorer (more or less like the windows explorer).
it works, but i'm not sure i did it the right way.

the left view contains a treeviewer. it acts as a selectionprovider.
-> getSite().setSelectionProvider(treeViewer);
when a node (directory) is selected the tableviewer shows the content.

the right view contains the tableviewer.it also acts as a selectionprovider
-> getSite().setSelectionProvider(tableViewer);
doubleclick on a folder opens the folder and the corresponding
node (directory) is selected in the treeViewer.


but then i had a problem, since the selectinProvider doesn't
differentiate between doubleclick and a single click. so, each
time i selected a directory in the tableViewer (with a single
click) the treeViewer was updated (the corresponding node was
selected), which then, due to the new selection in the tree
in return updated the tableViewer. unfortunately, this should
only happen when i doubleclick on a directory in the tableViewer.

i solved the problem by implementing the ISelectionProvider in
my ViewPart. so instead of writting
-> getSite().setSelectionProvider(tableViewer);
i wrote
-> getSite().setSelectionProvider(this); // (this = TableViewPart)


this is how i implemented the methods of ISelectionProvider:


private ListenerList selectionChangedListeners = new ListenerList(3);


public void addSelectionChangedListener(
ISelectionChangedListener listener) {
selectionChangedListeners.add(listener);
}



public ISelection getSelection() {
return viewer.getSelection();
}



public void removeSelectionChangedListener(
ISelectionChangedListener listener) {
selectionChangedListeners.remove(listener);
}



public void setSelection(ISelection selection) {
SelectionChangedEvent event =
new SelectionChangedEvent(this, selection);
fireSelectionChanged(event);
}


protected void fireSelectionChanged(final SelectionChangedEvent event) {
Object[] listeners = selectionChangedListeners.getListeners();
for (int i = 0; i < listeners.length; ++i) {
final ISelectionChangedListener l =
(ISelectionChangedListener) listeners[i];
SafeRunnable.run(new SafeRunnable() {
public void run() {
l.selectionChanged(event);
}
});
}




in the doubleclick listener of the tableviewer i inform all
selectionChangedListeners that a selection has accured by calling:
setSelection(event.getSelection());



i know,it's a long description & i do hope somebody bothered to read it!
i would be great if somebody could tell me if this is the best way
to do it or if there are any better ways!


cheers,
nick
Previous Topic:ContextFinder and 'jar plugins'
Next Topic:How to write to problem view and console view
Goto Forum:
  


Current Time: Mon Dec 02 23:09:35 GMT 2024

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

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

Back to the top