我正在开发Eclipse插件,它具有带工具栏和按钮的树视图。我想让插件工作,以便它将树视图显示为默认值,但如果出现一些错误,将会有一些文本和按钮来初始化或更新插件。插件视图应根据树视图和“错误视图”之间的插件状态动态更改。
现在我正在创建treeview实例并在createPartControl方法中执行其他所需的操作以向右显示树视图。我应该如何在插件视图中实现显示不同类型内容的动态视图?这有可能吗?
createPartControlMethod的代码:
public void createPartControl(Composite parent) {
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
drillDownAdapter = new DrillDownAdapter(viewer);
viewContentProvider = new ViewContentProvider();
viewer.setContentProvider(viewContentProvider);
viewer.setLabelProvider(new ViewLabelProvider());
viewer.setSorter(new NameSorter());
viewer.setInput(getViewSite());
viewer.expandToLevel(2);
// Create the help context id for the viewer's control
PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "my.plugin.viewer");
makeActions();
hookContextMenu();
hookDoubleClickAction();
contributeToActionBars();
setToolBarButtonsEnabled();
答案 0 :(得分:0)
最简单的方法是创建一个Composite
,其中包含StackLayout
和两个孩子:
private Composite container;
private TreeViewer viewer;
private Composite errorComposite;
private StackLayout layout;
public void createPartControl(Composite parent) {
container = new Composite(parent);
layout = new StackLayout();
viewer = new TreeViewer(container, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
... // setup viewer
errorComposite = new Composite(container, SWT.NONE);
... // setup error view
}