Search in sources :

Example 51 with AUndoableEdit

use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.

the class FrameEditorController method renameEltGroup.

private boolean renameEltGroup(final FrameElementGroup eltGroup, String tryName) {
    final String oldName = eltGroup.getName();
    boolean notDone = true;
    do {
        if (tryName.length() == 0) {
            tryName = interaction.protestNameCannotBeEmpty(DEFAULT_GROUP_PREFIX);
            // If canceled, indicate so; otherwise, test again
            if (tryName == null) {
                return false;
            }
        } else {
            FrameElementGroup groupForName = model.getEltGroup(tryName);
            // then no change is necessary!
            if (groupForName == eltGroup) {
                notDone = false;
            } else if (groupForName != null) {
                // A non-null widget for the tryName indicates a collision
                tryName = interaction.protestNameCollision(DEFAULT_GROUP_PREFIX);
                // If canceled, indicate so; otherwise, test again
                if (tryName == null) {
                    return false;
                }
            } else {
                // Not canceled, not empty, and not a collision
                notDone = false;
                final String newName = tryName;
                model.setEltGroupName(newName, eltGroup);
                IUndoableEdit edit = new AUndoableEdit(FrameEditorLID.ChangeNameProperty) {

                    @Override
                    public String getPresentationName() {
                        return CHG_WIDGET_NAME;
                    }

                    @Override
                    public void redo() {
                        super.redo();
                        model.setEltGroupName(newName, eltGroup);
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        model.setEltGroupName(oldName, eltGroup);
                    }
                };
                undoMgr.addEdit(edit);
            }
        }
    } while (notDone);
    return true;
}
Also used : AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)

Example 52 with AUndoableEdit

use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.

the class FrameEditorController method newSetWidgetColorAction.

/**
     * Returns a new anonymous IListenerAction for widget color changes.
     * @return
     */
private IListenerAction newSetWidgetColorAction() {
    return new AListenerAction() {

        public boolean performAction(Object prms) {
            final int oldColor = model.getWidgetColor();
            // Ask the user to get the color.
            Integer newColorChoice = interaction.selectColor(oldColor, SELECT_WIDGET_COLOR);
            // if the color is not the flag value, set it and add the undo.
            if (newColorChoice != null) {
                final int newColor = newColorChoice.intValue();
                model.setWidgetColor(newColor);
                undoMgr.addEdit(new AUndoableEdit(FrameEditorLID.SetWidgetColor) {

                    @Override
                    public String getPresentationName() {
                        return SET_WIDGET_COLOR;
                    }

                    @Override
                    public void redo() {
                        super.redo();
                        model.setWidgetColor(newColor);
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        model.setWidgetColor(oldColor);
                    }
                });
                return true;
            }
            return false;
        }
    };
}
Also used : AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 53 with AUndoableEdit

use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.

the class ProjectController method moveTaskAction.

protected boolean moveTaskAction(TaskSelectionState seln, boolean moveEarlier) {
    AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION);
    if ((tasks == null) || (tasks.length == 0)) {
        interaction.protestNoSelection();
        return false;
    }
    if (tasks.length > 1) {
        interaction.protestTooManySelectedTasks();
        return false;
    }
    final AUndertaking task = tasks[0];
    final TaskParent parent = project.getTaskParent(task);
    List<AUndertaking> siblings = parent.getUndertakings();
    int siblingCount = siblings.size();
    if (siblingCount == 1) {
        interaction.setStatusMessage(taskIsOnlyChild);
    } else {
        final int oldTaskIndex = siblings.indexOf(task);
        IUndoableEdit edit;
        if (moveEarlier) {
            if (oldTaskIndex == 0) {
                interaction.protestCannotMoveEarlier();
                return false;
            }
            parent.removeUndertaking(task);
            parent.addUndertaking(oldTaskIndex - 1, task);
            edit = new AUndoableEdit(ProjectLID.MoveTaskEarlier) {

                @Override
                public String getPresentationName() {
                    return MOVE_TASK_EARLIER;
                }

                @Override
                public void redo() {
                    super.redo();
                    parent.removeUndertaking(task);
                    parent.addUndertaking(oldTaskIndex - 1, task);
                }

                @Override
                public void undo() {
                    super.undo();
                    parent.removeUndertaking(task);
                    parent.addUndertaking(oldTaskIndex, task);
                }
            };
        } else {
            if (oldTaskIndex == siblingCount - 1) {
                interaction.protestCannotMoveLater();
                return false;
            }
            parent.removeUndertaking(task);
            parent.addUndertaking(oldTaskIndex + 1, task);
            edit = new AUndoableEdit(ProjectLID.MoveTaskEarlier) {

                @Override
                public String getPresentationName() {
                    return MOVE_TASK_LATER;
                }

                @Override
                public void redo() {
                    super.redo();
                    parent.removeUndertaking(task);
                    parent.addUndertaking(oldTaskIndex + 1, task);
                }

                @Override
                public void undo() {
                    super.undo();
                    parent.removeUndertaking(task);
                    parent.addUndertaking(oldTaskIndex, task);
                }
            };
        }
        undoMgr.addEdit(edit);
    }
    return true;
}
Also used : TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 54 with AUndoableEdit

use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.

the class ProjectController method createSetAlgorithmAction.

protected IListenerAction createSetAlgorithmAction(final IPredictionAlgo alg, final CogToolLID lid, final String actionString) {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return ProjectSelectionState.class;
        }

        public boolean performAction(Object actionParms) {
            ProjectSelectionState selState = (ProjectSelectionState) actionParms;
            Design design = selState.getSelectedDesign();
            AUndertaking[] tasks = selState.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
            DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
            // iterate through tasks and get set of TaskApplications
            final TaskApplication[] taskApps = new TaskApplication[tasks.length];
            final IPredictionAlgo[] oldAlgos = new IPredictionAlgo[tasks.length];
            for (int i = 0; i < tasks.length; i++) {
                // Make sure that the task application exists, and create it
                // if it does not.  No need to ensure a script.
                TaskApplication ta = ensureTaskApplication(tasks[i], design, null, demoMgr);
                taskApps[i] = ta;
                oldAlgos[i] = ta.getActiveAlgorithm();
                // now set the new algorithm
                ta.setActiveAlgorithm(alg);
            }
            undoMgr.addEdit(new AUndoableEdit(lid) {

                @Override
                public String getPresentationName() {
                    return actionString;
                }

                @Override
                public void redo() {
                    super.redo();
                    for (TaskApplication taskApp : taskApps) {
                        taskApp.setActiveAlgorithm(alg);
                    }
                }

                @Override
                public void undo() {
                    super.undo();
                    for (int i = 0; i < taskApps.length; i++) {
                        taskApps[i].setActiveAlgorithm(oldAlgos[i]);
                    }
                }
            });
            return true;
        }
    };
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication)

Example 55 with AUndoableEdit

use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.

the class ProjectController method renameDesign.

/**
     * The semantic application action to rename a given design from the given
     * "old" name to the given "new" name.
     * Adds the appropriate undo/redo to the controller's undo manager.
     *
     * @param renamedDesign the design to rename
     * @param oldDesignName the design's old name
     * @param newDesignName the desired new name for the design
     * @author mlh
     */
protected void renameDesign(final Design renamedDesign, final String oldDesignName, final String newDesignName) {
    // Nothing need be done if the two names are identical (ie, no change)
    if (!newDesignName.equals(oldDesignName)) {
        renamedDesign.setName(newDesignName);
        // Create undo/redo step and add to the undo manager
        undoMgr.addEdit(new AUndoableEdit(ProjectLID.RenameDesign) {

            @Override
            public String getPresentationName() {
                return RENAME_DESIGN;
            }

            @Override
            public void redo() {
                super.redo();
                renamedDesign.setName(newDesignName);
            }

            @Override
            public void undo() {
                super.undo();
                renamedDesign.setName(oldDesignName);
            }
        });
    }
}
Also used : AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)

Aggregations

AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)66 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)34 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)21 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)16 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)14 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)14 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)12 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)10 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)9 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)7 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)7 Design (edu.cmu.cs.hcii.cogtool.model.Design)7 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)7 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)7 TaskParent (edu.cmu.cs.hcii.cogtool.model.TaskParent)7 DictEntry (edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary.DictEntry)6 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)6 UndoManager (edu.cmu.cs.hcii.cogtool.util.UndoManager)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6