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
.wizard
;
13 import org
.apache
.log4j
.Logger
;
14 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
15 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
16 import org
.eclipse
.jface
.wizard
.WizardPage
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.graphics
.Color
;
19 import org
.eclipse
.swt
.widgets
.Composite
;
20 import org
.eclipse
.swt
.widgets
.Display
;
22 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
23 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
24 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
25 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonomicTree
;
27 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
28 import eu
.etaxonomy
.taxeditor
.forms
.CdmFormFactory
;
29 import eu
.etaxonomy
.taxeditor
.forms
.CdmFormFactory
.SelectionType
;
30 import eu
.etaxonomy
.taxeditor
.forms
.RootElement
;
31 import eu
.etaxonomy
.taxeditor
.forms
.TextWithLabelElement
;
32 import eu
.etaxonomy
.taxeditor
.forms
.selection
.ReferenceSelectionElement
;
33 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
36 * <p>ClassificationWizardPage class.</p>
39 * @created Sep 29, 2010
42 public class ClassificationWizardPage
extends WizardPage
implements IPropertyChangeListener
, IConversationEnabled
{
43 private static final Logger logger
= Logger
44 .getLogger(ClassificationWizardPage
.class);
45 private TaxonomicTree classification
;
47 private ConversationHolder conversation
;
48 private CdmFormFactory formFactory
;
49 private Composite control
;
50 private TextWithLabelElement text_classificationLabel
;
51 private ReferenceSelectionElement selection_reference
;
52 private TextWithLabelElement text_referenceDetail
;
55 * <p>Constructor for ClassificationWizardPage.</p>
57 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
58 * @param classification a {@link eu.etaxonomy.cdm.model.taxon.TaxonomicTree} object.
60 protected ClassificationWizardPage(ConversationHolder conversation
, TaxonomicTree classification
){
61 super("Classification");
62 this.setTitle("Classification");
63 this.setDescription(classification
== null ?
"Create a new Classification." : "Edit Classification.");
65 this.classification
= classification
;
66 this.conversation
= conversation
;
68 this.formFactory
= new CdmFormFactory(Display
.getCurrent());
70 formFactory
.addPropertyChangeListener(this);
77 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
80 public void createControl(Composite parent
) {
81 control
= formFactory
.createComposite(parent
);
83 control
.setLayout(CdmFormFactory
.LAYOUT(2, false));
84 RootElement rootElement
= new RootElement(formFactory
, control
);
86 text_classificationLabel
= formFactory
.createTextWithLabelElement(rootElement
, "Label", classification
.getName().getText(), SWT
.NULL
);
87 selection_reference
= (ReferenceSelectionElement
) formFactory
.createSelectionElement(SelectionType
.REFERENCE
, getConversationHolder(), rootElement
, "Reference", classification
.getReference(), SWT
.NULL
);
88 text_referenceDetail
= formFactory
.createTextWithLabelElement(rootElement
, "Reference Detail", classification
.getMicroReference(), SWT
.NULL
);
90 Color bgColor
= getShell().getBackground();
92 rootElement
.setBackground(bgColor
);
93 control
.setBackground(bgColor
);
98 private void initialize() {
99 if(classification
== null){
100 classification
= TaxonomicTree
.NewInstance(null, null, CdmStore
.getDefaultLanguage());
105 * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
109 public void propertyChange(PropertyChangeEvent event
) {
110 Object eventSource
= event
.getSource();
112 if(eventSource
== text_classificationLabel
){
113 classification
.setName(LanguageString
.NewInstance(text_classificationLabel
.getText(), CdmStore
.getDefaultLanguage()));
115 else if(eventSource
== selection_reference
){
116 classification
.setReference(selection_reference
.getEntity());
118 else if(eventSource
== text_referenceDetail
){
119 classification
.setMicroReference(text_referenceDetail
.getText());
129 private void checkComplete() {
130 if(CdmUtils
.isEmpty(text_classificationLabel
.getText())){
131 setMessage("A Classifications label may not be empty");
132 setPageComplete(false);
135 setPageComplete(true);
140 * <p>Getter for the field <code>classification</code>.</p>
142 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonomicTree} object.
144 public TaxonomicTree
getClassification() {
145 return classification
;
150 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
154 public void update(CdmDataChangeMap changeEvents
) {}
158 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
162 public ConversationHolder
getConversationHolder() {
167 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
171 public void dispose() {
172 formFactory
.removePropertyChangeListener(this);