@Override public void actionPerformed(ActionEvent e) { execute(); }
/** * @return {@code Boolean.TRUE} on success, {@code Boolean.FALSE} on failure, or {@code null} on cancellation. */ public Boolean execute() { Product product = productRef.get(); if (product != null) { return exportProduct(product, (String) getValue(PROPERTY_FORMAT_NAME)); } else { // reference was garbage collected, that's fine, no need to save. return true; } }
public void setFormatName(String formatName) { putValue(PROPERTY_FORMAT_NAME, formatName); }
/** * Action factory method used in NetBeans {@code layer.xml} file, e.g. * <p> * <pre> * <file name="org-esa-snap-csv-dataio-ExportCSVProduct.instance"> * <attr name="instanceCreate" methodvalue="org.openide.awt.Actions.context"/> * <attr name="type" stringvalue="ProductNode"/> * <attr name="delegate" methodvalue="ExportProductAction.create"/> * <attr name="selectionType" stringvalue="EXACTLY_ONE"/> * <attr name="displayName" stringvalue="CSV Product"/> * <attr name="formatName" stringvalue="CSV"/> * <attr name="useAllFileFilter" boolvalue="true"/> * <attr name="helpId" stringvalue="exportCsvProduct"/> * <attr name="ShortDescription" stringvalue="Writes a product in CSV format."/> * </file> * </pre> * * @param configuration Configuration attributes from layer.xml. * @return The action. * @since SNAP 2 */ public static ExportProductAction create(Map<String, Object> configuration) { ExportProductAction exportProductAction = new ExportProductAction(); exportProductAction.setFormatName((String) configuration.get(PROPERTY_FORMAT_NAME)); exportProductAction.setHelpCtx((String) configuration.get("helpId")); exportProductAction.setUseAllFileFilter((Boolean) configuration.get(PROPERTY_USE_ALL_FILE_FILTER)); return exportProductAction; }
private Boolean exportProduct(Product product, String formatName) { final ProductWriter productWriter = ProductIO.getProductWriter(formatName); if (productWriter == null) { Dialogs.showError(getDisplayName(), MessageFormat.format("No writer found for format {0}.", formatName)); return null; Dialogs.showError(getDisplayName(), MessageFormat.format("Writing this product as {0} is not possible:\n" + encodeQualification.getInfoString(), formatName fc.setDialogType(JFileChooser.SAVE_DIALOG); fc.setSubsetEnabled(true); fc.addChoosableFileFilter(getFileFilter(formatName)); fc.setProductToExport(product); int returnVal = fc.showSaveDialog(SnapApp.getDefault().getMainFrame()); Dialogs.showWarning(getDisplayName(), MessageFormat.format("The product\n" + "''{0}''\n" + getDisplayName(), operation.getProgressHandle(), true,
@Override public HelpCtx getHelpCtx() { return (HelpCtx) getValue(PROPERTY_HELP_CTX); }
@Override public Action createContextAwareInstance(Lookup actionContext) { ProductNode productNode = actionContext.lookup(ProductNode.class); setProduct(productNode.getProduct()); return this; }
public String getDisplayName() { return (String) getValue("displayName"); }
public void setUseAllFileFilter(Boolean useAllFileFilter) { putValue(PROPERTY_USE_ALL_FILE_FILTER, useAllFileFilter); }
public void setHelpCtx(String helpId) { putValue(PROPERTY_HELP_CTX, helpId != null ? new HelpCtx(helpId) : null); }