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
.eclipse
.core
.commands
.operations
.IUndoableOperation
;
13 import org
.eclipse
.swt
.graphics
.Font
;
14 import org
.eclipse
.swt
.widgets
.Composite
;
15 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
17 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
18 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
22 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
23 import eu
.etaxonomy
.taxeditor
.operations
.ChangeConceptRelationshipTypeOperation
;
24 import eu
.etaxonomy
.taxeditor
.operations
.ChangeConceptToSynonymOperation
;
25 import eu
.etaxonomy
.taxeditor
.propertysheet
.name
.ConceptPropertySource
;
32 public class ConceptComposite
extends NameComposite
<Taxon
> {
34 private Taxon relatedTaxon
;
35 private TaxonRelationshipType relationshipType
;
40 private boolean acceptedTaxonIsFromTaxon
;
42 private ConceptComposite(TaxonNameEditor editor
, Composite parent
,
43 Taxon relatedTaxon
, TaxonRelationshipType relationshipType
,
44 boolean acceptedTaxonIsFromTaxon
) {
45 super(editor
, parent
, relatedTaxon
);
47 this.relatedTaxon
= relatedTaxon
;
48 this.relationshipType
= relationshipType
;
49 this.setAcceptedTaxonIsFromTaxon(acceptedTaxonIsFromTaxon
);
51 initializeComposite();
55 * @see eu.etaxonomy.taxeditor.editor.name.NameComposite#initializeComposite()
58 protected void initializeComposite() {
61 setIcon(CONCEPT_ICON
);
62 setFont(getViewerFont());
63 setIndent(CONCEPT_INDENT
);
65 showRelationshipType();
68 initTextViewer(relatedTaxon
);
71 private void showRelationshipType() {
72 setNonEditableInfo(relationshipType
.getLabel());
75 private void showSec() {
76 if (relatedTaxon
== null) {
80 if (relatedTaxon
.getSec() == null) {
81 setNonEditableInfo("sec. ???");
83 setNonEditableInfo("sec. " + relatedTaxon
.getSec().getTitleCache());
87 public static ConceptComposite
getNewInstance(TaxonNameEditor editor
, Composite parent
, TaxonRelationship relationship
){
89 TaxonRelationshipType relationshipType
= relationship
.getType();
91 if (relationship
.getToTaxon().equals(editor
.getTaxon())) {
92 return new ConceptComposite (editor
, parent
,
93 relationship
.getFromTaxon(), relationshipType
, false);
95 return new ConceptComposite (editor
, parent
,
96 relationship
.getToTaxon(), relationshipType
, true);
101 * @see eu.etaxonomy.taxeditor.editor.GroupedComposite#getViewerFont()
104 protected Font
getViewerFont() {
109 * @see eu.etaxonomy.taxeditor.editor.IHasPropertySource#getPropertySource()
112 public IPropertySource
getPropertySource() {
113 return new ConceptPropertySource(relatedTaxon
);
116 public Taxon
getRelatedTaxon() {
120 protected TaxonNameBase
<?
, ?
> getName() {
121 return relatedTaxon
.getName();
124 protected void calculateErrors() {
125 super.calculateErrors();
127 textViewer
.setShowSecError(relatedTaxon
);
130 public Object
getData () {
131 return getRelatedTaxon();
135 * @param acceptedTaxonIsFromTaxon the acceptedTaxonIsFromTaxon to set
137 public void setAcceptedTaxonIsFromTaxon(boolean acceptedTaxonIsFromTaxon
) {
138 this.acceptedTaxonIsFromTaxon
= acceptedTaxonIsFromTaxon
;
142 * @return the acceptedTaxonIsFromTaxon
144 public boolean isAcceptedTaxonIsFromTaxon() {
145 return acceptedTaxonIsFromTaxon
;
148 public boolean setParent(Composite parent
) {
149 boolean doSetParent
= false;
151 if (parent
instanceof MisappliedGroupComposite
) {
152 IUndoableOperation operation
= new ChangeConceptRelationshipTypeOperation("change to misapplication",
153 editor
.getUndoContext(), taxon
, relatedTaxon
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR(), editor
); //$NON-NLS-1$
154 EditorUtil
.executeOperation(operation
);
159 if (parent
instanceof HomotypicalGroupComposite
) {
160 HomotypicalGroup homotypicalGroup
=
161 ((HomotypicalGroupComposite
)parent
).getGroup();
162 IUndoableOperation operation
= new ChangeConceptToSynonymOperation
163 ("change concept to synonym", editor
.getUndoContext(), taxon
, relatedTaxon
, homotypicalGroup
, editor
);
164 EditorUtil
.executeOperation(operation
);