Moving editor sources back into trunk
[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.ContextMenu;
22 import eu.etaxonomy.taxeditor.editor.EditorUtil;
23 import eu.etaxonomy.taxeditor.propertysheet.name.SynonymPropertySource;
24 import eu.etaxonomy.taxeditor.store.model.NameUtil;
25 import eu.etaxonomy.taxeditor.store.operations.ChangeHomotypicGroupOperation;
26 import eu.etaxonomy.taxeditor.store.operations.ChangeSynonymToMisapplicationOperation;
27
28 /**
29 * @author p.ciardelli
30 * @created 13.01.2009
31 * @version 1.0
32 */
33 public class SynonymComposite extends NameComposite {
34 @SuppressWarnings("unused")
35 private static final Logger logger = Logger
36 .getLogger(SynonymComposite.class);
37
38 private Synonym synonym;
39
40 public SynonymComposite(TaxonNameEditor editor, Composite parent, Synonym synonym) {
41 super(editor, parent, null, synonym);
42
43 this.taxon = editor.getTaxon();
44 this.synonym = synonym;
45
46 setIsDraggable(true);
47 setFont(getViewerFont());
48 setIndent(SYNONYM_INDENT);
49
50 if (isHomotypic()) {
51 if (NameUtil.isNameGroupBasionym(synonym.getName())) {
52 setIcon(HOMOTYPIC_SYNONYM_ORIGINAL_COMBINATION_ICON);
53 } else {
54 setIcon(HOMOTYPIC_SYNONYM_ICON);
55 }
56 } else {
57 if (NameUtil.isNameGroupBasionym(synonym.getName())) {
58 setIcon(HETEROTYPIC_SYNONYM_ORIGINAL_COMBINATION_ICON);
59 } else {
60 setIcon(HETEROTYPIC_SYNONYM_ICON);
61 }
62 }
63
64 initTextViewer(synonym);
65 }
66
67 private boolean isHomotypic() {
68 HomotypicalGroup group = synonym.getHomotypicGroup();
69 return group.equals(taxon.getHomotypicGroup());
70 }
71
72 public Synonym getSynonym() {
73 return synonym;
74 }
75
76 public boolean setParent(Composite parent) {
77
78 if (super.setParent(parent)) {
79
80 // Has this been moved to the misapplied names group?
81 if (parent instanceof MisappliedGroupComposite) {
82 IUndoableOperation operation = new ChangeSynonymToMisapplicationOperation
83 ("change to misapplication", editor.getUndoContext(), taxon, synonym, editor); //$NON-NLS-1$
84
85 EditorUtil.executeOperation(operation);
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 return true;
97 }
98
99 IUndoableOperation operation = new ChangeHomotypicGroupOperation
100 ("change type", editor.getUndoContext(), taxon, synonym, homotypicalGroup, editor); //$NON-NLS-1$
101
102 EditorUtil.executeOperation(operation);
103 }
104 return true;
105
106 }
107 return false;
108 }
109
110 public IPropertySource getPropertySource() {
111 if (NameUtil.isNameGroupBasionym(synonym.getName())) {
112 return new BasionymSynonymPropertySource(synonym);
113 } else {
114 return new SynonymPropertySource(synonym);
115 }
116 }
117
118 protected Font getViewerFont() {
119 return SYNONYM_FONT;
120 }
121
122 @Override
123 protected TaxonNameBase getName() {
124 return synonym.getName();
125 }
126
127 public Object getData () {
128 return getSynonym();
129 }
130 }