Problem with the Selection Service [message #464456] |
Wed, 07 March 2007 14:59 |
Eclipse User |
|
|
|
Originally posted by: fe.cetic.be
Hi,
In a RCP application, I want to trigger an action in a (target) view
when a selection is made in the TableViewer another (source) view.
Here is (the skeleton of) my source view :
public class ResultsView extends ViewPart {
private TableViewer resultsViewer;
public void createPartControl(Composite parent) {
resultsViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL |
SWT.V_SCROLL);
resultsViewer.setContentProvider(new ViewContentProvider());
resultsViewer.setLabelProvider(new ViewLabelProvider());
getSite().setSelectionProvider(resultsViewer);
}
}
Here is (the skeleton of) my target view :
public class DocumentView extends ViewPart implements ISelectionListener {
public void createPartControl(Composite parent) {
getSite().getWorkbenchWindow().getSelectionService().addSele ctionListener(this);
}
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
System.out.println("OK");
}
}
....but "OK" does not display
What's wrong ? Do I have to use a ISelectionChangedListener ? (what's
the difference with a ISelectionListener ?)
Thanks for this useful newsgroup,
Fabrice
|
|
|
|
Re: Problem with the Selection Service [message #464484 is a reply to message #464480] |
Thu, 08 March 2007 16:20 |
Eclipse User |
|
|
|
Originally posted by: fe.cetic.be
Daniel Krügler a écrit :
> Fabrice Estiévenart wrote:
>> public class ResultsView extends ViewPart {
>> private TableViewer resultsViewer;
>> public void createPartControl(Composite parent) {
>> resultsViewer = new TableViewer(parent, SWT.MULTI |
>> SWT.H_SCROLL | SWT.V_SCROLL);
>> resultsViewer.setContentProvider(new ViewContentProvider());
>> resultsViewer.setLabelProvider(new ViewLabelProvider());
>> getSite().setSelectionProvider(resultsViewer);
>> }
>> }
>>
>>
>> Here is (the skeleton of) my target view :
>>
>> public class DocumentView extends ViewPart implements
>> ISelectionListener {
>>
>> public void createPartControl(Composite parent) {
>> getSite().getWorkbenchWindow().getSelectionService().addSele ctionListener(this);
>>
>> }
>> public void selectionChanged(IWorkbenchPart part, ISelection
>> selection) {
>> System.out.println("OK");
>> }
>>
>> }
>>
>> ...but "OK" does not display
>>
>> What's wrong ? Do I have to use a ISelectionChangedListener ? (what's
>> the difference with a ISelectionListener ?)
>
> I guess you forgot to call the super method in the derived
> createPartControl method.
>
> Btw: You should also call
>
> getSite().getWorkbenchWindow().getSelectionService().removeS electionListener(this);
>
>
> in your dispose() function.
>
> Greetings from Bremen,
>
> Daniel Krügler
Hello and thanks for your suggestion, but still coping with my problem.
I have tried to embbed the action to trigger in an "Action" rather than
in a "View" :
public class ShowDocumentAction extends Action implements
ISelectionListener, IWorkbenchAction {
private final static String ID = "actions.showdocument";
private final IWorkbenchWindow window;
public ShowDocumentAction(IWorkbenchWindow window)
{
this.window = window;
setId(ID);
window.getSelectionService().addSelectionListener(this);
}
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
System.out.println("OK-changed");
}
}
public void run()
{
System.out.println("OK-run");
}
public void dispose() {
window.getSelectionService().removeSelectionListener(this);
}
}
....but without success :-(
Fabrice
|
|
|
Powered by
FUDForum. Page generated in 0.03462 seconds