Project

General

Profile

« Previous | Next » 

Revision 2d8cbf51

Added by Katja Luther about 4 years ago

correct handling of checklist perspective preference

View differences:

eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/LifeCycleManager.java
20 20
import org.eclipse.e4.core.di.annotations.Optional;
21 21
import org.eclipse.e4.ui.di.UIEventTopic;
22 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 23
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
26 24
import org.eclipse.e4.ui.workbench.UIEvents;
27 25
import org.eclipse.e4.ui.workbench.lifecycle.PostContextCreate;
......
36 34
import org.eclipse.ui.IWorkbenchPage;
37 35
import org.eclipse.ui.IWorkbenchWindow;
38 36
import org.eclipse.ui.PlatformUI;
37
import org.eclipse.ui.views.IViewDescriptor;
39 38
import org.osgi.service.event.Event;
40 39

  
41 40
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
41
import eu.etaxonomy.taxeditor.editor.AppModelId;
42 42
import eu.etaxonomy.taxeditor.model.IContextListener;
43 43
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
44 44
import eu.etaxonomy.taxeditor.store.CdmStore;
......
57 57
    @Inject
58 58
    private EModelService modelService;
59 59

  
60
    @Inject
61
    private EPartService partService;
62

  
60 63
    @Inject
61 64
    public LifeCycleManager() {
62 65
        CdmStore.getContextManager().addContextListener(this);
......
99 102
    }
100 103

  
101 104
    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();
105
            if(parent!=null){
106
                if(parent.getSelectedElement()!=null
107
                        && parent.getSelectedElement().equals(part)){
108
                    parent.setSelectedElement(null);
105
        if (CdmStore.isActive()) {
106
            try{
107
                List<MPart> elements = modelService.findElements(application, null, MPart.class, Arrays.asList(NON_RESTORE));
108

  
109
                Collection<MPart> parts = partService.getParts();
110
                for (MPart element : elements) {
111
                    String elementId = element.getElementId();
112
                    for (MPart part : parts) {
113
                        String partID = part.getElementId();
114
                        if (elementId.equals(partID)){
115
                            partService.hidePart(part);
116
                        }
117
                    }
109 118
                }
110
                parent.getChildren().remove(part);
119
            }catch(IllegalStateException e){
120
                //application does not have an active window
111 121
            }
122

  
112 123
        }
113 124

  
125

  
126

  
114 127
    }
115 128

  
116 129
    /**
......
118 131
     */
119 132
    @Override
120 133
    public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
134

  
121 135
    }
122 136

  
123 137
    /**
......
126 140
    @Override
127 141
    public void contextStop(IMemento memento, IProgressMonitor monitor) {
128 142
        hideParts();
143
        if (CdmStore.isActive()){
144
            IWorkbench workbench = PlatformUI.getWorkbench();
145
            IWorkbenchWindow window = workbench
146
                    .getActiveWorkbenchWindow();
147
            IViewDescriptor viewDescriptor = workbench.getViewRegistry().find(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVE_E4_FACTUALDATAPARTE4);
148
            if(viewDescriptor == null){
149
                memento.putBoolean("facts", false);
150
            }
151
            viewDescriptor = workbench.getViewRegistry().find(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_MEDIA_E4_MEDIAVIEWPARTE4);
152
            if(viewDescriptor == null){
153
                memento.putBoolean("media", false);
154
            }
155
        }
129 156
    }
130 157

  
131 158
    /**
......
137 164
        PreferencesUtil.updateDBPreferences();
138 165

  
139 166
        hideParts();
167

  
168
        IWorkbench workbench = PlatformUI.getWorkbench();
169
        IWorkbenchWindow window = workbench
170
                .getActiveWorkbenchWindow();
140 171
        if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowChecklistPerspective.getKey())){
141
            IWorkbench workbench = PlatformUI.getWorkbench();
142
            IWorkbenchWindow window = workbench
143
                    .getActiveWorkbenchWindow();
172

  
144 173

  
145 174
            IPerspectiveRegistry registry = workbench.getPerspectiveRegistry();
146 175
            IWorkbenchPage page = window.getActivePage();
147 176
            page.setPerspective(registry.findPerspectiveWithId("eu.etaxonomy.taxeditor.perspective.checklistperspective"));
148 177
        }else{
149
            IWorkbench workbench = PlatformUI.getWorkbench();
150
            IWorkbenchWindow window = workbench
151
                    .getActiveWorkbenchWindow();
178

  
152 179

  
153 180
            IPerspectiveRegistry registry = workbench.getPerspectiveRegistry();
154 181
            IWorkbenchPage page = window.getActivePage();
155 182
            page.setPerspective(registry.findPerspectiveWithId("eu.etaxonomy.taxeditor.application.perspective.taxonomic"));
183

  
156 184
        }
185
        hideParts();
186

  
157 187
        PreferencesUtil.checkNomenclaturalCode();
158 188
    }
159 189

  

Also available in: Unified diff