Search in sources :

Example 1 with WidgetsSelectDialog

use of org.csstudio.opibuilder.visualparts.WidgetsSelectDialog in project yamcs-studio by yamcs.

the class ReplaceWidgetsAction method run.

@Override
public void run() {
    WidgetsSelectDialog dialog = new WidgetsSelectDialog(getWorkbenchPart().getSite().getShell(), 1, false);
    // $NON-NLS-1$
    dialog.setDefaultSelectedWidgetID("org.csstudio.opibuilder.widgets.NativeText");
    if (dialog.open() == Window.OK) {
        String typeID = dialog.getOutput();
        execute(createReplaceWidgetCommand(typeID));
    }
}
Also used : WidgetsSelectDialog(org.csstudio.opibuilder.visualparts.WidgetsSelectDialog)

Example 2 with WidgetsSelectDialog

use of org.csstudio.opibuilder.visualparts.WidgetsSelectDialog in project yamcs-studio by yamcs.

the class DropPVtoContainerEditPolicy method getCommand.

@Override
public Command getCommand(Request request) {
    if (request.getType() == DropPVRequest.REQ_DROP_PV && request instanceof DropPVRequest) {
        var dropPVRequest = (DropPVRequest) request;
        if (dropPVRequest.getTargetWidget() != null && dropPVRequest.getTargetWidget() instanceof AbstractContainerEditpart) {
            var dialog = new WidgetsSelectDialog(getHost().getViewer().getControl().getShell(), dropPVRequest.getPvNames().length, true);
            if (dialog.open() == Window.OK) {
                var typeID = dialog.getOutput();
                var command = new CompoundCommand("Create Widget");
                var pvNames = dropPVRequest.getPvNames();
                var location = dropPVRequest.getLocation().getCopy();
                var container = ((AbstractContainerEditpart) dropPVRequest.getTargetWidget()).getWidgetModel();
                var parent = container.getParent();
                var temp = container;
                while (parent != null) {
                    location.translate(temp.getLocation().getNegated());
                    temp = parent;
                    parent = parent.getParent();
                }
                var i = 1;
                int lastWidth = 0, lastHeight = 0;
                for (var pvName : pvNames) {
                    var widgetModel = WidgetsService.getInstance().getWidgetDescriptor(typeID).getWidgetModel();
                    command.add(new WidgetCreateCommand(widgetModel, container, new Rectangle(location.getCopy().translate(lastWidth, lastHeight), new Dimension(-1, -1)), i != 1, true));
                    command.add(new SetWidgetPropertyCommand(widgetModel, AbstractPVWidgetModel.PROP_PVNAME, pvName.trim()));
                    if (i % WIDGETS_ACCOUNT_ON_A_ROW == 0) {
                        lastWidth = 0;
                        lastHeight += widgetModel.getHeight();
                    } else {
                        lastWidth += widgetModel.getWidth();
                    }
                    i++;
                }
                return command;
            }
        }
    }
    return null;
}
Also used : SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AbstractContainerEditpart(org.csstudio.opibuilder.editparts.AbstractContainerEditpart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) WidgetsSelectDialog(org.csstudio.opibuilder.visualparts.WidgetsSelectDialog) Dimension(org.eclipse.draw2d.geometry.Dimension) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) WidgetCreateCommand(org.csstudio.opibuilder.commands.WidgetCreateCommand)

Aggregations

WidgetsSelectDialog (org.csstudio.opibuilder.visualparts.WidgetsSelectDialog)2 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)1 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)1 AbstractContainerEditpart (org.csstudio.opibuilder.editparts.AbstractContainerEditpart)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1