@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 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(); } }
@Override public boolean cancel() { Dialogs.Answer answer = Dialogs.requestDecision(Bundle.CTL_WriteProductOperationName(), "Cancellation of writing may lead to an unreadable product.\n\n" + "Do you really want to cancel the write process?", false, null); return answer == Dialogs.Answer.YES; }
public CloseAllProductsAction() { super(Bundle.CTL_CloseAllProductsActionName()); ProductManager productManager = SnapApp.getDefault().getProductManager(); productManager.addListener(new CloseAllProductListener()); setEnabled(false); }
public CloseProductAction(Lookup actionContext) { super(Bundle.CTL_CloseProductActionName()); this.lkp = actionContext; Lookup.Result<ProductNode> productNode = lkp.lookupResult(ProductNode.class); productNode.addLookupListener(WeakListeners.create(LookupListener.class, this, productNode)); setEnableState(); setActionName(); }
static Boolean saveProduct(Product product) { Assert.notNull(product.getFileLocation()); final File file = product.getFileLocation(); if (file.isFile() && !file.canWrite()) { Dialogs.showWarning(Bundle.CTL_SaveProductActionName(), MessageFormat.format("The product\n" + "''{0}''\n" + "exists and cannot be overwritten, because it is read only.\n" + "Please choose another file or remove the write protection.", file.getPath()), null); return false; } SnapApp.getDefault().setStatusBarMessage(MessageFormat.format("Writing product ''{0}'' to {1}...", product.getDisplayName(), file)); boolean incremental = true; WriteProductOperation operation = new WriteProductOperation(product, incremental); BaseProgressUtils.runOffEventThreadWithProgressDialog(operation, Bundle.CTL_SaveProductActionName(), operation.getProgressHandle(), true, 50, 1000); SnapApp.getDefault().setStatusBarMessage(""); return operation.getStatus(); }
Dialogs.Answer answer = Dialogs.requestDecision(Bundle.CTL_OpenProductActionName(), MessageFormat.format("Product ''{0}'' has been modified.\n" + "Do you want to save it?",
public CloseOtherProductsAction(Lookup lkp) { super(Bundle.CTL_CloseAllOthersActionName()); this.lkp = lkp; Lookup.Result<ProductNode> lkpContext = lkp.lookupResult(ProductNode.class); lkpContext.addLookupListener(WeakListeners.create(LookupListener.class, this, lkpContext)); ProductManager productManager = SnapApp.getDefault().getProductManager(); productManager.addListener(new CloseOtherProductListener()); setEnableState(); }
for (File file : files) { if (openedFiles.contains(file)) { Dialogs.Answer answer = Dialogs.requestDecision(Bundle.CTL_OpenProductActionName(), MessageFormat.format("Product\n" + "{0}\n" + Dialogs.showError(Bundle.LBL_NoReaderFoundText() + String.format("%nFile '%s' can not be opened.", file)); continue; } else if (intendedPlugIns.size() == 1) {
public WriteProductOperation(Product product, File fileLocation, String formatName, Boolean incremental) { Assert.notNull(product, "product"); Assert.notNull(fileLocation, "fileLocation"); Assert.notNull(formatName, "formatName"); this.product = product; this.fileLocation = fileLocation; this.formatName = formatName; if (incremental != null) { this.incremental = incremental; } else { this.incremental = SnapApp.getDefault().getPreferences().getBoolean(PREFERENCE_KEY_SAVE_INCREMENTAL, DEFAULT_VALUE_SAVE_INCREMENTAL); } this.pm = ProgressHandleMonitor.create(Bundle.CTL_WriteProductOperationName(), this); }
if (!readerPlugIns.hasNext()) { Dialogs.showError( Bundle.LBL_NoReaderFoundText() + String.format("%nCan't find reader for the given format '%s'.", getFileFormat())); return false; }); if (filters.isEmpty()) { Dialogs.showError(Bundle.LBL_NoReaderFoundText()); return false; fc.setDialogTitle(SnapApp.getDefault().getInstanceName() + " - " + Bundle.CTL_OpenProductActionName()); fc.setAcceptAllFileFilterUsed(isUseAllFileFilter()); filters.forEach((filter) -> {