Project

General

Profile

Download (4.4 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.preference.wizard;
12

    
13
import org.eclipse.jface.wizard.Wizard;
14

    
15
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
16
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
17
import eu.etaxonomy.cdm.api.service.ITermService;
18
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
19
import eu.etaxonomy.cdm.model.common.Representation;
20
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
21
import eu.etaxonomy.taxeditor.model.MessagingUtils;
22
import eu.etaxonomy.taxeditor.store.CdmStore;
23
import eu.etaxonomy.taxeditor.store.TermStore;
24

    
25
/**
26
 * <p>VocabularyTermWizard class.</p>
27
 *
28
 * @author n.hoffmann
29
 * @created 12.06.2009
30
 * @version 1.0
31
 */
32
public class VocabularyTermWizard<T extends DefinedTermBase> extends Wizard implements IConversationEnabled {
33
	
34
	public T term = null;
35
	
36
	private boolean editMode = false;
37

    
38
	private Class<T> termClass;
39

    
40
	private ConversationHolder conversation;
41

    
42
	/**
43
	 * <p>Constructor for VocabularyTermWizard.</p>
44
	 *
45
	 * @param vocabularyClass a {@link java.lang.Class} object.
46
	 */
47
	public VocabularyTermWizard(Class<T> vocabularyClass, ConversationHolder conversation){	
48
		this.conversation = conversation;
49
		termClass = vocabularyClass;
50
	}
51
	
52
	/**
53
	 * <p>Constructor for VocabularyTermWizard.</p>
54
	 *
55
	 * @param vocabularyClass a {@link java.lang.Class} object.
56
	 * @param selectedTerm a T object.
57
	 */
58
	public VocabularyTermWizard(Class<T> vocabularyClass, T selectedTerm, ConversationHolder conversation){
59
		this(vocabularyClass, conversation);		
60
		term = (T) CdmStore.getService(ITermService.class).load(selectedTerm.getUuid());
61
		editMode = true;
62
	}
63
	
64
	/* (non-Javadoc)
65
	 * @see org.eclipse.jface.wizard.Wizard#addPages()
66
	 */
67
	/** {@inheritDoc} */
68
	@Override
69
	public void addPages() {
70
		super.addPages();
71
		
72
		addPage(new VocabularyTermWizardPage());
73
	}
74
	
75
	/* (non-Javadoc)
76
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
77
	 */
78
	/** {@inheritDoc} */
79
	@Override
80
	public boolean performFinish() {
81

    
82
		if(editMode){
83
			TermStore.updateVocabulary(getTerm());
84
		}else{
85
			TermStore.saveTerm(getTerm());
86
		}
87
		
88
		getConversationHolder().commit(true);
89
		
90
		return true;
91
	}
92

    
93
	/**
94
	 * <p>Setter for the field <code>term</code>.</p>
95
	 *
96
	 * @param term a T object.
97
	 */
98
	public void setTerm(T term) {
99
		this.term = term;
100
	}
101

    
102
	/**
103
	 * <p>Setter for the fields <code>term</code>.</p>
104
	 *
105
	 * @param text
106
	 * @param label a {@link java.lang.String} object.
107
	 * @param abbreviatedLabel a {@link java.lang.String} object.
108
	 */
109
	public void setTerm(String text, String label, String abbreviatedLabel) {
110
		Representation representation = getTerm().getRepresentation(CdmStore.getDefaultLanguage());
111
		representation.setText(text);
112
		representation.setLabel(label);
113
		representation.setAbbreviatedLabel(abbreviatedLabel);
114
	}
115
	
116
	/**
117
	 * <p>Getter for the field <code>term</code>.</p>
118
	 *
119
	 * @return the term
120
	 */
121
	public T getTerm() {
122
		if(term == null){
123
			try {
124
				term = (T) termClass.newInstance();
125
				
126
				term.addRepresentation(Representation.NewInstance("", "", "", CdmStore.getDefaultLanguage()));
127
			} catch (InstantiationException e) {
128
				MessagingUtils.error(this.getClass(), "InstantiationException when setting term", e);
129
			} catch (IllegalAccessException e) {
130
				MessagingUtils.error(this.getClass(), "IllegalAccessException when setting term", e);
131
			}
132
		}
133
		return term;
134
	}
135
	
136
	public Representation getRepresentation(){		
137
		return getTerm().getRepresentation(CdmStore.getDefaultLanguage());
138
	}
139

    
140
	/**
141
	 * <p>isEditMode</p>
142
	 *
143
	 * @return the editMode
144
	 */
145
	public boolean isEditMode() {
146
		return editMode;
147
	}
148

    
149
	/**
150
	 * <p>Getter for the field <code>termClass</code>.</p>
151
	 *
152
	 * @return a {@link java.lang.Class} object.
153
	 */
154
	public Class<T> getTermClass() {
155
		return termClass;
156
	}
157

    
158
	/* (non-Javadoc)
159
	 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
160
	 */
161
	@Override
162
	public void update(CdmDataChangeMap changeEvents) {
163
		// not needed
164
	}
165

    
166
	/* (non-Javadoc)
167
	 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
168
	 */
169
	@Override
170
	public ConversationHolder getConversationHolder() {
171
		return conversation;
172
	}
173

    
174
}
(3-3/4)