Search in sources :

Example 1 with RcvrOutOfMemoryException

use of edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException 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 RcvrOutOfMemoryException

use of edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException 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 RcvrOutOfMemoryException

use of edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException 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 RcvrOutOfMemoryException

use of edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException 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 RcvrOutOfMemoryException

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

the class DesignEditorCmd method copyElements.

public static void copyElements(Design design, FrameElement[] selectedElts, Iterator<FrameElement> eltsToCopy, boolean saveToClipboard) {
    try {
        // Set up a clipboard saver.  Indicate that no transitions
        // should be copied.
        CogToolClipboard.ClipboardClassSaver s = CogToolClipboard.startClipboardSave(CogToolClipboard.CopyWidgets, selectedElts, saveToClipboard);
        // Iterate through the widgets and save the selected items.
        while (eltsToCopy.hasNext()) {
            FrameElement elt = eltsToCopy.next();
            //       get pasted.
            if (!(elt instanceof ChildWidget)) {
                s.saveObject(elt);
            }
        }
        s.finish();
        if (!saveToClipboard) {
            FrameTemplateSupport.setFrameTemplate(design, s.getSavedString());
        }
    } catch (IOException e) {
        throw new RcvrClipboardException(e);
    } catch (OutOfMemoryError error) {
        throw new RcvrOutOfMemoryException("Copying Widgets", error);
    }
}
Also used : RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) CogToolClipboard(edu.cmu.cs.hcii.cogtool.CogToolClipboard) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IOException(java.io.IOException) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget)

Aggregations

RcvrClipboardException (edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException)6 RcvrOutOfMemoryException (edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException)6 IOException (java.io.IOException)6 ObjectSaver (edu.cmu.cs.hcii.cogtool.util.ObjectSaver)5 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)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 CogToolClipboard (edu.cmu.cs.hcii.cogtool.CogToolClipboard)1 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)1 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)1 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)1 RcvrIllegalStateException (edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException)1