fix #4461 fix ordering for Datasource View
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / taxon / TaxonBaseDetailElement.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.ui.section.taxon;
12
13 import java.util.Arrays;
14
15 import org.eclipse.jface.util.PropertyChangeEvent;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.ui.forms.widgets.ExpandableComposite;
18
19 import eu.etaxonomy.cdm.model.reference.Reference;
20 import eu.etaxonomy.cdm.model.taxon.Synonym;
21 import eu.etaxonomy.cdm.model.taxon.Taxon;
22 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
23 import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
24 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
25 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
26 import eu.etaxonomy.taxeditor.store.CdmStore;
27 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
28 import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
29 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
30 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
31 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
32 import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
33 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
34
35 /**
36 * <p>
37 * TaxonBaseDetailElement class.
38 * </p>
39 *
40 * @author n.hoffmann
41 * @created Feb 26, 2010
42 * @version 1.0
43 */
44 public class TaxonBaseDetailElement extends AbstractIdentifiableEntityDetailElement<TaxonBase> {
45
46 private CheckboxElement checkbox_doubtful;
47
48 private CheckboxElement checkbox_useNameCache;
49
50 private EntitySelectionElement<Reference> selection_secundum;
51
52 private TextWithLabelElement text_secundum_microreference;
53
54 private TextWithLabelElement text_appendedPhrase;
55
56 private CheckboxElement checkbox_excluded;
57
58 private CheckboxElement checkbox_unplaced;
59
60 private CheckboxElement checkbox_published;
61
62 // private SynonymRelationshipDetailSection sectionSynonymRelationship;
63
64 /**
65 * <p>
66 * Constructor for TaxonBaseDetailElement.
67 * </p>
68 *
69 * @param cdmFormFactory
70 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
71 * @param formElement
72 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
73 * @param style
74 * a int.
75 */
76 public TaxonBaseDetailElement(CdmFormFactory cdmFormFactory,
77 ICdmFormElement formElement, int style) {
78 super(cdmFormFactory, formElement);
79 }
80
81 /** {@inheritDoc} */
82 @Override
83 protected void createControls(ICdmFormElement formElement, TaxonBase entity, int style) {
84 toggleable_cache = formFactory.createToggleableTextField(formElement,
85 "Title Cache", entity.getTitleCache(),
86 entity.isProtectedTitleCache(), style);
87
88 //TODO RL
89 boolean rl=true;
90 if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
91 toggleable_cache.setVisible(false);
92 }
93 if (!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
94 text_appendedPhrase = formFactory.createTextWithLabelElement(
95 formElement, "Appended Phrase", entity.getAppendedPhrase(),
96 SWT.WRAP);
97
98 }
99
100 selection_secundum = formFactory.createSelectionElement(Reference.class,
101 getConversationHolder(), formElement, "Secundum",
102 entity.getSec(), EntitySelectionElement.ALL,
103 style);
104
105 text_secundum_microreference = formFactory.createTextWithLabelElement(
106 formElement, "Detail",
107 entity.getSecMicroReference(),null,
108 SWT.WRAP);
109
110 // TODO RL
111 if (!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)) {
112 checkbox_useNameCache = formFactory.createCheckbox(formElement,
113 "Exclude Authorship", entity.isUseNameCache(), style);
114
115 if (entity instanceof Taxon) {
116 checkbox_excluded = formFactory.createCheckbox(formElement,
117 "Taxon is excluded", ((Taxon) entity).isExcluded(), style);
118 checkbox_unplaced = formFactory.createCheckbox(formElement,
119 "Taxon is unplaced", ((Taxon) entity).isUnplaced(), style);
120 }
121
122 checkbox_doubtful = formFactory.createCheckbox(formElement,
123 entity.getClass().getSimpleName() + " is doubtful", entity.isDoubtful(), style);
124 }
125
126 if (entity instanceof Taxon) {
127 checkbox_published = formFactory.createCheckbox(formElement,
128 "Taxon is published", ((Taxon) entity).isPublish(), style);
129 }
130
131
132 // if(entity instanceof Synonym){
133 // sectionSynonymRelationship = formFactory.createSynonymRelationshipDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
134 // sectionSynonymRelationship.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
135 // sectionSynonymRelationship.setEntity((Synonym) entity);
136 // }
137 }
138
139 private void updateCheckboxPublish() {
140 if(getEntity() instanceof Taxon){
141 checkbox_published.setEnabled(
142 CdmStore.currentAuthentiationHasOneOfRoles(Role.ROLE_PUBLISH, Role.ROLE_ADMIN)
143 );
144 }
145 }
146
147 @Override
148 protected void updateControlStates() {
149 super.updateControlStates();
150 updateCheckboxPublish();
151 }
152
153 /** {@inheritDoc} */
154 @Override
155 protected void updateContent() {
156 super.updateContent();
157 toggleable_cache.setEnabled(getEntity().isProtectedTitleCache());
158 setIrrelevant(toggleable_cache.getState(),
159 Arrays.asList(new Object[] { toggleable_cache, checkbox_published, checkbox_unplaced, checkbox_excluded }));
160 }
161
162 @Override
163 protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
164 String title = getEntity().generateTitle();
165 getEntity().setTitleCache(title);
166 super.handleTitleCacheRelevantChange(event);
167 }
168
169 /** {@inheritDoc} */
170 @Override
171 public void handleEvent(Object eventSource) {
172 if (eventSource== toggleable_cache) {
173 handleToggleableCacheField();
174 } else if (eventSource == checkbox_doubtful) {
175 getEntity().setDoubtful(checkbox_doubtful.getSelection());
176 } else if (eventSource == checkbox_useNameCache) {
177 getEntity().setUseNameCache(checkbox_useNameCache.getSelection());
178 } else if (eventSource == selection_secundum) {
179 getEntity().setSec(selection_secundum.getSelection());
180 } else if (eventSource == text_appendedPhrase) {
181 getEntity().setAppendedPhrase(text_appendedPhrase.getText());
182 }else if (eventSource == text_secundum_microreference) {
183 getEntity().setSecMicroReference(text_secundum_microreference.getText());
184 }else if (eventSource == checkbox_excluded) {
185 ((Taxon) getEntity()).setExcluded(checkbox_excluded.getSelection());
186 } else if (eventSource == checkbox_unplaced) {
187 ((Taxon) getEntity()).setUnplaced(checkbox_unplaced.getSelection());
188 } else if (eventSource == checkbox_published) {
189 ((Taxon)getEntity()).setPublish(checkbox_published.getSelection());
190 }
191 }
192 @Override
193 protected void handleToggleableCacheField() {
194 boolean pushedState = toggleable_cache.getState();
195
196 getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
197 setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, checkbox_published, checkbox_unplaced, checkbox_excluded}));
198 updateToggleableCacheField();
199 }
200 }