use of edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign 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.Project.ITaskDesign in project cogtool by cogtool.
the class DesignEditorController method createExportDesignToXMLAction.
protected IListenerAction createExportDesignToXMLAction() {
return new AListenerAction() {
public boolean performAction(Object actionParms) {
String defaultFilename = design.getName() + ".xml";
File exportFile = interaction.selectXMLFile(false, defaultFilename);
if (exportFile == null) {
return false;
}
OutputStream oStream = null;
try {
try {
oStream = new FileOutputStream(exportFile);
Writer xmlWriter = new BufferedWriter(new OutputStreamWriter(oStream, "UTF-8"));
Map<ITaskDesign, TaskApplication> designTAs = project.taskApplicationsForDesign(design);
ExportCogToolXML.exportXML(design, designTAs, xmlWriter, "UTF-8");
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);
}
interaction.setStatusMessage(L10N.get("PC.DesignExportedToXML", "Design exported to XML:") + " " + exportFile.getName());
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign in project cogtool by cogtool.
the class SNIFACTCmd method addTasksToGroup.
/**
* Creates an undoable edit for the action of adding the list of tasks
* stored in the execution context to the given task group.
*/
protected static IUndoableEdit addTasksToGroup(final Project project, final TaskGroup group, final SNIFACTExecContext context, final String undoLabel) {
return new AUndoableEdit(ProjectLID.RecomputeScript) {
protected Map<ITaskDesign, TaskApplication>[] associatedTAs = null;
protected boolean recoverMgrs = false;
@Override
public String getPresentationName() {
return undoLabel;
}
@Override
public void redo() {
super.redo();
recoverMgrs = false;
List<AUndertaking> tasks = context.getTasks();
for (int i = 0; i < tasks.size(); i++) {
AUndertaking curTask = tasks.get(i);
group.addUndertaking(curTask);
project.restoreRemovedTaskApplications(associatedTAs[i]);
}
}
@Override
@SuppressWarnings("unchecked")
public void undo() {
super.undo();
recoverMgrs = true;
List<AUndertaking> tasks = context.getTasks();
int size = tasks.size();
if (associatedTAs == null) {
associatedTAs = new Map[size];
}
// delete children; IMPORTANT: reverse order!
for (int i = tasks.size() - 1; 0 <= i; i--) {
AUndertaking curTask = tasks.get(i);
associatedTAs[i] = project.taskApplicationsForRemovedTask(curTask);
group.removeUndertaking(curTask);
}
}
@Override
public void die() {
super.die();
if (recoverMgrs) {
for (Map<ITaskDesign, TaskApplication> associatedTA : associatedTAs) {
UndoManagerRecovery.recoverScriptManagers(project, associatedTA, true);
}
}
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign in project cogtool by cogtool.
the class ProjectCmd method addNewDesign.
public static void addNewDesign(final Project project, final Design design, final int beforeIndex, final String presentationName, IUndoableEditSequence editSeq) {
project.addDesign(beforeIndex, design);
// Create undo/redo step
editSeq.addEdit(new AUndoableEdit(ProjectLID.NewDesign) {
// Map from Project.ITaskDesign to TaskApplication
protected Map<ITaskDesign, TaskApplication> associatedTAs = null;
protected boolean recoverMgr = false;
@Override
public String getPresentationName() {
return presentationName;
}
@Override
public void redo() {
super.redo();
recoverMgr = false;
project.addDesign(beforeIndex, design);
if (associatedTAs != null) {
project.restoreRemovedTaskApplications(associatedTAs);
}
}
@Override
public void undo() {
super.undo();
recoverMgr = true;
associatedTAs = project.taskApplicationsForRemovedDesign(design);
project.removeDesign(design);
}
@Override
public void die() {
super.die();
if (recoverMgr) {
UndoManagerRecovery.recoverManagers(project, design, associatedTAs);
FrameTemplateSupport.clearFrameTemplate(design);
}
}
});
}
use of edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign 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;
}
};
}
Aggregations