Search in sources :

Example 61 with AUndertaking

use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.

the class ProjectController method createGenerateDictionaryAction.

protected IListenerAction createGenerateDictionaryAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return ProjectSelectionState.class;
        }

        public boolean performAction(Object prms) {
            ProjectSelectionState seln = (ProjectSelectionState) prms;
            AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
            Design d = seln.getSelectedDesign();
            boolean hasDict = false;
            ITermSimilarity defaultAlg = ISimilarityDictionary.DEFAULT_ALG;
            if (d != null) {
                ISimilarityDictionary dict = (ISimilarityDictionary) d.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
                if (!NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY)) {
                    hasDict = true;
                    defaultAlg = dict.getCurrentAlgorithm();
                }
            } else {
                // No design selected, so just show the compute options
                hasDict = true;
            }
            ProjectInteraction.GenerateEntriesData requestData = requestGenerateParms(generateEntriesMessage, defaultAlg, hasDict);
            if (requestData == null) {
                return false;
            }
            GenerateDictEntriesWorkThread workThread = new GenerateDictEntriesWorkThread(interaction, d, tasks, project, undoMgr, requestData);
            CogTool.logger.info(String.format("Generating dictionary for design %s in project %s.", d.getName(), getProject().getName()));
            ThreadManager.startNewThread(workThread);
            return true;
        }
    };
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ITermSimilarity(edu.cmu.cs.hcii.cogtool.model.ITermSimilarity) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary) ProjectInteraction(edu.cmu.cs.hcii.cogtool.ui.ProjectInteraction)

Example 62 with AUndertaking

use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.

the class ProjectController method createDeleteTaskAction.

// createDeleteDesignAction
// Action for DeleteTask
protected IListenerAction createDeleteTaskAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return TaskSelectionState.class;
        }

        public boolean performAction(Object prms) {
            TaskSelectionState selection = (TaskSelectionState) prms;
            AUndertaking[] selectedTasks = selection.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
            // Can only delete if one or more tasks are currently selected.
            if ((selectedTasks != null) && (selectedTasks.length > 0)) {
                if (interaction.confirmDeleteTasks(selectedTasks)) {
                    // Delete tasks without copying to the clipboard.
                    deleteTasks(selectedTasks, null, undoMgr);
                    return true;
                }
            } else {
                interaction.protestNoSelection();
            }
            return false;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState)

Example 63 with AUndertaking

use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.

the class ProjectController method createUngroupAction.

protected IListenerAction createUngroupAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return TaskSelectionState.class;
        }

        public boolean performAction(Object prms) {
            TaskSelectionState seln = (TaskSelectionState) prms;
            AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION | TaskSelectionState.TASK_GROUPS_ONLY);
            if ((tasks == null) || (tasks.length == 0)) {
                interaction.protestNoSelection();
                return false;
            }
            CompoundUndoableEdit editSeq = new CompoundUndoableEdit(L10N.get("PC.Ungroup", "Ungroup"), ProjectLID.Ungroup);
            for (AUndertaking task : tasks) {
                if (task.isTaskGroup()) {
                    TaskGroup group = (TaskGroup) task;
                    List<AUndertaking> childTasks = group.getUndertakings();
                    int numChildTasks = childTasks.size();
                    if (numChildTasks > 0) {
                        AUndertaking[] promoteTasks = new AUndertaking[numChildTasks];
                        childTasks.toArray(promoteTasks);
                        for (int j = numChildTasks - 1; j >= 0; j--) {
                            promoteTask(promoteTasks[j], ProjectLID.Ungroup, editSeq);
                        }
                    }
                }
            }
            deleteTasks(tasks, null, editSeq);
            if (editSeq.isSignificant()) {
                editSeq.end();
                undoMgr.addEdit(editSeq);
            }
            return true;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 64 with AUndertaking

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;
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) Task(edu.cmu.cs.hcii.cogtool.model.Task) TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 65 with AUndertaking

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;
}
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)

Aggregations

AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)89 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)38 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)35 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)30 Design (edu.cmu.cs.hcii.cogtool.model.Design)28 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)24 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)18 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)17 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)14 Script (edu.cmu.cs.hcii.cogtool.model.Script)13 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)13 IOException (java.io.IOException)12 TaskSelectionState (edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState)11 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)10 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)10 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)10 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)9 TaskParent (edu.cmu.cs.hcii.cogtool.model.TaskParent)9 TreeItem (org.eclipse.swt.widgets.TreeItem)9 ArrayList (java.util.ArrayList)7