use of edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState 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.ui.DesignSelectionState 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.ui.DesignSelectionState in project cogtool by cogtool.
the class ProjectController method createCutDesignAction.
// Action for CutDesign
protected IListenerAction createCutDesignAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return DesignSelectionState.class;
}
public boolean performAction(Object prms) {
DesignSelectionState selection = (DesignSelectionState) prms;
Design selectedDesign = selection.getSelectedDesign();
// Can only cut if a design is currently selected.
if (selectedDesign != null) {
if (interaction.confirmDeleteDesign(selectedDesign)) {
try {
ObjectSaver s = CogToolClipboard.startClipboardDesignSave(project, CogToolClipboard.SAVE_TO_CLIPBOARD);
// Delete selected design, copying to the clipboard
deleteDesign(selectedDesign, s);
s.finish();
return true;
} catch (IOException e) {
throw new RcvrClipboardException(e);
} catch (OutOfMemoryError error) {
throw new RcvrOutOfMemoryException("Cutting Design", error);
}
}
} else {
interaction.protestNoSelection();
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState in project cogtool by cogtool.
the class ProjectController method createNewDesign.
protected boolean createNewDesign(Object prms, boolean newProjectMode) {
DesignSelectionState selection = (DesignSelectionState) prms;
ProjectInteraction.DesignRequestData requestData = requestNewDesignParms(newProjectMode);
if (requestData == null) {
// canceled!
return false;
}
// Create the new design and insert before the
// selected design, if any.
createNewDesign(requestData.designName, requestData.deviceTypes, selection);
return true;
}
use of edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState in project cogtool by cogtool.
the class ProjectController method createRenameDesignAction.
// createEditDesignAction
// Action for RenameDesign
protected IListenerAction createRenameDesignAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return DesignSelectionState.class;
}
public boolean performAction(Object prms) {
DesignSelectionState selection = (DesignSelectionState) prms;
Design selectedDesign = selection.getSelectedDesign();
// Can only rename a selected design.
if (selectedDesign != null) {
return interactToRenameDesign(selectedDesign);
}
interaction.protestNoSelection();
return false;
}
};
}
Aggregations