merge from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / name / SynonymRelationshipWizardPage.java
1 // $Id$
2 /**
3 * Copyright (C) 2014 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 package eu.etaxonomy.taxeditor.ui.section.name;
11
12 import org.eclipse.jface.util.IPropertyChangeListener;
13 import org.eclipse.jface.util.PropertyChangeEvent;
14 import org.eclipse.jface.wizard.WizardPage;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.widgets.Composite;
17
18 import eu.etaxonomy.cdm.model.taxon.Synonym;
19 import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
20 import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
21 import eu.etaxonomy.cdm.model.taxon.Taxon;
22 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
23 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
24 import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
25 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
26 import eu.etaxonomy.taxeditor.ui.element.RootElement;
27 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
28
29 /**
30 * @author pplitzner
31 * @date 27.01.2014
32 *
33 */
34 public class SynonymRelationshipWizardPage extends WizardPage implements IPropertyChangeListener {
35
36 private final CdmFormFactory formFactory;
37
38 private EntitySelectionElement<Taxon> selection_relatedTo;
39
40 private TermComboElement<SynonymRelationshipType> combo_relationshipType;
41
42 private CheckboxElement checkboxProParte;
43
44 private boolean isProParte;
45
46 private CheckboxElement checkboxPartial;
47
48 private boolean isPartial;
49
50 private final Synonym entity;
51
52 private SynonymRelationshipType type;
53
54 private Taxon taxon;
55
56 private RootElement rootElement;
57
58 /**
59 * <p>
60 * Constructor for NameRelationshipWizardPage.
61 * </p>
62 *
63 * @param callingSection
64 * a
65 * {@link eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailSection}
66 * object.
67 */
68 protected SynonymRelationshipWizardPage(
69 SynonymRelationshipDetailSection callingSection) {
70 super("SynonymRelationshipWizardPage");
71 setTitle("New Synonym Relationship");
72 setDescription(callingSection.getEntity().getTitleCache());
73 this.entity = callingSection.getEntity();
74 this.formFactory = callingSection.getFormFactory();
75
76 formFactory.addPropertyChangeListener(this);
77 }
78
79 /*
80 * (non-Javadoc)
81 *
82 * @see
83 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
84 * .Composite)
85 */
86 /** {@inheritDoc} */
87 @Override
88 public void createControl(Composite parent) {
89 this.setPageComplete(false);
90
91 Composite control = formFactory.createComposite(parent);
92
93 control.setLayout(LayoutConstants.LAYOUT(2, false));
94
95 rootElement = new RootElement(formFactory, control);
96
97 combo_relationshipType = formFactory.createTermComboElement(SynonymRelationshipType.class,
98 rootElement, "Synonym Relationship Type", null, SWT.NULL);
99
100 selection_relatedTo = formFactory
101 .createSelectionElement(Taxon.class,
102 ((SynonymRelationshipWizard) getWizard())
103 .getConversationHolder(), rootElement,
104 "Related to", null, EntitySelectionElement.ALL,
105 SWT.NULL);
106
107 checkboxProParte = formFactory.createCheckbox(rootElement, "Pro Parte Synonym", null, SWT.NULL);
108
109 checkboxPartial = formFactory.createCheckbox(rootElement, "Partial Synonym", null, SWT.NULL);
110
111 setControl(control);
112 }
113
114 /**
115 * <p>
116 * getNameRelationship
117 * </p>
118 *
119 * @return a {@link eu.etaxonomy.cdm.model.name.NameRelationship} object.
120 */
121 public SynonymRelationship getSynonymRelationship() {
122 SynonymRelationship synonymRelationship = taxon.addSynonym(entity, combo_relationshipType.getSelection());
123 synonymRelationship.setPartial(isPartial);
124 synonymRelationship.setProParte(isProParte);
125 return synonymRelationship;
126 }
127
128 /** {@inheritDoc} */
129 @Override
130 public void propertyChange(PropertyChangeEvent event) {
131 if (event == null) {
132 return;
133 }
134 Object eventSource = event.getSource();
135 if (eventSource == combo_relationshipType) {
136 type = combo_relationshipType.getSelection();
137 } else if (eventSource == selection_relatedTo) {
138 taxon = selection_relatedTo.getEntity();
139 } else if (eventSource == checkboxProParte) {
140 isProParte = checkboxProParte.getSelection();
141 } else if (eventSource == checkboxPartial) {
142 isPartial = checkboxPartial.getSelection();
143 }
144
145 boolean complete = type != null && taxon != null;
146 setPageComplete(complete);
147 }
148
149 /** {@inheritDoc} */
150 @Override
151 public void dispose() {
152 rootElement.removeElements();
153 formFactory.removePropertyChangeListener(this);
154 super.dispose();
155 }
156 }