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
.ReferenceBase
;
33 import eu
.etaxonomy
.taxeditor
.editor
.reference
.ReferenceSelectComposite
;
34 import eu
.etaxonomy
.taxeditor
.store
.model
.Resources
;
35 import eu
.etaxonomy
.taxeditor
.store
.preference
.PreferencesUtil
;
42 public class ChooseNameTypeWizardPage
extends WizardPage
{
43 private static Logger logger
= Logger
44 .getLogger(ChooseNameTypeWizardPage
.class);
46 private TaxonNameBase
<?
, ?
> name
;
47 private NameTypeDesignation typeDesignation
;
48 private TaxonNameBase
<?
, ?
> savedName
;
51 private Button btnClearName
;
52 private Button btnRejected
;
53 private Button btnConserved
;
54 private Button btnLecto
;
55 private Button btnNotDesignated
;
57 private WritableList typeDesignationsList
;
59 private ReferenceSelectComposite referenceComposite
;
62 * @param typeDesignation
64 * @param typeDesignationsList
66 public ChooseNameTypeWizardPage(TypeDesignationBase
<?
> typeDesignation
,
67 TaxonNameBase
<?
, ?
> name
, WritableList typeDesignationsList
) {
70 Assert
.isTrue(typeDesignation
== null || typeDesignation
instanceof NameTypeDesignation
);
72 this.typeDesignation
= (NameTypeDesignation
) typeDesignation
;
74 this.typeDesignationsList
= typeDesignationsList
;
76 setTitle("Create or edit type designation");
77 setDescription("Create or edit type designation for '" + name
.getTitleCache() + "\".");
78 logger
.trace(this.getClass().getSimpleName() + " created.");
83 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
85 public void createControl(Composite parent
) {
87 // Create composite for popup dialog
88 Composite container
= new Composite(parent
, SWT
.NULL
);
89 container
.setLayout(new GridLayout());
90 setControl(container
);
93 final Label lblName
= new Label(container
, SWT
.NONE
);
94 lblName
.setText("Choose a name either by searching or entering it as free text:");
96 // Create 3-columned composite for name
97 Composite nameComposite
= new Composite(container
, SWT
.NULL
);
98 nameComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
99 GridLayout gridLayout
= new GridLayout();
100 gridLayout
.numColumns
= 3;
101 gridLayout
.marginHeight
= 0;
102 gridLayout
.marginWidth
= 0;
103 nameComposite
.setLayout(gridLayout
);
106 // TODO replace w NameSelectComposite
107 txtName
= new Text(nameComposite
, SWT
.BORDER
);
108 txtName
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
109 txtName
.addKeyListener(new KeyAdapter() {
111 public void keyReleased(KeyEvent e
) {
116 // Create name search button
117 Button btnSearchName
= new Button(nameComposite
, SWT
.NONE
);
118 btnSearchName
.setEnabled(true);
119 btnSearchName
.setLayoutData(new GridData());
120 btnSearchName
.setText("Search ...");
121 btnSearchName
.addSelectionListener(new SelectionAdapter() {
123 // Popup reference search
124 public void widgetSelected(SelectionEvent e
) {
129 // Create clear name button
130 btnClearName
= new Button(nameComposite
, SWT
.NONE
);
131 btnClearName
.setEnabled(false);
132 btnClearName
.setText("Clear");
133 btnClearName
.addSelectionListener(new SelectionAdapter() {
135 // Clear selected reference
136 public void widgetSelected(SelectionEvent e
) {
141 // Set text to name text if exists, disable ability to edit name
142 if (typeDesignation
!= null && typeDesignation
.getTypeName() != null) {
144 savedName
= typeDesignation
.getTypeName();
145 txtName
.setText(savedName
.getTitleCache());
146 txtName
.setEditable(false);
148 btnClearName
.setEnabled(false);
149 btnSearchName
.setEnabled(false);
152 // Tell user when he is entering a new name
153 Label lblNewNameFeedback
= new Label(container
, SWT
.NONE
);
154 lblNewNameFeedback
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, true, false));
155 lblNewNameFeedback
.setFont(
156 Resources
.italicizeFont(lblNewNameFeedback
.getFont()));
157 lblNewNameFeedback
.setText("Existing names can not be edited.");
159 // Create 2-columned composite for name
160 Composite booleansComposite
= new Composite(container
, SWT
.NULL
);
161 booleansComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
162 GridLayout gridLayout2
= new GridLayout();
163 gridLayout2
.numColumns
= 2;
164 gridLayout2
.marginHeight
= 15;
165 gridLayout2
.marginWidth
= 0;
166 booleansComposite
.setLayout(gridLayout2
);
168 btnRejected
= new Button(booleansComposite
, SWT
.CHECK
);
169 btnRejected
.setText("Is rejected type");
170 btnRejected
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
172 btnConserved
= new Button(booleansComposite
, SWT
.CHECK
);
173 btnConserved
.setText("Is conserved type");
174 btnConserved
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
176 btnLecto
= new Button(booleansComposite
, SWT
.CHECK
);
177 btnLecto
.setText("Is lecto type");
178 btnLecto
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
180 btnNotDesignated
= new Button(booleansComposite
, SWT
.CHECK
);
181 btnNotDesignated
.setText("Is not designated");
182 btnNotDesignated
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
184 // Set any boolean values
185 if (typeDesignation
!= null) {
186 if (typeDesignation
.isRejectedType()) {
187 btnRejected
.setSelection(true);
189 if (typeDesignation
.isConservedType()) {
190 btnConserved
.setSelection(true);
192 if (typeDesignation
.isLectoType()) {
193 btnLecto
.setSelection(true);
195 if (typeDesignation
.isNotDesignated()) {
196 btnNotDesignated
.setSelection(true);
200 // Create reference input composite
201 referenceComposite
= new ReferenceSelectComposite(container
);
203 // Set text to reference text if exists
204 if (typeDesignation
!= null && typeDesignation
.getCitation() != null) {
205 referenceComposite
.setMicroReference(typeDesignation
.getCitationMicroReference());
206 if (typeDesignation
.getCitation() != null) {
207 referenceComposite
.setReference(typeDesignation
.getCitation());
215 protected void popupNameSearch() {
216 Dialog dialog
= new NameSearchDialog(getShell());
217 Object value
= ((NameSearchDialog
) dialog
).open();
219 if (value
instanceof TaxonNameBase
) {
220 setSavedName((TaxonNameBase
<?
, ?
>) value
);
228 private void setSavedName(TaxonNameBase
<?
, ?
> savedName
) {
230 this.savedName
= savedName
;
232 txtName
.setText(savedName
.getTitleCache());
233 txtName
.setEditable(false);
235 btnClearName
.setEnabled(true);
241 protected void clearName() {
245 txtName
.setEditable(true);
247 btnClearName
.setEnabled(false);
251 public boolean canFlipToNextPage() {
252 return isPageComplete();
255 public boolean isPageComplete() {
256 return (txtName
.getText().length() > 0);
259 private void updatePage() {
261 getWizard().getContainer().updateButtons();
264 public void setPageComplete(boolean complete
) {
265 super.setPageComplete(complete
);
269 TaxonNameBase
<?
, ?
> typeName
= null;
270 if (savedName
!= null) {
271 typeName
= savedName
;
273 if (!txtName
.getText().equals("")) {
274 typeName
= PreferencesUtil
.getInstanceOfPreferredNameClass();
275 typeName
.setTitleCache(txtName
.getText());
279 ReferenceBase
<?
> citation
= referenceComposite
.getReference();
280 String citationMicroReference
= referenceComposite
.getMicroReference();
282 if (typeDesignation
== null) {
283 typeDesignation
= new TemporaryNameTypeDesignation(typeName
, citation
, citationMicroReference
,
284 null, btnRejected
.getSelection(), btnConserved
.getSelection(), btnLecto
.getSelection(), btnNotDesignated
.getSelection());
285 typeDesignation
.setLectoType(btnLecto
.getSelection());
287 typeDesignation
.setRejectedType(btnRejected
.getSelection());
288 typeDesignation
.setConservedType(btnConserved
.getSelection());
289 typeDesignation
.setLectoType(btnLecto
.getSelection());
290 typeDesignation
.setNotDesignated(btnNotDesignated
.getSelection());
291 typeDesignation
.setCitation(citation
);
292 typeDesignation
.setCitationMicroReference(citationMicroReference
);
295 typeDesignationsList
.remove(typeDesignation
);
296 typeDesignationsList
.add(typeDesignation
);
300 public class TemporaryNameTypeDesignation
extends
301 NameTypeDesignation
{
306 private static final long serialVersionUID
= 7309597024482795166L;
308 public TemporaryNameTypeDesignation(TaxonNameBase
<?
, ?
> typeName
, ReferenceBase
<?
> citation
, String citationMicroReference
,
309 String originalNameString
, boolean isRejectedType
, boolean isConservedType
, boolean isLectoType
, boolean isNotDesignated
) {
310 super(typeName
, citation
, citationMicroReference
, originalNameString
,
311 isRejectedType
, isConservedType
, isLectoType
, isNotDesignated
);