From: b.stoever Date: Wed, 16 Nov 2016 22:18:26 +0000 (+0100) Subject: Export single read alignment wizard validation refactored and extended. X-Git-Tag: 4.5.0^2~29 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/7ffbdbb1d16511194a10930cf2d84bfdcede8785?hp=661914bed4382c67f7aaf93967dad6a5f69dd802 Export single read alignment wizard validation refactored and extended. Some German translations in molecular plug-in added. --- diff --git a/eu.etaxonomy.taxeditor.molecular/OSGI-INF/l10n/bundle_de.properties b/eu.etaxonomy.taxeditor.molecular/OSGI-INF/l10n/bundle_de.properties index 2fee24384..40518278c 100644 --- a/eu.etaxonomy.taxeditor.molecular/OSGI-INF/l10n/bundle_de.properties +++ b/eu.etaxonomy.taxeditor.molecular/OSGI-INF/l10n/bundle_de.properties @@ -1,23 +1,23 @@ #Properties file for eu.etaxonomy.taxeditor.molecular editor.ALIGNMENT_EDITOR = Alignment Editor view.PHEROGRAM_VIEW = PherogramView -command.EDIT_SEQUENCE = Edit Sequence +command.EDIT_SEQUENCE = Sequenz bearbeiten command.name.SHOW_PHEROGRAM = Show Pherogram command.name.EXPORT_SEQUENCE_TO_FILE = Alignmentdatei exportieren -command.name.CUT_PHEROGRAM_LEFT = Cut pherogram left -command.name.CUT_PHEROGRAM_RIGHT = Cut pherogram right -command.name.REVERSE_COMPLEMENT_SELECTED_ROWS = Reverse complement selected rows -command.name.CREATE_CONSENUS_SEQUENCE = (Re)create consensus sequence -command.name.UPDATE_CONSENSUS_SEQUENCE = Update consensus sequence -command.name.TOGGLE_SHOW_PROBABILITY_VALUES = Toggle show probability values -command.name.TOGGLE_SHOW_BASE_CALL_LINES = Toggle show base call lines -command.name.CHANGE_QUALITY_OUTPUT = Change quality output -command.name.LOAD_PHEROGRAM = Load Pherogram -command.name.TOGGLE_INSERT_OVERWRITE = Toggle insert/overwrite -command.name.TOGGLE_LEFT_RIGHT_INSERTION = Toggle left/right insertion in base call sequence -command.TOGGLE_INSERT_OVERWRITE = Toggle insert/overwrite +command.name.CUT_PHEROGRAM_LEFT = Pherogramm links abschneiden +command.name.CUT_PHEROGRAM_RIGHT = Pherogramm rechts abschneiden +command.name.REVERSE_COMPLEMENT_SELECTED_ROWS = Ausgewählte Spalten reverse complementen +command.name.CREATE_CONSENUS_SEQUENCE = Konsensussequenz (neu) erzeugen +command.name.UPDATE_CONSENSUS_SEQUENCE = Konsensussequenz aktualisieren +command.name.TOGGLE_SHOW_PROBABILITY_VALUES = Anzeige von Wahrscheinlichkeiten umschalten +command.name.TOGGLE_SHOW_BASE_CALL_LINES = Base-Call-Linienanzeige umschalten +command.name.CHANGE_QUALITY_OUTPUT = Qualitätsausgabe umschalten +command.name.LOAD_PHEROGRAM = Pherogram laden +command.name.TOGGLE_INSERT_OVERWRITE = Einfügen/Überschreiben umschalten +command.name.TOGGLE_LEFT_RIGHT_INSERTION = Links/rechts Einfügen in Base-Call-Sequenz umschalten +command.TOGGLE_INSERT_OVERWRITE = Einfügen/Überschreiben umschalten menu.ALIGNMENT_EDITOR = Alignment Editor menu.label.PHEROGRAM_VIEW = Pherogram View -command.label.EDIT_SEQUENCE = Edit Sequence +command.label.EDIT_SEQUENCE = Sequenz bearbeiten command.label.EXPORT_SEQUENCE_TO_FILE = Alignmentdatei exportieren -command.label.SHOW_PHEROGRAM = Show Pherogram \ No newline at end of file +command.label.SHOW_PHEROGRAM = Pherogram anzeigen \ No newline at end of file diff --git a/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/editor/AlignmentEditor.java b/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/editor/AlignmentEditor.java index 6409f8f0a..da122384a 100644 --- a/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/editor/AlignmentEditor.java +++ b/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/editor/AlignmentEditor.java @@ -394,7 +394,7 @@ public class AlignmentEditor extends EditorPart { bars.getStatusLineManager().setMessage("Edit mode: " + (getReadsArea().getEditSettings().isInsert() ? "Insert" : "Overwrite") + " " + "Insertion in pherogram: " + - (getReadsArea().getEditSettings().isInsertLeftInDataArea() ? "Left" : "Right")); + (getReadsArea().getEditSettings().isInsertLeftInDataArea() ? "Left" : "Right")); //TODO multi language } @@ -412,7 +412,7 @@ public class AlignmentEditor extends EditorPart { @Override public void doSave(IProgressMonitor monitor) { if (getEditorInput() instanceof AlignmentEditorInput) { - String taskName = "Saving alignment"; + String taskName = "Saving alignment"; //TODO multi language monitor.beginTask(taskName, 3); //re-loading sequence to avoid session conflicts @@ -439,7 +439,7 @@ public class AlignmentEditor extends EditorPart { String id = iterator.next(); SingleReadAlignment singleRead = cdmMap.get(id); if (singleRead == null) { - throw new InternalError("Creating new reads from AlignmentEditor not implemented."); + throw new InternalError("Creating new reads from AlignmentEditor not implemented."); //TODO multi language //TODO Create new read object. => Shall it be allowed to add reads in the alignment editor which are not represented in the CDM tree before the alignment editor is saved? //singleRead = SingleReadAlignment.NewInstance(consensusSequence, singleRead, shifts, editedSequence); } @@ -538,13 +538,13 @@ public class AlignmentEditor extends EditorPart { private String cutPherogram(boolean left) { SelectionModel selection = getReadsArea().getSelection(); if (selection.getCursorHeight() != 1) { - return "Cutting pherograms is only possible if exactly one row is selected."; + return "Cutting pherograms is only possible if exactly one row is selected."; //TODO multi language } else { PherogramArea pherogramArea = getPherogramArea(getReadsArea().getSequenceOrder().idByIndex(selection.getCursorRow())); if (pherogramArea == null) { - return "There is no pherogram attached to the current sequence."; + return "There is no pherogram attached to the current sequence."; //TODO multi language } else { if (left) { @@ -552,7 +552,7 @@ public class AlignmentEditor extends EditorPart { return null; } else { - return "The left end of the selection lies outside the pherogram attached to this sequence."; + return "The left end of the selection lies outside the pherogram attached to this sequence."; //TODO multi language } } else { @@ -560,7 +560,7 @@ public class AlignmentEditor extends EditorPart { return null; } else { - return "The right end of the selection lies outside the pherogram attached to this sequence."; + return "The right end of the selection lies outside the pherogram attached to this sequence."; //TODO multi language } } } diff --git a/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ConsensusSequenceLabelValidator.java b/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ConsensusSequenceLabelValidator.java deleted file mode 100644 index 2c41a2860..000000000 --- a/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ConsensusSequenceLabelValidator.java +++ /dev/null @@ -1,66 +0,0 @@ -/** -* Copyright (C) 2016 EDIT -* European Distributed Institute of Taxonomy -* http://www.e-taxonomy.eu -* -* The contents of this file are subject to the Mozilla Public License Version 1.1 -* See LICENSE.TXT at the top of this package for the full license terms. -*/ -package eu.etaxonomy.taxeditor.molecular.io.wizard; - - -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.databinding.swt.ISWTObservableValue; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.widgets.Button; - - - -/** - * Validator to make sure a non-empty consensus sequence name is provided. It must be registered as a selection listener - * of the export consensus sequence check box of the wizard page in order to work properly. - * - * @author Ben Stöver - * @date 16.11.2016 - */ -public class ConsensusSequenceLabelValidator extends SelectionAdapter implements IValidator { - private boolean exportConsensusSequence = true; - private ISWTObservableValue checkBoxObersable; - - - public ConsensusSequenceLabelValidator(ISWTObservableValue checkBoxObersable) { - super(); - this.checkBoxObersable = checkBoxObersable; - } - - - /** - * {@inheritDoc} - */ - @Override - public IStatus validate(Object value) { - if (exportConsensusSequence && ((value == null) || ((String)value).isEmpty())) { - return ValidationStatus.error("The consensus sequence label must not be empty."); //TODO multi language - } - else { - return ValidationStatus.ok(); - } - } - - - /** - * {@inheritDoc} - */ - @Override - public void widgetSelected(SelectionEvent event) { - exportConsensusSequence = ((Button)event.getSource()).getSelection(); - - // Trigger validation of label: - Object value = checkBoxObersable.getValue(); - checkBoxObersable.setValue(""); - checkBoxObersable.setValue(value); - } -} diff --git a/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentValidator.java b/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentValidator.java deleted file mode 100644 index b382879a9..000000000 --- a/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentValidator.java +++ /dev/null @@ -1,30 +0,0 @@ -/** -* Copyright (C) 2016 EDIT -* European Distributed Institute of Taxonomy -* http://www.e-taxonomy.eu -* -* The contents of this file are subject to the Mozilla Public License Version 1.1 -* See LICENSE.TXT at the top of this package for the full license terms. -*/ -package eu.etaxonomy.taxeditor.molecular.io.wizard; - -import org.eclipse.core.databinding.validation.MultiValidator; -import org.eclipse.core.runtime.IStatus; - - - -/** - * @author bstoe_01 - * @date 16.11.2016 - * - */ -public class ExportSingleReadAlignmentValidator extends MultiValidator { - /** - * {@inheritDoc} - */ - @Override - protected IStatus validate() { - // TODO Auto-generated method stub - return null; - } -} diff --git a/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentWizardModel.java b/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentWizardModel.java index 7fa09c99c..161b35ff8 100644 --- a/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentWizardModel.java +++ b/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentWizardModel.java @@ -9,8 +9,14 @@ package eu.etaxonomy.taxeditor.molecular.io.wizard; +import info.bioinfweb.jphyloio.events.type.EventContentType; +import info.bioinfweb.jphyloio.factory.JPhyloIOReaderWriterFactory; import info.bioinfweb.jphyloio.formatinfo.JPhyloIOFormatInfo; +import java.util.Collections; +import java.util.Map; +import java.util.TreeMap; + import org.eclipse.core.databinding.observable.value.IObservableValue; import org.eclipse.core.databinding.observable.value.WritableValue; @@ -23,13 +29,29 @@ import org.eclipse.core.databinding.observable.value.WritableValue; * @date 16.11.2016 */ public class ExportSingleReadAlignmentWizardModel { + protected static final JPhyloIOReaderWriterFactory READER_WRITER_FACTORY = new JPhyloIOReaderWriterFactory(); + protected static final Map FORMAT_NAMES_TO_INFO_MAP = createFormatInfoList(); + + private IObservableValue exportSingleReads = new WritableValue(null, Boolean.class); private IObservableValue exportConsensusSequence = new WritableValue(null, Boolean.class); private IObservableValue consensusSequenceLabel = new WritableValue(null, String.class); - private IObservableValue formatInfo = new WritableValue(null, JPhyloIOFormatInfo.class); + private IObservableValue formatInfo = new WritableValue(null, String.class); private IObservableValue fileName = new WritableValue(null, String.class); + private static Map createFormatInfoList() { + Map result = new TreeMap(); + for (String formatID : READER_WRITER_FACTORY.getFormatIDsSet()) { + JPhyloIOFormatInfo info = READER_WRITER_FACTORY.getFormatInfo(formatID); + if (info.isElementModeled(EventContentType.ALIGNMENT, false)) { // Check if the current format allows to write alignments. + result.put(info.getFormatName(), info); + } + } + return Collections.unmodifiableMap(result); + } + + public boolean isExportSingleReads() { return (Boolean)exportSingleReads.getValue(); } @@ -60,13 +82,18 @@ public class ExportSingleReadAlignmentWizardModel { } - public JPhyloIOFormatInfo getFormatInfo() { - return (JPhyloIOFormatInfo)formatInfo.getValue(); + protected IObservableValue getFormatInfoObservable() { + return formatInfo; } - protected IObservableValue getFormatInfoObservable() { - return formatInfo; + /** + * Returns the JPhyloIO format info object to be used for exporting. + * + * @return the format info + */ + public JPhyloIOFormatInfo getFormatInfo() { + return FORMAT_NAMES_TO_INFO_MAP.get(formatInfo.getValue()); } diff --git a/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentWizardPage.java b/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentWizardPage.java index 0c9648f50..4719aa4f4 100644 --- a/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentWizardPage.java +++ b/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentWizardPage.java @@ -11,16 +11,16 @@ package eu.etaxonomy.taxeditor.molecular.io.wizard; import info.bioinfweb.commons.io.ContentExtensionFileFilter; -import info.bioinfweb.jphyloio.events.type.EventContentType; -import info.bioinfweb.jphyloio.factory.JPhyloIOReaderWriterFactory; +import info.bioinfweb.commons.io.ContentExtensionFileFilter.TestStrategy; +import info.bioinfweb.commons.io.ExtensionFileFilter; import info.bioinfweb.jphyloio.formatinfo.JPhyloIOFormatInfo; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.io.File; import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.UpdateValueStrategy; +import org.eclipse.core.databinding.validation.MultiValidator; +import org.eclipse.core.databinding.validation.ValidationStatus; +import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.databinding.swt.ISWTObservableValue; import org.eclipse.jface.databinding.swt.SWTObservables; import org.eclipse.jface.databinding.wizard.WizardPageSupport; @@ -47,10 +47,7 @@ import org.eclipse.swt.widgets.Text; * @date 18.04.2016 */ public class ExportSingleReadAlignmentWizardPage extends WizardPage { - private static final JPhyloIOReaderWriterFactory FACTORY = new JPhyloIOReaderWriterFactory(); - private static final List FORMATS = createFormatInfoList(); - - private Text consensusSequenceNameTextField; + private Text consensusSequenceLabelTextField; private Button exportConsensusSequenceCB; private Button exportSingleReadsCB; private Text fileTextField; @@ -62,20 +59,8 @@ public class ExportSingleReadAlignmentWizardPage extends WizardPage { */ public ExportSingleReadAlignmentWizardPage() { super("SingleReadSequencesExport"); //TODO Which pageName should be used here? Any conventions? - setTitle("Sequence export"); - setDescription("Defines which sequences of the single read alignment shall be exported."); - } - - - private static List createFormatInfoList() { - List result = new ArrayList(); - for (String formatID : FACTORY.getFormatIDsSet()) { - JPhyloIOFormatInfo info = FACTORY.getFormatInfo(formatID); - if (info.isElementModeled(EventContentType.ALIGNMENT, false)) { // Check if the current format allows to write alignments. - result.add(info); - } - } - return Collections.unmodifiableList(result); + setTitle("Sequence export"); //TODO multi language + setDescription("Defines which sequences of the single read alignment shall be exported."); //TODO multi language } @@ -100,15 +85,15 @@ public class ExportSingleReadAlignmentWizardPage extends WizardPage { fd_exportSingleReadsCB.left = new FormAttachment(0, 10); exportSingleReadsCB.setLayoutData(fd_exportSingleReadsCB); exportSingleReadsCB.setText("Export single reads"); - dbc.bindValue(SWTObservables.observeSelection(exportSingleReadsCB), - ((ExportSingleReadAlignmentWizard)getWizard()).getModel().getExportSingleReadsObservable()); + final ISWTObservableValue exportSingleReadsObservable = SWTObservables.observeSelection(exportSingleReadsCB); + dbc.bindValue(exportSingleReadsObservable, getWizard().getModel().getExportSingleReadsObservable()); exportConsensusSequenceCB = new Button(container, SWT.CHECK); exportConsensusSequenceCB.setSelection(true); exportConsensusSequenceCB.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - consensusSequenceNameTextField.setEnabled(exportConsensusSequenceCB.getSelection()); + consensusSequenceLabelTextField.setEnabled(exportConsensusSequenceCB.getSelection()); } }); FormData fd_exportConsensusSequenceCB = new FormData(); @@ -116,33 +101,26 @@ public class ExportSingleReadAlignmentWizardPage extends WizardPage { fd_exportConsensusSequenceCB.left = new FormAttachment(0, 10); exportConsensusSequenceCB.setLayoutData(fd_exportConsensusSequenceCB); exportConsensusSequenceCB.setText("Export consensus sequence"); - ISWTObservableValue exportConsensusSequenceObservable = SWTObservables.observeSelection(exportConsensusSequenceCB); - dbc.bindValue(exportConsensusSequenceObservable, - ((ExportSingleReadAlignmentWizard)getWizard()).getModel().getExportConsensusSequenceObservable()); + final ISWTObservableValue exportConsensusSequenceObservable = SWTObservables.observeSelection(exportConsensusSequenceCB); + dbc.bindValue(exportConsensusSequenceObservable, getWizard().getModel().getExportConsensusSequenceObservable()); - // Connect validation of check box and text field for consensus sequence label: - ConsensusSequenceLabelValidator consensusSequenceLabelValidator = - new ConsensusSequenceLabelValidator(exportConsensusSequenceObservable); - exportConsensusSequenceCB.addSelectionListener(consensusSequenceLabelValidator); - - consensusSequenceNameTextField = new Text(container, SWT.BORDER); - consensusSequenceNameTextField.setText("ConsensusSequence"); + consensusSequenceLabelTextField = new Text(container, SWT.BORDER); + consensusSequenceLabelTextField.setText("ConsensusSequence"); FormData fd_consensusSequenceNameTextField = new FormData(); fd_consensusSequenceNameTextField.left = new FormAttachment(0, 32); fd_consensusSequenceNameTextField.right = new FormAttachment(100, -10); fd_consensusSequenceNameTextField.top = new FormAttachment(exportConsensusSequenceCB, 6); fd_consensusSequenceNameTextField.bottom = new FormAttachment(30, 26); - consensusSequenceNameTextField.setLayoutData(fd_consensusSequenceNameTextField); - dbc.bindValue(SWTObservables.observeText(consensusSequenceNameTextField, SWT.Modify), // WidgetProperties.text().observe(consensusSequenceNameTextField) does not perform a refresh, although SWTObservables seems to be deprecated. - ((ExportSingleReadAlignmentWizard)getWizard()).getModel().getConsensusSequenceLabelObservable(), - new UpdateValueStrategy().setAfterConvertValidator(consensusSequenceLabelValidator), null); + consensusSequenceLabelTextField.setLayoutData(fd_consensusSequenceNameTextField); + final ISWTObservableValue consensusSequenceLabelObservable = SWTObservables.observeText(consensusSequenceLabelTextField, SWT.Modify); + dbc.bindValue(consensusSequenceLabelObservable, getWizard().getModel().getConsensusSequenceLabelObservable()); Label lblFormat = new Label(container, SWT.NONE); FormData fd_lblFormat = new FormData(); - fd_lblFormat.top = new FormAttachment(consensusSequenceNameTextField, 25); + fd_lblFormat.top = new FormAttachment(consensusSequenceLabelTextField, 25); fd_lblFormat.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT); lblFormat.setLayoutData(fd_lblFormat); - lblFormat.setText("Select the export format:"); + lblFormat.setText("Select the export format:"); //TODO multi language Label lblSelectTheData = new Label(container, SWT.NONE); fd_exportSingleReadsCB.top = new FormAttachment(lblSelectTheData, 6); @@ -150,38 +128,38 @@ public class ExportSingleReadAlignmentWizardPage extends WizardPage { fd_lblSelectTheData.left = new FormAttachment(0, 10); fd_lblSelectTheData.top = new FormAttachment(0, 10); lblSelectTheData.setLayoutData(fd_lblSelectTheData); - lblSelectTheData.setText("Select the data to export:"); + lblSelectTheData.setText("Select the data to export:"); //TODO multi language Label lblSelectTheExport = new Label(container, SWT.NONE); FormData fd_lblSelectTheExport = new FormData(); fd_lblSelectTheExport.top = new FormAttachment(lblFormat, 57); fd_lblSelectTheExport.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT); lblSelectTheExport.setLayoutData(fd_lblSelectTheExport); - lblSelectTheExport.setText("Select the export destination:"); + lblSelectTheExport.setText("Select the export destination:"); //TODO multi language Label lblAlignmentFile = new Label(container, SWT.NONE); FormData fd_lblAlignmentFile = new FormData(); fd_lblAlignmentFile.top = new FormAttachment(lblSelectTheExport, 9); fd_lblAlignmentFile.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT); lblAlignmentFile.setLayoutData(fd_lblAlignmentFile); - lblAlignmentFile.setText("Alignment file:"); + lblAlignmentFile.setText("Alignment file:"); //TODO multi language fileTextField = new Text(container, SWT.BORDER); FormData fd_text = new FormData(); - fd_text.left = new FormAttachment(lblAlignmentFile, 6); + fd_text.right = new FormAttachment(consensusSequenceLabelTextField, 0, SWT.RIGHT); fd_text.top = new FormAttachment(lblSelectTheExport, 6); + fd_text.left = new FormAttachment(lblAlignmentFile, 6); fileTextField.setLayoutData(fd_text); - dbc.bindValue(SWTObservables.observeText(fileTextField, SWT.Modify), - ((ExportSingleReadAlignmentWizard)getWizard()).getModel().getFileNameObservable(), - new UpdateValueStrategy().setAfterConvertValidator(new FileNameValidator()), null); + final ISWTObservableValue fileNameObservable = SWTObservables.observeText(fileTextField, SWT.Modify); + dbc.bindValue(fileNameObservable, getWizard().getModel().getFileNameObservable()); Button btnBrowse = new Button(container, SWT.NONE); btnBrowse.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { FileDialog dialog = new FileDialog(getShell(), SWT.OPEN); - dialog.setText("Export to"); //TODO Make multi language - ContentExtensionFileFilter filter = getSelectedFormat().createFileFilter(); + dialog.setText("Export to"); //TODO multi language + ContentExtensionFileFilter filter = getWizard().getModel().getFormatInfo().createFileFilter(TestStrategy.EXTENSION); dialog.setFilterExtensions(new String[]{filter.getExtensionsAsString()}); dialog.setFilterNames(new String[]{filter.getDescription()}); String selectedFile = dialog.open(); @@ -190,41 +168,78 @@ public class ExportSingleReadAlignmentWizardPage extends WizardPage { } } }); - fd_text.right = new FormAttachment(100, -134); FormData fd_btnBrowse = new FormData(); - fd_btnBrowse.left = new FormAttachment(fileTextField, 6); - fd_btnBrowse.top = new FormAttachment(lblAlignmentFile, -5, SWT.TOP); + fd_btnBrowse.bottom = new FormAttachment(100, -10); fd_btnBrowse.right = new FormAttachment(100, -10); btnBrowse.setLayoutData(fd_btnBrowse); btnBrowse.setText("Browse..."); formatComboBox = new Combo(container, SWT.READ_ONLY); - for (JPhyloIOFormatInfo formatInfo : FORMATS) { + for (JPhyloIOFormatInfo formatInfo : ExportSingleReadAlignmentWizardModel.FORMAT_NAMES_TO_INFO_MAP.values()) { formatComboBox.add(formatInfo.getFormatName()); } - //TODO Bind property and somehow handle translation. (Or use model view combo box from JFace.) - FormData fd_formatComboBox = new FormData(); - fd_formatComboBox.right = new FormAttachment(consensusSequenceNameTextField, 0, SWT.RIGHT); + fd_formatComboBox.right = new FormAttachment(consensusSequenceLabelTextField, 0, SWT.RIGHT); fd_formatComboBox.top = new FormAttachment(lblFormat, 6); fd_formatComboBox.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT); formatComboBox.setLayoutData(fd_formatComboBox); formatComboBox.select(0); + final ISWTObservableValue formatObservable = SWTObservables.observeSelection(formatComboBox); // ViewerProperties.singleSelection().observe(formatComboBox); falls ein ComboViewer verwendet wird. (Dann kann direkt FormatInfo verwendet werden.) + + Button appendExtensionButton = new Button(container, SWT.NONE); + appendExtensionButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + fileTextField.setText(fileTextField.getText() + ExtensionFileFilter.EXTENSION_SEPARATOR + + ExportSingleReadAlignmentWizardModel.FORMAT_NAMES_TO_INFO_MAP.get( + formatComboBox.getText()).createFileFilter(TestStrategy.EXTENSION).getDefaultExtension()); + } + }); + fd_btnBrowse.left = new FormAttachment(0, 446); + FormData fd_btnNewButton = new FormData(); + fd_btnNewButton.left = new FormAttachment(btnBrowse, -217, SWT.LEFT); + fd_btnNewButton.bottom = new FormAttachment(100, -10); + fd_btnNewButton.right = new FormAttachment(btnBrowse, -6); + appendExtensionButton.setLayoutData(fd_btnNewButton); + appendExtensionButton.setText("Append default extension"); //TODO multi language + dbc.bindValue(formatObservable, getWizard().getModel().getFormatInfoObservable()); + + dbc.addValidationStatusProvider(new MultiValidator() { + @Override + protected IStatus validate() { + String label = (String)consensusSequenceLabelObservable.getValue(); + boolean exportConsensus = (Boolean)exportConsensusSequenceObservable.getValue(); + boolean exportReads = (Boolean)exportSingleReadsObservable.getValue(); + + if (!exportConsensus && !exportReads) { + return ValidationStatus.error("Either single reads or the consensus sequence have to be selected for export."); //TODO multi language + } + else if (exportConsensus && ((label == null) || label.isEmpty())) { + return ValidationStatus.error("The consensus sequence label must not be empty."); //TODO multi language + } + + String fileName = (String)fileNameObservable.getValue(); + if ((fileName == null) || fileName.isEmpty()) { + return ValidationStatus.error("The file name must not be empty."); //TODO multi language + } + else if (!ExportSingleReadAlignmentWizardModel.FORMAT_NAMES_TO_INFO_MAP.get( + formatObservable.getValue()).createFileFilter(TestStrategy.EXTENSION).accept(new File(fileName))) { + + return ValidationStatus.warning("The file name does have a valid extension for the selected format."); //TODO multi language + } + else { + return ValidationStatus.ok(); + } + } + }); } /** - * Returns the JPhyloIO format info object to be used for exporting. - * - * @return the format info or {@code null}, if none was yet selected + * {@inheritDoc} */ - private JPhyloIOFormatInfo getSelectedFormat() { - if (formatComboBox != null) { - int index = formatComboBox.getSelectionIndex(); - if (index > -1) { - return FORMATS.get(index); - } - } - return null; + @Override + public ExportSingleReadAlignmentWizard getWizard() { + return (ExportSingleReadAlignmentWizard)super.getWizard(); // Would throw an exception, if this page is used within another wizard. } } diff --git a/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/FileNameValidator.java b/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/FileNameValidator.java deleted file mode 100644 index a9475c309..000000000 --- a/eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/FileNameValidator.java +++ /dev/null @@ -1,38 +0,0 @@ -/** -* Copyright (C) 2016 EDIT -* European Distributed Institute of Taxonomy -* http://www.e-taxonomy.eu -* -* The contents of this file are subject to the Mozilla Public License Version 1.1 -* See LICENSE.TXT at the top of this package for the full license terms. -*/ -package eu.etaxonomy.taxeditor.molecular.io.wizard; - - -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.runtime.IStatus; - - - -/** - * Validator to make sure a non-empty file name is provided. - * - * @author Ben Stöver - * @date 16.11.2016 - */ -public class FileNameValidator implements IValidator { - /** - * {@inheritDoc} - */ - @Override - public IStatus validate(Object value) { - if ((value == null) || ((String)value).isEmpty()) { - return ValidationStatus.error("The file name must not be empty."); - } - else { - return ValidationStatus.ok(); - } - //TODO Display warning, if the file extension does not match the selected format? (An according listener would have to be registered.) - } -}