3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.preference
.wizard
;
13 import org
.eclipse
.jface
.wizard
.Wizard
;
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
.store
.CdmStore
;
22 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
23 import eu
.etaxonomy
.taxeditor
.store
.TermStore
;
26 * <p>VocabularyTermWizard class.</p>
32 public class VocabularyTermWizard
<T
extends DefinedTermBase
> extends Wizard
implements IConversationEnabled
{
36 private boolean editMode
= false;
38 private Class
<T
> termClass
;
40 private ConversationHolder conversation
;
43 * <p>Constructor for VocabularyTermWizard.</p>
45 * @param vocabularyClass a {@link java.lang.Class} object.
47 public VocabularyTermWizard(Class
<T
> vocabularyClass
){
48 conversation
= CdmStore
.createConversation();
49 termClass
= vocabularyClass
;
53 * <p>Constructor for VocabularyTermWizard.</p>
55 * @param vocabularyClass a {@link java.lang.Class} object.
56 * @param selectedTerm a T object.
58 public VocabularyTermWizard(Class
<T
> vocabularyClass
, T selectedTerm
){
59 this(vocabularyClass
);
60 term
= (T
) CdmStore
.getService(ITermService
.class).load(selectedTerm
.getUuid());
65 * @see org.eclipse.jface.wizard.Wizard#addPages()
69 public void addPages() {
72 addPage(new VocabularyTermWizardPage());
76 * @see org.eclipse.jface.wizard.Wizard#performFinish()
80 public boolean performFinish() {
83 TermStore
.updateVocabulary(getTerm());
85 TermStore
.saveTerm(getTerm());
88 getConversationHolder().commit(false);
89 getConversationHolder().close();
95 * <p>Setter for the field <code>term</code>.</p>
97 * @param term a T object.
99 public void setTerm(T term
) {
104 * <p>Setter for the field <code>term</code>.</p>
109 * @param label a {@link java.lang.String} object.
110 * @param abbreviatedLabel a {@link java.lang.String} object.
112 public void setTerm(String text
, String label
, String abbreviatedLabel
) {
113 Representation representation
= getTerm().getRepresentation(CdmStore
.getDefaultLanguage());
114 representation
.setText(text
);
115 representation
.setLabel(label
);
116 representation
.setAbbreviatedLabel(abbreviatedLabel
);
120 * <p>Getter for the field <code>term</code>.</p>
127 term
= (T
) termClass
.newInstance();
129 term
.addRepresentation(Representation
.NewInstance("", "", "", CdmStore
.getDefaultLanguage()));
130 } catch (InstantiationException e
) {
131 StoreUtil
.error(this.getClass(), "InstantiationException when setting term", e
);
132 } catch (IllegalAccessException e
) {
133 StoreUtil
.error(this.getClass(), "IllegalAccessException when setting term", e
);
139 public Representation
getRepresentation(){
140 return getTerm().getRepresentation(CdmStore
.getDefaultLanguage());
146 * @return the editMode
148 public boolean isEditMode() {
153 * <p>Getter for the field <code>termClass</code>.</p>
155 * @return a {@link java.lang.Class} object.
157 public Class
<T
> getTermClass() {
162 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
165 public void update(CdmDataChangeMap changeEvents
) {
166 // TODO Auto-generated method stub
171 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
174 public ConversationHolder
getConversationHolder() {