Project

General

Profile

Download (2.41 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.molecular.handler;
2

    
3

    
4
import info.bioinfweb.libralign.pherogram.model.PherogramComponentModel;
5

    
6
import java.net.URI;
7

    
8
import org.eclipse.core.commands.AbstractHandler;
9
import org.eclipse.core.commands.ExecutionEvent;
10
import org.eclipse.core.commands.ExecutionException;
11
import org.eclipse.jface.viewers.ISelection;
12
import org.eclipse.jface.viewers.TreeNode;
13
import org.eclipse.ui.PartInitException;
14
import org.eclipse.ui.handlers.HandlerUtil;
15

    
16
import eu.etaxonomy.cdm.model.media.MediaUtils;
17
import eu.etaxonomy.cdm.model.molecular.SingleRead;
18
import eu.etaxonomy.taxeditor.editor.EditorUtil;
19
import eu.etaxonomy.taxeditor.model.MessagingUtils;
20
import eu.etaxonomy.taxeditor.molecular.TaxeditorMolecularPlugin;
21
import eu.etaxonomy.taxeditor.molecular.editor.AlignmentEditor;
22
import eu.etaxonomy.taxeditor.molecular.editor.PherogramViewPart;
23

    
24

    
25

    
26
/**
27
 * Displays an undistorted pherogram with {@link PherogramViewPart}.
28
 *
29
 * @author Ben Stöver
30
 */
31
public class ShowPherogramHandler extends AbstractHandler {
32
	public static void showPherogram(PherogramComponentModel model) throws PartInitException {
33
		PherogramViewPart.createView(model);
34
	}
35

    
36

    
37
	@Override
38
	public Object execute(ExecutionEvent event) throws ExecutionException {
39
		ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
40
		TreeNode treeNodeOfSelection = EditorUtil.getTreeNodeOfSelection(currentSelection);
41
		if (treeNodeOfSelection != null && treeNodeOfSelection.getValue() instanceof SingleRead) {
42
		    //TODO Can the parent node (containing the cut positions) be extracted from SingleRead?
43
			try {
44
			    SingleRead singleRead = (SingleRead)treeNodeOfSelection.getValue();
45
			    URI uri = null;
46
			    if (singleRead.getPherogram() != null) {  // Pherogram objects without URI are possible.
47
			        uri = MediaUtils.getFirstMediaRepresentationPart(singleRead.getPherogram()).getUri();
48
			    }
49

    
50
			    if (uri == null) {
51
	                MessagingUtils.messageDialog("No pherogram available", this,
52
	                        "The selected read does not have an associated pherogram.");
53
			    }
54
			    else {
55
	              showPherogram(new PherogramComponentModel(AlignmentEditor.readPherogram(uri)));
56
			    }
57
			}
58
	        catch (Exception e) {
59
	            MessagingUtils.errorDialog("Error", null, e.getLocalizedMessage(), TaxeditorMolecularPlugin.PLUGIN_ID,
60
	                    e, false);
61
	        }
62
        }
63
        return null;
64
    }
65
}
(16-16/22)