1
|
|
2
|
package eu.etaxonomy.taxeditor.workbench;
|
3
|
|
4
|
import javax.inject.Named;
|
5
|
|
6
|
import org.eclipse.core.commands.ExecutionException;
|
7
|
import org.eclipse.core.runtime.IAdaptable;
|
8
|
import org.eclipse.e4.core.di.annotations.Execute;
|
9
|
import org.eclipse.e4.ui.model.application.MApplication;
|
10
|
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
|
11
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
12
|
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
13
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
14
|
import org.eclipse.jface.window.Window;
|
15
|
import org.eclipse.swt.widgets.Shell;
|
16
|
import org.eclipse.ui.IPerspectiveDescriptor;
|
17
|
import org.eclipse.ui.IPerspectiveRegistry;
|
18
|
import org.eclipse.ui.IWorkbench;
|
19
|
import org.eclipse.ui.IWorkbenchPage;
|
20
|
import org.eclipse.ui.WorkbenchException;
|
21
|
import org.eclipse.ui.internal.Workbench;
|
22
|
import org.eclipse.ui.internal.dialogs.SelectPerspectiveDialog;
|
23
|
|
24
|
public class SwitchPerspectiveHandler {
|
25
|
@Execute
|
26
|
public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, IPerspectiveRegistry perspReg,
|
27
|
EModelService modelService, EPartService partService, MWindow window, MApplication application, IWorkbench workbench) throws ExecutionException{
|
28
|
|
29
|
SelectPerspectiveDialog dialog = new SelectPerspectiveDialog(shell, perspReg);
|
30
|
dialog.open();
|
31
|
|
32
|
if (dialog.getReturnCode() == Window.CANCEL) {
|
33
|
return;
|
34
|
}
|
35
|
|
36
|
final IPerspectiveDescriptor descriptor = dialog.getSelection();
|
37
|
String perspectiveId = descriptor.getId();
|
38
|
|
39
|
try {
|
40
|
IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
|
41
|
if (activePage != null) {
|
42
|
activePage.setPerspective(descriptor);
|
43
|
} else {
|
44
|
IAdaptable input = ((Workbench) workbench).getDefaultPageInput();
|
45
|
workbench.getActiveWorkbenchWindow().openPage(perspectiveId, input);
|
46
|
}
|
47
|
} catch (WorkbenchException e) {
|
48
|
throw new ExecutionException("Perspective could not be opened.", e); //$NON-NLS-1$
|
49
|
}
|
50
|
// // get the parent perspective stack, so that the loaded
|
51
|
// // perspective can be added to it.
|
52
|
// MPerspective activePerspective = modelService.getActivePerspective(window);
|
53
|
// MElementContainer<MUIElement> activePerspectiveParent = activePerspective.getParent();
|
54
|
//
|
55
|
// // remove the current perspective, which should be replaced by
|
56
|
// // the loaded one
|
57
|
// List<MPerspective> alreadyPresentPerspective = modelService.findElements(window,
|
58
|
// activePerspective.getElementId(), MPerspective.class, null);
|
59
|
// for (MPerspective perspective : alreadyPresentPerspective) {
|
60
|
// modelService.removePerspectiveModel(perspective, window);
|
61
|
// }
|
62
|
//
|
63
|
// // add the loaded perspective and switch to it
|
64
|
// activePerspectiveParent.getChildren().add(perspectiveToShow);
|
65
|
//
|
66
|
// partService.switchPerspective(perspectiveToShow);
|
67
|
|
68
|
// EPartService partService =
|
69
|
// window.getContext().get(EPartService.class);
|
70
|
// partService.switchPerspective(perspectiveId);
|
71
|
// if (descriptor != null) {
|
72
|
// int openPerspMode = WorkbenchPlugin.getDefault().getPreferenceStore()
|
73
|
// .getInt(IPreferenceConstants.OPEN_PERSP_MODE);
|
74
|
// IWorkbenchPage page = activeWorkbenchWindow.getActivePage();
|
75
|
// IPerspectiveDescriptor persp = page == null ? null :
|
76
|
// page.getPerspective();
|
77
|
// String perspectiveId = descriptor.getId();
|
78
|
// // only open it in a new window if the preference is set and the
|
79
|
// // current workbench page doesn't have an active perspective
|
80
|
// if (IPreferenceConstants.OPM_NEW_WINDOW == openPerspMode && persp !=
|
81
|
// null) {
|
82
|
// openNewWindowPerspective(perspectiveId, window);
|
83
|
// } else {
|
84
|
// openPerspective(perspectiveId, activeWorkbenchWindow);
|
85
|
// }
|
86
|
}
|
87
|
|
88
|
}
|