How to Refresh Eclipse View Plugin

被刻印的时光 ゝ 提交于 2019-12-01 00:36:16

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 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.

I have a similar problem with a tableViewer. For one case, the simple viewer.refresh() worked, but for another I had to get a solution not so "beautiful"..

The solution that I have for now is not set the input to null with viewer.setInput(null), and then set the input again the updated data. This temporarily results for me, since I don't have a large amount of data. Otherwise, the overhead of the creation on every change may not be feasible.

If I find a cleaner solution I will post it.

Thanks to Bananeweizen's answer, I've been able to hack up some code that does similar to what I need it to do, even though there is probably a better way. I've added ISelectionListener that listens to when a selection event happens (this goes in the ViewPart class as a global variable):

ISelectionListener selectionListener = new ISelectionListener() {
    public void selectionChanged(IWorkbenchPart part, ISelection sel) {
       if (!(sel instanceof IStructuredSelection))
           return;
       IStructuredSelection ss = (IStructuredSelection) sel;

       if(sel.toString().contains("org.eclipse.jdt.internal.debug.core.model")){
           viewer.setInput(getSite());
       }
    }
 };

So if I click on any of the debug buttons, it will refresh my view. setInput basically calls getElements() in the ContentProvider which provides specific implementation of how to form the table inside my view.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!