Search in sources :

Example 1 with DropPVRequest

use of org.csstudio.opibuilder.dnd.DropPVRequest in project yamcs-studio by yamcs.

the class DropPVtoXYGraphEditPolicy method getCommand.

@Override
public Command getCommand(Request request) {
    if (request.getType() == DropPVRequest.REQ_DROP_PV && request instanceof DropPVRequest) {
        DropPVRequest dropPVRequest = (DropPVRequest) request;
        if (dropPVRequest.getTargetWidget() != null && dropPVRequest.getTargetWidget() instanceof XYGraphEditPart) {
            CompoundCommand command = new CompoundCommand("Add Traces");
            XYGraphModel xyGraphModel = (XYGraphModel) dropPVRequest.getTargetWidget().getWidgetModel();
            int existTraces = xyGraphModel.getTracesAmount();
            if (existTraces >= XYGraphModel.MAX_TRACES_AMOUNT)
                return null;
            command.add(new SetWidgetPropertyCommand(xyGraphModel, XYGraphModel.PROP_TRACE_COUNT, dropPVRequest.getPvNames().length + existTraces));
            int i = existTraces;
            for (String pvName : dropPVRequest.getPvNames()) {
                command.add(new SetWidgetPropertyCommand(xyGraphModel, XYGraphModel.makeTracePropID(XYGraphModel.TraceProperty.YPV.propIDPre, i), pvName));
                command.add(new SetWidgetPropertyCommand(xyGraphModel, XYGraphModel.makeTracePropID(XYGraphModel.TraceProperty.NAME.propIDPre, i), pvName));
                if (++i >= XYGraphModel.MAX_TRACES_AMOUNT)
                    break;
            }
            return command;
        }
    }
    return super.getCommand(request);
}
Also used : SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) XYGraphModel(org.csstudio.opibuilder.widgets.model.XYGraphModel) DropPVRequest(org.csstudio.opibuilder.dnd.DropPVRequest) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Aggregations

SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)1 DropPVRequest (org.csstudio.opibuilder.dnd.DropPVRequest)1 XYGraphModel (org.csstudio.opibuilder.widgets.model.XYGraphModel)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1