use of edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator in project cogtool by cogtool.
the class SEDemoController method deleteScriptStep.
// createInsertSelfTransitionAction
/**
* Perform the operations needed to DELETE a script Action
*
* @param selection
* @return
*/
protected boolean deleteScriptStep(SEDemoSelectionState selection) {
// In case we need to go back to edit initial state.
final CognitiveModelGenerator modelGen = script.getModelGenerator();
final Demonstration demo = script.getDemonstration();
final TaskApplication taskApp = demo.getTaskApplication();
// If there is no selected action, try to delete the last item
DefaultModelGeneratorState selectedState = selection.getSelectedState();
final DefaultModelGeneratorState stateToDelete = getValidStepState(selectedState);
IUndoableEdit edit;
// If no states, go back to edit initial state
if ((stateToDelete == null) || stateToDelete.getScriptStep().isInitiallyGenerated()) {
closeWindow(false);
demo.setStartFrameChosen(false);
SEFrameChooserController.openController(taskApp, modelGen, project);
edit = new AUndoableEdit(SEDemoLID.Delete) {
protected DemoScriptCmd.ComputationUndoRedo computeUndoRedo = new DemoScriptCmd.ComputationUndoRedo(script);
@Override
public String getPresentationName() {
return CHANGE_START_FRAME;
}
@Override
public void redo() {
super.redo();
DefaultController seDemoController = ControllerRegistry.ONLY.findOpenController(script);
if (seDemoController != null) {
seDemoController.closeWindow(false);
}
demo.setStartFrameChosen(false);
SEFrameChooserController.openController(taskApp, modelGen, project);
computeUndoRedo.redoChanges();
}
@Override
public void undo() {
super.undo();
if (demo.getStartFrame() != null) {
demo.setStartFrameChosen(true);
// Close the frame chooser window.
DefaultController frameChooserController = ControllerRegistry.ONLY.findOpenController(taskApp);
if (frameChooserController != null) {
frameChooserController.closeWindow(false);
}
// Open the new demo view window
try {
SEDemoController.openController(taskApp, modelGen, project);
} catch (GraphicsUtil.ImageException ex) {
interaction.protestInvalidImageFile();
}
computeUndoRedo.undoChanges();
}
}
};
UndoManager seFrameMgr = UndoManager.getUndoManager(taskApp, project);
seFrameMgr.addEdit(edit);
undoMgr.addEdit(edit);
return true;
}
AScriptStep step = stateToDelete.getScriptStep();
// If a generated think step, simply delete
if ((step instanceof ThinkScriptStep) && !step.isInsertedByUser()) {
edit = new AUndoableEdit(SEDemoLID.Delete) {
protected int scriptIndex = script.removeState(stateToDelete);
protected DemoScriptCmd.ComputationUndoRedo computeUndoRedo = new DemoScriptCmd.ComputationUndoRedo(script);
@Override
public String getPresentationName() {
return DELETE_STEP;
}
@Override
public void redo() {
super.redo();
script.removeState(scriptIndex);
computeUndoRedo.redoChanges();
}
@Override
public void undo() {
super.undo();
script.insertState(stateToDelete, scriptIndex);
computeUndoRedo.undoChanges();
}
};
} else {
final AScriptStep demoStep = step.getOwner();
// There are no "new" steps to replace with when deleting
Set<AScriptStep> emptyDemoSteps = new HashSet<AScriptStep>();
if (demoStep.getCurrentFrame() == demoStep.getDestinationFrame()) {
final int atIndex = demo.removeStep(demoStep);
final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, demoStep, interaction);
Set<AScriptStep> oldDemoSteps = Collections.singleton(demoStep);
edit = new DemoStateManager.ADemoUndoableEdit(SEDemoLID.Delete, demo, emptyDemoSteps, oldDemoSteps, demoStateMgr) {
@Override
public String getPresentationName() {
return DELETE_STEP;
}
@Override
public void redo() {
super.redo();
demo.removeStep(atIndex);
DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
}
@Override
public void undo() {
super.undo();
demo.insertStep(demoStep, atIndex);
DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
}
};
} else {
if ((selectedState != null) && (demoStep != demo.getLastStep()) && !interaction.confirmDeleteScriptStep()) {
return false;
}
Set<AScriptStep> oldDemoSteps = new LinkedHashSet<AScriptStep>();
final int atIndex = demo.replaceSteps(demoStep, emptyDemoSteps, oldDemoSteps);
final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, demoStep, interaction);
edit = new DemoStateManager.ADemoUndoableEdit(SEDemoLID.Delete, demo, emptyDemoSteps, oldDemoSteps, demoStateMgr) {
@Override
public String getPresentationName() {
return DELETE_STEP;
}
@Override
public void redo() {
super.redo();
demo.replaceSteps(atIndex, redoDemoSteps);
DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
}
@Override
public void undo() {
super.undo();
demo.replaceSteps(atIndex, undoDemoSteps);
DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
}
};
}
}
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(DELETE_STEP, SEDemoLID.Delete);
editSequence.addEdit(edit);
if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
DemoScriptCmd.regenerateScripts(project, demo, demoStateMgr, interaction, editSequence);
}
editSequence.end();
undoMgr.addEdit(editSequence);
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator in project cogtool by cogtool.
the class UndoManagerRecovery method recoverScriptManagers.
/**
* Recover UndoManagers for the given TaskApplication instance and
* all the IScripts it contains.
*
* @param project the project containing the model objects
* @param taskApp TaskApplication
* @param stopTrackingEdits whether to stop tracking edits for the
* associated Demonstration
*/
public static void recoverScriptManagers(Project project, TaskApplication taskApp, boolean stopTrackingEdits) {
recoverManagers(project, taskApp);
Iterator<CognitiveModelGenerator> modelGens = taskApp.getModelGenerators();
while (modelGens.hasNext()) {
CognitiveModelGenerator modelGen = modelGens.next();
recoverManagers(project, taskApp.getScript(modelGen));
}
if (stopTrackingEdits) {
DemoStateManager.stopTrackingEdits(project, taskApp);
}
}
use of edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator in project cogtool by cogtool.
the class ResultDisplayPolicy method getTaskRowStrings.
public static String[] getTaskRowStrings(Project project, AUndertaking undertaking, String withSecs, int[] designOrder) {
List<Design> projectDesigns = project.getDesigns();
// Add 1 since the initial column is not a design.
String[] entries = new String[projectDesigns.size() + 1];
entries[0] = SWTStringUtil.insertEllipsis(undertaking.getName(), 300, StringUtil.EQUAL, SWTStringUtil.DEFAULT_FONT);
Iterator<Design> designIter = projectDesigns.iterator();
// advance index to "First result" position
int index = 1;
if (undertaking.isTaskGroup()) {
// TODO: Store group results instead of recomputing?
TaskGroup group = (TaskGroup) undertaking;
while (designIter.hasNext()) {
Design d = designIter.next();
double result = computeGroup(project, group, d);
updateDigits();
String formattedResult = (result == TimePredictionResult.UNSET_TIME) ? "?" : (cellNumberFormat.format(result) + withSecs);
int entryIndex = (designOrder != null) ? designOrder[index++] : index++;
entries[entryIndex] = group.getNature().toString() + ": " + formattedResult;
}
} else {
while (designIter.hasNext()) {
Design d = designIter.next();
TaskApplication ta = project.getTaskApplication(undertaking, d);
int entryIndex = (designOrder != null) ? designOrder[index++] : index++;
CognitiveModelGenerator gen = null;
if (ta != null) {
gen = ta.getFirstModelGenerator();
}
entries[entryIndex] = getTaskApplicationCell(project, ta, gen, true, withSecs);
}
}
return entries;
}
use of edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator in project cogtool by cogtool.
the class ComputePredictionCmd method addUndoableEditToScripts.
/**
* Adds the edit for each of the scripts in the demonstration.
* @param seq
* @param demo
* @param project
*/
protected static void addUndoableEditToScripts(IUndoableEdit edit, TaskApplication taskApp, Project project) {
Iterator<CognitiveModelGenerator> modelGens = taskApp.getModelGenerators();
while (modelGens.hasNext()) {
CognitiveModelGenerator modelGen = modelGens.next();
Script script = taskApp.getScript(modelGen);
if (script != null) {
UndoManager undoMgr = UndoManager.getUndoManager(script, project);
if (undoMgr != null) {
undoMgr.addEdit(edit);
}
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator in project cogtool by cogtool.
the class DemoScriptCmd method resetComputations.
/**
* Adds all generated undos/redos to the given collection.
*/
public static void resetComputations(TaskApplication taskApp, Collection<ComputationUndoRedo> undoRedos) {
Iterator<CognitiveModelGenerator> modelGens = taskApp.getModelGenerators();
while (modelGens.hasNext()) {
CognitiveModelGenerator modelGen = modelGens.next();
Script s = taskApp.getScript(modelGen);
if (s != null) {
undoRedos.add(new DemoScriptCmd.ComputationUndoRedo(s));
}
}
}
Aggregations