use of org.csstudio.opibuilder.commands.ChangeOrderCommand in project yamcs-studio by yamcs.
the class WidgetTreeContainerEditPolicy method getMoveChildrenCommand.
@Override
protected Command getMoveChildrenCommand(ChangeBoundsRequest request) {
CompoundCommand command = new CompoundCommand();
@SuppressWarnings("rawtypes") List editparts = request.getEditParts();
@SuppressWarnings("rawtypes") List children = getHost().getChildren();
int newIndex = findIndexOfTreeItemAt(request.getLocation());
int tempIndex = newIndex;
for (int i = 0; i < editparts.size(); i++) {
EditPart child = (EditPart) editparts.get(editparts.size() - 1 - i);
int oldIndex = children.indexOf(child);
if (oldIndex == tempIndex || oldIndex + 1 == tempIndex) {
command.add(UnexecutableCommand.INSTANCE);
return command;
} else if (oldIndex <= tempIndex) {
tempIndex--;
}
command.add(new ChangeOrderCommand(tempIndex, (AbstractContainerModel) getHost().getModel(), (AbstractWidgetModel) child.getModel()));
}
return command;
}
use of org.csstudio.opibuilder.commands.ChangeOrderCommand in project yamcs-studio by yamcs.
the class ChangeOrderAction method run.
@Override
public void run() {
Map<AbstractContainerModel, List<IndexedWidget>> widgetMap = new HashMap<AbstractContainerModel, List<IndexedWidget>>();
fillWidgetMap(widgetMap);
CompoundCommand compoundCommand = new CompoundCommand(orderType.getLabel());
// create compound command
for (final Map.Entry<AbstractContainerModel, List<IndexedWidget>> entry : widgetMap.entrySet()) {
// sort the list in map by the widget's original order in its container
AbstractContainerModel container = entry.getKey();
List<IndexedWidget> 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 (IndexedWidget indexedWidget : widgetList) {
compoundCommand.add(new ChangeOrderCommand(newIndex, container, indexedWidget.getWidget()));
}
break;
case STEP_BACK:
case TO_BACK:
for (int i = widgetList.size() - 1; i >= 0; i--) {
compoundCommand.add(new ChangeOrderCommand(newIndex, container, widgetList.get(i).getWidget()));
}
break;
default:
break;
}
}
execute(compoundCommand);
}
Aggregations