use of org.eclipse.gef.commands.CompoundCommand in project yamcs-studio by yamcs.
the class WidgetXYLayoutEditPolicy method createAddCommand.
@SuppressWarnings("deprecation")
@Override
protected Command createAddCommand(EditPart child, Object constraint) {
if (!(child instanceof AbstractBaseEditPart) || !(constraint instanceof Rectangle)) {
return super.createAddCommand(child, constraint);
}
var container = (AbstractContainerModel) getHost().getModel();
var widget = (AbstractWidgetModel) child.getModel();
var result = new CompoundCommand("Adding widgets to container");
result.add(new AddWidgetCommand(container, widget, (Rectangle) constraint));
return result;
}
use of org.eclipse.gef.commands.CompoundCommand 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;
}
use of org.eclipse.gef.commands.CompoundCommand in project yamcs-studio by yamcs.
the class CloneCommand method execute.
@Override
public void execute() {
var clipboard = new Clipboard(Display.getCurrent());
var tempModel = new DisplayModel();
for (var widget : _models) {
tempModel.addChild(widget, false);
}
var xml = XMLUtil.widgetToXMLString(tempModel, false);
clipboard.setContents(new Object[] { xml }, new Transfer[] { OPIWidgetsTransfer.getInstance() });
_clonedWidgets = getWidgetsFromClipboard();
_compoundCommand = new CompoundCommand();
var i = 0;
for (var widgetModel : _clonedWidgets) {
if (_difference != null) {
widgetModel.setLocation((widgetModel.getLocation().x + _difference.width), (widgetModel.getLocation().y + _difference.height));
} else {
widgetModel.setLocation((widgetModel.getLocation().x + 10), (widgetModel.getLocation().y + 10));
}
_compoundCommand.add(new WidgetCreateCommand(widgetModel, _parent, new Rectangle(widgetModel.getLocation(), widgetModel.getSize()), (i++ == 0 ? false : true)));
if (_hGuide != null) {
var hGuideCommand = new ChangeGuideCommand(widgetModel, true);
hGuideCommand.setNewGuide(_hGuide, _hAlignment);
_compoundCommand.add(hGuideCommand);
}
if (_vGuide != null) {
var vGuideCommand = new ChangeGuideCommand(widgetModel, false);
vGuideCommand.setNewGuide(_vGuide, _vAlignment);
_compoundCommand.add(vGuideCommand);
}
}
_compoundCommand.execute();
}
use of org.eclipse.gef.commands.CompoundCommand in project yamcs-studio by yamcs.
the class ChangeOrderAction method run.
@Override
public void run() {
Map<AbstractContainerModel, List<IndexedWidget>> widgetMap = new HashMap<>();
fillWidgetMap(widgetMap);
var compoundCommand = new CompoundCommand(orderType.getLabel());
// create compound command
for (var entry : widgetMap.entrySet()) {
// sort the list in map by the widget's original order in its container
var container = entry.getKey();
var widgetList = entry.getValue();
Collections.sort(widgetList);
int newIndex;
switch(orderType) {
case TO_FRONT:
newIndex = container.getChildren().size() - 1;
break;
case STEP_FRONT:
newIndex = widgetList.get(widgetList.size() - 1).getIndex() + 1;
break;
case STEP_BACK:
newIndex = widgetList.get(0).getIndex() - 1;
break;
case TO_BACK:
default:
newIndex = 0;
break;
}
// reorder
switch(orderType) {
case TO_FRONT:
case STEP_FRONT:
for (var indexedWidget : widgetList) {
compoundCommand.add(new ChangeOrderCommand(newIndex, container, indexedWidget.getWidget()));
}
break;
case STEP_BACK:
case TO_BACK:
for (var i = widgetList.size() - 1; i >= 0; i--) {
compoundCommand.add(new ChangeOrderCommand(newIndex, container, widgetList.get(i).getWidget()));
}
break;
default:
break;
}
}
execute(compoundCommand);
}
use of org.eclipse.gef.commands.CompoundCommand in project yamcs-studio by yamcs.
the class ChangeOrientationAction method run.
@Override
public void run() {
var compoundCommand = new CompoundCommand(orientationType.getLabel());
for (var widgetModel : getSelectedWidgetModels()) {
compoundCommand.add(new ChangeOrientationCommand(widgetModel, orientationType));
}
execute(compoundCommand);
}
Aggregations