use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method printTree.
/**
* Debugging utility
*/
protected void printTree(List<AUndertaking> tasks, String indent) {
for (AUndertaking u : tasks) {
if (u.isTaskGroup()) {
System.out.println(indent + "TaskGroup: " + u.getClass().getName());
printTree(((TaskGroup) u).getUndertakings(), indent + " ");
} else {
System.out.println(indent + "Task : " + u);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method createImportAction.
protected IListenerAction createImportAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object prms) {
boolean computeScripts = CogToolPref.COMPSCR.getBoolean();
if (importFile == null) {
importFile = interaction.selectXMLFile(true, null);
} else {
computeScripts = importFileComputes;
}
if (importFile == null) {
return false;
}
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(importXMLPresentation, ProjectLID.ImportXML);
Map<Design, Collection<Demonstration>> parsedDesigns = null;
Set<AUndertaking> newUndertakings = null;
TaskParent parent = project;
try {
if (CogToolPref.HCIPA.getBoolean()) {
TaskGroup importGroup = new TaskGroup(importFile.getName(), GroupNature.SUM);
parent = importGroup;
project.addUndertaking(importGroup);
editSeq.addEdit(createNewTaskUndo(project, Project.AT_END, importGroup, ProjectLID.ImportXML, importXMLPresentation));
}
ImportCogToolXML importer = new ImportCogToolXML();
if (!importer.importXML(importFile, parent, MODELGEN_ALG) || (importer.getDesigns().size() == 0)) {
List<String> errors = importer.getObjectFailures();
if ((errors != null) && (errors.size() > 0)) {
interaction.reportProblems(importXMLPresentation, errors);
} else {
interaction.reportProblem(importXMLPresentation, xmlParseFailed);
}
return false;
}
List<String> warnings = importer.getGenerationWarnings();
if (warnings.size() > 0) {
interaction.reportWarnings(importXMLPresentation, warnings);
}
parsedDesigns = importer.getDesigns();
newUndertakings = importer.getNewUndertakings();
} catch (ImportCogToolXML.ImportFailedException ex) {
throw new RcvrXMLParsingException("Missing XML component", ex);
} catch (GraphicsUtil.ImageException ex) {
throw new RcvrImageException("Image error during loading XML", ex);
} catch (IOException ex) {
throw new RcvrXMLParsingException("IO error loading XML", ex);
} catch (SAXException ex) {
throw new RcvrXMLParsingException("Error parsing XML", ex);
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
importFile = null;
importFileComputes = false;
}
for (AUndertaking u : newUndertakings) {
parent.addUndertaking(u);
final AUndertaking uu = u;
final TaskParent pp = parent;
editSeq.addEdit(new AUndoableEdit(ProjectLID.ImportXML) {
@Override
public void redo() {
super.redo();
pp.addUndertaking(uu);
}
@Override
public void undo() {
super.undo();
pp.removeUndertaking(uu);
}
});
}
Iterator<Map.Entry<Design, Collection<Demonstration>>> designDemos = parsedDesigns.entrySet().iterator();
while (designDemos.hasNext()) {
Map.Entry<Design, Collection<Demonstration>> entry = designDemos.next();
importDesign(parent, (DesignSelectionState) prms, entry.getKey(), entry.getValue(), newUndertakings, editSeq);
}
editSeq.end();
undoMgr.addEdit(editSeq);
if (computeScripts) {
//compute predictions for imported project
ProjectContextSelectionState seln = new ProjectContextSelectionState(project);
seln.addSelectedDesigns(project.getDesigns());
ui.selectAllTasks();
recomputeScripts(seln);
ui.deselectAllTasks();
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class SEDemoController method insertStep.
protected boolean insertStep(final AScriptStep newDemoStep, AScriptStep beforeStep, CogToolLID lid, final String presentationName) {
Set<AScriptStep> newDemoSteps = Collections.singleton(newDemoStep);
Set<AScriptStep> emptyDemoSteps = // None are being replaced!
new HashSet<AScriptStep>();
Demonstration demo = script.getDemonstration();
final int atIndex = demo.insertStep(newDemoStep, beforeStep);
final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, beforeStep, interaction);
if (CogToolPref.HCIPA.getBoolean()) {
TaskApplication ta = script.getDemonstration().getTaskApplication();
AUndertaking t = ta.getTask();
Design d = ta.getDesign();
// Starting with the script after t, update all of the scripts in
// the task group to reflect the new state
TaskGroup grp = t.getTaskGroup();
if (grp != null) {
List<AUndertaking> tasks = grp.getUndertakings();
int startIndex = tasks.indexOf(t);
Script prevScript = script;
for (int i = startIndex + 1; i < tasks.size(); i++) {
t = tasks.get(i);
ta = project.getTaskApplication(t, d);
if (ta == null) {
continue;
}
Script s = ta.getScript(script.getModelGenerator());
Demonstration curDemo = s.getDemonstration();
HCIPACmd.copyState(prevScript, curDemo);
scriptsUndoRedos.addAll(DemoScriptCmd.regenerateScripts(curDemo, 0, curDemo.getStepAt(0), interaction));
prevScript = s;
}
}
}
IUndoableEdit edit = new DemoStateManager.ADemoUndoableEdit(lid, demo, newDemoSteps, emptyDemoSteps, demoStateMgr) {
@Override
public String getPresentationName() {
return presentationName;
}
@Override
public void redo() {
super.redo();
demo.insertStep(newDemoStep, atIndex);
DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
}
@Override
public void undo() {
super.undo();
demo.removeStep(atIndex);
DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
}
};
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(presentationName, lid);
editSequence.addEdit(edit);
if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
DemoScriptCmd.regenerateScripts(project, demo, demoStateMgr, interaction, editSequence);
}
editSequence.end();
undoMgr.addEdit(editSequence);
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class SNIFACTCmd method addTasksToGroup.
/**
* Creates an undoable edit for the action of adding the list of tasks
* stored in the execution context to the given task group.
*/
protected static IUndoableEdit addTasksToGroup(final Project project, final TaskGroup group, final SNIFACTExecContext context, final String undoLabel) {
return new AUndoableEdit(ProjectLID.RecomputeScript) {
protected Map<ITaskDesign, TaskApplication>[] associatedTAs = null;
protected boolean recoverMgrs = false;
@Override
public String getPresentationName() {
return undoLabel;
}
@Override
public void redo() {
super.redo();
recoverMgrs = false;
List<AUndertaking> tasks = context.getTasks();
for (int i = 0; i < tasks.size(); i++) {
AUndertaking curTask = tasks.get(i);
group.addUndertaking(curTask);
project.restoreRemovedTaskApplications(associatedTAs[i]);
}
}
@Override
@SuppressWarnings("unchecked")
public void undo() {
super.undo();
recoverMgrs = true;
List<AUndertaking> tasks = context.getTasks();
int size = tasks.size();
if (associatedTAs == null) {
associatedTAs = new Map[size];
}
// delete children; IMPORTANT: reverse order!
for (int i = tasks.size() - 1; 0 <= i; i--) {
AUndertaking curTask = tasks.get(i);
associatedTAs[i] = project.taskApplicationsForRemovedTask(curTask);
group.removeUndertaking(curTask);
}
}
@Override
public void die() {
super.die();
if (recoverMgrs) {
for (Map<ITaskDesign, TaskApplication> associatedTA : associatedTAs) {
UndoManagerRecovery.recoverScriptManagers(project, associatedTA, true);
}
}
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method createDuplicateTaskFullAction.
protected IListenerAction createDuplicateTaskFullAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectUI.ChangeTaskPositionParms.class;
}
public boolean performAction(Object actionParms) {
ProjectUI.ChangeTaskPositionParms prms = (ProjectUI.ChangeTaskPositionParms) actionParms;
if ((prms.tasks == null) || (prms.tasks.getSelectedTaskCount() == 0)) {
interaction.protestNoSelection();
return false;
}
AUndertaking[] selectedTasks = prms.tasks.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION);
TaskParent placeBeforeTaskParent = (prms.placeBeforeTask != null) ? project.getTaskParent(prms.placeBeforeTask) : project;
List<AUndertaking> siblings = placeBeforeTaskParent.getUndertakings();
int atIndex = (prms.placeBeforeTask != null) ? siblings.indexOf(prms.placeBeforeTask) : siblings.size();
String presentationName = (selectedTasks.length > 1) ? DUPLICATE_TASKS : DUPLICATE_TASK;
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(presentationName, ProjectLID.DuplicateTaskFull);
AUndertaking lastDuplicate = null;
for (int i = 0; i < selectedTasks.length; i++) {
lastDuplicate = duplicateTask(selectedTasks[i], atIndex + i, placeBeforeTaskParent, siblings, ProjectLID.DuplicateTaskFull, presentationName, editSeq);
}
// Done with undo/redo steps; add the compound change
// to the undo manager.
editSeq.end();
undoMgr.addEdit(editSeq);
if (selectedTasks.length == 1) {
ui.initiateTaskRename(lastDuplicate);
}
return true;
}
};
}
Aggregations