use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method duplicateTask.
protected AUndertaking duplicateTask(AUndertaking task, int atIndex, TaskParent parent, List<AUndertaking> siblings, CogToolLID lid, String presentationName, IUndoableEditSequence editSeq) {
String newTaskName = NamedObjectUtil.makeNameUnique(task.getName(), siblings);
IUndoableEdit edit;
AUndertaking duplicateTask = task.duplicate(newTaskName);
// Create undo/redo step
if (task.isTaskGroup()) {
SNIFACTExecContext context = (SNIFACTExecContext) task.getAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR);
// duplicated as well.
if (!NullSafe.equals(context, WidgetAttributes.NO_CONTEXT)) {
duplicateTask.setAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR, context.duplicate());
}
edit = createNewTaskGroupUndo(parent, atIndex, (TaskGroup) duplicateTask, null, null, new AUndertaking[0], lid, presentationName);
} else {
edit = createNewTaskUndo(parent, atIndex, duplicateTask, lid, presentationName);
}
editSeq.addEdit(edit);
parent.addUndertaking(atIndex, duplicateTask);
if (task.isTaskGroup()) {
duplicateTaskApplications((TaskGroup) task, (TaskGroup) duplicateTask);
} else {
duplicateTaskApplications(task, duplicateTask);
}
return duplicateTask;
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method saveDesignToClipboard.
// createPasteAction
// Support for copying design and associated TA's to clipboard
protected void saveDesignToClipboard(Design design, ObjectSaver saver) {
try {
saver.saveObject(design);
Iterator<AUndertaking> rootTasks = project.getUndertakings().iterator();
while (rootTasks.hasNext()) {
AUndertaking childTask = rootTasks.next();
saver.saveObject(childTask);
}
Map<ITaskDesign, TaskApplication> associatedTAs = project.taskApplicationsForDesign(design);
Iterator<TaskApplication> taskApps = associatedTAs.values().iterator();
while (taskApps.hasNext()) {
TaskApplication ta = taskApps.next();
saver.saveObject(ta);
}
} catch (IOException ex) {
throw new RcvrClipboardException(ex);
}
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method recomputeScripts.
protected boolean recomputeScripts(AUndertaking task, Design design, DemoStateManager demoStateMgr, ComputeMessages computeMsgs, IUndoableEditSequence editSequence) {
if (CogToolPref.isTracingOverride == null && !CogToolPref.IS_TRACING.getBoolean()) {
Boolean answer = getInteraction().confirmNoTracing();
if (answer == null) {
// canceled
return false;
} else if (answer.booleanValue()) {
CogToolPref.IS_TRACING.setBoolean(true);
}
}
if (task.isTaskGroup()) {
if (!NullSafe.equals(WidgetAttributes.NO_CONTEXT, task.getAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR))) {
return computeSnifAct(design, task, editSequence, null);
}
Iterator<AUndertaking> allTasks = ((TaskGroup) task).getUndertakings().iterator();
CompoundUndoableEdit groupEditSeq = new CompoundUndoableEdit(RECOMPUTE_SCRIPTS, ProjectLID.RecomputeScript);
while (allTasks.hasNext()) {
if (!recomputeScripts(allTasks.next(), design, demoStateMgr, computeMsgs, groupEditSeq)) {
return false;
}
}
if (groupEditSeq.isSignificant()) {
groupEditSeq.end();
editSequence.addEdit(groupEditSeq);
}
return true;
}
TaskApplication ta = project.getTaskApplication(task, design);
if (ta != null) {
IPredictionAlgo activeAlg = ta.determineActiveAlgorithm(project);
if (activeAlg == SNIFACTPredictionAlgo.ONLY) {
return computeSnifAct(design, task, editSequence, null);
}
if (computeMsgs.canComputeScript(ta, demoStateMgr, editSequence)) {
if (!activeAlg.allowsComputation()) {
interaction.setStatusMessage(algDisallowsComputation);
interaction.reportProblem(RECOMPUTE_SCRIPTS, algDisallowsComputation);
return false;
} else if (!ta.getDemonstration().isStartFrameChosen()) {
// nothing to compute
interaction.setStatusMessage(noStartFrameChosen);
return false;
}
IUndoableEdit edit = ComputePredictionCmd.computeAllPredictions(project, ta, activeAlg, ta.determineComputeInBackground(project), interaction);
if (edit != null) {
ta.setActiveAlgorithm(activeAlg);
editSequence.addEdit(edit);
} else {
interaction.setStatusMessage(computeHadNoResult);
}
} else {
interaction.setStatusMessage(cannotRecomputeInvalid);
}
} else {
if (project.getDefaultAlgo() == SNIFACTPredictionAlgo.ONLY) {
return computeSnifAct(design, task, editSequence, null);
}
interaction.setStatusMessage(cannotRecomputeNoDemo);
}
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method mapProjectTasks.
protected void mapProjectTasks(AUndertaking task, TaskParent parent, Map<AUndertaking, AUndertaking> reuseTasks, IUndoableEditSequence editSeq, String presentationName) {
AUndertaking correspondingTask = parent.getUndertaking(task.getName());
if (correspondingTask != null) {
reuseTasks.put(task, correspondingTask);
if ((task instanceof TaskGroup) && (correspondingTask instanceof TaskGroup)) {
TaskGroup correspondingGroup = (TaskGroup) correspondingTask;
Iterator<AUndertaking> childTasks = ((TaskGroup) task).getUndertakings().iterator();
while (childTasks.hasNext()) {
AUndertaking childTask = childTasks.next();
mapProjectTasks(childTask, correspondingGroup, reuseTasks, editSeq, presentationName);
}
}
} else {
pasteTask(task, parent, parent.getUndertakings().size(), editSeq, presentationName);
}
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method createPasteAction.
// Action for Paste
protected IListenerAction createPasteAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object prms) {
ProjectSelectionState seln = (ProjectSelectionState) prms;
try {
// Check for CogTool objects to paste
Collection<Object> objects = CogToolClipboard.fetchCogToolObjects(project);
// designs and tasks only
int numObjectsPasted = 0;
if ((objects != null) && (objects.size() > 0)) {
// Paste tasks as children of the selected TaskGroup
AUndertaking[] selectedTasks = seln.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
TaskGroup taskParent = seln.getSelectedTaskParent();
int index;
// index at which new pasted Tasks will be placed.
if (taskParent != null) {
AUndertaking last = selectedTasks[selectedTasks.length - 1];
index = taskParent.getUndertakings().indexOf(last) + 1;
} else {
index = findLastSelectedRoot(selectedTasks);
}
// Create undo support
String presentationName = PASTE;
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(presentationName, ProjectLID.Paste);
// If task applications are pasted, they will have
// null Design fields; they should "arrive" after
// the Design being pasted at the same time!
Design newDesign = null;
// Existing tasks are to be re-used if the paste
// is within the same project as the copy/cut.
Map<AUndertaking, AUndertaking> reuseTasks = null;
Iterator<Object> objIt = objects.iterator();
while (objIt.hasNext()) {
Object o = objIt.next();
// unique name and create and place the design.
if (o instanceof Design) {
newDesign = (Design) o;
makeDesignNameUnique(newDesign);
// Add an undo step after creating/placing
ProjectCmd.addNewDesign(project, newDesign, seln.getSelectedDesign(), presentationName, editSeq);
numObjectsPasted++;
} else // or to the Project. Create and place.
if (o instanceof AUndertaking) {
AUndertaking task = (AUndertaking) o;
// project or pasting copied tasks
if (reuseTasks == null) {
pasteTask(task, taskParent, index++, editSeq, presentationName);
numObjectsPasted++;
} else {
// In this case, a copied design is
// being pasted into the same project.
// Map each undertaking to the
// corresponding one in the current project
mapProjectTasks(task, project, reuseTasks, editSeq, presentationName);
}
} else // along when copying an Design.
if (o instanceof TaskApplication) {
TaskApplication taskApp = (TaskApplication) o;
if (reuseTasks != null) {
AUndertaking reuseTask = reuseTasks.get(taskApp.getTask());
if (reuseTask != null) {
taskApp.setTask(reuseTask);
}
}
// The undo edit for adding the Design will
// remove and restore the task-applications;
// simply add to the project.
project.setTaskApplication(taskApp);
} else if (o instanceof CogToolClipboard.ProjectScope) {
CogToolClipboard.ProjectScope projectScope = (CogToolClipboard.ProjectScope) o;
// a copied design into the same project
if (projectScope.getProject() != null) {
reuseTasks = new HashMap<AUndertaking, AUndertaking>();
}
}
}
// Done with undo/redo steps; add the compound change
// to the undo manager.
editSeq.end();
undoMgr.addEdit(editSeq);
interaction.setStatusMessage(numObjectsPasted + " " + pasteComplete);
} else {
interaction.setStatusMessage(nothingPasted);
}
return true;
} catch (IOException e) {
throw new RcvrClipboardException(e);
} catch (SAXException e) {
throw new RcvrClipboardException(e);
} catch (ParserConfigurationException e) {
throw new RcvrClipboardException(e);
} catch (ClipboardUtil.ClipboardException e) {
throw new RcvrClipboardException(e);
}
}
};
}
Aggregations