How do I get the view by viewId in RCP? And then how to redraw the view? I want to implement the function that when I click a item form a list, then the related view will redraw and call the function 'createPartControl'.I konw the view's id.So how can I get to it?

This is the view's createPartControl() method.

public void createPartControl(Composite parent) {
    // TODO Auto-generated method stub
    final List list = new List(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    final ObjDumpParser objdump = new  ObjDumpParser();
    List<DisFunction> funclist = objdump.getTextFunList();
    int funcNum = funclist.size();
    System.out.println("123: " + funcNum);
    for (int i = 0; i < funcNum; i++){
        ......
有帮助吗?

解决方案

The IWorkbenchPage has the methods to control views:

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

IViewPart viewPart = page.showView("view id");

The part createPartControl will be called when the view is created, on subsequent calls to showView it is not called.

The viewPart will be an instance of your view class so you can add a method to that to update the view, something like:

MyView myView = (MyView)viewPart;

... call MyView method to update the view

Update showing on MyView:

public class MyView extends ViewPart
{
  private List list;

  public void createPartControl(Composite parent)
  {
     list = new List.....
  }


  public void update()
  {
    ... update list
  }
}

其他提示

This is the answer to the first question.

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            IViewPart view = page.findView("BIT_DEC.graphView");

The second question bothers me now.

Active workbench window might be null (happened for me while debugging).

            IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

            if (workbenchWindow == null) {
                IWorkbenchWindow[] allWindows = PlatformUI.getWorkbench().getWorkbenchWindows();
                for (IWorkbenchWindow window : allWindows) {
                    workbenchWindow = window;
                    if (workbenchWindow != null) {
                        break;
                    }
                }
            }

            if (workbenchWindow == null) {
                throw new IllegalStateException("Could not retrieve workbench window");
            }

            IWorkbenchPage activePage = workbenchWindow.getActivePage();

            try {
                IViewPart viewPart = activePage.showView(id);
                return viewPart;
            } catch (PartInitException e) {
                String message = "Could not show view " + id;
                LOG.warn(message, e);
                return null;
            }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top