Project

General

Profile

Download (3.91 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.model.IPartContentHasSupplementalData;
28
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
29
import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
30

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

    
38
    private ISelectionChangedListener selectionChangedListener;
39

    
40
    @Inject
41
    private ESelectionService selService;
42

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

    
47
    @PostConstruct
48
    public void create(Composite parent, MPart thisPart) {
49

    
50
        this.thisPart = thisPart;
51

    
52
        viewer = new DetailsViewerE4(parent, this);
53

    
54
        // Propagate selection from viewer
55
        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
56
        viewer.addSelectionChangedListener(selectionChangedListener);
57
    }
58

    
59
    @Override
60
    public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
61
        if (activePart==thisPart){
62
            return;
63
        }
64

    
65
        Object partObject = createPartObject(activePart);
66

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

    
100
//    protected void showEmptyPage() {
101
//        super.showEmptyPage();
102
//        if(viewer!=null){
103
//            viewer.showEmptyPage();
104
//        }
105
//        selectionProvidingPart = null;
106
//    }
107

    
108
    @Override
109
    protected String getViewName(){
110
        return Messages.DetailsViewPart_VIEWER_NAME;
111
    }
112

    
113
}
(1-1/2)