use of edu.cmu.cs.hcii.cogtool.model.TaskGroup 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.TaskGroup 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.TaskGroup in project cogtool by cogtool.
the class ProjectController method createUngroupAction.
protected IListenerAction createUngroupAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return TaskSelectionState.class;
}
public boolean performAction(Object prms) {
TaskSelectionState seln = (TaskSelectionState) prms;
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION | TaskSelectionState.TASK_GROUPS_ONLY);
if ((tasks == null) || (tasks.length == 0)) {
interaction.protestNoSelection();
return false;
}
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(L10N.get("PC.Ungroup", "Ungroup"), ProjectLID.Ungroup);
for (AUndertaking task : tasks) {
if (task.isTaskGroup()) {
TaskGroup group = (TaskGroup) task;
List<AUndertaking> childTasks = group.getUndertakings();
int numChildTasks = childTasks.size();
if (numChildTasks > 0) {
AUndertaking[] promoteTasks = new AUndertaking[numChildTasks];
childTasks.toArray(promoteTasks);
for (int j = numChildTasks - 1; j >= 0; j--) {
promoteTask(promoteTasks[j], ProjectLID.Ungroup, editSeq);
}
}
}
}
deleteTasks(tasks, null, editSeq);
if (editSeq.isSignificant()) {
editSeq.end();
undoMgr.addEdit(editSeq);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.TaskGroup in project cogtool by cogtool.
the class HCIPACmd method addHCIPATasks.
/**
* Returns the created subtasks
*/
public static AUndertaking[] addHCIPATasks(Project project, AUndertaking task, String taskName, CognitiveModelGenerator modelGen, String undoRedoLabel, IUndoableEditSequence editSeq) {
AUndertaking[] subtasks = new AUndertaking[6];
String[] subtaskNames = new String[] { IDENTIFY_LABEL + taskName, FUNCTION_LABEL, L10N.get("HC.AccessLabel", "3) Access Step"), L10N.get("HC.EnterLabel", "4) Enter Step"), L10N.get("HC.ConfirmLabel", "5) Confirm & Save Step"), L10N.get("HC.MonitorLabel", "6) Monitor Step") };
TaskGroup group = new TaskGroup(taskName, GroupNature.SUM);
for (int i = 0; i < 6; i++) {
subtasks[i] = new Task(subtaskNames[i]);
subtasks[i].setSpawned(true);
group.addUndertaking(i, subtasks[i]);
}
Iterator<Design> designs = project.getDesigns().iterator();
while (designs.hasNext()) {
initHCIPATaskDesign(project, taskName, subtasks, designs.next(), modelGen);
}
TaskParent parent = task.getTaskGroup();
if (parent == null) {
parent = project;
}
editSeq.addEdit(replaceTask(project, parent, task, group, undoRedoLabel));
return subtasks;
}
use of edu.cmu.cs.hcii.cogtool.model.TaskGroup in project cogtool by cogtool.
the class ProjectController method interactToRenameTask.
/**
* Interact with the user to solicit a new name for an
* <code>AUndertaking</code>. The new name must not be empty and must be
* unique within the <code>TaskGroup</code> that contains the given task
* or, if not a child, unique among the top-level tasks for the
* <code>Project</code>.
* <p>
* For a task that is an <code>TaskGroup</code>, the user is also
* allowed to change the group's <code>GroupNature</code>.
* <p>
* Currently unused.
*
* @param selectedDesign the design to rename
* @author mlh
*/
protected boolean interactToRenameTask(AUndertaking selectedTask, TaskSelectionState selection) {
String oldTaskName = selectedTask.getName();
ProjectInteraction.TaskRequestData requestData = new ProjectInteraction.TaskRequestData();
requestData.taskName = oldTaskName;
requestData.flags = ProjectInteraction.TaskRequestData.ASK_NOTHING;
GroupNature oldNature = GroupNature.MEAN;
// If an TaskGroup, allow the user to specify a new GroupNature.
if (selectedTask.isTaskGroup()) {
requestData.flags = ProjectInteraction.TaskRequestData.ASK_NATURE;
oldNature = ((TaskGroup) selectedTask).getNature();
}
requestData.nature = oldNature;
// cancels or specifies a non-empty name that is unique.
while (true) {
if (!interaction.requestNewTaskName(requestData)) {
// canceled!
return false;
}
if (requestData.taskName.equals("")) {
if (!interaction.protestEmptyTaskName()) {
return false;
}
} else {
TaskGroup parent = selection.getSelectedTaskParent();
if (isTaskNameUnique(requestData.taskName, oldTaskName, parent)) {
if (selectedTask.isTaskGroup() && (requestData.nature != oldNature)) {
modifyTaskGroup((TaskGroup) selectedTask, oldTaskName, requestData.taskName, oldNature, requestData.nature);
return true;
}
return renameTask(selectedTask, oldTaskName, requestData.taskName, parent);
} else {
if (!interaction.protestNotUniqueTaskName()) {
return false;
}
}
}
}
// If one ever gets here, uncomment the next line (Java!!)
// return false;
}
Aggregations