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
.jface
.wizard
.WizardPage
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.custom
.CCombo
;
16 import org
.eclipse
.swt
.events
.KeyAdapter
;
17 import org
.eclipse
.swt
.events
.KeyEvent
;
18 import org
.eclipse
.swt
.events
.SelectionAdapter
;
19 import org
.eclipse
.swt
.events
.SelectionEvent
;
20 import org
.eclipse
.swt
.layout
.GridData
;
21 import org
.eclipse
.swt
.layout
.GridLayout
;
22 import org
.eclipse
.swt
.widgets
.Composite
;
23 import org
.eclipse
.swt
.widgets
.Label
;
24 import org
.eclipse
.swt
.widgets
.Text
;
26 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
27 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
28 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
29 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationStatus
;
30 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnitBase
;
31 import eu
.etaxonomy
.cdm
.model
.occurrence
.Specimen
;
32 import eu
.etaxonomy
.taxeditor
.model
.CdmSessionDataRepository
;
39 public class ChooseTypeDesignationWizardPage
extends WizardPage
{
40 private static Logger logger
= Logger
41 .getLogger(ChooseTypeDesignationWizardPage
.class);
43 private SpecimenTypeDesignation typeDesignation
;
44 private CCombo statusCombo
;
46 private Text txtDesignationType
;
48 private TypeDesignationStatus
[] typeStatusArray
;
50 private TaxonNameBase name
;
53 * @param typeDesignation
55 public ChooseTypeDesignationWizardPage(
56 SpecimenTypeDesignation typeDesignation
, TaxonNameBase name
) {
59 this.typeDesignation
= typeDesignation
;
62 setTitle("Create or edit type designation");
63 setDescription("Create or edit type designation for '" + name
.getTitleCache() + "\".");
67 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
70 public void createControl(Composite parent
) {
72 // Create composite for popup dialog
73 Composite container
= new Composite(parent
, SWT
.NULL
);
74 final GridLayout gridLayout
= new GridLayout();
75 container
.setLayout(gridLayout
);
76 setControl(container
);
79 final Label lblChooseStatus
= new Label(container
, SWT
.NONE
);
80 lblChooseStatus
.setText("Choose designation type status:");
82 // Create designation type status dropdown
83 statusCombo
= new CCombo(container
, SWT
.BORDER
);
84 statusCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
85 TermVocabulary
<TypeDesignationStatus
> typeStatusSet
= CdmSessionDataRepository
.getDefault().getTypeDesignationStatus();
86 typeStatusArray
= new TypeDesignationStatus
[CdmSessionDataRepository
.getDefault().getTypeDesignationStatus().size()];
88 int selectedIndex
= -1;
89 for (TypeDesignationStatus typeStatus
:
90 CdmSessionDataRepository
.getDefault().getTypeDesignationStatus()) {
91 String label
= typeStatus
.getLabel();
92 typeStatusArray
[i
] = typeStatus
;
94 if (typeDesignation
!= null) {
95 if (typeStatus
.equals(typeDesignation
.getTypeStatus())) {
101 statusCombo
.add(label
);
104 // Set menu to type designation status if exists
105 statusCombo
.select(selectedIndex
);
107 statusCombo
.addSelectionListener(new SelectionAdapter() {
109 public void widgetSelected(SelectionEvent e
) {
115 final Label lblEnterText
= new Label(container
, SWT
.NONE
);
116 lblEnterText
.setText("Enter designation type text:");
118 txtDesignationType
= new Text(container
, SWT
.BORDER
);
119 txtDesignationType
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
120 txtDesignationType
.addKeyListener(new KeyAdapter() {
122 public void keyReleased(KeyEvent e
) {
127 // Set text to specimen text if exists
128 if (typeDesignation
!= null && typeDesignation
.getTypeSpecimen() != null) {
129 txtDesignationType
.setText(typeDesignation
.getTypeSpecimen().getTitleCache());
134 public boolean canFlipToNextPage() {
135 return isPageComplete();
138 public boolean isPageComplete() {
139 return (statusCombo
.getSelectionIndex() > -1
140 && txtDesignationType
.getText().length() > 0);
143 private void updatePage() {
145 getWizard().getContainer().updateButtons();
148 public void setPageComplete(boolean complete
) {
149 super.setPageComplete(complete
);
153 TypeDesignationStatus status
= typeStatusArray
[statusCombo
.getSelectionIndex()];
154 // String specimenText = txtDesignationType.getText();
157 if (typeDesignation
== null || typeDesignation
.getTypeSpecimen() == null) {
158 specimen
= Specimen
.NewInstance();
160 specimen
= (Specimen
) typeDesignation
.getTypeSpecimen();
162 specimen
.setTitleCache(txtDesignationType
.getText());
164 if (typeDesignation
== null) {
165 name
.addSpecimenTypeDesignation(specimen
, status
, null, null, null, true, true);
167 typeDesignation
.setTypeStatus(status
);
169 // if (typeDesignation.getTypeSpecimen() == null) {
170 // typeDesignation.setTypeSpecimen(Specimen.NewInstance());
172 // typeDesignation.getTypeSpecimen().setTitleCache(specimenText);