use of edu.cmu.cs.hcii.cogtool.model.TaskApplication 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.model.TaskApplication in project cogtool by cogtool.
the class ProjectController method createScriptViewerAction.
protected IListenerAction createScriptViewerAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object prms) {
if (prms != null) {
ProjectSelectionState seln = (ProjectSelectionState) prms;
// Must have selected tasks and design
Design design = seln.getSelectedDesign();
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
if ((design == null) || (tasks == null) || (tasks.length == 0)) {
return false;
}
boolean viewSuccessful = false;
// Viewing a script only applies to task groups
for (AUndertaking task : tasks) {
if (task.isTaskGroup()) {
TaskGroup group = (TaskGroup) task;
List<AUndertaking> childTasks = group.getUndertakings();
if (childTasks.size() > 0) {
AUndertaking firstTask = childTasks.get(0);
TaskApplication ta = project.getTaskApplication(firstTask, design);
if (ta != null) {
ITaskDesign td = project.getTaskDesign(task, design);
ScriptViewerController.openController(td, project);
viewSuccessful = true;
}
}
}
}
if (!viewSuccessful) {
interaction.setStatusMessage(L10N.get("PC.NoScriptsToView", "No scripts to view."));
}
return true;
}
interaction.protestNoSelection();
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication 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.model.TaskApplication in project cogtool by cogtool.
the class HCIPACmd method chgFnName.
protected static ThinkScriptStep chgFnName(Project project, AUndertaking renamedTask, Design design, CognitiveModelGenerator modelGen, String thinkLabel) {
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
TaskApplication ta = DemoStateManager.ensureTaskApplication(project, renamedTask, design, modelGen, demoMgr);
AScriptStep thinkStep = ta.getDemonstration().getLastStep();
if ((thinkStep != null) && (thinkStep instanceof ThinkScriptStep)) {
((ThinkScriptStep) thinkStep).setLabel(thinkLabel);
return (ThinkScriptStep) thinkStep;
}
// Either no step or not a think step
return null;
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class ProjectController method importDesign.
protected void importDesign(TaskParent parent, DesignSelectionState prms, Design newDesign, Collection<Demonstration> demonstrations, Set<AUndertaking> newUndertakings, IUndoableEditSequence editSeq) {
makeDesignNameUnique(newDesign);
ProjectCmd.addNewDesign(project, newDesign, prms.getSelectedDesign(), importXMLPresentation, editSeq);
// Add taskapplications/tasks as well for demonstrations
if ((demonstrations != null) && (demonstrations.size() > 0)) {
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, newDesign);
Iterator<Demonstration> demoIt = demonstrations.iterator();
while (demoIt.hasNext()) {
Demonstration demo = demoIt.next();
TaskApplication taskApp = demo.getTaskApplication();
AUndertaking demoTask = taskApp.getTask();
if (demoTask.getTaskGroup() == null && !newUndertakings.contains(demoTask)) {
// If the taskApp's task is not already part of the
// project, add it. Regardless, any project root task
// with the same name should be the same at this point!
AUndertaking rootTask = parent.getUndertaking(demoTask.getName());
if (rootTask == null) {
parent.addUndertaking(demoTask);
editSeq.addEdit(createNewTaskUndo(parent, Project.AT_END, demoTask, ProjectLID.ImportXML, importXMLPresentation));
} else if (rootTask != demoTask) {
throw new RcvrIllegalStateException("Unexpected root task difference");
}
}
project.setTaskApplication(taskApp);
demoMgr.trackEdits(demo);
}
}
}
Aggregations