Project

General

Profile

Download (3.08 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
import eu.etaxonomy.taxeditor.molecular.l10n.Messages;
27

    
28

    
29

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

    
39
	/* (non-Javadoc)
40
     * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
41
     */
42
    @Override
43
    public Object execute(ExecutionEvent event) throws ExecutionException {
44
        IEditorPart activeEditor = AbstractUtility.getActiveEditor();
45
        if (activeEditor instanceof AlignmentEditor) {
46
            AlignmentEditor alignmentEditor = (AlignmentEditor)activeEditor;
47

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

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