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
.ArrayList
;
13 import java
.util
.Iterator
;
14 import java
.util
.List
;
15 import java
.util
.Map
.Entry
;
17 import javax
.annotation
.PostConstruct
;
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
;
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
.AbstractCdmEditorPartE4
;
39 import eu
.etaxonomy
.taxeditor
.view
.e4
.details
.DetailsPartE4
;
40 import eu
.etaxonomy
.taxeditor
.view
.e4
.supplementaldata
.SupplementalDataPartE4
;
48 public class ConceptViewPartE4
extends AbstractCdmEditorPartE4
49 implements IPartContentHasDetails
, IPartContentHasSupplementalData
{
52 public void selectionChanged_internal(Object selection
, MPart activePart
, MPart thisPart
) {
53 if(activePart
==thisPart
){
56 if (!viewer
.getControl().isDisposed()){
57 viewer
.getControl().setEnabled(true);
59 Object partObject
= createPartObject(activePart
);
60 IStructuredSelection structuredSelection
= createSelection(selection
);
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
68 else if(partObject
instanceof AbstractGraphKeyEditorE4
){
71 else if(selection
!=null){
72 showViewer(structuredSelection
, activePart
, viewer
);
81 public void create(Composite parent
, EMenuService menuService
, MPart thisPart
) {
83 this.thisPart
= thisPart
;
85 ConceptRelationViewer conceptViewer
= new ConceptRelationViewer(parent
);
87 conceptViewer
.setContentProvider(new ConceptContentProvider());
88 conceptViewer
.setLabelProvider(new ConceptLabelProvider());
91 conceptViewer
.setSorter(new ViewerSorter());
93 viewer
= conceptViewer
;
95 // Propagate selection from viewer
96 selectionChangedListener
= (event
-> selService
.setSelection(viewer
.getSelection()));
97 viewer
.addSelectionChangedListener(selectionChangedListener
);
100 menuService
.registerContextMenu(viewer
.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.conceptview");
105 public void changed(Object object
) {
106 getViewer().refresh();
107 super.changed(object
);
110 private class ConceptRelationViewer
extends ListViewer
{
112 public ConceptRelationViewer(Composite parent
) {
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());
125 return new StructuredSelection(relationships
);
131 public void setSelection(ISelection selection
) {
132 super.setSelection(selection
);
138 protected String
getViewName() {
139 return Messages
.ConceptViewPart_VIEWER_NAME
;