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
.TaxEditorPlugin
;
34 import eu
.etaxonomy
.taxeditor
.controller
.PreferencesController
;
35 import eu
.etaxonomy
.taxeditor
.editor
.reference
.ReferenceSelectComposite
;
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() + "\".");
82 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
84 public void createControl(Composite parent
) {
86 // Create composite for popup dialog
87 Composite container
= new Composite(parent
, SWT
.NULL
);
88 container
.setLayout(new GridLayout());
89 setControl(container
);
92 final Label lblName
= new Label(container
, SWT
.NONE
);
93 lblName
.setText("Choose a name either by searching or entering it as free text:");
95 // Create 3-columned composite for name
96 Composite nameComposite
= new Composite(container
, SWT
.NULL
);
97 nameComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
98 GridLayout gridLayout
= new GridLayout();
99 gridLayout
.numColumns
= 3;
100 gridLayout
.marginHeight
= 0;
101 gridLayout
.marginWidth
= 0;
102 nameComposite
.setLayout(gridLayout
);
105 txtName
= new Text(nameComposite
, SWT
.BORDER
);
106 txtName
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
107 txtName
.addKeyListener(new KeyAdapter() {
109 public void keyReleased(KeyEvent e
) {
114 // Create name search button
115 Button btnSearchName
= new Button(nameComposite
, SWT
.NONE
);
116 btnSearchName
.setEnabled(true);
117 btnSearchName
.setLayoutData(new GridData());
118 btnSearchName
.setText("Search ...");
119 btnSearchName
.addSelectionListener(new SelectionAdapter() {
121 // Popup reference search
122 public void widgetSelected(SelectionEvent e
) {
127 // Create clear name button
128 btnClearName
= new Button(nameComposite
, SWT
.NONE
);
129 btnClearName
.setEnabled(false);
130 btnClearName
.setText("Clear");
131 btnClearName
.addSelectionListener(new SelectionAdapter() {
133 // Clear selected reference
134 public void widgetSelected(SelectionEvent e
) {
139 // Set text to name text if exists, disable ability to edit name
140 if (typeDesignation
!= null && typeDesignation
.getTypeName() != null) {
142 savedName
= typeDesignation
.getTypeName();
143 txtName
.setText(savedName
.getTitleCache());
144 txtName
.setEditable(false);
146 btnClearName
.setEnabled(false);
147 btnSearchName
.setEnabled(false);
150 // Tell user when he is entering a new name
151 Label lblNewNameFeedback
= new Label(container
, SWT
.NONE
);
152 lblNewNameFeedback
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, true, false));
153 lblNewNameFeedback
.setFont(
154 TaxEditorPlugin
.getDefault().italicizeFont(lblNewNameFeedback
.getFont()));
155 lblNewNameFeedback
.setText("Existing names can not be edited.");
157 // Create 2-columned composite for name
158 Composite booleansComposite
= new Composite(container
, SWT
.NULL
);
159 booleansComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
160 GridLayout gridLayout2
= new GridLayout();
161 gridLayout2
.numColumns
= 2;
162 gridLayout2
.marginHeight
= 15;
163 gridLayout2
.marginWidth
= 0;
164 booleansComposite
.setLayout(gridLayout2
);
166 btnRejected
= new Button(booleansComposite
, SWT
.CHECK
);
167 btnRejected
.setText("Is rejected type");
168 btnRejected
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
170 btnConserved
= new Button(booleansComposite
, SWT
.CHECK
);
171 btnConserved
.setText("Is conserved type");
172 btnConserved
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
174 btnLecto
= new Button(booleansComposite
, SWT
.CHECK
);
175 btnLecto
.setText("Is lecto type");
176 btnLecto
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
178 btnNotDesignated
= new Button(booleansComposite
, SWT
.CHECK
);
179 btnNotDesignated
.setText("Is not designated");
180 btnNotDesignated
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
182 // Set any boolean values
183 if (typeDesignation
!= null) {
184 if (typeDesignation
.isRejectedType()) {
185 btnRejected
.setSelection(true);
187 if (typeDesignation
.isConservedType()) {
188 btnConserved
.setSelection(true);
190 if (typeDesignation
.isLectoType()) {
191 btnLecto
.setSelection(true);
193 if (typeDesignation
.isNotDesignated()) {
194 btnNotDesignated
.setSelection(true);
198 // Create reference input composite
199 referenceComposite
= new ReferenceSelectComposite(container
);
201 // Set text to reference text if exists
202 if (typeDesignation
!= null && typeDesignation
.getCitation() != null) {
203 referenceComposite
.setMicroReference(typeDesignation
.getCitationMicroReference());
204 if (typeDesignation
.getCitation() != null) {
205 referenceComposite
.setReference(typeDesignation
.getCitation());
213 protected void popupNameSearch() {
214 Dialog dialog
= new NameSearchDialog(getShell());
215 Object value
= ((NameSearchDialog
) dialog
).open();
217 if (value
instanceof TaxonNameBase
) {
218 setSavedName((TaxonNameBase
) value
);
226 private void setSavedName(TaxonNameBase savedName
) {
228 this.savedName
= savedName
;
230 txtName
.setText(savedName
.getTitleCache());
231 txtName
.setEditable(false);
233 btnClearName
.setEnabled(true);
239 protected void clearName() {
243 txtName
.setEditable(true);
245 btnClearName
.setEnabled(false);
249 public boolean canFlipToNextPage() {
250 return isPageComplete();
253 public boolean isPageComplete() {
254 return (txtName
.getText().length() > 0);
257 private void updatePage() {
259 getWizard().getContainer().updateButtons();
262 public void setPageComplete(boolean complete
) {
263 super.setPageComplete(complete
);
267 TaxonNameBase typeName
= null;
268 if (savedName
!= null) {
269 typeName
= savedName
;
271 if (!txtName
.getText().equals("")) {
272 typeName
= PreferencesController
.getInstanceOfPreferredNameClass();
273 typeName
.setTitleCache(txtName
.getText());
277 ReferenceBase citation
= referenceComposite
.getReference();
278 String citationMicroReference
= referenceComposite
.getMicroReference();
280 if (typeDesignation
== null) {
281 typeDesignation
= new TemporaryNameTypeDesignation(typeName
, citation
, citationMicroReference
,
282 null, btnRejected
.getSelection(), btnConserved
.getSelection(), btnLecto
.getSelection(), btnNotDesignated
.getSelection());
283 typeDesignation
.setLectoType(btnLecto
.getSelection());
285 typeDesignation
.setRejectedType(btnRejected
.getSelection());
286 typeDesignation
.setConservedType(btnConserved
.getSelection());
287 typeDesignation
.setLectoType(btnLecto
.getSelection());
288 typeDesignation
.setNotDesignated(btnNotDesignated
.getSelection());
289 typeDesignation
.setCitation(citation
);
290 typeDesignation
.setCitationMicroReference(citationMicroReference
);
293 typeDesignationsList
.remove(typeDesignation
);
294 typeDesignationsList
.add(typeDesignation
);
298 public class TemporaryNameTypeDesignation
extends
299 NameTypeDesignation
{
310 // public TemporaryNameTypeDesignation() {
311 // super(null, null, null, null, false, false, false);
312 // setLectoType(false);
315 public TemporaryNameTypeDesignation(TaxonNameBase typeName
, ReferenceBase citation
, String citationMicroReference
,
316 String originalNameString
, boolean isRejectedType
, boolean isConservedType
, boolean isLectoType
, boolean isNotDesignated
) {
317 super(typeName
, citation
, citationMicroReference
, originalNameString
,
318 isRejectedType
, isConservedType
, isLectoType
, isNotDesignated
);