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