use of edu.cmu.cs.hcii.cogtool.model.GroupNature in project cogtool by cogtool.
the class ResultDisplayPolicy method computeGroup.
// getTaskApplicationCell
/**
* Recursively computes value of script results on a particular design
* for tasks within a group.
*
* @param group the group whose resVal to calculate
* @param d the design whose script results should be used here
* @return the recursive value of script results on design d
* for tasks in the given TaskGroup; -1.0 if the group is empty
*/
public static double computeGroup(Project project, TaskGroup group, Design d) {
List<AUndertaking> children = group.getUndertakings();
if (children.size() == 0) {
// trivial case
return TimePredictionResult.UNSET_TIME;
}
GroupNature nature = group.getNature();
boolean validReturnValue = false;
double returnValue = 0.0d;
double meanDivisor = 0.0d;
for (AUndertaking child : children) {
double stepValue = TimePredictionResult.UNSET_TIME;
if (child.isTaskGroup()) {
// recursive (TaskGroup) case
stepValue = computeGroup(project, (TaskGroup) child, d);
} else {
// terminal case
TaskApplication ta = project.getTaskApplication(child, d);
if (ta != null) {
APredictionResult result = ta.getResult(ta.getFirstModelGenerator(), ta.determineActiveAlgorithm(project));
stepValue = getComputationResult(result);
}
}
if ((nature == GroupNature.SUM) || (nature == GroupNature.MEAN)) {
if (stepValue != TimePredictionResult.UNSET_TIME) {
returnValue += stepValue;
meanDivisor += 1.0d;
validReturnValue = true;
}
} else if (nature == GroupNature.MIN) {
if ((stepValue != TimePredictionResult.UNSET_TIME) && ((stepValue < returnValue) || (!validReturnValue))) {
returnValue = stepValue;
validReturnValue = true;
}
} else if (nature == GroupNature.MAX) {
if (stepValue > returnValue) {
returnValue = stepValue;
validReturnValue = true;
}
}
}
if (validReturnValue) {
if ((nature == GroupNature.MEAN) && (meanDivisor != 0.0d)) {
returnValue /= meanDivisor;
}
return returnValue;
}
return TimePredictionResult.UNSET_TIME;
}
use of edu.cmu.cs.hcii.cogtool.model.GroupNature in project cogtool by cogtool.
the class ProjectUI method setViewEnabledState.
/**
* Enables or disables LIDs as appropriate
* @param sel the selection state on which to base enabling/disabling
* @param availability NORMAL or CONTEXT
* @see ListenerIdentifierMap
*/
protected void setViewEnabledState(ProjectSelectionState sel, Boolean availability) {
boolean hasDesign = sel.getSelectedDesign() != null;
setEnabled(CogToolLID.AddDesignDevices, availability, hasDesign);
String scriptLabel = "";
scriptLabel = hasMultipleScripts(sel) ? " " + SCRIPTS_LABEL : " " + SCRIPT_LABEL;
String label = "";
int selectedTaskCount = sel.getSelectedTaskCount();
boolean isSnifActTask = snifActTasksSelected(sel, TaskSelectionState.PRUNE_SELECTION);
boolean isSnifActGroup = snifActTasksSelected(sel, TaskSelectionState.TASK_GROUPS_ONLY);
if (selectedTaskCount > 0) {
AUndertaking[] tasks = sel.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
boolean allGroups = true;
for (int i = 0; i < tasks.length; i++) {
if (!tasks[i].isTaskGroup()) {
allGroups = false;
}
}
if (allGroups) {
label = (selectedTaskCount > 1) ? (" " + TASK_GROUPS_LABEL) : (" " + TASK_GROUP_LABEL);
} else {
label = (selectedTaskCount > 1) ? (" " + TASKS_LABEL) : (" " + TASK_LABEL);
}
}
if (hasDesign) {
label = " " + DESIGN_LABEL;
setEnabled(CogToolLID.ExportToXML, ListenerIdentifierMap.ALL, MenuUtil.ENABLED, L10N.get("PR.ExportDesignXMLLabel", "Export Design to XML"));
} else {
setEnabled(CogToolLID.ExportToXML, ListenerIdentifierMap.ALL, MenuUtil.ENABLED, EXPORT_PROJECT_LABEL);
}
String cutCopyLabel = (editor.getEditor() != null) ? "" : label;
String regenerateString = regenerateTitle;
boolean requiresRegeneration = selectionRequiresRegeneration(sel);
if (requiresRegeneration) {
regenerateString += scriptLabel;
}
setEnabled(CogToolLID.RegenerateScript, availability, requiresRegeneration, regenerateString);
AUndertaking[] tasks = sel.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
boolean singleTask = selectedTaskCount == 1;
boolean cellSelected = hasDesign && singleTask;
boolean anySelection = hasDesign || (selectedTaskCount > 0);
setEnabled(CogToolLID.ExportDesignToHTML, availability, hasDesign);
setEnabled(ProjectLID.ExportDictToCSV, availability, hasDesign);
setEnabled(ProjectLID.ImportDict, availability, hasDesign);
setEnabled(CogToolLID.CaptureBehavior, availability, true);
if (cellSelected) {
setEnabled(CogToolLID.Paste, availability, false);
setEnabled(CogToolLID.Duplicate, availability, false, MenuFactory.DUPLICATE_STRING);
setEnabled(CogToolLID.Rename, availability, false, MenuFactory.RENAME_STRING);
setEnabled(CogToolLID.Cut, availability, false, MenuFactory.CUT_STRING);
setEnabled(CogToolLID.Copy, availability, false, MenuFactory.COPY_STRING);
setEnabled(CogToolLID.Delete, availability, false, MenuFactory.DELETE_STRING);
String editLabel = MenuFactory.EDIT_STRING + " " + SCRIPT_LABEL;
boolean editEnabled = true;
if (tasks[0].isTaskGroup()) {
if (GroupNature.SUM.equals(((TaskGroup) tasks[0]).getNature())) {
editLabel = VIEW_SCRIPTS;
} else {
editLabel = MenuFactory.EDIT_STRING;
editEnabled = false;
}
}
setEnabled(CogToolLID.Edit, availability, editEnabled, editLabel);
if (isSnifActTask) {
// If it's a task generated by a run of SNIF-ACT (and therefore
// put in a group that has that attribute), the algorithm in its
// cell should never be changed.
setEnabled(ProjectLID.SetAlgorithmACTR6, availability, false);
setEnabled(ProjectLID.SetAlgorithmSNIFACT, availability, false);
setEnabled(ProjectLID.SetAlgorithmDefault, availability, false);
setEnabled(ProjectLID.SetAlgorithmHuman, availability, false);
setEnabled(ProjectLID.SetBackgroundComputationDefault, availability, false);
setEnabled(ProjectLID.SetBackgroundComputationFalse, availability, false);
setEnabled(ProjectLID.SetBackgroundComputationTrue, availability, false);
}
} else if (isSnifActTask) {
setEnabled(CogToolLID.Paste, availability, false);
setEnabled(CogToolLID.Duplicate, availability, false, MenuFactory.DUPLICATE_STRING);
setEnabled(CogToolLID.Cut, availability, false, MenuFactory.CUT_STRING);
setEnabled(CogToolLID.Copy, availability, false, MenuFactory.COPY_STRING);
setEnabled(CogToolLID.Rename, availability, hasDesign || singleTask, MenuFactory.RENAME_STRING + label);
setEnabled(CogToolLID.NewTask, availability, false);
setEnabled(CogToolLID.NewTaskGroup, availability, false);
} else {
setEnabled(CogToolLID.NewTask, availability, true);
setEnabled(CogToolLID.NewTaskGroup, availability, true);
setEnabled(CogToolLID.Paste, availability, true);
String dupString = MenuFactory.DUPLICATE_STRING;
if (anySelection) {
dupString += label;
}
setEnabled(CogToolLID.Duplicate, availability, anySelection, dupString);
// Edit enabled if only a single design selected
String editString = MenuFactory.EDIT_STRING;
if (hasDesign) {
editString += label;
}
setEnabled(CogToolLID.Edit, availability, hasDesign, editString);
// Rename enabled if a single selection
boolean enabled = hasDesign || singleTask;
String renameString = MenuFactory.RENAME_STRING;
if (enabled) {
renameString += label;
}
setEnabled(CogToolLID.Rename, availability, enabled, renameString);
// Cut, Copy, Delete, DeselectAll should be enabled
// if there is any selection (task or design)
setEnabled(CogToolLID.Cut, availability, anySelection, MenuFactory.CUT_STRING + cutCopyLabel);
setEnabled(CogToolLID.Copy, availability, anySelection, MenuFactory.COPY_STRING + cutCopyLabel);
setEnabled(CogToolLID.Delete, availability, anySelection, MenuFactory.DELETE_STRING + label);
setEnabled(CogToolLID.DeselectAll, availability, anySelection);
}
boolean showRecompute = anySelection && taskHasComputableScripts(sel);
if (!showRecompute && hasDesign && sel.getSelectedTaskCount() == 1) {
Design design = sel.getSelectedDesign();
TaskApplication taskApp = project.getTaskApplication(sel.getSelectedTask(), design);
if (taskApp != null && taskApp.getActiveAlgorithm() instanceof SNIFACTPredictionAlgo) {
showRecompute = true;
}
}
String recomputeString = recomputeTitle;
if (showRecompute) {
recomputeString += scriptLabel;
}
// If the user wants to call recompute let them.
setEnabled(CogToolLID.RecomputeScript, availability, showRecompute, recomputeString);
// The export trace is only available when a script is
// computed && there are traces to export.
boolean hasComputedResult = selectionHasComputedResult(sel);
boolean showExport = anySelection && //hasComputedResult &&
selectionHasTraces(sel);
setEnabled(ProjectLID.ExportTraces, availability, showExport);
setEnabled(ProjectLID.DisplayTraces, availability, showExport);
setEnabled(ProjectLID.ExportForSanlab, availability, showExport);
// Show Visualization should only be available when a script is
// computed/valid && there are ResultSteps to visualize.
boolean showVis = anySelection && hasComputedResult && selectionHasResultSteps(sel);
setEnabled(ProjectLID.ShowModelVisualization, availability, showVis);
// The export device and script lisp files
// is only available when a script is valid
// valid IE: not null, not invalid
boolean showExportFiles = anySelection && selectionHasScripts(sel) && hasComputedResult;
setEnabled(ProjectLID.ExportActrModelFile, availability, showExportFiles);
// Default to off; fix if truly enabled
setEnabled(ProjectLID.MoveTaskEarlier, ListenerIdentifierMap.ALL, false);
setEnabled(ProjectLID.MoveTaskLater, ListenerIdentifierMap.ALL, false);
setEnabled(ProjectLID.PromoteTask, ListenerIdentifierMap.ALL, false);
setEnabled(ProjectLID.DemoteTask, ListenerIdentifierMap.ALL, false);
// Allow "vertical" movement if effectively only one task is selected
if ((tasks != null) && !hasDesign) {
if (singleTask) {
boolean spawned = tasks[0].isSpawned();
TaskGroup parent = tasks[0].getTaskGroup();
List<AUndertaking> siblings;
if (parent != null) {
setEnabled(ProjectLID.PromoteTask, ListenerIdentifierMap.ALL, !spawned);
siblings = parent.getUndertakings();
} else {
siblings = project.getUndertakings();
}
int siblingCount = siblings.size();
int atIndex = siblings.indexOf(tasks[0]);
if (siblingCount > 1) {
boolean notFirstChild = (atIndex > 0);
setEnabled(ProjectLID.DemoteTask, ListenerIdentifierMap.ALL, notFirstChild && !spawned);
setEnabled(ProjectLID.MoveTaskEarlier, ListenerIdentifierMap.ALL, notFirstChild && !spawned);
setEnabled(ProjectLID.MoveTaskLater, ListenerIdentifierMap.ALL, (atIndex < siblingCount - 1) && !spawned);
}
} else if (tasks.length > 1) {
// Too many tasks selected to check conditions;
// let the controller handle the error cases.
setEnabled(ProjectLID.PromoteTask, ListenerIdentifierMap.ALL, !isSnifActTask);
setEnabled(ProjectLID.DemoteTask, ListenerIdentifierMap.ALL, !isSnifActTask);
}
}
// Stuff that is enabled only when a script exists.
boolean canExport = false;
if (hasDesign) {
Design design = sel.getSelectedDesign();
for (AUndertaking task : tasks) {
if (taskHasScripts(task, design)) {
canExport = true;
}
}
}
setEnabled(CogToolLID.ExportScriptToCSV, availability, canExport);
// Enable "Show XXX" options if any task groups are selected
boolean enabled = false;
int numTaskGroups = 0;
TaskGroup group = null;
for (AUndertaking task : tasks) {
if (task.isTaskGroup()) {
enabled = true;
numTaskGroups++;
group = (TaskGroup) task;
}
}
setEnabled(ProjectLID.Ungroup, availability, enabled && !isSnifActGroup);
setEnabled(CogToolLID.ShowSum, availability, enabled && !isSnifActGroup);
setEnabled(CogToolLID.ShowMean, availability, enabled);
setEnabled(CogToolLID.ShowMin, availability, enabled);
setEnabled(CogToolLID.ShowMax, availability, enabled);
setSelected(CogToolLID.ShowSum, availability, false);
setSelected(CogToolLID.ShowMean, availability, false);
setSelected(CogToolLID.ShowMin, availability, false);
setSelected(CogToolLID.ShowMax, availability, false);
if (enabled) {
if (numTaskGroups == 1) {
GroupNature nature = group.getNature();
CogToolLID id = null;
if (nature == GroupNature.SUM) {
id = CogToolLID.ShowSum;
} else if (nature == GroupNature.MEAN) {
id = CogToolLID.ShowMean;
} else if (nature == GroupNature.MIN) {
id = CogToolLID.ShowMin;
} else if (nature == GroupNature.MAX) {
id = CogToolLID.ShowMax;
}
setSelected(id, availability, true);
}
}
IPredictionAlgo defaultAlgo = project.getDefaultAlgo();
// enabled state for default algorithm settings
setSelected(ProjectLID.SetProjDefaultAlgoACTR, availability, defaultAlgo == ACTR6PredictionAlgo.ONLY);
setSelected(ProjectLID.SetProjDefaultAlgoSNIFACT, availability, defaultAlgo == SNIFACTPredictionAlgo.ONLY);
setSelected(ProjectLID.SetProjExecBackground, availability, project.getDefaultRunInBackground());
setSelected(ProjectLID.SetProjExecForeground, availability, !project.getDefaultRunInBackground());
// (TODO: same level/contiguous/subtrees for Group Tasks???)
// if the user has named the task (created the group), he can export
boolean canExportHCIPA = false;
if ((tasks != null) && (tasks.length > 0)) {
// Must have selected a top-level group
for (AUndertaking task : tasks) {
if (task.isTaskGroup() && (task.getTaskGroup() == null)) {
canExportHCIPA = true;
}
}
} else if (hasDesign) {
// At least one top-level task must be a group
Iterator<AUndertaking> allTasks = project.getUndertakings().iterator();
while (allTasks.hasNext()) {
AUndertaking u = allTasks.next();
if (u.isTaskGroup()) {
canExportHCIPA = true;
}
}
}
setEnabled(ProjectLID.ExportToHCIPA, availability, canExportHCIPA);
if (hasDesign) {
ISimilarityDictionary dict = (ISimilarityDictionary) sel.getSelectedDesign().getAttribute(WidgetAttributes.DICTIONARY_ATTR);
String newLabel = NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY) ? L10N.get("WT.GenerateDictionary", "Generate Dictionary...") : L10N.get("WT.UpdateDictionary", "Update Dictionary...");
setEnabled(ProjectLID.GenerateDictionary, availability, !isSnifActTask, newLabel);
} else if (tasks.length > 0) {
List<Design> designs = project.getDesigns();
String newLabel = designs.size() > 1 ? L10N.get("WT.UpdateDictionaries", "Update Dictionaries...") : L10N.get("WT.UpdateDictionary", "Update Dictionary...");
setEnabled(ProjectLID.GenerateDictionary, availability, !isSnifActTask, newLabel);
}
}
use of edu.cmu.cs.hcii.cogtool.model.GroupNature in project cogtool by cogtool.
the class ProjectController method interactToRenameTask.
/**
* Interact with the user to solicit a new name for an
* <code>AUndertaking</code>. The new name must not be empty and must be
* unique within the <code>TaskGroup</code> that contains the given task
* or, if not a child, unique among the top-level tasks for the
* <code>Project</code>.
* <p>
* For a task that is an <code>TaskGroup</code>, the user is also
* allowed to change the group's <code>GroupNature</code>.
* <p>
* Currently unused.
*
* @param selectedDesign the design to rename
* @author mlh
*/
protected boolean interactToRenameTask(AUndertaking selectedTask, TaskSelectionState selection) {
String oldTaskName = selectedTask.getName();
ProjectInteraction.TaskRequestData requestData = new ProjectInteraction.TaskRequestData();
requestData.taskName = oldTaskName;
requestData.flags = ProjectInteraction.TaskRequestData.ASK_NOTHING;
GroupNature oldNature = GroupNature.MEAN;
// If an TaskGroup, allow the user to specify a new GroupNature.
if (selectedTask.isTaskGroup()) {
requestData.flags = ProjectInteraction.TaskRequestData.ASK_NATURE;
oldNature = ((TaskGroup) selectedTask).getNature();
}
requestData.nature = oldNature;
// cancels or specifies a non-empty name that is unique.
while (true) {
if (!interaction.requestNewTaskName(requestData)) {
// canceled!
return false;
}
if (requestData.taskName.equals("")) {
if (!interaction.protestEmptyTaskName()) {
return false;
}
} else {
TaskGroup parent = selection.getSelectedTaskParent();
if (isTaskNameUnique(requestData.taskName, oldTaskName, parent)) {
if (selectedTask.isTaskGroup() && (requestData.nature != oldNature)) {
modifyTaskGroup((TaskGroup) selectedTask, oldTaskName, requestData.taskName, oldNature, requestData.nature);
return true;
}
return renameTask(selectedTask, oldTaskName, requestData.taskName, parent);
} else {
if (!interaction.protestNotUniqueTaskName()) {
return false;
}
}
}
}
// If one ever gets here, uncomment the next line (Java!!)
// return false;
}
use of edu.cmu.cs.hcii.cogtool.model.GroupNature in project cogtool by cogtool.
the class ProjectController method createShowNatureAction.
// Action for ShowSum, ShowMean, ShowMin, and ShowMax
protected IListenerAction createShowNatureAction(final GroupNature nature, final CogToolLID lid) {
return new IListenerAction() {
public Class<?> getParameterClass() {
return TaskSelectionState.class;
}
public boolean performAction(Object prms) {
if (prms != null) {
final List<TaskGroup> groups = new ArrayList<TaskGroup>();
final List<GroupNature> oldNatures = new ArrayList<GroupNature>();
TaskSelectionState seln = (TaskSelectionState) prms;
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.FAST_SELECTION);
// Change applies only to task group instances
for (AUndertaking task : tasks) {
if (task.isTaskGroup()) {
TaskGroup group = (TaskGroup) task;
GroupNature oldNature = group.getNature();
// record old value for undo support
if (oldNature != nature) {
oldNatures.add(oldNature);
groups.add(group);
group.setNature(nature);
}
}
}
// undo/redo step and add to undo manager
if (groups.size() > 0) {
undoMgr.addEdit(new AUndoableEdit(lid) {
@Override
public String getPresentationName() {
return CHANGE_GROUP_TYPE;
}
@Override
public void redo() {
super.redo();
for (int i = 0; i < groups.size(); i++) {
TaskGroup group = groups.get(i);
group.setNature(nature);
}
}
@Override
public void undo() {
super.undo();
for (int i = 0; i < groups.size(); i++) {
TaskGroup group = groups.get(i);
GroupNature oldNat = oldNatures.get(i);
group.setNature(oldNat);
}
}
});
}
}
return true;
}
};
}
Aggregations