private boolean saveAs() { FileDialog saveDialog = new FileDialog(shell, SWT.SAVE); saveDialog.setFilterExtensions(new String[] {"*.adr;", "*.*"}); saveDialog.setFilterNames(new String[] {"Address Books (*.adr)", "All Files "}); saveDialog.open(); String name = saveDialog.getFileName(); if (name.equals("")) return false; if (name.indexOf(".adr") != name.length() - 4) { name += ".adr"; } File file = new File(saveDialog.getFilterPath(), name); if (file.exists()) { MessageBox box = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO); box.setText(resAddressBook.getString("Save_as_title")); box.setMessage( resAddressBook.getString("File") + file.getName() + " " + resAddressBook.getString("Query_overwrite")); if (box.open() != SWT.YES) { return false; } } this.file = file; return save(); }
void lookUpTaxonID(String taxonID) { URI url; try { // We should look up the miITIS_TSN status, but since we don't // have any options there ... url = new URI( "http://www.itis.gov/servlet/SingleRpt/SingleRpt?search_topic=TSN&search_value=" + taxonID); } catch (URISyntaxException e) { throw new RuntimeException(e); } try { Desktop desktop = Desktop.getDesktop(); desktop.browse(url); } catch (IOException e) { MessageBox.messageBox( mainFrame, "Could not open URL '" + url + "'", "The following error occurred while looking up URL '" + url + "': " + e.getMessage(), MessageBox.ERROR); } }
/** * Load a file of a particular type. It's a pretty standard helper function, which uses DarwinCSV * and setCurrentCSV(...) to make file loading happen with messaging and whatnot. We can also * reset the display: just call loadFile(null). * * @param file The file to load. * @param type The type of file (see DarwinCSV's constants). */ private void loadFile(File file, short type) { // If the file was reset, reset the display and keep going. if (file == null) { mainFrame.setTitle(basicTitle); setCurrentCSV(null); return; } // Load up a new DarwinCSV and set current CSV. try { setCurrentCSV(new DarwinCSV(file, type)); } catch (IOException ex) { MessageBox.messageBox( mainFrame, "Could not read file '" + file + "'", "Unable to read file '" + file + "': " + ex); } // Set the main frame title, based on the filename and the index. mainFrame.setTitle( basicTitle + ": " + file.getName() + " (" + String.format("%,d", currentCSV.getRowIndex().getRowCount()) + " rows)"); }
void searchName(String nameToMatch) { URI url; try { // We should look up the miITIS_TSN status, but since we don't // have any options there ... url = new URI("http", "www.google.com", "/search", "q=" + nameToMatch); // I think the URI handles the URL encoding? } catch (URISyntaxException e) { throw new RuntimeException(e); } try { Desktop desktop = Desktop.getDesktop(); desktop.browse(url); } catch (IOException e) { MessageBox.messageBox( mainFrame, "Could not open URL '" + url + "'", "The following error occurred while looking up URL '" + url + "': " + e.getMessage(), MessageBox.ERROR); } }
private boolean closeAddressBook() { if (isModified) { // ask user if they want to save current address book MessageBox box = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO | SWT.CANCEL); box.setText(shell.getText()); box.setMessage(resAddressBook.getString("Close_save")); int choice = box.open(); if (choice == SWT.CANCEL) { return false; } else if (choice == SWT.YES) { if (!save()) return false; } } TableItem[] items = table.getItems(); for (int i = 0; i < items.length; i++) { items[i].dispose(); } return true; }
@Override protected void done() { // Turn off indeterminate. progressBar.setIndeterminate(false); // Check for exceptions, and display them if necessary. try { get(); } catch (Exception e) { StringWriter stack_trace = new StringWriter(); e.printStackTrace(new PrintWriter(stack_trace)); MessageBox.messageBox( mainFrame, "Error while " + task, "The following error occurred while " + task + ": " + e.getMessage() + "\n\nStack trace: " + stack_trace, MessageBox.ERROR); } }
private void displayError(String msg) { MessageBox box = new MessageBox(shell, SWT.ICON_ERROR); box.setMessage(msg); box.open(); }
private void aboutMenuItemWidgetSelected(SelectionEvent evt) { MessageBox message = new MessageBox(getShell(), SWT.OK | SWT.ICON_INFORMATION); message.setText("About Change_This_Title"); message.setMessage("Change this about message\n\nApplicationName v1.0"); message.open(); }