Project

General

Profile

Download (5.27 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.view.e4.details;
11

    
12
import javax.annotation.PostConstruct;
13
import javax.inject.Inject;
14

    
15
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
16
import org.eclipse.e4.core.contexts.IEclipseContext;
17
import org.eclipse.e4.core.services.log.Logger;
18
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
19
import org.eclipse.jface.viewers.IStructuredSelection;
20
import org.eclipse.jface.viewers.StructuredSelection;
21
import org.eclipse.swt.SWTException;
22
import org.eclipse.swt.widgets.Composite;
23

    
24
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
25
import eu.etaxonomy.cdm.model.description.Feature;
26
import eu.etaxonomy.taxeditor.l10n.Messages;
27
import eu.etaxonomy.taxeditor.model.AbstractUtility;
28
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
29
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
30
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
31
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
32
import eu.etaxonomy.taxeditor.model.MessagingUtils;
33
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
34
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
35
import eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4;
36
import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
37

    
38
/**
39
 * @author pplitzner
40
 * @date 18.07.2017
41
 *
42
 */
43
public class DetailsPartE4 extends AbstractCdmEditorPartE4 implements IPartContentHasSupplementalData, IPartContentHasFactualData {
44
	@Inject
45
	private Logger logger;
46

    
47
	@Inject
48
    public DetailsPartE4() {
49
    }
50

    
51
    @PostConstruct
52
    public void create(Composite parent, MPart thisPart, IEclipseContext context) {
53

    
54
        this.thisPart = thisPart;
55

    
56
        viewer = ContextInjectionFactory.make(DetailsViewerE4.class, context);
57
        ((DetailsViewerE4)viewer).init(parent, this);
58

    
59
        // Propagate selection from viewer
60
        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
61
        viewer.addSelectionChangedListener(selectionChangedListener);
62
    }
63

    
64
    @Override
65
    public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
66
        if (activePart==thisPart){
67
            return;
68
        }
69

    
70
        Object partObject = createPartObject(activePart);
71
        if (partObject instanceof SupplementalDataPartE4 ) {
72
            // do not show empty page
73
            return;
74
        }
75

    
76
        if(partObject instanceof IPartContentHasDetails){
77
            IStructuredSelection structuredSelection = createSelection(selection);
78
            if(structuredSelection==null || structuredSelection.isEmpty()){
79
                showEmptyPage();
80
                return;
81
            }
82
            if(!(partObject instanceof ISelectionElementEditingPart) &&
83
                    partObject instanceof IConversationEnabled && ((IConversationEnabled) partObject).getConversationHolder()==null) {
84
                //TODO show specific message (refactor EmptyElement to allow specific messages)
85
                showEmptyPage();
86
                return;
87
            }
88
            // do not show details for feature nodes TODO strange check to avoid having shown the distribution map for every FeatureNodeContainer
89
            if(structuredSelection.getFirstElement() instanceof FeatureNodeContainer){
90
                // do show the map for distributions
91
                Feature feature = ((FeatureNodeContainer) structuredSelection.getFirstElement()).getFeature();
92
                if(!feature.equals(Feature.DISTRIBUTION())){
93
                    showEmptyPage();
94
                    return;
95
                }
96
            }
97

    
98
            //FIXME this is a temporary workaround to fix selection handling for supplemental data view
99
            // Now the supp data view gets double selection from details view and name editor (see #7126)
100

    
101
            viewer.setSelection(structuredSelection, false);
102

    
103
            showViewer(structuredSelection, activePart, viewer);
104

    
105

    
106

    
107
            return;
108
        }
109
        else{
110
            showEmptyPage();
111
            return;
112
        }
113
    }
114

    
115
    public void refreshSelection(){
116
        selectionChanged_internal(new StructuredSelection(this.viewer.getInput()), selectionProvidingPart, thisPart);
117
    }
118

    
119
    @Override
120
    protected void showEmptyPage() {
121
        super.showEmptyPage();
122
        if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed() ){
123
        	try{
124
        		((DetailsViewerE4)viewer).destroySections();
125
        	}catch(SWTException e){
126
        		if (PreferencesUtil.isShowUpWidgetIsDisposedMessages() && e.getMessage().equals("Widget is disposed")){
127
                    MessagingUtils.errorDialog("Widget is disposed",
128
                            null,
129
                            MessagingUtils.WIDGET_IS_DISPOSED_MESSAGE,
130
                            null,
131
                            e,
132
                            true);
133

    
134
                }
135
        	}
136
        }
137
    }
138

    
139
    @Override
140
    protected String getViewName(){
141
        return Messages.DetailsViewPart_VIEWER_NAME;
142
    }
143

    
144
}
(1-1/2)