Project

General

Profile

Download (6.22 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.store.CdmStore;
24
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
25
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
26
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
27
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
28
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
29
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
30
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
31

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

    
39
	private CheckboxElement checkbox_doubtful;
40

    
41
	private CheckboxElement checkbox_useNameCache;
42

    
43
	private EntitySelectionElement<Reference> selection_secundum;
44
	private EntitySelectionElement<Reference> selection_sensu;
45
	private TextWithLabelElement text_secundum_microreference;
46

    
47
	private TextWithLabelElement text_appendedPhrase;
48

    
49
	private CheckboxElement checkbox_published;
50

    
51
    private TermComboElement<SynonymType> combo_relationshipType;
52
    private CheckboxElement checkProParte;
53
    private CheckboxElement checkPartial;
54

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

    
60
	/** {@inheritDoc} */
61
	@Override
62
	protected void createControls(ICdmFormElement formElement, TaxonBase entity, int style) {
63
			toggleable_cache = formFactory.createToggleableTextField(formElement,
64
					"Title Cache", entity.getTitleCache(),
65
					entity.isProtectedTitleCache(), style);
66

    
67

    
68
		text_appendedPhrase = formFactory.createTextWithLabelElement(
69
					formElement, "Appended Phrase", entity.getAppendedPhrase(),
70
					SWT.WRAP);
71

    
72

    
73

    
74
		selection_secundum = formFactory.createSelectionElement(Reference.class,//getConversationHolder(),
75
				 formElement, "Secundum",
76
				entity.getSec(), EntitySelectionElement.ALL,
77
				style);
78

    
79
		text_secundum_microreference = formFactory.createTextWithLabelElement(
80
                formElement, "Detail",
81
               entity.getSecMicroReference(),null,
82
                SWT.WRAP);
83

    
84

    
85
		checkbox_useNameCache = formFactory.createCheckbox(formElement,
86
					"Exclude Authorship", entity.isUseNameCache(), style);
87
		checkbox_doubtful = formFactory.createCheckbox(formElement,
88
					entity.getClass().getSimpleName() + " is doubtful", entity.isDoubtful(), style);
89

    
90

    
91

    
92
		checkbox_published = formFactory.createCheckbox(formElement,
93
		        entity.getClass().getSimpleName()+" is published", entity.isPublish(), style);
94

    
95

    
96
		if(entity instanceof Synonym){
97
		    //#6198 removed type as it is currently not handled correctly in the editor
98
//		    combo_relationshipType = formFactory.createDefinedTermComboElement(TermType.SynonymType, formElement, "Synonym Type", ((Synonym) entity).getType(), style);
99
	        checkProParte = formFactory.createCheckbox(formElement, "Pro Parte Synonym", ((Synonym) entity).isProParte(), style);
100
	        checkPartial= formFactory.createCheckbox(formElement, "Partial Synonym", ((Synonym) entity).isPartial(), style);
101
		}
102
	}
103

    
104
    private void updateCheckboxPublish() {
105
        if(getEntity() instanceof Taxon){
106
            checkbox_published.setEnabled(
107
            		CdmStore.currentAuthentiationHasOneOfRoles(Role.ROLE_PUBLISH, Role.ROLE_ADMIN)
108
            		);
109
        }
110
    }
111

    
112
	@Override
113
    protected void updateControlStates() {
114
        super.updateControlStates();
115
        updateCheckboxPublish();
116
    }
117

    
118
    /** {@inheritDoc} */
119
	@Override
120
	protected void updateContent() {
121
		super.updateContent();
122
		toggleable_cache.setEnabled(getEntity().isProtectedTitleCache());
123
		setIrrelevant(toggleable_cache.getState(),
124
				Arrays.asList(new Object[] { toggleable_cache, checkbox_published}));
125
	}
126

    
127
	@Override
128
	protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
129
		String title = getEntity().generateTitle();
130
		getEntity().setTitleCache(title);
131
		super.handleTitleCacheRelevantChange(event);
132
	}
133

    
134
	/** {@inheritDoc} */
135
	@Override
136
	public void handleEvent(Object eventSource) {
137
		if (eventSource== toggleable_cache) {
138
			handleToggleableCacheField();
139
		} else if (eventSource == checkbox_doubtful) {
140
			getEntity().setDoubtful(checkbox_doubtful.getSelection());
141
		} else if (eventSource == checkbox_useNameCache) {
142
			getEntity().setUseNameCache(checkbox_useNameCache.getSelection());
143
		} else if (eventSource == selection_secundum) {
144
			getEntity().setSec(selection_secundum.getSelection());
145
		} else if (eventSource == text_appendedPhrase) {
146
			getEntity().setAppendedPhrase(text_appendedPhrase.getText());
147
		} else if (eventSource == text_secundum_microreference) {
148
            getEntity().setSecMicroReference(text_secundum_microreference.getText());
149
		} else if (eventSource == checkbox_published) {
150
		    ((Taxon)getEntity()).setPublish(checkbox_published.getSelection());
151
		} else if(eventSource == combo_relationshipType){
152
            ((Synonym) getEntity()).setType(combo_relationshipType.getSelection());
153
        } else if(eventSource == checkPartial){
154
            ((Synonym) getEntity()).setPartial(checkPartial.getSelection());
155
        } else if(eventSource == checkProParte){
156
            ((Synonym) getEntity()).setProParte(checkProParte.getSelection());
157
        }
158
	}
159
	@Override
160
	protected void handleToggleableCacheField() {
161
        boolean pushedState = toggleable_cache.getState();
162

    
163
        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
164
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, checkbox_published}));
165
        updateToggleableCacheField();
166
    }
167
}
(3-3/10)