Project

General

Profile

Download (4.48 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.jface.viewers.SelectionChangedEvent;
18
import org.eclipse.swt.widgets.Composite;
19

    
20
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
21
import eu.etaxonomy.cdm.model.description.Feature;
22
import eu.etaxonomy.taxeditor.l10n.Messages;
23
import eu.etaxonomy.taxeditor.model.AbstractUtility;
24
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
25
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
26
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
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 implements IPartContentHasSupplementalData {
36

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

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

    
44
        this.thisPart = thisPart;
45

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

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

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

    
59
        Object partObject = createPartObject(activePart);
60

    
61
        if(partObject instanceof IPartContentHasDetails){
62
            IStructuredSelection structuredSelection = createSelection(selection);
63
            if(structuredSelection==null || structuredSelection.isEmpty()){
64
                showEmptyPage();
65
                return;
66
            }
67
            if(!(partObject instanceof ISelectionElementEditingPart) &&
68
                    partObject instanceof IConversationEnabled && ((IConversationEnabled) partObject).getConversationHolder()==null) {
69
                //TODO show specific message (refactor EmptyElement to allow specific messages)
70
                showEmptyPage();
71
                return;
72
            }
73
            // do not show details for feature nodes TODO strange check to avoid having shown the distribution map for every FeatureNodeContainer
74
            if(structuredSelection.getFirstElement() instanceof FeatureNodeContainer){
75
                // do show the map for distributions
76
                Feature feature = ((FeatureNodeContainer) structuredSelection.getFirstElement()).getFeature();
77
                if(!feature.equals(Feature.DISTRIBUTION())){
78
                    showEmptyPage();
79
                    return;
80
                }
81
            }
82
            if (structuredSelection.getFirstElement() instanceof SelectionChangedEvent){
83
                SelectionChangedEvent event = (SelectionChangedEvent)structuredSelection.getFirstElement();
84
                IStructuredSelection sel = (IStructuredSelection) event.getSelection();
85
//                TableViewer tableViewer = ((TableViewer)event.getSource());
86
//                ISelection sel = tableViewer.getSelection();
87
//                TableViewerEditor editor = (TableViewerEditor)tableViewer.getColumnViewerEditor();
88
//
89
//                ViewerCell cell = tableViewer.getColumnViewerEditor().getFocusCell();
90
//                Distribution dist = (Distribution)cell.getElement();
91
//                int columnIndex = cell.getColumnIndex();
92
                showViewer(sel, activePart, viewer);
93
                return;
94

    
95
            }
96
            showViewer(structuredSelection, activePart, viewer);
97
            return;
98
        }
99
        else{
100
            showEmptyPage();
101
            return;
102
        }
103
    }
104

    
105
    @Override
106
    protected void showEmptyPage() {
107
        super.showEmptyPage();
108
        if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed()){
109
            ((DetailsViewerE4)viewer).destroySections();
110
        }
111
    }
112

    
113
    @Override
114
    protected String getViewName(){
115
        return Messages.DetailsViewPart_VIEWER_NAME;
116
    }
117

    
118
}
(1-1/2)