Project

General

Profile

Download (3.75 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.ui.model.application.ui.basic.MPart;
16
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
17
import org.eclipse.jface.viewers.ISelectionChangedListener;
18
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.swt.widgets.Composite;
20

    
21
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
22
import eu.etaxonomy.cdm.model.description.Feature;
23
import eu.etaxonomy.taxeditor.l10n.Messages;
24
import eu.etaxonomy.taxeditor.model.AbstractUtility;
25
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
26
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
27
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
28
import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
29

    
30
/**
31
 * @author pplitzner
32
 * @date 18.07.2017
33
 *
34
 */
35
public class DetailsPartE4 extends AbstractCdmEditorPartE4{
36

    
37
    private ISelectionChangedListener selectionChangedListener;
38

    
39
    @Inject
40
    private ESelectionService selService;
41

    
42
    @Inject
43
    public DetailsPartE4() {
44
    }
45

    
46
    @PostConstruct
47
    public void create(Composite parent) {
48
        viewer = new DetailsViewerE4(parent, this);
49

    
50
        // Propagate selection from viewer
51
        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
52
        viewer.addSelectionChangedListener(selectionChangedListener);
53
    }
54

    
55
    @Override
56
    public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
57
        if (activePart==thisPart){
58
            return;
59
        }
60

    
61
        Object partObject = createPartObject(activePart);
62

    
63
        if(partObject instanceof IPartContentHasDetails){
64
            IStructuredSelection structuredSelection = createSelection(selection);
65
            if(structuredSelection==null || structuredSelection.isEmpty()){
66
                showEmptyPage();
67
                return;
68
            }
69
            if(!(partObject instanceof ISelectionElementEditingPart) &&
70
                    partObject instanceof IConversationEnabled && ((IConversationEnabled) partObject).getConversationHolder()==null) {
71
                //TODO show specific message (refactor EmptyElement to allow specific messages)
72
                showEmptyPage();
73
                return;
74
            }
75
            // do not show details for feature nodes TODO strange check to avoid having shown the distribution map for every FeatureNodeContainer
76
            if(structuredSelection.getFirstElement() instanceof FeatureNodeContainer){
77
                // do show the map for distributions
78
                Feature feature = ((FeatureNodeContainer) structuredSelection.getFirstElement()).getFeature();
79
                if(!feature.equals(Feature.DISTRIBUTION())){
80
                    showEmptyPage();
81
                    return;
82
                }
83
            }
84
            showViewer(structuredSelection, activePart, viewer);
85
            return;
86
        }
87
        else if(selectionProvidingPart!=null && selectionProvidingPart.isVisible()){
88
            return;
89
        }
90
        else{
91
            showEmptyPage();
92
            return;
93
        }
94
    }
95

    
96
//    protected void showEmptyPage() {
97
//        super.showEmptyPage();
98
//        if(viewer!=null){
99
//            viewer.showEmptyPage();
100
//        }
101
//        selectionProvidingPart = null;
102
//    }
103

    
104
    @Override
105
    protected String getViewName(){
106
        return Messages.DetailsViewPart_VIEWER_NAME;
107
    }
108

    
109
}
(1-1/2)