use of edu.cmu.cs.hcii.cogtool.model.TaskGroup 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.TaskGroup in project cogtool by cogtool.
the class ProjectUI method commitRenameTask.
// initiateTaskRename
/**
* Reports a task renaming to the controller.
* @param item
*/
protected boolean commitRenameTask(boolean activeCommit) {
boolean success = true;
if (editor.getEditor() != null) {
Text text = (Text) editor.getEditor();
String newName = text.getText();
TreeItem item = editor.getItem();
// Get task & parent taskgroup from item, don't use this.selection!
AUndertaking taskToRename = (AUndertaking) item.getData();
TreeItem parentItem = item.getParentItem();
TaskGroup parentGroup = (TaskGroup) ((parentItem != null) ? parentItem.getData() : null);
cleanupTaskEditor();
success = performAction((CogToolPref.HCIPA.getBoolean()) ? ProjectLID.HCIPARenameTask : ProjectLID.RenameTask, new ProjectUI.TaskRenameEvent(taskToRename, newName, parentGroup), false);
if (activeCommit) {
renameTaskItem = null;
}
}
return success;
}
use of edu.cmu.cs.hcii.cogtool.model.TaskGroup in project cogtool by cogtool.
the class ProjectMouseState method dealWithMouseDoubleClick.
@Override
protected void dealWithMouseDoubleClick(MouseEvent me) {
super.dealWithMouseDoubleClick(me);
TreeItem item = ui.tree.getItem(new Point(me.x, me.y));
TreeColumn column = ui.findColumn(me.x);
// check to see if the group visibility should toggle
if ((item != null) && (column == null)) {
// Toggle tree expand when a TaskGroup is double-clicked,
// but not if double-clicking on the first column to edit the name
AUndertaking u = (AUndertaking) item.getData();
if (u.isTaskGroup()) {
item.setExpanded(!item.getExpanded());
}
}
// If on a valid cell, either edit script or open the script viewer
if ((item != null) && (column != null) && (column.getData() != null)) {
AUndertaking u = (AUndertaking) item.getData();
// At the intersection of a task and design
ProjectContextSelectionState seln = new ProjectContextSelectionState(ui.getProject());
seln.setSelectedDesign((Design) column.getData());
seln.addSelectedTask(u);
if (u.isTaskGroup()) {
TaskGroup group = (TaskGroup) u;
if (GroupNature.SUM.equals(group.getNature())) {
item.setExpanded(true);
ui.cleanupTaskEditor();
//TODO: won't work since repaint won't occur until after we're all done.
ui.performAction(ProjectLID.ViewGroupScript, seln);
}
} else {
ui.cleanupTaskEditor();
//TODO: won't work since repaint won't occur until after we're all done.
ui.performAction(ProjectLID.EditScript, seln);
}
} else if ((item != null) && (column != null) && (column.getData() == null)) {
// In a valid row, first column
if (ui.treeOperationOccurred == 0) {
ui.initiateTaskRename(item, true);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.TaskGroup in project cogtool by cogtool.
the class ProjectSelectionState method getSelectedTaskParents.
/**
* Retrieves the parents of all selected tasks/groups.
*
* @return an array of task groups, using null to signify root tasks/groups
*/
public TaskGroup[] getSelectedTaskParents() {
int selectedItemCount = getSelectedTaskCount();
TaskGroup[] parents = new TaskGroup[selectedItemCount];
Iterator<AUndertaking> selectedTasks = getSelectedTaskIterator();
int i = 0;
while (selectedTasks.hasNext()) {
AUndertaking task = selectedTasks.next();
parents[i++] = task.getTaskGroup();
}
return parents;
}
use of edu.cmu.cs.hcii.cogtool.model.TaskGroup in project cogtool by cogtool.
the class ProjectSelectionState method getSelectedTaskParent.
/**
* Retrieves the parent task group that contains the selected undertaking.
*
* @return the parent task group if a all selected undertakings have the
* same parent; <code>null</code> is returned if there are no
* selected undertakings or if there are multiple selected
* undertakings with different parents or if all selected
* undertakings are top-level.
*/
public TaskGroup getSelectedTaskParent() {
boolean first = true;
TaskGroup allParent = null;
// Examine the parent task group for each selected undertaking
Iterator<AUndertaking> taskIt = getSelectedTaskIterator();
while (taskIt.hasNext()) {
AUndertaking item = taskIt.next();
TaskGroup parentOfItem = item.getTaskGroup();
// then null is the only possible response.
if (parentOfItem == null) {
return null;
}
// Remember first parent to compare against the remaining ones
if (first) {
first = false;
allParent = parentOfItem;
} else if (parentOfItem != allParent) {
// return null
return null;
}
}
// If there is no selected undertaking, return null
if (allParent == null) {
return null;
}
// Otherwise, return the shared parent task group
return allParent;
}
Aggregations