fixes #888 and #889
[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<Taxon> {
30
31 public MisappliedNameComposite(TaxonNameEditor editor, Composite parent, Taxon misappliedName) {
32 super(editor, parent, misappliedName);
33
34 initializeComposite();
35 }
36
37
38 /* (non-Javadoc)
39 * @see eu.etaxonomy.taxeditor.editor.name.NameComposite#initializeComposite()
40 */
41 @Override
42 protected void initializeComposite() {
43 setIsDraggable(true);
44 setIcon(MISAPPLIEDNAME_ICON);
45 setFont(getViewerFont());
46 setIndent(MISAPPLIEDNAME_INDENT);
47
48 showSec();
49
50 initTextViewer(getMisappliedName());
51 }
52
53 private void showSec() {
54 if (getMisappliedName() == null) {
55 return;
56 }
57
58 if (getMisappliedName().getSec() == null) {
59 setNonEditableInfo("sec. ???");
60 } else {
61 setNonEditableInfo("sec. " + getMisappliedName().getSec().getTitleCache());
62 }
63 }
64
65 public Taxon getMisappliedName() {
66 return getTaxonBase();
67 }
68
69 public boolean setParent(Composite parent) {
70
71 boolean doSetParent = false;
72
73 // Has this been moved to a HomotypicalGroup?
74 if (parent instanceof HomotypicalGroupComposite) {
75
76 HomotypicalGroup homotypicalGroup =
77 ((HomotypicalGroupComposite)parent).getGroup();
78
79 IUndoableOperation operation = new ChangeConceptToSynonymOperation
80 ("change misapplication to synonym", editor.getUndoContext(), taxon, getMisappliedName(), homotypicalGroup, editor);
81 EditorUtil.executeOperation(operation);
82
83 doSetParent = true;
84 }
85 return doSetParent;
86 }
87
88 public IPropertySource getPropertySource() {
89 return new MisapplicationPropertySource(getMisappliedName());
90 }
91
92 @Override
93 protected Font getViewerFont() {
94 return MISAPPLIEDNAME_FONT;
95 }
96
97 protected void calculateErrors() {
98 super.calculateErrors();
99
100 textViewer.setShowSecError(getMisappliedName());
101 }
102
103 @Override
104 protected TaxonNameBase<?, ?> getName() {
105 return getMisappliedName().getName();
106 }
107
108 public Object getData () {
109 return getMisappliedName();
110 }
111
112 }