3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.editor
.view
.concept
;
13 import java
.util
.Map
.Entry
;
15 import org
.eclipse
.jface
.action
.GroupMarker
;
16 import org
.eclipse
.jface
.action
.MenuManager
;
17 import org
.eclipse
.jface
.viewers
.ISelection
;
18 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
19 import org
.eclipse
.jface
.viewers
.ListViewer
;
20 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
21 import org
.eclipse
.jface
.viewers
.Viewer
;
22 import org
.eclipse
.jface
.viewers
.ViewerSorter
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.swt
.widgets
.Control
;
25 import org
.eclipse
.swt
.widgets
.Menu
;
26 import org
.eclipse
.ui
.IEditorInput
;
27 import org
.eclipse
.ui
.IEditorPart
;
28 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
29 import org
.eclipse
.ui
.IWorkbenchPart
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
33 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
34 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
35 import eu
.etaxonomy
.taxeditor
.editor
.key
.AbstractGraphKeyEditor
;
36 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
37 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
38 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
39 import eu
.etaxonomy
.taxeditor
.model
.LineSelection
;
40 import eu
.etaxonomy
.taxeditor
.view
.AbstractCdmEditorViewPart
;
44 * @created Jan 24, 2011
47 public class ConceptViewPart
extends AbstractCdmEditorViewPart
48 implements IPartContentHasDetails
, IPartContentHasSupplementalData
{
50 public static final String ID
= "eu.etaxonomy.taxeditor.editor.view.concept";
52 private ConceptRelationViewer viewer
;
55 protected void selectionChanged_internal(IWorkbenchPart part
, ISelection selection
) {
59 if(AbstractUtility
.getActiveEditor() == null){
64 if(part
instanceof BulkEditor
&& selection
instanceof LineSelection
){
65 if(((LineSelection
) selection
).getFirstElement() instanceof Taxon
){
66 showViewer(part
, (LineSelection
) selection
);
74 else if(part
instanceof AbstractGraphKeyEditor
){
79 else if(part
instanceof MultiPageTaxonEditor
){
80 if(! part
.equals(this.part
)){
81 IEditorInput input
= ((IEditorPart
) part
).getEditorInput();
82 showViewer(part
, new StructuredSelection(input
));
95 public boolean onComplete() {
100 public Viewer
getViewer() {
105 public void createViewer(Composite parent
) {
106 viewer
= new ConceptRelationViewer(parent
);
108 viewer
.setContentProvider(new ConceptContentProvider());
109 viewer
.setLabelProvider(new ConceptLabelProvider());
112 viewer
.setSorter(new ViewerSorter());
114 getSite().setSelectionProvider(viewer
);
119 private void createMenu(){
120 MenuManager menuManager
= new MenuManager();
121 menuManager
.add(new GroupMarker(IWorkbenchActionConstants
.MB_ADDITIONS
));
123 getSite().registerContextMenu(menuManager
, viewer
);
125 Control control
= viewer
.getControl();
126 Menu menu
= menuManager
.createContextMenu(control
);
128 control
.setMenu(menu
);
132 public void changed(Object object
) {
133 getViewer().refresh();
134 super.changed(object
);
137 private class ConceptRelationViewer
extends ListViewer
{
139 public ConceptRelationViewer(Composite parent
) {
144 public ISelection
getSelection() {
145 ISelection selection
= super.getSelection();
146 if(selection
instanceof IStructuredSelection
&& !selection
.isEmpty()){
147 Object firstElement
= ((IStructuredSelection
) selection
).getFirstElement();
148 TaxonRelationship taxonRelationship
= ((Entry
<TaxonRelationship
, Taxon
>)firstElement
).getKey();
149 return new StructuredSelection(taxonRelationship
);
156 public void setSelection(ISelection selection
) {
157 super.setSelection(selection
);