Project

General

Profile

Download (7.24 KB) Statistics
| Branch: | Tag: | Revision:
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.section.name.SynonymRelationshipDetailSection;
34
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
35

    
36
/**
37
 * <p>
38
 * TaxonBaseDetailElement class.
39
 * </p>
40
 *
41
 * @author n.hoffmann
42
 * @created Feb 26, 2010
43
 * @version 1.0
44
 */
45
public class TaxonBaseDetailElement extends AbstractIdentifiableEntityDetailElement<TaxonBase> {
46

    
47
	private CheckboxElement checkbox_doubtful;
48

    
49
	private CheckboxElement checkbox_useNameCache;
50

    
51
	private EntitySelectionElement<Reference> selection_secundum;
52

    
53
	private TextWithLabelElement text_secundum_microreference;
54

    
55
	private TextWithLabelElement text_appendedPhrase;
56

    
57
	private CheckboxElement checkbox_excluded;
58

    
59
	private CheckboxElement checkbox_unplaced;
60

    
61
	private CheckboxElement checkbox_published;
62

    
63
	private SynonymRelationshipDetailSection sectionSynonymRelationship;
64

    
65
	/**
66
	 * <p>
67
	 * Constructor for TaxonBaseDetailElement.
68
	 * </p>
69
	 *
70
	 * @param cdmFormFactory
71
	 *        a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
72
	 * @param formElement
73
	 *        a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
74
	 * @param style
75
	 *            a int.
76
	 */
77
	public TaxonBaseDetailElement(CdmFormFactory cdmFormFactory,
78
			ICdmFormElement formElement, int style) {
79
		super(cdmFormFactory, formElement);
80
	}
81

    
82
	/** {@inheritDoc} */
83
	@Override
84
	protected void createControls(ICdmFormElement formElement, TaxonBase entity, int style) {
85
			toggleable_cache = formFactory.createToggleableTextField(formElement,
86
					"Title Cache", entity.getTitleCache(),
87
					entity.isProtectedTitleCache(), style);
88

    
89
		//TODO RL
90
		boolean rl=true;
91
		if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
92
			toggleable_cache.setVisible(false);
93
		}
94
		if (!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
95
			text_appendedPhrase = formFactory.createTextWithLabelElement(
96
					formElement, "Appended Phrase", entity.getAppendedPhrase(),
97
					SWT.WRAP);
98
			//formFactory.createTextWithLabelElement(formElement, "Appended Phrase", nonViralName.getAppendedPhrase(), style);
99
		}
100

    
101
		selection_secundum = formFactory.createSelectionElement(Reference.class,
102
				getConversationHolder(), formElement, "Secundum",
103
				entity.getSec(), EntitySelectionElement.ALL,
104
				style);
105

    
106
		text_secundum_microreference = formFactory.createTextWithLabelElement(
107
                formElement, "Micro Reference",
108
               entity.getSecMicroReference(),null,
109
                SWT.WRAP);
110

    
111
		// TODO RL
112
		if (!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)) {
113
			checkbox_useNameCache = formFactory.createCheckbox(formElement,
114
					"Exclude Authorship", entity.isUseNameCache(), style);
115

    
116
			if (entity instanceof Taxon) {
117
				checkbox_excluded = formFactory.createCheckbox(formElement,
118
						"Taxon is excluded", ((Taxon) entity).isExcluded(), style);
119
				checkbox_unplaced = formFactory.createCheckbox(formElement,
120
						"Taxon is unplaced", ((Taxon) entity).isUnplaced(), style);
121
			}
122

    
123
			checkbox_doubtful = formFactory.createCheckbox(formElement,
124
					entity.getClass().getSimpleName() + " is doubtful", entity.isDoubtful(), style);
125
		}
126

    
127
		if (entity instanceof Taxon) {
128
			checkbox_published = formFactory.createCheckbox(formElement,
129
					"Taxon is published", ((Taxon) entity).isPublish(), style);
130
		}
131

    
132

    
133
		if(entity instanceof Synonym){
134
		    sectionSynonymRelationship = formFactory.createSynonymRelationshipDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
135
		    sectionSynonymRelationship.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
136
		    sectionSynonymRelationship.setEntity((Synonym) entity);
137
		}
138
	}
139

    
140
    private void updateCheckboxPublish() {
141
        if(getEntity() instanceof Taxon){
142
            checkbox_published.setEnabled(
143
            		CdmStore.currentAuthentiationHasOneOfRoles(Role.ROLE_PUBLISH, Role.ROLE_ADMIN)
144
            		);
145
        }
146
    }
147

    
148
	@Override
149
    protected void updateControlStates() {
150
        super.updateControlStates();
151
        updateCheckboxPublish();
152
    }
153

    
154
    /** {@inheritDoc} */
155
	@Override
156
	protected void updateContent() {
157
		super.updateContent();
158
		toggleable_cache.setEnabled(getEntity().isProtectedTitleCache());
159
		setIrrelevant(toggleable_cache.getState(),
160
				Arrays.asList(new Object[] { toggleable_cache, checkbox_published, checkbox_unplaced, checkbox_excluded }));
161
	}
162

    
163
	@Override
164
	protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
165
		String title = getEntity().generateTitle();
166
		getEntity().setTitleCache(title);
167
		super.handleTitleCacheRelevantChange(event);
168
	}
169

    
170
	/** {@inheritDoc} */
171
	@Override
172
	public void handleEvent(Object eventSource) {
173
		if (eventSource== toggleable_cache) {
174
			handleToggleableCacheField();
175
		} else if (eventSource == checkbox_doubtful) {
176
			getEntity().setDoubtful(checkbox_doubtful.getSelection());
177
		} else if (eventSource == checkbox_useNameCache) {
178
			getEntity().setUseNameCache(checkbox_useNameCache.getSelection());
179
		} else if (eventSource == selection_secundum) {
180
			getEntity().setSec(selection_secundum.getSelection());
181
		} else if (eventSource == text_appendedPhrase) {
182
			getEntity().setAppendedPhrase(text_appendedPhrase.getText());
183
		}else if (eventSource == text_secundum_microreference) {
184
            getEntity().setSecMicroReference(text_secundum_microreference.getText());
185
        }else if (eventSource == checkbox_excluded) {
186
			((Taxon) getEntity()).setExcluded(checkbox_excluded.getSelection());
187
		} else if (eventSource == checkbox_unplaced) {
188
		    ((Taxon) getEntity()).setUnplaced(checkbox_unplaced.getSelection());
189
		} else if (eventSource == checkbox_published) {
190
		    ((Taxon)getEntity()).setPublish(checkbox_published.getSelection());
191
		}
192
	}
193
	@Override
194
	protected void handleToggleableCacheField() {
195
        boolean pushedState = toggleable_cache.getState();
196

    
197
        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
198
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, checkbox_published, checkbox_unplaced, checkbox_excluded}));
199
        updateToggleableCacheField();
200
    }
201
}
(3-3/8)