@Override public void actionPerformed(ActionEvent e) { execute(); }
public boolean getUseAllFileFilter() { // by default the All file filter is used return getBooleanProperty("useAllFileFilter", true); }
public File[] getFiles() { Object value = getValue("files"); if (value instanceof File[]) { return (File[]) value; } return null; }
@Override public JMenuItem getMenuPresenter() { List<File> openedFiles = OpenProductAction.getOpenedProductFiles(); List<String> pathList = getRecentProductPaths().get(); final Preferences preference = SnapApp.getDefault().getPreferences(); int maxFileList = preference.getInt(UiBehaviorController.PREFERENCE_KEY_LIST_FILES_TO_REOPEN, DEFAULT_MAX_FILE_LIST_REOPEN); // Add "open recent product file" actions JMenu menu = new JMenu(Bundle.CTL_ReopenProductActionMenuText()); pathList.stream().limit(maxFileList).forEach(path->{ if (!openedFiles.contains(new File(path))) { JMenuItem menuItem = new JMenuItem(path); OpenProductAction openProductAction = new OpenProductAction(); openProductAction.setFile(new File(path)); menuItem.addActionListener(openProductAction); menu.add(menuItem); } }); // Add "Clear List" action if (menu.getComponentCount() > 0 || pathList.size() > 0) { menu.addSeparator(); JMenuItem menuItem = new JMenuItem(Bundle.CTL_ClearListActionMenuText()); menuItem.addActionListener(e -> getRecentProductPaths().clear()); menu.add(menuItem); } return menu; }
@Override public void drop(DropTargetDropEvent dtde) { try { final Transferable transferable = dtde.getTransferable(); if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); final List<File> fileList = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor); if (fileList.size() > 0) { final OpenProductAction open = new OpenProductAction(); open.setFiles(fileList.toArray(new File[fileList.size()])); dtde.dropComplete(Boolean.TRUE.equals(open.execute())); } } else { dtde.rejectDrop(); } } catch (UnsupportedFlavorException | IOException e) { SystemUtils.LOG.log(Level.SEVERE, "Exception during drag-and-drop operation", e); dtde.rejectDrop(); } }
/** * Executes the action command. * * @return {@code Boolean.TRUE} on success, {@code Boolean.FALSE} on failure, or {@code null} on cancellation. */ public Boolean execute() { final ProductOpener opener = new ProductOpener(); opener.setFiles(getFiles()); opener.setFileFormat(getFileFormat()); opener.setUseAllFileFilter(getUseAllFileFilter()); opener.setMultiSelectionEnabled(true); opener.setSubsetImportEnabled(false); return opener.openProduct(); }
public void setFiles(File... files) { putValue("files", files); }
@Override public void run() { try { ph.start(); ph.switchToIndeterminate(); Product product = ProductIO.readProduct(file, formatName); boolean interrupted = Thread.interrupted(); if (!interrupted) { if (product == null) { SwingUtilities.invokeLater( () -> Dialogs.showError(Bundle.LBL_NoReaderFoundText() + String.format("%nFile '%s' can not be opened.", file))); } else { OpenProductAction.getRecentProductPaths().add(file.getPath()); SwingUtilities.invokeLater(() -> SnapApp.getDefault().getProductManager().addProduct(product)); } } } catch (IOException problem) { SwingUtilities.invokeLater(() -> Dialogs.showError(Bundle.CTL_OpenProductActionName(), problem.getMessage())); } finally { ph.finish(); } }
private static Boolean openProductFilesCheckOpened(final String formatName, final File... files) { List<File> openedFiles = OpenProductAction.getOpenedProductFiles(); List<File> fileList = new ArrayList<>(Arrays.asList(files)); for (File file : files) {
OpenProductAction productAction = new OpenProductAction(); File[] files = fileList.stream().map(Path::toFile).filter(Objects::nonNull).toArray(File[]::new); productAction.setFiles(files); productAction.execute();
public void setFileFormat(String fileFormat) { putValue("fileFormat", fileFormat); }
OpenProductAction.getRecentProductPaths().add(fileLocation.getPath()); } else { if (metadataRoot != null) {
public String getFileFormat() { Object value = getValue("fileFormat"); if (value instanceof String) { return (String) value; } return null; }
public void setUseAllFileFilter(boolean useAllFileFilter) { putValue("useAllFileFilter", useAllFileFilter); }
private boolean getBooleanProperty(String propertyName, Boolean defaultValue) { final Object propValue = getValue(propertyName); if (propValue == null) { return defaultValue; } else { return Boolean.TRUE.equals(propValue); } }