use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class DictionaryEditorController method createAddNewEntryAction.
protected IListenerAction createAddNewEntryAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return DictionaryEditorUI.ComputeSimilarityParms.class;
}
public boolean performAction(Object actionParms) {
final DictionaryEditorUI.ComputeSimilarityParms parms = (DictionaryEditorUI.ComputeSimilarityParms) actionParms;
final ITermSimilarity oldAlg = pendingEntry.getDictEntry().algorithm;
final double oldSimilarity = pendingEntry.getSimilarity();
final double similarity;
if (checkNewEntry(parms.goalString, parms.searchString, parms.algorithm)) {
interaction.reportProblem(ERROR_TITLE, ENTRY_EXISTS);
return false;
}
if (parms.algorithm == ITermSimilarity.MANUAL) {
similarity = oldSimilarity;
} else {
similarity = computeSimilarity(parms.goalString, parms.searchString, parms.algorithm);
}
final String oldGoal = pendingEntry.getDictEntry().goalWord;
final String oldSearch = pendingEntry.getDictEntry().searchWord;
pendingEntry.clear();
final DictValue value = new DictValue(similarity);
dictionary.setSimilarity(parms.goalString, parms.searchString, parms.algorithm, value, parms.rowIndex);
undoMgr.addEdit(new AUndoableEdit(DictionaryEditorLID.CreateNewEntry) {
@Override
public String getPresentationName() {
return CREATE_ROW;
}
@Override
public void redo() {
super.redo();
pendingEntry.clear();
dictionary.setSimilarity(parms.goalString, parms.searchString, parms.algorithm, value, parms.rowIndex);
}
@Override
public void undo() {
super.undo();
dictionary.removeEntry(parms.rowIndex);
pendingEntry.setGoal(oldGoal);
pendingEntry.setSearch(oldSearch);
pendingEntry.setAlgorithm(oldAlg);
pendingEntry.setSimilarity(oldSimilarity);
}
});
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class DictionaryEditorController method createSetSimilarityAction.
protected IListenerAction createSetSimilarityAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return DictionaryEditorUI.SetSimilarityParms.class;
}
public boolean performAction(Object actionParms) {
DictionaryEditorUI.SetSimilarityParms parms = (DictionaryEditorUI.SetSimilarityParms) actionParms;
DictEntry entry = dictionary.getEntry(parms.rowIndex);
if (entry == null) {
final double oldSimil = pendingEntry.getSimilarity();
final double newSimil = parms.similarity;
if (PrecisionUtilities.withinEpsilon(oldSimil, newSimil, 0.001)) {
interaction.setStatusMessage(SIMIL_UNCHANGED);
return true;
}
final ITermSimilarity oldAlg = pendingEntry.getDictEntry().algorithm;
pendingEntry.setSimilarity(newSimil);
pendingEntry.setAlgorithm(ITermSimilarity.MANUAL);
undoMgr.addEdit(new AUndoableEdit(DictionaryEditorLID.SetSimilarity) {
@Override
public String getPresentationName() {
return SET_SIMILARITY;
}
@Override
public void redo() {
super.redo();
pendingEntry.setSimilarity(newSimil);
pendingEntry.setAlgorithm(ITermSimilarity.MANUAL);
}
@Override
public void undo() {
super.undo();
pendingEntry.setSimilarity(oldSimil);
pendingEntry.setAlgorithm(oldAlg);
}
});
return true;
}
if (PrecisionUtilities.withinEpsilon(dictionary.getValue(entry).similarity, parms.similarity, 0.001)) {
interaction.setStatusMessage(SIMIL_UNCHANGED);
return true;
}
setSimilarity(parms.rowIndex, parms.similarity, ITermSimilarity.MANUAL, undoMgr);
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class FrameEditorController method createCopyWidgetAction.
/**
* Set up the COPY widget code.
* Uses the persistence store to generate XML for the copy action.
* @return
*/
private IListenerAction createCopyWidgetAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameEditorSelectionState.class;
}
public boolean performAction(Object prms) {
FrameEditorSelectionState seln = (FrameEditorSelectionState) prms;
// If selection is non-zero, copy frame elements
int elementCount = seln.getElementSelectionCount();
if (elementCount > 0) {
copyElements(seln, DesignEditorCmd.SAVE_TO_CLIPBOARD);
if (elementCount == 1) {
interaction.setStatusMessage(WIDGET_COPIED);
} else {
interaction.setStatusMessage(WIDGETS_COPIED);
}
return true;
}
// tell user to select something.
interaction.protestNoSelection();
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class ProjectController method createSetAlgorithmAction.
protected IListenerAction createSetAlgorithmAction(final IPredictionAlgo alg, final CogToolLID lid, final String actionString) {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object actionParms) {
ProjectSelectionState selState = (ProjectSelectionState) actionParms;
Design design = selState.getSelectedDesign();
AUndertaking[] tasks = selState.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
// iterate through tasks and get set of TaskApplications
final TaskApplication[] taskApps = new TaskApplication[tasks.length];
final IPredictionAlgo[] oldAlgos = new IPredictionAlgo[tasks.length];
for (int i = 0; i < tasks.length; i++) {
// Make sure that the task application exists, and create it
// if it does not. No need to ensure a script.
TaskApplication ta = ensureTaskApplication(tasks[i], design, null, demoMgr);
taskApps[i] = ta;
oldAlgos[i] = ta.getActiveAlgorithm();
// now set the new algorithm
ta.setActiveAlgorithm(alg);
}
undoMgr.addEdit(new AUndoableEdit(lid) {
@Override
public String getPresentationName() {
return actionString;
}
@Override
public void redo() {
super.redo();
for (TaskApplication taskApp : taskApps) {
taskApp.setActiveAlgorithm(alg);
}
}
@Override
public void undo() {
super.undo();
for (int i = 0; i < taskApps.length; i++) {
taskApps[i].setActiveAlgorithm(oldAlgos[i]);
}
}
});
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class ProjectController method createScriptViewerAction.
protected IListenerAction createScriptViewerAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object prms) {
if (prms != null) {
ProjectSelectionState seln = (ProjectSelectionState) prms;
// Must have selected tasks and design
Design design = seln.getSelectedDesign();
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
if ((design == null) || (tasks == null) || (tasks.length == 0)) {
return false;
}
boolean viewSuccessful = false;
// Viewing a script only applies to task groups
for (AUndertaking task : tasks) {
if (task.isTaskGroup()) {
TaskGroup group = (TaskGroup) task;
List<AUndertaking> childTasks = group.getUndertakings();
if (childTasks.size() > 0) {
AUndertaking firstTask = childTasks.get(0);
TaskApplication ta = project.getTaskApplication(firstTask, design);
if (ta != null) {
ITaskDesign td = project.getTaskDesign(task, design);
ScriptViewerController.openController(td, project);
viewSuccessful = true;
}
}
}
}
if (!viewSuccessful) {
interaction.setStatusMessage(L10N.get("PC.NoScriptsToView", "No scripts to view."));
}
return true;
}
interaction.protestNoSelection();
return false;
}
};
}
Aggregations