use of edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState 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;
}
};
}
use of edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState in project cogtool by cogtool.
the class ProjectController method createDemoteTaskAction.
protected IListenerAction createDemoteTaskAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return TaskSelectionState.class;
}
public boolean performAction(Object prms) {
TaskSelectionState seln = (TaskSelectionState) prms;
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION);
if ((tasks == null) || (tasks.length == 0)) {
interaction.protestNoSelection();
return false;
}
List<String> errors = new ArrayList<String>();
String editLabel = (tasks.length > 1) ? DEMOTE_TASKS : DEMOTE_TASK;
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(editLabel, ProjectLID.DemoteTask);
for (AUndertaking task : tasks) {
String demoteError = demoteTask(task, editSeq);
if (demoteError != null) {
errors.add(demoteError);
}
}
if (errors.size() > 0) {
interaction.reportProblems(editLabel, errors);
}
if (editSeq.isSignificant()) {
editSeq.end();
undoMgr.addEdit(editSeq);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState in project cogtool by cogtool.
the class ProjectController method createDeleteTaskAction.
// createDeleteDesignAction
// Action for DeleteTask
protected IListenerAction createDeleteTaskAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return TaskSelectionState.class;
}
public boolean performAction(Object prms) {
TaskSelectionState selection = (TaskSelectionState) prms;
AUndertaking[] selectedTasks = selection.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
// Can only delete if one or more tasks are currently selected.
if ((selectedTasks != null) && (selectedTasks.length > 0)) {
if (interaction.confirmDeleteTasks(selectedTasks)) {
// Delete tasks without copying to the clipboard.
deleteTasks(selectedTasks, null, undoMgr);
return true;
}
} else {
interaction.protestNoSelection();
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState in project cogtool by cogtool.
the class ProjectController method createUngroupAction.
protected IListenerAction createUngroupAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return TaskSelectionState.class;
}
public boolean performAction(Object prms) {
TaskSelectionState seln = (TaskSelectionState) prms;
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION | TaskSelectionState.TASK_GROUPS_ONLY);
if ((tasks == null) || (tasks.length == 0)) {
interaction.protestNoSelection();
return false;
}
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(L10N.get("PC.Ungroup", "Ungroup"), ProjectLID.Ungroup);
for (AUndertaking task : tasks) {
if (task.isTaskGroup()) {
TaskGroup group = (TaskGroup) task;
List<AUndertaking> childTasks = group.getUndertakings();
int numChildTasks = childTasks.size();
if (numChildTasks > 0) {
AUndertaking[] promoteTasks = new AUndertaking[numChildTasks];
childTasks.toArray(promoteTasks);
for (int j = numChildTasks - 1; j >= 0; j--) {
promoteTask(promoteTasks[j], ProjectLID.Ungroup, editSeq);
}
}
}
}
deleteTasks(tasks, null, editSeq);
if (editSeq.isSignificant()) {
editSeq.end();
undoMgr.addEdit(editSeq);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState in project cogtool by cogtool.
the class ProjectController method createDuplicateTasksAction.
protected IListenerAction createDuplicateTasksAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return TaskSelectionState.class;
}
public boolean performAction(Object prms) {
TaskSelectionState seln = (TaskSelectionState) prms;
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
// Can only duplicate if one or more tasks are selected
if ((tasks != null) && (tasks.length > 0)) {
String presentationName = (tasks.length > 1) ? DUPLICATE_TASKS : DUPLICATE_TASK;
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(presentationName, ProjectLID.DuplicateTask);
AUndertaking lastDuplicate = null;
for (AUndertaking task : tasks) {
TaskParent parent = project.getTaskParent(task);
List<AUndertaking> parentUndertakings = parent.getUndertakings();
int atIndex = parentUndertakings.indexOf(task) + 1;
lastDuplicate = duplicateTask(task, atIndex, parent, parentUndertakings, ProjectLID.DuplicateTask, presentationName, editSeq);
}
// Done with undo/redo steps; add the compound change
// to the undo manager.
editSeq.end();
undoMgr.addEdit(editSeq);
if (tasks.length == 1) {
ui.initiateTaskRename(lastDuplicate);
}
} else {
interaction.protestNoSelection();
}
return true;
}
};
}
Aggregations