Search in sources :

Example 6 with DefaultModelGeneratorState

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

the class SEDemoController method deleteScriptStep.

// createInsertSelfTransitionAction
/**
     * Perform the operations needed to DELETE a script Action
     *
     * @param selection
     * @return
     */
protected boolean deleteScriptStep(SEDemoSelectionState selection) {
    // In case we need to go back to edit initial state.
    final CognitiveModelGenerator modelGen = script.getModelGenerator();
    final Demonstration demo = script.getDemonstration();
    final TaskApplication taskApp = demo.getTaskApplication();
    // If there is no selected action, try to delete the last item
    DefaultModelGeneratorState selectedState = selection.getSelectedState();
    final DefaultModelGeneratorState stateToDelete = getValidStepState(selectedState);
    IUndoableEdit edit;
    // If no states, go back to edit initial state
    if ((stateToDelete == null) || stateToDelete.getScriptStep().isInitiallyGenerated()) {
        closeWindow(false);
        demo.setStartFrameChosen(false);
        SEFrameChooserController.openController(taskApp, modelGen, project);
        edit = new AUndoableEdit(SEDemoLID.Delete) {

            protected DemoScriptCmd.ComputationUndoRedo computeUndoRedo = new DemoScriptCmd.ComputationUndoRedo(script);

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

            @Override
            public void redo() {
                super.redo();
                DefaultController seDemoController = ControllerRegistry.ONLY.findOpenController(script);
                if (seDemoController != null) {
                    seDemoController.closeWindow(false);
                }
                demo.setStartFrameChosen(false);
                SEFrameChooserController.openController(taskApp, modelGen, project);
                computeUndoRedo.redoChanges();
            }

            @Override
            public void undo() {
                super.undo();
                if (demo.getStartFrame() != null) {
                    demo.setStartFrameChosen(true);
                    // Close the frame chooser window.
                    DefaultController frameChooserController = ControllerRegistry.ONLY.findOpenController(taskApp);
                    if (frameChooserController != null) {
                        frameChooserController.closeWindow(false);
                    }
                    // Open the new demo view window
                    try {
                        SEDemoController.openController(taskApp, modelGen, project);
                    } catch (GraphicsUtil.ImageException ex) {
                        interaction.protestInvalidImageFile();
                    }
                    computeUndoRedo.undoChanges();
                }
            }
        };
        UndoManager seFrameMgr = UndoManager.getUndoManager(taskApp, project);
        seFrameMgr.addEdit(edit);
        undoMgr.addEdit(edit);
        return true;
    }
    AScriptStep step = stateToDelete.getScriptStep();
    // If a generated think step, simply delete
    if ((step instanceof ThinkScriptStep) && !step.isInsertedByUser()) {
        edit = new AUndoableEdit(SEDemoLID.Delete) {

            protected int scriptIndex = script.removeState(stateToDelete);

            protected DemoScriptCmd.ComputationUndoRedo computeUndoRedo = new DemoScriptCmd.ComputationUndoRedo(script);

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

            @Override
            public void redo() {
                super.redo();
                script.removeState(scriptIndex);
                computeUndoRedo.redoChanges();
            }

            @Override
            public void undo() {
                super.undo();
                script.insertState(stateToDelete, scriptIndex);
                computeUndoRedo.undoChanges();
            }
        };
    } else {
        final AScriptStep demoStep = step.getOwner();
        // There are no "new" steps to replace with when deleting
        Set<AScriptStep> emptyDemoSteps = new HashSet<AScriptStep>();
        if (demoStep.getCurrentFrame() == demoStep.getDestinationFrame()) {
            final int atIndex = demo.removeStep(demoStep);
            final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, demoStep, interaction);
            Set<AScriptStep> oldDemoSteps = Collections.singleton(demoStep);
            edit = new DemoStateManager.ADemoUndoableEdit(SEDemoLID.Delete, demo, emptyDemoSteps, oldDemoSteps, demoStateMgr) {

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

                @Override
                public void redo() {
                    super.redo();
                    demo.removeStep(atIndex);
                    DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
                }

                @Override
                public void undo() {
                    super.undo();
                    demo.insertStep(demoStep, atIndex);
                    DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
                }
            };
        } else {
            if ((selectedState != null) && (demoStep != demo.getLastStep()) && !interaction.confirmDeleteScriptStep()) {
                return false;
            }
            Set<AScriptStep> oldDemoSteps = new LinkedHashSet<AScriptStep>();
            final int atIndex = demo.replaceSteps(demoStep, emptyDemoSteps, oldDemoSteps);
            final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, demoStep, interaction);
            edit = new DemoStateManager.ADemoUndoableEdit(SEDemoLID.Delete, demo, emptyDemoSteps, oldDemoSteps, demoStateMgr) {

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

                @Override
                public void redo() {
                    super.redo();
                    demo.replaceSteps(atIndex, redoDemoSteps);
                    DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
                }

                @Override
                public void undo() {
                    super.undo();
                    demo.replaceSteps(atIndex, undoDemoSteps);
                    DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
                }
            };
        }
    }
    CompoundUndoableEdit editSequence = new CompoundUndoableEdit(DELETE_STEP, SEDemoLID.Delete);
    editSequence.addEdit(edit);
    if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
        DemoScriptCmd.regenerateScripts(project, demo, demoStateMgr, interaction, editSequence);
    }
    editSequence.end();
    undoMgr.addEdit(editSequence);
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ComputationUndoRedo(edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep) UndoManager(edu.cmu.cs.hcii.cogtool.util.UndoManager) ComputationUndoRedo(edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 7 with DefaultModelGeneratorState

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

the class SEDemoController method performChangeDelay.

// performInsertDelay
protected boolean performChangeDelay(SEDemoSelectionState selection) {
    DefaultModelGeneratorState selectedState = selection.getSelectedState();
    if ((selectedState == null) || !(selectedState.getScriptStep() instanceof DelayScriptStep)) {
        interaction.protestNotDelayStep();
        return false;
    }
    final DelayScriptStep delayStep = (DelayScriptStep) selectedState.getScriptStep();
    final double oldDuration = delayStep.getDelayDuration();
    final String oldLabel = delayStep.getLabel();
    final SEDemoInteraction.TimedActionData newData = getTimedActionData(oldDuration, oldLabel, IS_WAIT);
    if (newData == null) {
        return false;
    }
    delayStep.setDelayDuration(newData.duration);
    delayStep.setLabel(newData.labelString);
    final Collection<ComputationUndoRedo> computeUndoRedos = resetComputations();
    IUndoableEdit edit = new AUndoableEdit(SEDemoLID.ChangeWaitProperties) {

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

        @Override
        public void redo() {
            super.redo();
            delayStep.setDelayDuration(newData.duration);
            delayStep.setLabel(newData.labelString);
            DemoScriptCmd.redoAllChanges(computeUndoRedos);
        }

        @Override
        public void undo() {
            super.undo();
            delayStep.setDelayDuration(oldDuration);
            delayStep.setLabel(oldLabel);
            DemoScriptCmd.undoAllChanges(computeUndoRedos);
        }
    };
    undoMgr.addEdit(edit);
    return true;
}
Also used : DelayScriptStep(edu.cmu.cs.hcii.cogtool.model.DelayScriptStep) ComputationUndoRedo(edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) SEDemoInteraction(edu.cmu.cs.hcii.cogtool.ui.SEDemoInteraction) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 8 with DefaultModelGeneratorState

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

the class SEDemoController method setHandLocationAction.

protected void setHandLocationAction(final HandLocation handLoc) {
    final Demonstration demo = script.getDemonstration();
    final boolean mouseHand = demo.getMouseHand();
    final DefaultModelGeneratorState initialState = demo.getInitialState();
    final HandLocation oldLoc = initialState.getHandLocation(mouseHand);
    final DemoStateManager.IConformanceUndoRedo conformanceUndoRedo = demoStateMgr.restoreConformance(demo);
    initialState.setHandLocation(mouseHand, handLoc);
    demo.alertInitialStateChange();
    final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, 0, demo.getStepAt(0), interaction);
    IUndoableEdit edit = new AUndoableEdit(SEDemoLID.SetHandLocation) {

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

        @Override
        public void redo() {
            super.redo();
            conformanceUndoRedo.redo();
            initialState.setHandLocation(mouseHand, handLoc);
            demo.alertInitialStateChange();
            DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
        }

        @Override
        public void undo() {
            super.undo();
            conformanceUndoRedo.undo();
            initialState.setHandLocation(mouseHand, oldLoc);
            demo.alertInitialStateChange();
            DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
        }
    };
    undoMgr.addEdit(edit);
}
Also used : HandLocation(edu.cmu.cs.hcii.cogtool.model.HandLocation) ComputationUndoRedo(edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 9 with DefaultModelGeneratorState

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

the class SEFrameChooserController method setHandLocationAction.

protected void setHandLocationAction(final HandLocation handLoc) {
    final Demonstration demo = taskApp.getDemonstration();
    final boolean mouseHand = demo.getMouseHand();
    final DefaultModelGeneratorState initialState = demo.getInitialState();
    final HandLocation oldLoc = initialState.getHandLocation(mouseHand);
    initialState.setHandLocation(mouseHand, handLoc);
    demo.alertInitialStateChange();
    undoMgr.addEdit(new AUndoableEdit(SEFrameChooserLID.SetHandLocation) {

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

        @Override
        public void redo() {
            super.redo();
            initialState.setHandLocation(mouseHand, handLoc);
            demo.alertInitialStateChange();
        }

        @Override
        public void undo() {
            super.undo();
            initialState.setHandLocation(mouseHand, oldLoc);
            demo.alertInitialStateChange();
        }
    });
}
Also used : HandLocation(edu.cmu.cs.hcii.cogtool.model.HandLocation) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 10 with DefaultModelGeneratorState

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

the class SEFrameChooserController method setMouseHandAction.

protected void setMouseHandAction(final boolean mouseHand) {
    final Demonstration demo = taskApp.getDemonstration();
    final boolean oldMouseHand = demo.getMouseHand();
    final DefaultModelGeneratorState initialState = demo.getInitialState();
    final HandLocation mouseHandLoc = initialState.getHandLocation(oldMouseHand);
    demo.setMouseHand(mouseHand);
    initialState.setHandLocation(mouseHand, mouseHandLoc);
    initialState.setHandLocation(!mouseHand, HandLocation.OnKeyboard);
    undoMgr.addEdit(new AUndoableEdit(SEFrameChooserLID.SetMouseHand) {

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

        @Override
        public void redo() {
            super.redo();
            initialState.setHandLocation(mouseHand, mouseHandLoc);
            initialState.setHandLocation(!mouseHand, HandLocation.OnKeyboard);
            // Do this last as it will alert
            demo.setMouseHand(mouseHand);
        }

        @Override
        public void undo() {
            super.undo();
            initialState.setHandLocation(oldMouseHand, mouseHandLoc);
            initialState.setHandLocation(!oldMouseHand, HandLocation.OnKeyboard);
            // Do this last as it will alert
            demo.setMouseHand(oldMouseHand);
        }
    });
}
Also used : HandLocation(edu.cmu.cs.hcii.cogtool.model.HandLocation) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Aggregations

DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)21 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)9 ThinkScriptStep (edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep)7 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)7 AScriptStep (edu.cmu.cs.hcii.cogtool.model.AScriptStep)6 TableItem (org.eclipse.swt.widgets.TableItem)6 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)5 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)5 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)5 DelayScriptStep (edu.cmu.cs.hcii.cogtool.model.DelayScriptStep)4 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)4 HandLocation (edu.cmu.cs.hcii.cogtool.model.HandLocation)4 Script (edu.cmu.cs.hcii.cogtool.model.Script)4 EventObject (java.util.EventObject)4 Table (org.eclipse.swt.widgets.Table)3 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)2 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)2 Design (edu.cmu.cs.hcii.cogtool.model.Design)2 SEDemoInteraction (edu.cmu.cs.hcii.cogtool.ui.SEDemoInteraction)2 AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)2