Search in sources :

Example 1 with ChangeOrderCommand

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;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) ChangeOrderCommand(org.csstudio.opibuilder.commands.ChangeOrderCommand) EditPart(org.eclipse.gef.EditPart) List(java.util.List) Point(org.eclipse.draw2d.geometry.Point) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 2 with ChangeOrderCommand

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);
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) HashMap(java.util.HashMap) ChangeOrderCommand(org.csstudio.opibuilder.commands.ChangeOrderCommand) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Aggregations

List (java.util.List)2 ChangeOrderCommand (org.csstudio.opibuilder.commands.ChangeOrderCommand)2 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)1 Point (org.eclipse.draw2d.geometry.Point)1 EditPart (org.eclipse.gef.EditPart)1