Project

General

Profile

Download (9.28 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2016 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.molecular.io.wizard;
11

    
12

    
13
import org.eclipse.core.databinding.DataBindingContext;
14
import org.eclipse.core.databinding.validation.MultiValidator;
15
import org.eclipse.core.databinding.validation.ValidationStatus;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
18
import org.eclipse.jface.databinding.swt.SWTObservables;
19
import org.eclipse.jface.databinding.wizard.WizardPageSupport;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.events.SelectionAdapter;
22
import org.eclipse.swt.events.SelectionEvent;
23
import org.eclipse.swt.layout.FormAttachment;
24
import org.eclipse.swt.layout.FormData;
25
import org.eclipse.swt.layout.FormLayout;
26
import org.eclipse.swt.widgets.Button;
27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Label;
29
import org.eclipse.swt.widgets.Text;
30

    
31
import eu.etaxonomy.taxeditor.molecular.Messages;
32

    
33

    
34

    
35
/**
36
 * Wizard page that allows to specify which parts of a single read alignment shall be exported to an alignment file.
37
 *
38
 * @author Ben Stöver
39
 * @date 18.04.2016
40
 */
41
public class ExportSingleReadAlignmentOptionsPage extends AbstractExportSingleReadAlignmentWizardPage {
42
    private Text consensusSequenceLabelTextField;
43
    private Button exportConsensusSequenceCB;
44
    private Button exportSingleReadsCB;
45
    private Button gapRadioButton;
46
    private Button missingDataRadioButton;
47
    private Button elongateSequecesCheckBox;
48

    
49

    
50
    /**
51
     * Create the wizard.
52
     */
53
    public ExportSingleReadAlignmentOptionsPage() {
54
        super("ExportSingleReadAlignmentOptions");  //TODO Which pageName should be used here? Any conventions? //$NON-NLS-1$
55
        setTitle(Messages.wizardExportAlignmentOptionsTitle);
56
        setDescription(Messages.wizardExportAlignmentOptionsDescription);
57
    }
58

    
59

    
60
    /**
61
     * Create contents of the wizard.
62
     *
63
     * @param parent the parent component
64
     */
65
    @Override
66
    public void createControl(Composite parent) {
67
        DataBindingContext dbc = new DataBindingContext();
68
        WizardPageSupport.create(this, dbc);
69

    
70
        Composite container = new Composite(parent, SWT.NULL);
71

    
72
        setControl(container);
73
        container.setLayout(new FormLayout());
74

    
75
        exportSingleReadsCB = new Button(container, SWT.CHECK);
76
        FormData fd_exportSingleReadsCB = new FormData();
77
        fd_exportSingleReadsCB.top = new FormAttachment(0, 40);
78
        fd_exportSingleReadsCB.left = new FormAttachment(0, 10);
79
        exportSingleReadsCB.setLayoutData(fd_exportSingleReadsCB);
80
        exportSingleReadsCB.setText(Messages.wizardExportAlignmentExportSingleReads);
81
        final ISWTObservableValue exportSingleReadsObservable = SWTObservables.observeSelection(exportSingleReadsCB);
82
        dbc.bindValue(exportSingleReadsObservable, getWizard().getModel().getExportSingleReadsObservable());
83
        exportSingleReadsCB.setSelection(false);
84
        exportSingleReadsCB.setSelection(true);  // Must happen after the component has been bound to the model.
85

    
86

    
87
        exportConsensusSequenceCB = new Button(container, SWT.CHECK);
88
        exportConsensusSequenceCB.addSelectionListener(new SelectionAdapter() {
89
            @Override
90
            public void widgetSelected(SelectionEvent e) {
91
                consensusSequenceLabelTextField.setEnabled(exportConsensusSequenceCB.getSelection());
92
            }
93
        });
94
        FormData fd_exportConsensusSequenceCB = new FormData();
95
        fd_exportConsensusSequenceCB.top = new FormAttachment(exportSingleReadsCB, 6);
96
        fd_exportConsensusSequenceCB.left = new FormAttachment(0, 10);
97
        exportConsensusSequenceCB.setLayoutData(fd_exportConsensusSequenceCB);
98
        exportConsensusSequenceCB.setText(Messages.wizardExportAlignmentExportConsensusSeqLabel);
99
        final ISWTObservableValue exportConsensusSequenceObservable = SWTObservables.observeSelection(exportConsensusSequenceCB);
100
        dbc.bindValue(exportConsensusSequenceObservable, getWizard().getModel().getExportConsensusSequenceObservable());
101
        exportConsensusSequenceCB.setSelection(false);
102
        exportConsensusSequenceCB.setSelection(true);  // Must happen after the component has been bound to the model.
103

    
104
        consensusSequenceLabelTextField = new Text(container, SWT.BORDER);
105
        FormData fd_consensusSequenceNameTextField = new FormData();
106
        fd_consensusSequenceNameTextField.bottom = new FormAttachment(exportConsensusSequenceCB, 32, SWT.BOTTOM);
107
        fd_consensusSequenceNameTextField.top = new FormAttachment(exportConsensusSequenceCB, 6);
108
        fd_consensusSequenceNameTextField.right = new FormAttachment(100, -10);
109
        fd_consensusSequenceNameTextField.left = new FormAttachment(0, 32);
110
        consensusSequenceLabelTextField.setLayoutData(fd_consensusSequenceNameTextField);
111
        final ISWTObservableValue consensusSequenceLabelObservable = SWTObservables.observeText(consensusSequenceLabelTextField, SWT.Modify);
112
        dbc.bindValue(consensusSequenceLabelObservable, getWizard().getModel().getConsensusSequenceLabelObservable());
113
        consensusSequenceLabelTextField.setText("Consensus"); //$NON-NLS-1$
114

    
115
        Label lblSpecifyTheSequences = new Label(container, SWT.NONE);
116
        FormData fd_lblSpecifyTheSequences = new FormData();
117
        fd_lblSpecifyTheSequences.top = new FormAttachment(0, 10);
118
        fd_lblSpecifyTheSequences.left = new FormAttachment(0, 10);
119
        lblSpecifyTheSequences.setLayoutData(fd_lblSpecifyTheSequences);
120
        lblSpecifyTheSequences.setText(Messages.wizardExportAlignmentExportedSeqHeading);
121

    
122
        Label lblSpecifyAdditionalExport = new Label(container, SWT.NONE);
123
        FormData fd_lblSpecifyAdditionalExport = new FormData();
124
        fd_lblSpecifyAdditionalExport.top = new FormAttachment(consensusSequenceLabelTextField, 24);
125
        fd_lblSpecifyAdditionalExport.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT);
126
        lblSpecifyAdditionalExport.setLayoutData(fd_lblSpecifyAdditionalExport);
127
        lblSpecifyAdditionalExport.setText(Messages.wizardExportAlignmentAdditionalOptionsHeading);
128

    
129
        elongateSequecesCheckBox = new Button(container, SWT.CHECK);
130
        elongateSequecesCheckBox.addSelectionListener(new SelectionAdapter() {
131
            @Override
132
            public void widgetSelected(SelectionEvent e) {
133
                missingDataRadioButton.setEnabled(elongateSequecesCheckBox.getSelection());
134
                gapRadioButton.setEnabled(elongateSequecesCheckBox.getSelection());
135
            }
136
        });
137
        FormData fd_btnElongateSequecesTo = new FormData();
138
        fd_btnElongateSequecesTo.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT);
139
        fd_btnElongateSequecesTo.top = new FormAttachment(lblSpecifyAdditionalExport, 12);
140
        elongateSequecesCheckBox.setLayoutData(fd_btnElongateSequecesTo);
141
        elongateSequecesCheckBox.setText(Messages.wizardExportAlignmentElongateSeqHeading);
142
        dbc.bindValue(SWTObservables.observeSelection(elongateSequecesCheckBox), getWizard().getModel().getElongateSequencesObservable());
143

    
144
        missingDataRadioButton = new Button(container, SWT.RADIO);
145
        FormData fd_missingDataRadioButton = new FormData();
146
        fd_missingDataRadioButton.top = new FormAttachment(elongateSequecesCheckBox, 6);
147
        missingDataRadioButton.setLayoutData(fd_missingDataRadioButton);
148
        missingDataRadioButton.setEnabled(false);
149
        missingDataRadioButton.setText(Messages.wizardExportAlignmentElongateSeqMissingData);
150

    
151
        gapRadioButton = new Button(container, SWT.RADIO);
152
        fd_missingDataRadioButton.left = new FormAttachment(gapRadioButton, 80);
153
        FormData fd_gapRadioButton = new FormData();
154
        fd_gapRadioButton.top = new FormAttachment(elongateSequecesCheckBox, 6);
155
        fd_gapRadioButton.left = new FormAttachment(consensusSequenceLabelTextField, 0, SWT.LEFT);
156
        gapRadioButton.setLayoutData(fd_gapRadioButton);
157
        gapRadioButton.setEnabled(false);
158
        gapRadioButton.setSelection(true);
159
        gapRadioButton.setText(Messages.wizardExportAlignmentElongateSeqGap);
160
        dbc.bindValue(SWTObservables.observeSelection(gapRadioButton), getWizard().getModel().getUseGapTokenObservable());
161

    
162
        setPageComplete(true);  // Allow to finish the wizard in the previous page.
163

    
164
        dbc.addValidationStatusProvider(new MultiValidator() {
165
            @Override
166
            protected IStatus validate() {
167
                String label = (String)consensusSequenceLabelObservable.getValue();
168
                boolean exportConsensus = (Boolean)exportConsensusSequenceObservable.getValue();
169
                boolean exportReads = (Boolean)exportSingleReadsObservable.getValue();
170

    
171
                if (!exportConsensus && !exportReads) {
172
                    return ValidationStatus.error(Messages.wizardExportAlignmentErrorNothingToExport);
173
                }
174
                else if (exportConsensus && ((label == null) || label.isEmpty())) {
175
                    return ValidationStatus.error(Messages.wizardExportAlignmentErrorMissingSeqLabel);
176
                }
177
                else {
178
                    return ValidationStatus.ok();
179
                }
180
            }
181
        });
182
    }
183
}
(3-3/5)