3 * Copyright (C) 2017 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
;
12 import java
.util
.Arrays
;
13 import java
.util
.Collection
;
14 import java
.util
.List
;
16 import javax
.inject
.Inject
;
18 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
19 import org
.eclipse
.e4
.core
.contexts
.IEclipseContext
;
20 import org
.eclipse
.e4
.core
.di
.annotations
.Optional
;
21 import org
.eclipse
.e4
.ui
.di
.UIEventTopic
;
22 import org
.eclipse
.e4
.ui
.model
.application
.MApplication
;
23 import org
.eclipse
.e4
.ui
.model
.application
.ui
.MElementContainer
;
24 import org
.eclipse
.e4
.ui
.model
.application
.ui
.MUIElement
;
25 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
26 import org
.eclipse
.e4
.ui
.workbench
.UIEvents
;
27 import org
.eclipse
.e4
.ui
.workbench
.lifecycle
.PostContextCreate
;
28 import org
.eclipse
.e4
.ui
.workbench
.lifecycle
.PreSave
;
29 import org
.eclipse
.e4
.ui
.workbench
.lifecycle
.ProcessAdditions
;
30 import org
.eclipse
.e4
.ui
.workbench
.lifecycle
.ProcessRemovals
;
31 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EModelService
;
32 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EPartService
;
33 import org
.eclipse
.ui
.IMemento
;
34 import org
.eclipse
.ui
.IPerspectiveRegistry
;
35 import org
.eclipse
.ui
.IWorkbench
;
36 import org
.eclipse
.ui
.IWorkbenchPage
;
37 import org
.eclipse
.ui
.IWorkbenchWindow
;
38 import org
.eclipse
.ui
.PlatformUI
;
39 import org
.osgi
.service
.event
.Event
;
41 import eu
.etaxonomy
.taxeditor
.model
.IContextListener
;
42 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
43 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
44 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
51 public class LifeCycleManager
implements IContextListener
{
53 private static final String NON_RESTORE
= "nonRestore";
55 private MApplication application
;
58 private EModelService modelService
;
61 public LifeCycleManager() {
62 CdmStore
.getContextManager().addContextListener(this);
66 private void postContextCreate() {
70 private void processAdditions(MApplication application
) {
71 this.application
= application
;
77 private void processRemovals() {
81 private void preSave(){
86 public void subscribeAppShutdownStarted(@UIEventTopic(UIEvents
.UILifeCycle
.APP_SHUTDOWN_STARTED
) Event event
,
87 MApplication application
) {
88 IEclipseContext context
= application
.getContext();
89 EPartService partService
= context
.get(EPartService
.class);
91 Collection
<MPart
> dirtyParts
= partService
.getDirtyParts();
92 if(!dirtyParts
.isEmpty()){
93 partService
.saveAll(true);
95 } catch (IllegalStateException e
) {
97 //exception is ignored as this is a temporary fix until full e4 migration
101 private void hideParts() {
102 List
<MPart
> elements
= modelService
.findElements(application
, null, MPart
.class, Arrays
.asList(NON_RESTORE
));
103 for (MPart part
: elements
) {
104 MElementContainer
<MUIElement
> parent
= part
.getParent();
106 if(parent
.getSelectedElement()!=null
107 && parent
.getSelectedElement().equals(part
)){
108 parent
.setSelectedElement(null);
110 parent
.getChildren().remove(part
);
120 public void contextAboutToStop(IMemento memento
, IProgressMonitor monitor
) {
127 public void contextStop(IMemento memento
, IProgressMonitor monitor
) {
135 public void contextStart(IMemento memento
, IProgressMonitor monitor
) {
136 PreferencesUtil
.setDefaults();
137 PreferencesUtil
.updateDBPreferences();
140 if (PreferencesUtil
.getBooleanValue(IPreferenceKeys
.SHOW_CHECKLIST_PERSPECTIVE
)){
141 IWorkbench workbench
= PlatformUI
.getWorkbench();
142 IWorkbenchWindow window
= workbench
143 .getActiveWorkbenchWindow();
145 IPerspectiveRegistry registry
= workbench
.getPerspectiveRegistry();
146 IWorkbenchPage page
= window
.getActivePage();
147 page
.setPerspective(registry
.findPerspectiveWithId("eu.etaxonomy.taxeditor.perspective.checklistperspective"));
149 PreferencesUtil
.checkNomenclaturalCode();
156 public void contextRefresh(IProgressMonitor monitor
) {
163 public void workbenchShutdown(IMemento memento
, IProgressMonitor monitor
) {