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
;
12 import java
.util
.Map
.Entry
;
14 import org
.eclipse
.jface
.action
.GroupMarker
;
15 import org
.eclipse
.jface
.action
.MenuManager
;
16 import org
.eclipse
.jface
.viewers
.ISelection
;
17 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
18 import org
.eclipse
.jface
.viewers
.ListViewer
;
19 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
20 import org
.eclipse
.jface
.viewers
.Viewer
;
21 import org
.eclipse
.jface
.viewers
.ViewerSorter
;
22 import org
.eclipse
.swt
.widgets
.Composite
;
23 import org
.eclipse
.swt
.widgets
.Control
;
24 import org
.eclipse
.swt
.widgets
.Menu
;
25 import org
.eclipse
.ui
.IEditorInput
;
26 import org
.eclipse
.ui
.IEditorPart
;
27 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
28 import org
.eclipse
.ui
.IWorkbenchPart
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
32 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
33 import eu
.etaxonomy
.taxeditor
.editor
.Messages
;
34 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
35 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
36 import eu
.etaxonomy
.taxeditor
.editor
.key
.AbstractGraphKeyEditor
;
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
.AbstractCdmEditorViewPart
;
42 import eu
.etaxonomy
.taxeditor
.view
.detail
.DetailsViewPart
;
43 import eu
.etaxonomy
.taxeditor
.view
.supplementaldata
.SupplementalDataViewPart
;
47 * @created Jan 24, 2011
50 public class ConceptViewPart
extends AbstractCdmEditorViewPart
51 implements IPartContentHasDetails
, IPartContentHasSupplementalData
{
53 public static final String ID
= "eu.etaxonomy.taxeditor.editor.view.concept"; //$NON-NLS-1$
55 private ConceptRelationViewer viewer
;
58 protected void selectionChanged_internal(IWorkbenchPart part
, ISelection selection
) {
62 if(AbstractUtility
.getActiveEditor() == null){
67 if (part
instanceof DetailsViewPart
|| part
instanceof SupplementalDataViewPart
) {
68 // do not show empty page as these views are also used to edit the
69 // description selected in this view
72 else if(part
instanceof BulkEditor
&& selection
instanceof LineSelection
){
73 if(((LineSelection
) selection
).getFirstElement() instanceof Taxon
){
74 showViewer(part
, (LineSelection
) selection
);
81 else if(part
instanceof AbstractGraphKeyEditor
){
85 else if(part
instanceof MultiPageTaxonEditor
){
86 if(! part
.equals(this.part
)){
87 IEditorInput input
= ((IEditorPart
) part
).getEditorInput();
88 showViewer(part
, new StructuredSelection(input
));
98 protected String
createPartTitle(Object selectedObject
) {
99 if(selectedObject
instanceof TaxonEditorInput
){
100 return super.createPartTitle(((TaxonEditorInput
) selectedObject
).getTaxon());
102 return super.createPartTitle(selectedObject
);
106 public boolean onComplete() {
111 public Viewer
getViewer() {
116 public void createViewer(Composite parent
) {
117 viewer
= new ConceptRelationViewer(parent
);
119 viewer
.setContentProvider(new ConceptContentProvider());
120 viewer
.setLabelProvider(new ConceptLabelProvider());
123 viewer
.setSorter(new ViewerSorter());
125 getSite().setSelectionProvider(viewer
);
130 private void createMenu(){
131 MenuManager menuManager
= new MenuManager();
132 menuManager
.add(new GroupMarker(IWorkbenchActionConstants
.MB_ADDITIONS
));
134 getSite().registerContextMenu(menuManager
, viewer
);
136 Control control
= viewer
.getControl();
137 Menu menu
= menuManager
.createContextMenu(control
);
139 control
.setMenu(menu
);
143 public void changed(Object object
) {
144 getViewer().refresh();
145 super.changed(object
);
148 private class ConceptRelationViewer
extends ListViewer
{
150 public ConceptRelationViewer(Composite parent
) {
155 public ISelection
getSelection() {
156 ISelection selection
= super.getSelection();
157 if(selection
instanceof IStructuredSelection
&& !selection
.isEmpty()){
158 Object firstElement
= ((IStructuredSelection
) selection
).getFirstElement();
159 TaxonRelationship taxonRelationship
= ((Entry
<TaxonRelationship
, Taxon
>)firstElement
).getKey();
160 return new StructuredSelection(taxonRelationship
);
167 public void setSelection(ISelection selection
) {
168 super.setSelection(selection
);
174 protected String
getViewName() {
175 return Messages
.ConceptViewPart_VIEWER_NAME
;