如何刷新Eclipse View插件

如何刷新Eclipse View插件

问题描述:

我创建了一个基于eclipse插件视图教程的简单视图。我添加了允许我的插件监听调试器上的更改的功能。我的问题是,每次调试器上的某些事情发生时,我希望我的视图被刷新并使用新的信息进行更新。这是我有什么/我正在尝试的:

I created a simple view based off of the eclipse plugin view tutorial. I added functionality that allows my plugin to listen to changes on the debugger. My problem is, every time something on the debugger happens, I want my view to be refreshed and be updated with new information. Here is what I have/what I'm trying:

    public void createPartControl(Composite parent) {

        listener = new DebugContextListener(this);
        DebugUITools.getDebugContextManager().addDebugContextListener(listener);

        // Check if there is an already started debug context
        IAdaptable dc = DebugUITools.getDebugContext();
        if (dc != null) {
                dataCollection.add(new ProxyScope("hi")); // manually injecting data 
                Object o = dc.getAdapter(IStackFrame.class);
                if (o instanceof IStackFrame)
                        setStackFrame((IStackFrame) o);

                viewer.refresh(); // this doesn't work
        }       


        viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);

        // Set column lines visible, and create two columns
        Tree tree = viewer.getTree();
        tree.setHeaderVisible(true);
        tree.setLinesVisible(true);

        TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
        column1.setText("Name");
        column1.setWidth(400);
        TreeColumn column2 = new TreeColumn(tree, SWT.LEFT);
        column2.setText("Value");
        column2.setWidth(200);

        drillDownAdapter = new DrillDownAdapter(viewer);
        viewer.setContentProvider(new VariableViewContentProvider());
        viewer.setLabelProvider(new VariableViewLabelProvider());
        viewer.setSorter(new ViewerSorter());
        viewer.setInput(getViewSite());

....

}

所以基本上,我有所有这个调试听力逻辑在顶部,这发生在那个if语句里面。我知道一个事实,我的程序进入那里。每次改变我想刷新我的观点,而且我已经尝试过viewer.refresh,哪些不起作用。我的视图显示的信息是基于dataCollection对象,所以与dataCollection.add ...的行是我只是手动添加数据,就像调试器做的一样。如果我将该行放在if语句之外,那么我的视图有效(我猜这只是我第一次启动插件时视图的原始构造),但是当我将它放在if语句中时,它不起作用这意味着我的观点不会刷新。

So basically, I have all this debug listening logic at the top, which happens inside that if statement. I know for a fact that my program gets in there. Everytime somethign changes I want to refresh my view, and I've tried doing viewer.refresh, which doesnt work. The information my view displays is based off of the dataCollection object, so that line with the dataCollection.add... is me just adding data manually as if the debugger did something. If I put that line outside the if statement, then my view works (I'm guessing this is just the original construction of the view when I first start the plugin), but when I put it inside the if statement it doesn't work, meaning my view never refreshes.

感谢您的帮助。

createPartControls 是视图生命周期的时间,其中创建了包含的小部件(最初视图变得可见)。此代码只能在视图生命周期中执行一次,因此您无法直接在此处添加任何内容来刷新视图。

createPartControls is that time of the life cycle of a view, where its contained widgets are created (when the view becomes visible initially). This code is only executed once during the view life cycle, therefore you cannot add anything here directly to refresh your view.

Eclipse部件通常会更新其内容,作为对改变工作台内的选择(例如,用户可能在调试视图中单击另一个堆栈帧)。我不知道这是否已经完全满足您的需求,但这是一个很好的开始,并且在 Eclipse常见问题

Eclipse parts typically update their content as a reaction to a changed selection inside of the workbench (e.g. the user might click on another stack frame in the debug view). I'm not sure if that already completely fulfills your needs, but it's a good start for sure and described well in the Eclipse FAQ.