Question

I'm writing a program in Java in eclipse. I have two classes which extend from the super class ViewPart. Now I want to open only one of the classes automatically (that means when I run the program) and the other one should be opened by a button on the UI of the first. But I don't know how to open a ViewPart class manually.

I tried now

ActorCalendar actorCalendar = new ActorCalendar(); try { actorCalendar.getSite().getPage().showView("id", null, IWorkbenchPage.VIEW_VISIBLE); } catch (PartInitException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }

Here the class ActorCalendar is a class extended from the class ViewPart. This code Block is implemented in a Button at the other class extended from ViewPart. But then I get a NullPointerException at the class where this code block is implemented. In the line:

actorCalendar.getSite().getPage().showView("id", null, IWorkbenchPage.VIEW_VISIBLE);

What did I do wrong?

I hope someone can help me.

Thank you !

Was it helpful?

Solution 2

ActorCalendar actorCalendarView = new ActorCalendar();

try { IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("de.uhd.ifi.se.pcm.bppcm.ui.ActorCalendar"); if (view instanceof ActorCalendar) { actorCalendarView = (ActorCalendar) view; actorCalendarView.doStuff(); } } catch (PartInitException ex) { // showView() can throw an exception if view cannot be shown ex.printStackTrace(); }

this worked for me!

OTHER TIPS

You want org.eclipse.ui.IWorkbenchPage.showView(String). That will allow you to open a view by ID. If your button is in the first view's toolbar, you can get the workbench page from your view using getSite().getPage().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top