* @return selected File
* @param programs
* programs that are exported
*/
private File chooseFile(Program[] programs) {
JFileChooser select = new JFileChooser();
ExtensionFileFilter vCal = new ExtensionFileFilter(mExtension,
mExtensionFilter);
select.addChoosableFileFilter(vCal);
String ext = "." + mExtension;
if (mSavePath != null) {
select.setSelectedFile(new File(mSavePath));
select.setFileFilter(vCal);
}
// check if all programs have same title. if so, use as filename
String fileName = programs[0].getTitle();
for (int i = 1; i < programs.length; i++) {
if (!programs[i].getTitle().equals(fileName)) {
fileName = "";
}
}
fileName = CalendarToolbox.cleanFilename(fileName);
if (StringUtils.isNotEmpty(fileName)) {
if (mSavePath == null) {
mSavePath = "";
}
select.setSelectedFile(new File((new File(mSavePath).getParent())
+ File.separator + fileName + ext));
}
if (select.showSaveDialog(CalendarExportPlugin.getInstance()
.getBestParentFrame()) == JFileChooser.APPROVE_OPTION) {
String filename = select.getSelectedFile().getAbsolutePath();
if (!filename.toLowerCase().endsWith(ext)) {
if (filename.endsWith(".")) {
filename = filename.substring(0, filename.length() - 1);
}