Project

General

Profile

Download (3.92 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2017 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
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.
9
*/
10
package eu.etaxonomy.taxeditor;
11

    
12
import java.util.Arrays;
13
import java.util.List;
14

    
15
import javax.inject.Inject;
16

    
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.e4.ui.model.application.MApplication;
19
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
20
import org.eclipse.e4.ui.model.application.ui.MUIElement;
21
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
22
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
23
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
24
import org.eclipse.e4.ui.workbench.lifecycle.PostContextCreate;
25
import org.eclipse.e4.ui.workbench.lifecycle.PreSave;
26
import org.eclipse.e4.ui.workbench.lifecycle.ProcessAdditions;
27
import org.eclipse.e4.ui.workbench.lifecycle.ProcessRemovals;
28
import org.eclipse.e4.ui.workbench.modeling.EModelService;
29
import org.eclipse.ui.IMemento;
30

    
31
import eu.etaxonomy.taxeditor.model.IContextListener;
32
import eu.etaxonomy.taxeditor.store.CdmStore;
33

    
34
/**
35
 * @author pplitzner
36
 * @date 05.07.2017
37
 *
38
 */
39
public class LifeCycleManager implements IContextListener{
40

    
41
    private static final String NON_RESTORE = "nonRestore";
42

    
43
    private MApplication application;
44

    
45
    @Inject
46
    private EModelService modelService;
47

    
48
    @Inject
49
    public LifeCycleManager() {
50
        CdmStore.getContextManager().addContextListener(this);
51
    }
52

    
53
    @PostContextCreate
54
    private void postContextCreate() {
55
    }
56

    
57
    @ProcessAdditions
58
    private void processAdditions(MApplication application) {
59
        this.application = application;
60
        hideParts();
61
    }
62

    
63
    @ProcessRemovals
64
    private void processRemovals() {
65
    }
66

    
67
    @PreSave
68
    private void preSave(){
69
    }
70

    
71
    private void hideParts() {
72
        List<MPart> elements = modelService.findElements(application, null, MPart.class, Arrays.asList(NON_RESTORE));
73
        for (MPart part : elements) {
74
            MElementContainer<MUIElement> parent = part.getParent();
75
            if(parent!=null){
76
                if(parent.getSelectedElement()!=null
77
                        && parent.getSelectedElement().equals(part)){
78
                    parent.setSelectedElement(null);
79
                }
80
                parent.getChildren().remove(part);
81
            }
82
        }
83

    
84
        //FIXME E4 org.eclipse.ui.ediorss will not exist anymore when fully migrated
85
        List<MPlaceholder> uiElements = modelService.findElements(application, "org.eclipse.ui.editorss", MPlaceholder.class, null);
86
        for (MUIElement element : uiElements) {
87
            MElementContainer<MUIElement> parent = element.getParent();
88
            parent.setSelectedElement(null);
89
            parent.getChildren().remove(element);
90
        }
91
        List<MPartStack> additionals = modelService.findElements(application, "additional", MPartStack.class, null);
92
        for (MUIElement additional : additionals) {
93
            MElementContainer<MUIElement> parent = additional.getParent();
94
            parent.setSelectedElement(null);
95
            parent.getChildren().remove(additional);
96
        }
97
    }
98

    
99
    /**
100
     * {@inheritDoc}
101
     */
102
    @Override
103
    public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
104
    }
105

    
106
    /**
107
     * {@inheritDoc}
108
     */
109
    @Override
110
    public void contextStop(IMemento memento, IProgressMonitor monitor) {
111
        hideParts();
112
    }
113

    
114
    /**
115
     * {@inheritDoc}
116
     */
117
    @Override
118
    public void contextStart(IMemento memento, IProgressMonitor monitor) {
119
        hideParts();
120
    }
121

    
122
    /**
123
     * {@inheritDoc}
124
     */
125
    @Override
126
    public void contextRefresh(IProgressMonitor monitor) {
127
    }
128

    
129
    /**
130
     * {@inheritDoc}
131
     */
132
    @Override
133
    public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
134
    }
135

    
136
}
(5-5/8)