2 * Copyright (C) 2007 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
.namerelations
.wizard
;
12 import java
.beans
.PropertyChangeEvent
;
13 import java
.beans
.PropertyChangeListener
;
14 import java
.util
.ArrayList
;
15 import java
.util
.List
;
17 import org
.apache
.log4j
.Logger
;
18 import org
.eclipse
.jface
.wizard
.WizardPage
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.custom
.CCombo
;
21 import org
.eclipse
.swt
.events
.SelectionAdapter
;
22 import org
.eclipse
.swt
.events
.SelectionEvent
;
23 import org
.eclipse
.swt
.events
.SelectionListener
;
24 import org
.eclipse
.swt
.layout
.GridData
;
25 import org
.eclipse
.swt
.layout
.GridLayout
;
26 import org
.eclipse
.swt
.widgets
.Button
;
27 import org
.eclipse
.swt
.widgets
.Composite
;
28 import org
.eclipse
.swt
.widgets
.Group
;
29 import org
.eclipse
.swt
.widgets
.Label
;
31 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
32 import eu
.etaxonomy
.taxeditor
.model
.CdmSessionDataRepository
;
33 import eu
.etaxonomy
.taxeditor
.model
.CdmUtil
;
36 * An all-in-one relation wizard page where the user chooses a related name, a
37 * relationship type, and the relation\"s directionality.
39 * Note: does not yet return relation to wizard.
45 public class ChooseRelationTypeWizardPage
extends WizardPage
{
46 private static final Logger logger
= Logger
47 .getLogger(ChooseRelationTypeWizardPage
.class);
49 private List
<NameRelationshipType
> relationTypes
;
52 private Label lblDirection
;
53 private Button btnFromRelatedToBase
;
54 private Button btnFromBaseToRelated
;
56 private boolean typeSelected
= false;
57 private boolean directionSelected
= false;
59 private SelectionListener radioSelectionListener
= new SelectionAdapter() {
60 public void widgetSelected(SelectionEvent e
) {
61 directionSelected
= true;
64 if (e
.widget
.equals(btnFromRelatedToBase
)) {
65 relationModel
.setFromName(relationModel
.getRelatedName());
66 relationModel
.setToName(relationModel
.getBaseName());
69 if (e
.widget
.equals(btnFromBaseToRelated
)) {
70 relationModel
.setFromName(relationModel
.getBaseName());
71 relationModel
.setToName(relationModel
.getRelatedName());
76 private NameRelationWizardModel relationModel
;
78 public ChooseRelationTypeWizardPage(final NameRelationWizardModel relationModel
) {
80 setTitle("Choose relationship type and direction.");
82 this.relationModel
= relationModel
;
86 relationModel
.addPropertyChangeListener(new PropertyChangeListener() {
87 public void propertyChange(PropertyChangeEvent evt
) {
88 if (evt
.getPropertyName().equals(NameRelationWizardModel
.RELATEDNAME
)) {
92 if (evt
.getPropertyName().equals(NameRelationWizardModel
.RELATIONTYPE
)) {
93 if (relationModel
.getType() != null) {
106 public void createControl(Composite parent
) {
107 Composite container
= new Composite(parent
, SWT
.NULL
);
108 container
.setLayout(new GridLayout());
110 setControl(container
);
112 // Init relation type array
113 relationTypes
= new ArrayList
<NameRelationshipType
>();
116 final Label lblType
= new Label(container
, SWT
.NONE
);
117 lblType
.setText("Choose relationship type:");
119 // Create relation type dropdown
120 combo
= new CCombo(container
, SWT
.BORDER
);
121 combo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
122 for (NameRelationshipType relationType
:
123 CdmSessionDataRepository
.getDefault().getNameRelationshipTypes()) {
125 relationTypes
.add(relationType
);
127 String label
= relationType
.getLabel();
128 if (relationModel
.isZoological() &&
129 relationType
.equals(NameRelationshipType
.BASIONYM())) {
130 label
= "original combination for";
132 // label += " - " + relationType.getInverseLabel();
135 combo
.setVisibleItemCount(relationTypes
.size());
137 combo
.addSelectionListener(new SelectionAdapter() {
139 public void widgetSelected(SelectionEvent e
) {
140 int typeIndex
= combo
.getSelectionIndex();
141 relationModel
.setType(relationTypes
.get(typeIndex
));
145 final Group group
= new Group(container
, SWT
.NONE
);
146 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
147 final GridLayout gridLayout
= new GridLayout();
148 group
.setLayout(gridLayout
);
150 lblDirection
= new Label(group
, SWT
.NONE
);
151 final GridData gd_lblDirection
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
152 gd_lblDirection
.heightHint
= 32;
153 gd_lblDirection
.minimumHeight
= 40;
155 .setLayoutData(gd_lblDirection
);
156 lblDirection
.setEnabled(false);
157 lblDirection
.setText("Choose relationship direction:");
159 btnFromRelatedToBase
= new Button(group
, SWT
.RADIO
);
161 .setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
162 btnFromRelatedToBase
.setVisible(false);
163 btnFromRelatedToBase
.addSelectionListener(radioSelectionListener
);
165 btnFromBaseToRelated
= new Button(group
, SWT
.RADIO
);
167 .setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
168 btnFromBaseToRelated
.setVisible(false);
169 btnFromBaseToRelated
.addSelectionListener(radioSelectionListener
);
170 new Label(group
, SWT
.NONE
);
174 private void setDescription() {
175 setDescription("Choose relationship type and direction for the name relation between \""
176 + CdmUtil
.getDisplayName(relationModel
.getBaseName()) + "\" and \""
177 + CdmUtil
.getDisplayName(relationModel
.getRelatedName()) + "\".");
180 private void setDirectionLabels() {
181 String strDirection1
= "\"" + CdmUtil
.getDisplayName(relationModel
.getRelatedName()) + "\" "
182 + "is " + combo
.getText() + " " + "\""
183 + CdmUtil
.getDisplayName(relationModel
.getBaseName()) + "\"";
184 String strDirection2
= "\"" + CdmUtil
.getDisplayName(relationModel
.getBaseName()) + "\" "
185 + "is " + combo
.getText() + " " + "\""
186 + CdmUtil
.getDisplayName(relationModel
.getRelatedName()) + "\"";
188 btnFromRelatedToBase
.setText(strDirection1
);
189 btnFromBaseToRelated
.setText(strDirection2
);
193 public boolean canFlipToNextPage() {
198 public boolean isPageComplete() {
199 return (typeSelected
&& directionSelected
);
202 private void updatePage() {
204 if (!directionSelected
) {
210 getWizard().getContainer().updateButtons();
213 private void enableDirection() {
214 setDirectionLabels();
216 lblDirection
.setEnabled(true);
217 btnFromRelatedToBase
.setEnabled(true);
218 btnFromBaseToRelated
.setEnabled(true);
220 btnFromRelatedToBase
.setVisible(true);
221 btnFromBaseToRelated
.setVisible(true);
224 private void disableDirection() {
225 lblDirection
.setEnabled(false);
226 btnFromRelatedToBase
.setEnabled(false);
227 btnFromBaseToRelated
.setEnabled(false);
229 btnFromRelatedToBase
.setSelection(false);
230 btnFromBaseToRelated
.setSelection(false);