Search in sources :

Example 16 with TaskApplication

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

the class ProjectController method saveDesignToClipboard.

// createPasteAction
// Support for copying design and associated TA's to clipboard
protected void saveDesignToClipboard(Design design, ObjectSaver saver) {
    try {
        saver.saveObject(design);
        Iterator<AUndertaking> rootTasks = project.getUndertakings().iterator();
        while (rootTasks.hasNext()) {
            AUndertaking childTask = rootTasks.next();
            saver.saveObject(childTask);
        }
        Map<ITaskDesign, TaskApplication> associatedTAs = project.taskApplicationsForDesign(design);
        Iterator<TaskApplication> taskApps = associatedTAs.values().iterator();
        while (taskApps.hasNext()) {
            TaskApplication ta = taskApps.next();
            saver.saveObject(ta);
        }
    } catch (IOException ex) {
        throw new RcvrClipboardException(ex);
    }
}
Also used : ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException)

Example 17 with TaskApplication

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

the class ProjectController method recomputeScripts.

protected boolean recomputeScripts(AUndertaking task, Design design, DemoStateManager demoStateMgr, ComputeMessages computeMsgs, IUndoableEditSequence editSequence) {
    if (CogToolPref.isTracingOverride == null && !CogToolPref.IS_TRACING.getBoolean()) {
        Boolean answer = getInteraction().confirmNoTracing();
        if (answer == null) {
            // canceled
            return false;
        } else if (answer.booleanValue()) {
            CogToolPref.IS_TRACING.setBoolean(true);
        }
    }
    if (task.isTaskGroup()) {
        if (!NullSafe.equals(WidgetAttributes.NO_CONTEXT, task.getAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR))) {
            return computeSnifAct(design, task, editSequence, null);
        }
        Iterator<AUndertaking> allTasks = ((TaskGroup) task).getUndertakings().iterator();
        CompoundUndoableEdit groupEditSeq = new CompoundUndoableEdit(RECOMPUTE_SCRIPTS, ProjectLID.RecomputeScript);
        while (allTasks.hasNext()) {
            if (!recomputeScripts(allTasks.next(), design, demoStateMgr, computeMsgs, groupEditSeq)) {
                return false;
            }
        }
        if (groupEditSeq.isSignificant()) {
            groupEditSeq.end();
            editSequence.addEdit(groupEditSeq);
        }
        return true;
    }
    TaskApplication ta = project.getTaskApplication(task, design);
    if (ta != null) {
        IPredictionAlgo activeAlg = ta.determineActiveAlgorithm(project);
        if (activeAlg == SNIFACTPredictionAlgo.ONLY) {
            return computeSnifAct(design, task, editSequence, null);
        }
        if (computeMsgs.canComputeScript(ta, demoStateMgr, editSequence)) {
            if (!activeAlg.allowsComputation()) {
                interaction.setStatusMessage(algDisallowsComputation);
                interaction.reportProblem(RECOMPUTE_SCRIPTS, algDisallowsComputation);
                return false;
            } else if (!ta.getDemonstration().isStartFrameChosen()) {
                // nothing to compute
                interaction.setStatusMessage(noStartFrameChosen);
                return false;
            }
            IUndoableEdit edit = ComputePredictionCmd.computeAllPredictions(project, ta, activeAlg, ta.determineComputeInBackground(project), interaction);
            if (edit != null) {
                ta.setActiveAlgorithm(activeAlg);
                editSequence.addEdit(edit);
            } else {
                interaction.setStatusMessage(computeHadNoResult);
            }
        } else {
            interaction.setStatusMessage(cannotRecomputeInvalid);
        }
    } else {
        if (project.getDefaultAlgo() == SNIFACTPredictionAlgo.ONLY) {
            return computeSnifAct(design, task, editSequence, null);
        }
        interaction.setStatusMessage(cannotRecomputeNoDemo);
    }
    return true;
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)

Example 18 with TaskApplication

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

the class ProjectController method createVisualization.

public boolean createVisualization(Design design, AUndertaking task, int strategy) {
    TaskApplication ta = getVisualizationTA(design, task);
    if (ta != null) {
        IPredictionAlgo activeAlgo = ta.determineActiveAlgorithm(project);
        CognitiveModelGenerator gen = ta.getFirstModelGenerator();
        if (ta.getResult(gen, activeAlgo) != null) {
            PERTChartController c = PERTChartController.openController(ta, gen, activeAlgo, project, strategy, interaction);
            return (c != null);
        }
    }
    return false;
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)

Example 19 with TaskApplication

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

the class ProjectController method exportDesignToXML.

private boolean exportDesignToXML(Design design) {
    String defaultFilename = ((design != null) ? design.getName() : project.getName()) + ".xml";
    File exportFile = null;
    if (interaction != null && CogTool.exportCSVKludgeDir == null) {
        exportFile = interaction.selectXMLFile(false, defaultFilename);
    } else {
        exportFile = new File(CogTool.exportCSVKludgeDir, defaultFilename);
    }
    if (exportFile == null) {
        return false;
    }
    OutputStream oStream = null;
    String completionMsg;
    try {
        try {
            oStream = new FileOutputStream(exportFile);
            Writer xmlWriter = new BufferedWriter(new OutputStreamWriter(oStream, "UTF-8"));
            if (design == null) {
                ExportCogToolXML.exportXML(project, xmlWriter, "UTF-8");
                completionMsg = allDesignsExportedToXml;
            } else {
                Map<ITaskDesign, TaskApplication> designTAs = project.taskApplicationsForDesign(design);
                ExportCogToolXML.exportXML(design, designTAs, xmlWriter, "UTF-8");
                completionMsg = designExportedToXml;
            }
            xmlWriter.flush();
        } finally {
            if (oStream != null) {
                oStream.close();
            }
        }
    } catch (IllegalArgumentException e) {
        throw new RcvrIllegalStateException("Invalid argument exporting to XML", e);
    } catch (IllegalStateException e) {
        throw new RcvrIllegalStateException("Exporting to XML", e);
    } catch (IOException e) {
        throw new RcvrIOSaveException("Exporting to XML", e);
    } catch (Exception e) {
        throw new RecoverableException("Exporting to XML", e);
    }
    if (interaction != null) {
        interaction.setStatusMessage(completionMsg + " " + exportFile.getAbsolutePath());
    }
    return true;
}
Also used : RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) RcvrIOSaveException(edu.cmu.cs.hcii.cogtool.util.RcvrIOSaveException) RcvrXMLParsingException(edu.cmu.cs.hcii.cogtool.util.RcvrXMLParsingException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RcvrUnimplementedFnException(edu.cmu.cs.hcii.cogtool.util.RcvrUnimplementedFnException) RcvrCannotUndoRedoException(edu.cmu.cs.hcii.cogtool.util.RcvrCannotUndoRedoException) IOException(java.io.IOException) RcvrImportException(edu.cmu.cs.hcii.cogtool.util.RcvrImportException) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) RcvrImageException(edu.cmu.cs.hcii.cogtool.util.RcvrImageException) RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) FileNotFoundException(java.io.FileNotFoundException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) SAXException(org.xml.sax.SAXException) RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) RcvrParsingException(edu.cmu.cs.hcii.cogtool.util.RcvrParsingException) RecoverableException(edu.cmu.cs.hcii.cogtool.util.RecoverableException) RcvrIOSaveException(edu.cmu.cs.hcii.cogtool.util.RcvrIOSaveException) RcvrIOTempException(edu.cmu.cs.hcii.cogtool.util.RcvrIOTempException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) BufferedWriter(java.io.BufferedWriter) RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) File(java.io.File) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) FileWriter(java.io.FileWriter) RecoverableException(edu.cmu.cs.hcii.cogtool.util.RecoverableException)

Example 20 with TaskApplication

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

the class ProjectController method createPasteAction.

// Action for Paste
protected IListenerAction createPasteAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            ProjectSelectionState seln = (ProjectSelectionState) prms;
            try {
                // Check for CogTool objects to paste
                Collection<Object> objects = CogToolClipboard.fetchCogToolObjects(project);
                // designs and tasks only
                int numObjectsPasted = 0;
                if ((objects != null) && (objects.size() > 0)) {
                    // Paste tasks as children of the selected TaskGroup
                    AUndertaking[] selectedTasks = seln.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
                    TaskGroup taskParent = seln.getSelectedTaskParent();
                    int index;
                    // index at which new pasted Tasks will be placed.
                    if (taskParent != null) {
                        AUndertaking last = selectedTasks[selectedTasks.length - 1];
                        index = taskParent.getUndertakings().indexOf(last) + 1;
                    } else {
                        index = findLastSelectedRoot(selectedTasks);
                    }
                    // Create undo support
                    String presentationName = PASTE;
                    CompoundUndoableEdit editSeq = new CompoundUndoableEdit(presentationName, ProjectLID.Paste);
                    // If task applications are pasted, they will have
                    // null Design fields; they should "arrive" after
                    // the Design being pasted at the same time!
                    Design newDesign = null;
                    // Existing tasks are to be re-used if the paste
                    // is within the same project as the copy/cut.
                    Map<AUndertaking, AUndertaking> reuseTasks = null;
                    Iterator<Object> objIt = objects.iterator();
                    while (objIt.hasNext()) {
                        Object o = objIt.next();
                        // unique name and create and place the design.
                        if (o instanceof Design) {
                            newDesign = (Design) o;
                            makeDesignNameUnique(newDesign);
                            // Add an undo step after creating/placing
                            ProjectCmd.addNewDesign(project, newDesign, seln.getSelectedDesign(), presentationName, editSeq);
                            numObjectsPasted++;
                        } else // or to the Project.  Create and place.
                        if (o instanceof AUndertaking) {
                            AUndertaking task = (AUndertaking) o;
                            // project or pasting copied tasks
                            if (reuseTasks == null) {
                                pasteTask(task, taskParent, index++, editSeq, presentationName);
                                numObjectsPasted++;
                            } else {
                                // In this case, a copied design is
                                // being pasted into the same project.
                                // Map each undertaking to the
                                // corresponding one in the current project
                                mapProjectTasks(task, project, reuseTasks, editSeq, presentationName);
                            }
                        } else // along when copying an Design.
                        if (o instanceof TaskApplication) {
                            TaskApplication taskApp = (TaskApplication) o;
                            if (reuseTasks != null) {
                                AUndertaking reuseTask = reuseTasks.get(taskApp.getTask());
                                if (reuseTask != null) {
                                    taskApp.setTask(reuseTask);
                                }
                            }
                            // The undo edit for adding the Design will
                            // remove and restore the task-applications;
                            // simply add to the project.
                            project.setTaskApplication(taskApp);
                        } else if (o instanceof CogToolClipboard.ProjectScope) {
                            CogToolClipboard.ProjectScope projectScope = (CogToolClipboard.ProjectScope) o;
                            // a copied design into the same project
                            if (projectScope.getProject() != null) {
                                reuseTasks = new HashMap<AUndertaking, AUndertaking>();
                            }
                        }
                    }
                    // Done with undo/redo steps; add the compound change
                    // to the undo manager.
                    editSeq.end();
                    undoMgr.addEdit(editSeq);
                    interaction.setStatusMessage(numObjectsPasted + " " + pasteComplete);
                } else {
                    interaction.setStatusMessage(nothingPasted);
                }
                return true;
            } catch (IOException e) {
                throw new RcvrClipboardException(e);
            } catch (SAXException e) {
                throw new RcvrClipboardException(e);
            } catch (ParserConfigurationException e) {
                throw new RcvrClipboardException(e);
            } catch (ClipboardUtil.ClipboardException e) {
                throw new RcvrClipboardException(e);
            }
        }
    };
}
Also used : ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) HashMap(java.util.HashMap) CogToolClipboard(edu.cmu.cs.hcii.cogtool.CogToolClipboard) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) SAXException(org.xml.sax.SAXException) 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) ClipboardUtil(edu.cmu.cs.hcii.cogtool.util.ClipboardUtil) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

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