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
.model
.MessagingUtils
;
22 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
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
, ConversationHolder conversation
){
48 this.conversation
= conversation
;
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
, ConversationHolder conversation
){
59 this(vocabularyClass
, conversation
);
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(true);
94 * <p>Setter for the field <code>term</code>.</p>
96 * @param term a T object.
98 public void setTerm(T term
) {
103 * <p>Setter for the fields <code>term</code>.</p>
106 * @param label a {@link java.lang.String} object.
107 * @param abbreviatedLabel a {@link java.lang.String} object.
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
);
117 * <p>Getter for the field <code>term</code>.</p>
124 term
= (T
) termClass
.newInstance();
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
);
136 public Representation
getRepresentation(){
137 return getTerm().getRepresentation(CdmStore
.getDefaultLanguage());
143 * @return the editMode
145 public boolean isEditMode() {
150 * <p>Getter for the field <code>termClass</code>.</p>
152 * @return a {@link java.lang.Class} object.
154 public Class
<T
> getTermClass() {
159 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
162 public void update(CdmDataChangeMap changeEvents
) {
167 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
170 public ConversationHolder
getConversationHolder() {