use of edu.cmu.cs.hcii.cogtool.model.TaskGroup in project cogtool by cogtool.
the class ProjectController method createPasteAction.
// Action for Paste
protected IListenerAction createPasteAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object prms) {
ProjectSelectionState seln = (ProjectSelectionState) prms;
try {
// Check for CogTool objects to paste
Collection<Object> objects = CogToolClipboard.fetchCogToolObjects(project);
// designs and tasks only
int numObjectsPasted = 0;
if ((objects != null) && (objects.size() > 0)) {
// Paste tasks as children of the selected TaskGroup
AUndertaking[] selectedTasks = seln.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
TaskGroup taskParent = seln.getSelectedTaskParent();
int index;
// index at which new pasted Tasks will be placed.
if (taskParent != null) {
AUndertaking last = selectedTasks[selectedTasks.length - 1];
index = taskParent.getUndertakings().indexOf(last) + 1;
} else {
index = findLastSelectedRoot(selectedTasks);
}
// Create undo support
String presentationName = PASTE;
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(presentationName, ProjectLID.Paste);
// If task applications are pasted, they will have
// null Design fields; they should "arrive" after
// the Design being pasted at the same time!
Design newDesign = null;
// Existing tasks are to be re-used if the paste
// is within the same project as the copy/cut.
Map<AUndertaking, AUndertaking> reuseTasks = null;
Iterator<Object> objIt = objects.iterator();
while (objIt.hasNext()) {
Object o = objIt.next();
// unique name and create and place the design.
if (o instanceof Design) {
newDesign = (Design) o;
makeDesignNameUnique(newDesign);
// Add an undo step after creating/placing
ProjectCmd.addNewDesign(project, newDesign, seln.getSelectedDesign(), presentationName, editSeq);
numObjectsPasted++;
} else // or to the Project. Create and place.
if (o instanceof AUndertaking) {
AUndertaking task = (AUndertaking) o;
// project or pasting copied tasks
if (reuseTasks == null) {
pasteTask(task, taskParent, index++, editSeq, presentationName);
numObjectsPasted++;
} else {
// In this case, a copied design is
// being pasted into the same project.
// Map each undertaking to the
// corresponding one in the current project
mapProjectTasks(task, project, reuseTasks, editSeq, presentationName);
}
} else // along when copying an Design.
if (o instanceof TaskApplication) {
TaskApplication taskApp = (TaskApplication) o;
if (reuseTasks != null) {
AUndertaking reuseTask = reuseTasks.get(taskApp.getTask());
if (reuseTask != null) {
taskApp.setTask(reuseTask);
}
}
// The undo edit for adding the Design will
// remove and restore the task-applications;
// simply add to the project.
project.setTaskApplication(taskApp);
} else if (o instanceof CogToolClipboard.ProjectScope) {
CogToolClipboard.ProjectScope projectScope = (CogToolClipboard.ProjectScope) o;
// a copied design into the same project
if (projectScope.getProject() != null) {
reuseTasks = new HashMap<AUndertaking, AUndertaking>();
}
}
}
// Done with undo/redo steps; add the compound change
// to the undo manager.
editSeq.end();
undoMgr.addEdit(editSeq);
interaction.setStatusMessage(numObjectsPasted + " " + pasteComplete);
} else {
interaction.setStatusMessage(nothingPasted);
}
return true;
} catch (IOException e) {
throw new RcvrClipboardException(e);
} catch (SAXException e) {
throw new RcvrClipboardException(e);
} catch (ParserConfigurationException e) {
throw new RcvrClipboardException(e);
} catch (ClipboardUtil.ClipboardException e) {
throw new RcvrClipboardException(e);
}
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.TaskGroup in project cogtool by cogtool.
the class ProjectController method renameTask.
/**
* The semantic application action to rename the given selected task from
* the "old" name to the given "new" name.
* Adds the appropriate undo/redo to the controller's undo manager.
*
* @param renamedTask the task to rename
* @param newTaskName the new task name
* @param oldTaskName the renamed task's old name
* @param parent the name scope; if <code>null</code>, the project is
* the scope.
* @author mlh
*/
protected boolean renameTask(final AUndertaking renamedTask, final String oldTaskName, final String newTaskName, TaskGroup parent) {
// Check if newTaskName is empty; retry if user desires
if (newTaskName.length() == 0) {
if (interaction.protestEmptyTaskName()) {
ui.initiateTaskRename(renamedTask);
return true;
}
return false;
}
// Check uniqueness of new name; if not, complain
if (isTaskNameUnique(newTaskName, oldTaskName, parent)) {
// If renaming a group, use modifyTaskGroup
if (renamedTask.isTaskGroup()) {
TaskGroup group = (TaskGroup) renamedTask;
// Just a rename; not changing nature
modifyTaskGroup(group, oldTaskName, newTaskName, group.getNature(), group.getNature());
} else if (!newTaskName.equals(oldTaskName)) {
// Rename only if the name has changed
renamedTask.setName(newTaskName);
// Create undo/redo step and add to undo manager
undoMgr.addEdit(new AUndoableEdit(ProjectLID.RenameTask) {
@Override
public String getPresentationName() {
return RENAME_TASK;
}
@Override
public void redo() {
super.redo();
renamedTask.setName(newTaskName);
}
@Override
public void undo() {
super.undo();
renamedTask.setName(oldTaskName);
}
});
}
return true;
}
// Not unique; complain and retry if user desires
if (interaction.protestNotUniqueTaskName()) {
ui.initiateTaskRename(renamedTask);
return true;
}
return false;
}
use of edu.cmu.cs.hcii.cogtool.model.TaskGroup 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.TaskGroup in project cogtool by cogtool.
the class ResultDisplayPolicy method getTaskRowStrings.
public static String[] getTaskRowStrings(Project project, AUndertaking undertaking, String withSecs, int[] designOrder) {
List<Design> projectDesigns = project.getDesigns();
// Add 1 since the initial column is not a design.
String[] entries = new String[projectDesigns.size() + 1];
entries[0] = SWTStringUtil.insertEllipsis(undertaking.getName(), 300, StringUtil.EQUAL, SWTStringUtil.DEFAULT_FONT);
Iterator<Design> designIter = projectDesigns.iterator();
// advance index to "First result" position
int index = 1;
if (undertaking.isTaskGroup()) {
// TODO: Store group results instead of recomputing?
TaskGroup group = (TaskGroup) undertaking;
while (designIter.hasNext()) {
Design d = designIter.next();
double result = computeGroup(project, group, d);
updateDigits();
String formattedResult = (result == TimePredictionResult.UNSET_TIME) ? "?" : (cellNumberFormat.format(result) + withSecs);
int entryIndex = (designOrder != null) ? designOrder[index++] : index++;
entries[entryIndex] = group.getNature().toString() + ": " + formattedResult;
}
} else {
while (designIter.hasNext()) {
Design d = designIter.next();
TaskApplication ta = project.getTaskApplication(undertaking, d);
int entryIndex = (designOrder != null) ? designOrder[index++] : index++;
CognitiveModelGenerator gen = null;
if (ta != null) {
gen = ta.getFirstModelGenerator();
}
entries[entryIndex] = getTaskApplicationCell(project, ta, gen, true, withSecs);
}
}
return entries;
}
use of edu.cmu.cs.hcii.cogtool.model.TaskGroup in project cogtool by cogtool.
the class ScriptViewerUIModel method dispose.
/**
* Dispose: clear the currentFrame of the window, and remove all handlers
*/
@Override
public void dispose() {
TaskGroup group = (TaskGroup) taskDesign.getTask();
Iterator<AUndertaking> tasks = group.getUndertakings().iterator();
while (tasks.hasNext()) {
AUndertaking childTask = tasks.next();
TaskApplication tApp = project.getTaskApplication(childTask, design);
if (tApp != null) {
Script script = tApp.getOnlyScript();
script.removeAllHandlers(this);
script.getDemonstration().removeAllHandlers(this);
}
}
super.dispose();
}
Aggregations