Project

General

Profile

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

    
3

    
4
import java.net.URI;
5

    
6
import javax.inject.Named;
7

    
8
import org.eclipse.e4.core.di.annotations.Execute;
9
import org.eclipse.e4.core.di.annotations.Optional;
10
import org.eclipse.e4.ui.services.IServiceConstants;
11
import org.eclipse.jface.viewers.TreeNode;
12
import org.eclipse.ui.PartInitException;
13

    
14
import eu.etaxonomy.cdm.model.media.MediaUtils;
15
import eu.etaxonomy.cdm.model.molecular.SingleRead;
16
import eu.etaxonomy.taxeditor.model.MessagingUtils;
17
import eu.etaxonomy.taxeditor.molecular.TaxeditorMolecularPlugin;
18
import eu.etaxonomy.taxeditor.molecular.editor.AlignmentEditor;
19
import eu.etaxonomy.taxeditor.molecular.editor.PherogramViewPart;
20
import eu.etaxonomy.taxeditor.molecular.l10n.Messages;
21
import info.bioinfweb.libralign.pherogram.model.PherogramComponentModel;
22

    
23

    
24

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

    
35

    
36
	@Execute
37
	public Object execute(@Optional@Named(IServiceConstants.ACTIVE_SELECTION)TreeNode treeNodeOfSelection) {
38
		if (treeNodeOfSelection != null && treeNodeOfSelection.getValue() instanceof SingleRead) {
39
		    //TODO Can the parent node (containing the cut positions) be extracted from SingleRead?
40
			try {
41
			    SingleRead singleRead = (SingleRead)treeNodeOfSelection.getValue();
42
			    URI uri = null;
43
			    if (singleRead.getPherogram() != null) {  // Pherogram objects without URI are possible.
44
			        uri = MediaUtils.getFirstMediaRepresentationPart(singleRead.getPherogram()).getUri();
45
			    }
46

    
47
			    if (uri == null) {
48
	                MessagingUtils.messageDialog(Messages.ShowPherogramHandler_NO_PHEROGRAM, this,
49
	                        Messages.ShowPherogramHandler_NO_PHEROGRAM_MESSAGE);
50
			    }
51
			    else {
52
	              showPherogram(new PherogramComponentModel(AlignmentEditor.readPherogram(uri)));
53
			    }
54
			}
55
	        catch (Exception e) {
56
	            MessagingUtils.errorDialog(Messages.ShowPherogramHandler_ERROR, null, e.getLocalizedMessage(), TaxeditorMolecularPlugin.PLUGIN_ID,
57
	                    e, false);
58
	        }
59
        }
60
        return null;
61
    }
62
}
(16-16/22)