use of edu.cmu.cs.hcii.cogtool.model.AScriptStep in project cogtool by cogtool.
the class SEDemoController method insertStep.
protected boolean insertStep(final AScriptStep newDemoStep, AScriptStep beforeStep, CogToolLID lid, final String presentationName) {
Set<AScriptStep> newDemoSteps = Collections.singleton(newDemoStep);
Set<AScriptStep> emptyDemoSteps = // None are being replaced!
new HashSet<AScriptStep>();
Demonstration demo = script.getDemonstration();
final int atIndex = demo.insertStep(newDemoStep, beforeStep);
final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, beforeStep, interaction);
if (CogToolPref.HCIPA.getBoolean()) {
TaskApplication ta = script.getDemonstration().getTaskApplication();
AUndertaking t = ta.getTask();
Design d = ta.getDesign();
// Starting with the script after t, update all of the scripts in
// the task group to reflect the new state
TaskGroup grp = t.getTaskGroup();
if (grp != null) {
List<AUndertaking> tasks = grp.getUndertakings();
int startIndex = tasks.indexOf(t);
Script prevScript = script;
for (int i = startIndex + 1; i < tasks.size(); i++) {
t = tasks.get(i);
ta = project.getTaskApplication(t, d);
if (ta == null) {
continue;
}
Script s = ta.getScript(script.getModelGenerator());
Demonstration curDemo = s.getDemonstration();
HCIPACmd.copyState(prevScript, curDemo);
scriptsUndoRedos.addAll(DemoScriptCmd.regenerateScripts(curDemo, 0, curDemo.getStepAt(0), interaction));
prevScript = s;
}
}
}
IUndoableEdit edit = new DemoStateManager.ADemoUndoableEdit(lid, demo, newDemoSteps, emptyDemoSteps, demoStateMgr) {
@Override
public String getPresentationName() {
return presentationName;
}
@Override
public void redo() {
super.redo();
demo.insertStep(newDemoStep, atIndex);
DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
}
@Override
public void undo() {
super.undo();
demo.removeStep(atIndex);
DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
}
};
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(presentationName, lid);
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.AScriptStep 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.AScriptStep 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.AScriptStep in project cogtool by cogtool.
the class DemoScriptCmd method exportScriptToCSV.
public static boolean exportScriptToCSV(Script script, Project project, Interaction interaction, IUndoableEditSequence editSeq) {
Demonstration demo = script.getDemonstration();
TaskApplication ta = demo.getTaskApplication();
Design design = ta.getDesign();
AUndertaking task = ta.getTask();
String name = project.getName();
name += "_" + design.getName();
name += "_" + task.getName();
File dest = null;
if (interaction != null) {
dest = interaction.selectCSVFileDest(name);
} else {
dest = new File(CogTool.exportCSVKludgeDir, name + ".txt");
}
if (dest == null) {
return false;
}
FileWriter fw = null;
BufferedWriter buffer = null;
try {
fw = new FileWriter(dest);
buffer = new BufferedWriter(fw);
CSVSupport.writeCell("Format version:", buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(FORMAT_VERSION, buffer);
CSVSupport.addLineEnding(buffer);
Date now = new Date();
String date = DateFormat.getDateTimeInstance().format(now);
CSVSupport.writeCell("Date and Time:", buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(date, buffer);
CSVSupport.addLineEnding(buffer);
CSVSupport.writeCell("Project Name:", buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(project.getName(), buffer);
CSVSupport.addLineEnding(buffer);
CSVSupport.writeCell("Design Name:", buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(design.getName(), buffer);
CSVSupport.addLineEnding(buffer);
CSVSupport.writeCell("Task Hierarchy:", buffer);
String taskName = task.getFullName();
String[] cells = taskName.split(":");
for (String cell : cells) {
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(cell, buffer);
}
CSVSupport.addLineEnding(buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.addLineEnding(buffer);
buffer.write("\"Frame\",\"Action\",\"Widget-Name\"," + "\"Displayed-Label\",\"Widget-Type\"");
CSVSupport.addLineEnding(buffer);
IWidget lastMovedToWidget = null;
Iterator<DefaultModelGeneratorState> stepStates = script.getStepStates().iterator();
while (stepStates.hasNext()) {
DefaultModelGeneratorState stepState = stepStates.next();
AScriptStep step = stepState.getScriptStep();
TransitionSource stepFocus = step.getStepFocus();
String frameName = step.getCurrentFrame().getName();
String actionName = KeyDisplayUtil.convertActionToMenuText(step.getLocalizedString());
if ((!(step instanceof LookAtScriptStep)) && (!(step instanceof ThinkScriptStep)) && (!(step instanceof TextActionSegment))) {
actionName = step.getLocalizedActionString(actionName, lastMovedToWidget);
}
lastMovedToWidget = stepState.getLastMovedToWidget();
String widgetName = "";
String widgetType = "";
String widgetTitle = "";
if (stepFocus != null) {
widgetName = stepFocus.getName();
if (stepFocus instanceof IWidget) {
IWidget w = (IWidget) stepFocus;
widgetType = w.getWidgetType().toString();
String s = w.getTitle();
if (s != null) {
widgetTitle = s;
}
}
}
CSVSupport.writeCell(frameName, buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(actionName, buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(widgetName, buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(widgetTitle, buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(widgetType, buffer);
CSVSupport.addLineEnding(buffer);
}
Frame resultFrame = demo.getResultFrame();
if (resultFrame != null) {
CSVSupport.writeCell(resultFrame.getName(), buffer);
}
if (interaction != null) {
interaction.setStatusMessage(L10N.get("DSO.ExportCompletedPre", "Export completed to ") + dest + L10N.get("DSO.ExportCompletePost", "."));
}
} catch (IOException e) {
if (interaction != null) {
interaction.reportProblem("File I/O Error", e.getMessage());
} else {
e.printStackTrace();
}
return false;
} finally {
try {
if (buffer != null) {
buffer.close();
}
if (fw != null) {
fw.close();
}
} catch (IOException e) {
if (interaction != null) {
interaction.reportProblem("File I/O Error on Close", e.getMessage());
} else {
e.printStackTrace();
}
return false;
}
}
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.AScriptStep in project cogtool by cogtool.
the class SEDefaultUI method determineNextSelection.
protected boolean determineNextSelection(Script script, Collection<AScriptStep> scriptSteps, int action, int stepIndex, DelayedSelection seln) {
Demonstration demo = script.getDemonstration();
int numDemoSteps = demo.getStepCount();
boolean computableChange;
if (action == Demonstration.ScriptStepChange.ADD_STEP) {
// Select the next item after those that were added
if (scriptSteps != null) {
int numStepsAdded = scriptSteps.size();
stepIndex += numStepsAdded;
computableChange = (numDemoSteps == numStepsAdded);
} else {
stepIndex++;
computableChange = (numDemoSteps == 1);
}
} else {
computableChange = (numDemoSteps == 0);
}
AScriptStep stepToSelect = demo.getStepAt(stepIndex);
seln.addToSelection(stepToSelect);
return computableChange;
}
Aggregations