use of edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState in project cogtool by cogtool.
the class ProjectController method createExportScriptToCSVAction.
// Action for ExportScriptToCSV
protected IListenerAction createExportScriptToCSVAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object actionParms) {
ProjectSelectionState seln = (ProjectSelectionState) actionParms;
Design design = seln.getSelectedDesign();
if (design == null) {
interaction.protestNoSelection();
return false;
}
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
if (tasks.length == 0) {
interaction.protestNoSelection();
return false;
}
// TODO: Only perform this action when one cell is selected
// (i.e. one task is selected)
// Also, since CogTool doesn't support multiple algorithms
// yet, just use the first prediction algorithm in the map
// to get the script I want; this may need to be changed.
AUndertaking task = tasks[0];
TaskApplication taskApp = project.getTaskApplication(task, design);
if (taskApp == null) {
interaction.protestNoSelection();
return false;
}
Script script = taskApp.getScript(MODELGEN_ALG);
if (script == null) {
script = taskApp.getScript(IdentityModelGenerator.ONLY);
if (script == null) {
interaction.protestNoSelection();
return false;
}
}
return DemoScriptCmd.exportScriptToCSV(script, project, interaction, undoMgr);
}
};
}
use of edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState in project cogtool by cogtool.
the class ProjectController method createGenerateACTRModelAction.
// createImportHumanCSVFileAction
protected IListenerAction createGenerateACTRModelAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object prms) {
ProjectSelectionState seln = (ProjectSelectionState) prms;
// Must have selected tasks and design
Design design = seln.getSelectedDesign();
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
for (AUndertaking task : tasks) {
TaskApplication ta = project.getTaskApplication(task, design);
Script s = DemoStateManager.ensureScript(ta, KLMCognitiveGenerator.ONLY);
// TODO There's too much algorithm specific code
// in here; but for now it seems the expedient
// thing to do -- all this needs to be thought
// through for all back ends, and restructured
String path = s.getAssociatedPath();
String filename = null;
if (path == null) {
filename = design.getName() + "-" + task.getName();
} else {
filename = (new File(path)).getName();
if ((filename != null) && filename.endsWith(CogToolFileTypes.LISP_FILE_EXT)) {
filename = filename.substring(0, filename.length() - CogToolFileTypes.LISP_FILE_EXT.length());
}
}
File file = interaction.selectExportLocation(filename, CogToolFileTypes.LISP_FILE_EXT);
if (file == null) {
return false;
}
s.setAssociatedPath(file.getAbsolutePath());
// so we have to delete it.
if (file.length() == 0) {
file.delete();
}
try {
IPredictionAlgo taAlg = ta.determineActiveAlgorithm(project);
if (!(taAlg instanceof ACTRPredictionAlgo)) {
throw new RcvrIllegalStateException("Can't generate ACT-R Model from a non ACT-R task.");
}
ACTRPredictionAlgo algo = (ACTRPredictionAlgo) taAlg;
algo.outputModel(design, task, s.getDemonstration().getStartFrame(), s, file, null);
} catch (UnsupportedOperationException ex) {
throw new RcvrUnimplementedFnException(ex);
} catch (IOException ex) {
throw new RcvrIOException(("IOException generating model file for task " + task.getName() + " in design " + design.getName()), ex);
}
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState 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.ui.ProjectSelectionState 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.ui.ProjectSelectionState 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;
}
};
}
Aggregations