use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class SNIFACTCmd method addTasksToGroup.
/**
* Creates an undoable edit for the action of adding the list of tasks
* stored in the execution context to the given task group.
*/
protected static IUndoableEdit addTasksToGroup(final Project project, final TaskGroup group, final SNIFACTExecContext context, final String undoLabel) {
return new AUndoableEdit(ProjectLID.RecomputeScript) {
protected Map<ITaskDesign, TaskApplication>[] associatedTAs = null;
protected boolean recoverMgrs = false;
@Override
public String getPresentationName() {
return undoLabel;
}
@Override
public void redo() {
super.redo();
recoverMgrs = false;
List<AUndertaking> tasks = context.getTasks();
for (int i = 0; i < tasks.size(); i++) {
AUndertaking curTask = tasks.get(i);
group.addUndertaking(curTask);
project.restoreRemovedTaskApplications(associatedTAs[i]);
}
}
@Override
@SuppressWarnings("unchecked")
public void undo() {
super.undo();
recoverMgrs = true;
List<AUndertaking> tasks = context.getTasks();
int size = tasks.size();
if (associatedTAs == null) {
associatedTAs = new Map[size];
}
// delete children; IMPORTANT: reverse order!
for (int i = tasks.size() - 1; 0 <= i; i--) {
AUndertaking curTask = tasks.get(i);
associatedTAs[i] = project.taskApplicationsForRemovedTask(curTask);
group.removeUndertaking(curTask);
}
}
@Override
public void die() {
super.die();
if (recoverMgrs) {
for (Map<ITaskDesign, TaskApplication> associatedTA : associatedTAs) {
UndoManagerRecovery.recoverScriptManagers(project, associatedTA, true);
}
}
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class ScriptViewerController method createEditScriptAction.
protected IListenerAction createEditScriptAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return Script.class;
}
public boolean performAction(Object actionParms) {
Script s = (Script) actionParms;
TaskApplication ta = s.getDemonstration().getTaskApplication();
try {
SEDemoController.openController(ta, s.getModelGenerator(), project);
} catch (GraphicsUtil.ImageException ex) {
//interaction.protestInvalidImageFile();
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class HCIPACmd method exportToHCIPA.
public static boolean exportToHCIPA(Project project, Design design, TaskGroup group, File scriptFile) {
final String safeDblQuote = quotePHP("\"");
// final String safeDblQuote = "\""; // no escaping needed for SQL
StringBuilder php = new StringBuilder();
php.append("<?php\n");
php.append("// Generated by CogTool version: " + CogTool.getVersion() + "\n");
php.append("$COGTOOL_EXPORT_VERSION = " + HCIPA_EXPORT_VERSION + ";\n");
php.append("function insertIntoDatabase_" + HCIPA_EXPORT_VERSION + "($userId) {\n\t");
String functionName = (String) group.getAttribute(WidgetAttributes.HCIPA_FUNCTION_ATTR);
functionName = quotePHP(quoteSQL(functionName));
String access = "Access " + safeDblQuote + functionName + safeDblQuote + " function";
String enter = "Enter data for " + safeDblQuote + functionName + safeDblQuote + " Function";
String confirm = "Confirm & Save data using " + safeDblQuote + functionName + safeDblQuote + " function";
String monitor = "Monitor results of " + safeDblQuote + functionName + safeDblQuote + " function";
php.append("$userId = mysql_real_escape_string($userId);\n\t");
// fill out hcipa table
php.append("$deviceId = Create_Task($userId, \"" + quotePHP(quoteSQL(design.getName())) + "\",\n\t");
php.append('"' + RECOGNIZE_NEED + quotePHP(quoteSQL(group.getName())) + "\",\n\t");
php.append('"' + DECIDE_TO_USE + functionName + "\",\n\t");
php.append('"' + access + "\",\n\t\"" + enter + "\",\n\t");
php.append('"' + confirm + "\",\n\t\"" + monitor + "\");\n\n");
// php.append("$sqlStmt =\n<<<SQL__INSERT__STRING\n\t");
// php.append(SQL_INSERT + "HCIPA (\n\tUser_Id,\n\tDescription,\n\tIdentify_Task,\n\t");
// php.append("Select_Function,\n\tAccess,\n\tEnter,\n\tConfirm_Save,\n\tMonitor)\n\t"
// + SQL_VALUES + " ('$userId',\n\t'");
// php.append(quoteSQL(design.getName()) + "',\n\t");
// php.append("'" + RECOGNIZE_NEED + quoteSQL(group.getName()) + "',\n\t");
// php.append("'" + DECIDE_TO_USE + functionName + "',\n\t");
// php.append("'" + access + "',\n\t'" + enter + "',\n\t");
// php.append("'" + confirm + "',\n\t'" + monitor + "')\n");
// php.append("SQL__INSERT__STRING\n;\n\n\t");
// php.append("mysql_query($sqlStmt);\n\n\t");
// php.append("$deviceId = mysql_insert_id();\n");
// fill out hcipa_actions table
Iterator<AUndertaking> subtasks = group.getUndertakings().iterator();
while (subtasks.hasNext()) {
AUndertaking subtask = subtasks.next();
TaskApplication ta = project.getTaskApplication(subtask, design);
if (ta != null) {
Demonstration demo = ta.getDemonstration();
Iterator<AScriptStep> steps = demo.getSteps().iterator();
while (steps.hasNext()) {
AScriptStep step = steps.next();
buildActionStepInsert(subtask, step, demo, php);
}
}
}
try {
// write script to destFile
FileWriter fileOut = null;
BufferedWriter writer = null;
try {
fileOut = new FileWriter(scriptFile);
writer = new BufferedWriter(fileOut);
php.append("\treturn $deviceId;\n");
php.append("} // insertIntoDatabase_" + HCIPA_EXPORT_VERSION + "\n?>\n");
writer.write(php.toString());
} finally {
if (writer != null) {
writer.close();
} else if (fileOut != null) {
fileOut.close();
}
}
} catch (IOException ex) {
// so we don't have to import DesignExportToHTML!
throw new ExportIOException("Could not write PHP script ", ex);
}
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class HCIPACmd method initHCIPATaskDesign.
// For each design
protected static void initHCIPATaskDesign(Project project, String taskName, AUndertaking[] subtasks, Design design, CognitiveModelGenerator modelGen) {
Frame f = getStartFrame(design);
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
TaskApplication ta = DemoStateManager.ensureTaskApplication(project, subtasks[0], design, modelGen, demoMgr);
Script script = ta.getScript(modelGen);
Demonstration demo = script.getDemonstration();
demo.setStartFrame(f);
demo.setStartFrameChosen(true);
IPredictionAlgo computeAlg = ta.determineActiveAlgorithm(project);
ThinkScriptStep thinkStep = new ThinkScriptStep(f, RECOGNIZE_NEED + taskName);
demo.appendStep(thinkStep);
List<String> warnings = new ArrayList<String>();
List<DefaultModelGeneratorState> states = modelGen.generateScriptSteps(thinkStep, demo.getInitialState(), warnings);
script.replaceStepStates(0, states);
APredictionResult result = ComputePredictionCmd.computePrediction(computeAlg, script);
ta.setResult(modelGen, computeAlg, PredictionResultProxy.getLatestResult(result));
ta = DemoStateManager.ensureTaskApplication(project, subtasks[1], design, modelGen, demoMgr);
script = ta.getScript(modelGen);
demo = ta.getDemonstration();
demo.setStartFrame(f);
demo.setStartFrameChosen(true);
thinkStep = new ThinkScriptStep(f, "Select Function Step");
demo.appendStep(thinkStep);
states = modelGen.generateScriptSteps(thinkStep, demo.getInitialState(), warnings);
script.replaceStepStates(0, states);
result = ComputePredictionCmd.computePrediction(computeAlg, script);
ta.setResult(modelGen, computeAlg, PredictionResultProxy.getLatestResult(result));
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class ProjectCmd method addNewDesign.
public static void addNewDesign(final Project project, final Design design, final int beforeIndex, final String presentationName, IUndoableEditSequence editSeq) {
project.addDesign(beforeIndex, design);
// Create undo/redo step
editSeq.addEdit(new AUndoableEdit(ProjectLID.NewDesign) {
// Map from Project.ITaskDesign to TaskApplication
protected Map<ITaskDesign, TaskApplication> associatedTAs = null;
protected boolean recoverMgr = false;
@Override
public String getPresentationName() {
return presentationName;
}
@Override
public void redo() {
super.redo();
recoverMgr = false;
project.addDesign(beforeIndex, design);
if (associatedTAs != null) {
project.restoreRemovedTaskApplications(associatedTAs);
}
}
@Override
public void undo() {
super.undo();
recoverMgr = true;
associatedTAs = project.taskApplicationsForRemovedDesign(design);
project.removeDesign(design);
}
@Override
public void die() {
super.die();
if (recoverMgr) {
UndoManagerRecovery.recoverManagers(project, design, associatedTAs);
FrameTemplateSupport.clearFrameTemplate(design);
}
}
});
}
Aggregations