Project

General

Profile

Download (3.01 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.basic.MPart;
22
import org.eclipse.e4.ui.workbench.lifecycle.PostContextCreate;
23
import org.eclipse.e4.ui.workbench.lifecycle.PreSave;
24
import org.eclipse.e4.ui.workbench.lifecycle.ProcessAdditions;
25
import org.eclipse.e4.ui.workbench.lifecycle.ProcessRemovals;
26
import org.eclipse.e4.ui.workbench.modeling.EModelService;
27
import org.eclipse.ui.IMemento;
28

    
29
import eu.etaxonomy.taxeditor.model.IContextListener;
30
import eu.etaxonomy.taxeditor.store.CdmStore;
31

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

    
39
    private static final String NON_RESTORE = "nonRestore";
40

    
41
    private MApplication application;
42

    
43
    @Inject
44
    private EModelService modelService;
45

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

    
51
    @PostContextCreate
52
    private void postContextCreate() {
53
    }
54

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

    
61
    @ProcessRemovals
62
    private void processRemovals() {
63
    }
64

    
65
    @PreSave
66
    private void preSave(){
67
    }
68

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

    
83
    /**
84
     * {@inheritDoc}
85
     */
86
    @Override
87
    public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
88
    }
89

    
90
    /**
91
     * {@inheritDoc}
92
     */
93
    @Override
94
    public void contextStop(IMemento memento, IProgressMonitor monitor) {
95
        hideParts();
96
    }
97

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

    
106
    /**
107
     * {@inheritDoc}
108
     */
109
    @Override
110
    public void contextRefresh(IProgressMonitor monitor) {
111
    }
112

    
113
    /**
114
     * {@inheritDoc}
115
     */
116
    @Override
117
    public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
118
    }
119

    
120
}
(5-5/8)