Search in sources :

Example 6 with RcvrIOException

use of edu.cmu.cs.hcii.cogtool.util.RcvrIOException in project cogtool by cogtool.

the class DefaultController method save.

/**
     * Perform a Save operation, using a stored save location.
     *
     * @return true if file was saved, false otherwise
     * @throws RcvrIOException if the save operation fails
     */
protected boolean save() {
    try {
        // Save to this file's original location.
        project.setBuildVersion(CogTool.getVersion());
        persist.save(project, null);
        // Tell undo manager(s) that a save has just occurred
        try {
            UndoManager.markSavePoint(project);
        } catch (IllegalStateException ex) {
            throw new RcvrCannotUndoRedoException("Marking save point", ex);
        }
        return true;
    } catch (IOException e) {
        throw new RcvrIOSaveException("Error persisting project: " + e.getMessage(), e);
    }
}
Also used : RcvrCannotUndoRedoException(edu.cmu.cs.hcii.cogtool.util.RcvrCannotUndoRedoException) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) RcvrIOSaveException(edu.cmu.cs.hcii.cogtool.util.RcvrIOSaveException)

Example 7 with RcvrIOException

use of edu.cmu.cs.hcii.cogtool.util.RcvrIOException in project cogtool by cogtool.

the class DefaultController method saveAs.

/**
     * Perform a Save As... operation, prompting for a save location.
     *
     * @return true if file was saved, false otherwise
     * @throws RcvrIOException if the save operation fails
     */
protected boolean saveAs() {
    Interaction stdInteraction = getUI().getStandardInteraction();
    try {
        boolean nameIsInUse;
        File saveLoc;
        do {
            // Request a new file name, using the project's current name
            // as the default.
            // TODO: It is "evil" that the test for existing files is
            //       hidden within this call; separate at some point (mlh)
            saveLoc = stdInteraction.selectFileDest(project.getName());
            // If the save dialog was canceled, do nothing.
            if (saveLoc == null) {
                return false;
            }
            // If saveLoc is already open, refuse to save there.
            nameIsInUse = persist.isRegistered(saveLoc, project);
            if (nameIsInUse) {
                switch(stdInteraction.protestBeingEdited(saveLoc)) {
                    case Interaction.SAVE:
                        {
                            nameIsInUse = false;
                            break;
                        }
                    case Interaction.NO_SAVE:
                        {
                            // Simply loop to ask for a new name
                            break;
                        }
                    case Interaction.CANCEL:
                        {
                            return false;
                        }
                }
            }
        } while (nameIsInUse);
        CogToolPref.setRecent(saveLoc.getCanonicalPath());
        // Set the title BEFORE saving the project.
        String name = saveLoc.getName();
        // Remove the .cgt, if it is there.
        int periodIndex = name.lastIndexOf('.');
        if (periodIndex > 0) {
            name = name.substring(0, periodIndex);
        }
        project.setName(name);
        // Save to the selected location.
        project.setBuildVersion(CogTool.getVersion());
        persist.save(project, saveLoc);
        // Tell undo manager(s) that a save has just occurred
        try {
            UndoManager.markSavePoint(project);
        } catch (IllegalStateException ex) {
            throw new RcvrCannotUndoRedoException("Marking save point", ex);
        }
        return true;
    } catch (IOException e) {
        throw new RcvrIOSaveException("Error persisting project: " + e.getMessage(), e);
    }
}
Also used : RcvrCannotUndoRedoException(edu.cmu.cs.hcii.cogtool.util.RcvrCannotUndoRedoException) Interaction(edu.cmu.cs.hcii.cogtool.ui.Interaction) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) File(java.io.File) RcvrIOSaveException(edu.cmu.cs.hcii.cogtool.util.RcvrIOSaveException)

Aggregations

RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)7 IOException (java.io.IOException)6 File (java.io.File)5 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)4 Design (edu.cmu.cs.hcii.cogtool.model.Design)4 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)4 Script (edu.cmu.cs.hcii.cogtool.model.Script)4 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)4 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)4 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)4 RcvrUnimplementedFnException (edu.cmu.cs.hcii.cogtool.util.RcvrUnimplementedFnException)4 ACTRPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.ACTRPredictionAlgo)3 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)3 RcvrIOSaveException (edu.cmu.cs.hcii.cogtool.util.RcvrIOSaveException)3 RcvrIllegalStateException (edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException)3 RcvrCannotUndoRedoException (edu.cmu.cs.hcii.cogtool.util.RcvrCannotUndoRedoException)2 Interaction (edu.cmu.cs.hcii.cogtool.ui.Interaction)1 FileOutputStream (java.io.FileOutputStream)1 PrintWriter (java.io.PrintWriter)1 Matcher (java.util.regex.Matcher)1