4bd08111cd95e62b8b12f671d326f8176f4cd8df
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / SynonymComposite.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.taxeditor.editor.name;
11
12 import org.apache.log4j.Logger;
13 import org.eclipse.core.commands.operations.IUndoableOperation;
14 import org.eclipse.swt.graphics.Font;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.ui.views.properties.IPropertySource;
17
18 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
19 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
20 import eu.etaxonomy.cdm.model.taxon.Synonym;
21 import eu.etaxonomy.taxeditor.editor.EditorUtil;
22 import eu.etaxonomy.taxeditor.model.NameUtil;
23 import eu.etaxonomy.taxeditor.operations.ChangeHomotypicGroupOperation;
24 import eu.etaxonomy.taxeditor.operations.ChangeSynonymToMisapplicationOperation;
25 import eu.etaxonomy.taxeditor.propertysheet.name.SynonymPropertySource;
26
27 /**
28 * @author p.ciardelli
29 * @created 13.01.2009
30 * @version 1.0
31 */
32 public class SynonymComposite extends NameComposite {
33 @SuppressWarnings("unused")
34 private static final Logger logger = Logger
35 .getLogger(SynonymComposite.class);
36
37 private Synonym synonym;
38
39 public SynonymComposite(TaxonNameEditor editor, Composite parent, Synonym synonym) {
40 super(editor, parent, null, synonym);
41
42 this.taxon = editor.getTaxon();
43 this.synonym = synonym;
44
45 setIsDraggable(true);
46 setFont(getViewerFont());
47 setIndent(SYNONYM_INDENT);
48
49 if (isHomotypic()) {
50 if (NameUtil.isNameGroupBasionym(synonym.getName())) {
51 setIcon(HOMOTYPIC_SYNONYM_ORIGINAL_COMBINATION_ICON);
52 } else {
53 setIcon(HOMOTYPIC_SYNONYM_ICON);
54 }
55 } else {
56 if (NameUtil.isNameGroupBasionym(synonym.getName())) {
57 setIcon(HETEROTYPIC_SYNONYM_ORIGINAL_COMBINATION_ICON);
58 } else {
59 setIcon(HETEROTYPIC_SYNONYM_ICON);
60 }
61 }
62
63 initTextViewer(synonym);
64 }
65
66 private boolean isHomotypic() {
67 HomotypicalGroup group = synonym.getHomotypicGroup();
68 return group.equals(taxon.getHomotypicGroup());
69 }
70
71 public Synonym getSynonym() {
72 return synonym;
73 }
74
75 public boolean setParent(Composite parent) {
76
77 boolean doSetParent = false;
78
79 // Has this been moved to the misapplied names group?
80 if (parent instanceof MisappliedGroupComposite) {
81 IUndoableOperation operation = new ChangeSynonymToMisapplicationOperation
82 ("change to misapplication", editor.getUndoContext(), taxon, synonym, editor); //$NON-NLS-1$
83 EditorUtil.executeOperation(operation);
84
85 doSetParent = true;
86 }
87
88 // Has this been moved to a HomotypicalGroup?
89 if (parent instanceof HomotypicalGroupComposite) {
90
91 HomotypicalGroup homotypicalGroup =
92 ((HomotypicalGroupComposite)parent).getGroup();
93
94 // Make sure we are not dropping synonym on its own group
95 if (!homotypicalGroup.equals(synonym.getHomotypicGroup())) {
96 IUndoableOperation operation = new ChangeHomotypicGroupOperation
97 ("change type", editor.getUndoContext(), taxon, synonym, homotypicalGroup, editor); //$NON-NLS-1$
98 EditorUtil.executeOperation(operation);
99
100 doSetParent = true;
101 }
102 }
103 return doSetParent;
104 }
105
106 public IPropertySource getPropertySource() {
107 if (NameUtil.isNameGroupBasionym(synonym.getName())) {
108 return new BasionymSynonymPropertySource(synonym);
109 } else {
110 return new SynonymPropertySource(synonym);
111 }
112 }
113
114 protected Font getViewerFont() {
115 return SYNONYM_FONT;
116 }
117
118 @Override
119 protected TaxonNameBase<?, ?> getName() {
120 return synonym.getName();
121 }
122
123 public Object getData () {
124 return getSynonym();
125 }
126 }