\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
* @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
*/\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
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
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
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
}\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