Project

General

Profile

« Previous | Next » 

Revision 661914be

Added by Ben Stöver over 6 years ago

Intermediate commit in implementing wizard validation (before moving to MultiValidator).
Plug-in dependencies added to molecular.

View differences:

eu.etaxonomy.taxeditor.molecular/META-INF/MANIFEST.MF
12 12
 eu.etaxonomy.taxeditor.cdmlib,
13 13
 eu.etaxonomy.taxeditor.editor,
14 14
 eu.etaxonomy.taxeditor.store,
15
 eu.etaxonomy.taxeditor.molecular.lib
15
 eu.etaxonomy.taxeditor.molecular.lib,
16
 org.eclipse.core.databinding.observable;bundle-version="1.4.0",
17
 org.eclipse.core.databinding;bundle-version="1.4.0",
18
 org.eclipse.jface.databinding;bundle-version="1.5.0",
19
 org.eclipse.core.databinding.property;bundle-version="1.4.0"
16 20
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
17 21
Bundle-ActivationPolicy: lazy
18 22
Bundle-Vendor: EDIT
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/handler/ExportSequenceToFileHandler.java
17 17
import info.bioinfweb.jphyloio.factory.JPhyloIOReaderWriterFactory;
18 18
import info.bioinfweb.jphyloio.objecttranslation.ObjectTranslatorFactory;
19 19

  
20
import java.io.File;
20 21
import java.io.IOException;
21 22

  
22 23
import org.eclipse.core.commands.AbstractHandler;
......
68 69
                parameters.put(ReadWriteParameterNames.KEY_OBJECT_TRANSLATOR_FACTORY, translatorFactory);
69 70

  
70 71
                // Create writer and document adapters:
71
                JPhyloIOEventWriter writer = factory.getWriter(wizard.getSelectedFormat().getFormatID());
72
                JPhyloIOEventWriter writer = factory.getWriter(wizard.getModel().getFormatInfo().getFormatID());
72 73
                ListBasedDocumentDataAdapter document = new ListBasedDocumentDataAdapter();
73
                document.getMatrices().add(new CDMSequenceMatrixAdapter(sequence, wizard.getConsensusSequenceLabel()));
74
                document.getMatrices().add(new CDMSequenceMatrixAdapter(sequence, wizard.getModel().getConsensusSequenceLabel()));
74 75

  
75 76
                // Write document:
77
                File file = new File(wizard.getModel().getFileName());
76 78
                try {
77
                    writer.writeDocument(document, wizard.getSelectedFile(), parameters);
79
                    writer.writeDocument(document, file, parameters);
78 80
                }
79 81
                catch (IOException e) {
80 82
                    e.printStackTrace();
81 83
                    MessagingUtils.errorDialog("IO error", this,
82 84
                            "An error occured when trying to export a consensus sequence alignment to the file \"" +
83
                            wizard.getSelectedFile().getAbsolutePath() + "\".", TaxeditorMolecularPlugin.PLUGIN_ID, e, false);  //TODO set pluginID
85
                            file.getAbsolutePath() + "\".", TaxeditorMolecularPlugin.PLUGIN_ID, e, false);  //TODO set pluginID
84 86
                            //TODO Use multi language error message.
85 87
                }
86 88
            }
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ConsensusSequenceLabelValidator.java
1
/**
2
* Copyright (C) 2016 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
package eu.etaxonomy.taxeditor.molecular.io.wizard;
10

  
11

  
12
import org.eclipse.core.databinding.validation.IValidator;
13
import org.eclipse.core.databinding.validation.ValidationStatus;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
16
import org.eclipse.swt.events.SelectionAdapter;
17
import org.eclipse.swt.events.SelectionEvent;
18
import org.eclipse.swt.widgets.Button;
19

  
20

  
21

  
22
/**
23
 * Validator to make sure a non-empty consensus sequence name is provided. It must be registered as a selection listener
24
 * of the export consensus sequence check box of the wizard page in order to work properly.
25
 *
26
 * @author Ben Stöver
27
 * @date 16.11.2016
28
 */
29
public class ConsensusSequenceLabelValidator extends SelectionAdapter implements IValidator {
30
    private boolean exportConsensusSequence = true;
31
    private ISWTObservableValue checkBoxObersable;
32

  
33

  
34
    public ConsensusSequenceLabelValidator(ISWTObservableValue checkBoxObersable) {
35
        super();
36
        this.checkBoxObersable = checkBoxObersable;
37
    }
38

  
39

  
40
    /**
41
     * {@inheritDoc}
42
     */
43
    @Override
44
    public IStatus validate(Object value) {
45
        if (exportConsensusSequence && ((value == null) || ((String)value).isEmpty())) {
46
            return ValidationStatus.error("The consensus sequence label must not be empty.");  //TODO multi language
47
        }
48
        else {
49
            return ValidationStatus.ok();
50
        }
51
    }
52

  
53

  
54
    /**
55
     * {@inheritDoc}
56
     */
57
    @Override
58
    public void widgetSelected(SelectionEvent event) {
59
        exportConsensusSequence = ((Button)event.getSource()).getSelection();
60

  
61
        // Trigger validation of label:
62
        Object value = checkBoxObersable.getValue();
63
        checkBoxObersable.setValue("");
64
        checkBoxObersable.setValue(value);
65
    }
66
}
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentValidator.java
1
/**
2
* Copyright (C) 2016 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
package eu.etaxonomy.taxeditor.molecular.io.wizard;
10

  
11
import org.eclipse.core.databinding.validation.MultiValidator;
12
import org.eclipse.core.runtime.IStatus;
13

  
14

  
15

  
16
/**
17
 * @author bstoe_01
18
 * @date 16.11.2016
19
 *
20
 */
21
public class ExportSingleReadAlignmentValidator extends MultiValidator {
22
    /**
23
     * {@inheritDoc}
24
     */
25
    @Override
26
    protected IStatus validate() {
27
        // TODO Auto-generated method stub
28
        return null;
29
    }
30
}
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentWizard.java
10 10
package eu.etaxonomy.taxeditor.molecular.io.wizard;
11 11

  
12 12

  
13
import info.bioinfweb.jphyloio.formatinfo.JPhyloIOFormatInfo;
14

  
15
import java.io.File;
16

  
17 13
import org.eclipse.jface.wizard.Wizard;
18 14

  
19 15

  
......
25 21
 * @date 23.06.2016
26 22
 */
27 23
public class ExportSingleReadAlignmentWizard extends Wizard {
28
    private ExportSingleReadAlignmentWizardPage page;
24
    private ExportSingleReadAlignmentWizardModel model = new ExportSingleReadAlignmentWizardModel();
29 25

  
30
    private JPhyloIOFormatInfo selectedFormat = null;
31
    private File selectedFile = null;
32
    private String consensusSequenceLabel = null;
26
    private ExportSingleReadAlignmentWizardPage page;
33 27

  
34 28

  
35 29
    public ExportSingleReadAlignmentWizard() {
36
        setWindowTitle("Export single read alignment");  //TODO Use multi languange message
30
        setWindowTitle("Export single read alignment");  //TODO Use multi language message
31
    }
32

  
33

  
34
    public ExportSingleReadAlignmentWizardModel getModel() {
35
        return model;
37 36
    }
38 37

  
39 38

  
......
46 45

  
47 46
    @Override
48 47
    public boolean performFinish() {
49
        if (!page.getConsensusSequenceLabel().isEmpty()) {
50
            selectedFormat = page.getSelectedFormat();
51
            selectedFile = page.getSelectedFile();
52
            consensusSequenceLabel = page.getConsensusSequenceLabel();
53
            return true;
54
        }
55
        else {
56
            return false;  //TODO Display according error message in wizard heading, as long as valid inputs are not completed.
57
        }
58
    }
59

  
60

  
61
    public JPhyloIOFormatInfo getSelectedFormat() {
62
        return selectedFormat;
63
    }
64

  
65

  
66
    public File getSelectedFile() {
67
        return selectedFile;
68
    }
69

  
70

  
71
    public String getConsensusSequenceLabel() {
72
        return consensusSequenceLabel;
48
        return true;
49
        //TODO Add default extension to file, if necessary?
73 50
    }
74 51
}
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentWizardModel.java
1
/**
2
* Copyright (C) 2016 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
package eu.etaxonomy.taxeditor.molecular.io.wizard;
10

  
11

  
12
import info.bioinfweb.jphyloio.formatinfo.JPhyloIOFormatInfo;
13

  
14
import org.eclipse.core.databinding.observable.value.IObservableValue;
15
import org.eclipse.core.databinding.observable.value.WritableValue;
16

  
17

  
18

  
19
/**
20
 * The data model for a wizard to export single read alignments to different file formats using <i>JPhyloIO</i>.
21
 *
22
 * @author Ben Stöver
23
 * @date 16.11.2016
24
 */
25
public class ExportSingleReadAlignmentWizardModel {
26
    private IObservableValue exportSingleReads = new WritableValue(null, Boolean.class);
27
    private IObservableValue exportConsensusSequence = new WritableValue(null, Boolean.class);
28
    private IObservableValue consensusSequenceLabel = new WritableValue(null, String.class);
29
    private IObservableValue formatInfo = new WritableValue(null, JPhyloIOFormatInfo.class);
30
    private IObservableValue fileName = new WritableValue(null, String.class);
31

  
32

  
33
    public boolean isExportSingleReads() {
34
        return (Boolean)exportSingleReads.getValue();
35
    }
36

  
37

  
38
    protected IObservableValue getExportSingleReadsObservable() {
39
        return exportSingleReads;
40
    }
41

  
42

  
43
    public boolean isExportConsensusSequence() {
44
        return (Boolean)exportConsensusSequence.getValue();
45
    }
46

  
47

  
48
    protected IObservableValue getExportConsensusSequenceObservable() {
49
        return exportConsensusSequence;
50
    }
51

  
52

  
53
    public String getConsensusSequenceLabel() {
54
        return (String)consensusSequenceLabel.getValue();
55
    }
56

  
57

  
58
    protected IObservableValue getConsensusSequenceLabelObservable() {
59
        return consensusSequenceLabel;
60
    }
61

  
62

  
63
    public JPhyloIOFormatInfo getFormatInfo() {
64
        return (JPhyloIOFormatInfo)formatInfo.getValue();
65
    }
66

  
67

  
68
    protected IObservableValue getFormatInfoObservable() {
69
        return formatInfo;
70
    }
71

  
72

  
73
    public String getFileName() {
74
        return (String)fileName.getValue();
75
    }
76

  
77

  
78
    protected IObservableValue getFileNameObservable() {
79
        return fileName;
80
    }
81
}
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentWizardPage.java
15 15
import info.bioinfweb.jphyloio.factory.JPhyloIOReaderWriterFactory;
16 16
import info.bioinfweb.jphyloio.formatinfo.JPhyloIOFormatInfo;
17 17

  
18
import java.io.File;
19 18
import java.util.ArrayList;
20 19
import java.util.Collections;
21 20
import java.util.List;
22 21

  
22
import org.eclipse.core.databinding.DataBindingContext;
23
import org.eclipse.core.databinding.UpdateValueStrategy;
24
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
25
import org.eclipse.jface.databinding.swt.SWTObservables;
26
import org.eclipse.jface.databinding.wizard.WizardPageSupport;
23 27
import org.eclipse.jface.wizard.WizardPage;
24 28
import org.eclipse.swt.SWT;
25 29
import org.eclipse.swt.events.SelectionAdapter;
......
82 86
     */
83 87
    @Override
84 88
    public void createControl(Composite parent) {
89
        DataBindingContext dbc = new DataBindingContext();
90
        WizardPageSupport.create(this, dbc);
91

  
85 92
        Composite container = new Composite(parent, SWT.NULL);
86 93

  
87 94
        setControl(container);
......
93 100
        fd_exportSingleReadsCB.left = new FormAttachment(0, 10);
94 101
        exportSingleReadsCB.setLayoutData(fd_exportSingleReadsCB);
95 102
        exportSingleReadsCB.setText("Export single reads");
103
        dbc.bindValue(SWTObservables.observeSelection(exportSingleReadsCB),
104
                ((ExportSingleReadAlignmentWizard)getWizard()).getModel().getExportSingleReadsObservable());
96 105

  
97 106
        exportConsensusSequenceCB = new Button(container, SWT.CHECK);
98 107
        exportConsensusSequenceCB.setSelection(true);
......
107 116
        fd_exportConsensusSequenceCB.left = new FormAttachment(0, 10);
108 117
        exportConsensusSequenceCB.setLayoutData(fd_exportConsensusSequenceCB);
109 118
        exportConsensusSequenceCB.setText("Export consensus sequence");
119
        ISWTObservableValue exportConsensusSequenceObservable = SWTObservables.observeSelection(exportConsensusSequenceCB);
120
        dbc.bindValue(exportConsensusSequenceObservable,
121
                ((ExportSingleReadAlignmentWizard)getWizard()).getModel().getExportConsensusSequenceObservable());
122

  
123
        // Connect validation of check box and text field for consensus sequence label:
124
        ConsensusSequenceLabelValidator consensusSequenceLabelValidator =
125
                new ConsensusSequenceLabelValidator(exportConsensusSequenceObservable);
126
        exportConsensusSequenceCB.addSelectionListener(consensusSequenceLabelValidator);
110 127

  
111 128
        consensusSequenceNameTextField = new Text(container, SWT.BORDER);
112 129
        consensusSequenceNameTextField.setText("ConsensusSequence");
......
116 133
        fd_consensusSequenceNameTextField.top = new FormAttachment(exportConsensusSequenceCB, 6);
117 134
        fd_consensusSequenceNameTextField.bottom = new FormAttachment(30, 26);
118 135
        consensusSequenceNameTextField.setLayoutData(fd_consensusSequenceNameTextField);
136
        dbc.bindValue(SWTObservables.observeText(consensusSequenceNameTextField, SWT.Modify),  // WidgetProperties.text().observe(consensusSequenceNameTextField) does not perform a refresh, although SWTObservables seems to be deprecated.
137
                ((ExportSingleReadAlignmentWizard)getWizard()).getModel().getConsensusSequenceLabelObservable(),
138
                new UpdateValueStrategy().setAfterConvertValidator(consensusSequenceLabelValidator), null);
119 139

  
120 140
        Label lblFormat = new Label(container, SWT.NONE);
121 141
        FormData fd_lblFormat = new FormData();
......
151 171
        fd_text.left = new FormAttachment(lblAlignmentFile, 6);
152 172
        fd_text.top = new FormAttachment(lblSelectTheExport, 6);
153 173
        fileTextField.setLayoutData(fd_text);
174
        dbc.bindValue(SWTObservables.observeText(fileTextField, SWT.Modify),
175
                ((ExportSingleReadAlignmentWizard)getWizard()).getModel().getFileNameObservable(),
176
                new UpdateValueStrategy().setAfterConvertValidator(new FileNameValidator()), null);
154 177

  
155 178
        Button btnBrowse = new Button(container, SWT.NONE);
156 179
        btnBrowse.addSelectionListener(new SelectionAdapter() {
......
158 181
            public void widgetSelected(SelectionEvent e) {
159 182
                FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
160 183
                dialog.setText("Export to");  //TODO Make multi language
161
                //fd.setFilterPath("C:/");
162 184
                ContentExtensionFileFilter filter = getSelectedFormat().createFileFilter();
163 185
                dialog.setFilterExtensions(new String[]{filter.getExtensionsAsString()});
164 186
                dialog.setFilterNames(new String[]{filter.getDescription()});
......
166 188
                if (selectedFile != null) {  // Otherwise selecting was canceled.
167 189
                    fileTextField.setText(selectedFile);
168 190
                }
169
                //TODO Add default extension, if necessary.
170 191
            }
171 192
        });
172 193
        fd_text.right = new FormAttachment(100, -134);
......
181 202
        for (JPhyloIOFormatInfo formatInfo : FORMATS) {
182 203
            formatComboBox.add(formatInfo.getFormatName());
183 204
        }
205
        //TODO Bind property and somehow handle translation. (Or use model view combo box from JFace.)
184 206

  
185 207
        FormData fd_formatComboBox = new FormData();
186 208
        fd_formatComboBox.right = new FormAttachment(consensusSequenceNameTextField, 0, SWT.RIGHT);
......
196 218
     *
197 219
     * @return the format info or {@code null}, if none was yet selected
198 220
     */
199
    public JPhyloIOFormatInfo getSelectedFormat() {
221
    private JPhyloIOFormatInfo getSelectedFormat() {
200 222
        if (formatComboBox != null) {
201 223
            int index = formatComboBox.getSelectionIndex();
202 224
            if (index > -1) {
......
205 227
        }
206 228
        return null;
207 229
    }
208

  
209

  
210
    public File getSelectedFile() {
211
        if (fileTextField !=  null) {
212
            return new File(fileTextField.getText());
213
        }
214
        else {
215
            return null;
216
        }
217
    }
218

  
219

  
220
    public String getConsensusSequenceLabel() {
221
        if (consensusSequenceNameTextField != null) {
222
            return consensusSequenceNameTextField.getText();
223
        }
224
        else {
225
            return null;
226
        }
227
    }
228 230
}
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/FileNameValidator.java
1
/**
2
* Copyright (C) 2016 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
package eu.etaxonomy.taxeditor.molecular.io.wizard;
10

  
11

  
12
import org.eclipse.core.databinding.validation.IValidator;
13
import org.eclipse.core.databinding.validation.ValidationStatus;
14
import org.eclipse.core.runtime.IStatus;
15

  
16

  
17

  
18
/**
19
 * Validator to make sure a non-empty file name is provided.
20
 *
21
 * @author Ben Stöver
22
 * @date 16.11.2016
23
 */
24
public class FileNameValidator implements IValidator {
25
    /**
26
     * {@inheritDoc}
27
     */
28
    @Override
29
    public IStatus validate(Object value) {
30
        if ((value == null) || ((String)value).isEmpty()) {
31
            return ValidationStatus.error("The file name must not be empty.");
32
        }
33
        else {
34
            return ValidationStatus.ok();
35
        }
36
        //TODO Display warning, if the file extension does not match the selected format? (An according listener would have to be registered.)
37
    }
38
}

Also available in: Unified diff