List of usage examples for javax.swing JFileChooser getAcceptAllFileFilter
@BeanProperty(bound = false)
public FileFilter getAcceptAllFileFilter()
AcceptAll
file filter. From source file:com.monead.semantic.workbench.SemanticWorkbench.java
/** * Allow the user to select a file, which is expected to be an ontology, and * then load the file.// w w w. jav a 2 s. c o m */ private void openOntologyFile() { JFileChooser fileChooser; FileFilter defaultFileFilter = null; FileFilter preferredFileFilter = null; File chosenFile; if (lastDirectoryUsed == null) { lastDirectoryUsed = new File("."); } fileChooser = new JFileChooser(lastDirectoryUsed); for (FileFilterDefinition filterDefinition : FileFilterDefinition.values()) { if (filterDefinition.name().startsWith("ONTOLOGY")) { final FileFilter fileFilter = new SuffixFileFilter(filterDefinition.description(), filterDefinition.acceptedSuffixes()); if (filterDefinition.isPreferredOption()) { preferredFileFilter = fileFilter; } fileChooser.addChoosableFileFilter(fileFilter); if (filterDefinition.description().equals(latestChosenRdfFileFilterDescription)) { defaultFileFilter = fileFilter; } } } if (defaultFileFilter != null) { fileChooser.setFileFilter(defaultFileFilter); } else if (latestChosenRdfFileFilterDescription != null && latestChosenRdfFileFilterDescription.startsWith("All")) { fileChooser.setFileFilter(fileChooser.getAcceptAllFileFilter()); } else if (preferredFileFilter != null) { fileChooser.setFileFilter(preferredFileFilter); } fileChooser.setDialogTitle("Open Assertions File"); fileChooser.showOpenDialog(this); try { latestChosenRdfFileFilterDescription = fileChooser.getFileFilter().getDescription(); } catch (Throwable throwable) { LOGGER.warn("Unable to determine which ontology file filter was chosen", throwable); } chosenFile = fileChooser.getSelectedFile(); if (chosenFile != null) { setupToLoadOntologyFile(new FileSource(chosenFile)); } }
From source file:com.monead.semantic.workbench.SemanticWorkbench.java
/** * Allow the user to select a file, which is expected to be an ontology, and * then load the file./*from w w w. ja v a 2 s. co m*/ */ private void openSparqlQueryFile() { JFileChooser fileChooser; FileFilter defaultFileFilter = null; FileFilter preferredFileFilter = null; File chosenFile; if (lastDirectoryUsed == null) { lastDirectoryUsed = new File("."); } fileChooser = new JFileChooser(lastDirectoryUsed); for (FileFilterDefinition filterDefinition : FileFilterDefinition.values()) { if (filterDefinition.name().startsWith("SPARQL")) { final FileFilter fileFilter = new SuffixFileFilter(filterDefinition.description(), filterDefinition.acceptedSuffixes()); if (filterDefinition.isPreferredOption()) { preferredFileFilter = fileFilter; } fileChooser.addChoosableFileFilter(fileFilter); if (filterDefinition.description().equals(latestChosenSparqlFileFilterDescription)) { defaultFileFilter = fileFilter; } } } if (defaultFileFilter != null) { fileChooser.setFileFilter(defaultFileFilter); } else if (latestChosenSparqlFileFilterDescription != null && latestChosenSparqlFileFilterDescription.startsWith("All")) { fileChooser.setFileFilter(fileChooser.getAcceptAllFileFilter()); } else if (preferredFileFilter != null) { fileChooser.setFileFilter(preferredFileFilter); } fileChooser.setDialogTitle("Open SPARQL Query File"); fileChooser.showOpenDialog(this); try { latestChosenSparqlFileFilterDescription = fileChooser.getFileFilter().getDescription(); } catch (Throwable throwable) { LOGGER.warn("Unable to determine which SPARQL file filter was chosen", throwable); } chosenFile = fileChooser.getSelectedFile(); if (chosenFile != null) { loadSparqlQueryFile(chosenFile); } }
From source file:com.monead.semantic.workbench.SemanticWorkbench.java
/** * Save the text from the SPARQL query text area to a file. * //from w ww. j av a 2 s .c o m */ private void saveSparqlQueryToFile() { FileWriter out; JFileChooser fileChooser; FileFilter defaultFileFilter = null; FileFilter preferredFileFilter = null; File destinationFile; int choice; out = null; if (lastDirectoryUsed == null) { lastDirectoryUsed = new File("."); } fileChooser = new JFileChooser(); for (FileFilterDefinition filterDefinition : FileFilterDefinition.values()) { if (filterDefinition.name().startsWith("SPARQL")) { final FileFilter fileFilter = new SuffixFileFilter(filterDefinition.description(), filterDefinition.acceptedSuffixes()); if (filterDefinition.isPreferredOption()) { preferredFileFilter = fileFilter; } fileChooser.addChoosableFileFilter(fileFilter); if (filterDefinition.description().equals(latestChosenSparqlFileFilterDescription)) { defaultFileFilter = fileFilter; } } } if (defaultFileFilter != null) { fileChooser.setFileFilter(defaultFileFilter); } else if (latestChosenSparqlFileFilterDescription != null && latestChosenSparqlFileFilterDescription.startsWith("All")) { fileChooser.setFileFilter(fileChooser.getAcceptAllFileFilter()); } else if (preferredFileFilter != null) { fileChooser.setFileFilter(preferredFileFilter); } if (sparqlQueryFile != null) { fileChooser.setSelectedFile(sparqlQueryFile); } else { fileChooser.setSelectedFile(lastDirectoryUsed); } fileChooser.setDialogTitle("Save SPARQL Query to File"); choice = fileChooser.showSaveDialog(this); try { latestChosenSparqlFileFilterDescription = fileChooser.getFileFilter().getDescription(); } catch (Throwable throwable) { LOGGER.warn("Unable to determine which SPARQL file filter was chosen", throwable); } destinationFile = fileChooser.getSelectedFile(); // Did not click save, did not select a file or chose a directory // So do not write anything if (choice != JFileChooser.APPROVE_OPTION || destinationFile == null || (destinationFile.exists() && !destinationFile.isFile())) { return; // EARLY EXIT! } // Adjust file suffix if necessary final FileFilter fileFilter = fileChooser.getFileFilter(); if (fileFilter != null && fileFilter instanceof SuffixFileFilter && !fileChooser.getFileFilter().accept(destinationFile)) { destinationFile = ((SuffixFileFilter) fileFilter).makeWithPrimarySuffix(destinationFile); } if (okToOverwriteFile(destinationFile)) { LOGGER.info("Write SPARQL query to file, " + destinationFile); try { out = new FileWriter(destinationFile, false); if (sparqlServiceUrl.getSelectedIndex() != 0) { out.write( "# " + SPARQL_QUERY_SAVE_SERVICE_URL_PARAM + sparqlServiceUrl.getSelectedItem() + "\n"); } else { out.write("# " + SPARQL_QUERY_SAVE_SERVICE_URL_PARAM + SPARQL_QUERY_SAVE_SERVICE_URL_VALUE_FOR_NO_SERVICE_URL + "\n"); } if (defaultGraphUri.getText().trim().length() > 0) { out.write("# " + SPARQL_QUERY_SAVE_SERVICE_DEFAULT_GRAPH_PARAM + defaultGraphUri.getText().trim() + "\n"); } out.write(sparqlInput.getText()); setSparqlQueryFile(destinationFile); } catch (IOException ioExc) { final String errorMessage = "Unable to write to file: " + destinationFile; LOGGER.error(errorMessage, ioExc); throw new RuntimeException(errorMessage, ioExc); } finally { if (out != null) { try { out.close(); } catch (Throwable throwable) { final String errorMessage = "Failed to close output file: " + destinationFile; LOGGER.error(errorMessage, throwable); throw new RuntimeException(errorMessage, throwable); } } setTitle(); } } }
From source file:us.daveread.basicquery.BasicQuery.java
/** * Open or create a SQL statement file.//from w w w . ja va2 s .co m */ private void openSQLFile() { JFileChooser fileMenu; FileFilter defaultFileFilter = null; FileFilter preferredFileFilter = null; File chosenSQLFile; int returnVal; chosenSQLFile = null; // Save current information, including SQL Statements saveConfig(); // Allow user to choose/create new file for SQL Statements fileMenu = new JFileChooser(new File(queryFilename)); for (FileFilterDefinition filterDefinition : FileFilterDefinition.values()) { if (filterDefinition.name().startsWith("QUERY")) { final FileFilter fileFilter = new SuffixFileFilter(filterDefinition.description(), filterDefinition.acceptedSuffixes()); if (filterDefinition.isPreferredOption()) { preferredFileFilter = fileFilter; } fileMenu.addChoosableFileFilter(fileFilter); if (filterDefinition.description().equals(latestChosenQueryFileFilterDescription)) { defaultFileFilter = fileFilter; } } } if (defaultFileFilter != null) { fileMenu.setFileFilter(defaultFileFilter); } else if (latestChosenQueryFileFilterDescription != null && latestChosenQueryFileFilterDescription.startsWith("All")) { fileMenu.setFileFilter(fileMenu.getAcceptAllFileFilter()); } else if (preferredFileFilter != null) { fileMenu.setFileFilter(preferredFileFilter); } fileMenu.setSelectedFile(new File(queryFilename)); fileMenu.setDialogTitle(Resources.getString("dlgSQLFileTitle")); fileMenu.setDialogType(JFileChooser.OPEN_DIALOG); fileMenu.setFileSelectionMode(JFileChooser.FILES_ONLY); fileMenu.setMultiSelectionEnabled(false); if (fileMenu.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { chosenSQLFile = fileMenu.getSelectedFile(); // Adjust file suffix if necessary final FileFilter fileFilter = fileMenu.getFileFilter(); if (fileFilter != null && fileFilter instanceof SuffixFileFilter && !fileMenu.getFileFilter().accept(chosenSQLFile)) { chosenSQLFile = ((SuffixFileFilter) fileFilter).makeWithPrimarySuffix(chosenSQLFile); } if (!chosenSQLFile.exists()) { returnVal = JOptionPane.showConfirmDialog(this, Resources.getString("dlgNewSQLFileText", chosenSQLFile.getName()), Resources.getString("dlgNewSQLFileTitle"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (returnVal == JOptionPane.NO_OPTION) { querySelection.removeAllItems(); queryText.setText(""); QueryHistory.getInstance().clearAllQueries(); // Update GUI setPrevNextIndication(); } else if (returnVal == JOptionPane.CANCEL_OPTION) { chosenSQLFile = null; } } else { setQueryFilename(chosenSQLFile.getAbsolutePath()); querySelection.removeAllItems(); queryText.setText(""); loadCombo(querySelection, queryFilename); QueryHistory.getInstance().clearAllQueries(); // Update GUI setPrevNextIndication(); } } try { latestChosenQueryFileFilterDescription = fileMenu.getFileFilter().getDescription(); } catch (Throwable throwable) { LOGGER.warn("Unable to determine which ontology file filter was chosen", throwable); } if (chosenSQLFile != null) { setQueryFilename(chosenSQLFile.getAbsolutePath()); saveConfig(); } }