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
;
14 import org
.apache
.log4j
.Logger
;
15 import org
.eclipse
.core
.databinding
.observable
.list
.WritableList
;
16 import org
.eclipse
.core
.runtime
.Assert
;
17 import org
.eclipse
.jface
.wizard
.WizardPage
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.events
.KeyAdapter
;
20 import org
.eclipse
.swt
.events
.KeyEvent
;
21 import org
.eclipse
.swt
.events
.SelectionAdapter
;
22 import org
.eclipse
.swt
.events
.SelectionEvent
;
23 import org
.eclipse
.swt
.layout
.GridData
;
24 import org
.eclipse
.swt
.layout
.GridLayout
;
25 import org
.eclipse
.swt
.widgets
.Button
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.swt
.widgets
.Dialog
;
28 import org
.eclipse
.swt
.widgets
.Label
;
29 import org
.eclipse
.swt
.widgets
.Text
;
31 import eu
.etaxonomy
.cdm
.model
.name
.NameTypeDesignation
;
32 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
33 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
34 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
35 import eu
.etaxonomy
.taxeditor
.editor
.reference
.ReferenceSelectComposite
;
36 import eu
.etaxonomy
.taxeditor
.store
.model
.Resources
;
37 import eu
.etaxonomy
.taxeditor
.store
.preference
.PreferencesUtil
;
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
;
53 private Button btnClearName
;
54 private Button btnRejected
;
55 private Button btnConserved
;
56 private Button btnLecto
;
57 private Button btnNotDesignated
;
59 private WritableList typeDesignationsList
;
61 private ReferenceSelectComposite referenceComposite
;
64 * @param typeDesignation
66 * @param typeDesignationsList
68 public ChooseNameTypeWizardPage(TypeDesignationBase typeDesignation
,
69 TaxonNameBase name
, WritableList typeDesignationsList
) {
72 Assert
.isTrue(typeDesignation
== null || typeDesignation
instanceof NameTypeDesignation
);
74 this.typeDesignation
= (NameTypeDesignation
) typeDesignation
;
76 this.typeDesignationsList
= typeDesignationsList
;
78 setTitle("Create or edit type designation");
79 setDescription("Create or edit type designation for '" + name
.getTitleCache() + "\".");
84 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
86 public void createControl(Composite parent
) {
88 // Create composite for popup dialog
89 Composite container
= new Composite(parent
, SWT
.NULL
);
90 container
.setLayout(new GridLayout());
91 setControl(container
);
94 final Label lblName
= new Label(container
, SWT
.NONE
);
95 lblName
.setText("Choose a name either by searching or entering it as free text:");
97 // Create 3-columned composite for name
98 Composite nameComposite
= new Composite(container
, SWT
.NULL
);
99 nameComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
100 GridLayout gridLayout
= new GridLayout();
101 gridLayout
.numColumns
= 3;
102 gridLayout
.marginHeight
= 0;
103 gridLayout
.marginWidth
= 0;
104 nameComposite
.setLayout(gridLayout
);
107 // TODO replace w NameSelectComposite
108 txtName
= new Text(nameComposite
, SWT
.BORDER
);
109 txtName
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
110 txtName
.addKeyListener(new KeyAdapter() {
112 public void keyReleased(KeyEvent e
) {
117 // Create name search button
118 Button btnSearchName
= new Button(nameComposite
, SWT
.NONE
);
119 btnSearchName
.setEnabled(true);
120 btnSearchName
.setLayoutData(new GridData());
121 btnSearchName
.setText("Search ...");
122 btnSearchName
.addSelectionListener(new SelectionAdapter() {
124 // Popup reference search
125 public void widgetSelected(SelectionEvent e
) {
130 // Create clear name button
131 btnClearName
= new Button(nameComposite
, SWT
.NONE
);
132 btnClearName
.setEnabled(false);
133 btnClearName
.setText("Clear");
134 btnClearName
.addSelectionListener(new SelectionAdapter() {
136 // Clear selected reference
137 public void widgetSelected(SelectionEvent e
) {
142 // Set text to name text if exists, disable ability to edit name
143 if (typeDesignation
!= null && typeDesignation
.getTypeName() != null) {
145 savedName
= typeDesignation
.getTypeName();
146 txtName
.setText(savedName
.getTitleCache());
147 txtName
.setEditable(false);
149 btnClearName
.setEnabled(false);
150 btnSearchName
.setEnabled(false);
153 // Tell user when he is entering a new name
154 Label lblNewNameFeedback
= new Label(container
, SWT
.NONE
);
155 lblNewNameFeedback
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, true, false));
156 lblNewNameFeedback
.setFont(
157 Resources
.italicizeFont(lblNewNameFeedback
.getFont()));
158 lblNewNameFeedback
.setText("Existing names can not be edited.");
160 // Create 2-columned composite for name
161 Composite booleansComposite
= new Composite(container
, SWT
.NULL
);
162 booleansComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
163 GridLayout gridLayout2
= new GridLayout();
164 gridLayout2
.numColumns
= 2;
165 gridLayout2
.marginHeight
= 15;
166 gridLayout2
.marginWidth
= 0;
167 booleansComposite
.setLayout(gridLayout2
);
169 btnRejected
= new Button(booleansComposite
, SWT
.CHECK
);
170 btnRejected
.setText("Is rejected type");
171 btnRejected
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
173 btnConserved
= new Button(booleansComposite
, SWT
.CHECK
);
174 btnConserved
.setText("Is conserved type");
175 btnConserved
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
177 btnLecto
= new Button(booleansComposite
, SWT
.CHECK
);
178 btnLecto
.setText("Is lecto type");
179 btnLecto
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
181 btnNotDesignated
= new Button(booleansComposite
, SWT
.CHECK
);
182 btnNotDesignated
.setText("Is not designated");
183 btnNotDesignated
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
185 // Set any boolean values
186 if (typeDesignation
!= null) {
187 if (typeDesignation
.isRejectedType()) {
188 btnRejected
.setSelection(true);
190 if (typeDesignation
.isConservedType()) {
191 btnConserved
.setSelection(true);
193 if (typeDesignation
.isLectoType()) {
194 btnLecto
.setSelection(true);
196 if (typeDesignation
.isNotDesignated()) {
197 btnNotDesignated
.setSelection(true);
201 // Create reference input composite
202 referenceComposite
= new ReferenceSelectComposite(container
);
204 // Set text to reference text if exists
205 if (typeDesignation
!= null && typeDesignation
.getCitation() != null) {
206 referenceComposite
.setMicroReference(typeDesignation
.getCitationMicroReference());
207 if (typeDesignation
.getCitation() != null) {
208 referenceComposite
.setReference(typeDesignation
.getCitation());
216 protected void popupNameSearch() {
217 Dialog dialog
= new NameSearchDialog(getShell());
218 Object value
= ((NameSearchDialog
) dialog
).open();
220 if (value
instanceof TaxonNameBase
) {
221 setSavedName((TaxonNameBase
) value
);
229 private void setSavedName(TaxonNameBase savedName
) {
231 this.savedName
= savedName
;
233 txtName
.setText(savedName
.getTitleCache());
234 txtName
.setEditable(false);
236 btnClearName
.setEnabled(true);
242 protected void clearName() {
246 txtName
.setEditable(true);
248 btnClearName
.setEnabled(false);
252 public boolean canFlipToNextPage() {
253 return isPageComplete();
256 public boolean isPageComplete() {
257 return (txtName
.getText().length() > 0);
260 private void updatePage() {
262 getWizard().getContainer().updateButtons();
265 public void setPageComplete(boolean complete
) {
266 super.setPageComplete(complete
);
270 TaxonNameBase typeName
= null;
271 if (savedName
!= null) {
272 typeName
= savedName
;
274 if (!txtName
.getText().equals("")) {
275 typeName
= PreferencesUtil
.getInstanceOfPreferredNameClass();
276 typeName
.setTitleCache(txtName
.getText());
280 ReferenceBase citation
= referenceComposite
.getReference();
281 String citationMicroReference
= referenceComposite
.getMicroReference();
283 if (typeDesignation
== null) {
284 typeDesignation
= new TemporaryNameTypeDesignation(typeName
, citation
, citationMicroReference
,
285 null, btnRejected
.getSelection(), btnConserved
.getSelection(), btnLecto
.getSelection(), btnNotDesignated
.getSelection());
286 typeDesignation
.setLectoType(btnLecto
.getSelection());
288 typeDesignation
.setRejectedType(btnRejected
.getSelection());
289 typeDesignation
.setConservedType(btnConserved
.getSelection());
290 typeDesignation
.setLectoType(btnLecto
.getSelection());
291 typeDesignation
.setNotDesignated(btnNotDesignated
.getSelection());
292 typeDesignation
.setCitation(citation
);
293 typeDesignation
.setCitationMicroReference(citationMicroReference
);
296 typeDesignationsList
.remove(typeDesignation
);
297 typeDesignationsList
.add(typeDesignation
);
301 public class TemporaryNameTypeDesignation
extends
302 NameTypeDesignation
{
304 public TemporaryNameTypeDesignation(TaxonNameBase typeName
, ReferenceBase citation
, String citationMicroReference
,
305 String originalNameString
, boolean isRejectedType
, boolean isConservedType
, boolean isLectoType
, boolean isNotDesignated
) {
306 super(typeName
, citation
, citationMicroReference
, originalNameString
,
307 isRejectedType
, isConservedType
, isLectoType
, isNotDesignated
);