5c82a784a488635ffb99d4155e161a522b769fcd
[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 boolean doSetParent = false;
68
69 // Has this been moved to a HomotypicalGroup?
70 if (parent instanceof HomotypicalGroupComposite) {
71
72 HomotypicalGroup homotypicalGroup =
73 ((HomotypicalGroupComposite)parent).getGroup();
74
75 IUndoableOperation operation = new ChangeConceptToSynonymOperation
76 ("change misapplication to synonym", editor.getUndoContext(), taxon, misappliedName, homotypicalGroup, editor);
77 EditorUtil.executeOperation(operation);
78
79 doSetParent = true;
80 }
81 return doSetParent;
82 }
83
84 public IPropertySource getPropertySource() {
85 return new MisapplicationPropertySource(misappliedName);
86 }
87
88 @Override
89 protected Font getViewerFont() {
90 return MISAPPLIEDNAME_FONT;
91 }
92
93 protected void calculateErrors() {
94 super.calculateErrors();
95
96 textViewer.setShowSecError(misappliedName);
97 }
98
99 @Override
100 protected TaxonNameBase<?, ?> getName() {
101 return misappliedName.getName();
102 }
103
104 public Object getData () {
105 return getMisappliedName();
106 }
107 }