2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.propertysheet
.type
.wizard
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.core
.databinding
.observable
.list
.WritableList
;
14 import org
.eclipse
.core
.runtime
.Assert
;
15 import org
.eclipse
.jface
.wizard
.WizardPage
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.swt
.events
.KeyAdapter
;
18 import org
.eclipse
.swt
.events
.KeyEvent
;
19 import org
.eclipse
.swt
.events
.SelectionAdapter
;
20 import org
.eclipse
.swt
.events
.SelectionEvent
;
21 import org
.eclipse
.swt
.layout
.GridData
;
22 import org
.eclipse
.swt
.layout
.GridLayout
;
23 import org
.eclipse
.swt
.widgets
.Button
;
24 import org
.eclipse
.swt
.widgets
.Composite
;
25 import org
.eclipse
.swt
.widgets
.Dialog
;
26 import org
.eclipse
.swt
.widgets
.Label
;
27 import org
.eclipse
.swt
.widgets
.Text
;
29 import eu
.etaxonomy
.cdm
.model
.name
.NameTypeDesignation
;
30 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
31 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
32 import eu
.etaxonomy
.cdm
.model
.reference
.Generic
;
33 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
34 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
35 import eu
.etaxonomy
.taxeditor
.controller
.PreferencesController
;
36 import eu
.etaxonomy
.taxeditor
.propertysheet
.reference
.IReferenceSearch
;
37 import eu
.etaxonomy
.taxeditor
.propertysheet
.reference
.ReferenceSearchDialog
;
44 public class ChooseNameTypeWizardPage
extends WizardPage
{
45 private static Logger logger
= Logger
46 .getLogger(ChooseNameTypeWizardPage
.class);
48 private TaxonNameBase name
;
49 private NameTypeDesignation typeDesignation
;
50 private TaxonNameBase savedName
;
52 private ReferenceBase savedReference
;
55 private Button btnClearName
;
56 private Text txtReference
;
57 private Button btnClearReference
;
58 private Button btnRejected
;
59 private Button btnConserved
;
60 private Button btnLecto
;
61 private Button btnNotDesignated
;
63 private WritableList typeDesignationsList
;
66 * @param typeDesignation
68 * @param typeDesignationsList
70 public ChooseNameTypeWizardPage(TypeDesignationBase typeDesignation
,
71 TaxonNameBase name
, WritableList typeDesignationsList
) {
74 Assert
.isTrue(typeDesignation
== null || typeDesignation
instanceof NameTypeDesignation
);
76 this.typeDesignation
= (NameTypeDesignation
) typeDesignation
;
78 this.typeDesignationsList
= typeDesignationsList
;
80 setTitle("Create or edit type designation");
81 setDescription("Create or edit type designation for '" + name
.getTitleCache() + "\".");
86 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
88 public void createControl(Composite parent
) {
90 // Create composite for popup dialog
91 Composite container
= new Composite(parent
, SWT
.NULL
);
92 container
.setLayout(new GridLayout());
93 setControl(container
);
96 final Label lblName
= new Label(container
, SWT
.NONE
);
97 lblName
.setText("Choose a name either by searching or entering it as free text:");
99 // Create 3-columned composite for name
100 Composite nameComposite
= new Composite(container
, SWT
.NULL
);
101 nameComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
102 GridLayout gridLayout
= new GridLayout();
103 gridLayout
.numColumns
= 3;
104 gridLayout
.marginHeight
= 0;
105 gridLayout
.marginWidth
= 0;
106 nameComposite
.setLayout(gridLayout
);
109 txtName
= new Text(nameComposite
, SWT
.BORDER
);
110 txtName
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
111 txtName
.addKeyListener(new KeyAdapter() {
113 public void keyReleased(KeyEvent e
) {
118 // Create name search button
119 Button btnSearchName
= new Button(nameComposite
, SWT
.NONE
);
120 btnSearchName
.setEnabled(true);
121 btnSearchName
.setLayoutData(new GridData());
122 btnSearchName
.setText("Search ...");
123 btnSearchName
.addSelectionListener(new SelectionAdapter() {
125 // Popup reference search
126 public void widgetSelected(SelectionEvent e
) {
131 // Create clear name button
132 btnClearName
= new Button(nameComposite
, SWT
.NONE
);
133 btnClearName
.setEnabled(false);
134 btnClearName
.setText("Clear");
135 btnClearName
.addSelectionListener(new SelectionAdapter() {
137 // Clear selected reference
138 public void widgetSelected(SelectionEvent e
) {
143 // Set text to name text if exists, disable ability to edit name
144 if (typeDesignation
!= null && typeDesignation
.getTypeName() != null) {
146 savedName
= typeDesignation
.getTypeName();
147 txtName
.setText(savedName
.getTitleCache());
148 txtName
.setEditable(false);
150 btnClearName
.setEnabled(false);
151 btnSearchName
.setEnabled(false);
154 // Tell user when he is entering a new name
155 Label lblNewNameFeedback
= new Label(container
, SWT
.NONE
);
156 lblNewNameFeedback
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, true, false));
157 lblNewNameFeedback
.setFont(
158 TaxEditorPlugin
.getDefault().italicizeFont(lblNewNameFeedback
.getFont()));
159 lblNewNameFeedback
.setText("Existing names can not be edited.");
161 // Create 2-columned composite for name
162 Composite booleansComposite
= new Composite(container
, SWT
.NULL
);
163 booleansComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
164 GridLayout gridLayout2
= new GridLayout();
165 gridLayout2
.numColumns
= 2;
166 gridLayout2
.marginHeight
= 15;
167 gridLayout2
.marginWidth
= 0;
168 booleansComposite
.setLayout(gridLayout2
);
170 btnRejected
= new Button(booleansComposite
, SWT
.CHECK
);
171 btnRejected
.setText("Is rejected type");
172 btnRejected
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
174 btnConserved
= new Button(booleansComposite
, SWT
.CHECK
);
175 btnConserved
.setText("Is conserved type");
176 btnConserved
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
178 btnLecto
= new Button(booleansComposite
, SWT
.CHECK
);
179 btnLecto
.setText("Is lecto type");
180 btnLecto
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
182 btnNotDesignated
= new Button(booleansComposite
, SWT
.CHECK
);
183 btnNotDesignated
.setText("Is not designated");
184 btnNotDesignated
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
186 // Set any boolean values
187 if (typeDesignation
!= null) {
188 if (typeDesignation
.isRejectedType()) {
189 btnRejected
.setSelection(true);
191 if (typeDesignation
.isConservedType()) {
192 btnConserved
.setSelection(true);
194 if (typeDesignation
.isLectoType()) {
195 btnLecto
.setSelection(true);
197 if (typeDesignation
.isNotDesignated()) {
198 btnNotDesignated
.setSelection(true);
202 // Create reference text
203 final Label lblReference
= new Label(container
, SWT
.NONE
);
204 lblReference
.setText("Choose a reference either by searching or entering it as free text:");
206 // Create 3-columned composite for reference
207 Composite referenceComposite
= new Composite(container
, SWT
.NULL
);
208 referenceComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
209 GridLayout gridLayout3
= new GridLayout();
210 gridLayout3
.numColumns
= 3;
211 gridLayout3
.marginHeight
= 0;
212 gridLayout3
.marginWidth
= 0;
213 referenceComposite
.setLayout(gridLayout3
);
215 // Create reference input
216 txtReference
= new Text(referenceComposite
, SWT
.BORDER
);
217 txtReference
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
219 // Create reference search button
220 Button btnSearchReference
= new Button(referenceComposite
, SWT
.NONE
);
221 btnSearchReference
.setEnabled(true);
222 btnSearchReference
.setLayoutData(new GridData());
223 btnSearchReference
.setText("Search ...");
224 btnSearchReference
.addSelectionListener(new SelectionAdapter() {
226 // Popup reference search
227 public void widgetSelected(SelectionEvent e
) {
228 popupReferenceSearch();
232 // Create clear reference button
233 btnClearReference
= new Button(referenceComposite
, SWT
.NONE
);
234 btnClearReference
.setEnabled(false);
235 btnClearReference
.setText("Clear");
236 btnClearReference
.addSelectionListener(new SelectionAdapter() {
238 // Clear selected reference
239 public void widgetSelected(SelectionEvent e
) {
244 // Set text to reference text if exists
245 if (typeDesignation
!= null && typeDesignation
.getCitation() != null) {
247 savedReference
= typeDesignation
.getCitation();
248 txtReference
.setText(savedReference
.getTitleCache());
249 txtReference
.setEditable(false);
251 btnClearReference
.setEnabled(true);
254 // Tell user when he is entering a new reference
255 Label lblNewRefFeedback
= new Label(container
, SWT
.NONE
);
256 lblNewRefFeedback
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, true, false));
257 lblNewRefFeedback
.setFont(
258 TaxEditorPlugin
.getDefault().italicizeFont(lblNewRefFeedback
.getFont()));
259 lblNewRefFeedback
.setText("Existing references can only be edited in property sheet.");
265 protected void popupNameSearch() {
266 Dialog dialog
= new NameSearchDialog(getShell());
267 Object value
= ((NameSearchDialog
) dialog
).open();
269 if (value
instanceof TaxonNameBase
) {
270 setSavedName((TaxonNameBase
) value
);
275 protected void popupReferenceSearch() {
276 Dialog dialog
= new ReferenceSearchDialog(getShell(),
277 IReferenceSearch
.BIBREF
);
278 Object value
= ((ReferenceSearchDialog
) dialog
).open();
280 if (value
instanceof ReferenceBase
) {
281 setSavedReference((ReferenceBase
) value
);
288 private void setSavedName(TaxonNameBase savedName
) {
290 this.savedName
= savedName
;
292 txtName
.setText(savedName
.getTitleCache());
293 txtName
.setEditable(false);
295 btnClearName
.setEnabled(true);
301 private void setSavedReference(ReferenceBase reference
) {
303 savedReference
= reference
;
305 txtReference
.setText(reference
.getTitleCache());
306 txtReference
.setEditable(false);
308 btnClearReference
.setEnabled(true);
314 protected void clearName() {
318 txtName
.setEditable(true);
320 btnClearName
.setEnabled(false);
326 protected void clearReference() {
327 savedReference
= null;
329 txtReference
.setText("");
330 txtReference
.setEditable(true);
332 btnClearReference
.setEnabled(false);
336 public boolean canFlipToNextPage() {
337 return isPageComplete();
340 public boolean isPageComplete() {
341 return (txtName
.getText().length() > 0);
344 private void updatePage() {
346 getWizard().getContainer().updateButtons();
349 public void setPageComplete(boolean complete
) {
350 super.setPageComplete(complete
);
354 TaxonNameBase typeName
= null;
355 if (savedName
!= null) {
356 typeName
= savedName
;
358 if (!txtName
.getText().equals("")) {
359 typeName
= PreferencesController
.getInstanceOfPreferredNameClass();
360 typeName
.setTitleCache(txtName
.getText());
364 ReferenceBase citation
= null;
365 if (savedReference
!= null) {
366 citation
= savedReference
;
368 if (!txtReference
.getText().equals("")) {
369 citation
= Generic
.NewInstance();
370 citation
.setTitleCache(txtReference
.getText());
374 if (typeDesignation
== null) {
375 typeDesignation
= new TemporaryNameTypeDesignation(typeName
, citation
, null,
376 null, btnRejected
.getSelection(), btnConserved
.getSelection(), btnLecto
.getSelection(), btnNotDesignated
.getSelection());
377 typeDesignation
.setLectoType(btnLecto
.getSelection());
379 typeDesignation
.setRejectedType(btnRejected
.getSelection());
380 typeDesignation
.setConservedType(btnConserved
.getSelection());
381 typeDesignation
.setLectoType(btnLecto
.getSelection());
382 typeDesignation
.setNotDesignated(btnNotDesignated
.getSelection());
383 typeDesignation
.setCitation(citation
);
386 typeDesignationsList
.remove(typeDesignation
);
387 typeDesignationsList
.add(typeDesignation
);
391 public class TemporaryNameTypeDesignation
extends
392 NameTypeDesignation
{
403 // public TemporaryNameTypeDesignation() {
404 // super(null, null, null, null, false, false, false);
405 // setLectoType(false);
408 public TemporaryNameTypeDesignation(TaxonNameBase typeName
, ReferenceBase citation
, String citationMicroReference
,
409 String originalNameString
, boolean isRejectedType
, boolean isConservedType
, boolean isLectoType
, boolean isNotDesignated
) {
410 super(typeName
, citation
, citationMicroReference
, originalNameString
,
411 isRejectedType
, isConservedType
, isLectoType
, isNotDesignated
);