use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method createShowModelVisualizationAction.
// Action for ShowVisualization
protected IListenerAction createShowModelVisualizationAction() {
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);
if ((design == null) || (tasks == null) || (tasks.length == 0)) {
return false;
}
boolean visCreated = false;
for (AUndertaking task : tasks) {
if (createVisualization(design, task, -1)) {
visCreated = true;
break;
}
}
if (!visCreated) {
interaction.reportProblem(visualizationNotCreated, noResultsToVisualize);
}
return visCreated;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class SWTTreeProjectSelectionState method setSelectedCell.
/**
* Support for selecting a cell
*/
public void setSelectedCell(TreeItem item, TreeColumn column) {
if ((item != null) && (column != null)) {
AUndertaking t = (AUndertaking) item.getData();
Design d = (Design) column.getData();
if ((t != null) && (d != null)) {
deselectAll();
selectedColumns.add(column);
selectedItems.put(t, item);
raiseAlert(new ProjectSelectionChange(this, tree.indexOf(column), item, true));
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking 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.AUndertaking in project cogtool by cogtool.
the class ProjectUI method initiateTaskRename.
// initiateTaskRename
/**
* Triggers the task-renaming functionality in the UI on the given
* TreeItem's AUndertaking.
*/
public void initiateTaskRename(TreeItem taskToRenameItem, boolean selectAll) {
// Can progress only if no other rename is already in progress
if ((editor.getEditor() == null) && (taskToRenameItem != null)) {
// Ensure the selection is set properly so it looks right when done
selection.setSelectedItem(taskToRenameItem);
final AUndertaking task = (AUndertaking) taskToRenameItem.getData();
// The editor must have the same size as the cell.
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
// The control that will be the editor must be a child of the Tree
ManagedText newEditor = new ManagedText(tree, SWT.SINGLE | SWT.LEFT, Keypad.FULL_KEYPAD) {
@Override
public boolean confirm(int focusRule) {
return commitRenameTask(true);
}
@Override
public void cancel() {
cleanupTaskEditor();
}
};
newEditor.setFocus();
String taskName = task.getName();
int nameLength = taskName.length();
newEditor.setText(taskName);
if (selectAll) {
newEditor.selectAll();
} else {
newEditor.setSelection(nameLength, nameLength);
}
editor.setEditor(newEditor, taskToRenameItem);
setViewEnabledState(selection, ListenerIdentifierMap.NORMAL);
}
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectUI method showContextMenu.
// Override to set the correct context menu on the frame
// item item-selected column design where selection to use
//(a) ok n/a ok ok cell temporary cell
//(b) ok yes ok null task normal selection
//(c) ok no ok null task temporary task
//(d) ok n/a null n/a right of cells temporary task
//(e) null n/a ok ok design temporary design
//(f) null n/a ok null bottom-left no selection
//(g) null n/a null n/a bottom-right no selection
// TODO: dfm -- make the code match the above!!!!!
@Override
public void showContextMenu(int x, int y) {
// Clear any stale state
contextSelection.deselectAll();
// Check which region of the frame was hit
TreeItem item = tree.getItem(new Point(x, y));
TreeColumn column = findColumn(x);
// See if the context invocation was made beyond all designs
if (column == null) {
if (item == null) {
// see (g) above
showContextMenu();
} else {
// see (d) above
selectOverBox(item.getBounds());
contextSelection.addSelectedTask((AUndertaking) item.getData());
showContextMenu(contextSelection, View.CONTEXT);
}
} else // If not, the invocation occurred somewhere within the table
{
Design design = (Design) column.getData();
// Detect a context invocation in the table header/footer
if (item == null) {
// Detect a context invocation under the "tasks" heading
if (design == null) {
// see (f) above
showContextMenu();
} else // Otherwise the invocation lies under a design heading
{
// see (e) above
// TODO: Really? What if something else was selected?
selectOverBox(computeColumnArea(column));
contextSelection.setSelectedDesign(design);
showContextMenu(contextSelection, View.CONTEXT);
}
} else // Detect a context invocation inside the table body
{
AUndertaking undertaking = (AUndertaking) item.getData();
// Check for context invocation under the "tasks" column
if (design == null) {
// Set up the contextual selection state as necessary
if (selection.isTaskSelected(undertaking)) {
// see (b) above
showContextMenu();
} else {
// see (c) above
selectOverBox(item.getBounds());
contextSelection.addSelectedTask(undertaking);
showContextMenu(contextSelection, View.CONTEXT);
}
} else // Otherwise at the intersection of a task and a design
{
// see (a) above
selection.setSelectedCell(item, column);
Rectangle bounds = item.getBounds(tree.indexOf(column));
if (OSUtils.MACOSX) {
// XXX: DIRTY HACK TO fix SWT bug.
bounds.y -= 1;
bounds.height += 1;
}
selectOverBox(bounds);
// TODO: instead of the following, pass undertaking and
// design in to showContextMenuForIntersection()
Menu contextMenu = view.getContextMenuForIntersection(project, undertaking, design);
// Set up the contextual selection state as necessary
contextSelection.setSelectedDesign(design);
contextSelection.addSelectedTask(undertaking);
setViewEnabledState(contextSelection, ListenerIdentifierMap.CONTEXT);
contextMenu.setVisible(true);
}
}
}
}
Aggregations