use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class SEDefaultUI method addCloseIfTaskRemoved.
protected void addCloseIfTaskRemoved(Iterator<AUndertaking> undertakings, AlertHandler closeIfTaskRemovedHandler) {
while (undertakings.hasNext()) {
AUndertaking undertaking = undertakings.next();
if (undertaking.isTaskGroup()) {
TaskGroup taskGroup = (TaskGroup) undertaking;
taskGroup.addHandler(this, TaskGroup.TaskChange.class, closeIfTaskRemovedHandler);
Iterator<AUndertaking> childUndertakings = taskGroup.getUndertakings().iterator();
addCloseIfTaskRemoved(childUndertakings, closeIfTaskRemovedHandler);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class HCIPACmd method addHCIPATasks.
/**
* Returns the created subtasks
*/
public static AUndertaking[] addHCIPATasks(Project project, AUndertaking task, String taskName, CognitiveModelGenerator modelGen, String undoRedoLabel, IUndoableEditSequence editSeq) {
AUndertaking[] subtasks = new AUndertaking[6];
String[] subtaskNames = new String[] { IDENTIFY_LABEL + taskName, FUNCTION_LABEL, L10N.get("HC.AccessLabel", "3) Access Step"), L10N.get("HC.EnterLabel", "4) Enter Step"), L10N.get("HC.ConfirmLabel", "5) Confirm & Save Step"), L10N.get("HC.MonitorLabel", "6) Monitor Step") };
TaskGroup group = new TaskGroup(taskName, GroupNature.SUM);
for (int i = 0; i < 6; i++) {
subtasks[i] = new Task(subtaskNames[i]);
subtasks[i].setSpawned(true);
group.addUndertaking(i, subtasks[i]);
}
Iterator<Design> designs = project.getDesigns().iterator();
while (designs.hasNext()) {
initHCIPATaskDesign(project, taskName, subtasks, designs.next(), modelGen);
}
TaskParent parent = task.getTaskGroup();
if (parent == null) {
parent = project;
}
editSeq.addEdit(replaceTask(project, parent, task, group, undoRedoLabel));
return subtasks;
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking 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.AUndertaking in project cogtool by cogtool.
the class HCIPACmd method updateLabels.
public static IUndoableEdit updateLabels(final TaskGroup group, final String newName, final String undoRenameLabel) {
final String oldName = group.getName();
final AUndertaking t = group.getUndertakings().get(0);
group.setName(newName);
t.setName(IDENTIFY_LABEL + newName);
return new AUndoableEdit(ProjectLID.HCIPARenameTask) {
@Override
public String getPresentationName() {
return undoRenameLabel;
}
@Override
public void redo() {
super.redo();
group.setName(newName);
t.setName(IDENTIFY_LABEL + newName);
}
@Override
public void undo() {
super.undo();
group.setName(oldName);
t.setName(IDENTIFY_LABEL + oldName);
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method createDuplicateTaskAppAction.
protected IListenerAction createDuplicateTaskAppAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectUI.MoveCopyTaskApplicationParms.class;
}
public boolean performAction(Object p) {
if (p != null) {
ProjectUI.MoveCopyTaskApplicationParms parms = (ProjectUI.MoveCopyTaskApplicationParms) p;
// Must have selected tasks and design
if ((parms.design == null) || (parms.fromTask == null) || (parms.toTask == null)) {
interaction.protestNoSelection();
return false;
}
final AUndertaking fromTask = parms.fromTask;
final AUndertaking toTask = parms.toTask;
TaskApplication taskApp = project.getTaskApplication(fromTask, parms.design);
if (taskApp == null) {
interaction.protestNoTaskApplication();
return false;
}
final TaskApplication oldTaskApp = project.removeTaskApplication(parms.toTask, parms.design);
final TaskApplication newTaskApp = taskApp.duplicate(toTask, parms.design);
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, parms.design);
project.setTaskApplication(newTaskApp);
demoMgr.trackEdits(newTaskApp.getDemonstration());
IUndoableEdit edit = new AUndoableEdit(ProjectLID.DuplicateTaskApplication) {
protected boolean recoverMgrs = false;
@Override
public String getPresentationName() {
return DUPLICATE_TASKAPP;
}
@Override
public void redo() {
super.redo();
if (oldTaskApp != null) {
project.removeTaskApplication(oldTaskApp);
}
project.setTaskApplication(newTaskApp);
recoverMgrs = false;
}
@Override
public void undo() {
super.undo();
project.removeTaskApplication(newTaskApp);
if (oldTaskApp != null) {
project.setTaskApplication(oldTaskApp);
}
recoverMgrs = true;
}
@Override
public void die() {
if (recoverMgrs) {
recoverManagers(newTaskApp);
}
}
};
undoMgr.addEdit(edit);
}
return true;
}
};
}
Aggregations