Project

General

Profile

« Previous | Next » 

Revision dcf7fd09

Added by Patrick Plitzner almost 6 years ago

ref #7010 Adapt molecular handlers for multiple selection

View differences:

eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/editor/e4/handler/ShowPherogramHandlerE4.java
13 13
import org.eclipse.e4.ui.services.IServiceConstants;
14 14
import org.eclipse.e4.ui.workbench.modeling.EPartService;
15 15
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
16
import org.eclipse.jface.viewers.IStructuredSelection;
16 17
import org.eclipse.jface.viewers.TreeNode;
17 18

  
18 19
import eu.etaxonomy.cdm.model.media.MediaUtils;
......
33 34
 */
34 35
public class ShowPherogramHandlerE4 {
35 36

  
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
			    }
37
    @Execute
38
    public void execute(@Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
39
            EPartService partService) {
40
        //TODO Can the parent node (containing the cut positions) be extracted from SingleRead?
41
        try {
42
            SingleRead singleRead = (SingleRead) ((TreeNode) selection.getFirstElement()).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 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
	        }
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);
63 62
        }
64
        return null;
65 63
    }
66 64

  
67 65
    @CanExecute
68
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode selectedTreeNode, MHandledMenuItem menuItem) {
66
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, MHandledMenuItem menuItem) {
69 67
        boolean canExecute = false;
70
        if(selectedTreeNode!=null){
71
            Object value = selectedTreeNode.getValue();
72
            canExecute = value instanceof SingleRead;
73
        }
68
        canExecute = selection.size()==1
69
                && selection.getFirstElement() instanceof TreeNode
70
                && ((TreeNode) selection.getFirstElement()).getValue() instanceof SingleRead;
74 71
        menuItem.setVisible(canExecute);
75 72
        return canExecute;
76 73
    }

Also available in: Unified diff