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;
}
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;
}
};
}
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;
}
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;
}
};
}
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);
}
});
}
}
Aggregations