Project

General

Profile

Download (4.53 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.editor.view.concept.e4;
11

    
12
import java.util.ArrayList;
13
import java.util.Iterator;
14
import java.util.List;
15
import java.util.Map.Entry;
16

    
17
import javax.annotation.PostConstruct;
18

    
19
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
20
import org.eclipse.e4.ui.services.EMenuService;
21
import org.eclipse.jface.viewers.ISelection;
22
import org.eclipse.jface.viewers.IStructuredSelection;
23
import org.eclipse.jface.viewers.ListViewer;
24
import org.eclipse.jface.viewers.StructuredSelection;
25
import org.eclipse.jface.viewers.ViewerSorter;
26
import org.eclipse.swt.widgets.Composite;
27

    
28
import eu.etaxonomy.cdm.model.taxon.Taxon;
29
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
30
import eu.etaxonomy.taxeditor.editor.key.e4.AbstractGraphKeyEditorE4;
31
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
32
import eu.etaxonomy.taxeditor.editor.view.concept.ConceptContentProvider;
33
import eu.etaxonomy.taxeditor.editor.view.concept.ConceptLabelProvider;
34
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
35
import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
36
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
37
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
38
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPart;
39
import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
40
import eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4;
41

    
42
/**
43
 *
44
 * @author pplitzner
45
 * @date 21.08.2017
46
 *
47
 */
48
public class ConceptViewPartE4 extends AbstractCdmEditorPart
49
implements IPartContentHasDetails, IPartContentHasSupplementalData{
50

    
51
    @Override
52
    public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
53
        if(activePart==thisPart){
54
            return;
55
        }
56
        if (!viewer.getControl().isDisposed()){
57
            viewer.getControl().setEnabled(true);
58
        }
59
        Object partObject = getPartObject(activePart);
60
        IStructuredSelection structuredSelection = createSelection(selection);
61

    
62
        if (partObject instanceof DetailsPartE4 || partObject instanceof SupplementalDataPartE4
63
                || partObject instanceof FactualDataPartE4|| partObject instanceof MediaViewPartE4) {
64
            // do not show empty page as these views are also used to edit the
65
            // description selected in this view
66
            return;
67
        }
68
		else if(partObject instanceof AbstractGraphKeyEditorE4){
69
			showEmptyPage();
70
		}
71
		else if(selection!=null){
72
		    showViewer(structuredSelection, activePart, viewer);
73
		}
74
		else {
75
		    showEmptyPage();
76
		}
77

    
78
	}
79

    
80
	@PostConstruct
81
    public void create(Composite parent, EMenuService menuService, MPart thisPart) {
82

    
83
	    this.thisPart = thisPart;
84

    
85
	    ConceptRelationViewer conceptViewer = new ConceptRelationViewer(parent);
86

    
87
	    conceptViewer.setContentProvider(new ConceptContentProvider());
88
	    conceptViewer.setLabelProvider(new ConceptLabelProvider());
89

    
90

    
91
	    conceptViewer.setSorter(new ViewerSorter());
92

    
93
		viewer = conceptViewer;
94

    
95
		// Propagate selection from viewer
96
        selectionChangedListener = (event -> selService.setSelection(viewer.getSelection()));
97
        viewer.addSelectionChangedListener(selectionChangedListener);
98

    
99
        //create context menu
100
        menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.conceptview");
101

    
102
	}
103

    
104
	@Override
105
	public void changed(Object object) {
106
		getViewer().refresh();
107
		super.changed(object);
108
	}
109

    
110
	private class ConceptRelationViewer extends ListViewer {
111

    
112
		public ConceptRelationViewer(Composite parent) {
113
			super(parent);
114
		}
115

    
116
		@Override
117
		public ISelection getSelection() {
118
			ISelection selection = super.getSelection();
119
			List<TaxonRelationship> relationships = new ArrayList<>();
120
			if(selection instanceof IStructuredSelection && !selection.isEmpty()){
121
			    for(Iterator iter = ((IStructuredSelection) selection).iterator();iter.hasNext();){
122
			        Object object = iter.next();
123
			        relationships.add(((Entry<TaxonRelationship, Taxon>)object).getKey());
124
			    }
125
			    return new StructuredSelection(relationships);
126
			}
127
			return selection;
128
		}
129

    
130
		@Override
131
		public void setSelection(ISelection selection) {
132
			super.setSelection(selection);
133
		}
134

    
135
	}
136

    
137
	@Override
138
	protected String getViewName() {
139
		return Messages.ConceptViewPart_VIEWER_NAME;
140
	}
141

    
142
}
(1-1/2)