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)
89 public void createControl(Composite parent
) {
91 // Create composite for popup dialog
92 Composite container
= new Composite(parent
, SWT
.NULL
);
93 container
.setLayout(new GridLayout());
94 setControl(container
);
97 final Label lblName
= new Label(container
, SWT
.NONE
);
98 lblName
.setText("Choose a name either by searching or entering it as free text:");
100 // Create 3-columned composite for name
101 Composite nameComposite
= new Composite(container
, SWT
.NULL
);
102 nameComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
103 GridLayout gridLayout
= new GridLayout();
104 gridLayout
.numColumns
= 3;
105 gridLayout
.marginHeight
= 0;
106 gridLayout
.marginWidth
= 0;
107 nameComposite
.setLayout(gridLayout
);
110 txtName
= new Text(nameComposite
, SWT
.BORDER
);
111 txtName
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
112 txtName
.addKeyListener(new KeyAdapter() {
114 public void keyReleased(KeyEvent e
) {
119 // Create name search button
120 Button btnSearchName
= new Button(nameComposite
, SWT
.NONE
);
121 btnSearchName
.setEnabled(true);
122 btnSearchName
.setLayoutData(new GridData());
123 btnSearchName
.setText("Search ...");
124 btnSearchName
.addSelectionListener(new SelectionAdapter() {
126 // Popup reference search
127 public void widgetSelected(SelectionEvent e
) {
132 // Create clear name button
133 btnClearName
= new Button(nameComposite
, SWT
.NONE
);
134 btnClearName
.setEnabled(false);
135 btnClearName
.setText("Clear");
136 btnClearName
.addSelectionListener(new SelectionAdapter() {
138 // Clear selected reference
139 public void widgetSelected(SelectionEvent e
) {
144 // Set text to name text if exists, disable ability to edit name
145 if (typeDesignation
!= null && typeDesignation
.getTypeName() != null) {
147 savedName
= typeDesignation
.getTypeName();
148 txtName
.setText(savedName
.getTitleCache());
149 txtName
.setEditable(false);
151 btnClearName
.setEnabled(false);
152 btnSearchName
.setEnabled(false);
155 // Tell user when he is entering a new name
156 Label lblNewNameFeedback
= new Label(container
, SWT
.NONE
);
157 lblNewNameFeedback
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, true, false));
158 lblNewNameFeedback
.setFont(
159 TaxEditorPlugin
.getDefault().italicizeFont(lblNewNameFeedback
.getFont()));
160 lblNewNameFeedback
.setText("Existing names can not be edited.");
162 // Create 2-columned composite for name
163 Composite booleansComposite
= new Composite(container
, SWT
.NULL
);
164 booleansComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
165 GridLayout gridLayout2
= new GridLayout();
166 gridLayout2
.numColumns
= 2;
167 gridLayout2
.marginHeight
= 15;
168 gridLayout2
.marginWidth
= 0;
169 booleansComposite
.setLayout(gridLayout2
);
171 btnRejected
= new Button(booleansComposite
, SWT
.CHECK
);
172 btnRejected
.setText("Is rejected type");
173 btnRejected
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
175 btnConserved
= new Button(booleansComposite
, SWT
.CHECK
);
176 btnConserved
.setText("Is conserved type");
177 btnConserved
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
179 btnLecto
= new Button(booleansComposite
, SWT
.CHECK
);
180 btnLecto
.setText("Is lecto type");
181 btnLecto
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
183 btnNotDesignated
= new Button(booleansComposite
, SWT
.CHECK
);
184 btnNotDesignated
.setText("Is not designated");
185 btnNotDesignated
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
187 // Set any boolean values
188 if (typeDesignation
!= null) {
189 if (typeDesignation
.isRejectedType()) {
190 btnRejected
.setSelection(true);
192 if (typeDesignation
.isConservedType()) {
193 btnConserved
.setSelection(true);
195 if (typeDesignation
.isLectoType()) {
196 btnLecto
.setSelection(true);
198 if (typeDesignation
.isNotDesignated()) {
199 btnNotDesignated
.setSelection(true);
203 // Create reference text
204 final Label lblReference
= new Label(container
, SWT
.NONE
);
205 lblReference
.setText("Choose a reference either by searching or entering it as free text:");
207 // Create 3-columned composite for reference
208 Composite referenceComposite
= new Composite(container
, SWT
.NULL
);
209 referenceComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
210 GridLayout gridLayout3
= new GridLayout();
211 gridLayout3
.numColumns
= 3;
212 gridLayout3
.marginHeight
= 0;
213 gridLayout3
.marginWidth
= 0;
214 referenceComposite
.setLayout(gridLayout3
);
216 // Create reference input
217 txtReference
= new Text(referenceComposite
, SWT
.BORDER
);
218 txtReference
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
220 // Create reference search button
221 Button btnSearchReference
= new Button(referenceComposite
, SWT
.NONE
);
222 btnSearchReference
.setEnabled(true);
223 btnSearchReference
.setLayoutData(new GridData());
224 btnSearchReference
.setText("Search ...");
225 btnSearchReference
.addSelectionListener(new SelectionAdapter() {
227 // Popup reference search
228 public void widgetSelected(SelectionEvent e
) {
229 popupReferenceSearch();
233 // Create clear reference button
234 btnClearReference
= new Button(referenceComposite
, SWT
.NONE
);
235 btnClearReference
.setEnabled(false);
236 btnClearReference
.setText("Clear");
237 btnClearReference
.addSelectionListener(new SelectionAdapter() {
239 // Clear selected reference
240 public void widgetSelected(SelectionEvent e
) {
245 // Set text to reference text if exists
246 if (typeDesignation
!= null && typeDesignation
.getCitation() != null) {
248 savedReference
= typeDesignation
.getCitation();
249 txtReference
.setText(savedReference
.getTitleCache());
250 txtReference
.setEditable(false);
252 btnClearReference
.setEnabled(true);
255 // Tell user when he is entering a new reference
256 Label lblNewRefFeedback
= new Label(container
, SWT
.NONE
);
257 lblNewRefFeedback
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, true, false));
258 lblNewRefFeedback
.setFont(
259 TaxEditorPlugin
.getDefault().italicizeFont(lblNewRefFeedback
.getFont()));
260 lblNewRefFeedback
.setText("Existing references can only be edited in property sheet.");
266 protected void popupNameSearch() {
267 Dialog dialog
= new NameSearchDialog(getShell());
268 Object value
= ((NameSearchDialog
) dialog
).open();
270 if (value
instanceof TaxonNameBase
) {
271 setSavedName((TaxonNameBase
) value
);
276 protected void popupReferenceSearch() {
277 Dialog dialog
= new ReferenceSearchDialog(getShell(),
278 IReferenceSearch
.BIBREF
);
279 Object value
= ((ReferenceSearchDialog
) dialog
).open();
281 if (value
instanceof ReferenceBase
) {
282 setSavedReference((ReferenceBase
) value
);
289 private void setSavedName(TaxonNameBase savedName
) {
291 this.savedName
= savedName
;
293 txtName
.setText(savedName
.getTitleCache());
294 txtName
.setEditable(false);
296 btnClearName
.setEnabled(true);
302 private void setSavedReference(ReferenceBase reference
) {
304 savedReference
= reference
;
306 txtReference
.setText(reference
.getTitleCache());
307 txtReference
.setEditable(false);
309 btnClearReference
.setEnabled(true);
315 protected void clearName() {
319 txtName
.setEditable(true);
321 btnClearName
.setEnabled(false);
327 protected void clearReference() {
328 savedReference
= null;
330 txtReference
.setText("");
331 txtReference
.setEditable(true);
333 btnClearReference
.setEnabled(false);
337 public boolean canFlipToNextPage() {
338 return isPageComplete();
341 public boolean isPageComplete() {
342 return (txtName
.getText().length() > 0);
345 private void updatePage() {
347 getWizard().getContainer().updateButtons();
350 public void setPageComplete(boolean complete
) {
351 super.setPageComplete(complete
);
355 TaxonNameBase typeName
= null;
356 if (savedName
!= null) {
357 typeName
= savedName
;
359 if (!txtName
.getText().equals("")) {
360 typeName
= PreferencesController
.getInstanceOfPreferredNameClass();
361 typeName
.setTitleCache(txtName
.getText());
365 ReferenceBase citation
= null;
366 if (savedReference
!= null) {
367 citation
= savedReference
;
369 if (!txtReference
.getText().equals("")) {
370 citation
= Generic
.NewInstance();
371 citation
.setTitleCache(txtReference
.getText());
375 if (typeDesignation
== null) {
376 typeDesignation
= new TemporaryNameTypeDesignation(typeName
, citation
, null,
377 null, btnRejected
.getSelection(), btnConserved
.getSelection(), btnNotDesignated
.getSelection());
378 typeDesignation
.setLectoType(btnLecto
.getSelection());
380 typeDesignation
.setRejectedType(btnRejected
.getSelection());
381 typeDesignation
.setConservedType(btnConserved
.getSelection());
382 typeDesignation
.setLectoType(btnLecto
.getSelection());
383 typeDesignation
.setNotDesignated(btnNotDesignated
.getSelection());
384 typeDesignation
.setCitation(citation
);
387 typeDesignationsList
.remove(typeDesignation
);
388 typeDesignationsList
.add(typeDesignation
);
392 public class TemporaryNameTypeDesignation
extends
393 NameTypeDesignation
{
404 // public TemporaryNameTypeDesignation() {
405 // super(null, null, null, null, false, false, false);
406 // setLectoType(false);
409 public TemporaryNameTypeDesignation(TaxonNameBase typeName
, ReferenceBase citation
, String citationMicroReference
,
410 String originalNameString
, boolean isRejectedType
, boolean isConservedType
, boolean isNotDesignated
) {
411 super(typeName
, citation
, citationMicroReference
, originalNameString
,
412 isRejectedType
, isConservedType
, isNotDesignated
);