use of edu.cmu.cs.hcii.cogtool.model.TaskApplication 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.TaskApplication 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.TaskApplication in project cogtool by cogtool.
the class ProjectController method createVisualization.
public boolean createVisualization(Design design, AUndertaking task, int strategy) {
TaskApplication ta = getVisualizationTA(design, task);
if (ta != null) {
IPredictionAlgo activeAlgo = ta.determineActiveAlgorithm(project);
CognitiveModelGenerator gen = ta.getFirstModelGenerator();
if (ta.getResult(gen, activeAlgo) != null) {
PERTChartController c = PERTChartController.openController(ta, gen, activeAlgo, project, strategy, interaction);
return (c != null);
}
}
return false;
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class ProjectController method exportDesignToXML.
private boolean exportDesignToXML(Design design) {
String defaultFilename = ((design != null) ? design.getName() : project.getName()) + ".xml";
File exportFile = null;
if (interaction != null && CogTool.exportCSVKludgeDir == null) {
exportFile = interaction.selectXMLFile(false, defaultFilename);
} else {
exportFile = new File(CogTool.exportCSVKludgeDir, defaultFilename);
}
if (exportFile == null) {
return false;
}
OutputStream oStream = null;
String completionMsg;
try {
try {
oStream = new FileOutputStream(exportFile);
Writer xmlWriter = new BufferedWriter(new OutputStreamWriter(oStream, "UTF-8"));
if (design == null) {
ExportCogToolXML.exportXML(project, xmlWriter, "UTF-8");
completionMsg = allDesignsExportedToXml;
} else {
Map<ITaskDesign, TaskApplication> designTAs = project.taskApplicationsForDesign(design);
ExportCogToolXML.exportXML(design, designTAs, xmlWriter, "UTF-8");
completionMsg = designExportedToXml;
}
xmlWriter.flush();
} finally {
if (oStream != null) {
oStream.close();
}
}
} catch (IllegalArgumentException e) {
throw new RcvrIllegalStateException("Invalid argument exporting to XML", e);
} catch (IllegalStateException e) {
throw new RcvrIllegalStateException("Exporting to XML", e);
} catch (IOException e) {
throw new RcvrIOSaveException("Exporting to XML", e);
} catch (Exception e) {
throw new RecoverableException("Exporting to XML", e);
}
if (interaction != null) {
interaction.setStatusMessage(completionMsg + " " + exportFile.getAbsolutePath());
}
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication 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