use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method moveTaskAction.
protected boolean moveTaskAction(TaskSelectionState seln, boolean moveEarlier) {
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION);
if ((tasks == null) || (tasks.length == 0)) {
interaction.protestNoSelection();
return false;
}
if (tasks.length > 1) {
interaction.protestTooManySelectedTasks();
return false;
}
final AUndertaking task = tasks[0];
final TaskParent parent = project.getTaskParent(task);
List<AUndertaking> siblings = parent.getUndertakings();
int siblingCount = siblings.size();
if (siblingCount == 1) {
interaction.setStatusMessage(taskIsOnlyChild);
} else {
final int oldTaskIndex = siblings.indexOf(task);
IUndoableEdit edit;
if (moveEarlier) {
if (oldTaskIndex == 0) {
interaction.protestCannotMoveEarlier();
return false;
}
parent.removeUndertaking(task);
parent.addUndertaking(oldTaskIndex - 1, task);
edit = new AUndoableEdit(ProjectLID.MoveTaskEarlier) {
@Override
public String getPresentationName() {
return MOVE_TASK_EARLIER;
}
@Override
public void redo() {
super.redo();
parent.removeUndertaking(task);
parent.addUndertaking(oldTaskIndex - 1, task);
}
@Override
public void undo() {
super.undo();
parent.removeUndertaking(task);
parent.addUndertaking(oldTaskIndex, task);
}
};
} else {
if (oldTaskIndex == siblingCount - 1) {
interaction.protestCannotMoveLater();
return false;
}
parent.removeUndertaking(task);
parent.addUndertaking(oldTaskIndex + 1, task);
edit = new AUndoableEdit(ProjectLID.MoveTaskEarlier) {
@Override
public String getPresentationName() {
return MOVE_TASK_LATER;
}
@Override
public void redo() {
super.redo();
parent.removeUndertaking(task);
parent.addUndertaking(oldTaskIndex + 1, task);
}
@Override
public void undo() {
super.undo();
parent.removeUndertaking(task);
parent.addUndertaking(oldTaskIndex, task);
}
};
}
undoMgr.addEdit(edit);
}
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method createSetAlgorithmAction.
protected IListenerAction createSetAlgorithmAction(final IPredictionAlgo alg, final CogToolLID lid, final String actionString) {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object actionParms) {
ProjectSelectionState selState = (ProjectSelectionState) actionParms;
Design design = selState.getSelectedDesign();
AUndertaking[] tasks = selState.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
// iterate through tasks and get set of TaskApplications
final TaskApplication[] taskApps = new TaskApplication[tasks.length];
final IPredictionAlgo[] oldAlgos = new IPredictionAlgo[tasks.length];
for (int i = 0; i < tasks.length; i++) {
// Make sure that the task application exists, and create it
// if it does not. No need to ensure a script.
TaskApplication ta = ensureTaskApplication(tasks[i], design, null, demoMgr);
taskApps[i] = ta;
oldAlgos[i] = ta.getActiveAlgorithm();
// now set the new algorithm
ta.setActiveAlgorithm(alg);
}
undoMgr.addEdit(new AUndoableEdit(lid) {
@Override
public String getPresentationName() {
return actionString;
}
@Override
public void redo() {
super.redo();
for (TaskApplication taskApp : taskApps) {
taskApp.setActiveAlgorithm(alg);
}
}
@Override
public void undo() {
super.undo();
for (int i = 0; i < taskApps.length; i++) {
taskApps[i].setActiveAlgorithm(oldAlgos[i]);
}
}
});
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method createScriptViewerAction.
protected IListenerAction createScriptViewerAction() {
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;
}
boolean viewSuccessful = false;
// Viewing a script only applies to task groups
for (AUndertaking task : tasks) {
if (task.isTaskGroup()) {
TaskGroup group = (TaskGroup) task;
List<AUndertaking> childTasks = group.getUndertakings();
if (childTasks.size() > 0) {
AUndertaking firstTask = childTasks.get(0);
TaskApplication ta = project.getTaskApplication(firstTask, design);
if (ta != null) {
ITaskDesign td = project.getTaskDesign(task, design);
ScriptViewerController.openController(td, project);
viewSuccessful = true;
}
}
}
}
if (!viewSuccessful) {
interaction.setStatusMessage(L10N.get("PC.NoScriptsToView", "No scripts to view."));
}
return true;
}
interaction.protestNoSelection();
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method createSetBackgroundComputeAction.
protected IListenerAction createSetBackgroundComputeAction(final Boolean bkg, final ProjectLID lid, final String actionName) {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object actionParms) {
ProjectSelectionState selState = (ProjectSelectionState) actionParms;
Design design = selState.getSelectedDesign();
AUndertaking[] tasks = selState.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
// iterate through tasks and get set of TaskApplications
final TaskApplication[] taskApps = new TaskApplication[tasks.length];
final Boolean[] oldBkgSettings = new Boolean[tasks.length];
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
for (int i = 0; i < tasks.length; i++) {
// Make sure that the task application exists, and create it
// if it does not. No need to ensure a script.
TaskApplication ta = ensureTaskApplication(tasks[i], design, null, demoMgr);
taskApps[i] = ta;
oldBkgSettings[i] = ta.getComputeInBackground();
// now set the compute in background flag
ta.setComputeInBackground(bkg);
}
undoMgr.addEdit(new AUndoableEdit(lid) {
@Override
public String getPresentationName() {
return actionName;
}
@Override
public void redo() {
super.redo();
for (TaskApplication taskApp : taskApps) {
taskApp.setComputeInBackground(bkg);
}
}
@Override
public void undo() {
super.undo();
for (int i = 0; i < taskApps.length; i++) {
taskApps[i].setComputeInBackground(oldBkgSettings[i]);
}
}
});
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method importDesign.
protected void importDesign(TaskParent parent, DesignSelectionState prms, Design newDesign, Collection<Demonstration> demonstrations, Set<AUndertaking> newUndertakings, IUndoableEditSequence editSeq) {
makeDesignNameUnique(newDesign);
ProjectCmd.addNewDesign(project, newDesign, prms.getSelectedDesign(), importXMLPresentation, editSeq);
// Add taskapplications/tasks as well for demonstrations
if ((demonstrations != null) && (demonstrations.size() > 0)) {
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, newDesign);
Iterator<Demonstration> demoIt = demonstrations.iterator();
while (demoIt.hasNext()) {
Demonstration demo = demoIt.next();
TaskApplication taskApp = demo.getTaskApplication();
AUndertaking demoTask = taskApp.getTask();
if (demoTask.getTaskGroup() == null && !newUndertakings.contains(demoTask)) {
// If the taskApp's task is not already part of the
// project, add it. Regardless, any project root task
// with the same name should be the same at this point!
AUndertaking rootTask = parent.getUndertaking(demoTask.getName());
if (rootTask == null) {
parent.addUndertaking(demoTask);
editSeq.addEdit(createNewTaskUndo(parent, Project.AT_END, demoTask, ProjectLID.ImportXML, importXMLPresentation));
} else if (rootTask != demoTask) {
throw new RcvrIllegalStateException("Unexpected root task difference");
}
}
project.setTaskApplication(taskApp);
demoMgr.trackEdits(demo);
}
}
}
Aggregations