Search in sources :

Example 16 with IListenerAction

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

the class ProjectController method createSetProjDefaultAlg.

protected IListenerAction createSetProjDefaultAlg(final ProjectLID lid, final String label, final IPredictionAlgo alg) {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            final IPredictionAlgo oldDefaultAlg = project.getDefaultAlgo();
            project.setDefaultAlgo(alg);
            undoMgr.addEdit(new AUndoableEdit(lid) {

                @Override
                public String getPresentationName() {
                    return label;
                }

                @Override
                public void redo() {
                    super.redo();
                    project.setDefaultAlgo(alg);
                }

                @Override
                public void undo() {
                    super.undo();
                    project.setDefaultAlgo(oldDefaultAlg);
                }
            });
            return true;
        }
    };
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)

Example 17 with IListenerAction

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

Example 18 with IListenerAction

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

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

the class ProjectController method createDisplayTraces.

// Action for DisplayTraces
protected IListenerAction createDisplayTraces() {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            ProjectSelectionState sel = (ProjectSelectionState) actionParms;
            Design design = sel.getSelectedDesign();
            AUndertaking[] tasks = sel.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION);
            if (design != null) {
                if ((tasks != null) && (tasks.length > 0)) {
                    for (AUndertaking task : tasks) {
                        displayTraces(task, design);
                    }
                } else {
                    Iterator<AUndertaking> allTasks = project.getUndertakings().iterator();
                    while (allTasks.hasNext()) {
                        displayTraces(allTasks.next(), design);
                    }
                }
            } else if ((tasks != null) && (tasks.length > 0)) {
                for (AUndertaking task : tasks) {
                    Iterator<Design> allDesigns = project.getDesigns().iterator();
                    while (allDesigns.hasNext()) {
                        displayTraces(task, allDesigns.next());
                    }
                }
            }
            return true;
        }
    };
}
Also used : 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) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Iterator(java.util.Iterator)

Example 20 with IListenerAction

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

the class SEDemoController method createSetHandLocationAction.

protected IListenerAction createSetHandLocationAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            HandLocation handLoc = (HandLocation) prms;
            if (handLoc != null) {
                setHandLocationAction(handLoc);
                return true;
            }
            interaction.protestNoHandLocation();
            return false;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) HandLocation(edu.cmu.cs.hcii.cogtool.model.HandLocation)

Aggregations

IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)94 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)30 Design (edu.cmu.cs.hcii.cogtool.model.Design)29 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)29 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)23 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)23 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)21 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)19 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)17 IOException (java.io.IOException)14 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)13 TaskSelectionState (edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState)12 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)10 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)10 DesignSelectionState (edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState)10 FrameEditorSelectionState (edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState)9 FrameSelectionState (edu.cmu.cs.hcii.cogtool.ui.FrameSelectionState)9 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)8 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)8 File (java.io.File)8