/** * Displays a modal dialog with the provided error message text. * * @param message The error message text to be displayed. */ public static void showError(String message) { showError(null, message); }
/** * Displays a modal dialog with the provided warning message text. * * @param message The information message text to be displayed. */ public static void showWarning(String message) { showWarning(null, message, null); }
private void requestDeleteClassifier() { String name = (String) classifierNameComboBox.getSelectedItem(); if (name != null) { Dialogs.Answer answer = Dialogs.requestDecision("Delete Classifier", "Are you sure you want to delete classifier " + name, true, null); if (answer.equals(Dialogs.Answer.YES)) { final Path classifierDir = getClassifierFolder(); final File classiferFile = classifierDir.resolve(name + BaseClassifier.CLASSIFIER_FILE_EXTENSION).toFile(); if (classiferFile.exists()) { if (deleteClassifier(classiferFile, name)) { classifierNameComboBox.removeItem(name); if (classifierNameComboBox.getItemCount() == 0) { trainBtn.setSelected(true); } } else { Dialogs.showError("Unable to delete classifier " + classiferFile); } } else { Dialogs.showError("Unable to find classifier " + classiferFile); } } } }
@Override public void run() { answer[0] = Dialogs.requestDecision(title, msg, true, null); if (answer[0] == Dialogs.Answer.YES) { newFile[0] = Dialogs.requestFileForOpen(title, false, null, null); } } });
/** * Opens question dialog asking the user whether or not to overwrite an existing file. If the given * file does not exists, the question dialog is not shown. * * @param file the file to check for existance * @return <code>True</code> if the user confirms the dialog with 'yes' or the given file does not exist.<br> * <code>False</code> if the user does not want to overwrite the existing file.<br> * <code>null</code> if the user canceled the operation.<br> */ public static Boolean requestOverwriteDecision(String title, File file) { if (!file.exists()) { return Boolean.TRUE; } Answer answer = requestDecision(getDialogTitle(title), MessageFormat.format( "The file ''{0}'' already exists.\nDo you wish to overwrite it?", file), true, null); return answer == Answer.YES ? Boolean.TRUE : answer == Answer.NO ? Boolean.FALSE : null; }
public static void openInBrowser(URI uri) { boolean desktopSupported = Desktop.isDesktopSupported(); boolean browseSupported = Desktop.getDesktop().isSupported(Desktop.Action.BROWSE); if (desktopSupported && browseSupported) { try { Desktop.getDesktop().browse(uri); } catch (Throwable t) { Dialogs.showError(String.format("Failed to open URL:\n%s:\n%s", uri, t.getMessage())); } } else { SystemUtils.copyToClipboard(uri.toString()); Dialogs.showInformation("The URL has been copied to your Clipboard\n"); } }
return; Dialogs.showError(MessageFormat.format("An unexpected exception occurred!\nMessage: {0}", e.getCause().getMessage())); e.printStackTrace(); sb.append("\n"); Dialogs.showWarning(sb.toString());
@Override protected void onOK() { ToolAdapterOperatorDescriptor[] selection = ((AdapterListModel) this.operatorsTable.getModel()).getSelectedItems(); if (selection.length > 0) { this.descriptor = this.descriptorForm.applyChanges(); final Map<OSFamily, org.esa.snap.core.gpf.descriptor.dependency.Bundle> bundles = this.bundleForm.applyChanges(); JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fileChooser.showOpenDialog(getButton(ID_OTHER)) == JFileChooser.APPROVE_OPTION) { File targetFolder = fileChooser.getSelectedFile(); final String nbmName = this.descriptor.getName() + ".nbm"; ProgressWorker worker = new ProgressWorker("Export Module Suite", "Creating NetBeans module suite " + nbmName, () -> { try { ModulePackager.packModules(this.descriptor, new File(targetFolder, nbmName), bundles, selection); Dialogs.showInformation(String.format(Bundle.MSG_Export_Complete_Text(), targetFolder.getAbsolutePath()), null); } catch (IOException e) { SystemUtils.LOG.warning(e.getMessage()); Dialogs.showError(e.getMessage()); } }); worker.executeWithBlocking(); super.onOK(); } } else { Dialogs.showWarning("Please select at least one adapter"); } }
if (Dialogs.requestDecision("Product Errors", "The follow files have errors:\n" + str.toString() + question, false, null) == Dialogs.Answer.YES) { final File file = Dialogs.requestFileForSave("Save as...", false, new SnapFileFilter("Text File", new String[]{".txt"}, "Text File"), ".txt", "ProductErrorList", null, LAST_ERROR_OUTPUT_DIR_KEY); writeErrors(errorList, file); } catch (Exception e) { Dialogs.showError("Unable to save to " + file.getAbsolutePath());
Dialogs.showWarning(product.getName() + " missing " + iBandName + " band"); return; Dialogs.showWarning(product.getName() + " missing " + qBandName + " band"); return; Dialogs.showWarning(product.getName() + " already contains a " + intensityBandName + " band"); return; if (Dialogs.requestDecision("Convert to Intensity", "Would you like to convert i and q bands " + " to Intensity in a new virtual band?", true, null) == Dialogs.Answer.YES) { convert(product, iBandName, qBandName, intensityBandName);
sessionFile = Dialogs.requestFileForSave(TITLE, false, SessionManager.getDefault().getSessionFileFilter(), SessionManager.getDefault().getSessionFileFilter().getDefaultExtension(), final Session session = createSession(sessionFile); SessionIO.getInstance().writeSession(session, sessionFile); Dialogs.showInformation(TITLE, "Session saved.", null); } catch (Exception e) { e.printStackTrace(); Dialogs.showError(TITLE, e.getMessage()); } finally {
public void actionPerformed(final ActionEvent e) { final Dialogs.Answer status = Dialogs.requestDecision("Deleting selected files", "Are you sure you want to delete these products", true, null); if (status == Dialogs.Answer.YES) performFileAction(ProductFileHandler.TYPE.DELETE); } });
private void performNewAction() { try { final File aoiFile = Dialogs.requestFileForSave("New Area of Interest", false, aoiFileFilter, AOI.EXT, aoiManager.getNewAOIFile().getAbsolutePath(), null, AOIManager.LAST_AOI_PATH); if (aoiFile != null) { final AOI aoi = aoiManager.createAOI(aoiFile); final AOIDialog dlg = new AOIDialog(SnapApp.getDefault().getMainFrame(), aoi); dlg.show(); aoiManager.addBaseDir(aoi.getFile()); UpdateUI(); } } catch (Exception e) { Dialogs.showError("Unable to create new AOI: " + e.getMessage()); } }
@Override public void actionPerformed(ActionEvent ae) { final File file = Dialogs.requestFileForOpen(Bundle.CTL_ImportSeadasTrackActionName(), false, null, "importTrack.lastDir"); if (file == null) { return; } final Product product = SnapApp.getDefault().getSelectedProduct(AUTO); FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection; try { featureCollection = readTrack(file, product.getSceneGeoCoding()); } catch (IOException e) { Dialogs.showError(Bundle.CTL_ImportSeadasTrackActionName(), "Failed to load track file:\n" + e.getMessage()); return; } if (featureCollection.isEmpty()) { Dialogs.showError(Bundle.CTL_ImportSeadasTrackActionName(), "No records found."); return; } String name = FileUtils.getFilenameWithoutExtension(file); final PlacemarkDescriptor placemarkDescriptor = PlacemarkDescriptorRegistry.getInstance().getPlacemarkDescriptor(featureCollection.getSchema()); placemarkDescriptor.setUserDataOf(featureCollection.getSchema()); VectorDataNode vectorDataNode = new VectorDataNode(name, featureCollection, placemarkDescriptor); product.getVectorDataGroup().add(vectorDataNode); final ProductSceneView view = SnapApp.getDefault().getSelectedProductSceneView(); if (view != null) { view.setLayersVisible(vectorDataNode); } }
/** * Displays a modal dialog with the provided information message text. * * @param message The message text to be displayed. */ public static void showInformation(String message) { showInformation(message, null); }
private void exportToWkt() { SimpleFeatureFigure selectedFeatureFigure = getSimpleFeatureFigure(); if (selectedFeatureFigure == null) { Dialogs.showInformation(DLG_TITLE, "Please select a geometry.", null); return; targetGeom = transformGeometry(sourceGeom, sourceCrs, targetCrs); } catch (Exception e) { Dialogs.showWarning(DLG_TITLE, "Failed to transform geometry to " + targetCrs.getName() + ".\n" + "Using " + sourceCrs.getName() + " instead.", null); targetGeom = sourceGeom;
public File saveGraph() throws GraphException { String filename = "myGraph"; if (lastLoadedGraphFile != null) filename = lastLoadedGraphFile.getAbsolutePath(); final SnapFileFilter fileFilter = new SnapFileFilter("XML", "xml", "Graph"); final File filePath = Dialogs.requestFileForSave("Save Graph", false, fileFilter, ".xml", filename, null, LAST_GRAPH_PATH); if (filePath != null) writeGraph(filePath.getAbsolutePath()); return filePath; }
public void actionPerformed(ActionEvent e) { final File file = Dialogs.requestFileForOpen("AOI Processing Graph", false, null, GraphBuilderDialog.LAST_GRAPH_PATH); if (file != null) { graphField.setText(file.getAbsolutePath()); } } });
Product firstSourceProduct = findFirstSourceProduct(productToBeClosed, stillOpenProducts); if (firstSourceProduct != null) { Dialogs.showInformation("Close Not Possible", String.format("Can't close product '%s' because it is in use%n" + "by product '%s'.%n" + Dialogs.Answer answer = Dialogs.requestDecision(Bundle.CTL_OpenProductActionName(), MessageFormat.format("Product ''{0}'' has been modified.\n" + "Do you want to save it?",
Dialogs.Answer answer = Dialogs.requestDecision("Save Product As", MessageFormat.format("In order to save the product\n" + " {0}\n" + File newFile = Dialogs.requestFileForSave("Save Product As", false, DimapProductHelpers.createDimapFileFilter(),