I have a tree viewer next to a specialized viewer. When something is selected in the tree viewer, details about this object are shown in the specialized viewer. TreeViewer tree
, Composite control
, and MySpecializedViewer viewer
are instance variables.
public TheEverythingViewer(Composite parent) {
control = new Composite(parent, SWT.NONE);
control.setLayout(new GridLayout(2, false));
tree = new TreeViewer(control);
tree.setContentProvider(new MyContentProvider());
tree.setLabelProvider(new MyLabelProvider());
tree.setUseHashlookup(true);
tree.getControl().setLayoutData(new GridData(GridData.BEGINNING, GridData.FILL, false, true, 1, 1));
tree.addSelectionChangedListener(new ISelectionChangedListener() {
@Override public void selectionChanged(SelectionChangedEvent event) {
try {
IStructuredSelection sel = (IStructuredSelection) event.getSelection();
MyClass myInput = (MyClass) sel.getFirstElement();
if (viewer != null)
if (!viewer.getControl().isDisposed())
viewer.getControl().dispose();
viewer = new MySpecializedViewer(control, table);
control.getShell().layout();
} catch (Exception e) {
if (viewer != null)
if (!viewer.getControl().isDisposed())
viewer.getControl().dispose();
viewer = null;
}
}
});
}
Am I doing something wrong? I just want:
+--------------+--------------------------------------------+
| + Node | |
| - Node | |
| + Node | My |
| - Node | |
| - Node | Specialized |
| | Viewer |
| | |
| | |
| | |
| | |
| | |
| | |
| | +--------+ |
| | | | |
| | | | |
| | | | |
| | +--------+ |
| | |
| | |
| | |
| | |
+--------------+--------------------------------------------+
The specialized viewer has tables that need to consume more or less space depending on the selected node. And currently, creating a new instance of the specialized viewer is much, much simpler than changing it's input (that wouldn't work ATM).