Search in sources :

Example 41 with TaskApplication

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);
                }
            }
        }
    };
}
Also used : ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication)

Example 42 with TaskApplication

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;
        }
    };
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil)

Example 43 with TaskApplication

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;
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) FileWriter(java.io.FileWriter) ExportIOException(edu.cmu.cs.hcii.cogtool.ui.DesignExportToHTML.ExportIOException) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) ExportIOException(edu.cmu.cs.hcii.cogtool.ui.DesignExportToHTML.ExportIOException) IOException(java.io.IOException) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) BufferedWriter(java.io.BufferedWriter)

Example 44 with TaskApplication

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));
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ArrayList(java.util.ArrayList) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 45 with TaskApplication

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);
            }
        }
    });
}
Also used : ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication)

Aggregations

TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)63 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)38 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)22 Design (edu.cmu.cs.hcii.cogtool.model.Design)20 Script (edu.cmu.cs.hcii.cogtool.model.Script)20 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)17 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)16 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)15 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)14 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)12 IOException (java.io.IOException)12 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)11 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)11 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)10 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)10 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)10 APredictionResult (edu.cmu.cs.hcii.cogtool.model.APredictionResult)8 File (java.io.File)8 RcvrIllegalStateException (edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException)7 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)5