Project

General

Profile

Download (3.61 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.jface.viewers.IStructuredSelection;
17
import org.eclipse.swt.widgets.Composite;
18

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

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

    
36
    @Inject
37
    public DetailsPartE4() {
38
    }
39

    
40
    @PostConstruct
41
    public void create(Composite parent, MPart thisPart) {
42

    
43
        this.thisPart = thisPart;
44

    
45
        viewer = new DetailsViewerE4(parent, this);
46

    
47
        // Propagate selection from viewer
48
        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
49
        viewer.addSelectionChangedListener(selectionChangedListener);
50
    }
51

    
52
    @Override
53
    public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
54
        if (activePart==thisPart){
55
            return;
56
        }
57

    
58
        Object partObject = createPartObject(activePart);
59

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

    
90
    @Override
91
    protected void showEmptyPage() {
92
        super.showEmptyPage();
93
        if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed()){
94
            ((DetailsViewerE4)viewer).destroySections();
95
        }
96
    }
97

    
98
    @Override
99
    protected String getViewName(){
100
        return Messages.DetailsViewPart_VIEWER_NAME;
101
    }
102

    
103
}
(1-1/2)