0

I have created a plugin view (source ) and am trying to update it from other plugin (target).

I have done following and still getting a NPE , please help:

  1. Exported all the packages including the view class in (source) plugin

  2. Included the package visibility to the (target) plugin

  3. Added the (source) plugin as Required Plugin in dependencies tab

(Source Plugin)

<plugin>
   <extension
         point="org.eclipse.ui.views">
      <view
            class="com.he.reportLayer.views.BrowserView"
            id="com.he.reportLayer.views.BrowserView"
            name="Live Reporter!">
      </view>
   </extension>
</plugin>  

(Target Plugin)

 BrowserView view=null;
            try {
                view =(BrowserView)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("com.he.reportLayer.views.BrowserView");
            } catch (PartInitException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
Amrit
  • 433
  • 3
  • 19
  • getWorkbench, getActiveWorkbenchWindow, getActivePage and showView can all return null - so which one is it? Do some debugging! – greg-449 Jan 07 '15 at 19:26
  • getActiveWorkbenchWindow is returning null – Amrit Jan 08 '15 at 03:52
  • So you are running this code when there is no window open. How is this code being run? – greg-449 Jan 08 '15 at 07:32
  • Code is being invoked from other plugin and workbench windows are open as show in screenshot. Run As > Run Script > ILaunchShortcut call some class A in other plugin which invokes the view to update it. – Amrit Jan 08 '15 at 08:14
  • As per the link http://stackoverflow.com/questions/1265174/nullpointerexception-in-platformui-getworkbench-getactiveworkbenchwindow-get I wrapped the view updates in a Runnable thread but view is getting updated in last not in sync with execution. – Amrit Jan 08 '15 at 08:20
  • Any help here !! please advice the best way to update your views be it same plugin or from some other plugin. – Amrit Jan 08 '15 at 12:35
  • What is 'Run Script > ILaunchShortcut'? This is not part of core Eclipse – greg-449 Jan 08 '15 at 13:03
  • These are coming from org.eclipse.debug.ui.launchShortcuts extension point for the plugin and clicking on Run Script calls class implementing ILaunchShortcut – Amrit Jan 08 '15 at 13:17
  • If you want to test plugins you need to use 'Run As > Eclipse Application' – greg-449 Jan 08 '15 at 13:38
  • I am getting NPE as I am trying to update the view from a Non UI thread – Amrit Jan 09 '15 at 09:35

1 Answers1

0

Couple of changes solved the problem :

  1. When you are updating your view from a Non UI thread use :

Display.getDefault().asyncExec(new Runnable() { public void run() {

            IWorkbenchWindow iw =
                PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            try {
                view =
                        (BrowserView) iw.getActivePage().showView(
                            "com.he.reportLayer.views.BrowserView");
                view.getBrowserInstance().setUrl(url);
            } catch (PartInitException e) {
                e.printStackTrace();
            }
           // System.out.println("View >>" + view);
        }
    });
  1. Use eclipse jobs API https://eclipse.org/articles/Article-Concurrency/jobs-api.html for not blocking the UI
Amrit
  • 433
  • 3
  • 19