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
.custom
.CCombo
;
18 import org
.eclipse
.swt
.events
.KeyAdapter
;
19 import org
.eclipse
.swt
.events
.KeyEvent
;
20 import org
.eclipse
.swt
.events
.SelectionAdapter
;
21 import org
.eclipse
.swt
.events
.SelectionEvent
;
22 import org
.eclipse
.swt
.layout
.GridData
;
23 import org
.eclipse
.swt
.layout
.GridLayout
;
24 import org
.eclipse
.swt
.widgets
.Button
;
25 import org
.eclipse
.swt
.widgets
.Composite
;
26 import org
.eclipse
.swt
.widgets
.Dialog
;
27 import org
.eclipse
.swt
.widgets
.Label
;
28 import org
.eclipse
.swt
.widgets
.Text
;
30 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
31 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
32 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
33 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
34 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
35 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationStatus
;
36 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnitBase
;
37 import eu
.etaxonomy
.cdm
.model
.occurrence
.Specimen
;
38 import eu
.etaxonomy
.cdm
.model
.reference
.Generic
;
39 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
40 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
41 import eu
.etaxonomy
.taxeditor
.model
.CdmSessionDataRepository
;
42 import eu
.etaxonomy
.taxeditor
.propertysheet
.reference
.IReferenceSearch
;
43 import eu
.etaxonomy
.taxeditor
.propertysheet
.reference
.ReferenceSearchDialog
;
50 public class ChooseSpecimenTypeWizardPage
extends WizardPage
{
51 private static Logger logger
= Logger
52 .getLogger(ChooseSpecimenTypeWizardPage
.class);
54 private TaxonNameBase name
;
55 private SpecimenTypeDesignation typeDesignation
;
56 private WritableList typeDesignationsList
;
58 private ReferenceBase savedReference
;
60 private CCombo statusCombo
;
61 private Text txtDesignationType
;
62 private TypeDesignationStatus
[] typeStatusArray
;
63 private Text txtReference
;
64 private Button btnClearReference
;
68 * @param typeDesignation
69 * @param typeDesignationsList
71 public ChooseSpecimenTypeWizardPage(
72 TypeDesignationBase typeDesignation
, TaxonNameBase name
, WritableList typeDesignationsList
) {
75 Assert
.isTrue(typeDesignation
== null || typeDesignation
instanceof SpecimenTypeDesignation
,"");
77 this.typeDesignation
= (SpecimenTypeDesignation
) typeDesignation
;
79 this.typeDesignationsList
= typeDesignationsList
;
81 setTitle("Create or edit type designation");
82 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 lblChooseStatus
= new Label(container
, SWT
.NONE
);
98 lblChooseStatus
.setText("Choose designation type status:");
100 // Create designation type status dropdown
101 statusCombo
= new CCombo(container
, SWT
.BORDER
);
102 statusCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
103 TermVocabulary
<TypeDesignationStatus
> typeStatusSet
= CdmSessionDataRepository
.getDefault().getTypeDesignationStatus();
104 typeStatusArray
= new TypeDesignationStatus
[CdmSessionDataRepository
.getDefault().getTypeDesignationStatus().size()];
106 int selectedIndex
= -1;
107 for (TypeDesignationStatus typeStatus
:
108 CdmSessionDataRepository
.getDefault().getTypeDesignationStatus()) {
109 String label
= typeStatus
.getLabel();
110 typeStatusArray
[i
] = typeStatus
;
112 if (typeDesignation
!= null && typeDesignation
.getTypeStatus() != null) {
113 if (typeStatus
.equals(typeDesignation
.getTypeStatus())) {
119 statusCombo
.add(label
);
122 // Set menu to type designation status if exists
123 statusCombo
.select(selectedIndex
);
125 statusCombo
.addSelectionListener(new SelectionAdapter() {
127 public void widgetSelected(SelectionEvent e
) {
133 final Label lblEnterText
= new Label(container
, SWT
.NONE
);
134 lblEnterText
.setText("Enter designation type text:");
136 txtDesignationType
= new Text(container
, SWT
.BORDER
);
137 txtDesignationType
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
138 txtDesignationType
.addKeyListener(new KeyAdapter() {
140 public void keyReleased(KeyEvent e
) {
145 // Set text to specimen text if exists
146 if (typeDesignation
!= null && typeDesignation
.getTypeSpecimen() != null) {
147 txtDesignationType
.setText(typeDesignation
.getTypeSpecimen().getTitleCache());
150 // Create reference text
151 final Label lblReference
= new Label(container
, SWT
.NONE
);
152 lblReference
.setText("Choose a reference either by searching or entering it as free text:");
154 // Create 3-columned composite for reference
155 Composite referenceComposite
= new Composite(container
, SWT
.NULL
);
156 referenceComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
157 GridLayout gridLayout
= new GridLayout();
158 gridLayout
.numColumns
= 3;
159 gridLayout
.marginHeight
= 0;
160 gridLayout
.marginWidth
= 0;
161 referenceComposite
.setLayout(gridLayout
);
163 // Create reference input
164 txtReference
= new Text(referenceComposite
, SWT
.BORDER
);
165 txtReference
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
167 // Create reference search button
168 Button btnSearchReference
= new Button(referenceComposite
, SWT
.NONE
);
169 btnSearchReference
.setEnabled(true);
170 btnSearchReference
.setLayoutData(new GridData());
171 btnSearchReference
.setText("Search ...");
172 btnSearchReference
.addSelectionListener(new SelectionAdapter() {
174 // Popup reference search
175 public void widgetSelected(SelectionEvent e
) {
180 // Create clear reference button
181 btnClearReference
= new Button(referenceComposite
, SWT
.NONE
);
182 btnClearReference
.setEnabled(false);
183 btnClearReference
.setText("Clear");
184 btnClearReference
.addSelectionListener(new SelectionAdapter() {
186 // Clear selected reference
187 public void widgetSelected(SelectionEvent e
) {
192 // Set text to reference text if exists
193 if (typeDesignation
!= null && typeDesignation
.getCitation() != null) {
195 savedReference
= typeDesignation
.getCitation();
196 txtReference
.setText(savedReference
.getTitleCache());
197 txtReference
.setEditable(false);
199 btnClearReference
.setEnabled(true);
202 // Tell user when he is entering a new reference
203 Label lblNewRefFeedback
= new Label(container
, SWT
.NONE
);
204 lblNewRefFeedback
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, true, false));
205 lblNewRefFeedback
.setFont(
206 TaxEditorPlugin
.getDefault().italicizeFont(lblNewRefFeedback
.getFont()));
207 lblNewRefFeedback
.setText("Existing references can only be edited in property sheet.");
213 protected void popupSearch() {
214 Dialog dialog
= new ReferenceSearchDialog(getShell(),
215 IReferenceSearch
.BIBREF
);
216 Object value
= ((ReferenceSearchDialog
) dialog
).open();
218 if (value
instanceof ReferenceBase
) {
219 setSavedReference((ReferenceBase
) value
);
226 private void setSavedReference(ReferenceBase reference
) {
228 savedReference
= reference
;
230 txtReference
.setText(reference
.getTitleCache());
231 txtReference
.setEditable(false);
233 btnClearReference
.setEnabled(true);
239 protected void clearReference() {
240 savedReference
= null;
242 txtReference
.setText("");
243 txtReference
.setEditable(true);
245 btnClearReference
.setEnabled(false);
249 public boolean canFlipToNextPage() {
250 return isPageComplete();
253 public boolean isPageComplete() {
254 return (statusCombo
.getSelectionIndex() > -1
255 && txtDesignationType
.getText().length() > 0);
258 private void updatePage() {
260 getWizard().getContainer().updateButtons();
263 public void setPageComplete(boolean complete
) {
264 super.setPageComplete(complete
);
268 ReferenceBase citation
= null;
269 if (savedReference
!= null) {
270 citation
= savedReference
;
272 if (!txtReference
.getText().equals("")) {
273 citation
= Generic
.NewInstance();
274 citation
.setTitleCache(txtReference
.getText());
278 TypeDesignationStatus status
= typeStatusArray
[statusCombo
.getSelectionIndex()];
281 if (typeDesignation
== null || typeDesignation
.getTypeSpecimen() == null) {
282 specimen
= Specimen
.NewInstance();
284 specimen
= CdmBase
.deproxy(typeDesignation
.getTypeSpecimen(), Specimen
.class);
286 specimen
.setTitleCache(txtDesignationType
.getText());
288 if (typeDesignation
== null) {
289 typeDesignation
= new TemporarySpecimenTypeDesignation(specimen
, status
,
290 citation
, null, null, true);
292 typeDesignation
.setTypeSpecimen(specimen
);
293 typeDesignation
.setTypeStatus(status
);
294 typeDesignation
.setCitation(citation
);
297 typeDesignationsList
.remove(typeDesignation
);
298 typeDesignationsList
.add(typeDesignation
);
302 public class TemporarySpecimenTypeDesignation
extends
303 SpecimenTypeDesignation
{
305 TemporarySpecimenTypeDesignation(DerivedUnitBase specimen
, TypeDesignationStatus status
, ReferenceBase citation
, String citationMicroReference
,
306 String originalNameString
, boolean isNotDesignated
) {
307 super(specimen
, status
, citation
, citationMicroReference
,
308 originalNameString
, isNotDesignated
);