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
.reference
.ReferenceBase
;
35 import eu
.etaxonomy
.taxeditor
.editor
.labels
.ILabelImageStrategy
;
36 import eu
.etaxonomy
.taxeditor
.editor
.labels
.LabelImageProvider
;
37 import eu
.etaxonomy
.taxeditor
.editor
.name
.NameSelectComposite
;
38 import eu
.etaxonomy
.taxeditor
.editor
.reference
.ReferenceSelectComposite
;
39 import eu
.etaxonomy
.taxeditor
.model
.NameHelper
;
40 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
41 import eu
.etaxonomy
.taxeditor
.store
.VocabularyStore
;
44 * An all-in-one relation wizard page where the user chooses a related name, a
45 * relationship type, and the relation's directionality.
51 public class ChooseRelationWizardPage
extends WizardPage
{
53 private List
<NameRelationshipType
> relationTypes
;
55 private Combo typeCombo
;
56 private Label lblDirection
;
57 private Button btnFromRelatedToBase
;
58 private Button btnFromBaseToRelated
;
60 private boolean typeSelected
= false;
61 private boolean directionSelected
= false;
63 private SelectionListener radioSelectionListener
= new SelectionAdapter() {
64 public void widgetSelected(SelectionEvent e
) {
65 directionSelected
= true;
66 if (e
.widget
.equals(btnFromRelatedToBase
)) {
67 fromName
= relatedName
;
70 if (e
.widget
.equals(btnFromBaseToRelated
)) {
78 private NameSelectComposite nameComposite
;
80 private boolean nameSelected
;
82 private TaxonNameBase
<?
, ?
> baseName
;
83 private TaxonNameBase
<?
, ?
> relatedName
;
84 private TaxonNameBase
<?
, ?
> fromName
;
85 private TaxonNameBase
<?
, ?
> toName
;
87 private NameRelationshipType type
;
89 private Label lblType
;
91 private ReferenceSelectComposite referenceComposite
;
93 private WritableList nameRelationsList
;
95 private LabelImageProvider labelProvider
;
97 public ChooseRelationWizardPage(TaxonNameBase
<?
, ?
> name
, WritableList nameRelationsList
) {
100 this.baseName
= name
;
101 this.nameRelationsList
= nameRelationsList
;
103 ILabelImageStrategy strategy
= LabelImageProvider
.getLabelStrategy(name
);
104 this.labelProvider
= new LabelImageProvider(strategy
);
106 setTitle("Create name relationship.");
107 setDescription("Create a relationship for \""
108 + NameHelper
.getDisplayName(baseName
) + "\".");
111 public void createControl(Composite parent
) {
112 Composite container
= new Composite(parent
, SWT
.NULL
);
113 container
.setLayout(new GridLayout());
115 setControl(container
);
117 // Create name input composite
118 nameComposite
= new NameSelectComposite(container
);
119 nameComposite
.addPropertyChangeListener(new PropertyChangeListener() {
120 public void propertyChange(PropertyChangeEvent evt
) {
125 // Init relation type array
126 relationTypes
= new ArrayList
<NameRelationshipType
>();
129 lblType
= new Label(container
, SWT
.NONE
);
130 lblType
.setText("Choose relationship type:");
132 // Create relation type dropdown
133 typeCombo
= new Combo(container
, SWT
.BORDER
);
134 typeCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
135 for (NameRelationshipType relationType
:
136 PreferencesUtil
.getPreferredNameRelationshipTypes()) {
138 relationTypes
.add(relationType
);
139 String label
= labelProvider
.getNameRelationTypeLabel(relationType
);
140 typeCombo
.add(label
);
142 typeCombo
.setVisibleItemCount(relationTypes
.size());
144 typeCombo
.addSelectionListener(new SelectionAdapter() {
146 public void widgetSelected(SelectionEvent e
) {
150 typeCombo
.setEnabled(false);
152 final Group group
= new Group(container
, SWT
.NONE
);
153 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
154 final GridLayout gridLayout
= new GridLayout();
155 group
.setLayout(gridLayout
);
157 lblDirection
= new Label(group
, SWT
.NONE
);
158 final GridData gd_lblDirection
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
159 gd_lblDirection
.heightHint
= 32;
160 gd_lblDirection
.minimumHeight
= 40;
162 .setLayoutData(gd_lblDirection
);
163 lblDirection
.setEnabled(false);
164 lblDirection
.setText("Choose relationship direction:");
166 btnFromRelatedToBase
= new Button(group
, SWT
.RADIO
);
168 .setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
169 btnFromRelatedToBase
.setVisible(false);
170 btnFromRelatedToBase
.addSelectionListener(radioSelectionListener
);
172 btnFromBaseToRelated
= new Button(group
, SWT
.RADIO
);
174 .setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
175 btnFromBaseToRelated
.setVisible(false);
176 btnFromBaseToRelated
.addSelectionListener(radioSelectionListener
);
177 new Label(group
, SWT
.NONE
);
179 // Create reference input composite
180 referenceComposite
= new ReferenceSelectComposite(container
);
185 private void setName() {
186 nameSelected
= nameComposite
.getName() == null ?
false : true;
188 this.relatedName
= nameComposite
.getName();
190 this.relatedName
= null;
198 private void setType() {
199 int typeIndex
= typeCombo
.getSelectionIndex();
200 type
= relationTypes
.get(typeIndex
);
205 private void setDirectionLabels() {
206 String strDirection1
= "\"" + NameHelper
.getDisplayName(relatedName
) + "\" "
207 + "is " + typeCombo
.getText() + " " + "\""
208 + NameHelper
.getDisplayName(baseName
) + "\"";
209 String strDirection2
= "\"" + NameHelper
.getDisplayName(baseName
) + "\" "
210 + "is " + typeCombo
.getText() + " " + "\""
211 + NameHelper
.getDisplayName(relatedName
) + "\"";
213 btnFromRelatedToBase
.setText(strDirection1
);
214 btnFromBaseToRelated
.setText(strDirection2
);
218 public boolean canFlipToNextPage() {
219 return isPageComplete();
222 public boolean isPageComplete() {
223 return (nameSelected
&& typeSelected
&& directionSelected
);
226 private void updatePage() {
230 enableDirection(true);
232 enableDirection(false);
236 enableDirection(false);
238 getWizard().getContainer().updateButtons();
241 private void enableType(boolean enabled
) {
242 lblType
.setEnabled(enabled
);
243 typeCombo
.setEnabled(enabled
);
246 private void enableDirection(boolean enabled
) {
248 setDirectionLabels();
250 // directionSelected = false;
252 lblDirection
.setEnabled(enabled
);
253 btnFromRelatedToBase
.setEnabled(enabled
);
254 btnFromBaseToRelated
.setEnabled(enabled
);
256 btnFromRelatedToBase
.setVisible(enabled
);
257 btnFromBaseToRelated
.setVisible(enabled
);
262 * @see org.eclipse.jface.wizard.WizardPage#setPageComplete(boolean)
264 public void setPageComplete(boolean complete
) {
265 super.setPageComplete(complete
);
267 // Add a new relation to the list
269 NameRelationship relation
= new TemporaryNameRelationship(
270 toName
, fromName
, type
, referenceComposite
.getReference(),
271 referenceComposite
.getMicroReference(), null);
272 nameRelationsList
.add(relation
);
276 public class TemporaryNameRelationship
extends NameRelationship
{
281 private static final long serialVersionUID
= 1231912353305134080L;
288 * @param citationMicroReference
289 * @param ruleConsidered
291 protected TemporaryNameRelationship(TaxonNameBase
<?
, ?
> toName
,
292 TaxonNameBase
<?
, ?
> fromName
, NameRelationshipType type
,
293 ReferenceBase
<?
> citation
, String citationMicroReference
,
294 String ruleConsidered
) {
295 super(toName
, fromName
, type
, citation
, citationMicroReference
, ruleConsidered
);