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