Project

General

Profile

Download (3.55 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.model.common.DefinedTermBase;
17
import eu.etaxonomy.cdm.model.common.Representation;
18
import eu.etaxonomy.taxeditor.store.CdmStore;
19
import eu.etaxonomy.taxeditor.store.StoreUtil;
20
import eu.etaxonomy.taxeditor.store.TermStore;
21

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

    
35
	private Class<T> termClass;
36

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

    
76
		ConversationHolder conversation = CdmStore.createConversation();
77
		
78
		if(editMode){
79
			TermStore.updateVocabulary(getTerm());
80
		}else{
81
			TermStore.saveTerm(getTerm());
82
		}
83
		
84
		conversation.commit(false);
85
		
86
		return true;
87
	}
88

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

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

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

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

    
156
}
(1-1/2)