use of edu.cmu.cs.hcii.cogtool.util.IListenerAction 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.util.IListenerAction in project cogtool by cogtool.
the class ProjectController method createDemoteTaskAction.
protected IListenerAction createDemoteTaskAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return TaskSelectionState.class;
}
public boolean performAction(Object prms) {
TaskSelectionState seln = (TaskSelectionState) prms;
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION);
if ((tasks == null) || (tasks.length == 0)) {
interaction.protestNoSelection();
return false;
}
List<String> errors = new ArrayList<String>();
String editLabel = (tasks.length > 1) ? DEMOTE_TASKS : DEMOTE_TASK;
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(editLabel, ProjectLID.DemoteTask);
for (AUndertaking task : tasks) {
String demoteError = demoteTask(task, editSeq);
if (demoteError != null) {
errors.add(demoteError);
}
}
if (errors.size() > 0) {
interaction.reportProblems(editLabel, errors);
}
if (editSeq.isSignificant()) {
editSeq.end();
undoMgr.addEdit(editSeq);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction 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.util.IListenerAction in project cogtool by cogtool.
the class ProjectController method createImportAction.
protected IListenerAction createImportAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object prms) {
boolean computeScripts = CogToolPref.COMPSCR.getBoolean();
if (importFile == null) {
importFile = interaction.selectXMLFile(true, null);
} else {
computeScripts = importFileComputes;
}
if (importFile == null) {
return false;
}
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(importXMLPresentation, ProjectLID.ImportXML);
Map<Design, Collection<Demonstration>> parsedDesigns = null;
Set<AUndertaking> newUndertakings = null;
TaskParent parent = project;
try {
if (CogToolPref.HCIPA.getBoolean()) {
TaskGroup importGroup = new TaskGroup(importFile.getName(), GroupNature.SUM);
parent = importGroup;
project.addUndertaking(importGroup);
editSeq.addEdit(createNewTaskUndo(project, Project.AT_END, importGroup, ProjectLID.ImportXML, importXMLPresentation));
}
ImportCogToolXML importer = new ImportCogToolXML();
if (!importer.importXML(importFile, parent, MODELGEN_ALG) || (importer.getDesigns().size() == 0)) {
List<String> errors = importer.getObjectFailures();
if ((errors != null) && (errors.size() > 0)) {
interaction.reportProblems(importXMLPresentation, errors);
} else {
interaction.reportProblem(importXMLPresentation, xmlParseFailed);
}
return false;
}
List<String> warnings = importer.getGenerationWarnings();
if (warnings.size() > 0) {
interaction.reportWarnings(importXMLPresentation, warnings);
}
parsedDesigns = importer.getDesigns();
newUndertakings = importer.getNewUndertakings();
} catch (ImportCogToolXML.ImportFailedException ex) {
throw new RcvrXMLParsingException("Missing XML component", ex);
} catch (GraphicsUtil.ImageException ex) {
throw new RcvrImageException("Image error during loading XML", ex);
} catch (IOException ex) {
throw new RcvrXMLParsingException("IO error loading XML", ex);
} catch (SAXException ex) {
throw new RcvrXMLParsingException("Error parsing XML", ex);
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
importFile = null;
importFileComputes = false;
}
for (AUndertaking u : newUndertakings) {
parent.addUndertaking(u);
final AUndertaking uu = u;
final TaskParent pp = parent;
editSeq.addEdit(new AUndoableEdit(ProjectLID.ImportXML) {
@Override
public void redo() {
super.redo();
pp.addUndertaking(uu);
}
@Override
public void undo() {
super.undo();
pp.removeUndertaking(uu);
}
});
}
Iterator<Map.Entry<Design, Collection<Demonstration>>> designDemos = parsedDesigns.entrySet().iterator();
while (designDemos.hasNext()) {
Map.Entry<Design, Collection<Demonstration>> entry = designDemos.next();
importDesign(parent, (DesignSelectionState) prms, entry.getKey(), entry.getValue(), newUndertakings, editSeq);
}
editSeq.end();
undoMgr.addEdit(editSeq);
if (computeScripts) {
//compute predictions for imported project
ProjectContextSelectionState seln = new ProjectContextSelectionState(project);
seln.addSelectedDesigns(project.getDesigns());
ui.selectAllTasks();
recomputeScripts(seln);
ui.deselectAllTasks();
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class SEDemoController method createInsertSelfTransitionAction.
protected IListenerAction createInsertSelfTransitionAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return SEDemoUI.SelfTransition.class;
}
public boolean performAction(Object actionParms) {
SEDemoUI.SelfTransition prms = (SEDemoUI.SelfTransition) actionParms;
if (prms.target != null) {
TaskApplication taskApp = script.getDemonstration().getTaskApplication();
Set<DeviceType> deviceTypeSet = taskApp.getDesign().getDeviceTypes();
int deviceTypes = DeviceType.buildDeviceSet(deviceTypeSet);
int limitMode = ActionProperties.determineChangeActionMode(prms.target);
AAction action = prms.action;
if (prms.action == null) {
properties.resetValues();
properties.setInitialActionType(prms.target, deviceTypeSet);
if (!interaction.determineNewAction(properties, deviceTypes, limitMode, L10N.get("DE.SetActionType", "Set Action Type"))) {
return false;
}
action = EditActionCmd.buildActionFromProperties(properties, deviceTypes, limitMode, interaction);
if (action == null) {
return false;
}
}
action = EditActionCmd.ensureActionIsUnique(prms.target, action, properties, deviceTypes, limitMode, null, interaction);
if (action == null) {
return false;
}
return performSelfTransition(prms.selection, prms.target, action, properties.delayInSecs, properties.delayLabel);
}
return false;
}
};
}
Aggregations