p2izing the editor
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / editor / name / ConceptComposite.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.jface.action.MenuManager;
14 import org.eclipse.swt.graphics.Font;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.ui.forms.IManagedForm;
17 import org.eclipse.ui.views.properties.IPropertySource;
18
19 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
20 import eu.etaxonomy.cdm.model.taxon.Taxon;
21 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
22 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
23 import eu.etaxonomy.taxeditor.actions.name.ChangeConceptRelationAction;
24 import eu.etaxonomy.taxeditor.actions.name.RemoveConceptAction;
25 import eu.etaxonomy.taxeditor.editor.ContextMenu;
26 import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository;
27 import eu.etaxonomy.taxeditor.propertysheet.name.TaxonBasePropertySource;
28
29 /**
30 * @author p.ciardelli
31 * @created 26.01.2009
32 * @version 1.0
33 */
34 public class ConceptComposite extends NameComposite {
35 private static final Logger logger = Logger
36 .getLogger(ConceptComposite.class);
37
38 private Taxon relatedTaxon;
39 private TaxonRelationshipType relationshipType;
40
41 /**
42 *
43 */
44 private boolean acceptedTaxonIsFromTaxon;
45
46 private ConceptComposite(Composite parent, IManagedForm form,
47 Taxon taxon, Taxon relatedTaxon, TaxonRelationshipType relationshipType,
48 boolean acceptedTaxonIsFromTaxon) {
49 super(parent, form, relatedTaxon);
50
51 this.taxon = taxon;
52 this.relatedTaxon = relatedTaxon;
53 this.relationshipType = relationshipType;
54 this.acceptedTaxonIsFromTaxon = acceptedTaxonIsFromTaxon;
55
56 setIsDraggable(true);
57 setIcon(CONCEPT_ICON);
58 setFont(getViewerFont());
59 setIndent(CONCEPT_INDENT);
60
61 createMenu();
62
63 showRelationshipType();
64 showSec();
65
66 initTextViewer(relatedTaxon);
67 }
68
69 private void showRelationshipType() {
70 setNonEditableInfo(relationshipType.getLabel());
71 }
72
73 private void showSec() {
74 if (relatedTaxon == null) {
75 return;
76 }
77
78 if (relatedTaxon.getSec() == null) {
79 setNonEditableInfo("sec. ???");
80 } else {
81 setNonEditableInfo("sec. " + relatedTaxon.getSec().getTitleCache());
82 }
83 }
84
85 public static ConceptComposite getNewInstance(Composite parent, IManagedForm form,
86 Taxon taxon, TaxonRelationship relationship){
87
88 TaxonRelationshipType relationshipType = relationship.getType();
89
90 if (relationship.getToTaxon() == null || relationship.getFromTaxon() == null) {
91 logger.warn("Could not create concept composite - related taxon is null");
92 return null;
93 }
94
95 if (relationship.getToTaxon().equals(taxon)) {
96 return new ConceptComposite (parent, form, taxon,
97 relationship.getFromTaxon(), relationshipType, false);
98 } else {
99 return new ConceptComposite (parent, form, taxon,
100 relationship.getToTaxon(), relationshipType, true);
101 }
102 }
103
104 private void createMenu() {
105 ContextMenu contextMenu = createContextMenu();
106
107 // Remove misapplied name from taxon
108 contextMenu.addAction(new RemoveConceptAction(taxon, relatedTaxon, relationshipType));
109 MenuManager subMenu = new MenuManager("Change relation type");
110 for (TaxonRelationshipType type : CdmSessionDataRepository.getDefault().getConceptRelationshipTypes()) {
111 subMenu.add(new ChangeConceptRelationAction(taxon, relatedTaxon, type));
112 }
113 contextMenu.addSubmenu(subMenu);
114 }
115
116
117 /* (non-Javadoc)
118 * @see eu.etaxonomy.taxeditor.editor.GroupedComposite#getViewerFont()
119 */
120 @Override
121 protected Font getViewerFont() {
122 return CONCEPT_FONT;
123 }
124
125 /* (non-Javadoc)
126 * @see eu.etaxonomy.taxeditor.editor.IHasPropertySource#getPropertySource()
127 */
128
129 public IPropertySource getPropertySource() {
130 return new TaxonBasePropertySource(relatedTaxon, "Concept Name");
131 }
132
133 public Taxon getRelatedTaxon() {
134 return relatedTaxon;
135 }
136
137 protected TaxonNameBase getName() {
138 return relatedTaxon.getName();
139 }
140
141 protected void calculateErrors() {
142 super.calculateErrors();
143
144 textViewer.setShowSecError(relatedTaxon);
145 }
146
147 public Object getData () {
148 return getRelatedTaxon();
149 }
150 }
151
152
153
154
155
156