Merge branch 'release/4.0.0'
[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.swt.SWT;
16 import org.eclipse.swt.widgets.Composite;
17
18 import eu.etaxonomy.cdm.model.common.TermType;
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.AbstractEntityCollectionElementWizardPage;
23 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
24 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
25
26 /**
27 * <p>
28 * NameRelationshipWizardPage class.
29 * </p>
30 *
31 * @author n.hoffmann
32 * @created Jun 1, 2010
33 * @version 1.0
34 */
35 public class NameRelationshipWizardPage extends AbstractEntityCollectionElementWizardPage implements
36 IPropertyChangeListener {
37
38 private EntitySelectionElement<TaxonNameBase> selection_relatedTo;
39
40 private TermComboElement<NameRelationshipType> combo_relationshipType;
41
42 private final TaxonNameBase entity;
43
44 private NameRelationshipType type;
45
46 private TaxonNameBase toName;
47
48 /**
49 * <p>
50 * Constructor for NameRelationshipWizardPage.
51 * </p>
52 *
53 * @param callingSection
54 * a
55 * {@link eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailSection}
56 * object.
57 */
58 protected NameRelationshipWizardPage(
59 NameRelationshipDetailSection callingSection) {
60 super("NameRelationshipWizardPage");
61 setTitle("New Name Relationship");
62 setDescription(callingSection.getEntity().getTitleCache());
63 this.entity = callingSection.getEntity();
64 this.formFactory = callingSection.getFormFactory();
65
66 formFactory.addPropertyChangeListener(this);
67 }
68
69 /*
70 * (non-Javadoc)
71 *
72 * @see
73 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
74 * .Composite)
75 */
76 /** {@inheritDoc} */
77 @Override
78 public void createControl(Composite parent) {
79 super.createControl(parent);
80
81 combo_relationshipType = formFactory.createDefinedTermComboElement(TermType.NameRelationshipType,
82 rootElement, "Name Relationship Type", null, SWT.NULL);
83
84 selection_relatedTo = formFactory
85 .createSelectionElement(TaxonNameBase.class,
86 ((NameRelationshipWizard) getWizard())
87 .getConversationHolder(), rootElement,
88 "Related to", null, EntitySelectionElement.ALL,
89 SWT.NULL);
90
91 }
92
93 /**
94 * <p>
95 * getNameRelationship
96 * </p>
97 *
98 * @return a {@link eu.etaxonomy.cdm.model.name.NameRelationship} object.
99 */
100 public NameRelationship getNameRelationship() {
101 return entity.addRelationshipToName(toName, type, null, null, null);
102 }
103
104 /** {@inheritDoc} */
105 @Override
106 public void propertyChange(PropertyChangeEvent event) {
107 if (event == null) {
108 return;
109 }
110 Object eventSource = event.getSource();
111 if (eventSource == combo_relationshipType) {
112 type = combo_relationshipType.getSelection();
113 } else if (eventSource == selection_relatedTo) {
114 toName = selection_relatedTo.getEntity();
115 }
116
117 boolean complete = type != null && toName != null;
118 setPageComplete(complete);
119 }
120
121 }