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
.core
.databinding
.observable
.list
.WritableList
;
19 import org
.eclipse
.jface
.wizard
.WizardPage
;
20 import org
.eclipse
.swt
.SWT
;
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
.Combo
;
28 import org
.eclipse
.swt
.widgets
.Composite
;
29 import org
.eclipse
.swt
.widgets
.Group
;
30 import org
.eclipse
.swt
.widgets
.Label
;
32 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
33 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
34 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
35 import eu
.etaxonomy
.cdm
.model
.name
.ZoologicalName
;
36 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
37 import eu
.etaxonomy
.taxeditor
.editor
.name
.NameSelectComposite
;
38 import eu
.etaxonomy
.taxeditor
.editor
.reference
.ReferenceSelectComposite
;
39 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
40 import eu
.etaxonomy
.taxeditor
.store
.model
.NameRelationsUtil
;
41 import eu
.etaxonomy
.taxeditor
.store
.model
.NameUtil
;
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
{
52 private static final Logger logger
= Logger
53 .getLogger(ChooseRelationWizardPage
.class);
55 private List
<NameRelationshipType
> relationTypes
;
57 private Combo typeCombo
;
58 private Label lblDirection
;
59 private Button btnFromRelatedToBase
;
60 private Button btnFromBaseToRelated
;
62 private boolean typeSelected
= false;
63 private boolean directionSelected
= false;
65 private SelectionListener radioSelectionListener
= new SelectionAdapter() {
66 public void widgetSelected(SelectionEvent e
) {
67 directionSelected
= true;
68 if (e
.widget
.equals(btnFromRelatedToBase
)) {
69 fromName
= relatedName
;
72 if (e
.widget
.equals(btnFromBaseToRelated
)) {
80 private NameSelectComposite nameComposite
;
82 private boolean nameSelected
;
84 private TaxonNameBase baseName
;
85 private TaxonNameBase relatedName
;
86 private TaxonNameBase fromName
;
87 private TaxonNameBase toName
;
89 private NameRelationshipType type
;
91 private Label lblType
;
93 private ReferenceSelectComposite referenceComposite
;
95 private WritableList nameRelationsList
;
97 public ChooseRelationWizardPage(TaxonNameBase name
, WritableList nameRelationsList
) {
100 this.baseName
= name
;
101 this.nameRelationsList
= nameRelationsList
;
103 setTitle("Create name relationship.");
104 setDescription("Create a relationship for \""
105 + NameUtil
.getDisplayName(baseName
) + "\".");
108 public void createControl(Composite parent
) {
109 Composite container
= new Composite(parent
, SWT
.NULL
);
110 container
.setLayout(new GridLayout());
112 setControl(container
);
114 // Create name input composite
115 nameComposite
= new NameSelectComposite(container
);
116 nameComposite
.addPropertyChangeListener(new PropertyChangeListener() {
117 public void propertyChange(PropertyChangeEvent evt
) {
122 // Init relation type array
123 relationTypes
= new ArrayList
<NameRelationshipType
>();
126 lblType
= new Label(container
, SWT
.NONE
);
127 lblType
.setText("Choose relationship type:");
129 // Create relation type dropdown
130 typeCombo
= new Combo(container
, SWT
.BORDER
);
131 typeCombo
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
132 for (NameRelationshipType relationType
:
133 CdmStore
.getDefault().getNameRelationshipTypes()) {
135 relationTypes
.add(relationType
);
136 boolean isZoological
= baseName
instanceof ZoologicalName
;
137 String label
= NameRelationsUtil
.getNameRelationTypeLabel(relationType
, isZoological
);
138 typeCombo
.add(label
);
140 typeCombo
.setVisibleItemCount(relationTypes
.size());
142 typeCombo
.addSelectionListener(new SelectionAdapter() {
144 public void widgetSelected(SelectionEvent e
) {
148 typeCombo
.setEnabled(false);
150 final Group group
= new Group(container
, SWT
.NONE
);
151 group
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
152 final GridLayout gridLayout
= new GridLayout();
153 group
.setLayout(gridLayout
);
155 lblDirection
= new Label(group
, SWT
.NONE
);
156 final GridData gd_lblDirection
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
157 gd_lblDirection
.heightHint
= 32;
158 gd_lblDirection
.minimumHeight
= 40;
160 .setLayoutData(gd_lblDirection
);
161 lblDirection
.setEnabled(false);
162 lblDirection
.setText("Choose relationship direction:");
164 btnFromRelatedToBase
= new Button(group
, SWT
.RADIO
);
166 .setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
167 btnFromRelatedToBase
.setVisible(false);
168 btnFromRelatedToBase
.addSelectionListener(radioSelectionListener
);
170 btnFromBaseToRelated
= new Button(group
, SWT
.RADIO
);
172 .setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
173 btnFromBaseToRelated
.setVisible(false);
174 btnFromBaseToRelated
.addSelectionListener(radioSelectionListener
);
175 new Label(group
, SWT
.NONE
);
177 // Create reference input composite
178 referenceComposite
= new ReferenceSelectComposite(container
);
183 private void setName() {
184 nameSelected
= nameComposite
.getName() == null ?
false : true;
186 this.relatedName
= nameComposite
.getName();
188 this.relatedName
= null;
196 private void setType() {
197 int typeIndex
= typeCombo
.getSelectionIndex();
198 type
= relationTypes
.get(typeIndex
);
203 private void setDirectionLabels() {
204 String strDirection1
= "\"" + NameUtil
.getDisplayName(relatedName
) + "\" "
205 + "is " + typeCombo
.getText() + " " + "\""
206 + NameUtil
.getDisplayName(baseName
) + "\"";
207 String strDirection2
= "\"" + NameUtil
.getDisplayName(baseName
) + "\" "
208 + "is " + typeCombo
.getText() + " " + "\""
209 + NameUtil
.getDisplayName(relatedName
) + "\"";
211 btnFromRelatedToBase
.setText(strDirection1
);
212 btnFromBaseToRelated
.setText(strDirection2
);
216 public boolean canFlipToNextPage() {
217 return isPageComplete();
220 public boolean isPageComplete() {
221 return (nameSelected
&& typeSelected
&& directionSelected
);
224 private void updatePage() {
228 enableDirection(true);
230 enableDirection(false);
234 enableDirection(false);
236 getWizard().getContainer().updateButtons();
239 private void enableType(boolean enabled
) {
240 lblType
.setEnabled(enabled
);
241 typeCombo
.setEnabled(enabled
);
244 private void enableDirection(boolean enabled
) {
246 setDirectionLabels();
248 // directionSelected = false;
250 lblDirection
.setEnabled(enabled
);
251 btnFromRelatedToBase
.setEnabled(enabled
);
252 btnFromBaseToRelated
.setEnabled(enabled
);
254 btnFromRelatedToBase
.setVisible(enabled
);
255 btnFromBaseToRelated
.setVisible(enabled
);
260 * @see org.eclipse.jface.wizard.WizardPage#setPageComplete(boolean)
262 public void setPageComplete(boolean complete
) {
263 super.setPageComplete(complete
);
265 // Add a new relation to the list
267 NameRelationship relation
= new TemporaryNameRelationship(
268 toName
, fromName
, type
, referenceComposite
.getReference(),
269 referenceComposite
.getMicroReference(), null);
270 nameRelationsList
.add(relation
);
274 public class TemporaryNameRelationship
extends NameRelationship
{
276 private TaxonNameBase tempToName
;
277 private TaxonNameBase tempFromName
;
278 private NameRelationshipType tempType
;
279 private ReferenceBase tempCitation
;
280 private String tempCitationMicroReference
;
281 private String tempRuleConsidered
;
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
);
296 // super(null, null, null, null, null, null);
298 // this.tempToName = toName;
299 // this.tempFromName = fromName;
300 // this.tempType = type;
301 // this.tempCitation = citation;
302 // this.tempCitationMicroReference = citationMicroReference;
303 // this.tempRuleConsidered = ruleConsidered;
306 // public TaxonNameBase getToName(){
307 // return tempToName;
310 // public TaxonNameBase getFromName(){
311 // return tempFromName;
314 // public String getRuleConsidered(){
315 // return tempRuleConsidered;