use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class ProjectController method createMoveTaskAppAction.
protected IListenerAction createMoveTaskAppAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectUI.MoveCopyTaskApplicationParms.class;
}
public boolean performAction(Object p) {
if (p != null) {
ProjectUI.MoveCopyTaskApplicationParms parms = (ProjectUI.MoveCopyTaskApplicationParms) p;
// Must have selected tasks and design
if ((parms.design == null) || (parms.fromTask == null) || (parms.toTask == null)) {
interaction.protestNoSelection();
return false;
}
final AUndertaking fromTask = parms.fromTask;
final AUndertaking toTask = parms.toTask;
final TaskApplication taskApp = project.removeTaskApplication(parms.fromTask, parms.design);
if (taskApp == null) {
interaction.protestNoTaskApplication();
return false;
}
final TaskApplication oldTaskApp = project.removeTaskApplication(parms.toTask, parms.design);
taskApp.setTask(toTask);
project.setTaskApplication(taskApp);
IUndoableEdit edit = new AUndoableEdit(ProjectLID.MoveTaskApplication) {
@Override
public String getPresentationName() {
return MOVE_TASKAPP;
}
@Override
public void redo() {
super.redo();
project.removeTaskApplication(taskApp);
if (oldTaskApp != null) {
project.removeTaskApplication(oldTaskApp);
}
taskApp.setTask(toTask);
project.setTaskApplication(taskApp);
}
@Override
public void undo() {
super.undo();
project.removeTaskApplication(taskApp);
taskApp.setTask(fromTask);
if (oldTaskApp != null) {
project.setTaskApplication(oldTaskApp);
}
project.setTaskApplication(taskApp);
}
};
undoMgr.addEdit(edit);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class ProjectController method createOpenDictionaryAction.
protected IListenerAction createOpenDictionaryAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object prms) {
ProjectSelectionState seln = (ProjectSelectionState) prms;
Design design = seln.getSelectedDesign();
if (design != null) {
openDictionaryEditor(design);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class ProjectController method createDuplicateDesignAction.
protected IListenerAction createDuplicateDesignAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return DesignSelectionState.class;
}
public boolean performAction(Object prms) {
DesignSelectionState seln = (DesignSelectionState) prms;
Design design = seln.getSelectedDesign();
// Can only duplicate if a design is currently selected.
if (design == null) {
interaction.protestNoSelection();
return false;
}
// Determine new name
String copyName = NamedObjectUtil.makeNameUnique(design.getName(), project.getDesigns());
Design designCopy = design.duplicate(copyName);
ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if (!NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY)) {
designCopy.setAttribute(WidgetAttributes.DICTIONARY_ATTR, dict.duplicate());
}
ProjectCmd.addNewDesign(project, designCopy, seln.getSelectedDesign(), DUPLICATE_DESIGN, undoMgr);
Map<ITaskDesign, TaskApplication> associatedTAs = project.taskApplicationsForDesign(design);
duplicateTaskApplications(designCopy, associatedTAs);
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class ProjectController method createNewDesignForImport.
// createNewDesignAction
// Action for NewDesign2, createNewDesignForImport
protected IListenerAction createNewDesignForImport() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return DesignSelectionState.class;
// return Class.class;
}
public boolean performAction(Object prms) {
//call convert on the converter file
Class<ImportConverter> translatorClass = CogToolLID.NewDesignFromImport.getClassAttribute();
//CogToolLID.NewDesignFromImport.setClassAttribute(null);
Object converter = null;
try {
converter = translatorClass.newInstance();
} catch (InstantiationException e) {
throw new RcvrImportException("Translator class cannot be instantiated.");
} catch (IllegalAccessException e) {
throw new RcvrImportException("The translator class is not accessible.");
}
Design design = null;
Method isInputFileDirectory = null;
try {
isInputFileDirectory = translatorClass.getMethod("isInputFileDirectory", new Class[0]);
} catch (SecurityException e) {
throw new RcvrImportException("The security manager does not allow access to this method.");
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
throw new RcvrImportException("isInputFileDirectory does not exist in the converter file.");
}
boolean reqDir = false;
try {
reqDir = (Boolean) isInputFileDirectory.invoke(converter);
} catch (IllegalArgumentException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (IllegalAccessException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (InvocationTargetException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
//parameters needed to be passed to importDesign. A file and design are passed.
Class<?>[] parameters = new Class<?>[2];
parameters[0] = File.class;
parameters[1] = Design.class;
Method importDesignMethod = null;
try {
importDesignMethod = translatorClass.getMethod("importDesign", parameters);
} catch (SecurityException e) {
throw new RcvrImportException("The security manager does not allow access to this method.");
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String designName = "";
/*Instead of a inputFile, a directory was specified. Every file in the directory
needs to be parsed */
Method allowedExtsMethod = null;
try {
allowedExtsMethod = translatorClass.getMethod("allowedExtensions", new Class[0]);
} catch (SecurityException e) {
throw new RcvrImportException("The security manager does not allow access to this method.");
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] extensions = null;
try {
extensions = (String[]) allowedExtsMethod.invoke(converter);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (reqDir) {
/*TODO: Need to confirm that directory name is guaranteed to only accept a directory*/
String directoryName = interaction.askUserForDirectory("Choose a directory of files", "This directory contains the files that you wish to import.");
if (directoryName != null) {
File directory = new File(directoryName);
if (directory != null) {
//TODO: What to do about importing it twice, designName [2];
designName = directory.getName();
Set<DeviceType> deviceTypeSet = new HashSet<DeviceType>();
Method selectedDevicesMethod = null;
try {
selectedDevicesMethod = translatorClass.getMethod("selectedDevices", new Class[0]);
} catch (SecurityException e) {
throw new RcvrImportException("The security manager does not allow access to this method.");
} catch (NoSuchMethodException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
deviceTypeSet = (Set<DeviceType>) selectedDevicesMethod.invoke(converter);
} catch (IllegalArgumentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalAccessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InvocationTargetException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ProjectInteraction.DesignRequestData requestData = new ProjectInteraction.DesignRequestData();
requestData.designName = designName;
requestData.deviceTypes = deviceTypeSet;
//TODO: may need to keep checking the value that this returns
interaction.requestNewDesignName(requestData, false, project, false);
design = new Design(requestData.designName, requestData.deviceTypes);
makeDesignNameUnique(design);
// Collection<DeviceType> deviceTypes = (Collection<DeviceType>)
// designLoader.createCollection(design, Design.deviceTypesVAR, 1);
// Collection<?> frames =
//designLoader.createCollection(design, Design.framesVAR, 1);
File[] directoryContents = directory.listFiles();
for (File file : directoryContents) {
String fileName = file.getName();
//If there is no extension then null is the file extension
String fileExt = (fileName.lastIndexOf(".") == -1) ? null : fileName.substring(fileName.lastIndexOf('.'));
//Example: ".txt" will now be "txt" and . will now be ""
if (fileExt != null) {
fileExt = (fileExt.length()) > 1 ? fileExt = fileExt.substring(1) : "";
}
for (String extension : extensions) {
if (extension == null || extension.equalsIgnoreCase(fileExt)) {
try {
importDesignMethod.invoke(converter, file, design);
break;
/* Break is needed if the converter author placed the same
* extension in the array twice then this conversion will
* not occur more than once. */
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
//throw new RcvrImportXmlException("Not a valid XML file to parse.");
//ignore
System.out.println("fileName " + fileName);
break;
}
}
}
}
}
}
} else {
File importFile = interaction.selectFile(true, null, extensions);
try {
designName = importFile.getName();
//TODO: ask user for design name since it can be different from the filename
Set<DeviceType> deviceTypeSet = new HashSet<DeviceType>();
design = new Design(designName, deviceTypeSet);
makeDesignNameUnique(design);
//Collection<DeviceType> deviceTypes = (Collection<DeviceType>)
//designLoader.createCollection(design, Design.deviceTypesVAR, 1);
//Collection<?> frames =
// designLoader.createCollection(design, Design.framesVAR, 1);
System.out.println("design " + design.getName());
importDesignMethod.invoke(converter, importFile, design);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//change inputfile to the specific file
}
if (design != null) {
ProjectCmd.addNewDesign(project, design, ((DesignSelectionState) prms).getSelectedDesign(), NEW_DESIGN, undoMgr);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.
the class ProjectController method createSetAlgorithmHumanAction.
protected IListenerAction createSetAlgorithmHumanAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object actionParms) {
ProjectSelectionState parms = (ProjectSelectionState) actionParms;
final TaskApplication ta = project.getTaskApplication(parms.getSelectedTask(), parms.getSelectedDesign());
final IPredictionAlgo oldAlgo = ta.determineActiveAlgorithm(project);
ta.setActiveAlgorithm(HumanDataAlgo.ONLY);
undoMgr.addEdit(new AUndoableEdit(ProjectLID.SetAlgorithmHuman) {
@Override
public String getPresentationName() {
return L10N.get("UNDO.PM.SetHumanAlgorithm", "Set Algorithm to Human Data");
}
@Override
public void redo() {
super.redo();
ta.setActiveAlgorithm(HumanDataAlgo.ONLY);
}
@Override
public void undo() {
super.undo();
ta.setActiveAlgorithm(oldAlgo);
}
});
return true;
}
};
}
Aggregations