Revision bcb823d5
Added by Ben Stöver over 7 years ago
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/handler/ExportSequenceToFileHandler.java | ||
---|---|---|
15 | 15 |
import info.bioinfweb.jphyloio.ReadWriteParameterNames; |
16 | 16 |
import info.bioinfweb.jphyloio.dataadapters.implementations.ListBasedDocumentDataAdapter; |
17 | 17 |
import info.bioinfweb.jphyloio.factory.JPhyloIOReaderWriterFactory; |
18 |
import info.bioinfweb.jphyloio.formats.JPhyloIOFormatIDs; |
|
19 | 18 |
import info.bioinfweb.jphyloio.objecttranslation.ObjectTranslatorFactory; |
20 | 19 |
|
21 |
import java.io.File; |
|
22 | 20 |
import java.io.IOException; |
23 | 21 |
|
24 | 22 |
import org.eclipse.core.commands.AbstractHandler; |
25 | 23 |
import org.eclipse.core.commands.ExecutionEvent; |
26 | 24 |
import org.eclipse.core.commands.ExecutionException; |
25 |
import org.eclipse.core.runtime.IStatus; |
|
27 | 26 |
import org.eclipse.jface.viewers.ISelection; |
28 | 27 |
import org.eclipse.jface.viewers.TreeNode; |
28 |
import org.eclipse.jface.wizard.WizardDialog; |
|
29 | 29 |
import org.eclipse.ui.handlers.HandlerUtil; |
30 | 30 |
|
31 | 31 |
import eu.etaxonomy.cdm.model.molecular.Sequence; |
... | ... | |
35 | 35 |
import eu.etaxonomy.taxeditor.molecular.io.CDMPherogramAlignmentObjectTranslator; |
36 | 36 |
import eu.etaxonomy.taxeditor.molecular.io.CDMSequenceMatrixAdapter; |
37 | 37 |
import eu.etaxonomy.taxeditor.molecular.io.SingleReadAlignmentRDFXMLConstants; |
38 |
import eu.etaxonomy.taxeditor.molecular.io.wizard.ExportSingleReadAlignmentWizard; |
|
38 | 39 |
|
39 | 40 |
|
40 | 41 |
|
... | ... | |
56 | 57 |
if (treeNodeOfSelection != null && treeNodeOfSelection.getValue() instanceof Sequence) { |
57 | 58 |
Sequence sequence = (Sequence)treeNodeOfSelection.getValue(); |
58 | 59 |
|
59 |
//TODO Collect the following information using a wizard. |
|
60 |
File targetFile = new File("O:\\Projects\\Bereich BBI\\EDIT Campanula\\Testdaten\\NeXMLExport.xml"); |
|
61 |
String formatID = JPhyloIOFormatIDs.NEXML_FORMAT_ID; |
|
60 |
final ExportSingleReadAlignmentWizard wizard = new ExportSingleReadAlignmentWizard(); |
|
61 |
final WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), wizard); |
|
62 |
if (dialog.open() == IStatus.OK) { //TODO Is the window disposed? |
|
63 |
// Prepare writer parameters: |
|
64 |
ReadWriteParameterMap parameters = new ReadWriteParameterMap(); |
|
65 |
ObjectTranslatorFactory translatorFactory = new ObjectTranslatorFactory(); |
|
66 |
translatorFactory.addXSDTranslators(true); |
|
67 |
translatorFactory.addTranslator(new CDMPherogramAlignmentObjectTranslator(), true, SingleReadAlignmentRDFXMLConstants.DATA_TYPE_PHERORAGM_ALIGNMENT); |
|
68 |
parameters.put(ReadWriteParameterNames.KEY_OBJECT_TRANSLATOR_FACTORY, translatorFactory); |
|
62 | 69 |
|
63 |
ReadWriteParameterMap parameters = new ReadWriteParameterMap(); |
|
64 |
ObjectTranslatorFactory translatorFactory = new ObjectTranslatorFactory(); |
|
65 |
translatorFactory.addXSDTranslators(true); |
|
66 |
translatorFactory.addTranslator(new CDMPherogramAlignmentObjectTranslator(), true, SingleReadAlignmentRDFXMLConstants.DATA_TYPE_PHERORAGM_ALIGNMENT); |
|
67 |
parameters.put(ReadWriteParameterNames.KEY_OBJECT_TRANSLATOR_FACTORY, translatorFactory); |
|
70 |
// Create writer and document adapters: |
|
71 |
JPhyloIOEventWriter writer = factory.getWriter(wizard.getSelectedFormat()); |
|
72 |
ListBasedDocumentDataAdapter document = new ListBasedDocumentDataAdapter(); |
|
73 |
document.getMatrices().add(new CDMSequenceMatrixAdapter(sequence, wizard.getConsensusSequenceLabel())); |
|
68 | 74 |
|
69 |
String consensusSequenceLabel = "Consensus sequence"; |
|
70 |
JPhyloIOEventWriter writer = factory.getWriter(formatID); |
|
71 |
|
|
72 |
ListBasedDocumentDataAdapter document = new ListBasedDocumentDataAdapter(); |
|
73 |
document.getMatrices().add(new CDMSequenceMatrixAdapter(sequence, consensusSequenceLabel)); |
|
74 |
|
|
75 |
try { |
|
76 |
writer.writeDocument(document, targetFile, parameters); |
|
77 |
} |
|
78 |
catch (IOException e) { |
|
79 |
e.printStackTrace(); |
|
80 |
MessagingUtils.errorDialog("IO error", this, |
|
81 |
"An error occured when trying to export a consensus sequence alignment to the file \"" + |
|
82 |
targetFile.getAbsolutePath() + "\".", TaxeditorMolecularPlugin.PLUGIN_ID, e, false); //TODO set pluginID |
|
83 |
//TODO Use multi language error message. |
|
75 |
// Write document: |
|
76 |
try { |
|
77 |
writer.writeDocument(document, wizard.getSelectedFile(), parameters); |
|
78 |
} |
|
79 |
catch (IOException e) { |
|
80 |
e.printStackTrace(); |
|
81 |
MessagingUtils.errorDialog("IO error", this, |
|
82 |
"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 |
|
84 |
//TODO Use multi language error message. |
|
85 |
} |
|
84 | 86 |
} |
85 | 87 |
} |
86 | 88 |
return null; |
Also available in: Unified diff
Missing dependency Apache commons.lang added to molecular.lib.
Single read alignment export feature now makes use of wizard. (Selecting which sequences to export is not yet supported.)