Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Problem with the Selection Service
Problem with the Selection Service [message #464456] Wed, 07 March 2007 14:59 Go to next message
Eclipse UserFriend
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 #464480 is a reply to message #464456] Thu, 08 March 2007 13:02 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
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
Re: Problem with the Selection Service [message #464484 is a reply to message #464480] Thu, 08 March 2007 16:20 Go to previous message
Eclipse UserFriend
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
Previous Topic:showing a list of registered views
Next Topic:How to disable closing of Welcome screen
Goto Forum:
  


Current Time: Wed Sep 11 23:58:25 GMT 2024

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

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

Back to the top