use of org.csstudio.opibuilder.commands.WidgetCreateCommand 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) {
DropPVRequest dropPVRequest = (DropPVRequest) request;
if (dropPVRequest.getTargetWidget() != null && dropPVRequest.getTargetWidget() instanceof AbstractContainerEditpart) {
WidgetsSelectDialog dialog = new WidgetsSelectDialog(getHost().getViewer().getControl().getShell(), dropPVRequest.getPvNames().length, true);
if (dialog.open() == Window.OK) {
String typeID = dialog.getOutput();
CompoundCommand command = new CompoundCommand("Create Widget");
// $NON-NLS-1$
String[] pvNames = dropPVRequest.getPvNames();
Point location = dropPVRequest.getLocation().getCopy();
AbstractContainerModel container = ((AbstractContainerEditpart) dropPVRequest.getTargetWidget()).getWidgetModel();
AbstractContainerModel parent = container.getParent();
AbstractContainerModel temp = container;
while (parent != null) {
location.translate(temp.getLocation().getNegated());
temp = parent;
parent = parent.getParent();
}
int i = 1;
int lastWidth = 0, lastHeight = 0;
for (String pvName : pvNames) {
AbstractWidgetModel 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;
}
Aggregations