public void actionPerformed(ActionEvent event) { final String expression = editExpression(validPixelExpressionField.getText()); if (expression != null) { try { binningFormModel.setProperty(BinningFormModel.PROPERTY_KEY_MASK_EXPR, expression); } catch (ValidationException e) { appContext.handleError("Invalid expression", e); } } } });
protected void handleProcessingError(Throwable t) { String msg; if (t instanceof OperatorCancelException) { return; } if (isInternalException(t)) { msg = MessageFormat.format("An internal error occurred during the target product processing.\n{0}", formatThrowable(t)); } else { msg = MessageFormat.format("A problem occurred during the target product processing.\n{0}", formatThrowable(t)); } appContext.handleError(msg, t); }
@Override protected void done() { try { Product firstProduct = get(); if (firstProduct != null) { binningFormModel.useAsContextProduct(firstProduct); firstProduct.dispose(); } } catch (Exception ex) { String msg = String.format("Cannot open source products.\n%s", ex.getMessage()); appContext.handleError(msg, ex); } } };
@Override public void selectionChanged(SelectionChangeEvent event) { final Product product = (Product) event.getSelection().getSelectedValue(); try { if (product != null) { final Map<String, Object> map = MosaicOp.getOperatorParameters(product); final Stream<Map.Entry<String, Object>> entrySetStream = map.entrySet().stream(); final Stream<Map.Entry<String, Object>> filteredStream = entrySetStream.filter(entry -> propertySet.getProperty(entry.getKey()) != null); filteredStream.forEach(entry -> propertySet.setValue(entry.getKey(), entry.getValue())); } propertySet.setValue(MosaicFormModel.PROPERTY_UPDATE_PRODUCT, product); } catch (OperatorException e) { appContext.handleError("Selected product cannot be used for update mode.", e); } } });
@Override public void selectionChanged(SelectionChangeEvent event) { final Product product = (Product) event.getSelection().getSelectedValue(); try { if (product != null) { final Map<String, Object> map = S2tbxMosaicOp.getOperatorParameters(product); final Stream<Map.Entry<String, Object>> entrySetStream = map.entrySet().stream(); final Stream<Map.Entry<String, Object>> filteredStream = entrySetStream.filter(entry -> propertySet.getProperty(entry.getKey()) != null); filteredStream.forEach(entry -> propertySet.setValue(entry.getKey(), entry.getValue())); } propertySet.setValue(S2tbxMosaicFormModel.PROPERTY_UPDATE_PRODUCT, product); } catch (OperatorException e) { appContext.handleError("Selected product cannot be used for update mode.", e); } } });
@Override protected void done() { try { get(); Object outputDir = parameterMap.get("outputDir"); String message; if (outputDir != null) { message = String.format( "The pixel extraction tool has run successfully and written the result file(s) to %s.", outputDir.toString()); } else { message = "The pixel extraction tool has run successfully and written the result file to to std.out."; } showInformationDialog(message); } catch (InterruptedException ignore) { } catch (ExecutionException e) { appContext.handleError(e.getMessage(), e); } finally { AbstractButton runButton = getButton(ID_OK); runButton.setEnabled(true); } } }
protected void handleInitialisationError(Throwable t) { String msg; if (t instanceof OperatorCancelException) { msg = MessageFormat.format("An internal error occurred during the target product initialisation.\n{0}", formatThrowable(t)); showErrorDialog(msg); return; } if (isInternalException(t)) { msg = MessageFormat.format("An internal error occurred during the target product initialisation.\n{0}", formatThrowable(t)); } else { msg = MessageFormat.format("A problem occurred during the target product initialisation.\n{0}", formatThrowable(t)); } appContext.handleError(msg, t); }
appContext.handleError(String.format("Error occurred while reading file: %s", selectedFile), ioe); } finally { if (reader != null) {
public void actionPerformed(final ActionEvent e) { try { final File mstFile = tableModel.getFileAt(0); if (mstFile.exists()) { final ProductEntry[] entryList = DBSearch.search(mstFile); for (ProductEntry entry : entryList) { if (tableModel.getIndexOf(entry.getFile()) < 0) tableModel.addFile(entry); } } } catch (Exception ex) { appContext.handleError("Unable to query DB", ex); } } });
private int editExpression(String[] value, final boolean booleanExpected) { Product product; try { product = mosaicModel.getReferenceProduct(); } catch (IOException ioe) { appContext.handleError(ioe.getMessage(), ioe); return 0; } if (product == null) { final String msg = "No source product specified."; appContext.handleError(msg, new IllegalStateException(msg)); return 0; } final ProductExpressionPane pep; if (booleanExpected) { pep = ProductExpressionPane.createBooleanExpressionPane(new Product[]{product}, product, appContext.getPreferences()); } else { pep = ProductExpressionPane.createGeneralExpressionPane(new Product[]{product}, product, appContext.getPreferences()); } pep.setCode(value[0]); final int i = pep.showModalDialog(appContext.getApplicationWindow(), value[0]); if (i == ModalDialog.ID_OK) { value[0] = pep.getCode(); } return i; }
private int editExpression(String[] value, final boolean booleanExpected) { Product product; try { product = mosaicModel.getReferenceProduct(); } catch (IOException ioe) { appContext.handleError(ioe.getMessage(), ioe); return 0; } if (product == null) { final String msg = "No source product specified."; appContext.handleError(msg, new IllegalStateException(msg)); return 0; } final ProductExpressionPane pep; if (booleanExpected) { pep = ProductExpressionPane.createBooleanExpressionPane(new Product[]{product}, product, appContext.getPreferences()); } else { pep = ProductExpressionPane.createGeneralExpressionPane(new Product[]{product}, product, appContext.getPreferences()); } pep.setCode(value[0]); final int i = pep.showModalDialog(appContext.getApplicationWindow(), value[0]); if (i == ModalDialog.ID_OK) { value[0] = pep.getCode(); } return i; }
@Override public void contentsChanged(ListDataEvent event) { final Product[] sourceProducts = sourceProductList.getSourceProducts(); try { binningFormModel.setProperty(BinningFormModel.PROPERTY_KEY_SOURCE_PRODUCTS, sourceProducts); } catch (ValidationException e) { appContext.handleError("Unable to set source products.", e); } if (sourceProducts.length > 0) { binningFormModel.useAsContextProduct(sourceProducts[0]); return; } String[] sourceProductPaths = binningFormModel.getSourceProductPaths(); if (sourceProductPaths != null && sourceProductPaths.length > 0) { openFirstProduct(sourceProductPaths); return; } binningFormModel.useAsContextProduct(null); }
} catch (ValidationException ve) { appContext.handleError("Invalid input path", ve);
@Override public void propertyChange(PropertyChangeEvent evt) { final Product product = (Product) evt.getNewValue(); final TargetProductSelectorModel selectorModel = targetProductSelector.getModel(); if (product != null) { final String formatName = product.getProductReader().getReaderPlugIn().getFormatNames()[0]; final ProductIOPlugInManager ioPlugInManager = ProductIOPlugInManager.getInstance(); final Iterator<ProductWriterPlugIn> writerIterator = ioPlugInManager.getWriterPlugIns(formatName); if (writerIterator.hasNext()) { selectorModel.setFormatName(formatName); } else { final String errMsg = "Cannot write to update product."; final String iseMsg = String.format("No product writer found for format '%s'", formatName); appContext.handleError(errMsg, new IllegalStateException(iseMsg)); } final File fileLocation = product.getFileLocation(); final String fileName = FileUtils.getFilenameWithoutExtension(fileLocation); final File fileDir = fileLocation.getParentFile(); selectorModel.setProductName(fileName); selectorModel.setProductDir(fileDir); } else { selectorModel.setFormatName(ProductIO.DEFAULT_FORMAT_NAME); selectorModel.setProductName("Multi-size Mosaic"); String homeDirPath = SystemUtils.getUserHomeDir().getPath(); final PropertyMap prefs = appContext.getPreferences(); String saveDir = prefs.getPropertyString(SaveProductAsAction.PREFERENCES_KEY_LAST_PRODUCT_DIR, homeDirPath); selectorModel.setProductDir(new File(saveDir)); } } }
private AbstractButton createOutputDirChooserButton(final Property outputFileProperty) { AbstractButton button = new JButton("..."); button.addActionListener(e -> { FolderChooser folderChooser = new FolderChooser(); folderChooser.setCurrentDirectory(new File(getDefaultOutputPath(appContext))); folderChooser.setDialogTitle("Select output directory"); folderChooser.setMultiSelectionEnabled(false); int result = folderChooser.showDialog(appContext.getApplicationWindow(), "Select"); /*I18N*/ if (result != JFileChooser.APPROVE_OPTION) { return; } File selectedFile = folderChooser.getSelectedFile(); setOutputDirPath(selectedFile.getAbsolutePath()); try { outputFileProperty.setValue(selectedFile); appContext.getPreferences().setPropertyString(PROPERTY_NAME_LAST_OPEN_OUTPUT_DIR, selectedFile.getAbsolutePath()); } catch (ValidationException ve) { // not expected to ever come here appContext.handleError("Invalid input path", ve); } }); return button; }
@Override public void propertyChange(PropertyChangeEvent evt) { final Product product = (Product) evt.getNewValue(); final TargetProductSelectorModel selectorModel = targetProductSelector.getModel(); if (product != null) { final String formatName = product.getProductReader().getReaderPlugIn().getFormatNames()[0]; final ProductIOPlugInManager ioPlugInManager = ProductIOPlugInManager.getInstance(); final Iterator<ProductWriterPlugIn> writerIterator = ioPlugInManager.getWriterPlugIns(formatName); if (writerIterator.hasNext()) { selectorModel.setFormatName(formatName); } else { final String errMsg = "Cannot write to update product."; final String iseMsg = String.format("No product writer found for format '%s'", formatName); appContext.handleError(errMsg, new IllegalStateException(iseMsg)); } final File fileLocation = product.getFileLocation(); final String fileName = FileUtils.getFilenameWithoutExtension(fileLocation); final File fileDir = fileLocation.getParentFile(); selectorModel.setProductName(fileName); selectorModel.setProductDir(fileDir); } else { selectorModel.setFormatName(ProductIO.DEFAULT_FORMAT_NAME); selectorModel.setProductName("mosaic"); String homeDirPath = SystemUtils.getUserHomeDir().getPath(); final PropertyMap prefs = appContext.getPreferences(); String saveDir = prefs.getPropertyString(SaveProductAsAction.PREFERENCES_KEY_LAST_PRODUCT_DIR, homeDirPath); selectorModel.setProductDir(new File(saveDir)); } } }
} catch (ValidationException ve) { appContext.handleError("Invalid input path", ve);
@Override public void actionPerformed(ActionEvent e) { PropertyMap preferences = appContext.getPreferences(); final SnapFileChooser fileChooser = getFileChooser( preferences.getPropertyString(LAST_OPEN_CSV_DIR, SystemUtils.getUserHomeDir().getPath())); int answer = fileChooser.showDialog(parent, "Select"); if (answer == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); preferences.setPropertyString(LAST_OPEN_CSV_DIR, selectedFile.getParent()); try { final List<SimpleFeature> extendedFeatures = PixExOpUtils.extractFeatures(selectedFile); for (SimpleFeature extendedFeature : extendedFeatures) { final GenericPlacemarkDescriptor placemarkDescriptor = new GenericPlacemarkDescriptor( extendedFeature.getFeatureType()); final Placemark placemark = placemarkDescriptor.createPlacemark(extendedFeature); setName(extendedFeature, placemark); setDateTime(extendedFeature, placemark); setPlacemarkGeoPos(extendedFeature, placemark); tableModel.addPlacemark(placemark); } } catch (IOException exception) { appContext.handleError(String.format("Error occurred while reading file: %s \n" + exception.getLocalizedMessage() + "\nPossible reason: Other char separator than tabulator used", selectedFile), exception); } } }
appContext.handleError("Could not create a 'Coordinate Reference System'.\n" + e.getMessage(), e);
appContext.handleError("Could not create a 'Coordinate Reference System'.\n" + e.getMessage(), e);