/** Asks the user to choose one or more files. See description in service interface */ public FileContents[] openMultiFileDialog(final String pathHint, final String[] extentions) throws IOException { // Check permission with user first if (!_fileSaveServiceImpl.askUser()) return null; FileContents[] fcs = (FileContents[]) AccessController.doPrivileged( new PrivilegedAction() { public Object run() { JFileChooser jfc = null; FileSystemView fsv = getFileSystemView(); // use pathHint if possible if (pathHint != null) { jfc = new JFileChooser(pathHint, fsv); } else { // use lastOpenPath jfc = new JFileChooser(_fileSaveServiceImpl.getLastPath(), fsv); } jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setDialogType(JFileChooser.OPEN_DIALOG); jfc.setMultiSelectionEnabled(true); int state = jfc.showOpenDialog(null); if (state == JFileChooser.CANCEL_OPTION) { // User selected to cancle operation return null; } File[] fs = jfc.getSelectedFiles(); if (fs != null && fs.length > 0) { FileContents[] fcontents = new FileContents[fs.length]; for (int i = 0; i < fs.length; i++) { try { fcontents[i] = new FileContentsImpl( fs[i], FileSaveServiceImpl.computeMaxLength(fs[i].length())); _fileSaveServiceImpl.setLastPath(fs[i].getPath()); } catch (FileNotFoundException ie) { // Fall through } catch (IOException ioe) { } } return fcontents; } return null; } }); return fcs; }
/** Asks the user to choose a file. See description in service interface */ public FileContents openFileDialog(final String pathHint, final String[] extentions) throws IOException { // Ask user permission first if (!_fileSaveServiceImpl.askUser()) return null; FileContents fc = (FileContents) AccessController.doPrivileged( new PrivilegedAction() { public Object run() { JFileChooser jfc = null; FileSystemView fsv = getFileSystemView(); // use pathHint if possible if (pathHint != null) { jfc = new JFileChooser(pathHint, fsv); } else { // use lastOpenPath jfc = new JFileChooser(_fileSaveServiceImpl.getLastPath(), fsv); } jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setDialogType(JFileChooser.OPEN_DIALOG); jfc.setMultiSelectionEnabled(false); int state = jfc.showOpenDialog(null); if (state == JFileChooser.CANCEL_OPTION) { // User selected to cancle operation return null; } File f = jfc.getSelectedFile(); if (f != null) { try { _fileSaveServiceImpl.setLastPath(f.getPath()); return new FileContentsImpl( f, FileSaveServiceImpl.computeMaxLength(f.length())); } catch (FileNotFoundException ie) { // Fall through } catch (IOException ioe) { } } return null; } }); return fc; }