Sunday 26 October 2008

Geoff on GEF pt. IV

Wow! Things are now really falling into place.

Most of my effort recently has been spent trying to get my GEF ViewPart to display in a seperate window, as a nice touch I wanted it to display in fullscreen on a second monitor if one is available. Amazingly, I've done it.


@SuppressWarnings("restriction")
@Override
public void run() {
Display display = Display.getDefault();
Monitor[] monitors = display.getMonitors();

Monitor lastMon = monitors[monitors.length - 1];
Rectangle bounds = lastMon.getBounds();

try {
IWorkbenchWindow window = Workbench.getInstance().openWorkbenchWindow("org.gamingclubnetwork.tournament.perspective.display", null);

Shell shell = window.getShell();
shell.setMenuBar(null);
shell.setLocation(bounds.x, bounds.y);
shell.setFullScreen(monitors.length > 1);
}
catch (WorkbenchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


First of all we look for all available monitors and grab the last one (I assumed the secondary display will be used for projectors or large monitors).
With that done, the trick is to open a new workbench window specifying a new perspective that contains just my GEF view. I then grab the shell of this workbench, remove the menu bar, set it's location to the top corner of the monitor to show it on and then set to full screen if not on the primary display.

No comments: