d4df27f25a62e4d63d77f8ebd1a872de40c22208
[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.propertysheet.name.SynonymPropertySource;
23 import eu.etaxonomy.taxeditor.store.model.NameUtil;
24 import eu.etaxonomy.taxeditor.store.operations.ChangeHomotypicGroupOperation;
25 import eu.etaxonomy.taxeditor.store.operations.ChangeSynonymToMisapplicationOperation;
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 if (super.setParent(parent)) {
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
84 EditorUtil.executeOperation(operation);
85 }
86
87 // Has this been moved to a HomotypicalGroup?
88 if (parent instanceof HomotypicalGroupComposite) {
89
90 HomotypicalGroup homotypicalGroup =
91 ((HomotypicalGroupComposite)parent).getGroup();
92
93 // Make sure we are not dropping synonym on its own group
94 if (homotypicalGroup.equals(synonym.getHomotypicGroup())) {
95 return true;
96 }
97
98 IUndoableOperation operation = new ChangeHomotypicGroupOperation
99 ("change type", editor.getUndoContext(), taxon, synonym, homotypicalGroup, editor); //$NON-NLS-1$
100
101 EditorUtil.executeOperation(operation);
102 }
103 return true;
104
105 }
106 return false;
107 }
108
109 public IPropertySource getPropertySource() {
110 if (NameUtil.isNameGroupBasionym(synonym.getName())) {
111 return new BasionymSynonymPropertySource(synonym);
112 } else {
113 return new SynonymPropertySource(synonym);
114 }
115 }
116
117 protected Font getViewerFont() {
118 return SYNONYM_FONT;
119 }
120
121 @Override
122 protected TaxonNameBase getName() {
123 return synonym.getName();
124 }
125
126 public Object getData () {
127 return getSynonym();
128 }
129 }