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
.name
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.jface
.action
.MenuManager
;
14 import org
.eclipse
.swt
.graphics
.Font
;
15 import org
.eclipse
.swt
.widgets
.Composite
;
16 import org
.eclipse
.ui
.forms
.IManagedForm
;
17 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
19 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
23 import eu
.etaxonomy
.taxeditor
.actions
.name
.ChangeConceptRelationAction
;
24 import eu
.etaxonomy
.taxeditor
.actions
.name
.RemoveConceptAction
;
25 import eu
.etaxonomy
.taxeditor
.editor
.ContextMenu
;
26 import eu
.etaxonomy
.taxeditor
.model
.CdmSessionDataRepository
;
27 import eu
.etaxonomy
.taxeditor
.propertysheet
.name
.TaxonBasePropertySource
;
34 public class ConceptComposite
extends NameComposite
{
35 private static final Logger logger
= Logger
36 .getLogger(ConceptComposite
.class);
38 private Taxon relatedTaxon
;
39 private TaxonRelationshipType relationshipType
;
44 private boolean acceptedTaxonIsFromTaxon
;
46 private ConceptComposite(Composite parent
, IManagedForm form
,
47 Taxon taxon
, Taxon relatedTaxon
, TaxonRelationshipType relationshipType
,
48 boolean acceptedTaxonIsFromTaxon
) {
49 super(parent
, form
, relatedTaxon
);
52 this.relatedTaxon
= relatedTaxon
;
53 this.relationshipType
= relationshipType
;
54 this.acceptedTaxonIsFromTaxon
= acceptedTaxonIsFromTaxon
;
57 setIcon(CONCEPT_ICON
);
58 setFont(getViewerFont());
59 setIndent(CONCEPT_INDENT
);
63 showRelationshipType();
66 initTextViewer(relatedTaxon
);
69 private void showRelationshipType() {
70 setNonEditableInfo(relationshipType
.getLabel());
73 private void showSec() {
74 if (relatedTaxon
== null) {
78 if (relatedTaxon
.getSec() == null) {
79 setNonEditableInfo("sec. ???");
81 setNonEditableInfo("sec. " + relatedTaxon
.getSec().getTitleCache());
85 public static ConceptComposite
getNewInstance(Composite parent
, IManagedForm form
,
86 Taxon taxon
, TaxonRelationship relationship
){
88 TaxonRelationshipType relationshipType
= relationship
.getType();
90 if (relationship
.getToTaxon() == null || relationship
.getFromTaxon() == null) {
91 logger
.warn("Could not create concept composite - related taxon is null");
95 if (relationship
.getToTaxon().equals(taxon
)) {
96 return new ConceptComposite (parent
, form
, taxon
,
97 relationship
.getFromTaxon(), relationshipType
, false);
99 return new ConceptComposite (parent
, form
, taxon
,
100 relationship
.getToTaxon(), relationshipType
, true);
104 private void createMenu() {
105 ContextMenu contextMenu
= createContextMenu();
107 // Remove misapplied name from taxon
108 contextMenu
.addAction(new RemoveConceptAction(taxon
, relatedTaxon
, relationshipType
));
109 MenuManager subMenu
= new MenuManager("Change relation type");
110 for (TaxonRelationshipType type
: CdmSessionDataRepository
.getDefault().getConceptRelationshipTypes()) {
111 subMenu
.add(new ChangeConceptRelationAction(taxon
, relatedTaxon
, type
));
113 contextMenu
.addSubmenu(subMenu
);
118 * @see eu.etaxonomy.taxeditor.editor.GroupedComposite#getViewerFont()
121 protected Font
getViewerFont() {
126 * @see eu.etaxonomy.taxeditor.editor.IHasPropertySource#getPropertySource()
129 public IPropertySource
getPropertySource() {
130 return new TaxonBasePropertySource(relatedTaxon
, "Concept Name");
133 public Taxon
getRelatedTaxon() {
137 protected TaxonNameBase
getName() {
138 return relatedTaxon
.getName();
141 protected void calculateErrors() {
142 super.calculateErrors();
144 textViewer
.setShowSecError(relatedTaxon
);
147 public Object
getData () {
148 return getRelatedTaxon();