use of edu.cmu.cs.hcii.cogtool.model.AAction 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;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.AAction in project cogtool by cogtool.
the class DesignEditorController method changeTransitionAction.
protected void changeTransitionAction(final Transition transition, final AAction newAction, final double delayInSecs, final String delayLabel, IUndoableEditSequence editSequence) {
final AAction oldAction = transition.getAction();
final double oldDelayInSecs = transition.getDelayInSecs();
final String oldDelayLabel = transition.getDelayLabel();
// Must check that the transition's source can accept the new action
if ((!oldAction.equals(newAction)) || ((delayInSecs != NO_DELAY_CHANGE) && ((delayInSecs != oldDelayInSecs) || !oldDelayLabel.equals(delayLabel)))) {
transition.setAction(newAction);
if (delayInSecs != NO_DELAY_CHANGE) {
transition.setDelayInfo(delayInSecs, delayLabel);
}
DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.ObsoletingEdit(DesignEditorLID.ChangeWidgetAction, demoStateMgr) {
@Override
public String getPresentationName() {
return changeAction;
}
@Override
public void redo() {
super.redo();
transition.setAction(newAction);
if (delayInSecs != NO_DELAY_CHANGE) {
transition.setDelayInfo(delayInSecs, delayLabel);
}
stateMgr.noteTransitionEdit(transition, this);
if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
}
}
@Override
public void undo() {
super.undo();
transition.setAction(oldAction);
if (delayInSecs != NO_DELAY_CHANGE) {
transition.setDelayInfo(oldDelayInSecs, oldDelayLabel);
}
stateMgr.noteTransitionEdit(transition, this);
if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
}
}
};
demoStateMgr.noteTransitionEdit(transition, edit);
editSequence.addEdit(edit);
if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.AAction in project cogtool by cogtool.
the class DesignEditorController method changeTransitionSource.
// deleteTransitions
protected boolean changeTransitionSource(final Transition transition, final TransitionSource newSource) {
final TransitionSource oldSource = transition.getSource();
if (newSource != oldSource) {
AAction action = transition.getAction();
// Check that the new source is consistent the transition's action
if (!newSource.canAccept(action)) {
interaction.protestInconsistentSource();
return false;
}
while (newSource.getTransition(action) != null) {
//TODO: allow interaction to change? Must handle in undo then!
if (!interaction.protestNotUniqueAction(action, newSource, false)) {
return false;
}
}
oldSource.removeTransition(transition);
transition.setSource(newSource);
newSource.addTransition(transition);
final boolean invalidating = (newSource.getFrame() != oldSource.getFrame());
DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.DesignUndoableEdit(DesignEditorLID.ChangeSource, demoStateMgr) {
@Override
public String getPresentationName() {
return changeTransitionSource;
}
@Override
public Boolean getEditNature() {
return invalidating ? DemoStateManager.INVALIDATING : DemoStateManager.OBSOLETING;
}
@Override
public void redo() {
super.redo();
oldSource.removeTransition(transition);
transition.setSource(newSource);
newSource.addTransition(transition);
stateMgr.noteTransitionEdit(transition, this);
if (!invalidating && CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
}
}
@Override
public void undo() {
super.undo();
newSource.removeTransition(transition);
transition.setSource(oldSource);
oldSource.addTransition(transition);
stateMgr.noteTransitionEdit(transition, this);
if (!invalidating && CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
}
}
};
demoStateMgr.noteTransitionEdit(transition, edit);
undoMgr.addEdit(edit);
if (!invalidating && CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
}
}
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.AAction in project cogtool by cogtool.
the class SEDemoController method performEditSelfTransition.
// performChangeDelay
protected boolean performEditSelfTransition(ActionScriptStep step) {
TransitionSource source = step.getStepFocus();
AAction action = step.getAction();
Design design = source.getFrame().getDesign();
int deviceTypes = DeviceType.buildDeviceSet(design.getDeviceTypes());
int limitMode = ActionProperties.determineChangeActionMode(source);
properties.updateProperties(step, action, source);
if (!interaction.determineNewAction(properties, deviceTypes, limitMode, EDIT_SELF_TRANSITION)) {
return false;
}
action = EditActionCmd.buildActionFromProperties(properties, deviceTypes, limitMode, interaction);
if (action == null) {
return false;
}
action = EditActionCmd.ensureActionIsUnique(source, action, properties, deviceTypes, limitMode, null, interaction);
if (action == null) {
return false;
}
return changeSelfTransition(step, action, properties.delayInSecs, properties.delayLabel);
}
use of edu.cmu.cs.hcii.cogtool.model.AAction in project cogtool by cogtool.
the class SEDemoController method createInsertSelfTransitionAction.
protected IListenerAction createInsertSelfTransitionAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return SEDemoUI.SelfTransition.class;
}
public boolean performAction(Object actionParms) {
SEDemoUI.SelfTransition prms = (SEDemoUI.SelfTransition) actionParms;
if (prms.target != null) {
TaskApplication taskApp = script.getDemonstration().getTaskApplication();
Set<DeviceType> deviceTypeSet = taskApp.getDesign().getDeviceTypes();
int deviceTypes = DeviceType.buildDeviceSet(deviceTypeSet);
int limitMode = ActionProperties.determineChangeActionMode(prms.target);
AAction action = prms.action;
if (prms.action == null) {
properties.resetValues();
properties.setInitialActionType(prms.target, deviceTypeSet);
if (!interaction.determineNewAction(properties, deviceTypes, limitMode, L10N.get("DE.SetActionType", "Set Action Type"))) {
return false;
}
action = EditActionCmd.buildActionFromProperties(properties, deviceTypes, limitMode, interaction);
if (action == null) {
return false;
}
}
action = EditActionCmd.ensureActionIsUnique(prms.target, action, properties, deviceTypes, limitMode, null, interaction);
if (action == null) {
return false;
}
return performSelfTransition(prms.selection, prms.target, action, properties.delayInSecs, properties.delayLabel);
}
return false;
}
};
}
Aggregations