Search in sources :

Example 26 with IListenerAction

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

the class ProjectController method createShowModelVisualizationAction.

// Action for ShowVisualization
protected IListenerAction createShowModelVisualizationAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            ProjectSelectionState seln = (ProjectSelectionState) prms;
            // Must have selected tasks and design
            Design design = seln.getSelectedDesign();
            AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
            if ((design == null) || (tasks == null) || (tasks.length == 0)) {
                return false;
            }
            boolean visCreated = false;
            for (AUndertaking task : tasks) {
                if (createVisualization(design, task, -1)) {
                    visCreated = true;
                    break;
                }
            }
            if (!visCreated) {
                interaction.reportProblem(visualizationNotCreated, noResultsToVisualize);
            }
            return visCreated;
        }
    };
}
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)

Example 27 with IListenerAction

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

the class ProjectController method createDeleteDesignAction.

// createInitiateTaskRenameAction
// Action for DeleteDesign
protected IListenerAction createDeleteDesignAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            DesignSelectionState selection = (DesignSelectionState) prms;
            Design selectedDesign = selection.getSelectedDesign();
            // Can only delete if a design is currently selected.
            if (selectedDesign != null) {
                if (interaction.confirmDeleteDesign(selectedDesign)) {
                    // Delete selected design, without copying
                    // to the clipboard.
                    deleteDesign(selectedDesign, null);
                    return true;
                }
            } else {
                interaction.protestNoSelection();
            }
            return false;
        }
    };
}
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) DesignSelectionState(edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState)

Example 28 with IListenerAction

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

the class DefaultController method assignActions.

/**
     * Registers the set of <code>IListenerAction</code> instances
     * that implement the semantic actions that are possible.
     * <p>
     * For this class, this consists of the actions that all CogTool
     * model editing windows support.
     *
     * @author mlh
     */
@Override
protected void assignActions() {
    super.assignActions();
    UI ui = getUI();
    final Interaction interaction = getUI().getStandardInteraction();
    if (ui != null) {
        // Set "save as" action
        ui.setAction(CogToolLID.SaveProjectAs, new AListenerAction() {

            public boolean performAction(Object prms) {
                return saveAs();
            }
        });
        // Set "save" action
        ui.setAction(CogToolLID.SaveProject, new AListenerAction() {

            public boolean performAction(Object prms) {
                return forceSave();
            }
        });
        ui.setAction(CogToolLID.CloseWindow, createCloseWindowAction());
        ui.setAction(CogToolLID.CloseProject, new AListenerAction() {

            public boolean performAction(Object prms) {
                return closeProject(project, true);
            }
        });
        ui.setAction(CogToolLID.Properties, new AListenerAction() {

            public boolean performAction(Object prms) {
                return showProperties();
            }
        });
        ui.setAction(CogToolLID.SetAttribute, new IListenerAction() {

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

            public boolean performAction(Object prms) {
                UI.SetAttributeParameters p = (UI.SetAttributeParameters) prms;
                return DefaultCmd.setAttribute(p.target, null, p.attrName, p.value, interaction, undoMgr);
            }
        });
    }
}
Also used : UI(edu.cmu.cs.hcii.cogtool.ui.UI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) Interaction(edu.cmu.cs.hcii.cogtool.ui.Interaction) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction)

Example 29 with IListenerAction

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

the class DesignEditorController method createChangeActionAction.

protected IListenerAction createChangeActionAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            DesignEditorUI.ChangeActionParameters chgPrms = (DesignEditorUI.ChangeActionParameters) prms;
            if (chgPrms != null) {
                Transition[] transitions = chgPrms.selection.getSelectedTransitions();
                if ((transitions != null) && (transitions.length > 0)) {
                    properties.copyValues(chgPrms.properties);
                    // TODO: Assume one for the moment; ui enforces it!
                    TransitionSource source = transitions[0].getSource();
                    int deviceTypes = DeviceType.buildDeviceSet(design.getDeviceTypes());
                    int limitMode = ActionProperties.determineChangeActionMode(source);
                    AAction newAction = EditActionCmd.buildActionFromProperties(properties, deviceTypes, limitMode, interaction);
                    if (newAction == null) {
                        return false;
                    }
                    newAction = EditActionCmd.ensureActionIsUnique(source, newAction, properties, deviceTypes, limitMode, transitions[0], interaction);
                    if (newAction == null) {
                        return false;
                    }
                    return changeTransitionsAction(transitions, newAction, NO_DELAY_CHANGE, null);
                // TODO: If the given action properties are unusable
                // (e.g., not unique from the source or empty string)
                // and we should therefore return false so that an
                // action that commits property changes can be
                // canceled, assign the ensureActionIsUnique result
                // to a new variable uniqueAction and return the AND of
                // the changeTransitionsAction call (first) with
                // (newAction == uniqueAction).
                }
            }
            return false;
        }
    };
}
Also used : TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) DesignEditorUI(edu.cmu.cs.hcii.cogtool.ui.DesignEditorUI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) Transition(edu.cmu.cs.hcii.cogtool.model.Transition) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) AAction(edu.cmu.cs.hcii.cogtool.model.AAction)

Example 30 with IListenerAction

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

the class DesignEditorController method createNewTransitionAction.

// renameFrame
protected IListenerAction createNewTransitionAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            DesignEditorUI.NewTransitionParameters newPrms = (DesignEditorUI.NewTransitionParameters) prms;
            if (newPrms != null) {
                CompoundUndoableEdit editSequence = null;
                if (newPrms.target == null) {
                    editSequence = new CompoundUndoableEdit(DesignEditorCmd.NEW_TRANSITION, DesignEditorLID.NewTransition);
                    newPrms.target = createNewFrame(newPrms.x, newPrms.y, editSequence);
                }
                IUndoableEdit edit = createNewTransition(newPrms.source, newPrms.target);
                // null is returned if the operation is canceled.
                if (edit != null) {
                    if (editSequence != null) {
                        editSequence.addEdit(edit);
                        editSequence.end();
                        edit = editSequence;
                    }
                    undoMgr.addEdit(edit);
                    if (editSequence != null) {
                        ui.initiateFrameRename(newPrms.target);
                    }
                    return true;
                } else if (editSequence != null) {
                    editSequence.end();
                    editSequence.undo();
                }
                return false;
            } else {
                throw new RcvrUIException("Cannot create transition without parameters.");
            }
        }
    };
}
Also used : DesignEditorUI(edu.cmu.cs.hcii.cogtool.ui.DesignEditorUI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) RcvrUIException(edu.cmu.cs.hcii.cogtool.util.RcvrUIException)

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