Using a Viewer with multiple views (Providers) [message #306691] |
Thu, 03 August 2006 11:01  |
Eclipse User |
|
|
|
Originally posted by: dennis.rietmann.solnet.ch
Hi,
I want to use a (eg. Tree-)Viewer in a way that one can switch from one
view to another and back (to display different data but still using
only 1 Viewer). A view consists of the data set with setInput(), a
specific ContentProvider and LabelProvider.
When I trigger the switch (via button) sth. like the following code will
get executed:
if (...) {
/* switch from view 1 to view 2 */
treeViewer.setContentProvider(cp2);
treeViewer.setInput(data2);
treeViewer.setLabelProvider(lp2);
}
else {
/* switch from view 2 to view 1 */
treeViewer.setContentProvider(cp1);
treeViewer.setInput(data1);
treeViewer.setLabelProvider(lp1);
}
....
After _each_ setX() method the treeViewer triggers a refresh and calls
the Providers and some Listeners (like SelectionChangedListener).
Therefore I had to add a lot of ugly checks to determine if everything
is in place, but also performance-wise I think this is far from optimal.
So, my question is: Is there a better way to do this or how would you
improve this? I would appreciate any advice.
Thanks,
Dennis
|
|
|
|
|
Re: Using a Viewer with multiple views (Providers) [message #306745 is a reply to message #306735] |
Fri, 04 August 2006 01:21  |
Eclipse User |
|
|
|
Yes. Maybe I'd do the refresh before making the dialog visible, hide the
first one.
Tom
Dennis schrieb:
> Hi Tom,
>
> thanks for the hint, I'll probably use this and trigger a refresh after
> switching.
> Did you have something like the following in mind, or is there an easier
> solution?
>
> private void switchView() {
> if (view == ...) {
> treeViewer1.setVisible(false);
> ((GridData)treeViewer1.getLayoutData()).exclude = true;
> treeViewer2.setVisible(true);
> ((GridData)treeViewer2.getLayoutData()).exclude = false;
> treeViewer2.refresh();
> view = ...
> } else {
> /* same stuff the other way around */
> }
>
> container.layout();
>
> }
>
> Dennis
>
> Tom Schindl wrote:
>> Why not hiding and showing viewers instead of replacing content? I don't
>> think that there's a better way than you do it now.
>>
>> Tom
|
|
|
Powered by
FUDForum. Page generated in 0.03077 seconds