package org.simantics.charts.editor.e4; import java.util.List; import javax.inject.Named; import org.eclipse.e4.core.di.annotations.CanExecute; import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.e4.ui.di.AboutToHide; import org.eclipse.e4.ui.di.AboutToShow; import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem; import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory; import org.eclipse.e4.ui.services.IServiceConstants; import org.simantics.charts.editor.TrackExperimentTimeAction; import org.simantics.trend.configuration.TrendSpec; import org.simantics.trend.impl.ItemNode; import org.simantics.trend.impl.TrendNode; import org.simantics.trend.impl.TrendParticipant; public class MoveHairlineHandler { @AboutToShow public void aboutToShow(List items) { MDirectMenuItem menuItem = MMenuFactory.INSTANCE.createDirectMenuItem(); menuItem.setContributionURI("bundleclass://org.simantics.charts/org.simantics.charts.editor.e4.MoveHairlineHandler"); menuItem.setLabel("Move Hairline Here"); items.add(menuItem); } @AboutToHide public void aboutToHide() { } @CanExecute public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart) { if (activePart != null && activePart.getObject() instanceof TimeSeriesEditor) { TimeSeriesEditor editor = (TimeSeriesEditor) activePart.getObject(); TrendNode trendNode = editor.trendNode; TrendParticipant tp = editor.tp; if (trendNode == null || tp == null) return false; TrendSpec trendSpec = trendNode.getTrendSpec(); boolean hairlineMovementAllowed = !(trendSpec.experimentIsRunning && trendSpec.viewProfile.trackExperimentTime); return hairlineMovementAllowed; } return false; } @Execute public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart) { if (activePart.getObject() instanceof TimeSeriesEditor) { TimeSeriesEditor editor = (TimeSeriesEditor) activePart.getObject(); TrendNode trendNode = editor.trendNode; TrendParticipant tp = editor.tp; if (trendNode == null || tp == null) return; TrendSpec trendSpec = trendNode.getTrendSpec(); ItemNode hoverItem = tp.hoveringItem; // #TODO Finish this when we are fully in E4 workbench // trend.valueTipTime = time; // trend.repaint(); // if (setTrackExperimentTime != null) { // TrackExperimentTimeAction.setTracking(chart, setTrackExperimentTime); // } } } }