Project

General

Profile

Download (2.92 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.molecular.handler;
10

    
11

    
12
import java.io.File;
13
import java.io.IOException;
14

    
15
import org.biojava.bio.chromatogram.UnsupportedChromatogramFormatException;
16
import org.eclipse.core.commands.AbstractHandler;
17
import org.eclipse.core.commands.ExecutionEvent;
18
import org.eclipse.core.commands.ExecutionException;
19
import org.eclipse.swt.widgets.FileDialog;
20

    
21
import eu.etaxonomy.taxeditor.model.AbstractUtility;
22
import eu.etaxonomy.taxeditor.model.MessagingUtils;
23
import eu.etaxonomy.taxeditor.molecular.TaxeditorMolecularPlugin;
24
import eu.etaxonomy.taxeditor.molecular.editor.AlignmentEditor;
25
import eu.etaxonomy.taxeditor.molecular.l10n.Messages;
26

    
27

    
28

    
29
/**
30
 * Handler that loads an additional read into the contig alignment displayed by an instance of {@link AlignmentEditor}.
31
 *
32
 * @author Ben Stöver
33
 * @author pplitzner
34
 */
35
public class LoadPherogramHandler extends AbstractHandler {
36
	//TODO Change so that also URIs which do not point to files can be specified.
37

    
38
    @Override
39
    public Object execute(ExecutionEvent event) throws ExecutionException {
40
        Object activeEditor = AbstractUtility.getActiveE4Editor();
41
        if (activeEditor instanceof AlignmentEditor) {
42
            AlignmentEditor alignmentEditor = (AlignmentEditor)activeEditor;
43

    
44
            FileDialog fileDialog = new FileDialog(alignmentEditor.getSite().getShell());
45
            fileDialog.setText(Messages.LoadPherogramHandler_IMPORT_PHEROGRAM);
46
            fileDialog.setFilterNames(new String[]{Messages.LoadPherogramHandler_ALL_FORMATS, Messages.LoadPherogramHandler_AB1, Messages.LoadPherogramHandler_SCF, Messages.LoadPherogramHandler_ALL});
47
            fileDialog.setFilterExtensions(new String[]{"*.ab1;*.scf", "*.ab1", "*.scf", "*.*"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
48

    
49
            String path = fileDialog.open();
50
            if (path != null) {
51
            	try {
52
            		alignmentEditor.addRead(new File(path).toURI(), false);
53
            	}
54
            	catch (UnsupportedChromatogramFormatException e) {
55
                    MessagingUtils.errorDialog(Messages.LoadPherogramHandler_UNSUPPORTED_FORMAT, this,
56
                            String.format(Messages.LoadPherogramHandler_UNSUPPORTED_FORMAT_MESSAGE, path), TaxeditorMolecularPlugin.PLUGIN_ID, e, false);  //TODO set pluginID
57
            	}
58
            	catch (IOException e) {
59
                    MessagingUtils.errorDialog(Messages.LoadPherogramHandler_UNSUPPORTED_FORMAT_FILE, this,
60
                    		Messages.LoadPherogramHandler_UNSUPPORTED_FORMAT_FILE_MESSAGE + path,
61
                    		TaxeditorMolecularPlugin.PLUGIN_ID, e, false);  //TODO set pluginID
62
            	}
63
            }
64
        }
65
        return null;
66
    }
67
}
(14-14/22)