use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class ScriptViewerUI method addSelectionChangeListeners.
/**
* Add the selection Change event listeners.
*/
protected void addSelectionChangeListeners() {
SWTselectionChangeHandler = new SelectionListener() {
public void widgetSelected(SelectionEvent evt) {
SWTList swtList = view.getScriptEditorList();
TableItem[] selectedItems = swtList.getSelectionObject();
for (TableItem selectedItem : selectedItems) {
// TODO: Currently supports only single selection.
Object data = selectedItem.getData();
if (data instanceof Frame) {
selection.setSelectedState(null);
} else {
selection.setSelectedState(selectedItem);
}
}
setViewEnabledState(selection, ListenerIdentifierMap.NORMAL);
// Let selection change handle changing the frame
}
public void widgetDefaultSelected(SelectionEvent evt) {
SWTList swtList = view.getScriptEditorList();
TableItem[] selectedItems = swtList.getSelectionObject();
// TODO: Currently supports only single selection.
for (TableItem selectedItem : selectedItems) {
Object data = selectedItem.getData();
if (data instanceof DefaultModelGeneratorState) {
Script s = (Script) selectedItem.getData(SWTListGroupScript.SCRIPT_DATA_KEY);
DefaultModelGeneratorState stepState = (DefaultModelGeneratorState) data;
// In case we need this; not a context selection
// in truth, but we can re-use the structure.
contextSelection.setSelectedState(stepState);
performAction(ProjectLID.EditScript, s);
}
}
}
};
view.addSWTListSelectionHandler(SWTselectionChangeHandler);
AlertHandler selectionChangeHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
SEDemoSelectionState.StepStateSelectionChange event = (SEDemoSelectionState.StepStateSelectionChange) alert;
if (event != null) {
if (event.selected) {
DefaultModelGeneratorState stepState = event.changedState;
Frame resultFrame = null;
Script script = getSelectedScript(stepState);
AUndertaking t = script.getDemonstration().getTaskApplication().getTask();
if (stepState != null) {
resultFrame = stepState.getScriptStep().getCurrentFrame();
} else if (script != null) {
resultFrame = script.getDemonstration().getResultFrame();
}
DefaultModelGeneratorState overrideState = script.getPreviousState(stepState);
if (overrideState == null) {
TaskGroup group = (TaskGroup) task;
List<AUndertaking> siblingTasks = group.getUndertakings();
int currentTaskIndex = siblingTasks.indexOf(t);
CognitiveModelGenerator modelGen = script.getModelGenerator();
while ((overrideState == null) && (0 <= --currentTaskIndex)) {
AUndertaking prevSibling = siblingTasks.get(currentTaskIndex);
TaskApplication ta = project.getTaskApplication(prevSibling, design);
if (ta != null) {
script = ta.getScript(modelGen);
if (script != null) {
overrideState = script.getLastState();
}
}
}
}
uiModel.setCurrentOverride(script, overrideState);
try {
setCurrentFrame(resultFrame);
} catch (GraphicsUtil.ImageException ex) {
throw new RcvrImageException("Changing current demonstration frame", ex);
}
}
}
}
};
selection.addHandler(this, SEDemoSelectionState.StepStateSelectionChange.class, selectionChangeHandler);
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class ProjectUI method createPredicates.
// setUpDragAndDrop
protected void createPredicates() {
requiresRegenerationPredicate = new ProjectSelectionPredicate(project) {
@Override
protected boolean isSatisfiedBy(Design design, AUndertaking t) {
TaskApplication ta = project.getTaskApplication(t, design);
if (ta != null) {
Demonstration demo = ta.getDemonstration();
return demo.isObsolete();
}
return false;
}
};
hasComputableScriptsPredicate = new ProjectSelectionPredicate(project) {
@Override
protected boolean isSatisfiedBy(Design design, AUndertaking t) {
TaskApplication taskApp = project.getTaskApplication(t, design);
if (taskApp != null) {
IPredictionAlgo activeAlg = taskApp.determineActiveAlgorithm(project);
APredictionResult result = taskApp.getResult(taskApp.getFirstModelGenerator(), activeAlg);
if ((result != null) && !result.canBeRecomputed()) {
return false;
}
return taskApp.hasComputableScript() && !taskApp.getDemonstration().isInvalid();
}
return project.getDefaultAlgo() == SNIFACTPredictionAlgo.ONLY;
}
};
hasComputedResultPredicate = new ProjectSelectionPredicate(project) {
@Override
protected boolean isSatisfiedBy(Design design, AUndertaking t) {
TaskApplication taskApp = project.getTaskApplication(t, design);
return ((taskApp != null) && taskApp.hasComputedResult());
}
};
hasResultStepsPredicate = new ProjectSelectionPredicate(project) {
@Override
protected boolean isSatisfiedBy(Design design, AUndertaking t) {
TaskApplication taskApp = project.getTaskApplication(t, design);
return (taskApp != null) && taskApp.hasResultSteps();
}
};
hasScriptsPredicate = new ProjectSelectionPredicate(project) {
@Override
protected boolean isSatisfiedBy(Design design, AUndertaking t) {
TaskApplication taskApp = project.getTaskApplication(t, design);
return (taskApp != null) && taskApp.hasScript();
}
};
hasTracesPredicate = new ProjectSelectionPredicate(project) {
@Override
protected boolean isSatisfiedBy(Design design, AUndertaking t) {
TaskApplication taskApp = project.getTaskApplication(t, design);
return (taskApp != null) && taskApp.hasResultTraces();
}
};
hasMultipleScriptsPredicate = new ProjectSelectionPredicate(project) {
protected int numScripts = 0;
@Override
protected void resetState() {
numScripts = 0;
}
@Override
protected boolean isSatisfiedBy(Design design, AUndertaking t) {
TaskApplication taskApp = project.getTaskApplication(t, design);
if (taskApp != null) {
Iterator<CognitiveModelGenerator> modelGens = taskApp.getModelGenerators();
while (modelGens.hasNext()) {
CognitiveModelGenerator modelGen = modelGens.next();
Script script = taskApp.getScript(modelGen);
if (script != null) {
if (++numScripts > 1) {
return true;
}
}
}
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class ScriptViewerUI method getSelectedScript.
protected Script getSelectedScript(DefaultModelGeneratorState stepState) {
SWTList swtList = view.getScriptEditorList();
if (stepState == null) {
TaskGroup group = (TaskGroup) task;
List<AUndertaking> tasks = group.getUndertakings();
int numTasks = tasks.size();
for (int i = numTasks - 1; i >= 0; i--) {
AUndertaking t = tasks.get(i);
TaskApplication ta = project.getTaskApplication(t, design);
if (ta != null) {
return ta.getOnlyScript();
}
}
}
TableItem item = swtList.getItemList().get(stepState);
return (Script) item.getData(SWTListGroupScript.SCRIPT_DATA_KEY);
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class ProjectController method createMoveTaskAppAction.
protected IListenerAction createMoveTaskAppAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectUI.MoveCopyTaskApplicationParms.class;
}
public boolean performAction(Object p) {
if (p != null) {
ProjectUI.MoveCopyTaskApplicationParms parms = (ProjectUI.MoveCopyTaskApplicationParms) p;
// Must have selected tasks and design
if ((parms.design == null) || (parms.fromTask == null) || (parms.toTask == null)) {
interaction.protestNoSelection();
return false;
}
final AUndertaking fromTask = parms.fromTask;
final AUndertaking toTask = parms.toTask;
final TaskApplication taskApp = project.removeTaskApplication(parms.fromTask, parms.design);
if (taskApp == null) {
interaction.protestNoTaskApplication();
return false;
}
final TaskApplication oldTaskApp = project.removeTaskApplication(parms.toTask, parms.design);
taskApp.setTask(toTask);
project.setTaskApplication(taskApp);
IUndoableEdit edit = new AUndoableEdit(ProjectLID.MoveTaskApplication) {
@Override
public String getPresentationName() {
return MOVE_TASKAPP;
}
@Override
public void redo() {
super.redo();
project.removeTaskApplication(taskApp);
if (oldTaskApp != null) {
project.removeTaskApplication(oldTaskApp);
}
taskApp.setTask(toTask);
project.setTaskApplication(taskApp);
}
@Override
public void undo() {
super.undo();
project.removeTaskApplication(taskApp);
taskApp.setTask(fromTask);
if (oldTaskApp != null) {
project.setTaskApplication(oldTaskApp);
}
project.setTaskApplication(taskApp);
}
};
undoMgr.addEdit(edit);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class ProjectController method createDuplicateDesignAction.
protected IListenerAction createDuplicateDesignAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return DesignSelectionState.class;
}
public boolean performAction(Object prms) {
DesignSelectionState seln = (DesignSelectionState) prms;
Design design = seln.getSelectedDesign();
// Can only duplicate if a design is currently selected.
if (design == null) {
interaction.protestNoSelection();
return false;
}
// Determine new name
String copyName = NamedObjectUtil.makeNameUnique(design.getName(), project.getDesigns());
Design designCopy = design.duplicate(copyName);
ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if (!NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY)) {
designCopy.setAttribute(WidgetAttributes.DICTIONARY_ATTR, dict.duplicate());
}
ProjectCmd.addNewDesign(project, designCopy, seln.getSelectedDesign(), DUPLICATE_DESIGN, undoMgr);
Map<ITaskDesign, TaskApplication> associatedTAs = project.taskApplicationsForDesign(design);
duplicateTaskApplications(designCopy, associatedTAs);
return true;
}
};
}
Aggregations