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
.Specimen
;
31 import eu
.etaxonomy
.taxeditor
.model
.CdmSessionDataRepository
;
38 public class ChooseTypeDesignationWizardPage
extends WizardPage
{
39 private static Logger logger
= Logger
40 .getLogger(ChooseTypeDesignationWizardPage
.class);
42 private TaxonNameBase name
;
43 private SpecimenTypeDesignation typeDesignation
;
45 private CCombo statusCombo
;
46 private Text txtDesignationType
;
48 private TypeDesignationStatus
[] typeStatusArray
;
51 * @param typeDesignation
53 public ChooseTypeDesignationWizardPage(
54 SpecimenTypeDesignation typeDesignation
, TaxonNameBase name
) {
57 this.typeDesignation
= typeDesignation
;
60 setTitle("Create or edit type designation");
61 setDescription("Create or edit type designation for '" + name
.getTitleCache() + "\".");
65 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
68 public void createControl(Composite parent
) {
70 // Create composite for popup dialog
71 Composite container
= new Composite(parent
, SWT
.NULL
);
72 final GridLayout gridLayout
= new GridLayout();
73 container
.setLayout(gridLayout
);
74 setControl(container
);
77 final Label lblChooseStatus
= new Label(container
, SWT
.NONE
);
78 lblChooseStatus
.setText("Choose designation type status:");
80 // Create designation type status dropdown
81 statusCombo
= new CCombo(container
, SWT
.BORDER
);
82 statusCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
83 TermVocabulary
<TypeDesignationStatus
> typeStatusSet
= CdmSessionDataRepository
.getDefault().getTypeDesignationStatus();
84 typeStatusArray
= new TypeDesignationStatus
[CdmSessionDataRepository
.getDefault().getTypeDesignationStatus().size()];
86 int selectedIndex
= -1;
87 for (TypeDesignationStatus typeStatus
:
88 CdmSessionDataRepository
.getDefault().getTypeDesignationStatus()) {
89 String label
= typeStatus
.getLabel();
90 typeStatusArray
[i
] = typeStatus
;
92 if (typeDesignation
!= null && typeDesignation
.getTypeStatus() != null) {
93 if (typeStatus
.equals(typeDesignation
.getTypeStatus())) {
99 statusCombo
.add(label
);
102 // Set menu to type designation status if exists
103 statusCombo
.select(selectedIndex
);
105 statusCombo
.addSelectionListener(new SelectionAdapter() {
107 public void widgetSelected(SelectionEvent e
) {
113 final Label lblEnterText
= new Label(container
, SWT
.NONE
);
114 lblEnterText
.setText("Enter designation type text:");
116 txtDesignationType
= new Text(container
, SWT
.BORDER
);
117 txtDesignationType
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
118 txtDesignationType
.addKeyListener(new KeyAdapter() {
120 public void keyReleased(KeyEvent e
) {
125 // Set text to specimen text if exists
126 if (typeDesignation
!= null && typeDesignation
.getTypeSpecimen() != null) {
127 txtDesignationType
.setText(typeDesignation
.getTypeSpecimen().getTitleCache());
132 public boolean canFlipToNextPage() {
133 return isPageComplete();
136 public boolean isPageComplete() {
137 return (statusCombo
.getSelectionIndex() > -1
138 && txtDesignationType
.getText().length() > 0);
141 private void updatePage() {
143 getWizard().getContainer().updateButtons();
146 public void setPageComplete(boolean complete
) {
147 super.setPageComplete(complete
);
151 TypeDesignationStatus status
= typeStatusArray
[statusCombo
.getSelectionIndex()];
154 if (typeDesignation
== null || typeDesignation
.getTypeSpecimen() == null) {
155 specimen
= Specimen
.NewInstance();
156 typeDesignation
.setTypeSpecimen(specimen
);
158 specimen
= (Specimen
) typeDesignation
.getTypeSpecimen(); // Next version (or 3 or 4 version from now) - this or something like this will return specimen:
160 specimen
.setTitleCache(txtDesignationType
.getText());
162 if (typeDesignation
== null) {
163 name
.addSpecimenTypeDesignation(specimen
, status
, null, null, null, true, true);
165 typeDesignation
.setTypeStatus(status
);