Search in sources :

Example 6 with ITaskDesign

use of edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign 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 7 with ITaskDesign

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

the class DesignEditorController method createExportDesignToXMLAction.

protected IListenerAction createExportDesignToXMLAction() {
    return new AListenerAction() {

        public boolean performAction(Object actionParms) {
            String defaultFilename = design.getName() + ".xml";
            File exportFile = interaction.selectXMLFile(false, defaultFilename);
            if (exportFile == null) {
                return false;
            }
            OutputStream oStream = null;
            try {
                try {
                    oStream = new FileOutputStream(exportFile);
                    Writer xmlWriter = new BufferedWriter(new OutputStreamWriter(oStream, "UTF-8"));
                    Map<ITaskDesign, TaskApplication> designTAs = project.taskApplicationsForDesign(design);
                    ExportCogToolXML.exportXML(design, designTAs, xmlWriter, "UTF-8");
                    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);
            }
            interaction.setStatusMessage(L10N.get("PC.DesignExportedToXML", "Design exported to XML:") + " " + exportFile.getName());
            return true;
        }
    };
}
Also used : RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) IOException(java.io.IOException) RcvrIOSaveException(edu.cmu.cs.hcii.cogtool.util.RcvrIOSaveException) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) RcvrImageException(edu.cmu.cs.hcii.cogtool.util.RcvrImageException) RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) SAXException(org.xml.sax.SAXException) RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) RcvrUIException(edu.cmu.cs.hcii.cogtool.util.RcvrUIException) IOException(java.io.IOException) RecoverableException(edu.cmu.cs.hcii.cogtool.util.RecoverableException) RcvrIOSaveException(edu.cmu.cs.hcii.cogtool.util.RcvrIOSaveException) 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) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) RecoverableException(edu.cmu.cs.hcii.cogtool.util.RecoverableException)

Example 8 with ITaskDesign

use of edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign 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 9 with ITaskDesign

use of edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign 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)

Example 10 with ITaskDesign

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

the class ProjectController method createScriptViewerAction.

protected IListenerAction createScriptViewerAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            if (prms != null) {
                ProjectSelectionState seln = (ProjectSelectionState) prms;
                // Must have selected tasks and design
                Design design = seln.getSelectedDesign();
                AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
                if ((design == null) || (tasks == null) || (tasks.length == 0)) {
                    return false;
                }
                boolean viewSuccessful = false;
                // Viewing a script only applies to task groups
                for (AUndertaking task : tasks) {
                    if (task.isTaskGroup()) {
                        TaskGroup group = (TaskGroup) task;
                        List<AUndertaking> childTasks = group.getUndertakings();
                        if (childTasks.size() > 0) {
                            AUndertaking firstTask = childTasks.get(0);
                            TaskApplication ta = project.getTaskApplication(firstTask, design);
                            if (ta != null) {
                                ITaskDesign td = project.getTaskDesign(task, design);
                                ScriptViewerController.openController(td, project);
                                viewSuccessful = true;
                            }
                        }
                    }
                }
                if (!viewSuccessful) {
                    interaction.setStatusMessage(L10N.get("PC.NoScriptsToView", "No scripts to view."));
                }
                return true;
            }
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Aggregations

ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)10 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)10 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)5 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)5 RcvrClipboardException (edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException)4 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)4 IOException (java.io.IOException)4 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)3 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)3 TaskParent (edu.cmu.cs.hcii.cogtool.model.TaskParent)3 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Design (edu.cmu.cs.hcii.cogtool.model.Design)2 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)2 RcvrIOSaveException (edu.cmu.cs.hcii.cogtool.util.RcvrIOSaveException)2 RcvrIllegalStateException (edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException)2 RcvrImageException (edu.cmu.cs.hcii.cogtool.util.RcvrImageException)2 RcvrOutOfMemoryException (edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException)2 RecoverableException (edu.cmu.cs.hcii.cogtool.util.RecoverableException)2