// ignored.
WorkbenchWindow win = (WorkbenchWindow) window;
if (win != null) {
WorkbenchPage page = win.getActiveWorkbenchPage();
if (page != null) {
IPerspectiveDescriptor perspectives[] = page
.getOpenPerspectives();
for (int i = 0; i < perspectives.length; i++) {
IPerspectiveDescriptor persp = perspectives[i];
if (perspectiveId.equals(persp.getId())) {
win.makeVisible();
page.setPerspective(persp);
return page;
}
}
}
}
// If another window that has the workspace root as input and the
// requested
// perpective open and active, then the window is given focus.
IAdaptable input = getDefaultPageInput();
IWorkbenchWindow[] windows = getWorkbenchWindows();
for (int i = 0; i < windows.length; i++) {
win = (WorkbenchWindow) windows[i];
if (window != win) {
WorkbenchPage page = win.getActiveWorkbenchPage();
if (page != null) {
boolean inputSame = false;
if (input == null) {
inputSame = (page.getInput() == null);
} else {
inputSame = input.equals(page.getInput());
}
if (inputSame) {
Perspective persp = page.getActivePerspective();
if (persp != null) {
IPerspectiveDescriptor desc = persp.getDesc();
if (desc != null) {
if (perspectiveId.equals(desc.getId())) {
Shell shell = win.getShell();
shell.open();
if (shell.getMinimized()) {
shell.setMinimized(false);
}
return page;
}
}
}
}
}
}
}
// Otherwise the requested perspective is opened and shown in the
// specified
// window or in a new window depending on the current user preference
// for opening
// perspectives, and that window is given focus.
win = (WorkbenchWindow) window;
if (win != null) {
IPreferenceStore store = WorkbenchPlugin.getDefault()
.getPreferenceStore();
int mode = store.getInt(IPreferenceConstants.OPEN_PERSP_MODE);
IWorkbenchPage page = win.getActiveWorkbenchPage();
IPerspectiveDescriptor persp = null;
if (page != null) {
persp = page.getPerspective();
}
// Only open a new window if user preference is set and the window
// has an active perspective.
if (IPreferenceConstants.OPM_NEW_WINDOW == mode && persp != null) {
IWorkbenchWindow newWindow = openWorkbenchWindow(perspectiveId,
input);
return newWindow.getActivePage();
}
IPerspectiveDescriptor desc = getPerspectiveRegistry()
.findPerspectiveWithId(perspectiveId);
if (desc == null) {
throw new WorkbenchException(
NLS
.bind(