use of edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary 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);
}
}
Aggregations