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 java.io.File;
|
14
|
|
15
|
import org.eclipse.core.databinding.DataBindingContext;
|
16
|
import org.eclipse.core.databinding.validation.MultiValidator;
|
17
|
import org.eclipse.core.databinding.validation.ValidationStatus;
|
18
|
import org.eclipse.core.runtime.IStatus;
|
19
|
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
|
20
|
import org.eclipse.jface.databinding.swt.SWTObservables;
|
21
|
import org.eclipse.jface.databinding.wizard.WizardPageSupport;
|
22
|
import org.eclipse.swt.SWT;
|
23
|
import org.eclipse.swt.events.SelectionAdapter;
|
24
|
import org.eclipse.swt.events.SelectionEvent;
|
25
|
import org.eclipse.swt.layout.FormAttachment;
|
26
|
import org.eclipse.swt.layout.FormData;
|
27
|
import org.eclipse.swt.layout.FormLayout;
|
28
|
import org.eclipse.swt.widgets.Button;
|
29
|
import org.eclipse.swt.widgets.Combo;
|
30
|
import org.eclipse.swt.widgets.Composite;
|
31
|
import org.eclipse.swt.widgets.DirectoryDialog;
|
32
|
import org.eclipse.swt.widgets.Label;
|
33
|
import org.eclipse.swt.widgets.Text;
|
34
|
|
35
|
import eu.etaxonomy.taxeditor.molecular.l10n.Messages;
|
36
|
import info.bioinfweb.commons.io.ContentExtensionFileFilter.TestStrategy;
|
37
|
import info.bioinfweb.commons.io.ExtensionFileFilter;
|
38
|
import info.bioinfweb.jphyloio.formatinfo.JPhyloIOFormatInfo;
|
39
|
|
40
|
|
41
|
|
42
|
/**
|
43
|
* Wizard page that allows to specify which parts of a single read alignment shall be exported to an alignment file.
|
44
|
*
|
45
|
* @author Ben Stöver
|
46
|
* @date 18.04.2016
|
47
|
*/
|
48
|
public class ExportSingleReadAlignmentFileFormatPage extends AbstractExportSingleReadAlignmentWizardPage {
|
49
|
private Text fileTextField;
|
50
|
private Combo formatComboBox;
|
51
|
|
52
|
|
53
|
/**
|
54
|
* Create the wizard.
|
55
|
*/
|
56
|
public ExportSingleReadAlignmentFileFormatPage() {
|
57
|
super("ExportSingleReadAlignmentFileFormat"); //TODO Which pageName should be used here? Any conventions? //$NON-NLS-1$
|
58
|
setTitle(Messages.wizardExportAlignmentTitle);
|
59
|
setDescription(Messages.wizardExportAlignmentDescription);
|
60
|
}
|
61
|
|
62
|
|
63
|
/**
|
64
|
* Create contents of the wizard.
|
65
|
*
|
66
|
* @param parent the parent component
|
67
|
*/
|
68
|
@Override
|
69
|
public void createControl(Composite parent) {
|
70
|
DataBindingContext dbc = new DataBindingContext();
|
71
|
WizardPageSupport.create(this, dbc);
|
72
|
|
73
|
Composite container = new Composite(parent, SWT.NULL);
|
74
|
|
75
|
setControl(container);
|
76
|
container.setLayout(new FormLayout());
|
77
|
|
78
|
Label lblFormat = new Label(container, SWT.NONE);
|
79
|
FormData fd_lblFormat = new FormData();
|
80
|
fd_lblFormat.right = new FormAttachment(100, -10);
|
81
|
fd_lblFormat.top = new FormAttachment(0, 10);
|
82
|
fd_lblFormat.left = new FormAttachment(0, 10);
|
83
|
lblFormat.setLayoutData(fd_lblFormat);
|
84
|
lblFormat.setText(Messages.wizardExportAlignmentExportFormatLabel);
|
85
|
|
86
|
Label lblSelectTheExport = new Label(container, SWT.NONE);
|
87
|
FormData fd_lblSelectTheExport = new FormData();
|
88
|
fd_lblSelectTheExport.right = new FormAttachment(100, -10);
|
89
|
fd_lblSelectTheExport.left = new FormAttachment(0, 10);
|
90
|
lblSelectTheExport.setLayoutData(fd_lblSelectTheExport);
|
91
|
lblSelectTheExport.setText(Messages.wizardExportAlignmentDestinationLabel);
|
92
|
|
93
|
Label lblAlignmentFile = new Label(container, SWT.NONE);
|
94
|
FormData fd_lblAlignmentFile = new FormData();
|
95
|
fd_lblAlignmentFile.top = new FormAttachment(lblSelectTheExport, 9);
|
96
|
fd_lblAlignmentFile.right = new FormAttachment(0, 128);
|
97
|
fd_lblAlignmentFile.left = new FormAttachment(0, 10);
|
98
|
lblAlignmentFile.setLayoutData(fd_lblAlignmentFile);
|
99
|
lblAlignmentFile.setText(Messages.wizardExportAlignmentFileLabel);
|
100
|
|
101
|
fileTextField = new Text(container, SWT.BORDER);
|
102
|
FormData fd_text = new FormData();
|
103
|
fd_text.left = new FormAttachment(lblAlignmentFile, 6);
|
104
|
fd_text.right = new FormAttachment(100, -10);
|
105
|
fd_text.top = new FormAttachment(lblSelectTheExport, 6);
|
106
|
fileTextField.setLayoutData(fd_text);
|
107
|
final ISWTObservableValue fileNameObservable = SWTObservables.observeText(fileTextField, SWT.Modify);
|
108
|
dbc.bindValue(fileNameObservable, getWizard().getModel().getFileNameObservable());
|
109
|
|
110
|
Button btnBrowse = new Button(container, SWT.NONE);
|
111
|
btnBrowse.addSelectionListener(new SelectionAdapter() {
|
112
|
@Override
|
113
|
public void widgetSelected(SelectionEvent e) {
|
114
|
DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.OPEN);
|
115
|
dialog.setText(Messages.wizardExportAlignmentFileDialogTitle);
|
116
|
// ContentExtensionFileFilter filter = getSelectedFormat().createFileFilter(TestStrategy.EXTENSION);
|
117
|
// dialog.setFilterExtensions(new String[]{filter.getExtensionsAsString()});
|
118
|
// dialog.setFilterNames(new String[]{filter.getDescription()});
|
119
|
String selectedFile = dialog.open();
|
120
|
if (selectedFile != null) { // Otherwise selecting was canceled.
|
121
|
fileTextField.setText(selectedFile+File.separator+fileTextField.getText());
|
122
|
}
|
123
|
}
|
124
|
});
|
125
|
FormData fd_btnBrowse = new FormData();
|
126
|
fd_btnBrowse.bottom = new FormAttachment(fileTextField, 43, SWT.BOTTOM);
|
127
|
fd_btnBrowse.top = new FormAttachment(fileTextField, 13);
|
128
|
fd_btnBrowse.left = new FormAttachment(100, -128);
|
129
|
fd_btnBrowse.right = new FormAttachment(100, -10);
|
130
|
btnBrowse.setLayoutData(fd_btnBrowse);
|
131
|
btnBrowse.setText(Messages.wizardExportAlignmentBrowseButton);
|
132
|
|
133
|
formatComboBox = new Combo(container, SWT.READ_ONLY);
|
134
|
fd_lblSelectTheExport.top = new FormAttachment(formatComboBox, 23);
|
135
|
for (JPhyloIOFormatInfo formatInfo : ExportSingleReadAlignmentWizardModel.FORMATS) {
|
136
|
formatComboBox.add(formatInfo.getFormatName());
|
137
|
}
|
138
|
FormData fd_formatComboBox = new FormData();
|
139
|
fd_formatComboBox.top = new FormAttachment(lblFormat, 6);
|
140
|
fd_formatComboBox.left = new FormAttachment(0, 10);
|
141
|
fd_formatComboBox.right = new FormAttachment(100, -10);
|
142
|
formatComboBox.setLayoutData(fd_formatComboBox);
|
143
|
final ISWTObservableValue formatObservable = SWTObservables.observeSingleSelectionIndex(formatComboBox); // ViewerProperties.singleSelection().observe(formatComboBox); falls ein ComboViewer verwendet wird. (Dann kann direkt FormatInfo verwendet werden.)
|
144
|
dbc.bindValue(formatObservable, getWizard().getModel().getFormatInfoObservable());
|
145
|
formatComboBox.select(0); // Must happen after the component has been bound to the model.
|
146
|
|
147
|
Button appendExtensionButton = new Button(container, SWT.NONE);
|
148
|
appendExtensionButton.addSelectionListener(new SelectionAdapter() {
|
149
|
@Override
|
150
|
public void widgetSelected(SelectionEvent e) {
|
151
|
fileTextField.setText(fileTextField.getText() + ExtensionFileFilter.EXTENSION_SEPARATOR +
|
152
|
getSelectedFormat().createFileFilter(TestStrategy.EXTENSION).getDefaultExtension());
|
153
|
}
|
154
|
});
|
155
|
FormData fd_btnNewButton = new FormData();
|
156
|
fd_btnNewButton.left = new FormAttachment(btnBrowse, -264, SWT.LEFT);
|
157
|
fd_btnNewButton.bottom = new FormAttachment(fileTextField, 43, SWT.BOTTOM);
|
158
|
fd_btnNewButton.right = new FormAttachment(btnBrowse, -6);
|
159
|
fd_btnNewButton.top = new FormAttachment(fileTextField, 13);
|
160
|
appendExtensionButton.setLayoutData(fd_btnNewButton);
|
161
|
appendExtensionButton.setText(Messages.wizardExportAlignmentAppendExtensionButton);
|
162
|
|
163
|
dbc.addValidationStatusProvider(new MultiValidator() {
|
164
|
@Override
|
165
|
protected IStatus validate() {
|
166
|
String fileName = (String)fileNameObservable.getValue();
|
167
|
Integer index = (Integer)formatObservable.getValue(); // If formatObservable.getValue() is not called from within this method, it is not called on modifications of the according combo anymore. (Would be interesting to know why.)
|
168
|
if ((fileName == null) || fileName.isEmpty()) {
|
169
|
return ValidationStatus.error(Messages.wizardExportAlignmentErrorMissingFileName);
|
170
|
}
|
171
|
else if (!ExportSingleReadAlignmentWizardModel.FORMATS.get(index).createFileFilter(TestStrategy.EXTENSION).accept(
|
172
|
new File(fileName))) {
|
173
|
|
174
|
return ValidationStatus.warning(Messages.wizardExportAlignmentwarningMissingExtension);
|
175
|
}
|
176
|
else if (fileName.charAt(0) == ExtensionFileFilter.EXTENSION_SEPARATOR) {
|
177
|
return ValidationStatus.warning(Messages.wizardExportAlignmentWarningFileNameStartsDot);
|
178
|
}
|
179
|
else if (new File(fileName).exists()) {
|
180
|
return ValidationStatus.warning(Messages.wizardExportAlignmentWarningFileExists);
|
181
|
}
|
182
|
else {
|
183
|
return ValidationStatus.ok();
|
184
|
}
|
185
|
}
|
186
|
});
|
187
|
}
|
188
|
|
189
|
|
190
|
private JPhyloIOFormatInfo getSelectedFormat() {
|
191
|
return ExportSingleReadAlignmentWizardModel.FORMATS.get(formatComboBox.getSelectionIndex());
|
192
|
}
|
193
|
}
|