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
|
*/
|
32
|
public class ShowPherogramHandler extends AbstractHandler {
|
33
|
public static void showPherogram(PherogramComponentModel model) throws PartInitException {
|
34
|
PherogramViewPart.createView(model);
|
35
|
}
|
36
|
|
37
|
|
38
|
@Override
|
39
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
40
|
ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
|
41
|
TreeNode treeNodeOfSelection = EditorUtil.getTreeNodeOfSelection(currentSelection);
|
42
|
if (treeNodeOfSelection != null && treeNodeOfSelection.getValue() instanceof SingleRead) {
|
43
|
//TODO Can the parent node (containing the cut positions) be extracted from SingleRead?
|
44
|
try {
|
45
|
SingleRead singleRead = (SingleRead)treeNodeOfSelection.getValue();
|
46
|
URI uri = null;
|
47
|
if (singleRead.getPherogram() != null) { // Pherogram objects without URI are possible.
|
48
|
uri = MediaUtils.getFirstMediaRepresentationPart(singleRead.getPherogram()).getUri();
|
49
|
}
|
50
|
|
51
|
if (uri == null) {
|
52
|
MessagingUtils.messageDialog("No pherogram available", this,
|
53
|
"The selected read does not have an associated pherogram.");
|
54
|
}
|
55
|
else {
|
56
|
showPherogram(new PherogramComponentModel(AlignmentEditor.readPherogram(uri)));
|
57
|
}
|
58
|
}
|
59
|
catch (Exception e) {
|
60
|
MessagingUtils.errorDialog("Error", null, e.getLocalizedMessage(), TaxeditorMolecularPlugin.PLUGIN_ID,
|
61
|
e, false);
|
62
|
}
|
63
|
}
|
64
|
return null;
|
65
|
}
|
66
|
}
|