a803a64d6b58b4595eaa22a71dedd0080d63e028
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / handler / LoadPherogramHandler.java
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.editor.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.editor.molecular.AlignmentEditor;
23 import eu.etaxonomy.taxeditor.model.AbstractUtility;
24 import eu.etaxonomy.taxeditor.model.MessagingUtils;
25
26
27
28 /**
29 * Handler that loads an additional read into the contig alignment displayed by an instance of {@link AlignmentEditor}.
30 *
31 * @author Ben Stöver
32 * @author pplitzner
33 */
34 public class LoadPherogramHandler extends AbstractHandler {
35 //TODO Change so that also URIs which do not point to files can be specified.
36
37 /* (non-Javadoc)
38 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
39 */
40 @Override
41 public Object execute(ExecutionEvent event) throws ExecutionException {
42 IEditorPart activeEditor = AbstractUtility.getActiveEditor();
43 if (activeEditor instanceof AlignmentEditor) {
44 AlignmentEditor alignmentEditor = (AlignmentEditor)activeEditor;
45
46 FileDialog fileDialog = new FileDialog(alignmentEditor.getSite().getShell());
47 fileDialog.setText("Import pherogram into contig alignment");
48 fileDialog.setFilterNames(new String[]{"All supported formats", "AB1 pherogram files", "SCF pherogram files", "All files"});
49 fileDialog.setFilterExtensions(new String[]{"*.ab1;*.scf", "*.ab1", "*.scf", "*.*"});
50
51 String path = fileDialog.open();
52 if (path != null) {
53 try {
54 alignmentEditor.addRead(new File(path).toURI(), false);
55 }
56 catch (UnsupportedChromatogramFormatException e) {
57 MessagingUtils.errorDialog("Unsupported format", this, "The format of the pherogram file \"" + path +
58 "\" is not supported. (Only AB1 and SCF are supported.)", "eu.etaxonomy.taxeditor.editor", e, false); //TODO set pluginID
59 }
60 catch (IOException e) {
61 MessagingUtils.errorDialog("Unsupported format", this,
62 "An IO error occurred while trying to read the file \"" + path + "\".",
63 "/eu.etaxonomy.taxeditor.editor", e, false); //TODO set pluginID
64 }
65 }
66 }
67 return null;
68 }
69 }