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
;
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
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
27 import eu
.etaxonomy
.taxeditor
.editor
.key
.e4
.AbstractGraphKeyEditorE4
;
28 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
29 import eu
.etaxonomy
.taxeditor
.editor
.view
.concept
.ConceptContentProvider
;
30 import eu
.etaxonomy
.taxeditor
.editor
.view
.concept
.ConceptLabelProvider
;
31 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.e4
.FactualDataPartE4
;
32 import eu
.etaxonomy
.taxeditor
.editor
.view
.media
.e4
.MediaViewPartE4
;
33 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
34 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
35 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
36 import eu
.etaxonomy
.taxeditor
.view
.e4
.AbstractCdmEditorPartE4
;
37 import eu
.etaxonomy
.taxeditor
.view
.e4
.details
.DetailsPartE4
;
38 import eu
.etaxonomy
.taxeditor
.view
.e4
.supplementaldata
.SupplementalDataPartE4
;
46 public class ConceptViewPartE4
extends AbstractCdmEditorPartE4
47 implements IPartContentHasDetails
, IPartContentHasSupplementalData
{
50 public void selectionChanged_internal(Object selection
, MPart activePart
, MPart thisPart
) {
51 if(activePart
==thisPart
){
54 if (!viewer
.getControl().isDisposed()){
55 viewer
.getControl().setEnabled(true);
57 Object partObject
= createPartObject(activePart
);
58 IStructuredSelection structuredSelection
= createSelection(selection
);
60 if (partObject
instanceof DetailsPartE4
|| partObject
instanceof SupplementalDataPartE4
61 || partObject
instanceof FactualDataPartE4
|| partObject
instanceof MediaViewPartE4
) {
62 // do not show empty page as these views are also used to edit the
63 // description selected in this view
66 else if(partObject
instanceof AbstractGraphKeyEditorE4
){
69 else if(selection
!=null){
70 showViewer(structuredSelection
, activePart
, viewer
);
79 public void create(Composite parent
, EMenuService menuService
, MPart thisPart
) {
81 this.thisPart
= thisPart
;
83 ConceptRelationViewer conceptViewer
= new ConceptRelationViewer(parent
);
85 conceptViewer
.setContentProvider(new ConceptContentProvider());
86 conceptViewer
.setLabelProvider(new ConceptLabelProvider());
89 conceptViewer
.setSorter(new ViewerSorter());
91 viewer
= conceptViewer
;
93 // Propagate selection from viewer
94 selectionChangedListener
= (event
-> selService
.setSelection(AbstractUtility
.getElementsFromSelectionChangedEvent(event
)));
95 viewer
.addSelectionChangedListener(selectionChangedListener
);
98 menuService
.registerContextMenu(viewer
.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.conceptview");
103 public void changed(Object object
) {
104 getViewer().refresh();
105 super.changed(object
);
108 private class ConceptRelationViewer
extends ListViewer
{
110 public ConceptRelationViewer(Composite parent
) {
115 public ISelection
getSelection() {
116 ISelection selection
= super.getSelection();
117 if(selection
instanceof IStructuredSelection
&& !selection
.isEmpty()){
118 Object firstElement
= ((IStructuredSelection
) selection
).getFirstElement();
119 TaxonRelationship taxonRelationship
= ((Entry
<TaxonRelationship
, Taxon
>)firstElement
).getKey();
120 return new StructuredSelection(taxonRelationship
);
127 public void setSelection(ISelection selection
) {
128 super.setSelection(selection
);
134 protected String
getViewName() {
135 return Messages
.ConceptViewPart_VIEWER_NAME
;