Project

General

Profile

Download (2.49 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.Messages;
21
import eu.etaxonomy.taxeditor.molecular.TaxeditorMolecularPlugin;
22
import eu.etaxonomy.taxeditor.molecular.editor.AlignmentEditor;
23
import eu.etaxonomy.taxeditor.molecular.editor.PherogramViewPart;
24

    
25

    
26

    
27
/**
28
 * Displays an undistorted pherogram with {@link PherogramViewPart}.
29
 *
30
 * @author Ben Stöver
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(Messages.ShowPherogramHandler_NO_PHEROGRAM, this,
53
	                        Messages.ShowPherogramHandler_NO_PHEROGRAM_MESSAGE);
54
			    }
55
			    else {
56
	              showPherogram(new PherogramComponentModel(AlignmentEditor.readPherogram(uri)));
57
			    }
58
			}
59
	        catch (Exception e) {
60
	            MessagingUtils.errorDialog(Messages.ShowPherogramHandler_ERROR, null, e.getLocalizedMessage(), TaxeditorMolecularPlugin.PLUGIN_ID,
61
	                    e, false);
62
	        }
63
        }
64
        return null;
65
    }
66
}
(16-16/22)