Export single read alignment wizard validation refactored and extended.
authorb.stoever <stoever@bioinfweb.info>
Wed, 16 Nov 2016 22:18:26 +0000 (23:18 +0100)
committerb.stoever <stoever@bioinfweb.info>
Wed, 16 Nov 2016 22:18:26 +0000 (23:18 +0100)
Some German translations in molecular plug-in added.

eu.etaxonomy.taxeditor.molecular/OSGI-INF/l10n/bundle_de.properties
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/editor/AlignmentEditor.java
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ConsensusSequenceLabelValidator.java [deleted file]
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentValidator.java [deleted file]
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentWizardModel.java
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentWizardPage.java
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/FileNameValidator.java [deleted file]

index 2fee24384be8a2864f0ab084b78bd0662a48f0ba..40518278c1e2377bcb726bf9c9f81cecfea8782e 100644 (file)
@@ -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
index 6409f8f0a2222553bd63c755134d0377728bef3b..da122384a7af28eaa9445d2f2b70ee8a16515177 100644 (file)
@@ -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 (file)
index 2c41a28..0000000
+++ /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 (file)
index b382879..0000000
+++ /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;
-    }
-}
index 7fa09c99c9697cd3a4d9128ca768045e8bf20acb..161b35ff8d829c6ffd62e69453ea03e77c466cda 100644 (file)
@@ -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<String, JPhyloIOFormatInfo> 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<String, JPhyloIOFormatInfo> createFormatInfoList() {
+        Map<String, JPhyloIOFormatInfo> result = new TreeMap<String, JPhyloIOFormatInfo>();
+        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 <i>JPhyloIO</i> format info object to be used for exporting.
+     *
+     * @return the format info
+     */
+    public JPhyloIOFormatInfo getFormatInfo() {
+        return FORMAT_NAMES_TO_INFO_MAP.get(formatInfo.getValue());
     }
 
 
index 0c9648f50b50f8f37466f80b67f987f9947baede..4719aa4f491296dfd7322bbbbae00e589c45634c 100644 (file)
@@ -11,16 +11,16 @@ package eu.etaxonomy.taxeditor.molecular.io.wizard;
 \r
 \r
 import info.bioinfweb.commons.io.ContentExtensionFileFilter;\r
-import info.bioinfweb.jphyloio.events.type.EventContentType;\r
-import info.bioinfweb.jphyloio.factory.JPhyloIOReaderWriterFactory;\r
+import info.bioinfweb.commons.io.ContentExtensionFileFilter.TestStrategy;\r
+import info.bioinfweb.commons.io.ExtensionFileFilter;\r
 import info.bioinfweb.jphyloio.formatinfo.JPhyloIOFormatInfo;\r
 \r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.List;\r
+import java.io.File;\r
 \r
 import org.eclipse.core.databinding.DataBindingContext;\r
-import org.eclipse.core.databinding.UpdateValueStrategy;\r
+import org.eclipse.core.databinding.validation.MultiValidator;\r
+import org.eclipse.core.databinding.validation.ValidationStatus;\r
+import org.eclipse.core.runtime.IStatus;\r
 import org.eclipse.jface.databinding.swt.ISWTObservableValue;\r
 import org.eclipse.jface.databinding.swt.SWTObservables;\r
 import org.eclipse.jface.databinding.wizard.WizardPageSupport;\r
@@ -47,10 +47,7 @@ import org.eclipse.swt.widgets.Text;
  * @date 18.04.2016\r
  */\r
 public class ExportSingleReadAlignmentWizardPage extends WizardPage {\r
-    private static final JPhyloIOReaderWriterFactory FACTORY = new JPhyloIOReaderWriterFactory();\r
-    private static final List<JPhyloIOFormatInfo> FORMATS = createFormatInfoList();\r
-\r
-    private Text consensusSequenceNameTextField;\r
+    private Text consensusSequenceLabelTextField;\r
     private Button exportConsensusSequenceCB;\r
     private Button exportSingleReadsCB;\r
     private Text fileTextField;\r
@@ -62,20 +59,8 @@ public class ExportSingleReadAlignmentWizardPage extends WizardPage {
      */\r
     public ExportSingleReadAlignmentWizardPage() {\r
         super("SingleReadSequencesExport");  //TODO Which pageName should be used here? Any conventions?\r
-        setTitle("Sequence export");\r
-        setDescription("Defines which sequences of the single read alignment shall be exported.");\r
-    }\r
-\r
-\r
-    private static List<JPhyloIOFormatInfo> createFormatInfoList() {\r
-        List<JPhyloIOFormatInfo> result = new ArrayList<JPhyloIOFormatInfo>();\r
-        for (String formatID : FACTORY.getFormatIDsSet()) {\r
-            JPhyloIOFormatInfo info = FACTORY.getFormatInfo(formatID);\r
-            if (info.isElementModeled(EventContentType.ALIGNMENT, false)) {  // Check if the current format allows to write alignments.\r
-                result.add(info);\r
-            }\r
-        }\r
-        return Collections.unmodifiableList(result);\r
+        setTitle("Sequence export");  //TODO multi language\r
+        setDescription("Defines which sequences of the single read alignment shall be exported.");  //TODO multi language\r
     }\r
 \r
 \r
@@ -100,15 +85,15 @@ public class ExportSingleReadAlignmentWizardPage extends WizardPage {
         fd_exportSingleReadsCB.left = new FormAttachment(0, 10);\r
         exportSingleReadsCB.setLayoutData(fd_exportSingleReadsCB);\r
         exportSingleReadsCB.setText("Export single reads");\r
-        dbc.bindValue(SWTObservables.observeSelection(exportSingleReadsCB),\r
-                ((ExportSingleReadAlignmentWizard)getWizard()).getModel().getExportSingleReadsObservable());\r
+        final ISWTObservableValue exportSingleReadsObservable = SWTObservables.observeSelection(exportSingleReadsCB);\r
+        dbc.bindValue(exportSingleReadsObservable, getWizard().getModel().getExportSingleReadsObservable());\r
 \r
         exportConsensusSequenceCB = new Button(container, SWT.CHECK);\r
         exportConsensusSequenceCB.setSelection(true);\r
         exportConsensusSequenceCB.addSelectionListener(new SelectionAdapter() {\r
             @Override\r
             public void widgetSelected(SelectionEvent e) {\r
-                consensusSequenceNameTextField.setEnabled(exportConsensusSequenceCB.getSelection());\r
+                consensusSequenceLabelTextField.setEnabled(exportConsensusSequenceCB.getSelection());\r
             }\r
         });\r
         FormData fd_exportConsensusSequenceCB = new FormData();\r
@@ -116,33 +101,26 @@ public class ExportSingleReadAlignmentWizardPage extends WizardPage {
         fd_exportConsensusSequenceCB.left = new FormAttachment(0, 10);\r
         exportConsensusSequenceCB.setLayoutData(fd_exportConsensusSequenceCB);\r
         exportConsensusSequenceCB.setText("Export consensus sequence");\r
-        ISWTObservableValue exportConsensusSequenceObservable = SWTObservables.observeSelection(exportConsensusSequenceCB);\r
-        dbc.bindValue(exportConsensusSequenceObservable,\r
-                ((ExportSingleReadAlignmentWizard)getWizard()).getModel().getExportConsensusSequenceObservable());\r
+        final ISWTObservableValue exportConsensusSequenceObservable = SWTObservables.observeSelection(exportConsensusSequenceCB);\r
+        dbc.bindValue(exportConsensusSequenceObservable, getWizard().getModel().getExportConsensusSequenceObservable());\r
 \r
-        // Connect validation of check box and text field for consensus sequence label:\r
-        ConsensusSequenceLabelValidator consensusSequenceLabelValidator =\r
-                new ConsensusSequenceLabelValidator(exportConsensusSequenceObservable);\r
-        exportConsensusSequenceCB.addSelectionListener(consensusSequenceLabelValidator);\r
-\r
-        consensusSequenceNameTextField = new Text(container, SWT.BORDER);\r
-        consensusSequenceNameTextField.setText("ConsensusSequence");\r
+        consensusSequenceLabelTextField = new Text(container, SWT.BORDER);\r
+        consensusSequenceLabelTextField.setText("ConsensusSequence");\r
         FormData fd_consensusSequenceNameTextField = new FormData();\r
         fd_consensusSequenceNameTextField.left = new FormAttachment(0, 32);\r
         fd_consensusSequenceNameTextField.right = new FormAttachment(100, -10);\r
         fd_consensusSequenceNameTextField.top = new FormAttachment(exportConsensusSequenceCB, 6);\r
         fd_consensusSequenceNameTextField.bottom = new FormAttachment(30, 26);\r
-        consensusSequenceNameTextField.setLayoutData(fd_consensusSequenceNameTextField);\r
-        dbc.bindValue(SWTObservables.observeText(consensusSequenceNameTextField, SWT.Modify),  // WidgetProperties.text().observe(consensusSequenceNameTextField) does not perform a refresh, although SWTObservables seems to be deprecated.\r
-                ((ExportSingleReadAlignmentWizard)getWizard()).getModel().getConsensusSequenceLabelObservable(),\r
-                new UpdateValueStrategy().setAfterConvertValidator(consensusSequenceLabelValidator), null);\r
+        consensusSequenceLabelTextField.setLayoutData(fd_consensusSequenceNameTextField);\r
+        final ISWTObservableValue consensusSequenceLabelObservable = SWTObservables.observeText(consensusSequenceLabelTextField, SWT.Modify);\r
+        dbc.bindValue(consensusSequenceLabelObservable, getWizard().getModel().getConsensusSequenceLabelObservable());\r
 \r
         Label lblFormat = new Label(container, SWT.NONE);\r
         FormData fd_lblFormat = new FormData();\r
-        fd_lblFormat.top = new FormAttachment(consensusSequenceNameTextField, 25);\r
+        fd_lblFormat.top = new FormAttachment(consensusSequenceLabelTextField, 25);\r
         fd_lblFormat.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT);\r
         lblFormat.setLayoutData(fd_lblFormat);\r
-        lblFormat.setText("Select the export format:");\r
+        lblFormat.setText("Select the export format:");  //TODO multi language\r
 \r
         Label lblSelectTheData = new Label(container, SWT.NONE);\r
         fd_exportSingleReadsCB.top = new FormAttachment(lblSelectTheData, 6);\r
@@ -150,38 +128,38 @@ public class ExportSingleReadAlignmentWizardPage extends WizardPage {
         fd_lblSelectTheData.left = new FormAttachment(0, 10);\r
         fd_lblSelectTheData.top = new FormAttachment(0, 10);\r
         lblSelectTheData.setLayoutData(fd_lblSelectTheData);\r
-        lblSelectTheData.setText("Select the data to export:");\r
+        lblSelectTheData.setText("Select the data to export:");  //TODO multi language\r
 \r
         Label lblSelectTheExport = new Label(container, SWT.NONE);\r
         FormData fd_lblSelectTheExport = new FormData();\r
         fd_lblSelectTheExport.top = new FormAttachment(lblFormat, 57);\r
         fd_lblSelectTheExport.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT);\r
         lblSelectTheExport.setLayoutData(fd_lblSelectTheExport);\r
-        lblSelectTheExport.setText("Select the export destination:");\r
+        lblSelectTheExport.setText("Select the export destination:");  //TODO multi language\r
 \r
         Label lblAlignmentFile = new Label(container, SWT.NONE);\r
         FormData fd_lblAlignmentFile = new FormData();\r
         fd_lblAlignmentFile.top = new FormAttachment(lblSelectTheExport, 9);\r
         fd_lblAlignmentFile.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT);\r
         lblAlignmentFile.setLayoutData(fd_lblAlignmentFile);\r
-        lblAlignmentFile.setText("Alignment file:");\r
+        lblAlignmentFile.setText("Alignment file:");  //TODO multi language\r
 \r
         fileTextField = new Text(container, SWT.BORDER);\r
         FormData fd_text = new FormData();\r
-        fd_text.left = new FormAttachment(lblAlignmentFile, 6);\r
+        fd_text.right = new FormAttachment(consensusSequenceLabelTextField, 0, SWT.RIGHT);\r
         fd_text.top = new FormAttachment(lblSelectTheExport, 6);\r
+        fd_text.left = new FormAttachment(lblAlignmentFile, 6);\r
         fileTextField.setLayoutData(fd_text);\r
-        dbc.bindValue(SWTObservables.observeText(fileTextField, SWT.Modify),\r
-                ((ExportSingleReadAlignmentWizard)getWizard()).getModel().getFileNameObservable(),\r
-                new UpdateValueStrategy().setAfterConvertValidator(new FileNameValidator()), null);\r
+        final ISWTObservableValue fileNameObservable = SWTObservables.observeText(fileTextField, SWT.Modify);\r
+        dbc.bindValue(fileNameObservable, getWizard().getModel().getFileNameObservable());\r
 \r
         Button btnBrowse = new Button(container, SWT.NONE);\r
         btnBrowse.addSelectionListener(new SelectionAdapter() {\r
             @Override\r
             public void widgetSelected(SelectionEvent e) {\r
                 FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);\r
-                dialog.setText("Export to");  //TODO Make multi language\r
-                ContentExtensionFileFilter filter = getSelectedFormat().createFileFilter();\r
+                dialog.setText("Export to");  //TODO multi language\r
+                ContentExtensionFileFilter filter = getWizard().getModel().getFormatInfo().createFileFilter(TestStrategy.EXTENSION);\r
                 dialog.setFilterExtensions(new String[]{filter.getExtensionsAsString()});\r
                 dialog.setFilterNames(new String[]{filter.getDescription()});\r
                 String selectedFile = dialog.open();\r
@@ -190,41 +168,78 @@ public class ExportSingleReadAlignmentWizardPage extends WizardPage {
                 }\r
             }\r
         });\r
-        fd_text.right = new FormAttachment(100, -134);\r
         FormData fd_btnBrowse = new FormData();\r
-        fd_btnBrowse.left = new FormAttachment(fileTextField, 6);\r
-        fd_btnBrowse.top = new FormAttachment(lblAlignmentFile, -5, SWT.TOP);\r
+        fd_btnBrowse.bottom = new FormAttachment(100, -10);\r
         fd_btnBrowse.right = new FormAttachment(100, -10);\r
         btnBrowse.setLayoutData(fd_btnBrowse);\r
         btnBrowse.setText("Browse...");\r
 \r
         formatComboBox = new Combo(container, SWT.READ_ONLY);\r
-        for (JPhyloIOFormatInfo formatInfo : FORMATS) {\r
+        for (JPhyloIOFormatInfo formatInfo : ExportSingleReadAlignmentWizardModel.FORMAT_NAMES_TO_INFO_MAP.values()) {\r
             formatComboBox.add(formatInfo.getFormatName());\r
         }\r
-        //TODO Bind property and somehow handle translation. (Or use model view combo box from JFace.)\r
-\r
         FormData fd_formatComboBox = new FormData();\r
-        fd_formatComboBox.right = new FormAttachment(consensusSequenceNameTextField, 0, SWT.RIGHT);\r
+        fd_formatComboBox.right = new FormAttachment(consensusSequenceLabelTextField, 0, SWT.RIGHT);\r
         fd_formatComboBox.top = new FormAttachment(lblFormat, 6);\r
         fd_formatComboBox.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT);\r
         formatComboBox.setLayoutData(fd_formatComboBox);\r
         formatComboBox.select(0);\r
+        final ISWTObservableValue formatObservable = SWTObservables.observeSelection(formatComboBox);  // ViewerProperties.singleSelection().observe(formatComboBox); falls ein ComboViewer verwendet wird. (Dann kann direkt FormatInfo verwendet werden.)\r
+\r
+        Button appendExtensionButton = new Button(container, SWT.NONE);\r
+        appendExtensionButton.addSelectionListener(new SelectionAdapter() {\r
+            @Override\r
+            public void widgetSelected(SelectionEvent e) {\r
+                fileTextField.setText(fileTextField.getText() + ExtensionFileFilter.EXTENSION_SEPARATOR +\r
+                        ExportSingleReadAlignmentWizardModel.FORMAT_NAMES_TO_INFO_MAP.get(\r
+                                formatComboBox.getText()).createFileFilter(TestStrategy.EXTENSION).getDefaultExtension());\r
+            }\r
+        });\r
+        fd_btnBrowse.left = new FormAttachment(0, 446);\r
+        FormData fd_btnNewButton = new FormData();\r
+        fd_btnNewButton.left = new FormAttachment(btnBrowse, -217, SWT.LEFT);\r
+        fd_btnNewButton.bottom = new FormAttachment(100, -10);\r
+        fd_btnNewButton.right = new FormAttachment(btnBrowse, -6);\r
+        appendExtensionButton.setLayoutData(fd_btnNewButton);\r
+        appendExtensionButton.setText("Append default extension");  //TODO multi language\r
+        dbc.bindValue(formatObservable, getWizard().getModel().getFormatInfoObservable());\r
+\r
+        dbc.addValidationStatusProvider(new MultiValidator() {\r
+            @Override\r
+            protected IStatus validate() {\r
+                String label = (String)consensusSequenceLabelObservable.getValue();\r
+                boolean exportConsensus = (Boolean)exportConsensusSequenceObservable.getValue();\r
+                boolean exportReads = (Boolean)exportSingleReadsObservable.getValue();\r
+\r
+                if (!exportConsensus && !exportReads) {\r
+                    return ValidationStatus.error("Either single reads or the consensus sequence have to be selected for export.");  //TODO multi language\r
+                }\r
+                else if (exportConsensus && ((label == null) || label.isEmpty())) {\r
+                    return ValidationStatus.error("The consensus sequence label must not be empty.");  //TODO multi language\r
+                }\r
+\r
+                String fileName = (String)fileNameObservable.getValue();\r
+                if ((fileName == null) || fileName.isEmpty()) {\r
+                    return ValidationStatus.error("The file name must not be empty.");  //TODO multi language\r
+                }\r
+                else if (!ExportSingleReadAlignmentWizardModel.FORMAT_NAMES_TO_INFO_MAP.get(\r
+                        formatObservable.getValue()).createFileFilter(TestStrategy.EXTENSION).accept(new File(fileName))) {\r
+\r
+                    return ValidationStatus.warning("The file name does have a valid extension for the selected format.");  //TODO multi language\r
+                }\r
+                else {\r
+                    return ValidationStatus.ok();\r
+                }\r
+            }\r
+        });\r
     }\r
 \r
 \r
     /**\r
-     * Returns the <i>JPhyloIO</i> format info object to be used for exporting.\r
-     *\r
-     * @return the format info or {@code null}, if none was yet selected\r
+     * {@inheritDoc}\r
      */\r
-    private JPhyloIOFormatInfo getSelectedFormat() {\r
-        if (formatComboBox != null) {\r
-            int index = formatComboBox.getSelectionIndex();\r
-            if (index > -1) {\r
-                return FORMATS.get(index);\r
-            }\r
-        }\r
-        return null;\r
+    @Override\r
+    public ExportSingleReadAlignmentWizard getWizard() {\r
+        return (ExportSingleReadAlignmentWizard)super.getWizard();  // Would throw an exception, if this page is used within another wizard.\r
     }\r
 }\r
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 (file)
index a9475c3..0000000
+++ /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.)
-    }
-}