df24d7c6c3fb97633b1c61a574f927b3f9709100
[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
39 /**
40 * <p>
41 * Constructor for TaxonNodeWizardPage.
42 * </p>
43 *
44 * @param formFactory
45 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
46 * object.
47 * @param conversation
48 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
49 * object.
50 * @param entity
51 * a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
52 * @param closeOnEnterListener
53 */
54 public TaxonNodeWizardPage(CdmFormFactory formFactory,
55 ConversationHolder conversation, ITaxonTreeNode entity, IWizardPageListener closeOnEnterListener) {
56 super(formFactory, conversation, entity);
57 this.wizardPageListener = closeOnEnterListener;
58 setTitle("Create a new Taxon");
59 }
60
61 /*
62 * (non-Javadoc)
63 *
64 * @see
65 * eu.etaxonomy.taxeditor.forms.AbstractCdmEntityWizardPage#createElement
66 * (eu.etaxonomy.taxeditor.forms.ICdmFormElement)
67 */
68 /** {@inheritDoc} */
69 @Override
70 public TaxonNodeDetailElement createElement(ICdmFormElement rootElement) {
71 TaxonNodeDetailElement detailElement = formFactory.createTaxonNodeDetailElement(rootElement);
72 detailElement.setEntity(entity);
73 formFactory.addPropertyChangeListener(this);
74 detailElement.getTextNewTaxonName().getMainControl().addListener(SWT.KeyDown, this);
75 return detailElement;
76 }
77
78 /**
79 * <p>
80 * openInEditor
81 * </p>
82 *
83 * @return a boolean.
84 */
85 public boolean openInEditor() {
86 return ((TaxonNodeDetailElement) getDetailElement()).isOpenInEditor();
87 }
88
89 /*
90 * (non-Javadoc)
91 *
92 * @see
93 * org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
94 * .jface.util.PropertyChangeEvent)
95 */
96 /** {@inheritDoc} */
97 @Override
98 public void propertyChange(PropertyChangeEvent event) {
99 if (event.getSource() == getDetailElement()) {
100 checkComplete();
101 }
102 }
103
104 @Override
105 protected void checkComplete() {
106 TaxonNodeDetailElement detailElement = (TaxonNodeDetailElement) getDetailElement();
107
108 if (detailElement.getClassification() == null) {
109 setMessage("No classification set.", WARNING);
110 }
111 else if(detailElement.getTextNewTaxonName().getText().isEmpty()){
112 setMessage("No taxon name set.", ERROR);
113 }
114 else if(!detailElement.isComplete()){
115 setMessage("Not all required fields are filled.", ERROR);
116 }
117 else {
118 setMessage(null);
119 setPageComplete(true);
120 return;
121 }
122
123 setPageComplete(false);
124 }
125
126 /**
127 * <p>
128 * Getter for the field <code>parentTreeNode</code>.
129 * </p>
130 *
131 * @return a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
132 */
133 public ITaxonTreeNode getParentTreeNode() {
134 return ((TaxonNodeDetailElement) getDetailElement())
135 .getParentTreeNode();
136 }
137
138 public Taxon getTaxon() {
139 return ((TaxonNodeDetailElement) getDetailElement()).getTaxon();
140 }
141
142 /*
143 * (non-Javadoc)
144 *
145 * @see eu.etaxonomy.taxeditor.forms.AbstractCdmEntityWizardPage#dispose()
146 */
147 /** {@inheritDoc} */
148 @Override
149 public void dispose() {
150 formFactory.removePropertyChangeListener(this);
151 super.dispose();
152 }
153
154 @Override
155 public void handleEvent(Event event) {
156 TaxonNodeDetailElement detailElement = (TaxonNodeDetailElement) getDetailElement();
157 if(event.widget == detailElement.getTextNewTaxonName().getMainControl()
158 && event.keyCode == SWT.CR && isPageComplete()){
159 wizardPageListener.close();
160 }
161 }
162
163 }