use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class HCIPACmd method updateLabels.
public static IUndoableEdit updateLabels(final TaskGroup group, final String newName, final String undoRenameLabel) {
final String oldName = group.getName();
final AUndertaking t = group.getUndertakings().get(0);
group.setName(newName);
t.setName(IDENTIFY_LABEL + newName);
return new AUndoableEdit(ProjectLID.HCIPARenameTask) {
@Override
public String getPresentationName() {
return undoRenameLabel;
}
@Override
public void redo() {
super.redo();
group.setName(newName);
t.setName(IDENTIFY_LABEL + newName);
}
@Override
public void undo() {
super.undo();
group.setName(oldName);
t.setName(IDENTIFY_LABEL + oldName);
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method createDuplicateTaskAppAction.
protected IListenerAction createDuplicateTaskAppAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectUI.MoveCopyTaskApplicationParms.class;
}
public boolean performAction(Object p) {
if (p != null) {
ProjectUI.MoveCopyTaskApplicationParms parms = (ProjectUI.MoveCopyTaskApplicationParms) p;
// Must have selected tasks and design
if ((parms.design == null) || (parms.fromTask == null) || (parms.toTask == null)) {
interaction.protestNoSelection();
return false;
}
final AUndertaking fromTask = parms.fromTask;
final AUndertaking toTask = parms.toTask;
TaskApplication taskApp = project.getTaskApplication(fromTask, parms.design);
if (taskApp == null) {
interaction.protestNoTaskApplication();
return false;
}
final TaskApplication oldTaskApp = project.removeTaskApplication(parms.toTask, parms.design);
final TaskApplication newTaskApp = taskApp.duplicate(toTask, parms.design);
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, parms.design);
project.setTaskApplication(newTaskApp);
demoMgr.trackEdits(newTaskApp.getDemonstration());
IUndoableEdit edit = new AUndoableEdit(ProjectLID.DuplicateTaskApplication) {
protected boolean recoverMgrs = false;
@Override
public String getPresentationName() {
return DUPLICATE_TASKAPP;
}
@Override
public void redo() {
super.redo();
if (oldTaskApp != null) {
project.removeTaskApplication(oldTaskApp);
}
project.setTaskApplication(newTaskApp);
recoverMgrs = false;
}
@Override
public void undo() {
super.undo();
project.removeTaskApplication(newTaskApp);
if (oldTaskApp != null) {
project.setTaskApplication(oldTaskApp);
}
recoverMgrs = true;
}
@Override
public void die() {
if (recoverMgrs) {
recoverManagers(newTaskApp);
}
}
};
undoMgr.addEdit(edit);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method duplicateTaskApplications.
protected void duplicateTaskApplications(TaskGroup originalGroup, TaskGroup groupCopy) {
Iterator<AUndertaking> originalChildren = originalGroup.getUndertakings().iterator();
Iterator<AUndertaking> copyChildren = groupCopy.getUndertakings().iterator();
// Iterate in parallel
while (originalChildren.hasNext() && copyChildren.hasNext()) {
AUndertaking originalTask = originalChildren.next();
AUndertaking taskCopy = copyChildren.next();
if (originalTask instanceof TaskGroup) {
duplicateTaskApplications((TaskGroup) originalTask, (TaskGroup) taskCopy);
} else {
duplicateTaskApplications(originalTask, taskCopy);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method recomputeScripts.
protected boolean recomputeScripts(ProjectSelectionState seln) {
Design design = seln.getSelectedDesign();
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
ComputeMessages computeMsgs = new ComputeMessages();
String editLabel = ui.hasMultipleScripts(seln) ? RECOMPUTE_SCRIPTS : RECOMPUTE_SCRIPT;
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(editLabel, ProjectLID.RecomputeScript);
editSequence.setManager(undoMgr);
if (design != null) {
DemoStateManager demoStateMgr = DemoStateManager.getStateManager(project, design);
if ((tasks != null) && (tasks.length > 0)) {
for (int i = 0; i < tasks.length; i++) {
if (!recomputeScripts(tasks[i], design, demoStateMgr, computeMsgs, editSequence)) {
return false;
}
}
} else {
Iterator<AUndertaking> allTasks = project.getUndertakings().iterator();
while (allTasks.hasNext()) {
if (!recomputeScripts(allTasks.next(), design, demoStateMgr, computeMsgs, editSequence)) {
return false;
}
}
}
} else if ((tasks != null) && (tasks.length > 0)) {
for (int i = 0; i < tasks.length; i++) {
Iterator<Design> allDesigns = project.getDesigns().iterator();
while (allDesigns.hasNext()) {
design = allDesigns.next();
DemoStateManager demoStateMgr = DemoStateManager.getStateManager(project, design);
if (!recomputeScripts(tasks[i], design, demoStateMgr, computeMsgs, editSequence)) {
return false;
}
}
}
}
if (editSequence.isSignificant()) {
editSequence.end();
undoMgr.addEdit(editSequence);
}
computeMsgs.presentMessages();
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method createScriptEditorAction.
// Action for EditScript
protected IListenerAction createScriptEditorAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object prms) {
if (prms != null) {
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;
}
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
// Editing a script only applies to tasks, not task groups
for (int i = 0; i < tasks.length; i++) {
if (!tasks[i].isTaskGroup()) {
CognitiveModelGenerator gen = MODELGEN_ALG;
TaskGroup group = tasks[i].getTaskGroup();
if (group != null) {
Object isSnifAct = group.getAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR);
if (isSnifAct != null) {
gen = IdentityModelGenerator.ONLY;
}
}
// If no script set exists for this cell, create
TaskApplication ta = ensureTaskApplication(tasks[i], design, gen, demoMgr);
Demonstration demo = ta.getDemonstration();
if (CogToolPref.HCIPA.getBoolean()) {
HCIPACmd.checkStartFrame(project, ta, gen);
}
// Determine which window to open/create
if ((demo.getStartFrame() == null) || !demo.isStartFrameChosen()) {
// No start frame; present ui to choose one
SEFrameChooserController.openController(ta, gen, project);
} else {
// Start frame chosen; go straight to demo ui
try {
SEDemoController.openController(ta, gen, project);
} catch (GraphicsUtil.ImageException ex) {
interaction.protestInvalidImageFile();
}
}
}
// Else do nothing when a TaskGroup cell is "edited"
}
return true;
}
interaction.protestNoSelection();
return false;
}
};
}
Aggregations