Project

General

Profile

Download (3.85 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.common.TermType;
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.ui.combo.TermComboElement;
24
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
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
 * <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 EntitySelectionElement<TaxonNameBase> selection_relatedTo;
44

    
45
	private TermComboElement<NameRelationshipType> combo_relationshipType;
46

    
47
	private final TaxonNameBase entity;
48

    
49
	private NameRelationshipType type;
50

    
51
	private TaxonNameBase toName;
52

    
53
	private RootElement rootElement;
54

    
55
	/**
56
	 * <p>
57
	 * Constructor for NameRelationshipWizardPage.
58
	 * </p>
59
	 *
60
	 * @param callingSection
61
	 *            a
62
	 *            {@link eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailSection}
63
	 *            object.
64
	 */
65
	protected NameRelationshipWizardPage(
66
			NameRelationshipDetailSection callingSection) {
67
		super("NameRelationshipWizardPage");
68
		setTitle("New Name Relationship");
69
		setDescription(callingSection.getEntity().getTitleCache());
70
		this.entity = callingSection.getEntity();
71
		this.formFactory = callingSection.getFormFactory();
72

    
73
		formFactory.addPropertyChangeListener(this);
74
	}
75

    
76
	/*
77
	 * (non-Javadoc)
78
	 *
79
	 * @see
80
	 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
81
	 * .Composite)
82
	 */
83
	/** {@inheritDoc} */
84
	@Override
85
	public void createControl(Composite parent) {
86
		this.setPageComplete(false);
87

    
88
		Composite control = formFactory.createComposite(parent);
89

    
90
		control.setLayout(LayoutConstants.LAYOUT(2, false));
91

    
92
		rootElement = new RootElement(formFactory, control);
93

    
94
		combo_relationshipType = formFactory.createDefinedTermComboElement(TermType.NameRelationshipType,
95
						rootElement, "Name Relationship Type", null, SWT.NULL);
96

    
97
		selection_relatedTo = formFactory
98
				.createSelectionElement(TaxonNameBase.class,
99
						((NameRelationshipWizard) getWizard())
100
								.getConversationHolder(), rootElement,
101
						"Related to", null, EntitySelectionElement.ALL,
102
						SWT.NULL);
103

    
104
		setControl(control);
105
	}
106

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

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

    
131
		boolean complete = type != null && toName != null;
132
		setPageComplete(complete);
133
	}
134

    
135
	/** {@inheritDoc} */
136
	@Override
137
	public void dispose() {
138
		rootElement.removeElements();
139
		formFactory.removePropertyChangeListener(this);
140
		super.dispose();
141
	}
142
}
(11-11/25)