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.AlignmentEditor;
|
23
|
import eu.etaxonomy.taxeditor.molecular.editor.PherogramViewPart;
|
24
|
import eu.etaxonomy.taxeditor.molecular.editor.e4.PherogramPartE4;
|
25
|
import eu.etaxonomy.taxeditor.molecular.l10n.Messages;
|
26
|
import info.bioinfweb.libralign.pherogram.model.PherogramComponentModel;
|
27
|
|
28
|
|
29
|
|
30
|
/**
|
31
|
* Displays an undistorted pherogram with {@link PherogramViewPart}.
|
32
|
*
|
33
|
* @author Ben Stöver
|
34
|
*/
|
35
|
public class ShowPherogramHandlerE4 {
|
36
|
|
37
|
@Execute
|
38
|
public Object execute(@Optional@Named(IServiceConstants.ACTIVE_SELECTION)TreeNode treeNodeOfSelection,
|
39
|
EPartService partService) {
|
40
|
if (treeNodeOfSelection != null && treeNodeOfSelection.getValue() instanceof SingleRead) {
|
41
|
//TODO Can the parent node (containing the cut positions) be extracted from SingleRead?
|
42
|
try {
|
43
|
SingleRead singleRead = (SingleRead)treeNodeOfSelection.getValue();
|
44
|
URI uri = null;
|
45
|
if (singleRead.getPherogram() != null) { // Pherogram objects without URI are possible.
|
46
|
uri = MediaUtils.getFirstMediaRepresentationPart(singleRead.getPherogram()).getUri();
|
47
|
}
|
48
|
|
49
|
if (uri == null) {
|
50
|
MessagingUtils.messageDialog(Messages.ShowPherogramHandler_NO_PHEROGRAM, this,
|
51
|
Messages.ShowPherogramHandler_NO_PHEROGRAM_MESSAGE);
|
52
|
}
|
53
|
else {
|
54
|
MPart part = partService.createPart(eu.etaxonomy.taxeditor.molecular.AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_MOLECULAR_EDITOR_E4_PHEROGRAMPARTE4);
|
55
|
part = partService.showPart(part, PartState.ACTIVATE);
|
56
|
PherogramPartE4 pherogramPart = (PherogramPartE4) part.getObject();
|
57
|
pherogramPart.init(new PherogramComponentModel(AlignmentEditor.readPherogram(uri)));
|
58
|
}
|
59
|
}
|
60
|
catch (Exception e) {
|
61
|
MessagingUtils.errorDialog(Messages.ShowPherogramHandler_ERROR, null, e.getLocalizedMessage(), TaxeditorMolecularPlugin.PLUGIN_ID,
|
62
|
e, false);
|
63
|
}
|
64
|
}
|
65
|
return null;
|
66
|
}
|
67
|
|
68
|
@CanExecute
|
69
|
public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode selectedTreeNode, MHandledMenuItem menuItem) {
|
70
|
boolean canExecute = false;
|
71
|
if(selectedTreeNode!=null){
|
72
|
Object value = selectedTreeNode.getValue();
|
73
|
canExecute = value instanceof SingleRead;
|
74
|
}
|
75
|
menuItem.setVisible(canExecute);
|
76
|
return canExecute;
|
77
|
}
|
78
|
}
|