Project

General

Profile

Download (3.66 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2007 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
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.swt.SWT;
15
import org.eclipse.swt.widgets.Composite;
16

    
17
import eu.etaxonomy.cdm.model.name.NameRelationship;
18
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
19
import eu.etaxonomy.cdm.model.name.TaxonName;
20
import eu.etaxonomy.taxeditor.l10n.Messages;
21
import eu.etaxonomy.taxeditor.ui.AbstractEntityCollectionElementWizardPage;
22
import eu.etaxonomy.taxeditor.ui.combo.NameRelationshipTypeCombo;
23
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
24

    
25
/**
26
 * <p>
27
 * NameRelationshipWizardPage class.
28
 * </p>
29
 *
30
 * @author n.hoffmann
31
 * @created Jun 1, 2010
32
 * @version 1.0
33
 */
34
public class NameRelationshipWizardPage extends AbstractEntityCollectionElementWizardPage implements
35
		IPropertyChangeListener {
36

    
37
	private EntitySelectionElement<TaxonName> selection_relatedTo;
38

    
39
	private NameRelationshipTypeCombo combo_relationshipType;
40

    
41
	private final TaxonName entity;
42

    
43
	private NameRelationshipType type;
44

    
45
	private TaxonName relatedName;
46
	boolean inverse;
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"); //$NON-NLS-1$
61
		setTitle("New Name Relationship"); //$NON-NLS-1$
62
		//setDescription(callingSection.getEntity().getTitleCache());
63
		setDescription(Messages.NameRelationshipWizardPage_description);
64
		this.entity = callingSection.getEntity();
65
		this.formFactory = callingSection.getFormFactory();
66

    
67
		formFactory.addPropertyChangeListener(this);
68
	}
69

    
70
	/*
71
	 * (non-Javadoc)
72
	 *
73
	 * @see
74
	 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
75
	 * .Composite)
76
	 */
77
	/** {@inheritDoc} */
78
	@Override
79
	public void createControl(Composite parent) {
80
	    super.createControl(parent);
81

    
82
		combo_relationshipType = formFactory.createNameRelationshipTypeCombo(rootElement,
83
	            entity.getNameCache(), SWT.NULL, false,null);
84

    
85

    
86
		selection_relatedTo = formFactory
87
				.createSelectionElement(TaxonName.class,
88
						((NameRelationshipWizard) getWizard())
89
								.getConversationHolder(), rootElement,
90
						"",this.entity, EntitySelectionElement.ALL,
91
						SWT.NULL, true);
92

    
93
	}
94

    
95
	/**
96
	 * <p>
97
	 * getNameRelationship
98
	 * </p>
99
	 *
100
	 * @return a {@link eu.etaxonomy.cdm.model.name.NameRelationship} object.
101
	 */
102
	public NameRelationship getNameRelationship() {
103
	    NameRelationship rel;
104
	    if (inverse){
105
	        rel = entity.addRelationshipFromName(relatedName, type, null, null, null);
106
	    }else{
107
	        rel = entity.addRelationshipToName(relatedName, type, null, null, null);
108
	    }
109
	    return rel;
110
	}
111

    
112
	/** {@inheritDoc} */
113
	@Override
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().getTerm();
121
			this.inverse = combo_relationshipType.getSelection().isInverse();
122
		} else if (eventSource == selection_relatedTo) {
123
			relatedName = selection_relatedTo.getEntity();
124
		}
125

    
126
		boolean complete = type != null && relatedName != null;
127
		setPageComplete(complete);
128
	}
129

    
130
}
(11-11/21)