2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.preference
.wizard
;
12 import org
.eclipse
.jface
.wizard
.Wizard
;
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
.common
.DefinedTermBase
;
18 import eu
.etaxonomy
.cdm
.model
.common
.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
;
25 * <p>VocabularyTermWizard class.</p>
31 public class VocabularyTermWizard
<T
extends DefinedTermBase
> extends Wizard
implements IConversationEnabled
{
35 private boolean editMode
= false;
37 private Class
<T
> termClass
;
39 private ConversationHolder conversation
;
42 * <p>Constructor for VocabularyTermWizard.</p>
44 * @param vocabularyClass a {@link java.lang.Class} object.
46 public VocabularyTermWizard(Class
<T
> vocabularyClass
, ConversationHolder conversation
){
47 this.conversation
= conversation
;
48 termClass
= vocabularyClass
;
52 * <p>Constructor for VocabularyTermWizard.</p>
54 * @param vocabularyClass a {@link java.lang.Class} object.
55 * @param selectedTerm a T object.
57 public VocabularyTermWizard(Class
<T
> vocabularyClass
, T selectedTerm
, ConversationHolder conversation
){
58 this(vocabularyClass
, conversation
);
59 term
= (T
) CdmStore
.getService(ITermService
.class).load(selectedTerm
.getUuid());
64 * @see org.eclipse.jface.wizard.Wizard#addPages()
68 public void addPages() {
71 addPage(new VocabularyTermWizardPage());
75 * @see org.eclipse.jface.wizard.Wizard#performFinish()
79 public boolean performFinish() {
82 TermStore
.updateVocabulary(getTerm());
84 TermStore
.saveTerm(getTerm());
87 getConversationHolder().commit(true);
93 * <p>Setter for the field <code>term</code>.</p>
95 * @param term a T object.
97 public void setTerm(T term
) {
102 * <p>Setter for the fields <code>term</code>.</p>
105 * @param label a {@link java.lang.String} object.
106 * @param abbreviatedLabel a {@link java.lang.String} object.
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
);
116 * <p>Getter for the field <code>term</code>.</p>
123 term
= (T
) termClass
.newInstance();
125 term
.addRepresentation(Representation
.NewInstance("", "", "", CdmStore
.getDefaultLanguage()));
126 } catch (InstantiationException e
) {
127 MessagingUtils
.error(this.getClass(), "InstantiationException when setting term", e
);
128 } catch (IllegalAccessException e
) {
129 MessagingUtils
.error(this.getClass(), "IllegalAccessException when setting term", e
);
135 public Representation
getRepresentation(){
136 return getTerm().getRepresentation(CdmStore
.getDefaultLanguage());
142 * @return the editMode
144 public boolean isEditMode() {
149 * <p>Getter for the field <code>termClass</code>.</p>
151 * @return a {@link java.lang.Class} object.
153 public Class
<T
> getTermClass() {
158 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
161 public void update(CdmDataChangeMap changeEvents
) {
166 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
169 public ConversationHolder
getConversationHolder() {