Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » changing selection provider in view part with two stacked viewers
changing selection provider in view part with two stacked viewers [message #100724] Sun, 27 July 2003 00:44 Go to next message
Eclipse UserFriend
Originally posted by: kjwenger.netzero.org

hi folks,

i have some trouble hot-swapping the selection provider of a view site when
working with two viewers in a view part alternatively.
when changing the selection providers using
"getSite().setSelectionProvider(otherViewer);", none of the selections made
are propagated to the listeners.

the viewers are created in the control part creation method like shown
below:

public void createPartControl(Composite parent) {
parent.setLayout(stackLayout = new StackLayout());

viewer = treeViewer = new TreeViewer(
parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
treeViewer.setContentProvider(new ViewContentProvider());
treeViewer.setLabelProvider(new ViewLabelProvider());
treeViewer.setSorter(new NameSorter());
treeViewer.setInput(ResourcesPlugin.getWorkspace());

tableViewer = new TableViewer(
parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
tableViewer.setContentProvider(new ViewContentProvider());
tableViewer.setLabelProvider(new ViewLabelProvider());
tableViewer.setSorter(new NameSorter());
tableViewer.setInput(ResourcesPlugin.getWorkspace());

getSite().setSelectionProvider(viewer);

stackLayout.topControl = treeViewer.getControl();
parent.layout();
}

switching between the viewers is done in an action that's created like
following:

private void makeActions() {
action2 = new Action() {
public void run() {
Viewer oldViewer = viewer;
if (stackLayout.topControl == treeViewer.getControl()) {
stackLayout.topControl =
(viewer = tableViewer).getControl();
} else {
stackLayout.topControl =
(viewer = treeViewer).getControl();
}
parent.layout();
getSite().setSelectionProvider(viewer);
viewer.setSelection(oldViewer.getSelection());
ISelectionService selectionService =

getViewSite().getPage().getWorkbenchWindow().getSelectionSer vice();
if (selectionService instanceof AbstractSelectionService) {
AbstractSelectionService abstractSelectionService =
(AbstractSelectionService) selectionService;

abstractSelectionService.partDeactivated(SampleView.this);
abstractSelectionService.partActivated(SampleView.this);
}
}
};
}

the code to directly approach the selection service was added as a last
resort.

the funny thing is that when you deactivate and active the view after
switching the viewer by clicking in the workbench, the selection mechanism
works again.

many thanks!

klaus
Re: changing selection provider in view part with two stacked viewers [message #102372 is a reply to message #100724] Tue, 29 July 2003 11:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.NOSPAM.us.ibm.com

Probably this is because the selection provider choice is only looked at
whenever the viewer becomes active. Setting it after that means it won't
be seen. The selection provider in the site should not be changed after
the init step of the view. Instead you should write your own selection
provider that forwards the selection from the appropriate viewer. And
this forwarding provider is the one placed into the site.

Rich
Re: changing selection provider in view part with two stacked viewers [message #102863 is a reply to message #102372] Wed, 30 July 2003 02:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: markus_keller.ch.ibm.spam.protect.com

You might want to look at
org.eclipse.jdt.internal.ui.typehierarchy.SelectionProviderM ediator

Markus


Richard L. Kulp wrote:

> Probably this is because the selection provider choice is only looked at
> whenever the viewer becomes active. Setting it after that means it won't
> be seen. The selection provider in the site should not be changed after
> the init step of the view. Instead you should write your own selection
> provider that forwards the selection from the appropriate viewer. And
> this forwarding provider is the one placed into the site.
>
> Rich
>
Re: changing selection provider in view part with two stacked viewers [message #103002 is a reply to message #102863] Wed, 30 July 2003 07:55 Go to previous message
Eclipse UserFriend
Originally posted by: kjwenger.netzero.org

ecellent tip!!!

works like a charm with minimal additions/modifications.

many thanks!!!

klaus

"Markus Keller" <markus_keller@ch.ibm.spam.protect.com> wrote in message
news:bg7pj0$5bp$1@eclipse.org...
> You might want to look at
> org.eclipse.jdt.internal.ui.typehierarchy.SelectionProviderM ediator
>
> Markus
>
>
> Richard L. Kulp wrote:
>
> > Probably this is because the selection provider choice is only looked at
> > whenever the viewer becomes active. Setting it after that means it won't
> > be seen. The selection provider in the site should not be changed after
> > the init step of the view. Instead you should write your own selection
> > provider that forwards the selection from the appropriate viewer. And
> > this forwarding provider is the one placed into the site.
> >
> > Rich
> >
>
Previous Topic:embedded wizards
Next Topic:How can I specify the order of the classpath in Eclipse?
Goto Forum:
  


Current Time: Sat May 03 14:10:58 EDT 2025

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

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

Back to the top