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)
88 public void createControl(Composite parent
) {
90 // Create composite for popup dialog
91 Composite container
= new Composite(parent
, SWT
.NULL
);
92 container
.setLayout(new GridLayout());
93 setControl(container
);
96 final Label lblChooseStatus
= new Label(container
, SWT
.NONE
);
97 lblChooseStatus
.setText("Choose designation type status:");
99 // Create designation type status dropdown
100 statusCombo
= new CCombo(container
, SWT
.BORDER
);
101 statusCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
102 TermVocabulary
<TypeDesignationStatus
> typeStatusSet
= CdmSessionDataRepository
.getDefault().getTypeDesignationStatus();
103 typeStatusArray
= new TypeDesignationStatus
[CdmSessionDataRepository
.getDefault().getTypeDesignationStatus().size()];
105 int selectedIndex
= -1;
106 for (TypeDesignationStatus typeStatus
:
107 CdmSessionDataRepository
.getDefault().getTypeDesignationStatus()) {
108 String label
= typeStatus
.getLabel();
109 typeStatusArray
[i
] = typeStatus
;
111 if (typeDesignation
!= null && typeDesignation
.getTypeStatus() != null) {
112 if (typeStatus
.equals(typeDesignation
.getTypeStatus())) {
118 statusCombo
.add(label
);
121 // Set menu to type designation status if exists
122 statusCombo
.select(selectedIndex
);
124 statusCombo
.addSelectionListener(new SelectionAdapter() {
126 public void widgetSelected(SelectionEvent e
) {
132 final Label lblEnterText
= new Label(container
, SWT
.NONE
);
133 lblEnterText
.setText("Enter designation type text:");
135 txtDesignationType
= new Text(container
, SWT
.BORDER
);
136 txtDesignationType
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
137 txtDesignationType
.addKeyListener(new KeyAdapter() {
139 public void keyReleased(KeyEvent e
) {
144 // Set text to specimen text if exists
145 if (typeDesignation
!= null && typeDesignation
.getTypeSpecimen() != null) {
146 txtDesignationType
.setText(typeDesignation
.getTypeSpecimen().getTitleCache());
149 // Create reference text
150 final Label lblReference
= new Label(container
, SWT
.NONE
);
151 lblReference
.setText("Choose a reference either by searching or entering it as free text:");
153 // Create 3-columned composite for reference
154 Composite referenceComposite
= new Composite(container
, SWT
.NULL
);
155 referenceComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
156 GridLayout gridLayout
= new GridLayout();
157 gridLayout
.numColumns
= 3;
158 gridLayout
.marginHeight
= 0;
159 gridLayout
.marginWidth
= 0;
160 referenceComposite
.setLayout(gridLayout
);
162 // Create reference input
163 txtReference
= new Text(referenceComposite
, SWT
.BORDER
);
164 txtReference
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
166 // Create reference search button
167 Button btnSearchReference
= new Button(referenceComposite
, SWT
.NONE
);
168 btnSearchReference
.setEnabled(true);
169 btnSearchReference
.setLayoutData(new GridData());
170 btnSearchReference
.setText("Search ...");
171 btnSearchReference
.addSelectionListener(new SelectionAdapter() {
173 // Popup reference search
174 public void widgetSelected(SelectionEvent e
) {
179 // Create clear reference button
180 btnClearReference
= new Button(referenceComposite
, SWT
.NONE
);
181 btnClearReference
.setEnabled(false);
182 btnClearReference
.setText("Clear");
183 btnClearReference
.addSelectionListener(new SelectionAdapter() {
185 // Clear selected reference
186 public void widgetSelected(SelectionEvent e
) {
191 // Set text to reference text if exists
192 if (typeDesignation
!= null && typeDesignation
.getCitation() != null) {
194 savedReference
= typeDesignation
.getCitation();
195 txtReference
.setText(savedReference
.getTitleCache());
196 txtReference
.setEditable(false);
198 btnClearReference
.setEnabled(true);
201 // Tell user when he is entering a new reference
202 Label lblNewRefFeedback
= new Label(container
, SWT
.NONE
);
203 lblNewRefFeedback
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, true, false));
204 lblNewRefFeedback
.setFont(
205 TaxEditorPlugin
.getDefault().italicizeFont(lblNewRefFeedback
.getFont()));
206 lblNewRefFeedback
.setText("Existing references can only be edited in property sheet.");
212 protected void popupSearch() {
213 Dialog dialog
= new ReferenceSearchDialog(getShell(),
214 IReferenceSearch
.BIBREF
);
215 Object value
= ((ReferenceSearchDialog
) dialog
).open();
217 if (value
instanceof ReferenceBase
) {
218 setSavedReference((ReferenceBase
) value
);
225 private void setSavedReference(ReferenceBase reference
) {
227 savedReference
= reference
;
229 txtReference
.setText(reference
.getTitleCache());
230 txtReference
.setEditable(false);
232 btnClearReference
.setEnabled(true);
238 protected void clearReference() {
239 savedReference
= null;
241 txtReference
.setText("");
242 txtReference
.setEditable(true);
244 btnClearReference
.setEnabled(false);
248 public boolean canFlipToNextPage() {
249 return isPageComplete();
252 public boolean isPageComplete() {
253 return (statusCombo
.getSelectionIndex() > -1
254 && txtDesignationType
.getText().length() > 0);
257 private void updatePage() {
259 getWizard().getContainer().updateButtons();
262 public void setPageComplete(boolean complete
) {
263 super.setPageComplete(complete
);
267 ReferenceBase citation
= null;
268 if (savedReference
!= null) {
269 citation
= savedReference
;
271 if (!txtReference
.getText().equals("")) {
272 citation
= Generic
.NewInstance();
273 citation
.setTitleCache(txtReference
.getText());
277 TypeDesignationStatus status
= typeStatusArray
[statusCombo
.getSelectionIndex()];
280 if (typeDesignation
== null || typeDesignation
.getTypeSpecimen() == null) {
281 specimen
= Specimen
.NewInstance();
283 specimen
= CdmBase
.deproxy(typeDesignation
.getTypeSpecimen(), Specimen
.class);
285 specimen
.setTitleCache(txtDesignationType
.getText());
287 if (typeDesignation
== null) {
288 typeDesignation
= new TemporarySpecimenTypeDesignation(specimen
, status
,
289 citation
, null, null, true);
291 typeDesignation
.setTypeSpecimen(specimen
);
292 typeDesignation
.setTypeStatus(status
);
293 typeDesignation
.setCitation(citation
);
296 typeDesignationsList
.remove(typeDesignation
);
297 typeDesignationsList
.add(typeDesignation
);
301 public class TemporarySpecimenTypeDesignation
extends
302 SpecimenTypeDesignation
{
304 TemporarySpecimenTypeDesignation(DerivedUnitBase specimen
, TypeDesignationStatus status
, ReferenceBase citation
, String citationMicroReference
,
305 String originalNameString
, boolean isNotDesignated
) {
306 super(specimen
, status
, citation
, citationMicroReference
,
307 originalNameString
, isNotDesignated
);