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
|
}
|