Project

General

Profile

Download (4 KB) Statistics
| Branch: | Tag: | Revision:
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.forms.CdmFormFactory;
23
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.SelectionType;
24
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.TermComboType;
25
import eu.etaxonomy.taxeditor.ui.forms.RootElement;
26
import eu.etaxonomy.taxeditor.ui.selection.NameSelectionElement;
27
import eu.etaxonomy.taxeditor.ui.term.NameRelationshipTypeComboElement;
28

    
29
/**
30
 * <p>
31
 * NameRelationshipWizardPage class.
32
 * </p>
33
 * 
34
 * @author n.hoffmann
35
 * @created Jun 1, 2010
36
 * @version 1.0
37
 */
38
public class NameRelationshipWizardPage extends WizardPage implements
39
		IPropertyChangeListener {
40

    
41
	private final CdmFormFactory formFactory;
42

    
43
	private NameSelectionElement selection_relatedTo;
44

    
45
	private NameRelationshipTypeComboElement combo_relationshipType;
46

    
47
	private final NameRelationshipDetailSection callingSection;
48

    
49
	private final TaxonNameBase entity;
50

    
51
	private NameRelationshipType type;
52

    
53
	private TaxonNameBase toName;
54

    
55
	private RootElement rootElement;
56

    
57
	/**
58
	 * <p>
59
	 * Constructor for NameRelationshipWizardPage.
60
	 * </p>
61
	 * 
62
	 * @param callingSection
63
	 *            a
64
	 *            {@link eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailSection}
65
	 *            object.
66
	 */
67
	protected NameRelationshipWizardPage(
68
			NameRelationshipDetailSection callingSection) {
69
		super("NameRelationshipWizardPage");
70
		setTitle("New Name Relationship");
71
		setDescription(callingSection.getEntity().getTitleCache());
72
		this.callingSection = callingSection;
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(CdmFormFactory.LAYOUT(2, false));
94

    
95
		rootElement = new RootElement(formFactory, control);
96

    
97
		combo_relationshipType = (NameRelationshipTypeComboElement) formFactory
98
				.createTermComboElement(TermComboType.NAMERELATIONSHIP,
99
						rootElement, "Name Relationship Type", null, SWT.NULL);
100

    
101
		selection_relatedTo = (NameSelectionElement) formFactory
102
				.createSelectionElement(SelectionType.NAME,
103
						((NameRelationshipWizard) getWizard())
104
								.getConversationHolder(), rootElement,
105
						"Related to", null, NameSelectionElement.DEFAULT,
106
						SWT.NULL);
107

    
108
		setControl(control);
109
	}
110

    
111
	/**
112
	 * <p>
113
	 * getNameRelationship
114
	 * </p>
115
	 * 
116
	 * @return a {@link eu.etaxonomy.cdm.model.name.NameRelationship} object.
117
	 */
118
	public NameRelationship getNameRelationship() {
119
		return entity.addRelationshipToName(toName, type, null, null, null);
120
	}
121

    
122
	/** {@inheritDoc} */
123
	@Override
124
	public void propertyChange(PropertyChangeEvent event) {
125
		if (event == null) {
126
			return;
127
		}
128
		Object eventSource = event.getSource();
129
		if (eventSource == combo_relationshipType) {
130
			type = combo_relationshipType.getSelection();
131
		} else if (eventSource == selection_relatedTo) {
132
			toName = selection_relatedTo.getEntity();
133
		}
134

    
135
		setPageComplete(type != null && toName != null);
136
	}
137

    
138
	/** {@inheritDoc} */
139
	@Override
140
	public void dispose() {
141
		rootElement.removeElements();
142
		formFactory.removePropertyChangeListener(this);
143
		super.dispose();
144
	}
145
}
(11-11/21)