Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / editor / e4 / MoveHairlineHandler.java
1 package org.simantics.charts.editor.e4;\r
2 \r
3 import java.util.List;\r
4 \r
5 import javax.inject.Named;\r
6 \r
7 import org.eclipse.e4.core.di.annotations.CanExecute;\r
8 import org.eclipse.e4.core.di.annotations.Execute;\r
9 import org.eclipse.e4.ui.di.AboutToHide;\r
10 import org.eclipse.e4.ui.di.AboutToShow;\r
11 import org.eclipse.e4.ui.model.application.ui.basic.MPart;\r
12 import org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem;\r
13 import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;\r
14 import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;\r
15 import org.eclipse.e4.ui.services.IServiceConstants;\r
16 import org.simantics.charts.editor.TrackExperimentTimeAction;\r
17 import org.simantics.trend.configuration.TrendSpec;\r
18 import org.simantics.trend.impl.ItemNode;\r
19 import org.simantics.trend.impl.TrendNode;\r
20 import org.simantics.trend.impl.TrendParticipant;\r
21 \r
22 public class MoveHairlineHandler {\r
23 \r
24     @AboutToShow\r
25     public void aboutToShow(List<MMenuElement> items) {\r
26         MDirectMenuItem menuItem = MMenuFactory.INSTANCE.createDirectMenuItem();\r
27         menuItem.setContributionURI("bundleclass://org.simantics.charts/org.simantics.charts.editor.e4.MoveHairlineHandler");\r
28         menuItem.setLabel("Move Hairline Here");\r
29         items.add(menuItem);\r
30     }\r
31     \r
32     @AboutToHide\r
33     public void aboutToHide() {\r
34         \r
35     }\r
36     \r
37     @CanExecute\r
38     public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart) {\r
39         if (activePart != null && activePart.getObject() instanceof TimeSeriesEditor) {\r
40             TimeSeriesEditor editor = (TimeSeriesEditor) activePart.getObject();\r
41             \r
42             TrendNode trendNode = editor.trendNode;\r
43             TrendParticipant tp = editor.tp;\r
44             if (trendNode == null || tp == null)\r
45                 return false;\r
46             \r
47             TrendSpec trendSpec = trendNode.getTrendSpec();\r
48             boolean hairlineMovementAllowed =\r
49                     !(trendSpec.experimentIsRunning &&\r
50                       trendSpec.viewProfile.trackExperimentTime);\r
51             \r
52             return hairlineMovementAllowed;\r
53         }\r
54         return false;\r
55     }\r
56     \r
57     @Execute\r
58     public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart) {\r
59         if (activePart.getObject() instanceof TimeSeriesEditor) {\r
60             TimeSeriesEditor editor = (TimeSeriesEditor) activePart.getObject();\r
61             \r
62             TrendNode trendNode = editor.trendNode;\r
63             TrendParticipant tp = editor.tp;\r
64             if (trendNode == null || tp == null)\r
65                 return;\r
66 \r
67             TrendSpec trendSpec = trendNode.getTrendSpec();\r
68             ItemNode hoverItem = tp.hoveringItem;\r
69             \r
70             // #TODO Finish this when we are fully in E4 workbench\r
71             \r
72 //            trend.valueTipTime = time;\r
73 //            trend.repaint();\r
74 //            if (setTrackExperimentTime != null) {\r
75 //                TrackExperimentTimeAction.setTracking(chart, setTrackExperimentTime);\r
76 //            }\r
77             \r
78         }\r
79     }\r
80 \r
81 }\r