merging in latest changes from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / name / NameRelationshipWizardPage.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.ui.section.name;
12
13 import org.eclipse.jface.util.IPropertyChangeListener;
14 import org.eclipse.jface.util.PropertyChangeEvent;
15 import org.eclipse.jface.wizard.WizardPage;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.widgets.Composite;
18
19 import eu.etaxonomy.cdm.model.name.NameRelationship;
20 import eu.etaxonomy.cdm.model.name.NameRelationshipType;
21 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
22 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
23 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
24 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
25 import eu.etaxonomy.taxeditor.ui.element.RootElement;
26 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
27
28 /**
29 * <p>
30 * NameRelationshipWizardPage class.
31 * </p>
32 *
33 * @author n.hoffmann
34 * @created Jun 1, 2010
35 * @version 1.0
36 */
37 public class NameRelationshipWizardPage extends WizardPage implements
38 IPropertyChangeListener {
39
40 private final CdmFormFactory formFactory;
41
42 private EntitySelectionElement<TaxonNameBase> selection_relatedTo;
43
44 private TermComboElement<NameRelationshipType> combo_relationshipType;
45
46 private final TaxonNameBase entity;
47
48 private NameRelationshipType type;
49
50 private TaxonNameBase toName;
51
52 private RootElement rootElement;
53
54 /**
55 * <p>
56 * Constructor for NameRelationshipWizardPage.
57 * </p>
58 *
59 * @param callingSection
60 * a
61 * {@link eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailSection}
62 * object.
63 */
64 protected NameRelationshipWizardPage(
65 NameRelationshipDetailSection callingSection) {
66 super("NameRelationshipWizardPage");
67 setTitle("New Name Relationship");
68 setDescription(callingSection.getEntity().getTitleCache());
69 this.entity = callingSection.getEntity();
70 this.formFactory = callingSection.getFormFactory();
71
72 formFactory.addPropertyChangeListener(this);
73 }
74
75 /*
76 * (non-Javadoc)
77 *
78 * @see
79 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
80 * .Composite)
81 */
82 /** {@inheritDoc} */
83 @Override
84 public void createControl(Composite parent) {
85 this.setPageComplete(false);
86
87 Composite control = formFactory.createComposite(parent);
88
89 control.setLayout(LayoutConstants.LAYOUT(2, false));
90
91 rootElement = new RootElement(formFactory, control);
92
93 combo_relationshipType = formFactory.createTermComboElement(NameRelationshipType.class,
94 rootElement, "Name Relationship Type", null, SWT.NULL);
95
96 selection_relatedTo = formFactory
97 .createSelectionElement(TaxonNameBase.class,
98 ((NameRelationshipWizard) getWizard())
99 .getConversationHolder(), rootElement,
100 "Related to", null, EntitySelectionElement.ALL,
101 SWT.NULL);
102
103 setControl(control);
104 }
105
106 /**
107 * <p>
108 * getNameRelationship
109 * </p>
110 *
111 * @return a {@link eu.etaxonomy.cdm.model.name.NameRelationship} object.
112 */
113 public NameRelationship getNameRelationship() {
114 return entity.addRelationshipToName(toName, type, null, null, null);
115 }
116
117 /** {@inheritDoc} */
118 @Override
119 public void propertyChange(PropertyChangeEvent event) {
120 if (event == null) {
121 return;
122 }
123 Object eventSource = event.getSource();
124 if (eventSource == combo_relationshipType) {
125 type = combo_relationshipType.getSelection();
126 } else if (eventSource == selection_relatedTo) {
127 toName = selection_relatedTo.getEntity();
128 }
129
130 boolean complete = type != null && toName != null;
131 setPageComplete(complete);
132 }
133
134 /** {@inheritDoc} */
135 @Override
136 public void dispose() {
137 rootElement.removeElements();
138 formFactory.removePropertyChangeListener(this);
139 super.dispose();
140 }
141 }