2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.concept
.e4
;
12 import java
.util
.Map
.Entry
;
14 import javax
.annotation
.PostConstruct
;
15 import javax
.inject
.Inject
;
16 import javax
.inject
.Named
;
18 import org
.eclipse
.e4
.core
.di
.annotations
.Optional
;
19 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
20 import org
.eclipse
.e4
.ui
.services
.EMenuService
;
21 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
22 import org
.eclipse
.e4
.ui
.workbench
.modeling
.ESelectionService
;
23 import org
.eclipse
.jface
.viewers
.ISelection
;
24 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
25 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
26 import org
.eclipse
.jface
.viewers
.ListViewer
;
27 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
28 import org
.eclipse
.jface
.viewers
.ViewerSorter
;
29 import org
.eclipse
.swt
.widgets
.Composite
;
30 import org
.eclipse
.ui
.IEditorInput
;
31 import org
.eclipse
.ui
.IEditorPart
;
33 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
35 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
36 import eu
.etaxonomy
.taxeditor
.editor
.key
.AbstractGraphKeyEditor
;
37 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
38 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
39 import eu
.etaxonomy
.taxeditor
.editor
.view
.concept
.ConceptContentProvider
;
40 import eu
.etaxonomy
.taxeditor
.editor
.view
.concept
.ConceptLabelProvider
;
41 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
42 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
43 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
44 import eu
.etaxonomy
.taxeditor
.model
.LineSelection
;
45 import eu
.etaxonomy
.taxeditor
.view
.e4
.AbstractCdmEditorPartE4
;
46 import eu
.etaxonomy
.taxeditor
.view
.e4
.details
.DetailsPartE4
;
47 import eu
.etaxonomy
.taxeditor
.view
.e4
.supplementaldata
.SupplementalDataPartE4
;
55 public class ConceptViewPartE4
extends AbstractCdmEditorPartE4
56 implements IPartContentHasDetails
, IPartContentHasSupplementalData
{
58 private ISelectionChangedListener selectionChangedListener
;
61 private ESelectionService selService
;
65 public void selectionChanged(
66 @Named(IServiceConstants
.ACTIVE_SELECTION
)Object selection
,
67 @Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
69 if(activePart
==thisPart
){
73 Object partObject
= createPartObject(activePart
);
75 if (partObject
instanceof DetailsPartE4
|| partObject
instanceof SupplementalDataPartE4
) {
76 // do not show empty page as these views are also used to edit the
77 // description selected in this view
80 else if(partObject
instanceof BulkEditor
&& selection
instanceof LineSelection
){
81 if(((LineSelection
) selection
).getFirstElement() instanceof Taxon
){
82 showViewer((LineSelection
) selection
, activePart
, viewer
);
89 else if(partObject
instanceof AbstractGraphKeyEditor
){
92 else if(partObject
instanceof TaxonNameEditorE4
){
93 IEditorInput input
= ((IEditorPart
) partObject
).getEditorInput();
94 showViewer(new StructuredSelection(input
), activePart
, viewer
);
103 public void create(Composite parent
, EMenuService menuService
, MPart thisPart
) {
105 this.thisPart
= thisPart
;
107 ConceptRelationViewer conceptViewer
= new ConceptRelationViewer(parent
);
109 conceptViewer
.setContentProvider(new ConceptContentProvider());
110 conceptViewer
.setLabelProvider(new ConceptLabelProvider());
113 conceptViewer
.setSorter(new ViewerSorter());
115 viewer
= conceptViewer
;
117 // Propagate selection from viewer
118 selectionChangedListener
= (event
-> selService
.setSelection(AbstractUtility
.getElementsFromSelectionChangedEvent(event
)));
119 viewer
.addSelectionChangedListener(selectionChangedListener
);
121 //create context menu
122 menuService
.registerContextMenu(viewer
.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.conceptview");
127 public void changed(Object object
) {
128 getViewer().refresh();
129 super.changed(object
);
132 private class ConceptRelationViewer
extends ListViewer
{
134 public ConceptRelationViewer(Composite parent
) {
139 public ISelection
getSelection() {
140 ISelection selection
= super.getSelection();
141 if(selection
instanceof IStructuredSelection
&& !selection
.isEmpty()){
142 Object firstElement
= ((IStructuredSelection
) selection
).getFirstElement();
143 TaxonRelationship taxonRelationship
= ((Entry
<TaxonRelationship
, Taxon
>)firstElement
).getKey();
144 return new StructuredSelection(taxonRelationship
);
151 public void setSelection(ISelection selection
) {
152 super.setSelection(selection
);
158 protected String
getViewName() {
159 return Messages
.ConceptViewPart_VIEWER_NAME
;