use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class ProjectController method createSetProjDefaultAlg.
protected IListenerAction createSetProjDefaultAlg(final ProjectLID lid, final String label, final IPredictionAlgo alg) {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object actionParms) {
final IPredictionAlgo oldDefaultAlg = project.getDefaultAlgo();
project.setDefaultAlgo(alg);
undoMgr.addEdit(new AUndoableEdit(lid) {
@Override
public String getPresentationName() {
return label;
}
@Override
public void redo() {
super.redo();
project.setDefaultAlgo(alg);
}
@Override
public void undo() {
super.undo();
project.setDefaultAlgo(oldDefaultAlg);
}
});
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction 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.util.IListenerAction in project cogtool by cogtool.
the class ProjectController method createCutTaskAction.
// Action for CutTask
protected IListenerAction createCutTaskAction() {
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 cut if one or more tasks are currently selected.
if ((selectedTasks != null) && (selectedTasks.length > 0)) {
try {
ObjectSaver saver = CogToolClipboard.startClipboardSave(CogToolClipboard.CopyTasks, CogToolClipboard.SAVE_TO_CLIPBOARD);
deleteTasks(selectedTasks, saver, undoMgr);
// flush!
saver.finish();
return true;
} catch (IOException e) {
throw new RcvrClipboardException("Could not execute cut", e);
} catch (OutOfMemoryError error) {
throw new RcvrOutOfMemoryException("Cutting Tasks", error);
}
} else {
interaction.protestNoSelection();
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class ProjectController method createDisplayTraces.
// Action for DisplayTraces
protected IListenerAction createDisplayTraces() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object actionParms) {
ProjectSelectionState sel = (ProjectSelectionState) actionParms;
Design design = sel.getSelectedDesign();
AUndertaking[] tasks = sel.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION);
if (design != null) {
if ((tasks != null) && (tasks.length > 0)) {
for (AUndertaking task : tasks) {
displayTraces(task, design);
}
} else {
Iterator<AUndertaking> allTasks = project.getUndertakings().iterator();
while (allTasks.hasNext()) {
displayTraces(allTasks.next(), design);
}
}
} else if ((tasks != null) && (tasks.length > 0)) {
for (AUndertaking task : tasks) {
Iterator<Design> allDesigns = project.getDesigns().iterator();
while (allDesigns.hasNext()) {
displayTraces(task, allDesigns.next());
}
}
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class SEDemoController method createSetHandLocationAction.
protected IListenerAction createSetHandLocationAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return HandLocation.class;
}
public boolean performAction(Object prms) {
HandLocation handLoc = (HandLocation) prms;
if (handLoc != null) {
setHandLocationAction(handLoc);
return true;
}
interaction.protestNoHandLocation();
return false;
}
};
}
Aggregations