Project

General

Profile

Download (5.04 KB) Statistics
| Branch: | Tag: | Revision:
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.common.TermType;
19
import eu.etaxonomy.cdm.model.taxon.Synonym;
20
import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
21
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
24
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
25
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
26
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
27
import eu.etaxonomy.taxeditor.ui.element.RootElement;
28
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
29

    
30
/**
31
 * @author pplitzner
32
 * @date 27.01.2014
33
 *
34
 */
35
public class SynonymRelationshipWizardPage extends WizardPage implements IPropertyChangeListener {
36

    
37
    private final CdmFormFactory formFactory;
38

    
39
    private EntitySelectionElement<Taxon> selection_relatedTo;
40

    
41
    private TermComboElement<SynonymRelationshipType> combo_relationshipType;
42

    
43
    private CheckboxElement checkboxProParte;
44

    
45
    private boolean isProParte;
46

    
47
    private CheckboxElement checkboxPartial;
48

    
49
    private boolean isPartial;
50

    
51
    private final Synonym entity;
52

    
53
    private SynonymRelationshipType type;
54

    
55
    private Taxon taxon;
56

    
57
    private RootElement rootElement;
58

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

    
77
        formFactory.addPropertyChangeListener(this);
78
    }
79

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

    
92
        Composite control = formFactory.createComposite(parent);
93

    
94
        control.setLayout(LayoutConstants.LAYOUT(2, false));
95

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

    
98
        combo_relationshipType = formFactory.createDefinedTermComboElement(TermType.SynonymRelationshipType,
99
                rootElement, "Synonym Relationship Type", null, SWT.NULL);
100

    
101
        selection_relatedTo = formFactory
102
                .createSelectionElement(Taxon.class,
103
                        ((SynonymRelationshipWizard) getWizard())
104
                        .getConversationHolder(), rootElement,
105
                        "Related to", null, EntitySelectionElement.ALL,
106
                        SWT.NULL);
107

    
108
        checkboxProParte = formFactory.createCheckbox(rootElement, "Pro Parte Synonym", null, SWT.NULL);
109

    
110
        checkboxPartial = formFactory.createCheckbox(rootElement, "Partial Synonym", null, SWT.NULL);
111

    
112
        setControl(control);
113
    }
114

    
115
    /**
116
     * <p>
117
     * getNameRelationship
118
     * </p>
119
     *
120
     * @return a {@link eu.etaxonomy.cdm.model.name.NameRelationship} object.
121
     */
122
    public SynonymRelationship getSynonymRelationship() {
123
        SynonymRelationship synonymRelationship = taxon.addSynonym(entity, combo_relationshipType.getSelection());
124
        synonymRelationship.setPartial(isPartial);
125
        synonymRelationship.setProParte(isProParte);
126
        return synonymRelationship;
127
    }
128

    
129
    /** {@inheritDoc} */
130
    @Override
131
    public void propertyChange(PropertyChangeEvent event) {
132
        if (event == null) {
133
            return;
134
        }
135
        Object eventSource = event.getSource();
136
        if (eventSource == combo_relationshipType) {
137
            type = combo_relationshipType.getSelection();
138
        } else if (eventSource == selection_relatedTo) {
139
            taxon = selection_relatedTo.getEntity();
140
        } else if (eventSource == checkboxProParte) {
141
            isProParte = checkboxProParte.getSelection();
142
        } else if (eventSource == checkboxPartial) {
143
            isPartial = checkboxPartial.getSelection();
144
        }
145

    
146
        boolean complete = type != null && taxon != null;
147
        setPageComplete(complete);
148
    }
149

    
150
    /** {@inheritDoc} */
151
    @Override
152
    public void dispose() {
153
        rootElement.removeElements();
154
        formFactory.removePropertyChangeListener(this);
155
        super.dispose();
156
    }
157
}
(24-24/25)