Project

General

Profile

Download (5.11 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.Map.Entry;
13

    
14
import javax.annotation.PostConstruct;
15

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

    
27
import eu.etaxonomy.cdm.model.taxon.Taxon;
28
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
29
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
30
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
31
import eu.etaxonomy.taxeditor.editor.key.AbstractGraphKeyEditor;
32
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
33
import eu.etaxonomy.taxeditor.editor.view.concept.ConceptContentProvider;
34
import eu.etaxonomy.taxeditor.editor.view.concept.ConceptLabelProvider;
35
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
36
import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
37
import eu.etaxonomy.taxeditor.model.AbstractUtility;
38
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
39
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
40
import eu.etaxonomy.taxeditor.model.LineSelection;
41
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
42
import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
43
import eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4;
44

    
45
/**
46
 *
47
 * @author pplitzner
48
 * @date 21.08.2017
49
 *
50
 */
51
public class ConceptViewPartE4 extends AbstractCdmEditorPartE4
52
implements IPartContentHasDetails, IPartContentHasSupplementalData{
53

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

    
60
        Object partObject = createPartObject(activePart);
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 BulkEditor && selection instanceof LineSelection){
69
			if(((LineSelection) selection).getFirstElement() instanceof Taxon){
70
				showViewer((LineSelection) selection, activePart, viewer);
71
			}
72
			else{
73
				showEmptyPage();
74
			}
75
			return;
76
		}
77
		else if(partObject instanceof AbstractGraphKeyEditor){
78
			showEmptyPage();
79
		}
80
		else if(partObject instanceof MultiPageTaxonEditor){
81
		    IEditorInput input = ((IEditorPart) partObject).getEditorInput();
82
		    showViewer(new StructuredSelection(input), activePart, viewer);
83
		}
84
		else {
85
		    showEmptyPage();
86
		}
87

    
88
	}
89

    
90
    //FIXME E4 implement
91
//	@Override
92
//	protected String createPartTitle(Object selectedObject) {
93
//		if(selectedObject instanceof TaxonEditorInput){
94
//			return super.createPartTitle(((TaxonEditorInput) selectedObject).getTaxon());
95
//		}
96
//		return super.createPartTitle(selectedObject);
97
//	}
98

    
99
	@PostConstruct
100
    public void create(Composite parent, EMenuService menuService) {
101

    
102
	    ConceptRelationViewer conceptViewer = new ConceptRelationViewer(parent);
103

    
104
	    conceptViewer.setContentProvider(new ConceptContentProvider());
105
	    conceptViewer.setLabelProvider(new ConceptLabelProvider());
106

    
107

    
108
	    conceptViewer.setSorter(new ViewerSorter());
109

    
110
		viewer = conceptViewer;
111

    
112
		// Propagate selection from viewer
113
        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
114
        viewer.addSelectionChangedListener(selectionChangedListener);
115

    
116
        //create context menu
117
        menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.conceptview");
118

    
119
	}
120

    
121
	@Override
122
	public void changed(Object object) {
123
		getViewer().refresh();
124
		super.changed(object);
125
	}
126

    
127
	private class ConceptRelationViewer extends ListViewer {
128

    
129
		public ConceptRelationViewer(Composite parent) {
130
			super(parent);
131
		}
132

    
133
		@Override
134
		public ISelection getSelection() {
135
			ISelection selection = super.getSelection();
136
			if(selection instanceof IStructuredSelection && !selection.isEmpty()){
137
				Object firstElement = ((IStructuredSelection) selection).getFirstElement();
138
				TaxonRelationship taxonRelationship = ((Entry<TaxonRelationship, Taxon>)firstElement).getKey();
139
				return new StructuredSelection(taxonRelationship);
140

    
141
			}
142
			return selection;
143
		}
144

    
145
		@Override
146
		public void setSelection(ISelection selection) {
147
			super.setSelection(selection);
148
		}
149

    
150
	}
151

    
152
	@Override
153
	protected String getViewName() {
154
		return Messages.ConceptViewPart_VIEWER_NAME;
155
	}
156

    
157
}
(1-1/2)