Changed calls to retrieve term vocabularies to preferred term mechanism where applicable.
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / propertysheet / tabbed / NamePropertySection.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.propertysheet.tabbed;
12
13 import java.util.Properties;
14
15 import org.apache.log4j.Logger;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.custom.CCombo;
18 import org.eclipse.swt.custom.CLabel;
19 import org.eclipse.swt.events.ModifyEvent;
20 import org.eclipse.swt.events.ModifyListener;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Text;
24 import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
25
26 import eu.etaxonomy.cdm.common.CdmUtils;
27 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
28 import eu.etaxonomy.cdm.model.name.Rank;
29 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
30 import eu.etaxonomy.taxeditor.store.CdmStore;
31 import eu.etaxonomy.taxeditor.store.VocabularyStore;
32
33 /**
34 * @author n.hoffmann
35 * @created 05.06.2009
36 * @version 1.0
37 */
38 public class NamePropertySection extends AbstractNamePropertySection {
39 private static final Logger logger = Logger
40 .getLogger(NamePropertySection.class);
41
42
43 private CCombo rankCombo;
44
45 private Text uninomialText;
46 private Text infragenericEpithetText;
47 private Text specificEpithetText;
48 private Text infraSpecificEpithetText;
49 private Text appendedPhraseText;
50
51 private CCombo nomenclaturalStatusCombo;
52
53 protected ModifyListener listener = new ModifyListener() {
54
55 public void modifyText(ModifyEvent arg0) {
56 logger.warn("element modified");
57
58 // FIXME this is a workaround because cache do not get generated on change of underlying data
59 // remove once this is fixed in library
60 name.setAuthorshipCache(null,false);
61 name.setNameCache(null, false);
62 // workaround end
63
64
65
66 name.setGenusOrUninomial(uninomialText.getText());
67
68 // TODO refresh the editor
69 //EditorUtil.getActiveEditorPage(Page.NAME).setDirty();
70 //EditorUtil.getActiveEditorPage(Page.NAME).redraw(false);
71 groupedComposite.refresh();
72 }
73 };
74
75
76 @Override
77 public void createControls(Composite parent, TabbedPropertySheetPage editorPropertySheetPage){
78 super.createControls(parent, editorPropertySheetPage);
79 // super.createControls(parent, tabbedPropertySheetPage);
80
81 GridData textFieldLayout = new GridData(SWT.FILL, SWT.FILL, true, true);
82 GridData comboLayout = new GridData(SWT.FILL, SWT.FILL, true, false);
83
84 // rank
85 CLabel rankComboLabel = getWidgetFactory().createCLabel(composite, "Rank:");
86 rankCombo = getWidgetFactory().createCCombo(composite);
87 rankCombo.setLayoutData(comboLayout);
88
89 for (Rank rank : PreferencesUtil.getPreferredRanks()){
90 rankCombo.add(rank.getLabel(CdmStore.getDefaultLanguage()));
91 }
92
93 // uninomial
94 CLabel uninomialLabel = getWidgetFactory().createCLabel(composite, "Uninomial");
95 uninomialText = getWidgetFactory().createText(composite, "");
96 uninomialText.setLayoutData(textFieldLayout);
97
98 // infrageneric epithet
99 CLabel infragenericEpithetLabel = getWidgetFactory().createCLabel(composite, "Infrageneric Epithet");
100 infragenericEpithetText = getWidgetFactory().createText(composite, "");
101 infragenericEpithetText.setLayoutData(textFieldLayout);
102
103 // specific epithet
104 CLabel specificEpithetLabel = getWidgetFactory().createCLabel(composite, "Specific Epithet");
105 specificEpithetText = getWidgetFactory().createText(composite, "");
106 specificEpithetText.setLayoutData(textFieldLayout);
107
108 // infraspecific epithet
109 CLabel infraspecificEpithetLabel = getWidgetFactory().createCLabel(composite, "Infraspecific Epithet");
110 infraSpecificEpithetText = getWidgetFactory().createText(composite, "");
111 infraSpecificEpithetText.setLayoutData(textFieldLayout);
112
113 // appended phrase
114 CLabel appendedPhraseLabel = getWidgetFactory().createCLabel(composite, "Appended Phrase");
115 appendedPhraseText = getWidgetFactory().createText(composite, "");
116 appendedPhraseText.setLayoutData(textFieldLayout);
117
118 // nomenclatural status
119 CLabel nomenclaturalStatusLabel = getWidgetFactory().createCLabel(composite, "Nomenclatural Status", SWT.NO_BACKGROUND);
120 nomenclaturalStatusCombo = getWidgetFactory().createCCombo(composite);
121 nomenclaturalStatusCombo.setLayoutData(comboLayout);
122
123 for(NomenclaturalStatusType nomenclaturalStatusType : PreferencesUtil.getPreferredNomenclaturalStatusTypes()){
124 nomenclaturalStatusCombo.add(nomenclaturalStatusType.getLabel(CdmStore.getDefaultLanguage()));
125 }
126
127 }
128
129 /* (non-Javadoc)
130 * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#refresh()
131 */
132 @Override
133 public void refresh() {
134 super.refresh();
135
136 section.setText("Name");
137
138 cacheText.removeModifyListener(listener);
139 cacheText.setText(CdmUtils.Nz(name.getNameCache()));
140 cacheText.addModifyListener(listener);
141
142 editCacheButton.setSelection(name.isProtectedNameCache());
143
144 uninomialText.removeModifyListener(listener);
145 uninomialText.setText(CdmUtils.Nz(name.getGenusOrUninomial()));
146 uninomialText.addModifyListener(listener);
147
148 infragenericEpithetText.setText(CdmUtils.Nz(name.getInfraGenericEpithet()));
149 specificEpithetText.setText(CdmUtils.Nz(name.getSpecificEpithet()));
150 infraSpecificEpithetText.setText(CdmUtils.Nz(name.getInfraSpecificEpithet()));
151
152 appendedPhraseText.setText(CdmUtils.Nz(name.getAppendedPhrase()));
153
154 }
155
156 /* (non-Javadoc)
157 * @see eu.etaxonomy.taxeditor.propertysheet.tabbed.AbstractNamePropertySection#toggleCacheEditing()
158 */
159 @Override
160 protected void toggleCacheEditing() {
161 super.toggleCacheEditing();
162
163 if(name.isProtectedNameCache()){
164 name.setProtectedNameCache(false);
165 }else{
166 name.setProtectedNameCache(true);
167 }
168 }
169 }