Project

General

Profile

« Previous | Next » 

Revision 80e535dd

Added by Ben Stöver over 7 years ago

Additional strings externalized in molecular plugin.
Wizard for exporting single read alignments now warns and prompts if files are overwritten.
Bug fix: Changes in the format selection in the wizard now trigger validation again.
ExportSingleReadAlignmentWizardModel uses format list instead of map again.

View differences:

eu.etaxonomy.taxeditor.molecular/OSGI-INF/l10n/messages.properties
1
exportSequenceToFileHandlerIOErrorMessage=An error occurred when trying to export a consensus sequence alignment to the file "%s".
2
exportSequenceToFileHandlerIOErrorTitle=I/O error
3
exportSequenceToFileHandlerOverwriteTitle=Overwrite file
4
exportSequenceToFileHandlerOverwriteText=The file \"%s\" already exists.\n\nDo you want to overwrite it?
1 5
wizardExportAlignmentAppendExtensionButton=Append default extension
2 6
wizardExportAlignmentBrowseButton=Browse...
3 7
wizardExportAlignmentDataLabel=Select the data to export:
......
14 18
wizardExportAlignmentTitle=Sequence export
15 19
wizardExportAlignmentWarningFileNameStartsDot=File starting with '.' are not supported on all operating systems.
16 20
wizardExportAlignmentwarningMissingExtension=The file name does have a valid extension for the selected format.
17
exportSequenceToFileHandlerIOErrorMessage=An error occurred when trying to export a consensus sequence alignment to the file "%s".
18
exportSequenceToFileHandlerIOErrorTitle=I/O error
21
wizardExportAlignmentWarningFileExists=The file already exists and will be overwritten.
22
wizardExportAlignmentOptionsDescription=Specify additional export parameters.
23
wizardExportAlignmentOptionsTitle=Export options
24
wizardExportAlignmentExportedSeqHeading=Specify the sequences to be exported:
25
wizardExportAlignmentAdditionalOptionsHeading=Specify additional export options:
26
wizardExportAlignmentElongateSeqHeading=Elongate sequences to have equal length with:
27
wizardExportAlignmentElongateSeqMissingData=Missing data ('?')"
28
wizardExportAlignmentElongateSeqGap=Gap ('-')
eu.etaxonomy.taxeditor.molecular/OSGI-INF/l10n/messages_de.properties
1
exportSequenceToFileHandlerIOErrorMessage=Beim Schreiben der Datei "%s" ist ein Fehler aufgetreten.
2
exportSequenceToFileHandlerIOErrorTitle=E/A Fehler
3
exportSequenceToFileHandlerOverwriteTitle=Datei ?berschreiben
4
exportSequenceToFileHandlerOverwriteText=Die Datei \"%s\" existiert bereits.\n\nSoll sie ?berschrieben werden?
1 5
wizardExportAlignmentAppendExtensionButton=Standarddateiendung anh?ngen
2 6
wizardExportAlignmentBrowseButton=Durchsuchen...
3 7
wizardExportAlignmentDataLabel=Zu exportierende Daten:
......
14 18
wizardExportAlignmentTitle=Sequenzexport
15 19
wizardExportAlignmentWarningFileNameStartsDot=Dateinamen, die mit einem '.' beginnen, werden nicht auf allen Betriebssystemen unterst?tzt.
16 20
wizardExportAlignmentwarningMissingExtension=Der momentane Dateiname hat keine zum aktuellen Format passende Endung.
17
exportSequenceToFileHandlerIOErrorMessage=Beim Schreiben der Datei "%s" ist ein Fehler aufgetreten.
18
exportSequenceToFileHandlerIOErrorTitle=E/A Fehler
21
wizardExportAlignmentWarningFileExists=The existiert bereits und w?rde ?berschrieben.
22
wizardExportAlignmentOptionsDescription=Geben Sie weitere Exportparameter an!
23
wizardExportAlignmentOptionsTitle=Exportoptionen
24
wizardExportAlignmentExportedSeqHeading=Zu exportierende Sequenzen:
25
wizardExportAlignmentAdditionalOptionsHeading=Erweiterte Exportoptionen:
26
wizardExportAlignmentElongateSeqHeading=Sequenzen auf einheitliche L?nge bringen mit:
27
wizardExportAlignmentElongateSeqMissingData=Fehlende Daten ('?')"
28
wizardExportAlignmentElongateSeqGap=L?cke ('-')
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/Messages.java
14 14

  
15 15

  
16 16
/**
17
 * Messages and texts for the molecular plugin.
17
 * Provides messages and texts for classes of the molecular plugin.
18 18
 *
19 19
 * @author Ben Stöver
20 20
 * @date 17.11.2016
21 21
 */
22 22
public class Messages extends NLS {
23 23
    private static final String BUNDLE_NAME = "OSGI-INF/l10n/messages"; //$NON-NLS-1$
24

  
25

  
24 26
    public static String exportSequenceToFileHandlerIOErrorMessage;
25 27
    public static String exportSequenceToFileHandlerIOErrorTitle;
28
    public static String exportSequenceToFileHandlerOverwriteTitle;
29
    public static String exportSequenceToFileHandlerOverwriteText;
30

  
26 31
    public static String wizardExportAlignmentAppendExtensionButton;
27 32
    public static String wizardExportAlignmentBrowseButton;
28 33
    public static String wizardExportAlignmentDataLabel;
......
36 41
    public static String wizardExportAlignmentExportSingleReads;
37 42
    public static String wizardExportAlignmentFileDialogTitle;
38 43
    public static String wizardExportAlignmentFileLabel;
44
    public static String wizardExportAlignmentOptionsDescription;
45
    public static String wizardExportAlignmentOptionsTitle;
39 46
    public static String wizardExportAlignmentTitle;
40 47
    public static String wizardExportAlignmentWarningFileNameStartsDot;
41 48
    public static String wizardExportAlignmentwarningMissingExtension;
49
    public static String wizardExportAlignmentWarningFileExists;
50
    public static String wizardExportAlignmentExportedSeqHeading;
51
    public static String wizardExportAlignmentAdditionalOptionsHeading;
52
    public static String wizardExportAlignmentElongateSeqHeading;
53
    public static String wizardExportAlignmentElongateSeqMissingData;
54
    public static String wizardExportAlignmentElongateSeqGap;
42 55

  
43 56

  
44 57
    static {
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/handler/ExportSequenceToFileHandler.java
84 84

  
85 85
                // Write document:
86 86
                File file = new File(wizard.getModel().getFileName());
87
                try {
88
                    writer.writeDocument(document, file, parameters);
89
                }
90
                catch (IOException e) {
91
                    e.printStackTrace();
92
                    MessagingUtils.errorDialog(Messages.exportSequenceToFileHandlerIOErrorTitle, this,
93
                            String.format(Messages.exportSequenceToFileHandlerIOErrorMessage,
94
                                    file.getAbsolutePath()), TaxeditorMolecularPlugin.PLUGIN_ID, e, false);
87
                if (!file.exists() || MessagingUtils.confirmDialog(Messages.exportSequenceToFileHandlerOverwriteTitle, String.format(
88
                        Messages.exportSequenceToFileHandlerOverwriteText, file.getAbsolutePath()))) {
89

  
90
                    try {
91
                        writer.writeDocument(document, file, parameters);
92
                    }
93
                    catch (IOException e) {
94
                        e.printStackTrace();
95
                        MessagingUtils.errorDialog(Messages.exportSequenceToFileHandlerIOErrorTitle, this,
96
                                String.format(Messages.exportSequenceToFileHandlerIOErrorMessage,
97
                                        file.getAbsolutePath()), TaxeditorMolecularPlugin.PLUGIN_ID, e, false);
98
                    }
95 99
                }
100

  
96 101
            }
97 102
        }
98 103
        return null;
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentFileFormatPage.java
125 125
            }
126 126
        });
127 127
        FormData fd_btnBrowse = new FormData();
128
        fd_btnBrowse.bottom = new FormAttachment(100, -150);
128
        fd_btnBrowse.bottom = new FormAttachment(fileTextField, 43, SWT.BOTTOM);
129 129
        fd_btnBrowse.top = new FormAttachment(fileTextField, 13);
130 130
        fd_btnBrowse.left = new FormAttachment(100, -128);
131 131
        fd_btnBrowse.right = new FormAttachment(100, -10);
......
134 134

  
135 135
        formatComboBox = new Combo(container, SWT.READ_ONLY);
136 136
        fd_lblSelectTheExport.top = new FormAttachment(formatComboBox, 23);
137
        for (JPhyloIOFormatInfo formatInfo : ExportSingleReadAlignmentWizardModel.FORMAT_NAMES_TO_INFO_MAP.values()) {
137
        for (JPhyloIOFormatInfo formatInfo : ExportSingleReadAlignmentWizardModel.FORMATS) {
138 138
            formatComboBox.add(formatInfo.getFormatName());
139 139
        }
140 140
        FormData fd_formatComboBox = new FormData();
......
142 142
        fd_formatComboBox.left = new FormAttachment(0, 10);
143 143
        fd_formatComboBox.right = new FormAttachment(100, -10);
144 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.)
145
        final ISWTObservableValue formatObservable = SWTObservables.observeSingleSelectionIndex(formatComboBox);  // ViewerProperties.singleSelection().observe(formatComboBox); falls ein ComboViewer verwendet wird. (Dann kann direkt FormatInfo verwendet werden.)
146 146
        dbc.bindValue(formatObservable, getWizard().getModel().getFormatInfoObservable());
147 147
        formatComboBox.select(0);  // Must happen after the component has been bound to the model.
148 148

  
......
155 155
            }
156 156
        });
157 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);
158
        fd_btnNewButton.left = new FormAttachment(btnBrowse, -264, SWT.LEFT);
159
        fd_btnNewButton.bottom = new FormAttachment(fileTextField, 43, SWT.BOTTOM);
161 160
        fd_btnNewButton.right = new FormAttachment(btnBrowse, -6);
161
        fd_btnNewButton.top = new FormAttachment(fileTextField, 13);
162 162
        appendExtensionButton.setLayoutData(fd_btnNewButton);
163 163
        appendExtensionButton.setText(Messages.wizardExportAlignmentAppendExtensionButton);
164 164

  
......
166 166
            @Override
167 167
            protected IStatus validate() {
168 168
                String fileName = (String)fileNameObservable.getValue();
169
                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.)
169 170
                if ((fileName == null) || fileName.isEmpty()) {
170 171
                    return ValidationStatus.error(Messages.wizardExportAlignmentErrorMissingFileName);
171 172
                }
172
                else if (!getSelectedFormat().createFileFilter(TestStrategy.EXTENSION).accept(new File(fileName))) {
173
                else if (!ExportSingleReadAlignmentWizardModel.FORMATS.get(index).createFileFilter(TestStrategy.EXTENSION).accept(
174
                        new File(fileName))) {
175

  
173 176
                    return ValidationStatus.warning(Messages.wizardExportAlignmentwarningMissingExtension);
174 177
                }
175 178
                else if (fileName.charAt(0) == ExtensionFileFilter.EXTENSION_SEPARATOR) {
176 179
                    return ValidationStatus.warning(Messages.wizardExportAlignmentWarningFileNameStartsDot);
177 180
                }
181
                else if (new File(fileName).exists()) {
182
                    return ValidationStatus.warning(Messages.wizardExportAlignmentWarningFileExists);
183
                }
178 184
                else {
179 185
                    return ValidationStatus.ok();
180 186
                }
......
184 190

  
185 191

  
186 192
    private JPhyloIOFormatInfo getSelectedFormat() {
187
        return ExportSingleReadAlignmentWizardModel.FORMAT_NAMES_TO_INFO_MAP.get(formatComboBox.getText());
193
        return ExportSingleReadAlignmentWizardModel.FORMATS.get(formatComboBox.getSelectionIndex());
188 194
    }
189 195
}
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentOptionsPage.java
52 52
     */
53 53
    public ExportSingleReadAlignmentOptionsPage() {
54 54
        super("ExportSingleReadAlignmentOptions");  //TODO Which pageName should be used here? Any conventions? //$NON-NLS-1$
55
        setTitle("Export options");
56
        setDescription("Specify additional export parameters.");
55
        setTitle(Messages.wizardExportAlignmentOptionsTitle);
56
        setDescription(Messages.wizardExportAlignmentOptionsDescription);
57 57
    }
58 58

  
59 59

  
......
110 110
        consensusSequenceLabelTextField.setLayoutData(fd_consensusSequenceNameTextField);
111 111
        final ISWTObservableValue consensusSequenceLabelObservable = SWTObservables.observeText(consensusSequenceLabelTextField, SWT.Modify);
112 112
        dbc.bindValue(consensusSequenceLabelObservable, getWizard().getModel().getConsensusSequenceLabelObservable());
113
        consensusSequenceLabelTextField.setText("Consensus");
113
        consensusSequenceLabelTextField.setText("Consensus"); //$NON-NLS-1$
114 114

  
115 115
        Label lblSpecifyTheSequences = new Label(container, SWT.NONE);
116 116
        FormData fd_lblSpecifyTheSequences = new FormData();
117 117
        fd_lblSpecifyTheSequences.top = new FormAttachment(0, 10);
118 118
        fd_lblSpecifyTheSequences.left = new FormAttachment(0, 10);
119 119
        lblSpecifyTheSequences.setLayoutData(fd_lblSpecifyTheSequences);
120
        lblSpecifyTheSequences.setText("Specify the sequences to be exported:");
120
        lblSpecifyTheSequences.setText(Messages.wizardExportAlignmentExportedSeqHeading);
121 121

  
122 122
        Label lblSpecifyAdditionalExport = new Label(container, SWT.NONE);
123 123
        FormData fd_lblSpecifyAdditionalExport = new FormData();
124 124
        fd_lblSpecifyAdditionalExport.top = new FormAttachment(consensusSequenceLabelTextField, 24);
125 125
        fd_lblSpecifyAdditionalExport.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT);
126 126
        lblSpecifyAdditionalExport.setLayoutData(fd_lblSpecifyAdditionalExport);
127
        lblSpecifyAdditionalExport.setText("Specify additional export options:");
127
        lblSpecifyAdditionalExport.setText(Messages.wizardExportAlignmentAdditionalOptionsHeading);
128 128

  
129 129
        elongateSequecesCheckBox = new Button(container, SWT.CHECK);
130 130
        elongateSequecesCheckBox.addSelectionListener(new SelectionAdapter() {
......
138 138
        fd_btnElongateSequecesTo.left = new FormAttachment(exportSingleReadsCB, 0, SWT.LEFT);
139 139
        fd_btnElongateSequecesTo.top = new FormAttachment(lblSpecifyAdditionalExport, 12);
140 140
        elongateSequecesCheckBox.setLayoutData(fd_btnElongateSequecesTo);
141
        elongateSequecesCheckBox.setText("Elongate sequences to have equal length with:");
141
        elongateSequecesCheckBox.setText(Messages.wizardExportAlignmentElongateSeqHeading);
142 142
        dbc.bindValue(SWTObservables.observeSelection(elongateSequecesCheckBox), getWizard().getModel().getElongateSequencesObservable());
143 143

  
144 144
        missingDataRadioButton = new Button(container, SWT.RADIO);
......
146 146
        fd_missingDataRadioButton.top = new FormAttachment(elongateSequecesCheckBox, 6);
147 147
        missingDataRadioButton.setLayoutData(fd_missingDataRadioButton);
148 148
        missingDataRadioButton.setEnabled(false);
149
        missingDataRadioButton.setText("Missing data ('?')");
149
        missingDataRadioButton.setText(Messages.wizardExportAlignmentElongateSeqMissingData);
150 150

  
151 151
        gapRadioButton = new Button(container, SWT.RADIO);
152 152
        fd_missingDataRadioButton.left = new FormAttachment(gapRadioButton, 80);
......
156 156
        gapRadioButton.setLayoutData(fd_gapRadioButton);
157 157
        gapRadioButton.setEnabled(false);
158 158
        gapRadioButton.setSelection(true);
159
        gapRadioButton.setText("Gap ('-')");
159
        gapRadioButton.setText(Messages.wizardExportAlignmentElongateSeqGap);
160 160
        dbc.bindValue(SWTObservables.observeSelection(gapRadioButton), getWizard().getModel().getUseGapTokenObservable());
161 161

  
162 162
        setPageComplete(true);  // Allow to finish the wizard in the previous page.
eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/io/wizard/ExportSingleReadAlignmentWizardModel.java
14 14
import info.bioinfweb.jphyloio.factory.JPhyloIOReaderWriterFactory;
15 15
import info.bioinfweb.jphyloio.formatinfo.JPhyloIOFormatInfo;
16 16

  
17
import java.util.ArrayList;
17 18
import java.util.Collections;
18
import java.util.Map;
19
import java.util.TreeMap;
19
import java.util.List;
20 20

  
21 21
import org.eclipse.core.databinding.observable.value.IObservableValue;
22 22
import org.eclipse.core.databinding.observable.value.WritableValue;
......
31 31
 */
32 32
public class ExportSingleReadAlignmentWizardModel {
33 33
    protected static final JPhyloIOReaderWriterFactory READER_WRITER_FACTORY = new JPhyloIOReaderWriterFactory();
34
    protected static final Map<String, JPhyloIOFormatInfo> FORMAT_NAMES_TO_INFO_MAP = createFormatInfoList();
34
    protected static final List<JPhyloIOFormatInfo> FORMATS = createFormatInfoList();
35 35

  
36 36

  
37
    private IObservableValue formatInfo = new WritableValue(null, String.class);
37
    private IObservableValue formatInfo = new WritableValue(0, Integer.class);
38 38
    private IObservableValue fileName = new WritableValue(null, String.class);
39 39
    private IObservableValue exportSingleReads = new WritableValue(true, Boolean.class);
40 40
    private IObservableValue exportConsensusSequence = new WritableValue(true, Boolean.class);
......
43 43
    private IObservableValue useGapToken = new WritableValue(true, Boolean.class);
44 44

  
45 45

  
46
    private static Map<String, JPhyloIOFormatInfo> createFormatInfoList() {
47
        Map<String, JPhyloIOFormatInfo> result = new TreeMap<String, JPhyloIOFormatInfo>();
46
    private static List<JPhyloIOFormatInfo> createFormatInfoList() {
47
        List<JPhyloIOFormatInfo> result = new ArrayList<JPhyloIOFormatInfo>();
48 48
        for (String formatID : READER_WRITER_FACTORY.getFormatIDsSet()) {
49 49
            JPhyloIOFormatInfo info = READER_WRITER_FACTORY.getFormatInfo(formatID);
50 50
            if (info.isElementModeled(EventContentType.ALIGNMENT, false)) {  // Check if the current format allows to write alignments.
51
                result.put(info.getFormatName(), info);
51
                result.add(info);
52 52
            }
53 53
        }
54
        return Collections.unmodifiableMap(result);
54
        return Collections.unmodifiableList(result);
55 55
    }
56 56

  
57 57

  
......
66 66
     * @return the format info
67 67
     */
68 68
    public JPhyloIOFormatInfo getFormatInfo() {
69
        return FORMAT_NAMES_TO_INFO_MAP.get(formatInfo.getValue());
69
        return FORMATS.get((Integer)formatInfo.getValue());
70 70
    }
71 71

  
72 72

  
......
133 133
    protected IObservableValue getUseGapTokenObservable() {
134 134
        return useGapToken;
135 135
    }
136

  
137

  
138 136
}

Also available in: Unified diff