Project

General

Profile

Download (5.58 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
//            if (partObject instanceof IDistributionEditor){
98
//
99
//                showViewer(structuredSelection, activePart, viewer);
100
//                return;
101
//
102
//            }
103
            //FIXME this is a temporary workaround to fix selection handling for supplemental data view
104
            // Now the supp data view gets double selection from details view and name editor (see #7126)
105
            viewer.setSelection(structuredSelection, false);
106

    
107
            showViewer(structuredSelection, activePart, viewer);
108
            if (viewer instanceof DetailsViewerE4){
109

    
110
                ((DetailsViewerE4)viewer).setDetailsEnabled(isEnabled());
111
            }
112

    
113

    
114
            return;
115
        }
116
        else{
117
            showEmptyPage();
118
            return;
119
        }
120
    }
121

    
122
    public void refreshSelection(){
123
        selectionChanged_internal(new StructuredSelection(this.viewer.getInput()), selectionProvidingPart, thisPart);
124
    }
125

    
126
    @Override
127
    protected void showEmptyPage() {
128
        super.showEmptyPage();
129
        if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed() ){
130
        	try{
131
        		((DetailsViewerE4)viewer).destroySections();
132
        	}catch(SWTException e){
133
        		if (PreferencesUtil.isShowUpWidgetIsDisposedMessages() && e.getMessage().equals("Widget is disposed")){
134
                    MessagingUtils.errorDialog("Widget is disposed",
135
                            null,
136
                            MessagingUtils.WIDGET_IS_DISPOSED_MESSAGE,
137
                            null,
138
                            e,
139
                            true);
140

    
141
                }
142
        	}
143
        }
144
    }
145

    
146
    @Override
147
    protected String getViewName(){
148
        return Messages.DetailsViewPart_VIEWER_NAME;
149
    }
150

    
151
}
(1-1/2)