.
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / MisappliedNameComposite.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.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;
16
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.taxeditor.editor.EditorUtil;
21 import eu.etaxonomy.taxeditor.operations.ChangeConceptToSynonymOperation;
22 import eu.etaxonomy.taxeditor.propertysheet.name.MisapplicationPropertySource;
23
24 /**
25 * @author p.ciardelli
26 * @created 13.01.2009
27 * @version 1.0
28 */
29 public class MisappliedNameComposite extends NameComposite {
30
31 private Taxon misappliedName;
32
33 public MisappliedNameComposite(TaxonNameEditor editor, Composite parent, Taxon misappliedName) {
34 super(editor, parent, NameComposite.MISAPPLIED_NAME, misappliedName);
35
36 this.taxon = editor.getTaxon();
37 this.misappliedName = misappliedName;
38
39 setIsDraggable(true);
40 setIcon(MISAPPLIEDNAME_ICON);
41 setFont(getViewerFont());
42 setIndent(MISAPPLIEDNAME_INDENT);
43
44 showSec();
45
46 initTextViewer(misappliedName);
47 }
48
49 private void showSec() {
50 if (misappliedName == null) {
51 return;
52 }
53
54 if (misappliedName.getSec() == null) {
55 setNonEditableInfo("sec. ???");
56 } else {
57 setNonEditableInfo("sec. " + misappliedName.getSec().getTitleCache());
58 }
59 }
60
61 public Taxon getMisappliedName() {
62 return misappliedName;
63 }
64
65 public boolean setParent(Composite parent) {
66
67 if (super.setParent(parent)) {
68
69 // If this has been moved to the misapplied names group, do nothing
70 if (parent instanceof MisappliedGroupComposite) {
71 return true;
72 }
73
74 // Has this been moved to a HomotypicalGroup?
75 if (parent instanceof HomotypicalGroupComposite) {
76
77 HomotypicalGroup homotypicalGroup =
78 ((HomotypicalGroupComposite)parent).getGroup();
79
80 IUndoableOperation operation = new ChangeConceptToSynonymOperation
81 ("change misapplication to synonym", editor.getUndoContext(), taxon, misappliedName, homotypicalGroup, editor);
82 EditorUtil.executeOperation(operation);
83 }
84 return true;
85
86 }
87 return false;
88 }
89
90 public IPropertySource getPropertySource() {
91 return new MisapplicationPropertySource(misappliedName);
92 }
93
94 @Override
95 protected Font getViewerFont() {
96 return MISAPPLIEDNAME_FONT;
97 }
98
99 protected void calculateErrors() {
100 super.calculateErrors();
101
102 textViewer.setShowSecError(misappliedName);
103 }
104
105 @Override
106 protected TaxonNameBase<?, ?> getName() {
107 return misappliedName.getName();
108 }
109
110 public Object getData () {
111 return getMisappliedName();
112 }
113 }