Plug-in dependencies added to molecular.
eu.etaxonomy.taxeditor.cdmlib,
eu.etaxonomy.taxeditor.editor,
eu.etaxonomy.taxeditor.store,
- eu.etaxonomy.taxeditor.molecular.lib
+ eu.etaxonomy.taxeditor.molecular.lib,
+ org.eclipse.core.databinding.observable;bundle-version="1.4.0",
+ org.eclipse.core.databinding;bundle-version="1.4.0",
+ org.eclipse.jface.databinding;bundle-version="1.5.0",
+ org.eclipse.core.databinding.property;bundle-version="1.4.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Bundle-Vendor: EDIT
import info.bioinfweb.jphyloio.factory.JPhyloIOReaderWriterFactory;\r
import info.bioinfweb.jphyloio.objecttranslation.ObjectTranslatorFactory;\r
\r
+import java.io.File;\r
import java.io.IOException;\r
\r
import org.eclipse.core.commands.AbstractHandler;\r
parameters.put(ReadWriteParameterNames.KEY_OBJECT_TRANSLATOR_FACTORY, translatorFactory);\r
\r
// Create writer and document adapters:\r
- JPhyloIOEventWriter writer = factory.getWriter(wizard.getSelectedFormat().getFormatID());\r
+ JPhyloIOEventWriter writer = factory.getWriter(wizard.getModel().getFormatInfo().getFormatID());\r
ListBasedDocumentDataAdapter document = new ListBasedDocumentDataAdapter();\r
- document.getMatrices().add(new CDMSequenceMatrixAdapter(sequence, wizard.getConsensusSequenceLabel()));\r
+ document.getMatrices().add(new CDMSequenceMatrixAdapter(sequence, wizard.getModel().getConsensusSequenceLabel()));\r
\r
// Write document:\r
+ File file = new File(wizard.getModel().getFileName());\r
try {\r
- writer.writeDocument(document, wizard.getSelectedFile(), parameters);\r
+ writer.writeDocument(document, file, parameters);\r
}\r
catch (IOException e) {\r
e.printStackTrace();\r
MessagingUtils.errorDialog("IO error", this,\r
"An error occured when trying to export a consensus sequence alignment to the file \"" +\r
- wizard.getSelectedFile().getAbsolutePath() + "\".", TaxeditorMolecularPlugin.PLUGIN_ID, e, false); //TODO set pluginID\r
+ file.getAbsolutePath() + "\".", TaxeditorMolecularPlugin.PLUGIN_ID, e, false); //TODO set pluginID\r
//TODO Use multi language error message.\r
}\r
}\r
--- /dev/null
+/**
+* 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);
+ }
+}
--- /dev/null
+/**
+* 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;
+ }
+}
package eu.etaxonomy.taxeditor.molecular.io.wizard;\r
\r
\r
-import info.bioinfweb.jphyloio.formatinfo.JPhyloIOFormatInfo;\r
-\r
-import java.io.File;\r
-\r
import org.eclipse.jface.wizard.Wizard;\r
\r
\r
* @date 23.06.2016\r
*/\r
public class ExportSingleReadAlignmentWizard extends Wizard {\r
- private ExportSingleReadAlignmentWizardPage page;\r
+ private ExportSingleReadAlignmentWizardModel model = new ExportSingleReadAlignmentWizardModel();\r
\r
- private JPhyloIOFormatInfo selectedFormat = null;\r
- private File selectedFile = null;\r
- private String consensusSequenceLabel = null;\r
+ private ExportSingleReadAlignmentWizardPage page;\r
\r
\r
public ExportSingleReadAlignmentWizard() {\r
- setWindowTitle("Export single read alignment"); //TODO Use multi languange message\r
+ setWindowTitle("Export single read alignment"); //TODO Use multi language message\r
+ }\r
+\r
+\r
+ public ExportSingleReadAlignmentWizardModel getModel() {\r
+ return model;\r
}\r
\r
\r
\r
@Override\r
public boolean performFinish() {\r
- if (!page.getConsensusSequenceLabel().isEmpty()) {\r
- selectedFormat = page.getSelectedFormat();\r
- selectedFile = page.getSelectedFile();\r
- consensusSequenceLabel = page.getConsensusSequenceLabel();\r
- return true;\r
- }\r
- else {\r
- return false; //TODO Display according error message in wizard heading, as long as valid inputs are not completed.\r
- }\r
- }\r
-\r
-\r
- public JPhyloIOFormatInfo getSelectedFormat() {\r
- return selectedFormat;\r
- }\r
-\r
-\r
- public File getSelectedFile() {\r
- return selectedFile;\r
- }\r
-\r
-\r
- public String getConsensusSequenceLabel() {\r
- return consensusSequenceLabel;\r
+ return true;\r
+ //TODO Add default extension to file, if necessary?\r
}\r
}\r
--- /dev/null
+/**
+* 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 info.bioinfweb.jphyloio.formatinfo.JPhyloIOFormatInfo;
+
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.observable.value.WritableValue;
+
+
+
+/**
+ * The data model for a wizard to export single read alignments to different file formats using <i>JPhyloIO</i>.
+ *
+ * @author Ben Stöver
+ * @date 16.11.2016
+ */
+public class ExportSingleReadAlignmentWizardModel {
+ 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 fileName = new WritableValue(null, String.class);
+
+
+ public boolean isExportSingleReads() {
+ return (Boolean)exportSingleReads.getValue();
+ }
+
+
+ protected IObservableValue getExportSingleReadsObservable() {
+ return exportSingleReads;
+ }
+
+
+ public boolean isExportConsensusSequence() {
+ return (Boolean)exportConsensusSequence.getValue();
+ }
+
+
+ protected IObservableValue getExportConsensusSequenceObservable() {
+ return exportConsensusSequence;
+ }
+
+
+ public String getConsensusSequenceLabel() {
+ return (String)consensusSequenceLabel.getValue();
+ }
+
+
+ protected IObservableValue getConsensusSequenceLabelObservable() {
+ return consensusSequenceLabel;
+ }
+
+
+ public JPhyloIOFormatInfo getFormatInfo() {
+ return (JPhyloIOFormatInfo)formatInfo.getValue();
+ }
+
+
+ protected IObservableValue getFormatInfoObservable() {
+ return formatInfo;
+ }
+
+
+ public String getFileName() {
+ return (String)fileName.getValue();
+ }
+
+
+ protected IObservableValue getFileNameObservable() {
+ return fileName;
+ }
+}
import info.bioinfweb.jphyloio.factory.JPhyloIOReaderWriterFactory;\r
import info.bioinfweb.jphyloio.formatinfo.JPhyloIOFormatInfo;\r
\r
-import java.io.File;\r
import java.util.ArrayList;\r
import java.util.Collections;\r
import java.util.List;\r
\r
+import org.eclipse.core.databinding.DataBindingContext;\r
+import org.eclipse.core.databinding.UpdateValueStrategy;\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
import org.eclipse.jface.wizard.WizardPage;\r
import org.eclipse.swt.SWT;\r
import org.eclipse.swt.events.SelectionAdapter;\r
*/\r
@Override\r
public void createControl(Composite parent) {\r
+ DataBindingContext dbc = new DataBindingContext();\r
+ WizardPageSupport.create(this, dbc);\r
+\r
Composite container = new Composite(parent, SWT.NULL);\r
\r
setControl(container);\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
\r
exportConsensusSequenceCB = new Button(container, SWT.CHECK);\r
exportConsensusSequenceCB.setSelection(true);\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
+\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
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
\r
Label lblFormat = new Label(container, SWT.NONE);\r
FormData fd_lblFormat = new FormData();\r
fd_text.left = new FormAttachment(lblAlignmentFile, 6);\r
fd_text.top = new FormAttachment(lblSelectTheExport, 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
\r
Button btnBrowse = new Button(container, SWT.NONE);\r
btnBrowse.addSelectionListener(new SelectionAdapter() {\r
public void widgetSelected(SelectionEvent e) {\r
FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);\r
dialog.setText("Export to"); //TODO Make multi language\r
- //fd.setFilterPath("C:/");\r
ContentExtensionFileFilter filter = getSelectedFormat().createFileFilter();\r
dialog.setFilterExtensions(new String[]{filter.getExtensionsAsString()});\r
dialog.setFilterNames(new String[]{filter.getDescription()});\r
if (selectedFile != null) { // Otherwise selecting was canceled.\r
fileTextField.setText(selectedFile);\r
}\r
- //TODO Add default extension, if necessary.\r
}\r
});\r
fd_text.right = new FormAttachment(100, -134);\r
for (JPhyloIOFormatInfo formatInfo : FORMATS) {\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
*\r
* @return the format info or {@code null}, if none was yet selected\r
*/\r
- public JPhyloIOFormatInfo getSelectedFormat() {\r
+ private JPhyloIOFormatInfo getSelectedFormat() {\r
if (formatComboBox != null) {\r
int index = formatComboBox.getSelectionIndex();\r
if (index > -1) {\r
}\r
return null;\r
}\r
-\r
-\r
- public File getSelectedFile() {\r
- if (fileTextField != null) {\r
- return new File(fileTextField.getText());\r
- }\r
- else {\r
- return null;\r
- }\r
- }\r
-\r
-\r
- public String getConsensusSequenceLabel() {\r
- if (consensusSequenceNameTextField != null) {\r
- return consensusSequenceNameTextField.getText();\r
- }\r
- else {\r
- return null;\r
- }\r
- }\r
}\r
--- /dev/null
+/**
+* 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.)
+ }
+}