use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.
the class ProjectController method openProjectOnCompute.
/**
* editSeq will be null if no regeneration occurred; otherwise,
* the edit sequence will contain the undoable edit for the regeneration.
*/
public static boolean openProjectOnCompute(Project project, final Script script, final APredictionResult newResult, CompoundUndoableEdit editSeq) {
boolean notModified;
try {
notModified = UndoManager.isAtSavePoint(project);
} catch (IllegalStateException ex) {
System.err.println("Ignoring that isAtSavePoint failed.");
notModified = false;
}
ProjectController c = ProjectController.openController(project, false, notModified);
final CognitiveModelGenerator modelGen = script.getModelGenerator();
final IPredictionAlgo computeAlg = newResult.getPredictionAlgorithm();
final TaskApplication taskApp = script.getDemonstration().getTaskApplication();
final APredictionResult oldResult = taskApp.getResult(modelGen, computeAlg);
taskApp.setResult(modelGen, computeAlg, PredictionResultProxy.getLatestResult(newResult));
UndoManager scriptUndoMgr = UndoManager.getUndoManager(script, project);
IUndoableEdit edit = new AUndoableEdit(ProjectLID.RecomputeScript) {
protected APredictionResult redoResult = newResult;
protected APredictionResult undoResult = oldResult;
@Override
public String getPresentationName() {
return COMPUTE_SCRIPT;
}
@Override
public void redo() {
super.redo();
redoResult = PredictionResultProxy.getLatestResult(redoResult);
taskApp.setResult(modelGen, computeAlg, redoResult);
}
@Override
public void undo() {
super.undo();
undoResult = PredictionResultProxy.getLatestResult(undoResult);
taskApp.setResult(modelGen, computeAlg, undoResult);
}
};
if (editSeq != null) {
editSeq.addEdit(edit);
editSeq.end();
edit = editSeq;
}
// Add to script's undo mgr first to set owner properly
scriptUndoMgr.addEdit(edit);
c.undoMgr.addEdit(edit);
c.takeFocus();
return true;
}
use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.
the class ProjectController method createSetBackgroundComputeAction.
protected IListenerAction createSetBackgroundComputeAction(final Boolean bkg, final ProjectLID lid, final String actionName) {
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);
// iterate through tasks and get set of TaskApplications
final TaskApplication[] taskApps = new TaskApplication[tasks.length];
final Boolean[] oldBkgSettings = new Boolean[tasks.length];
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
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;
oldBkgSettings[i] = ta.getComputeInBackground();
// now set the compute in background flag
ta.setComputeInBackground(bkg);
}
undoMgr.addEdit(new AUndoableEdit(lid) {
@Override
public String getPresentationName() {
return actionName;
}
@Override
public void redo() {
super.redo();
for (TaskApplication taskApp : taskApps) {
taskApp.setComputeInBackground(bkg);
}
}
@Override
public void undo() {
super.undo();
for (int i = 0; i < taskApps.length; i++) {
taskApps[i].setComputeInBackground(oldBkgSettings[i]);
}
}
});
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.
the class ProjectController method setProjectDefaultExecution.
protected boolean setProjectDefaultExecution(ProjectLID lid, final String label, final boolean inBackground) {
final boolean wasInBkg = project.getDefaultRunInBackground();
if (wasInBkg != inBackground) {
project.setDefaultRunInBackground(inBackground);
undoMgr.addEdit(new AUndoableEdit(lid) {
@Override
public String getPresentationName() {
return label;
}
@Override
public void redo() {
super.redo();
project.setDefaultRunInBackground(inBackground);
}
@Override
public void undo() {
super.undo();
project.setDefaultRunInBackground(wasInBkg);
}
});
}
return true;
}
use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.
the class FrameEditorController method createUngroupElementsAction.
private IListenerAction createUngroupElementsAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameEditorSelectionState.class;
}
public boolean performAction(Object prms) {
FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
Iterator<FrameElement> selectedElts = selection.getSelectedElementsIterator();
final Set<FrameElementGroup> selectedGroups = new HashSet<FrameElementGroup>();
while (selectedElts.hasNext()) {
FrameElement elt = selectedElts.next();
if (elt instanceof FrameElementGroup) {
selectedGroups.add((FrameElementGroup) elt);
} else {
selectedGroups.addAll(elt.getRootElement().getEltGroups());
}
}
if (selectedGroups.size() > 0) {
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(UNGROUP_ELEMENTS, FrameEditorLID.Ungroup);
Iterator<FrameElementGroup> groups = selectedGroups.iterator();
while (groups.hasNext()) {
FrameElementGroup group = groups.next();
ungroup(group, editSequence);
removeRootElement(UNGROUP_ELEMENTS, group, null, editSequence);
}
IUndoableEdit edit = new AUndoableEdit(FrameEditorLID.Ungroup) {
@Override
public String getPresentationName() {
return UNGROUP_ELEMENTS;
}
@Override
public void redo() {
super.redo();
Iterator<FrameElementGroup> groups = selectedGroups.iterator();
while (groups.hasNext()) {
FrameElementGroup group = groups.next();
ungroup(group, null);
}
}
@Override
public void undo() {
super.undo();
Iterator<FrameElementGroup> groups = selectedGroups.iterator();
while (groups.hasNext()) {
FrameElementGroup group = groups.next();
regroup(group);
}
}
};
editSequence.addEdit(edit);
// Commit the edit
editSequence.end();
// Only add this edit if it is significant
if (editSequence.isSignificant()) {
undoMgr.addEdit(editSequence);
}
return true;
}
interaction.protestNoSelection();
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.
the class ProjectController method modifyTaskGroup.
// renameTask
/**
* Utility to modify a task that is a group, modifying both its name
* and its nature.
*
* @param modifiedTaskGroup group to modify
* @param oldTaskName the old name
* @param newTaskName the new name
* @param oldNature the old computational nature of the group's subtasks
* @param newNature the new computational nature of the group's subtasks
*/
protected void modifyTaskGroup(final TaskGroup modifiedTaskGroup, final String oldTaskName, final String newTaskName, final GroupNature oldNature, final GroupNature newNature) {
// Rename only if the name or nature has changed
if ((!newTaskName.equals(oldTaskName)) || (oldNature != newNature)) {
modifiedTaskGroup.setName(newTaskName);
modifiedTaskGroup.setNature(newNature);
// Create undo/redo step and add to undo manager
undoMgr.addEdit(new AUndoableEdit(ProjectLID.EditTask) {
@Override
public String getPresentationName() {
return RENAME_TASK_GROUP;
}
@Override
public void redo() {
super.redo();
modifiedTaskGroup.setName(newTaskName);
modifiedTaskGroup.setNature(newNature);
}
@Override
public void undo() {
super.undo();
modifiedTaskGroup.setName(oldTaskName);
modifiedTaskGroup.setNature(oldNature);
}
});
}
}
Aggregations