544ad4e02f3061f5230b4bce7ed2afca9e271cb7
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / newWizard / ClassificationWizardPage.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10
11 package eu.etaxonomy.taxeditor.newWizard;
12
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;
21
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;
34
35 /**
36 * <p>
37 * ClassificationWizardPage class.
38 * </p>
39 *
40 * @author n.hoffmann
41 * @created Sep 29, 2010
42 * @version 1.0
43 */
44 @Deprecated
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;
51
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;
58
59 /**
60 * <p>
61 * Constructor for ClassificationWizardPage.
62 * </p>
63 *
64 * @param conversation
65 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
66 * object.
67 * @param classification
68 * a {@link eu.etaxonomy.cdm.model.taxon.TaxonomicTree} object.
69 */
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.");
76
77 this.classification = classification;
78 this.conversation = conversation;
79
80 this.formFactory = new CdmFormFactory(Display.getCurrent());
81
82 formFactory.addPropertyChangeListener(this);
83
84 initialize();
85 }
86
87 /*
88 * (non-Javadoc)
89 *
90 * @see
91 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
92 * .Composite)
93 */
94 /** {@inheritDoc} */
95 @Override
96 public void createControl(Composite parent) {
97 control = formFactory.createComposite(parent);
98
99 control.setLayout(CdmFormFactory.LAYOUT(2, false));
100 RootElement rootElement = new RootElement(formFactory, control);
101
102 text_classificationLabel = formFactory.createTextWithLabelElement(
103 rootElement, "Label", classification.getName().getText(),
104 SWT.NULL);
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);
113
114 Color bgColor = getShell().getBackground();
115
116 rootElement.setBackground(bgColor);
117 control.setBackground(bgColor);
118
119 setControl(control);
120 }
121
122 private void initialize() {
123 if (classification == null) {
124 classification = Classification.NewInstance(null, null,
125 CdmStore.getDefaultLanguage());
126 }
127 }
128
129 /*
130 * (non-Javadoc)
131 *
132 * @see
133 * org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
134 * .jface.util.PropertyChangeEvent)
135 */
136 /** {@inheritDoc} */
137 @Override
138 public void propertyChange(PropertyChangeEvent event) {
139 Object eventSource = event.getSource();
140
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());
149 }
150
151 checkComplete();
152 }
153
154 /**
155 *
156 */
157 private void checkComplete() {
158 if (CdmUtils.isEmpty(text_classificationLabel.getText())) {
159 setMessage("A Classifications label may not be empty");
160 setPageComplete(false);
161 } else {
162 setMessage(null);
163 setPageComplete(true);
164 }
165 }
166
167 /**
168 * <p>
169 * Getter for the field <code>classification</code>.
170 * </p>
171 *
172 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonomicTree} object.
173 */
174 public Classification getClassification() {
175 return classification;
176 }
177
178 /*
179 * (non-Javadoc)
180 *
181 * @see
182 * eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
183 * (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
184 */
185 /** {@inheritDoc} */
186 @Override
187 public void update(CdmDataChangeMap changeEvents) {
188 }
189
190 /*
191 * (non-Javadoc)
192 *
193 * @see
194 * eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
195 * ()
196 */
197 /** {@inheritDoc} */
198 @Override
199 public ConversationHolder getConversationHolder() {
200 return conversation;
201 }
202
203 /*
204 * (non-Javadoc)
205 *
206 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
207 */
208 /** {@inheritDoc} */
209 @Override
210 public void dispose() {
211 formFactory.removePropertyChangeListener(this);
212 super.dispose();
213 }
214 }