62d95788b0a643f6d1e38aca7021ce9a95b52bd1
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / classification / TaxonNodeWizardPage.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.ui.section.classification;
12
13 import org.eclipse.jface.util.PropertyChangeEvent;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.widgets.Event;
16 import org.eclipse.swt.widgets.Listener;
17
18 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
19 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
20 import eu.etaxonomy.cdm.model.taxon.Taxon;
21 import eu.etaxonomy.taxeditor.newWizard.IWizardPageListener;
22 import eu.etaxonomy.taxeditor.ui.element.AbstractCdmEntityWizardPage;
23 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
24 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
25
26 /**
27 * <p>
28 * TaxonNodeWizardPage class.
29 * </p>
30 *
31 * @author n.hoffmann
32 * @created Sep 15, 2009
33 * @version 1.0
34 */
35 public class TaxonNodeWizardPage extends AbstractCdmEntityWizardPage<ITaxonTreeNode> implements Listener{
36
37 private final IWizardPageListener wizardPageListener;
38 private final boolean isCreateNew;
39
40 /**
41 * <p>
42 * Constructor for TaxonNodeWizardPage.
43 * </p>
44 *
45 * @param formFactory
46 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
47 * object.
48 * @param conversation
49 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
50 * object.
51 * @param entity
52 * a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
53 * @param closeOnEnterListener
54 */
55 public TaxonNodeWizardPage(CdmFormFactory formFactory,
56 ConversationHolder conversation, ITaxonTreeNode entity, IWizardPageListener closeOnEnterListener, boolean isCreateNew) {
57 super(formFactory, conversation, entity);
58 this.wizardPageListener = closeOnEnterListener;
59 setTitle("TaxonNode");
60 this.isCreateNew = isCreateNew;
61
62 }
63
64 /*
65 * (non-Javadoc)
66 *
67 * @see
68 * eu.etaxonomy.taxeditor.forms.AbstractCdmEntityWizardPage#createElement
69 * (eu.etaxonomy.taxeditor.forms.ICdmFormElement)
70 */
71 /** {@inheritDoc} */
72 @Override
73 public TaxonNodeDetailElement createElement(ICdmFormElement rootElement) {
74 TaxonNodeDetailElement detailElement = formFactory.createTaxonNodeDetailElement(rootElement, this.isCreateNew);
75 detailElement.setEntity(entity);
76 formFactory.addPropertyChangeListener(this);
77 if (isCreateNew){
78 detailElement.getTextNewTaxonName().getMainControl().addListener(SWT.KeyDown, this);
79 }
80 return detailElement;
81 }
82
83 /**
84 * <p>
85 * openInEditor
86 * </p>
87 *
88 * @return a boolean.
89 */
90 public boolean openInEditor() {
91 return ((TaxonNodeDetailElement) getDetailElement()).isOpenInEditor();
92 }
93
94 /*
95 * (non-Javadoc)
96 *
97 * @see
98 * org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
99 * .jface.util.PropertyChangeEvent)
100 */
101 /** {@inheritDoc} */
102 @Override
103 public void propertyChange(PropertyChangeEvent event) {
104 checkComplete();
105 }
106
107 @Override
108 protected void checkComplete() {
109 TaxonNodeDetailElement detailElement = (TaxonNodeDetailElement) getDetailElement();
110
111 if (detailElement.getClassification() == null) {
112 setMessage("No classification set.", WARNING);
113 }
114 else if(isCreateNew ){
115 if(detailElement.getTextNewTaxonName().getText().isEmpty()){
116 setMessage("No taxon name set.", ERROR);
117 } else{
118 setMessage(null);
119 setPageComplete(true);
120 return;
121 }
122 }
123 else if(!detailElement.isComplete()){
124 setMessage("Not all required fields are filled.", ERROR);
125 }
126 else {
127 setMessage(null);
128 setPageComplete(true);
129 return;
130 }
131
132 setPageComplete(false);
133 }
134
135 /**
136 * <p>
137 * Getter for the field <code>parentTreeNode</code>.
138 * </p>
139 *
140 * @return a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
141 */
142 public ITaxonTreeNode getParentTreeNode() {
143 return ((TaxonNodeDetailElement) getDetailElement())
144 .getParentTreeNode();
145 }
146
147 public Taxon getTaxon() {
148 return ((TaxonNodeDetailElement) getDetailElement()).getTaxon();
149 }
150
151 /*
152 * (non-Javadoc)
153 *
154 * @see eu.etaxonomy.taxeditor.forms.AbstractCdmEntityWizardPage#dispose()
155 */
156 /** {@inheritDoc} */
157 @Override
158 public void dispose() {
159 formFactory.removePropertyChangeListener(this);
160 super.dispose();
161 }
162
163 @Override
164 public void handleEvent(Event event) {
165 TaxonNodeDetailElement detailElement = (TaxonNodeDetailElement) getDetailElement();
166 if(event.widget == detailElement.getTextNewTaxonName().getMainControl()
167 && event.keyCode == SWT.CR && isPageComplete()){
168 wizardPageListener.close();
169 }
170 }
171
172 }