Project

General

Profile

Download (4.45 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.preference.wizard;
11

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

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

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

    
37
	private Class<T> termClass;
38

    
39
	private ConversationHolder conversation;
40

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

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

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

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

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

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

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

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

    
173
}
(13-13/14)