Project

General

Profile

Download (6.72 KB) Statistics
| Branch: | Tag: | Revision:
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.ui.section.taxon;
11

    
12
import java.util.Arrays;
13

    
14
import org.eclipse.jface.util.PropertyChangeEvent;
15
import org.eclipse.swt.SWT;
16

    
17
import eu.etaxonomy.cdm.model.reference.Reference;
18
import eu.etaxonomy.cdm.model.taxon.Synonym;
19
import eu.etaxonomy.cdm.model.taxon.SynonymType;
20
import eu.etaxonomy.cdm.model.taxon.Taxon;
21
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
22
import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
23
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
24
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
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.TextWithLabelElement;
31
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
32
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
33

    
34
/**
35
 * @author n.hoffmann
36
 * @created Feb 26, 2010
37
 * @version 1.0
38
 */
39
public class TaxonBaseDetailElement extends AbstractIdentifiableEntityDetailElement<TaxonBase> {
40

    
41
	private CheckboxElement checkbox_doubtful;
42

    
43
	private CheckboxElement checkbox_useNameCache;
44

    
45
	private EntitySelectionElement<Reference> selection_secundum;
46
	private EntitySelectionElement<Reference> selection_sensu;
47
	private TextWithLabelElement text_secundum_microreference;
48

    
49
	private TextWithLabelElement text_appendedPhrase;
50

    
51
	private CheckboxElement checkbox_published;
52

    
53
    private TermComboElement<SynonymType> combo_relationshipType;
54
    private CheckboxElement checkProParte;
55
    private CheckboxElement checkPartial;
56

    
57
	public TaxonBaseDetailElement(CdmFormFactory cdmFormFactory,
58
			ICdmFormElement formElement, int style) {
59
		super(cdmFormFactory, formElement);
60
	}
61

    
62
	/** {@inheritDoc} */
63
	@Override
64
	protected void createControls(ICdmFormElement formElement, TaxonBase entity, int style) {
65

    
66
		toggleable_cache = formFactory.createToggleableTextField(formElement,
67
					"Title Cache", entity.getTitleCache(),
68
					entity.isProtectedTitleCache(), style);
69

    
70

    
71
		text_appendedPhrase = formFactory.createTextWithLabelElement(
72
					formElement, "Appended Phrase", entity.getAppendedPhrase(),
73
					SWT.WRAP);
74

    
75

    
76

    
77
		selection_secundum = formFactory.createSelectionElement(Reference.class,//getConversationHolder(),
78
				 formElement, "Secundum",
79
				entity.getSec(), EntitySelectionElement.ALL,
80
				style);
81
		if (!PreferencesUtil.getBooleanValue(IPreferenceKeys.DISABLE_SEC)){
82
		    selection_secundum.setEnabled(false);
83
		}
84
		if (PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_SEC_DETAILS)){
85
    		text_secundum_microreference = formFactory.createTextWithLabelElement(
86
                    formElement, "Detail",
87
                   entity.getSecMicroReference(),null,
88
                    SWT.WRAP);
89
		}
90

    
91
		checkbox_useNameCache = formFactory.createCheckbox(formElement,
92
					"Exclude Authorship", entity.isUseNameCache(), style);
93
		checkbox_doubtful = formFactory.createCheckbox(formElement,
94
					entity.getClass().getSimpleName() + " is doubtful", entity.isDoubtful(), style);
95

    
96

    
97

    
98
		checkbox_published = formFactory.createCheckbox(formElement,
99
		        entity.getClass().getSimpleName()+" is published", entity.isPublish(), style);
100

    
101

    
102
		if(entity instanceof Synonym){
103
		    //#6198 removed type as it is currently not handled correctly in the editor
104
//		    combo_relationshipType = formFactory.createDefinedTermComboElement(TermType.SynonymType, formElement, "Synonym Type", ((Synonym) entity).getType(), style);
105
			//#7334 removed pro parte and partial as they are handled as concept relationships now
106
//	        checkProParte = formFactory.createCheckbox(formElement, "Pro Parte Synonym", ((Synonym) entity).isProParte(), style);
107
//	        checkPartial= formFactory.createCheckbox(formElement, "Partial Synonym", ((Synonym) entity).isPartial(), style);
108
		}
109
	}
110

    
111
    private void updateCheckboxPublish() {
112
        if(getEntity() instanceof Taxon){
113
            checkbox_published.setEnabled(
114
            		CdmStore.currentAuthentiationHasOneOfRoles(Role.ROLE_PUBLISH, Role.ROLE_ADMIN)
115
            		);
116
        }
117
    }
118

    
119
	@Override
120
    protected void updateControlStates() {
121
        super.updateControlStates();
122
        updateCheckboxPublish();
123
    }
124

    
125
    /** {@inheritDoc} */
126
	@Override
127
	protected void updateContent() {
128
		super.updateContent();
129
		toggleable_cache.setEnabled(getEntity().isProtectedTitleCache());
130
		setIrrelevant(toggleable_cache.getState(),
131
				Arrays.asList(new Object[] { toggleable_cache, checkbox_published}));
132
	}
133

    
134
	@Override
135
	protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
136
		String title = getEntity().generateTitle();
137
		getEntity().setTitleCache(title);
138
		super.handleTitleCacheRelevantChange(event);
139
	}
140

    
141
	/** {@inheritDoc} */
142
	@Override
143
	public void handleEvent(Object eventSource) {
144
		if (eventSource== toggleable_cache) {
145
			handleToggleableCacheField();
146
		} else if (eventSource == checkbox_doubtful) {
147
			getEntity().setDoubtful(checkbox_doubtful.getSelection());
148
		} else if (eventSource == checkbox_useNameCache) {
149
			getEntity().setUseNameCache(checkbox_useNameCache.getSelection());
150
		} else if (eventSource == selection_secundum) {
151
			getEntity().setSec(selection_secundum.getSelection());
152
		} else if (eventSource == text_appendedPhrase) {
153
			getEntity().setAppendedPhrase(text_appendedPhrase.getText());
154
		} else if (eventSource == text_secundum_microreference) {
155
            getEntity().setSecMicroReference(text_secundum_microreference.getText());
156
		} else if (eventSource == checkbox_published) {
157
		    getEntity().setPublish(checkbox_published.getSelection());
158
		} else if(eventSource == combo_relationshipType){
159
            ((Synonym) getEntity()).setType(combo_relationshipType.getSelection());
160
		//#7334/5 removed pro parte and partial as they are handled as concept relationships now
161
//        } else if(eventSource == checkPartial){
162
//            ((Synonym) getEntity()).setPartial(checkPartial.getSelection());
163
//        } else if(eventSource == checkProParte){
164
//            ((Synonym) getEntity()).setProParte(checkProParte.getSelection());
165
        }
166
	}
167
	@Override
168
	protected void handleToggleableCacheField() {
169
        boolean pushedState = toggleable_cache.getState();
170

    
171
        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
172
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, checkbox_published}));
173
        updateToggleableCacheField();
174
    }
175
}
(3-3/10)