Project

General

Profile

Download (6.35 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.model.taxon.TaxonRelationship;
23
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
24
import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
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
			toggleable_cache = formFactory.createToggleableTextField(formElement,
66
					"Title Cache", entity.getTitleCache(),
67
					entity.isProtectedTitleCache(), style);
68

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

    
74

    
75

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

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

    
86

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

    
92

    
93
		if (entity instanceof Taxon) {
94
			checkbox_published = formFactory.createCheckbox(formElement,
95
					"Taxon is published", ((Taxon) entity).isPublish(), style);
96
		}
97

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

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

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

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

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

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

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