Search in sources :

Example 1 with ObjectSaver

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

the class ProjectController method createCopyTaskAction.

// createRenameDesignAction
// Action for CopyTask
protected IListenerAction createCopyTaskAction() {
    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);
            // Can only copy to clipboard if one or more tasks are selected
            if ((tasks != null) && (tasks.length > 0)) {
                try {
                    ObjectSaver s = CogToolClipboard.startClipboardSave(CogToolClipboard.CopyTasks, CogToolClipboard.SAVE_TO_CLIPBOARD);
                    for (AUndertaking task : tasks) {
                        s.saveObject(task);
                    }
                    s.finish();
                    if (tasks.length == 1) {
                        interaction.setStatusMessage(TASK_COPIED);
                    } else {
                        interaction.setStatusMessage(TASKS_COPIED);
                    }
                    return true;
                } catch (IOException e) {
                    throw new RcvrClipboardException(e);
                } catch (OutOfMemoryError error) {
                    throw new RcvrOutOfMemoryException("Copying Tasks", error);
                }
            } else {
                interaction.protestNoSelection();
            }
            return false;
        }
    };
}
Also used : ObjectSaver(edu.cmu.cs.hcii.cogtool.util.ObjectSaver) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException)

Example 2 with ObjectSaver

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

the class ProjectController method createCutDesignAction.

// Action for CutDesign
protected IListenerAction createCutDesignAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            DesignSelectionState selection = (DesignSelectionState) prms;
            Design selectedDesign = selection.getSelectedDesign();
            // Can only cut if a design is currently selected.
            if (selectedDesign != null) {
                if (interaction.confirmDeleteDesign(selectedDesign)) {
                    try {
                        ObjectSaver s = CogToolClipboard.startClipboardDesignSave(project, CogToolClipboard.SAVE_TO_CLIPBOARD);
                        // Delete selected design, copying to the clipboard
                        deleteDesign(selectedDesign, s);
                        s.finish();
                        return true;
                    } catch (IOException e) {
                        throw new RcvrClipboardException(e);
                    } catch (OutOfMemoryError error) {
                        throw new RcvrOutOfMemoryException("Cutting Design", error);
                    }
                }
            } else {
                interaction.protestNoSelection();
            }
            return false;
        }
    };
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) ObjectSaver(edu.cmu.cs.hcii.cogtool.util.ObjectSaver) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) DesignSelectionState(edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState)

Example 3 with ObjectSaver

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

the class ProjectController method createCutTaskAction.

// Action for CutTask
protected IListenerAction createCutTaskAction() {
    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 cut if one or more tasks are currently selected.
            if ((selectedTasks != null) && (selectedTasks.length > 0)) {
                try {
                    ObjectSaver saver = CogToolClipboard.startClipboardSave(CogToolClipboard.CopyTasks, CogToolClipboard.SAVE_TO_CLIPBOARD);
                    deleteTasks(selectedTasks, saver, undoMgr);
                    // flush!
                    saver.finish();
                    return true;
                } catch (IOException e) {
                    throw new RcvrClipboardException("Could not execute cut", e);
                } catch (OutOfMemoryError error) {
                    throw new RcvrOutOfMemoryException("Cutting Tasks", error);
                }
            } else {
                interaction.protestNoSelection();
            }
            return false;
        }
    };
}
Also used : ObjectSaver(edu.cmu.cs.hcii.cogtool.util.ObjectSaver) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException)

Example 4 with ObjectSaver

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

the class ProjectController method createCopyDesignAction.

// Action for CopyDesign
protected IListenerAction createCopyDesignAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            DesignSelectionState seln = (DesignSelectionState) prms;
            Design design = seln.getSelectedDesign();
            // Can only copy if a design is currently selected.
            if (design != null) {
                try {
                    ObjectSaver s = CogToolClipboard.startClipboardDesignSave(project, CogToolClipboard.SAVE_TO_CLIPBOARD);
                    saveDesignToClipboard(design, s);
                    s.finish();
                    interaction.setStatusMessage(DESIGN_COPIED);
                    return true;
                } catch (IOException e) {
                    throw new RcvrClipboardException(e);
                } catch (OutOfMemoryError error) {
                    throw new RcvrOutOfMemoryException("Copying Design", error);
                }
            } else {
                interaction.protestNoSelection();
            }
            return false;
        }
    };
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) ObjectSaver(edu.cmu.cs.hcii.cogtool.util.ObjectSaver) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) DesignSelectionState(edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState)

Example 5 with ObjectSaver

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

the class DesignEditorController method copyFrames.

protected void copyFrames(Frame[] frames) {
    try {
        // Passing the set of frames as part of purpose allows us
        // to copy only those transitions that link those frames.
        ObjectSaver s = CogToolClipboard.startClipboardSave(CogToolClipboard.CopyFrames, frames, CogToolClipboard.SAVE_TO_CLIPBOARD);
        for (Frame frame : frames) {
            s.saveObject(frame);
        }
        s.finish();
    } catch (IOException e) {
        throw new RcvrClipboardException(e);
    } catch (IllegalStateException e) {
        throw new RcvrClipboardException(e);
    } catch (OutOfMemoryError error) {
        throw new RcvrOutOfMemoryException("Copying Frames", error);
    }
}
Also used : ObjectSaver(edu.cmu.cs.hcii.cogtool.util.ObjectSaver) RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) IOException(java.io.IOException)

Aggregations

ObjectSaver (edu.cmu.cs.hcii.cogtool.util.ObjectSaver)5 RcvrClipboardException (edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException)5 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)5 RcvrOutOfMemoryException (edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException)5 IOException (java.io.IOException)5 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)4 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)2 Design (edu.cmu.cs.hcii.cogtool.model.Design)2 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)2 DesignSelectionState (edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState)2 TaskSelectionState (edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState)2 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)1 RcvrIllegalStateException (edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException)1