Project

General

Profile

Download (5.68 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
package eu.etaxonomy.taxeditor.ui.section.taxon;
10

    
11
import org.eclipse.jface.util.PropertyChangeEvent;
12
import org.eclipse.swt.SWT;
13

    
14
import eu.etaxonomy.cdm.model.taxon.SecundumSource;
15
import eu.etaxonomy.cdm.model.taxon.Synonym;
16
import eu.etaxonomy.cdm.model.taxon.SynonymType;
17
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
18
import eu.etaxonomy.cdm.persistence.permission.Role;
19
import eu.etaxonomy.taxeditor.preference.NameDetailsConfigurator;
20
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
21
import eu.etaxonomy.taxeditor.store.CdmStore;
22
import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
23
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
24
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
25
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
26
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
27
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
28
import eu.etaxonomy.taxeditor.ui.section.reference.SecundumSourceElement;
29

    
30
/**
31
 * @author n.hoffmann
32
 * @created Feb 26, 2010
33
 */
34
public class TaxonBaseDetailElement extends AbstractIdentifiableEntityDetailElement<TaxonBase<?>> {
35

    
36
	private CheckboxElement checkbox_doubtful;
37

    
38
	private CheckboxElement checkbox_useNameCache;
39

    
40
//	private EntitySelectionElement<Reference> selection_secundum;
41
    private SecundumSourceElement secElement;
42

    
43

    
44
	private TextWithLabelElement text_appendedPhrase;
45

    
46
	private CheckboxElement checkbox_published;
47

    
48
    private TermComboElement<SynonymType> combo_relationshipType;
49

    
50
	public TaxonBaseDetailElement(CdmFormFactory cdmFormFactory,
51
			ICdmFormElement formElement, int style) {
52
		super(cdmFormFactory, formElement);
53
	}
54

    
55
	@Override
56
	protected void createControls(ICdmFormElement formElement, TaxonBase<?> entity, int style) {
57

    
58
	    NameDetailsConfigurator config = PreferencesUtil.getPreferredNameDetailsConfiguration();
59
		toggleable_cache = formFactory.createToggleableTextField(formElement,
60
					"Title Cache", entity.getTitleCache(),
61
					entity.isProtectedTitleCache(), style);
62

    
63
		text_appendedPhrase = formFactory.createTextWithLabelElement(
64
					formElement, "Appended Phrase", entity.getAppendedPhrase(),
65
					SWT.WRAP);
66

    
67
		secElement = formFactory.createSecundumSourceElement(formElement, null, "Secundum");
68

    
69
		secElement.setCdmEntity(entity);
70
		 if (entity.getSecSource() == null){
71
	            SecundumSource source = SecundumSource.NewSecundumInstance(entity);
72
	            entity.setSecSource(source);
73
	            secElement.setEntity(source);
74
	        }else{
75
	            secElement.setEntity(entity.getSecSource());
76
	        }
77

    
78
		if (config != null && !config.isSecEnabled()){
79
		    secElement.setEnabled(false);
80
		}
81

    
82

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

    
88

    
89
		checkbox_published = formFactory.createCheckbox(formElement,
90
		        entity.getClass().getSimpleName()+" is published", entity.isPublish(), style);
91

    
92

    
93
	    //cache relevance
94
        registerCacheRelevance(checkbox_doubtful);
95
        registerCacheRelevance(checkbox_useNameCache);
96
        registerCacheRelevance(secElement);
97
        registerCacheRelevance(text_appendedPhrase);
98
        registerCacheRelevance(combo_relationshipType);
99
	}
100

    
101
    private void updateCheckboxPublish() {
102
        checkbox_published.setEnabled(
103
            		CdmStore.currentAuthentiationHasOneOfRoles(Role.ROLE_PUBLISH, Role.ROLE_ADMIN)
104
            		);
105

    
106
    }
107

    
108
	@Override
109
    protected void updateControlStates() {
110
        super.updateControlStates();
111
        updateCheckboxPublish();
112
    }
113

    
114
	@Override
115
	protected void updateContent() {
116
		super.updateContent();
117
		toggleable_cache.setCacheEnabled(getEntity().isProtectedTitleCache());
118
		updateCacheRelevance();
119
	}
120

    
121
	@Override
122
	protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
123
		String title = getEntity().generateTitle();
124
		getEntity().setTitleCache(title);
125
		super.handleTitleCacheRelevantChange(event);
126
	}
127

    
128
	@Override
129
	public void handleEvent(Object eventSource) {
130
		if (eventSource== toggleable_cache) {
131
			handleToggleableCacheField();
132
		} else if (eventSource == checkbox_doubtful) {
133
			getEntity().setDoubtful(checkbox_doubtful.getSelection());
134
		} else if (eventSource == checkbox_useNameCache) {
135
			getEntity().setUseNameCache(checkbox_useNameCache.getSelection());
136
		} else if (eventSource == secElement) {
137
			getEntity().setSecSource(secElement.getEntity());
138
		} else if (eventSource == text_appendedPhrase) {
139
			getEntity().setAppendedPhrase(text_appendedPhrase.getText());
140
		} else if (eventSource == checkbox_published) {
141
		    getEntity().setPublish(checkbox_published.getSelection());
142
		} else if(eventSource == combo_relationshipType){
143
            ((Synonym) getEntity()).setType(combo_relationshipType.getSelection());
144
		//#7334/5 removed pro parte and partial as they are handled as concept relationships now
145
//        } else if(eventSource == checkPartial){
146
//            ((Synonym) getEntity()).setPartial(checkPartial.getSelection());
147
//        } else if(eventSource == checkProParte){
148
//            ((Synonym) getEntity()).setProParte(checkProParte.getSelection());
149
        }
150
	}
151

    
152
	@Override
153
	protected void handleToggleableCacheField() {
154
        getEntity().setTitleCache(toggleable_cache.getText(), toggleable_cache.getState());
155
        updateCacheRelevance();
156
        updateToggleableCacheField();
157
    }
158
}
(3-3/10)