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.jphyloio.events.type.EventContentType;
|
15
|
import info.bioinfweb.jphyloio.factory.JPhyloIOReaderWriterFactory;
|
16
|
import info.bioinfweb.jphyloio.formatinfo.JPhyloIOFormatInfo;
|
17
|
|
18
|
import java.io.File;
|
19
|
import java.util.ArrayList;
|
20
|
import java.util.Collections;
|
21
|
import java.util.List;
|
22
|
|
23
|
import org.eclipse.jface.wizard.WizardPage;
|
24
|
import org.eclipse.swt.SWT;
|
25
|
import org.eclipse.swt.events.SelectionAdapter;
|
26
|
import org.eclipse.swt.events.SelectionEvent;
|
27
|
import org.eclipse.swt.layout.FormAttachment;
|
28
|
import org.eclipse.swt.layout.FormData;
|
29
|
import org.eclipse.swt.layout.FormLayout;
|
30
|
import org.eclipse.swt.widgets.Button;
|
31
|
import org.eclipse.swt.widgets.Combo;
|
32
|
import org.eclipse.swt.widgets.Composite;
|
33
|
import org.eclipse.swt.widgets.FileDialog;
|
34
|
import org.eclipse.swt.widgets.Label;
|
35
|
import org.eclipse.swt.widgets.Text;
|
36
|
|
37
|
|
38
|
|
39
|
/**
|
40
|
* Wizard page that allows to specify which parts of a single read alignment shall be exported to an alignment file.
|
41
|
*
|
42
|
* @author Ben Stöver
|
43
|
* @date 18.04.2016
|
44
|
*/
|
45
|
public class ExportSingleReadAlignmentWizardPage extends WizardPage {
|
46
|
private static final JPhyloIOReaderWriterFactory FACTORY = new JPhyloIOReaderWriterFactory();
|
47
|
private static final List<JPhyloIOFormatInfo> FORMATS = createFormatInfoList();
|
48
|
|
49
|
private Text consensusSequenceNameTextField;
|
50
|
private Button exportConsensusSequenceCB;
|
51
|
private Button exportSingleReadsCB;
|
52
|
private Text fileTextField;
|
53
|
private Combo formatComboBox;
|
54
|
|
55
|
|
56
|
/**
|
57
|
* Create the wizard.
|
58
|
*/
|
59
|
public ExportSingleReadAlignmentWizardPage() {
|
60
|
super("SingleReadSequencesExport"); //TODO Which pageName should be used here? Any conventions?
|
61
|
setTitle("Sequence export");
|
62
|
setDescription("Defines which sequences of the single read alignment shall be exported.");
|
63
|
}
|
64
|
|
65
|
|
66
|
private static List<JPhyloIOFormatInfo> createFormatInfoList() {
|
67
|
List<JPhyloIOFormatInfo> result = new ArrayList<JPhyloIOFormatInfo>();
|
68
|
for (String formatID : FACTORY.getFormatIDsSet()) {
|
69
|
JPhyloIOFormatInfo info = FACTORY.getFormatInfo(formatID);
|
70
|
if (info.isElementModeled(EventContentType.ALIGNMENT, false)) { // Check if the current format allows to write alignments.
|
71
|
result.add(info);
|
72
|
}
|
73
|
}
|
74
|
return Collections.unmodifiableList(result);
|
75
|
}
|
76
|
|
77
|
|
78
|
/**
|
79
|
* Create contents of the wizard.
|
80
|
*
|
81
|
* @param parent the parent component
|
82
|
*/
|
83
|
@Override
|
84
|
public void createControl(Composite parent) {
|
85
|
Composite container = new Composite(parent, SWT.NULL);
|
86
|
|
87
|
setControl(container);
|
88
|
container.setLayout(new FormLayout());
|
89
|
|
90
|
exportSingleReadsCB = new Button(container, SWT.CHECK);
|
91
|
exportSingleReadsCB.setSelection(true);
|
92
|
FormData fd_exportSingleReadsCB = new FormData();
|
93
|
fd_exportSingleReadsCB.left = new FormAttachment(0, 10);
|
94
|
exportSingleReadsCB.setLayoutData(fd_exportSingleReadsCB);
|
95
|
exportSingleReadsCB.setText("Export single reads");
|
96
|
|
97
|
exportConsensusSequenceCB = new Button(container, SWT.CHECK);
|
98
|
exportConsensusSequenceCB.setSelection(true);
|
99
|
exportConsensusSequenceCB.addSelectionListener(new SelectionAdapter() {
|
100
|
@Override
|
101
|
public void widgetSelected(SelectionEvent e) {
|
102
|
consensusSequenceNameTextField.setEnabled(exportConsensusSequenceCB.getSelection());
|
103
|
}
|
104
|
});
|
105
|
FormData fd_exportConsensusSequenceCB = new FormData();
|
106
|
fd_exportConsensusSequenceCB.top = new FormAttachment(exportSingleReadsCB, 6);
|
107
|
fd_exportConsensusSequenceCB.left = new FormAttachment(0, 10);
|
108
|
exportConsensusSequenceCB.setLayoutData(fd_exportConsensusSequenceCB);
|
109
|
exportConsensusSequenceCB.setText("Export consensus sequence");
|
110
|
|
111
|
consensusSequenceNameTextField = new Text(container, SWT.BORDER);
|
112
|
consensusSequenceNameTextField.setText("ConsensusSequence");
|
113
|
FormData fd_consensusSequenceNameTextField = new FormData();
|
114
|
fd_consensusSequenceNameTextField.left = new FormAttachment(0, 32);
|
115
|
fd_consensusSequenceNameTextField.right = new FormAttachment(100, -10);
|
116
|
fd_consensusSequenceNameTextField.top = new FormAttachment(exportConsensusSequenceCB, 6);
|
117
|
fd_consensusSequenceNameTextField.bottom = new FormAttachment(30, 26);
|
118
|
consensusSequenceNameTextField.setLayoutData(fd_consensusSequenceNameTextField);
|
119
|
|
120
|
Label lblFormat = new Label(container, SWT.NONE);
|
121
|
FormData fd_lblFormat = new FormData();
|
122
|
fd_lblFormat.top = new FormAttachment(consensusSequenceNameTextField, 25);
|
123
|
fd_lblFormat.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT);
|
124
|
lblFormat.setLayoutData(fd_lblFormat);
|
125
|
lblFormat.setText("Select the export format:");
|
126
|
|
127
|
Label lblSelectTheData = new Label(container, SWT.NONE);
|
128
|
fd_exportSingleReadsCB.top = new FormAttachment(lblSelectTheData, 6);
|
129
|
FormData fd_lblSelectTheData = new FormData();
|
130
|
fd_lblSelectTheData.left = new FormAttachment(0, 10);
|
131
|
fd_lblSelectTheData.top = new FormAttachment(0, 10);
|
132
|
lblSelectTheData.setLayoutData(fd_lblSelectTheData);
|
133
|
lblSelectTheData.setText("Select the data to export:");
|
134
|
|
135
|
Label lblSelectTheExport = new Label(container, SWT.NONE);
|
136
|
FormData fd_lblSelectTheExport = new FormData();
|
137
|
fd_lblSelectTheExport.top = new FormAttachment(lblFormat, 57);
|
138
|
fd_lblSelectTheExport.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT);
|
139
|
lblSelectTheExport.setLayoutData(fd_lblSelectTheExport);
|
140
|
lblSelectTheExport.setText("Select the export destination:");
|
141
|
|
142
|
Label lblAlignmentFile = new Label(container, SWT.NONE);
|
143
|
FormData fd_lblAlignmentFile = new FormData();
|
144
|
fd_lblAlignmentFile.top = new FormAttachment(lblSelectTheExport, 9);
|
145
|
fd_lblAlignmentFile.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT);
|
146
|
lblAlignmentFile.setLayoutData(fd_lblAlignmentFile);
|
147
|
lblAlignmentFile.setText("Alignment file:");
|
148
|
|
149
|
fileTextField = new Text(container, SWT.BORDER);
|
150
|
FormData fd_text = new FormData();
|
151
|
fd_text.left = new FormAttachment(lblAlignmentFile, 6);
|
152
|
fd_text.top = new FormAttachment(lblSelectTheExport, 6);
|
153
|
fileTextField.setLayoutData(fd_text);
|
154
|
|
155
|
Button btnBrowse = new Button(container, SWT.NONE);
|
156
|
btnBrowse.addSelectionListener(new SelectionAdapter() {
|
157
|
@Override
|
158
|
public void widgetSelected(SelectionEvent e) {
|
159
|
FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
|
160
|
dialog.setText("Export to"); //TODO Make multi language
|
161
|
//fd.setFilterPath("C:/");
|
162
|
ContentExtensionFileFilter filter = getSelectedFormat().createFileFilter();
|
163
|
dialog.setFilterExtensions(new String[]{filter.getExtensionsAsString()});
|
164
|
dialog.setFilterNames(new String[]{filter.getDescription()});
|
165
|
String selectedFile = dialog.open();
|
166
|
if (selectedFile != null) { // Otherwise selecting was canceled.
|
167
|
fileTextField.setText(selectedFile);
|
168
|
}
|
169
|
//TODO Add default extension, if necessary.
|
170
|
}
|
171
|
});
|
172
|
fd_text.right = new FormAttachment(100, -134);
|
173
|
FormData fd_btnBrowse = new FormData();
|
174
|
fd_btnBrowse.left = new FormAttachment(fileTextField, 6);
|
175
|
fd_btnBrowse.top = new FormAttachment(lblAlignmentFile, -5, SWT.TOP);
|
176
|
fd_btnBrowse.right = new FormAttachment(100, -10);
|
177
|
btnBrowse.setLayoutData(fd_btnBrowse);
|
178
|
btnBrowse.setText("Browse...");
|
179
|
|
180
|
formatComboBox = new Combo(container, SWT.READ_ONLY);
|
181
|
for (JPhyloIOFormatInfo formatInfo : FORMATS) {
|
182
|
formatComboBox.add(formatInfo.getFormatName());
|
183
|
}
|
184
|
|
185
|
FormData fd_formatComboBox = new FormData();
|
186
|
fd_formatComboBox.right = new FormAttachment(consensusSequenceNameTextField, 0, SWT.RIGHT);
|
187
|
fd_formatComboBox.top = new FormAttachment(lblFormat, 6);
|
188
|
fd_formatComboBox.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT);
|
189
|
formatComboBox.setLayoutData(fd_formatComboBox);
|
190
|
formatComboBox.select(0);
|
191
|
}
|
192
|
|
193
|
|
194
|
/**
|
195
|
* Returns the <i>JPhyloIO</i> format info object to be used for exporting.
|
196
|
*
|
197
|
* @return the format info or {@code null}, if none was yet selected
|
198
|
*/
|
199
|
public JPhyloIOFormatInfo getSelectedFormat() {
|
200
|
if (formatComboBox != null) {
|
201
|
int index = formatComboBox.getSelectionIndex();
|
202
|
if (index > -1) {
|
203
|
return FORMATS.get(index);
|
204
|
}
|
205
|
}
|
206
|
return null;
|
207
|
}
|
208
|
|
209
|
|
210
|
public File getSelectedFile() {
|
211
|
if (fileTextField != null) {
|
212
|
return new File(fileTextField.getText());
|
213
|
}
|
214
|
else {
|
215
|
return null;
|
216
|
}
|
217
|
}
|
218
|
|
219
|
|
220
|
public String getConsensusSequenceLabel() {
|
221
|
if (consensusSequenceNameTextField != null) {
|
222
|
return consensusSequenceNameTextField.getText();
|
223
|
}
|
224
|
else {
|
225
|
return null;
|
226
|
}
|
227
|
}
|
228
|
}
|