Project

General

Profile

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

    
3

    
4
import java.net.URI;
5

    
6
import javax.inject.Named;
7

    
8
import org.eclipse.e4.core.di.annotations.CanExecute;
9
import org.eclipse.e4.core.di.annotations.Execute;
10
import org.eclipse.e4.core.di.annotations.Optional;
11
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
12
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
13
import org.eclipse.e4.ui.services.IServiceConstants;
14
import org.eclipse.e4.ui.workbench.modeling.EPartService;
15
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
16
import org.eclipse.jface.viewers.TreeNode;
17

    
18
import eu.etaxonomy.cdm.model.media.MediaUtils;
19
import eu.etaxonomy.cdm.model.molecular.SingleRead;
20
import eu.etaxonomy.taxeditor.model.MessagingUtils;
21
import eu.etaxonomy.taxeditor.molecular.TaxeditorMolecularPlugin;
22
import eu.etaxonomy.taxeditor.molecular.editor.e4.AlignmentEditorE4;
23
import eu.etaxonomy.taxeditor.molecular.editor.e4.PherogramPartE4;
24
import eu.etaxonomy.taxeditor.molecular.l10n.Messages;
25
import info.bioinfweb.libralign.pherogram.model.PherogramComponentModel;
26

    
27

    
28

    
29
/**
30
 * Displays an undistorted pherogram with {@link PherogramPartE4}.
31
 *
32
 * @author Ben Stöver
33
 */
34
public class ShowPherogramHandlerE4 {
35

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

    
48
			    if (uri == null) {
49
	                MessagingUtils.messageDialog(Messages.ShowPherogramHandler_NO_PHEROGRAM, this,
50
	                        Messages.ShowPherogramHandler_NO_PHEROGRAM_MESSAGE);
51
			    }
52
			    else {
53
			        MPart part = partService.createPart(eu.etaxonomy.taxeditor.molecular.AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_MOLECULAR_EDITOR_E4_PHEROGRAMPARTE4);
54
			        part = partService.showPart(part, PartState.ACTIVATE);
55
			        PherogramPartE4 pherogramPart = (PherogramPartE4) part.getObject();
56
			        pherogramPart.init(new PherogramComponentModel(AlignmentEditorE4.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

    
67
    @CanExecute
68
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode selectedTreeNode, MHandledMenuItem menuItem) {
69
        boolean canExecute = false;
70
        if(selectedTreeNode!=null){
71
            Object value = selectedTreeNode.getValue();
72
            canExecute = value instanceof SingleRead;
73
        }
74
        menuItem.setVisible(canExecute);
75
        return canExecute;
76
    }
77
}
(12-12/17)