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
.eclipse
.core
.databinding
.observable
.list
.WritableList
;
18 import org
.eclipse
.jface
.wizard
.WizardPage
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.events
.SelectionAdapter
;
21 import org
.eclipse
.swt
.events
.SelectionEvent
;
22 import org
.eclipse
.swt
.events
.SelectionListener
;
23 import org
.eclipse
.swt
.layout
.GridData
;
24 import org
.eclipse
.swt
.layout
.GridLayout
;
25 import org
.eclipse
.swt
.widgets
.Button
;
26 import org
.eclipse
.swt
.widgets
.Combo
;
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
.NameRelationship
;
32 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
33 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
34 import eu
.etaxonomy
.cdm
.model
.name
.ZoologicalName
;
35 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
36 import eu
.etaxonomy
.taxeditor
.editor
.name
.NameSelectComposite
;
37 import eu
.etaxonomy
.taxeditor
.editor
.reference
.ReferenceSelectComposite
;
38 import eu
.etaxonomy
.taxeditor
.model
.NameRelationsUtil
;
39 import eu
.etaxonomy
.taxeditor
.model
.NameUtil
;
40 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
43 * An all-in-one relation wizard page where the user chooses a related name, a
44 * relationship type, and the relation's directionality.
50 public class ChooseRelationWizardPage
extends WizardPage
{
52 private List
<NameRelationshipType
> relationTypes
;
54 private Combo typeCombo
;
55 private Label lblDirection
;
56 private Button btnFromRelatedToBase
;
57 private Button btnFromBaseToRelated
;
59 private boolean typeSelected
= false;
60 private boolean directionSelected
= false;
62 private SelectionListener radioSelectionListener
= new SelectionAdapter() {
63 public void widgetSelected(SelectionEvent e
) {
64 directionSelected
= true;
65 if (e
.widget
.equals(btnFromRelatedToBase
)) {
66 fromName
= relatedName
;
69 if (e
.widget
.equals(btnFromBaseToRelated
)) {
77 private NameSelectComposite nameComposite
;
79 private boolean nameSelected
;
81 private TaxonNameBase
<?
, ?
> baseName
;
82 private TaxonNameBase
<?
, ?
> relatedName
;
83 private TaxonNameBase
<?
, ?
> fromName
;
84 private TaxonNameBase
<?
, ?
> toName
;
86 private NameRelationshipType type
;
88 private Label lblType
;
90 private ReferenceSelectComposite referenceComposite
;
92 private WritableList nameRelationsList
;
94 public ChooseRelationWizardPage(TaxonNameBase
<?
, ?
> name
, WritableList nameRelationsList
) {
98 this.nameRelationsList
= nameRelationsList
;
100 setTitle("Create name relationship.");
101 setDescription("Create a relationship for \""
102 + NameUtil
.getDisplayName(baseName
) + "\".");
105 public void createControl(Composite parent
) {
106 Composite container
= new Composite(parent
, SWT
.NULL
);
107 container
.setLayout(new GridLayout());
109 setControl(container
);
111 // Create name input composite
112 nameComposite
= new NameSelectComposite(container
);
113 nameComposite
.addPropertyChangeListener(new PropertyChangeListener() {
114 public void propertyChange(PropertyChangeEvent evt
) {
119 // Init relation type array
120 relationTypes
= new ArrayList
<NameRelationshipType
>();
123 lblType
= new Label(container
, SWT
.NONE
);
124 lblType
.setText("Choose relationship type:");
126 // Create relation type dropdown
127 typeCombo
= new Combo(container
, SWT
.BORDER
);
128 typeCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
129 for (NameRelationshipType relationType
:
130 CdmStore
.getDefault().getNameRelationshipTypes()) {
132 relationTypes
.add(relationType
);
133 boolean isZoological
= baseName
instanceof ZoologicalName
;
134 String label
= NameRelationsUtil
.getNameRelationTypeLabel(relationType
, isZoological
);
135 typeCombo
.add(label
);
137 typeCombo
.setVisibleItemCount(relationTypes
.size());
139 typeCombo
.addSelectionListener(new SelectionAdapter() {
141 public void widgetSelected(SelectionEvent e
) {
145 typeCombo
.setEnabled(false);
147 final Group group
= new Group(container
, SWT
.NONE
);
148 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
149 final GridLayout gridLayout
= new GridLayout();
150 group
.setLayout(gridLayout
);
152 lblDirection
= new Label(group
, SWT
.NONE
);
153 final GridData gd_lblDirection
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
154 gd_lblDirection
.heightHint
= 32;
155 gd_lblDirection
.minimumHeight
= 40;
157 .setLayoutData(gd_lblDirection
);
158 lblDirection
.setEnabled(false);
159 lblDirection
.setText("Choose relationship direction:");
161 btnFromRelatedToBase
= new Button(group
, SWT
.RADIO
);
163 .setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
164 btnFromRelatedToBase
.setVisible(false);
165 btnFromRelatedToBase
.addSelectionListener(radioSelectionListener
);
167 btnFromBaseToRelated
= new Button(group
, SWT
.RADIO
);
169 .setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
170 btnFromBaseToRelated
.setVisible(false);
171 btnFromBaseToRelated
.addSelectionListener(radioSelectionListener
);
172 new Label(group
, SWT
.NONE
);
174 // Create reference input composite
175 referenceComposite
= new ReferenceSelectComposite(container
);
180 private void setName() {
181 nameSelected
= nameComposite
.getName() == null ?
false : true;
183 this.relatedName
= nameComposite
.getName();
185 this.relatedName
= null;
193 private void setType() {
194 int typeIndex
= typeCombo
.getSelectionIndex();
195 type
= relationTypes
.get(typeIndex
);
200 private void setDirectionLabels() {
201 String strDirection1
= "\"" + NameUtil
.getDisplayName(relatedName
) + "\" "
202 + "is " + typeCombo
.getText() + " " + "\""
203 + NameUtil
.getDisplayName(baseName
) + "\"";
204 String strDirection2
= "\"" + NameUtil
.getDisplayName(baseName
) + "\" "
205 + "is " + typeCombo
.getText() + " " + "\""
206 + NameUtil
.getDisplayName(relatedName
) + "\"";
208 btnFromRelatedToBase
.setText(strDirection1
);
209 btnFromBaseToRelated
.setText(strDirection2
);
213 public boolean canFlipToNextPage() {
214 return isPageComplete();
217 public boolean isPageComplete() {
218 return (nameSelected
&& typeSelected
&& directionSelected
);
221 private void updatePage() {
225 enableDirection(true);
227 enableDirection(false);
231 enableDirection(false);
233 getWizard().getContainer().updateButtons();
236 private void enableType(boolean enabled
) {
237 lblType
.setEnabled(enabled
);
238 typeCombo
.setEnabled(enabled
);
241 private void enableDirection(boolean enabled
) {
243 setDirectionLabels();
245 // directionSelected = false;
247 lblDirection
.setEnabled(enabled
);
248 btnFromRelatedToBase
.setEnabled(enabled
);
249 btnFromBaseToRelated
.setEnabled(enabled
);
251 btnFromRelatedToBase
.setVisible(enabled
);
252 btnFromBaseToRelated
.setVisible(enabled
);
257 * @see org.eclipse.jface.wizard.WizardPage#setPageComplete(boolean)
259 public void setPageComplete(boolean complete
) {
260 super.setPageComplete(complete
);
262 // Add a new relation to the list
264 NameRelationship relation
= new TemporaryNameRelationship(
265 toName
, fromName
, type
, referenceComposite
.getReference(),
266 referenceComposite
.getMicroReference(), null);
267 nameRelationsList
.add(relation
);
271 public class TemporaryNameRelationship
extends NameRelationship
{
276 private static final long serialVersionUID
= 1231912353305134080L;
283 * @param citationMicroReference
284 * @param ruleConsidered
286 protected TemporaryNameRelationship(TaxonNameBase
<?
, ?
> toName
,
287 TaxonNameBase
<?
, ?
> fromName
, NameRelationshipType type
,
288 ReferenceBase
<?
> citation
, String citationMicroReference
,
289 String ruleConsidered
) {
290 super(toName
, fromName
, type
, citation
, citationMicroReference
, ruleConsidered
);