Project

General

Profile

« Previous | Next » 

Revision 8c2f8358

Added by Patrick Plitzner over 6 years ago

ref #6925 Parts with "non-restore" tag are closed when context stops

View differences:

eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/LifeCycleManager.java
12 12
import java.util.Arrays;
13 13
import java.util.List;
14 14

  
15
import javax.inject.Inject;
16

  
17
import org.eclipse.core.runtime.IProgressMonitor;
15 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;
16 22
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
23
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
17 24
import org.eclipse.e4.ui.workbench.lifecycle.PostContextCreate;
18 25
import org.eclipse.e4.ui.workbench.lifecycle.PreSave;
19 26
import org.eclipse.e4.ui.workbench.lifecycle.ProcessAdditions;
20 27
import org.eclipse.e4.ui.workbench.lifecycle.ProcessRemovals;
21 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;
22 33

  
23 34
/**
24 35
 * @author pplitzner
25 36
 * @date 05.07.2017
26 37
 *
27 38
 */
28
public class LifeCycleManager {
39
public class LifeCycleManager implements IContextListener{
29 40

  
30 41
    private static final String NON_RESTORE = "nonRestore";
31 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

  
32 53
    @PostContextCreate
33 54
    private void postContextCreate() {
34 55
    }
35 56

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

  
40 63
    @ProcessRemovals
......
42 65
    }
43 66

  
44 67
    @PreSave
45
    private void preSave(EModelService modelService, MApplication application){
68
    private void preSave(){
69
    }
70

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

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

  
96
    /**
97
     * {@inheritDoc}
98
     */
99
    @Override
100
    public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
101
    }
102

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

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

  
119
    /**
120
     * {@inheritDoc}
121
     */
122
    @Override
123
    public void contextRefresh(IProgressMonitor monitor) {
124
    }
125

  
126
    /**
127
     * {@inheritDoc}
128
     */
129
    @Override
130
    public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
131
    }
132

  
52 133
}

Also available in: Unified diff