Project

General

Profile

Download (2.88 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.editor.e4.handler;
10

    
11

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

    
15
import javax.inject.Named;
16

    
17
import org.biojava.bio.chromatogram.UnsupportedChromatogramFormatException;
18
import org.eclipse.e4.core.di.annotations.Execute;
19
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
20
import org.eclipse.e4.ui.services.IServiceConstants;
21
import org.eclipse.swt.widgets.FileDialog;
22
import org.eclipse.swt.widgets.Shell;
23

    
24
import eu.etaxonomy.cdm.common.URI;
25
import eu.etaxonomy.taxeditor.model.MessagingUtils;
26
import eu.etaxonomy.taxeditor.molecular.TaxeditorMolecularPlugin;
27
import eu.etaxonomy.taxeditor.molecular.editor.e4.AlignmentEditorE4;
28
import eu.etaxonomy.taxeditor.molecular.l10n.Messages;
29

    
30

    
31

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

    
41
    @Execute
42
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
43
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
44
        AlignmentEditorE4 alignmentEditor = (AlignmentEditorE4) activePart.getObject();
45

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

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