including changes from cdmlib-print
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / 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.section.name;
12
13 import org.apache.log4j.Logger;
14 import org.eclipse.jface.util.IPropertyChangeListener;
15 import org.eclipse.jface.util.PropertyChangeEvent;
16 import org.eclipse.jface.wizard.WizardPage;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.widgets.Composite;
19
20 import eu.etaxonomy.cdm.model.name.NameRelationship;
21 import eu.etaxonomy.cdm.model.name.NameRelationshipType;
22 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
23 import eu.etaxonomy.taxeditor.forms.CdmFormFactory;
24 import eu.etaxonomy.taxeditor.forms.CdmFormFactory.SelectionType;
25 import eu.etaxonomy.taxeditor.forms.CdmFormFactory.TermComboType;
26 import eu.etaxonomy.taxeditor.forms.RootElement;
27 import eu.etaxonomy.taxeditor.forms.selection.NameSelectionElement;
28 import eu.etaxonomy.taxeditor.forms.term.NameRelationshipTypeComboElement;
29
30 /**
31 * <p>NameRelationshipWizardPage class.</p>
32 *
33 * @author n.hoffmann
34 * @created Jun 1, 2010
35 * @version 1.0
36 */
37 public class NameRelationshipWizardPage extends WizardPage implements IPropertyChangeListener {
38
39
40 private static final Logger logger = Logger
41 .getLogger(NameRelationshipWizardPage.class);
42
43
44 private CdmFormFactory formFactory;
45
46
47 private NameSelectionElement selection_relatedTo;
48
49
50 private NameRelationshipTypeComboElement combo_relationshipType;
51
52
53 private NameRelationshipDetailSection callingSection;
54
55
56 private TaxonNameBase entity;
57
58
59 private NameRelationshipType type;
60
61
62 private TaxonNameBase toName;
63
64
65 private RootElement rootElement;
66
67
68 /**
69 * <p>Constructor for NameRelationshipWizardPage.</p>
70 *
71 * @param callingSection a {@link eu.etaxonomy.taxeditor.section.name.NameRelationshipDetailSection} object.
72 */
73 protected NameRelationshipWizardPage(NameRelationshipDetailSection callingSection) {
74 super("NameRelationshipWizardPage");
75 setTitle("New Name Relationship");
76 setDescription(callingSection.getEntity().getTitleCache());
77 this.callingSection = callingSection;
78 this.entity = callingSection.getEntity();
79 this.formFactory = callingSection.getFormFactory();
80
81 formFactory.addPropertyChangeListener(this);
82 }
83
84 /* (non-Javadoc)
85 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
86 */
87 /** {@inheritDoc} */
88 public void createControl(Composite parent) {
89 this.setPageComplete(false);
90
91 Composite control = formFactory.createComposite(parent);
92
93 control.setLayout(CdmFormFactory.LAYOUT(2, false));
94
95 rootElement = new RootElement(formFactory, control);
96
97 combo_relationshipType = (NameRelationshipTypeComboElement) formFactory.createTermComboElement(TermComboType.NAMERELATIONSHIP, rootElement, "Name Relationship Type", null, SWT.NULL);
98
99 selection_relatedTo = (NameSelectionElement) formFactory.createSelectionElement(SelectionType.NAME, ((NameRelationshipWizard)getWizard()).getConversationHolder(), rootElement, "Related to", null, SWT.NULL);
100
101 setControl(control);
102 }
103
104 /**
105 * <p>getNameRelationship</p>
106 *
107 * @return a {@link eu.etaxonomy.cdm.model.name.NameRelationship} object.
108 */
109 public NameRelationship getNameRelationship(){
110 return entity.addRelationshipToName(toName, type, null, null, null);
111 }
112
113 /** {@inheritDoc} */
114 public void propertyChange(PropertyChangeEvent event) {
115 if(event == null){
116 return;
117 }
118 Object eventSource = event.getSource();
119 if(eventSource == combo_relationshipType){
120 type = combo_relationshipType.getSelection();
121 }
122 else if(eventSource == selection_relatedTo){
123 toName = selection_relatedTo.getEntity();
124 }
125
126 setPageComplete(type != null && toName != null);
127 }
128
129 /** {@inheritDoc} */
130 @Override
131 public void dispose() {
132 rootElement.removeElements();
133 formFactory.removePropertyChangeListener(this);
134 super.dispose();
135 }
136 }