1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.ui.section.name;
|
11
|
|
12
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
13
|
import org.eclipse.swt.SWT;
|
14
|
import org.eclipse.swt.widgets.Composite;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
17
|
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
|
18
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
19
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
20
|
import eu.etaxonomy.taxeditor.ui.AbstractEntityCollectionElementWizardPage;
|
21
|
import eu.etaxonomy.taxeditor.ui.combo.NameRelationshipTypeCombo;
|
22
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
23
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
24
|
|
25
|
/**
|
26
|
* <p>
|
27
|
* NameRelationshipWizardPage class.
|
28
|
* </p>
|
29
|
*
|
30
|
* @author n.hoffmann
|
31
|
* @created Jun 1, 2010
|
32
|
* @version 1.0
|
33
|
*/
|
34
|
public class NameRelationshipWizardPage extends AbstractEntityCollectionElementWizardPage {
|
35
|
|
36
|
private EntitySelectionElement<TaxonName> selection_relatedTo;
|
37
|
|
38
|
private NameRelationshipTypeCombo combo_relationshipType;
|
39
|
|
40
|
private final TaxonName entity;
|
41
|
|
42
|
private NameRelationshipType type;
|
43
|
|
44
|
private TaxonName relatedName;
|
45
|
boolean inverse;
|
46
|
|
47
|
/**
|
48
|
* <p>
|
49
|
* Constructor for NameRelationshipWizardPage.
|
50
|
* </p>
|
51
|
*
|
52
|
* @param callingSection
|
53
|
* a
|
54
|
* {@link eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailSection}
|
55
|
* object.
|
56
|
*/
|
57
|
protected NameRelationshipWizardPage(
|
58
|
NameRelationshipDetailSection callingSection, CdmFormFactory formFactory) {
|
59
|
super("NameRelationshipWizardPage", formFactory); //$NON-NLS-1$
|
60
|
setTitle("New Name Relationship"); //$NON-NLS-1$
|
61
|
//setDescription(callingSection.getEntity().getTitleCache());
|
62
|
setDescription(Messages.NameRelationshipWizardPage_description);
|
63
|
this.entity = callingSection.getEntity();
|
64
|
|
65
|
formFactory.addPropertyChangeListener(this);
|
66
|
}
|
67
|
|
68
|
/*
|
69
|
* (non-Javadoc)
|
70
|
*
|
71
|
* @see
|
72
|
* org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
|
73
|
* .Composite)
|
74
|
*/
|
75
|
/** {@inheritDoc} */
|
76
|
@Override
|
77
|
public void createControl(Composite parent) {
|
78
|
super.createControl(parent);
|
79
|
|
80
|
combo_relationshipType = formFactory.createNameRelationshipTypeCombo(rootElement,
|
81
|
entity.getNameCache(), SWT.NULL, false,null);
|
82
|
|
83
|
|
84
|
selection_relatedTo = formFactory
|
85
|
.createSelectionElement(TaxonName.class, rootElement,
|
86
|
"",this.entity, EntitySelectionElement.ALL,
|
87
|
SWT.NULL, true);
|
88
|
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* <p>
|
93
|
* getNameRelationship
|
94
|
* </p>
|
95
|
*
|
96
|
* @return a {@link eu.etaxonomy.cdm.model.name.NameRelationship} object.
|
97
|
*/
|
98
|
public NameRelationship getNameRelationship() {
|
99
|
NameRelationship rel;
|
100
|
if (inverse){
|
101
|
rel = entity.addRelationshipFromName(relatedName, type, null, null, null, null);
|
102
|
}else{
|
103
|
rel = entity.addRelationshipToName(relatedName, type, null, null, null, null);
|
104
|
}
|
105
|
return rel;
|
106
|
}
|
107
|
|
108
|
/** {@inheritDoc} */
|
109
|
@Override
|
110
|
public void propertyChange(PropertyChangeEvent event) {
|
111
|
if (event == null) {
|
112
|
return;
|
113
|
}
|
114
|
Object eventSource = event.getSource();
|
115
|
if (eventSource == combo_relationshipType && combo_relationshipType.getSelection() != null) {
|
116
|
type = combo_relationshipType.getSelection().getTerm();
|
117
|
this.inverse = combo_relationshipType.getSelection().isInverse();
|
118
|
} else if (eventSource == selection_relatedTo) {
|
119
|
relatedName = selection_relatedTo.getEntity();
|
120
|
|
121
|
}
|
122
|
|
123
|
boolean complete = type != null && relatedName != null;
|
124
|
setPageComplete(complete);
|
125
|
}
|
126
|
|
127
|
}
|