use of edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary in project cogtool by cogtool.
the class DictEntryGenerator method insertEntries.
public void insertEntries(final DictionaryEditorController dec, final boolean computeAll, final ITermSimilarity oldAlg, final ITermSimilarity alg, Project project, IUndoableEditSequence editSequence) {
final ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if ((newDictEntries.size() > 0) || (updatedDictEntries.size() > 0)) {
dict.insertEntries(newDictEntries, computeAll);
dict.insertEntries(updatedDictEntries, computeAll);
IUndoableEdit edit = new AUndoableEdit(ProjectLID.GenerateDictionary) {
@Override
public String getPresentationName() {
return GENERATE_DICTIONARY;
}
@Override
public void redo() {
super.redo();
dict.insertEntries(newDictEntries, computeAll);
dict.insertEntries(updatedDictEntries, computeAll);
dec.setCurrentAlgorithm(alg);
}
@Override
public void undo() {
super.undo();
dict.removeEntries(newDictEntries);
dict.insertEntries(oldDictEntries, computeAll);
dec.setCurrentAlgorithm(oldAlg);
}
};
editSequence.addEdit(edit);
UndoManager.getUndoManager(dict, project).addEdit(edit);
} else {
dec.interaction.setStatusMessage("No entries to compute.");
}
}
use of edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary in project cogtool by cogtool.
the class ProjectController method createExportDictionaryAction.
protected IListenerAction createExportDictionaryAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object actionParms) {
ProjectSelectionState seln = (ProjectSelectionState) actionParms;
Design design = seln.getSelectedDesign();
if (design == null) {
interaction.reportProblem("Export Dictionary", "No design is selected");
return false;
}
ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if (dict == null) {
interaction.reportProblem("Export Dictionary", "No dictionary exists for the selected design");
return false;
}
return DictionaryEditorCmd.exportDictionaryToCSV(dict, interaction);
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary in project cogtool by cogtool.
the class UndoManagerRecovery method recoverManagers.
/**
* Recover UndoManagers for the given design and its associated
* task applications. Also recovers for the design's frames and widgets.
*
* @param project the project containing the model objects
* @param design design whose ITaskApplications to recover managers for
* @param associatedTAs maps ITaskDesign to TaskApplication
*/
public static void recoverManagers(Project project, Design design, Map<ITaskDesign, TaskApplication> associatedTAs) {
DemoStateManager.removeStateManager(project, design);
// Recover UndoManagers for design's frames
// (used by FrameEditorControllers)
Iterator<Frame> frames = design.getFrames().iterator();
while (frames.hasNext()) {
Frame frame = frames.next();
recoverManagers(project, frame);
}
recoverScriptManagers(project, associatedTAs, false);
// Recover UndoManager for design's dictionary, if one exists
ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if (!NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY)) {
recoverManagers(project, dict);
}
// Recover UndoManager for design (used by DesignEditorController)
recoverManagers(project, design);
}
use of edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary in project cogtool by cogtool.
the class ProjectController method createGenerateDictionaryAction.
protected IListenerAction createGenerateDictionaryAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object prms) {
ProjectSelectionState seln = (ProjectSelectionState) prms;
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
Design d = seln.getSelectedDesign();
boolean hasDict = false;
ITermSimilarity defaultAlg = ISimilarityDictionary.DEFAULT_ALG;
if (d != null) {
ISimilarityDictionary dict = (ISimilarityDictionary) d.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if (!NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY)) {
hasDict = true;
defaultAlg = dict.getCurrentAlgorithm();
}
} else {
// No design selected, so just show the compute options
hasDict = true;
}
ProjectInteraction.GenerateEntriesData requestData = requestGenerateParms(generateEntriesMessage, defaultAlg, hasDict);
if (requestData == null) {
return false;
}
GenerateDictEntriesWorkThread workThread = new GenerateDictEntriesWorkThread(interaction, d, tasks, project, undoMgr, requestData);
CogTool.logger.info(String.format("Generating dictionary for design %s in project %s.", d.getName(), getProject().getName()));
ThreadManager.startNewThread(workThread);
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary in project cogtool by cogtool.
the class ProjectController method openDictionaryEditor.
protected void openDictionaryEditor(Design design) {
ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if (NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY)) {
dict = new SimilarityDictionary();
design.setAttribute(WidgetAttributes.DICTIONARY_ATTR, dict);
}
DictionaryEditorController.openController(dict, design, project);
}
Aggregations