use of edu.cmu.cs.hcii.cogtool.model.TaskParent in project cogtool by cogtool.
the class ProjectController method createChangeTaskPositionAction.
protected IListenerAction createChangeTaskPositionAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectUI.ChangeTaskPositionParms.class;
}
public boolean performAction(Object actionParms) {
ProjectUI.ChangeTaskPositionParms prms = (ProjectUI.ChangeTaskPositionParms) actionParms;
if ((prms.placeBeforeTask != null) && prms.tasks.isInSelectedHierarchy(prms.placeBeforeTask)) {
// Nothing to do
return false;
}
if ((prms.tasks == null) || (prms.tasks.getSelectedTaskCount() == 0)) {
interaction.protestNoSelection();
return false;
}
final AUndertaking[] selectedTasks = prms.tasks.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION);
final TaskParent[] oldParents = new TaskParent[selectedTasks.length];
final int[] indexes = new int[selectedTasks.length];
final String[] oldNames = new String[selectedTasks.length];
final TaskParent placeBeforeTaskParent = (prms.placeBeforeTask != null) ? project.getTaskParent(prms.placeBeforeTask) : project;
final List<AUndertaking> siblings = placeBeforeTaskParent.getUndertakings();
// If the place-before-task is selected, find the next
// sibling that is not selected.
AUndertaking placeBefore = prms.placeBeforeTask;
if (prms.tasks.isTaskSelected(placeBefore)) {
int siblingIndex = siblings.indexOf(placeBefore);
int siblingCount = siblings.size();
while (++siblingIndex < siblingCount) {
placeBefore = siblings.get(siblingIndex);
if (!prms.tasks.isTaskSelected(placeBefore)) {
break;
}
}
if (siblingIndex >= siblingCount) {
placeBefore = null;
}
}
// Remove first so that the atIndex computation works!
removeChildTasks(selectedTasks, oldParents, indexes);
final int atIndex = (placeBefore != null) ? siblings.indexOf(placeBefore) : siblings.size();
// Add each selected task as siblings before the given task
for (int i = 0; i < selectedTasks.length; i++) {
oldNames[i] = selectedTasks[i].getName();
String newName = NamedObjectUtil.makeNameUnique(oldNames[i], siblings);
if (!newName.equals(oldNames[i])) {
selectedTasks[i].setName(newName);
}
placeBeforeTaskParent.addUndertaking(atIndex + i, selectedTasks[i]);
}
// Create undo/redo step and add to undo manager
IUndoableEdit edit = new AUndoableEdit(ProjectLID.ChangeTaskPosition) {
@Override
public String getPresentationName() {
return (selectedTasks.length > 1) ? MOVE_TASKS : MOVE_TASK;
}
@Override
public void redo() {
super.redo();
removeChildTasks(selectedTasks, null, null);
// before the given task
for (int i = 0; i < selectedTasks.length; i++) {
String newName = NamedObjectUtil.makeNameUnique(oldNames[i], siblings);
if (!newName.equals(oldNames[i])) {
selectedTasks[i].setName(newName);
}
placeBeforeTaskParent.addUndertaking(atIndex + i, selectedTasks[i]);
}
}
@Override
public void undo() {
super.undo();
removeChildTasks(selectedTasks, null, null);
// Un-delete children; IMPORTANT: reverse order!
for (int i = selectedTasks.length - 1; 0 <= i; i--) {
if (!oldNames[i].equals(selectedTasks[i].getName())) {
selectedTasks[i].setName(oldNames[i]);
}
// Add to old parent at old index
oldParents[i].addUndertaking(indexes[i], selectedTasks[i]);
}
}
};
undoMgr.addEdit(edit);
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.TaskParent 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.TaskParent 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;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.TaskParent 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.TaskParent in project cogtool by cogtool.
the class ProjectController method createDuplicateTasksAction.
protected IListenerAction createDuplicateTasksAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return TaskSelectionState.class;
}
public boolean performAction(Object prms) {
TaskSelectionState seln = (TaskSelectionState) prms;
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
// Can only duplicate if one or more tasks are selected
if ((tasks != null) && (tasks.length > 0)) {
String presentationName = (tasks.length > 1) ? DUPLICATE_TASKS : DUPLICATE_TASK;
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(presentationName, ProjectLID.DuplicateTask);
AUndertaking lastDuplicate = null;
for (AUndertaking task : tasks) {
TaskParent parent = project.getTaskParent(task);
List<AUndertaking> parentUndertakings = parent.getUndertakings();
int atIndex = parentUndertakings.indexOf(task) + 1;
lastDuplicate = duplicateTask(task, atIndex, parent, parentUndertakings, ProjectLID.DuplicateTask, presentationName, editSeq);
}
// Done with undo/redo steps; add the compound change
// to the undo manager.
editSeq.end();
undoMgr.addEdit(editSeq);
if (tasks.length == 1) {
ui.initiateTaskRename(lastDuplicate);
}
} else {
interaction.protestNoSelection();
}
return true;
}
};
}
Aggregations