use of edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState in project cogtool by cogtool.
the class ProjectController method createEditACTRModelAction.
// TODO it is a crock that we're cloning this stuff; when we have time
// we should design a shared mechanism to be used by all back ends
protected IListenerAction createEditACTRModelAction() {
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);
for (AUndertaking task : tasks) {
TaskApplication ta = project.getTaskApplication(task, design);
if (ta == null) {
return false;
}
// find the script
Script script = ta.getScript(KLMCognitiveGenerator.ONLY);
if (script == null) {
return false;
}
// get the resourcePath
String resourcePath = script.getAssociatedPath();
if (resourcePath == null) {
return false;
}
try {
FileUtil.editFile(new File(resourcePath));
} catch (UnsupportedOperationException ex) {
throw new RcvrUnimplementedFnException("Editing a file is not implemented", ex);
} catch (IOException ex) {
throw new RcvrIOException("Problem when trying to edit a file.", ex);
}
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState in project cogtool by cogtool.
the class ProjectController method createExportActrModelFile.
// Action for ExportDesignFiles
// XXX: does this really belong in ProjectController? It seems like
// something that's tied to whichever backend we're really using,
// and so should be somewhere else
protected IListenerAction createExportActrModelFile() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object actionParms) {
ProjectSelectionState sel = (ProjectSelectionState) actionParms;
// Must have selected tasks and design
Design design = sel.getSelectedDesign();
AUndertaking[] tasks = sel.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
if ((design == null) || (tasks == null) || (tasks.length == 0)) {
return false;
}
// Ask user for location of saved file.
File exportFile = interaction.selectExportLocation("Exported ACT-R Model", CogToolFileTypes.LISP_FILE_EXT);
// User canceled
if (exportFile == null) {
return false;
}
for (AUndertaking task : tasks) {
// If no script set exists for this cell, create
TaskApplication ta = project.getTaskApplication(task, design);
if (ta != null) {
if (ta.getDesign() != design) {
throw new RcvrIllegalStateException("Unexpected Design mis-match (" + ta.getDesign() + ", " + design + ")");
}
// If no script exists for this cell, create one
Script script = DemoStateManager.ensureScript(ta, MODELGEN_ALG);
try {
IPredictionAlgo taAlg = ta.determineActiveAlgorithm(project);
if (!(taAlg instanceof ACTRPredictionAlgo)) {
throw new RcvrIllegalStateException("Can't export ACT-R Model from a non ACT-R task.");
}
if (script.getAssociatedPath() != null) {
File f = new File(script.getAssociatedPath());
// The following will throw an IOException if
// the input file doesn't exist; this is exactly
// the same behaviour as if we're trying to do
// a recompute, and is better than silently
// substituting a generated model file
FileUtil.copyTextFileToFile(f, exportFile);
return true;
}
ACTRPredictionAlgo algo = (ACTRPredictionAlgo) taAlg;
algo.outputModel(design, task, ta.getDemonstration().getStartFrame(), script, exportFile, null);
} catch (UnsupportedOperationException ex) {
throw new RcvrUnimplementedFnException(ex);
} catch (IOException ex) {
throw new RcvrIOException(("IOException exporting model file for task " + task.getName() + " in design " + design.getName()), ex);
}
}
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState in project cogtool by cogtool.
the class ProjectController method createExportDictionaryAction.
protected IListenerAction createExportDictionaryAction() {
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.reportProblem("Export Dictionary", "No design is selected");
return false;
}
ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if (dict == null) {
interaction.reportProblem("Export Dictionary", "No dictionary exists for the selected design");
return false;
}
return DictionaryEditorCmd.exportDictionaryToCSV(dict, interaction);
}
};
}
use of edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState in project cogtool by cogtool.
the class ProjectController method createGenerateDictionaryAction.
protected IListenerAction createGenerateDictionaryAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object prms) {
ProjectSelectionState seln = (ProjectSelectionState) prms;
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
Design d = seln.getSelectedDesign();
boolean hasDict = false;
ITermSimilarity defaultAlg = ISimilarityDictionary.DEFAULT_ALG;
if (d != null) {
ISimilarityDictionary dict = (ISimilarityDictionary) d.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if (!NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY)) {
hasDict = true;
defaultAlg = dict.getCurrentAlgorithm();
}
} else {
// No design selected, so just show the compute options
hasDict = true;
}
ProjectInteraction.GenerateEntriesData requestData = requestGenerateParms(generateEntriesMessage, defaultAlg, hasDict);
if (requestData == null) {
return false;
}
GenerateDictEntriesWorkThread workThread = new GenerateDictEntriesWorkThread(interaction, d, tasks, project, undoMgr, requestData);
CogTool.logger.info(String.format("Generating dictionary for design %s in project %s.", d.getName(), getProject().getName()));
ThreadManager.startNewThread(workThread);
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState 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;
}
};
}
Aggregations