refactoring of package names for consistency
[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.RootElement;
25 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.SelectionType;
26 import eu.etaxonomy.taxeditor.ui.selection.NameSelectionElement;
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 NameSelectionElement selection_relatedTo;
43
44 private TermComboElement<NameRelationshipType> combo_relationshipType;
45
46 private final NameRelationshipDetailSection callingSection;
47
48 private final TaxonNameBase entity;
49
50 private NameRelationshipType type;
51
52 private TaxonNameBase toName;
53
54 private RootElement rootElement;
55
56 /**
57 * <p>
58 * Constructor for NameRelationshipWizardPage.
59 * </p>
60 *
61 * @param callingSection
62 * a
63 * {@link eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailSection}
64 * object.
65 */
66 protected NameRelationshipWizardPage(
67 NameRelationshipDetailSection callingSection) {
68 super("NameRelationshipWizardPage");
69 setTitle("New Name Relationship");
70 setDescription(callingSection.getEntity().getTitleCache());
71 this.callingSection = callingSection;
72 this.entity = callingSection.getEntity();
73 this.formFactory = callingSection.getFormFactory();
74
75 formFactory.addPropertyChangeListener(this);
76 }
77
78 /*
79 * (non-Javadoc)
80 *
81 * @see
82 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
83 * .Composite)
84 */
85 /** {@inheritDoc} */
86 @Override
87 public void createControl(Composite parent) {
88 this.setPageComplete(false);
89
90 Composite control = formFactory.createComposite(parent);
91
92 control.setLayout(CdmFormFactory.LAYOUT(2, false));
93
94 rootElement = new RootElement(formFactory, control);
95
96 combo_relationshipType = formFactory.createTermComboElement(NameRelationshipType.class,
97 rootElement, "Name Relationship Type", null, SWT.NULL);
98
99 selection_relatedTo = (NameSelectionElement) formFactory
100 .createSelectionElement(SelectionType.NAME,
101 ((NameRelationshipWizard) getWizard())
102 .getConversationHolder(), rootElement,
103 "Related to", null, NameSelectionElement.DEFAULT,
104 SWT.NULL);
105
106 setControl(control);
107 }
108
109 /**
110 * <p>
111 * getNameRelationship
112 * </p>
113 *
114 * @return a {@link eu.etaxonomy.cdm.model.name.NameRelationship} object.
115 */
116 public NameRelationship getNameRelationship() {
117 return entity.addRelationshipToName(toName, type, null, null, null);
118 }
119
120 /** {@inheritDoc} */
121 @Override
122 public void propertyChange(PropertyChangeEvent event) {
123 if (event == null) {
124 return;
125 }
126 Object eventSource = event.getSource();
127 if (eventSource == combo_relationshipType) {
128 type = combo_relationshipType.getSelection();
129 } else if (eventSource == selection_relatedTo) {
130 toName = selection_relatedTo.getEntity();
131 }
132
133 boolean complete = type != null && toName != null;
134 setPageComplete(complete);
135 }
136
137 /** {@inheritDoc} */
138 @Override
139 public void dispose() {
140 rootElement.removeElements();
141 formFactory.removePropertyChangeListener(this);
142 super.dispose();
143 }
144 }