use of edu.cmu.cs.hcii.cogtool.model.AUndertaking 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.AUndertaking 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.AUndertaking 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.AUndertaking 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.AUndertaking in project cogtool by cogtool.
the class ProjectSelectionState method getSelectedTasks.
/**
* Return the set of selected undertakings (tasks and/or task groups).
* <p>
* Although it should not be depended upon, the returned array
* is generally not <code>null</code> (which would indicate no selected
* undertakings). Instead, if there are no selected undertakings,
* an array of zero length is returned.
* <p>
* The mode parameter indicates whether or not to prune the set of selected
* undertakings (i.e., pruning removes from consideration those selected
* undertakings that are children of other selected ITaskGroups) and/or
* whether or not to ensure the selected undertakings are presented in
* order of their occurrence in the pre-order traversal of the Project's
* root undertakings. The constants PRUNE_SELECTION and ORDER_SELECTION
* may be OR'ed together for both effects. For neither effect, to achieve
* the fastest "selection" (e.g., when it is known that only one task is
* selected), FAST_SELECTION may be used.
*
* @param flags whether to prune and/or present
* @return the set of selected undertakings
* @author mlh
*/
public AUndertaking[] getSelectedTasks(int flags) {
boolean prune = (flags & PRUNE_SELECTION) != 0;
boolean taskGroupsOnly = (flags & TASK_GROUPS_ONLY) != 0;
List<AUndertaking> keptTasks = new ArrayList<AUndertaking>();
if ((flags & ORDER_SELECTION) != 0) {
orderSelection(project.getUndertakings().iterator(), prune, taskGroupsOnly, keptTasks);
} else {
Iterator<AUndertaking> allSelectedTasks = getSelectedTaskIterator();
while (allSelectedTasks.hasNext()) {
AUndertaking selectedTask = allSelectedTasks.next();
if ((!prune) || (!isAncestorSelected(selectedTask))) {
if ((!taskGroupsOnly) || selectedTask.isTaskGroup()) {
keptTasks.add(selectedTask);
}
}
}
}
AUndertaking[] selection = new AUndertaking[keptTasks.size()];
keptTasks.toArray(selection);
return selection;
}
Aggregations