Revision 00d1a6ce
Added by Ben Stöver over 7 years ago
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/handler/ExportSequenceToFileHandler.java | ||
---|---|---|
10 | 10 |
package eu.etaxonomy.taxeditor.molecular.handler; |
11 | 11 |
|
12 | 12 |
|
13 |
import info.bioinfweb.commons.bio.SequenceUtils; |
|
14 | 13 |
import info.bioinfweb.jphyloio.JPhyloIOEventWriter; |
15 | 14 |
import info.bioinfweb.jphyloio.ReadWriteParameterMap; |
16 | 15 |
import info.bioinfweb.jphyloio.ReadWriteParameterNames; |
... | ... | |
39 | 38 |
import eu.etaxonomy.taxeditor.molecular.io.CDMSequenceMatrixAdapter; |
40 | 39 |
import eu.etaxonomy.taxeditor.molecular.io.SingleReadAlignmentRDFXMLConstants; |
41 | 40 |
import eu.etaxonomy.taxeditor.molecular.io.wizard.ExportSingleReadAlignmentWizard; |
41 |
import eu.etaxonomy.taxeditor.util.ApplicationUtil; |
|
42 | 42 |
|
43 | 43 |
|
44 | 44 |
|
45 | 45 |
/** |
46 | 46 |
* Allows to export a single read alignment to various alignment formats using |
47 |
* <a href="http://bioinfweb.info/JPhyloIO/">JPhyloIO</a>. |
|
47 |
* <a href="http://bioinfweb.info/JPhyloIO/"><i>JPhyloIO</i> |
|
48 |
* </a>. |
|
48 | 49 |
* |
49 | 50 |
* @author Ben Stöver |
50 | 51 |
* @date 24.04.2016 |
... | ... | |
65 | 66 |
if (dialog.open() == IStatus.OK) { |
66 | 67 |
// Prepare writer parameters: |
67 | 68 |
ReadWriteParameterMap parameters = new ReadWriteParameterMap(); |
68 |
parameters.put(ReadWriteParameterNames.KEY_SEQUENCE_EXTENSION_TOKEN, Character.toString(SequenceUtils.GAP_CHAR)); |
|
69 |
parameters.put(ReadWriteParameterNames.KEY_APPLICATION_NAME, ApplicationUtil.getTitle()); |
|
70 |
parameters.put(ReadWriteParameterNames.KEY_APPLICATION_VERSION, ApplicationUtil.getVersion()); |
|
71 |
parameters.put(ReadWriteParameterNames.KEY_APPLICATION_URL, "http://cybertaxonomy.eu/taxeditor/"); //TODO Specify URL obtained from a central class? |
|
72 |
parameters.put(ReadWriteParameterNames.KEY_SEQUENCE_EXTENSION_TOKEN, wizard.getModel().getElongationToken()); |
|
69 | 73 |
|
70 | 74 |
// Create and register object translator for writing pherogram alignment shifts: |
71 | 75 |
ObjectTranslatorFactory translatorFactory = new ObjectTranslatorFactory(); |
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentFileFormatPage.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2016 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
package eu.etaxonomy.taxeditor.molecular.io.wizard; |
|
11 |
|
|
12 |
|
|
13 |
import info.bioinfweb.commons.io.ContentExtensionFileFilter; |
|
14 |
import info.bioinfweb.commons.io.ContentExtensionFileFilter.TestStrategy; |
|
15 |
import info.bioinfweb.commons.io.ExtensionFileFilter; |
|
16 |
import info.bioinfweb.jphyloio.formatinfo.JPhyloIOFormatInfo; |
|
17 |
|
|
18 |
import java.io.File; |
|
19 |
|
|
20 |
import org.eclipse.core.databinding.DataBindingContext; |
|
21 |
import org.eclipse.core.databinding.validation.MultiValidator; |
|
22 |
import org.eclipse.core.databinding.validation.ValidationStatus; |
|
23 |
import org.eclipse.core.runtime.IStatus; |
|
24 |
import org.eclipse.jface.databinding.swt.ISWTObservableValue; |
|
25 |
import org.eclipse.jface.databinding.swt.SWTObservables; |
|
26 |
import org.eclipse.jface.databinding.wizard.WizardPageSupport; |
|
27 |
import org.eclipse.swt.SWT; |
|
28 |
import org.eclipse.swt.events.SelectionAdapter; |
|
29 |
import org.eclipse.swt.events.SelectionEvent; |
|
30 |
import org.eclipse.swt.layout.FormAttachment; |
|
31 |
import org.eclipse.swt.layout.FormData; |
|
32 |
import org.eclipse.swt.layout.FormLayout; |
|
33 |
import org.eclipse.swt.widgets.Button; |
|
34 |
import org.eclipse.swt.widgets.Combo; |
|
35 |
import org.eclipse.swt.widgets.Composite; |
|
36 |
import org.eclipse.swt.widgets.FileDialog; |
|
37 |
import org.eclipse.swt.widgets.Label; |
|
38 |
import org.eclipse.swt.widgets.Text; |
|
39 |
|
|
40 |
import eu.etaxonomy.taxeditor.molecular.Messages; |
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
/** |
|
45 |
* Wizard page that allows to specify which parts of a single read alignment shall be exported to an alignment file. |
|
46 |
* |
|
47 |
* @author Ben Stöver |
|
48 |
* @date 18.04.2016 |
|
49 |
*/ |
|
50 |
public class ExportSingleReadAlignmentFileFormatPage extends AbstractExportSingleReadAlignmentWizardPage { |
|
51 |
private Text fileTextField; |
|
52 |
private Combo formatComboBox; |
|
53 |
|
|
54 |
|
|
55 |
/** |
|
56 |
* Create the wizard. |
|
57 |
*/ |
|
58 |
public ExportSingleReadAlignmentFileFormatPage() { |
|
59 |
super("ExportSingleReadAlignmentFileFormat"); //TODO Which pageName should be used here? Any conventions? //$NON-NLS-1$ |
|
60 |
setTitle(Messages.wizardExportAlignmentTitle); |
|
61 |
setDescription(Messages.wizardExportAlignmentDescription); |
|
62 |
} |
|
63 |
|
|
64 |
|
|
65 |
/** |
|
66 |
* Create contents of the wizard. |
|
67 |
* |
|
68 |
* @param parent the parent component |
|
69 |
*/ |
|
70 |
@Override |
|
71 |
public void createControl(Composite parent) { |
|
72 |
DataBindingContext dbc = new DataBindingContext(); |
|
73 |
WizardPageSupport.create(this, dbc); |
|
74 |
|
|
75 |
Composite container = new Composite(parent, SWT.NULL); |
|
76 |
|
|
77 |
setControl(container); |
|
78 |
container.setLayout(new FormLayout()); |
|
79 |
|
|
80 |
Label lblFormat = new Label(container, SWT.NONE); |
|
81 |
FormData fd_lblFormat = new FormData(); |
|
82 |
fd_lblFormat.right = new FormAttachment(100, -10); |
|
83 |
fd_lblFormat.top = new FormAttachment(0, 10); |
|
84 |
fd_lblFormat.left = new FormAttachment(0, 10); |
|
85 |
lblFormat.setLayoutData(fd_lblFormat); |
|
86 |
lblFormat.setText(Messages.wizardExportAlignmentExportFormatLabel); |
|
87 |
|
|
88 |
Label lblSelectTheExport = new Label(container, SWT.NONE); |
|
89 |
FormData fd_lblSelectTheExport = new FormData(); |
|
90 |
fd_lblSelectTheExport.right = new FormAttachment(100, -10); |
|
91 |
fd_lblSelectTheExport.left = new FormAttachment(0, 10); |
|
92 |
lblSelectTheExport.setLayoutData(fd_lblSelectTheExport); |
|
93 |
lblSelectTheExport.setText(Messages.wizardExportAlignmentDestinationLabel); |
|
94 |
|
|
95 |
Label lblAlignmentFile = new Label(container, SWT.NONE); |
|
96 |
FormData fd_lblAlignmentFile = new FormData(); |
|
97 |
fd_lblAlignmentFile.top = new FormAttachment(lblSelectTheExport, 9); |
|
98 |
fd_lblAlignmentFile.right = new FormAttachment(0, 128); |
|
99 |
fd_lblAlignmentFile.left = new FormAttachment(0, 10); |
|
100 |
lblAlignmentFile.setLayoutData(fd_lblAlignmentFile); |
|
101 |
lblAlignmentFile.setText(Messages.wizardExportAlignmentFileLabel); |
|
102 |
|
|
103 |
fileTextField = new Text(container, SWT.BORDER); |
|
104 |
FormData fd_text = new FormData(); |
|
105 |
fd_text.left = new FormAttachment(lblAlignmentFile, 6); |
|
106 |
fd_text.right = new FormAttachment(100, -10); |
|
107 |
fd_text.top = new FormAttachment(lblSelectTheExport, 6); |
|
108 |
fileTextField.setLayoutData(fd_text); |
|
109 |
final ISWTObservableValue fileNameObservable = SWTObservables.observeText(fileTextField, SWT.Modify); |
|
110 |
dbc.bindValue(fileNameObservable, getWizard().getModel().getFileNameObservable()); |
|
111 |
|
|
112 |
Button btnBrowse = new Button(container, SWT.NONE); |
|
113 |
btnBrowse.addSelectionListener(new SelectionAdapter() { |
|
114 |
@Override |
|
115 |
public void widgetSelected(SelectionEvent e) { |
|
116 |
FileDialog dialog = new FileDialog(getShell(), SWT.OPEN); |
|
117 |
dialog.setText(Messages.wizardExportAlignmentFileDialogTitle); |
|
118 |
ContentExtensionFileFilter filter = getSelectedFormat().createFileFilter(TestStrategy.EXTENSION); |
|
119 |
dialog.setFilterExtensions(new String[]{filter.getExtensionsAsString()}); |
|
120 |
dialog.setFilterNames(new String[]{filter.getDescription()}); |
|
121 |
String selectedFile = dialog.open(); |
|
122 |
if (selectedFile != null) { // Otherwise selecting was canceled. |
|
123 |
fileTextField.setText(selectedFile); |
|
124 |
} |
|
125 |
} |
|
126 |
}); |
|
127 |
FormData fd_btnBrowse = new FormData(); |
|
128 |
fd_btnBrowse.bottom = new FormAttachment(100, -150); |
|
129 |
fd_btnBrowse.top = new FormAttachment(fileTextField, 13); |
|
130 |
fd_btnBrowse.left = new FormAttachment(100, -128); |
|
131 |
fd_btnBrowse.right = new FormAttachment(100, -10); |
|
132 |
btnBrowse.setLayoutData(fd_btnBrowse); |
|
133 |
btnBrowse.setText(Messages.wizardExportAlignmentBrowseButton); |
|
134 |
|
|
135 |
formatComboBox = new Combo(container, SWT.READ_ONLY); |
|
136 |
fd_lblSelectTheExport.top = new FormAttachment(formatComboBox, 23); |
|
137 |
for (JPhyloIOFormatInfo formatInfo : ExportSingleReadAlignmentWizardModel.FORMAT_NAMES_TO_INFO_MAP.values()) { |
|
138 |
formatComboBox.add(formatInfo.getFormatName()); |
|
139 |
} |
|
140 |
FormData fd_formatComboBox = new FormData(); |
|
141 |
fd_formatComboBox.top = new FormAttachment(lblFormat, 6); |
|
142 |
fd_formatComboBox.left = new FormAttachment(0, 10); |
|
143 |
fd_formatComboBox.right = new FormAttachment(100, -10); |
|
144 |
formatComboBox.setLayoutData(fd_formatComboBox); |
|
145 |
final ISWTObservableValue formatObservable = SWTObservables.observeSelection(formatComboBox); // ViewerProperties.singleSelection().observe(formatComboBox); falls ein ComboViewer verwendet wird. (Dann kann direkt FormatInfo verwendet werden.) |
|
146 |
dbc.bindValue(formatObservable, getWizard().getModel().getFormatInfoObservable()); |
|
147 |
formatComboBox.select(0); // Must happen after the component has been bound to the model. |
|
148 |
|
|
149 |
Button appendExtensionButton = new Button(container, SWT.NONE); |
|
150 |
appendExtensionButton.addSelectionListener(new SelectionAdapter() { |
|
151 |
@Override |
|
152 |
public void widgetSelected(SelectionEvent e) { |
|
153 |
fileTextField.setText(fileTextField.getText() + ExtensionFileFilter.EXTENSION_SEPARATOR + |
|
154 |
getSelectedFormat().createFileFilter(TestStrategy.EXTENSION).getDefaultExtension()); |
|
155 |
} |
|
156 |
}); |
|
157 |
FormData fd_btnNewButton = new FormData(); |
|
158 |
fd_btnNewButton.bottom = new FormAttachment(100, -150); |
|
159 |
fd_btnNewButton.top = new FormAttachment(fileTextField, 13); |
|
160 |
fd_btnNewButton.left = new FormAttachment(btnBrowse, -276, SWT.LEFT); |
|
161 |
fd_btnNewButton.right = new FormAttachment(btnBrowse, -6); |
|
162 |
appendExtensionButton.setLayoutData(fd_btnNewButton); |
|
163 |
appendExtensionButton.setText(Messages.wizardExportAlignmentAppendExtensionButton); |
|
164 |
|
|
165 |
dbc.addValidationStatusProvider(new MultiValidator() { |
|
166 |
@Override |
|
167 |
protected IStatus validate() { |
|
168 |
String fileName = (String)fileNameObservable.getValue(); |
|
169 |
if ((fileName == null) || fileName.isEmpty()) { |
|
170 |
return ValidationStatus.error(Messages.wizardExportAlignmentErrorMissingFileName); |
|
171 |
} |
|
172 |
else if (!getSelectedFormat().createFileFilter(TestStrategy.EXTENSION).accept(new File(fileName))) { |
|
173 |
return ValidationStatus.warning(Messages.wizardExportAlignmentwarningMissingExtension); |
|
174 |
} |
|
175 |
else if (fileName.charAt(0) == ExtensionFileFilter.EXTENSION_SEPARATOR) { |
|
176 |
return ValidationStatus.warning(Messages.wizardExportAlignmentWarningFileNameStartsDot); |
|
177 |
} |
|
178 |
else { |
|
179 |
return ValidationStatus.ok(); |
|
180 |
} |
|
181 |
} |
|
182 |
}); |
|
183 |
} |
|
184 |
|
|
185 |
|
|
186 |
private JPhyloIOFormatInfo getSelectedFormat() { |
|
187 |
return ExportSingleReadAlignmentWizardModel.FORMAT_NAMES_TO_INFO_MAP.get(formatComboBox.getText()); |
|
188 |
} |
|
189 |
} |
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentWizard.java | ||
---|---|---|
23 | 23 |
public class ExportSingleReadAlignmentWizard extends Wizard { |
24 | 24 |
private ExportSingleReadAlignmentWizardModel model = new ExportSingleReadAlignmentWizardModel(); |
25 | 25 |
|
26 |
private ExportSingleReadAlignmentWizardPage page; |
|
26 |
private ExportSingleReadAlignmentFileFormatPage fileFormatPage; |
|
27 |
private ExportSingleReadAlignmentOptionsPage optionsPage; |
|
27 | 28 |
|
28 | 29 |
|
29 | 30 |
public ExportSingleReadAlignmentWizard() { |
... | ... | |
38 | 39 |
|
39 | 40 |
@Override |
40 | 41 |
public void addPages() { |
41 |
page = new ExportSingleReadAlignmentWizardPage(); |
|
42 |
addPage(page); |
|
42 |
fileFormatPage = new ExportSingleReadAlignmentFileFormatPage(); |
|
43 |
optionsPage = new ExportSingleReadAlignmentOptionsPage(); |
|
44 |
|
|
45 |
addPage(fileFormatPage); |
|
46 |
addPage(optionsPage); |
|
43 | 47 |
} |
44 | 48 |
|
45 | 49 |
|
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentWizardModel.java | ||
---|---|---|
9 | 9 |
package eu.etaxonomy.taxeditor.molecular.io.wizard; |
10 | 10 |
|
11 | 11 |
|
12 |
import info.bioinfweb.commons.bio.SequenceUtils; |
|
12 | 13 |
import info.bioinfweb.jphyloio.events.type.EventContentType; |
13 | 14 |
import info.bioinfweb.jphyloio.factory.JPhyloIOReaderWriterFactory; |
14 | 15 |
import info.bioinfweb.jphyloio.formatinfo.JPhyloIOFormatInfo; |
... | ... | |
33 | 34 |
protected static final Map<String, JPhyloIOFormatInfo> FORMAT_NAMES_TO_INFO_MAP = createFormatInfoList(); |
34 | 35 |
|
35 | 36 |
|
36 |
private IObservableValue exportSingleReads = new WritableValue(true, Boolean.class); |
|
37 |
private IObservableValue exportConsensusSequence = new WritableValue(true, Boolean.class); |
|
38 |
private IObservableValue consensusSequenceLabel = new WritableValue("ConsensusSequence", String.class); |
|
39 | 37 |
private IObservableValue formatInfo = new WritableValue(null, String.class); |
40 | 38 |
private IObservableValue fileName = new WritableValue(null, String.class); |
39 |
private IObservableValue exportSingleReads = new WritableValue(true, Boolean.class); |
|
40 |
private IObservableValue exportConsensusSequence = new WritableValue(true, Boolean.class); |
|
41 |
private IObservableValue consensusSequenceLabel = new WritableValue("Consensus", String.class); |
|
42 |
private IObservableValue elongateSequences = new WritableValue(false, Boolean.class); |
|
43 |
private IObservableValue useGapToken = new WritableValue(true, Boolean.class); |
|
41 | 44 |
|
42 | 45 |
|
43 | 46 |
private static Map<String, JPhyloIOFormatInfo> createFormatInfoList() { |
... | ... | |
52 | 55 |
} |
53 | 56 |
|
54 | 57 |
|
58 |
protected IObservableValue getFormatInfoObservable() { |
|
59 |
return formatInfo; |
|
60 |
} |
|
61 |
|
|
62 |
|
|
63 |
/** |
|
64 |
* Returns the <i>JPhyloIO</i> format info object to be used for exporting. |
|
65 |
* |
|
66 |
* @return the format info |
|
67 |
*/ |
|
68 |
public JPhyloIOFormatInfo getFormatInfo() { |
|
69 |
return FORMAT_NAMES_TO_INFO_MAP.get(formatInfo.getValue()); |
|
70 |
} |
|
71 |
|
|
72 |
|
|
73 |
public String getFileName() { |
|
74 |
return (String)fileName.getValue(); |
|
75 |
} |
|
76 |
|
|
77 |
|
|
78 |
protected IObservableValue getFileNameObservable() { |
|
79 |
return fileName; |
|
80 |
} |
|
81 |
|
|
82 |
|
|
55 | 83 |
public boolean isExportSingleReads() { |
56 | 84 |
return (Boolean)exportSingleReads.getValue(); |
57 | 85 |
} |
... | ... | |
82 | 110 |
} |
83 | 111 |
|
84 | 112 |
|
85 |
protected IObservableValue getFormatInfoObservable() { |
|
86 |
return formatInfo; |
|
113 |
public String getElongationToken() { |
|
114 |
if ((Boolean)elongateSequences.getValue()) { |
|
115 |
if ((Boolean)useGapToken.getValue()) { |
|
116 |
return Character.toString(SequenceUtils.GAP_CHAR); |
|
117 |
} |
|
118 |
else { |
|
119 |
return Character.toString(SequenceUtils.MISSING_DATA_CHAR); |
|
120 |
} |
|
121 |
} |
|
122 |
else { |
|
123 |
return null; |
|
124 |
} |
|
87 | 125 |
} |
88 | 126 |
|
89 | 127 |
|
90 |
/** |
|
91 |
* Returns the <i>JPhyloIO</i> format info object to be used for exporting. |
|
92 |
* |
|
93 |
* @return the format info |
|
94 |
*/ |
|
95 |
public JPhyloIOFormatInfo getFormatInfo() { |
|
96 |
return FORMAT_NAMES_TO_INFO_MAP.get(formatInfo.getValue()); |
|
128 |
protected IObservableValue getElongateSequencesObservable() { |
|
129 |
return elongateSequences; |
|
97 | 130 |
} |
98 | 131 |
|
99 | 132 |
|
100 |
public String getFileName() {
|
|
101 |
return (String)fileName.getValue();
|
|
133 |
protected IObservableValue getUseGapTokenObservable() {
|
|
134 |
return useGapToken;
|
|
102 | 135 |
} |
103 | 136 |
|
104 | 137 |
|
105 |
protected IObservableValue getFileNameObservable() { |
|
106 |
return fileName; |
|
107 |
} |
|
108 | 138 |
} |
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentWizardPage.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2016 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
package eu.etaxonomy.taxeditor.molecular.io.wizard; |
|
11 |
|
|
12 |
|
|
13 |
import info.bioinfweb.commons.io.ContentExtensionFileFilter; |
|
14 |
import info.bioinfweb.commons.io.ContentExtensionFileFilter.TestStrategy; |
|
15 |
import info.bioinfweb.commons.io.ExtensionFileFilter; |
|
16 |
import info.bioinfweb.jphyloio.formatinfo.JPhyloIOFormatInfo; |
|
17 |
|
|
18 |
import java.io.File; |
|
19 |
|
|
20 |
import org.eclipse.core.databinding.DataBindingContext; |
|
21 |
import org.eclipse.core.databinding.validation.MultiValidator; |
|
22 |
import org.eclipse.core.databinding.validation.ValidationStatus; |
|
23 |
import org.eclipse.core.runtime.IStatus; |
|
24 |
import org.eclipse.jface.databinding.swt.ISWTObservableValue; |
|
25 |
import org.eclipse.jface.databinding.swt.SWTObservables; |
|
26 |
import org.eclipse.jface.databinding.wizard.WizardPageSupport; |
|
27 |
import org.eclipse.jface.wizard.WizardPage; |
|
28 |
import org.eclipse.swt.SWT; |
|
29 |
import org.eclipse.swt.events.SelectionAdapter; |
|
30 |
import org.eclipse.swt.events.SelectionEvent; |
|
31 |
import org.eclipse.swt.layout.FormAttachment; |
|
32 |
import org.eclipse.swt.layout.FormData; |
|
33 |
import org.eclipse.swt.layout.FormLayout; |
|
34 |
import org.eclipse.swt.widgets.Button; |
|
35 |
import org.eclipse.swt.widgets.Combo; |
|
36 |
import org.eclipse.swt.widgets.Composite; |
|
37 |
import org.eclipse.swt.widgets.FileDialog; |
|
38 |
import org.eclipse.swt.widgets.Label; |
|
39 |
import org.eclipse.swt.widgets.Text; |
|
40 |
|
|
41 |
import eu.etaxonomy.taxeditor.molecular.Messages; |
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
/** |
|
46 |
* Wizard page that allows to specify which parts of a single read alignment shall be exported to an alignment file. |
|
47 |
* |
|
48 |
* @author Ben Stöver |
|
49 |
* @date 18.04.2016 |
|
50 |
*/ |
|
51 |
public class ExportSingleReadAlignmentWizardPage extends WizardPage { |
|
52 |
private Text consensusSequenceLabelTextField; |
|
53 |
private Button exportConsensusSequenceCB; |
|
54 |
private Button exportSingleReadsCB; |
|
55 |
private Text fileTextField; |
|
56 |
private Combo formatComboBox; |
|
57 |
|
|
58 |
|
|
59 |
/** |
|
60 |
* Create the wizard. |
|
61 |
*/ |
|
62 |
public ExportSingleReadAlignmentWizardPage() { |
|
63 |
super("SingleReadSequencesExport"); //TODO Which pageName should be used here? Any conventions? //$NON-NLS-1$ |
|
64 |
setTitle(Messages.wizardExportAlignmentTitle); |
|
65 |
setDescription(Messages.wizardExportAlignmentDescription); |
|
66 |
} |
|
67 |
|
|
68 |
|
|
69 |
/** |
|
70 |
* Create contents of the wizard. |
|
71 |
* |
|
72 |
* @param parent the parent component |
|
73 |
*/ |
|
74 |
@Override |
|
75 |
public void createControl(Composite parent) { |
|
76 |
DataBindingContext dbc = new DataBindingContext(); |
|
77 |
WizardPageSupport.create(this, dbc); |
|
78 |
|
|
79 |
Composite container = new Composite(parent, SWT.NULL); |
|
80 |
|
|
81 |
setControl(container); |
|
82 |
container.setLayout(new FormLayout()); |
|
83 |
|
|
84 |
exportSingleReadsCB = new Button(container, SWT.CHECK); |
|
85 |
FormData fd_exportSingleReadsCB = new FormData(); |
|
86 |
fd_exportSingleReadsCB.left = new FormAttachment(0, 10); |
|
87 |
exportSingleReadsCB.setLayoutData(fd_exportSingleReadsCB); |
|
88 |
exportSingleReadsCB.setText(Messages.wizardExportAlignmentExportSingleReads); |
|
89 |
final ISWTObservableValue exportSingleReadsObservable = SWTObservables.observeSelection(exportSingleReadsCB); |
|
90 |
dbc.bindValue(exportSingleReadsObservable, getWizard().getModel().getExportSingleReadsObservable()); |
|
91 |
exportSingleReadsCB.setSelection(false); |
|
92 |
exportSingleReadsCB.setSelection(true); // Must happen after the component has been bound to the model. |
|
93 |
|
|
94 |
|
|
95 |
exportConsensusSequenceCB = new Button(container, SWT.CHECK); |
|
96 |
exportConsensusSequenceCB.addSelectionListener(new SelectionAdapter() { |
|
97 |
@Override |
|
98 |
public void widgetSelected(SelectionEvent e) { |
|
99 |
consensusSequenceLabelTextField.setEnabled(exportConsensusSequenceCB.getSelection()); |
|
100 |
} |
|
101 |
}); |
|
102 |
FormData fd_exportConsensusSequenceCB = new FormData(); |
|
103 |
fd_exportConsensusSequenceCB.top = new FormAttachment(exportSingleReadsCB, 6); |
|
104 |
fd_exportConsensusSequenceCB.left = new FormAttachment(0, 10); |
|
105 |
exportConsensusSequenceCB.setLayoutData(fd_exportConsensusSequenceCB); |
|
106 |
exportConsensusSequenceCB.setText(Messages.wizardExportAlignmentExportConsensusSeqLabel); |
|
107 |
final ISWTObservableValue exportConsensusSequenceObservable = SWTObservables.observeSelection(exportConsensusSequenceCB); |
|
108 |
dbc.bindValue(exportConsensusSequenceObservable, getWizard().getModel().getExportConsensusSequenceObservable()); |
|
109 |
exportConsensusSequenceCB.setSelection(false); |
|
110 |
exportConsensusSequenceCB.setSelection(true); // Must happen after the component has been bound to the model. |
|
111 |
|
|
112 |
consensusSequenceLabelTextField = new Text(container, SWT.BORDER); |
|
113 |
FormData fd_consensusSequenceNameTextField = new FormData(); |
|
114 |
fd_consensusSequenceNameTextField.bottom = new FormAttachment(exportConsensusSequenceCB, 32, SWT.BOTTOM); |
|
115 |
fd_consensusSequenceNameTextField.left = new FormAttachment(0, 32); |
|
116 |
fd_consensusSequenceNameTextField.right = new FormAttachment(100, -10); |
|
117 |
fd_consensusSequenceNameTextField.top = new FormAttachment(exportConsensusSequenceCB, 6); |
|
118 |
consensusSequenceLabelTextField.setLayoutData(fd_consensusSequenceNameTextField); |
|
119 |
final ISWTObservableValue consensusSequenceLabelObservable = SWTObservables.observeText(consensusSequenceLabelTextField, SWT.Modify); |
|
120 |
dbc.bindValue(consensusSequenceLabelObservable, getWizard().getModel().getConsensusSequenceLabelObservable()); |
|
121 |
consensusSequenceLabelTextField.setText("ConsensusSequence"); // Must happen after the component has been bound to the model. //$NON-NLS-1$ |
|
122 |
|
|
123 |
Label lblFormat = new Label(container, SWT.NONE); |
|
124 |
FormData fd_lblFormat = new FormData(); |
|
125 |
fd_lblFormat.top = new FormAttachment(consensusSequenceLabelTextField, 36); |
|
126 |
fd_lblFormat.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT); |
|
127 |
lblFormat.setLayoutData(fd_lblFormat); |
|
128 |
lblFormat.setText(Messages.wizardExportAlignmentExportFormatLabel); |
|
129 |
|
|
130 |
Label lblSelectTheData = new Label(container, SWT.NONE); |
|
131 |
fd_exportSingleReadsCB.top = new FormAttachment(lblSelectTheData, 6); |
|
132 |
FormData fd_lblSelectTheData = new FormData(); |
|
133 |
fd_lblSelectTheData.left = new FormAttachment(0, 10); |
|
134 |
fd_lblSelectTheData.top = new FormAttachment(0, 10); |
|
135 |
lblSelectTheData.setLayoutData(fd_lblSelectTheData); |
|
136 |
lblSelectTheData.setText(Messages.wizardExportAlignmentDataLabel); |
|
137 |
|
|
138 |
Label lblSelectTheExport = new Label(container, SWT.NONE); |
|
139 |
FormData fd_lblSelectTheExport = new FormData(); |
|
140 |
fd_lblSelectTheExport.top = new FormAttachment(lblFormat, 57); |
|
141 |
fd_lblSelectTheExport.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT); |
|
142 |
lblSelectTheExport.setLayoutData(fd_lblSelectTheExport); |
|
143 |
lblSelectTheExport.setText(Messages.wizardExportAlignmentDestinationLabel); |
|
144 |
|
|
145 |
Label lblAlignmentFile = new Label(container, SWT.NONE); |
|
146 |
FormData fd_lblAlignmentFile = new FormData(); |
|
147 |
fd_lblAlignmentFile.top = new FormAttachment(lblSelectTheExport, 9); |
|
148 |
fd_lblAlignmentFile.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT); |
|
149 |
lblAlignmentFile.setLayoutData(fd_lblAlignmentFile); |
|
150 |
lblAlignmentFile.setText(Messages.wizardExportAlignmentFileLabel); |
|
151 |
|
|
152 |
fileTextField = new Text(container, SWT.BORDER); |
|
153 |
FormData fd_text = new FormData(); |
|
154 |
fd_text.right = new FormAttachment(100, -10); |
|
155 |
fd_text.left = new FormAttachment(lblAlignmentFile, 6); |
|
156 |
fd_text.top = new FormAttachment(lblSelectTheExport, 6); |
|
157 |
fileTextField.setLayoutData(fd_text); |
|
158 |
final ISWTObservableValue fileNameObservable = SWTObservables.observeText(fileTextField, SWT.Modify); |
|
159 |
dbc.bindValue(fileNameObservable, getWizard().getModel().getFileNameObservable()); |
|
160 |
|
|
161 |
Button btnBrowse = new Button(container, SWT.NONE); |
|
162 |
btnBrowse.addSelectionListener(new SelectionAdapter() { |
|
163 |
@Override |
|
164 |
public void widgetSelected(SelectionEvent e) { |
|
165 |
FileDialog dialog = new FileDialog(getShell(), SWT.OPEN); |
|
166 |
dialog.setText(Messages.wizardExportAlignmentFileDialogTitle); |
|
167 |
ContentExtensionFileFilter filter = getSelectedFormat().createFileFilter(TestStrategy.EXTENSION); |
|
168 |
dialog.setFilterExtensions(new String[]{filter.getExtensionsAsString()}); |
|
169 |
dialog.setFilterNames(new String[]{filter.getDescription()}); |
|
170 |
String selectedFile = dialog.open(); |
|
171 |
if (selectedFile != null) { // Otherwise selecting was canceled. |
|
172 |
fileTextField.setText(selectedFile); |
|
173 |
} |
|
174 |
} |
|
175 |
}); |
|
176 |
FormData fd_btnBrowse = new FormData(); |
|
177 |
fd_btnBrowse.left = new FormAttachment(100, -128); |
|
178 |
fd_btnBrowse.bottom = new FormAttachment(fileTextField, 43, SWT.BOTTOM); |
|
179 |
fd_btnBrowse.top = new FormAttachment(fileTextField, 13); |
|
180 |
fd_btnBrowse.right = new FormAttachment(100, -10); |
|
181 |
btnBrowse.setLayoutData(fd_btnBrowse); |
|
182 |
btnBrowse.setText(Messages.wizardExportAlignmentBrowseButton); |
|
183 |
|
|
184 |
formatComboBox = new Combo(container, SWT.READ_ONLY); |
|
185 |
for (JPhyloIOFormatInfo formatInfo : ExportSingleReadAlignmentWizardModel.FORMAT_NAMES_TO_INFO_MAP.values()) { |
|
186 |
formatComboBox.add(formatInfo.getFormatName()); |
|
187 |
} |
|
188 |
FormData fd_formatComboBox = new FormData(); |
|
189 |
fd_formatComboBox.left = new FormAttachment(0, 10); |
|
190 |
fd_formatComboBox.right = new FormAttachment(100, -10); |
|
191 |
fd_formatComboBox.top = new FormAttachment(lblFormat, 6); |
|
192 |
formatComboBox.setLayoutData(fd_formatComboBox); |
|
193 |
final ISWTObservableValue formatObservable = SWTObservables.observeSelection(formatComboBox); // ViewerProperties.singleSelection().observe(formatComboBox); falls ein ComboViewer verwendet wird. (Dann kann direkt FormatInfo verwendet werden.) |
|
194 |
dbc.bindValue(formatObservable, getWizard().getModel().getFormatInfoObservable()); |
|
195 |
formatComboBox.select(0); // Must happen after the component has been bound to the model. |
|
196 |
|
|
197 |
Button appendExtensionButton = new Button(container, SWT.NONE); |
|
198 |
appendExtensionButton.addSelectionListener(new SelectionAdapter() { |
|
199 |
@Override |
|
200 |
public void widgetSelected(SelectionEvent e) { |
|
201 |
fileTextField.setText(fileTextField.getText() + ExtensionFileFilter.EXTENSION_SEPARATOR + |
|
202 |
getSelectedFormat().createFileFilter(TestStrategy.EXTENSION).getDefaultExtension()); |
|
203 |
} |
|
204 |
}); |
|
205 |
FormData fd_btnNewButton = new FormData(); |
|
206 |
fd_btnNewButton.left = new FormAttachment(btnBrowse, -276, SWT.LEFT); |
|
207 |
fd_btnNewButton.right = new FormAttachment(btnBrowse, -6); |
|
208 |
fd_btnNewButton.bottom = new FormAttachment(fileTextField, 43, SWT.BOTTOM); |
|
209 |
fd_btnNewButton.top = new FormAttachment(fileTextField, 13); |
|
210 |
appendExtensionButton.setLayoutData(fd_btnNewButton); |
|
211 |
appendExtensionButton.setText(Messages.wizardExportAlignmentAppendExtensionButton); |
|
212 |
|
|
213 |
dbc.addValidationStatusProvider(new MultiValidator() { |
|
214 |
@Override |
|
215 |
protected IStatus validate() { |
|
216 |
String label = (String)consensusSequenceLabelObservable.getValue(); |
|
217 |
boolean exportConsensus = (Boolean)exportConsensusSequenceObservable.getValue(); |
|
218 |
boolean exportReads = (Boolean)exportSingleReadsObservable.getValue(); |
|
219 |
|
|
220 |
if (!exportConsensus && !exportReads) { |
|
221 |
return ValidationStatus.error(Messages.wizardExportAlignmentErrorNothingToExport); |
|
222 |
} |
|
223 |
else if (exportConsensus && ((label == null) || label.isEmpty())) { |
|
224 |
return ValidationStatus.error(Messages.wizardExportAlignmentErrorMissingSeqLabel); |
|
225 |
} |
|
226 |
|
|
227 |
String fileName = (String)fileNameObservable.getValue(); |
|
228 |
if ((fileName == null) || fileName.isEmpty()) { |
|
229 |
return ValidationStatus.error(Messages.wizardExportAlignmentErrorMissingFileName); |
|
230 |
} |
|
231 |
else if (!getSelectedFormat().createFileFilter(TestStrategy.EXTENSION).accept(new File(fileName))) { |
|
232 |
return ValidationStatus.warning(Messages.wizardExportAlignmentwarningMissingExtension); |
|
233 |
} |
|
234 |
else if (fileName.charAt(0) == ExtensionFileFilter.EXTENSION_SEPARATOR) { |
|
235 |
return ValidationStatus.warning(Messages.wizardExportAlignmentWarningFileNameStartsDot); |
|
236 |
} |
|
237 |
else { |
|
238 |
return ValidationStatus.ok(); |
|
239 |
} |
|
240 |
} |
|
241 |
}); |
|
242 |
} |
|
243 |
|
|
244 |
|
|
245 |
private JPhyloIOFormatInfo getSelectedFormat() { |
|
246 |
return ExportSingleReadAlignmentWizardModel.FORMAT_NAMES_TO_INFO_MAP.get(formatComboBox.getText()); |
|
247 |
} |
|
248 |
|
|
249 |
|
|
250 |
/** |
|
251 |
* {@inheritDoc} |
|
252 |
*/ |
|
253 |
@Override |
|
254 |
public ExportSingleReadAlignmentWizard getWizard() { |
|
255 |
return (ExportSingleReadAlignmentWizard)super.getWizard(); // Would throw an exception, if this page is used within another wizard. |
|
256 |
} |
|
257 |
} |
Also available in: Unified diff
Export single read alignment wizard separated into two pages.
Option to elongate sequences added.
Application information parameters of JPhyloIO set.