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
.newWizard
;
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
.Classification
;
27 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
28 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
29 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
;
30 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
.SelectionType
;
31 import eu
.etaxonomy
.taxeditor
.ui
.forms
.RootElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.forms
.TextWithLabelElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.selection
.ReferenceSelectionElement
;
37 * ClassificationWizardPage class.
41 * @created Sep 29, 2010
45 // remove this file when refactoring is complete
46 public class ClassificationWizardPage
extends WizardPage
implements
47 IPropertyChangeListener
, IConversationEnabled
{
48 private static final Logger logger
= Logger
49 .getLogger(ClassificationWizardPage
.class);
50 private Classification classification
;
52 private final ConversationHolder conversation
;
53 private final CdmFormFactory formFactory
;
54 private Composite control
;
55 private TextWithLabelElement text_classificationLabel
;
56 private ReferenceSelectionElement selection_reference
;
57 private TextWithLabelElement text_referenceDetail
;
61 * Constructor for ClassificationWizardPage.
65 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
67 * @param classification
68 * a {@link eu.etaxonomy.cdm.model.taxon.TaxonomicTree} object.
70 protected ClassificationWizardPage(ConversationHolder conversation
,
71 Classification classification
) {
72 super("Classification");
73 this.setTitle("Classification");
74 this.setDescription(classification
== null ?
"Create a new Classification."
75 : "Edit Classification.");
77 this.classification
= classification
;
78 this.conversation
= conversation
;
80 this.formFactory
= new CdmFormFactory(Display
.getCurrent());
82 formFactory
.addPropertyChangeListener(this);
91 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
96 public void createControl(Composite parent
) {
97 control
= formFactory
.createComposite(parent
);
99 control
.setLayout(CdmFormFactory
.LAYOUT(2, false));
100 RootElement rootElement
= new RootElement(formFactory
, control
);
102 text_classificationLabel
= formFactory
.createTextWithLabelElement(
103 rootElement
, "Label", classification
.getName().getText(),
105 selection_reference
= (ReferenceSelectionElement
) formFactory
106 .createSelectionElement(SelectionType
.REFERENCE
,
107 getConversationHolder(), rootElement
, "Reference",
108 classification
.getReference(),
109 ReferenceSelectionElement
.DEFAULT
, SWT
.NULL
);
110 text_referenceDetail
= formFactory
.createTextWithLabelElement(
111 rootElement
, "Reference Detail",
112 classification
.getMicroReference(), SWT
.NULL
);
114 Color bgColor
= getShell().getBackground();
116 rootElement
.setBackground(bgColor
);
117 control
.setBackground(bgColor
);
122 private void initialize() {
123 if (classification
== null) {
124 classification
= Classification
.NewInstance(null, null,
125 CdmStore
.getDefaultLanguage());
133 * org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
134 * .jface.util.PropertyChangeEvent)
138 public void propertyChange(PropertyChangeEvent event
) {
139 Object eventSource
= event
.getSource();
141 if (eventSource
== text_classificationLabel
) {
142 classification
.setName(LanguageString
.NewInstance(
143 text_classificationLabel
.getText(),
144 CdmStore
.getDefaultLanguage()));
145 } else if (eventSource
== selection_reference
) {
146 classification
.setReference(selection_reference
.getEntity());
147 } else if (eventSource
== text_referenceDetail
) {
148 classification
.setMicroReference(text_referenceDetail
.getText());
157 private void checkComplete() {
158 if (CdmUtils
.isEmpty(text_classificationLabel
.getText())) {
159 setMessage("A Classifications label may not be empty");
160 setPageComplete(false);
163 setPageComplete(true);
169 * Getter for the field <code>classification</code>.
172 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonomicTree} object.
174 public Classification
getClassification() {
175 return classification
;
182 * eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
183 * (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
187 public void update(CdmDataChangeMap changeEvents
) {
194 * eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
199 public ConversationHolder
getConversationHolder() {
206 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
210 public void dispose() {
211 formFactory
.removePropertyChangeListener(this);