Project

General

Profile

Download (2.87 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
import org.eclipse.ui.IEditorPart;
21

    
22
import eu.etaxonomy.taxeditor.model.AbstractUtility;
23
import eu.etaxonomy.taxeditor.model.MessagingUtils;
24
import eu.etaxonomy.taxeditor.molecular.TaxeditorMolecularPlugin;
25
import eu.etaxonomy.taxeditor.molecular.editor.AlignmentEditor;
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
	/* (non-Javadoc)
39
     * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
40
     */
41
    @Override
42
    public Object execute(ExecutionEvent event) throws ExecutionException {
43
        IEditorPart activeEditor = AbstractUtility.getActiveEditor();
44
        if (activeEditor instanceof AlignmentEditor) {
45
            AlignmentEditor alignmentEditor = (AlignmentEditor)activeEditor;
46

    
47
            FileDialog fileDialog = new FileDialog(alignmentEditor.getSite().getShell());
48
            fileDialog.setText("Import pherogram into contig alignment");
49
            fileDialog.setFilterNames(new String[]{"All supported formats", "AB1 pherogram files", "SCF pherogram files", "All files"});
50
            fileDialog.setFilterExtensions(new String[]{"*.ab1;*.scf", "*.ab1", "*.scf", "*.*"});
51

    
52
            String path = fileDialog.open();
53
            if (path != null) {
54
            	try {
55
            		alignmentEditor.addRead(new File(path).toURI(), false);
56
            	}
57
            	catch (UnsupportedChromatogramFormatException e) {
58
                    MessagingUtils.errorDialog("Unsupported format", this, "The format of the pherogram file \"" + path +
59
                    		"\" is not supported. (Only AB1 and SCF are supported.)", TaxeditorMolecularPlugin.PLUGIN_ID, e, false);  //TODO set pluginID
60
            	}
61
            	catch (IOException e) {
62
                    MessagingUtils.errorDialog("Unsupported format", this,
63
                    		"An IO error occurred while trying to read the file \"" + path + "\".",
64
                    		TaxeditorMolecularPlugin.PLUGIN_ID, e, false);  //TODO set pluginID
65
            	}
66
            }
67
        }
68
        return null;
69
    }
70
}
(9-9/18)