use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class ProjectController method createScriptEditorAction.
// Action for EditScript
protected IListenerAction createScriptEditorAction() {
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;
}
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
// Editing a script only applies to tasks, not task groups
for (int i = 0; i < tasks.length; i++) {
if (!tasks[i].isTaskGroup()) {
CognitiveModelGenerator gen = MODELGEN_ALG;
TaskGroup group = tasks[i].getTaskGroup();
if (group != null) {
Object isSnifAct = group.getAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR);
if (isSnifAct != null) {
gen = IdentityModelGenerator.ONLY;
}
}
// If no script set exists for this cell, create
TaskApplication ta = ensureTaskApplication(tasks[i], design, gen, demoMgr);
Demonstration demo = ta.getDemonstration();
if (CogToolPref.HCIPA.getBoolean()) {
HCIPACmd.checkStartFrame(project, ta, gen);
}
// Determine which window to open/create
if ((demo.getStartFrame() == null) || !demo.isStartFrameChosen()) {
// No start frame; present ui to choose one
SEFrameChooserController.openController(ta, gen, project);
} else {
// Start frame chosen; go straight to demo ui
try {
SEDemoController.openController(ta, gen, project);
} catch (GraphicsUtil.ImageException ex) {
interaction.protestInvalidImageFile();
}
}
}
// Else do nothing when a TaskGroup cell is "edited"
}
return true;
}
interaction.protestNoSelection();
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class ProjectController method createDuplicateTasksAction.
protected IListenerAction createDuplicateTasksAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return TaskSelectionState.class;
}
public boolean performAction(Object prms) {
TaskSelectionState seln = (TaskSelectionState) prms;
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
// Can only duplicate if one or more tasks are selected
if ((tasks != null) && (tasks.length > 0)) {
String presentationName = (tasks.length > 1) ? DUPLICATE_TASKS : DUPLICATE_TASK;
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(presentationName, ProjectLID.DuplicateTask);
AUndertaking lastDuplicate = null;
for (AUndertaking task : tasks) {
TaskParent parent = project.getTaskParent(task);
List<AUndertaking> parentUndertakings = parent.getUndertakings();
int atIndex = parentUndertakings.indexOf(task) + 1;
lastDuplicate = duplicateTask(task, atIndex, parent, parentUndertakings, ProjectLID.DuplicateTask, presentationName, editSeq);
}
// Done with undo/redo steps; add the compound change
// to the undo manager.
editSeq.end();
undoMgr.addEdit(editSeq);
if (tasks.length == 1) {
ui.initiateTaskRename(lastDuplicate);
}
} else {
interaction.protestNoSelection();
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction 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.util.IListenerAction 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.util.IListenerAction in project cogtool by cogtool.
the class ProjectController method createNewTaskGroupAction.
// createNewTaskUndo
// Action for NewTaskGroup
protected IListenerAction createNewTaskGroupAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return TaskSelectionState.class;
}
public boolean performAction(Object prms) {
TaskSelectionState selection = (TaskSelectionState) prms;
// Figure out what the selection is
AUndertaking[] selectedTasks = selection.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION);
TaskGroup newGroup = null;
if ((selectedTasks == null) || (selectedTasks.length == 0)) {
String newGroupName = computeNewTaskName(project, DEFAULT_TASK_GROUP_PREFIX);
// No task selection -- add a new root task group
newGroup = addTaskGroup(project, project.getUndertakings().size(), newGroupName, selectedTasks);
} else {
// One selected task: create new group at selected position
// Multiple selected tasks:
// if all tasks have same parent,
// create new group after last selection
// if tasks do not have same parent,
// add new root group after last selected root
// but, if no selected root, new root at end
// Get parent
TaskGroup parent = selection.getSelectedTaskParent();
if (parent == null) {
String newGroupName = computeNewTaskName(project, DEFAULT_TASK_GROUP_PREFIX);
newGroup = addTaskGroup(project, findLastSelectedRoot(selectedTasks), newGroupName, selectedTasks);
} else {
String newGroupName = computeNewTaskName(parent, DEFAULT_TASK_GROUP_PREFIX);
AUndertaking last = selectedTasks[selectedTasks.length - 1];
newGroup = addTaskGroup(parent, parent.getUndertakings().indexOf(last) + 1, newGroupName, selectedTasks);
}
}
// Task is automatically selected when added -- rename
// Cannot put this into the ui because of undo/redo
ui.initiateTaskRename(newGroup);
return true;
}
};
}
Aggregations