我在专门的查看器旁边有一个树查看器。在树查看器中选择某些内容时,有关此对象的详细信息将显示在专用查看器中。TreeViewer tree
, Composite control
, 和MySpecializedViewer viewer
是实例变量。
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;
}
}
});
}
难道我做错了什么?我只是想:
+--------------+--------------------------------------------+
| + Node | |
| - Node | |
| + Node | My |
| - Node | |
| - Node | Specialized |
| | Viewer |
| | |
| | |
| | |
| | |
| | |
| | |
| | +--------+ |
| | | | |
| | | | |
| | | | |
| | +--------+ |
| | |
| | |
| | |
| | |
+--------------+--------------------------------------------+
专用查看器具有需要根据所选节点消耗更多或更少空间的表。目前,创建专用查看器的新实例比更改其输入要简单得多(这在 ATM 上不起作用)。