List of usage examples for javax.swing JFileChooser addChoosableFileFilter
@BeanProperty(preferred = true, description = "Adds a filter to the list of user choosable file filters.") public void addChoosableFileFilter(FileFilter filter)
From source file:org.nuclos.client.customcomp.resplan.AbstractResPlanExportDialog.java
@PostConstruct private void init() { double border = 10; double inset = 5; double size[][] = { { border, 100, inset, 200, inset, 30, inset, 65, border }, // Columns { border, 20, inset, 20, inset, 30, border } }; // Rows final TableLayout tl = new TableLayout(size); setLayout(tl);/* w ww. j a va 2 s.c om*/ final SpringLocaleDelegate sld = getSpringLocaleDelegate(); final JLabel fileLabel = new JLabel(sld.getText("nuclos.resplan.dialog.file"), SwingConstants.RIGHT); add(fileLabel, "1, 1"); file = new JTextField(); file.setText(save.getPath()); add(file, "3, 1"); final JButton browse = new JButton("..."); add(browse, "5, 1"); final JLabel typeLabel = new JLabel(sld.getText("nuclos.resplan.dialog.type"), SwingConstants.RIGHT); add(typeLabel, "1, 3"); fileTypes = new JComboBox(new String[] { ImageType.SVG.getFileExtension(), ImageType.EMF.getFileExtension(), ImageType.PNG.getFileExtension() }); fileTypes.setSelectedItem(defaultFileType); fileTypes.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { checkFile(); } }); add(fileTypes, "3, 3"); browse.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final JFileChooser chooser = new JFileChooser(save.getParent()); chooser.setAcceptAllFileFilterUsed(false); chooser.addChoosableFileFilter(new MyFileFilter((String) fileTypes.getSelectedItem())); // chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); final int returnVal = chooser.showSaveDialog(parent); if (returnVal == JFileChooser.APPROVE_OPTION) { save = chooser.getSelectedFile(); checkFile(); } } }); final JPanel buttons = new JPanel(new FlowLayout()); add(buttons, "1, 5, 7, 5"); final JButton export = new JButton(sld.getText("nuclos.resplan.dialog.export")); buttons.add(export); export.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final String filePath = file.getText(); if (!filePath.equals(save.getPath())) { save = new File(filePath); } checkFile(); if (save.exists()) { String file = save.getAbsolutePath(); if (save.canWrite()) { int ans = JOptionPane.showConfirmDialog(AbstractResPlanExportDialog.this, sld.getMessage("general.overwrite.file", "general.overwrite.file", file), sld.getMessage("general.overwrite.file.title", "general.overwrite.file.title"), JOptionPane.OK_CANCEL_OPTION); if (ans != JOptionPane.YES_OPTION) { return; } } else { JOptionPane.showMessageDialog(AbstractResPlanExportDialog.this, sld.getMessage("general.notwritable.file", "general.notwritable.file", file), sld.getMessage("general.notwritable.file.title", "general.notwritable.file.title"), JOptionPane.ERROR_MESSAGE); return; } } export(); storePreferences(); dispose(); } }); final JButton cancel = new JButton(sld.getText("general.cancel")); buttons.add(cancel); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }); pack(); setLocationRelativeTo(parent); setVisible(true); }
From source file:org.photovault.swingui.BrowserWindow.java
/** Shows an file selection dialog that allows user to select a file to import. After that shows the PhotoInfo dialog to allow the user to edit the eriginal information about the file. *//* w w w . j a v a 2 s. c o m*/ protected void importFile() { // Show the file chooser dialog JFileChooser fc = new JFileChooser(); fc.addChoosableFileFilter(new ImageFilter()); fc.setAccessory(new ImagePreview(fc)); fc.setMultiSelectionEnabled(true); int retval = fc.showDialog(window, "Import"); if (retval == JFileChooser.APPROVE_OPTION) { // Add the selected file to the database and allow user to edit its attributes final File[] files = fc.getSelectedFiles(); final ProgressDlg pdlg = new ProgressDlg(window, true); // Add all the selected files to DB final PhotoInfo[] photos = new PhotoInfo[files.length]; Thread importThread = new Thread() { @Override public void run() { for (int n = 0; n < files.length; n++) { try { photos[n] = PhotoInfo.addToDB(files[n]); pdlg.setProgressPercent((n * 100) / files.length); pdlg.setStatus("" + (n + 1) + " of " + files.length + " files imported."); } catch (Exception e) { log.error("Unexpected exception: " + e.getMessage()); } } pdlg.completed(); } }; importThread.start(); pdlg.setVisible(true); // Show editor dialog for the added photos // PhotoInfoDlg dlg = new PhotoInfoDlg( window, false, photos ); PhotoInfoDlg dlg = null; dlg.showDialog(); } }
From source file:org.processmining.analysis.performance.PerformanceAnalysisGUI.java
/** * Creates a filechooser where the user can select the (comma-seperated) * file that he wants to export to. If this file already exists, permission * to overwrite is requested, else a new file is created to which the * time-metrics of the selected place/transitions are exported. * /*from w ww . j av a2s . c om*/ */ private void exportObjectMetrics() { // create and initialize the file chooser final JFileChooser fc = new JFileChooser(); NameFilter filt1 = new NameFilter(".csv"); NameFilter filt2 = new NameFilter(".txt"); fc.addChoosableFileFilter(filt1); fc.addChoosableFileFilter(filt2); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(filt1); // check whether a place is selected int result = fc.showDialog(this, "Export"); if (result == 0) { // Export-button was pushed File selectedFile = fc.getSelectedFile(); if (!(selectedFile.getName().endsWith(fc.getFileFilter().getDescription().substring(1)))) { // create new file, with filetype added to it selectedFile = new File( selectedFile.getAbsolutePath() + fc.getFileFilter().getDescription().substring(1)); } if (!selectedFile.exists()) { if (boxMap.get(sb1.getSelectedItem()) instanceof ExtendedPlace) { // actually perform export of place time-metrics exportPlaceMetrics(selectedFile); } else { if (boxMap.get(sb2.getSelectedItem()) instanceof ExtendedTransition) { // actually perform export of transition time-metrics exportTransitionMetrics(selectedFile); } else { // actually perform export of activity time-metrics exportActivityMetrics(selectedFile); } } } else { // file already exist, open a confirm dialog containing a // 'Yes' Button as well as a 'No' button int overwrite = JOptionPane.showConfirmDialog(this, "File already exists! Overwrite?", "Confirm Dialog", 0); if (overwrite == 0) { // user has selected Yes if (boxMap.get(sb1.getSelectedItem()) instanceof ExtendedPlace) { // actually perform export of place time-metrics exportPlaceMetrics(selectedFile); } else { if (boxMap.get(sb2.getSelectedItem()) instanceof ExtendedTransition) { // actually perform export of transition // time-metrics exportTransitionMetrics(selectedFile); } else { // actually perform export of activity time-metrics exportActivityMetrics(selectedFile); } } } } } }
From source file:org.processmining.analysis.performance.PerformanceAnalysisGUI.java
/** * Creates a filechooser where the user can select the (comma-seperated) * file that he wants to export to. If this file already exists, permission * to overwrite is requested, else a new file is created to which the * throughput times of the selected process instances are exported. * // w w w.ja v a 2s .c o m */ private void exportProcessMetrics() { // create and initialize the file chooser final JFileChooser fc = new JFileChooser(); NameFilter filt1 = new NameFilter(".csv"); NameFilter filt2 = new NameFilter(".txt"); fc.addChoosableFileFilter(filt1); fc.addChoosableFileFilter(filt2); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(filt1); // check whether a place is selected int result = fc.showDialog(this, "Export"); if (result == 0) { // Export-button was pushed File selectedFile = fc.getSelectedFile(); if (!(selectedFile.getName().endsWith(fc.getFileFilter().getDescription().substring(1)))) { // create new file, with filetype added to it selectedFile = new File( selectedFile.getAbsolutePath() + fc.getFileFilter().getDescription().substring(1)); } if (!selectedFile.exists()) { try { // actually export the throughput times to the file replayResult.exportToFile(getSelectedInstances(), selectedFile, timeDivider, timeSort, advancedSettings[0]); } catch (IOException ex) { Message.add("IO exception: " + ex.toString(), 2); } } else { // file already exist, open a confirm dialog containing a // 'Yes' Button as well as a 'No' button int overwrite = JOptionPane.showConfirmDialog(this, "File already exists! Overwrite?", "Confirm Dialog", 0); if (overwrite == 0) { // user has selected Yes try { // actually export the throughput times to the file replayResult.exportToFile(getSelectedInstances(), selectedFile, timeDivider, timeSort, advancedSettings[0]); } catch (IOException ex) { Message.add("IO exception: " + ex.toString(), 2); } } } } }
From source file:org.prom5.analysis.performance.PerformanceAnalysisGUI.java
/** * Creates a filechooser where the user can select the (comma-seperated) * file that he wants to export to. If this file already exists, permission * to overwrite is requested, else a new file is created to which the * time-metrics of the selected place/transitions are exported. * *///from w w w .j a v a 2 s .co m private void exportObjectMetrics() { //create and initialize the file chooser final JFileChooser fc = new JFileChooser(); NameFilter filt1 = new NameFilter(".csv"); NameFilter filt2 = new NameFilter(".txt"); fc.addChoosableFileFilter(filt1); fc.addChoosableFileFilter(filt2); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(filt1); //check whether a place is selected int result = fc.showDialog(this, "Export"); if (result == 0) { //Export-button was pushed File selectedFile = fc.getSelectedFile(); if (!(selectedFile.getName().endsWith(fc.getFileFilter().getDescription().substring(1)))) { //create new file, with filetype added to it selectedFile = new File( selectedFile.getAbsolutePath() + fc.getFileFilter().getDescription().substring(1)); } if (!selectedFile.exists()) { if (boxMap.get(sb1.getSelectedItem()) instanceof ExtendedPlace) { //actually perform export of place time-metrics exportPlaceMetrics(selectedFile); } else { if (boxMap.get(sb2.getSelectedItem()) instanceof ExtendedTransition) { //actually perform export of transition time-metrics exportTransitionMetrics(selectedFile); } else { //actually perform export of activity time-metrics exportActivityMetrics(selectedFile); } } } else { //file already exist, open a confirm dialog containing a //'Yes' Button as well as a 'No' button int overwrite = JOptionPane.showConfirmDialog(this, "File already exists! Overwrite?", "Confirm Dialog", 0); if (overwrite == 0) { //user has selected Yes if (boxMap.get(sb1.getSelectedItem()) instanceof ExtendedPlace) { //actually perform export of place time-metrics exportPlaceMetrics(selectedFile); } else { if (boxMap.get(sb2.getSelectedItem()) instanceof ExtendedTransition) { //actually perform export of transition time-metrics exportTransitionMetrics(selectedFile); } else { //actually perform export of activity time-metrics exportActivityMetrics(selectedFile); } } } } } }
From source file:org.prom5.analysis.performance.PerformanceAnalysisGUI.java
/** * Creates a filechooser where the user can select the (comma-seperated) * file that he wants to export to. If this file already exists, permission * to overwrite is requested, else a new file is created to which the * throughput times of the selected process instances are exported. * */// w w w . j av a 2 s . c o m private void exportProcessMetrics() { //create and initialize the file chooser final JFileChooser fc = new JFileChooser(); NameFilter filt1 = new NameFilter(".csv"); NameFilter filt2 = new NameFilter(".txt"); fc.addChoosableFileFilter(filt1); fc.addChoosableFileFilter(filt2); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(filt1); //check whether a place is selected int result = fc.showDialog(this, "Export"); if (result == 0) { //Export-button was pushed File selectedFile = fc.getSelectedFile(); if (!(selectedFile.getName().endsWith(fc.getFileFilter().getDescription().substring(1)))) { //create new file, with filetype added to it selectedFile = new File( selectedFile.getAbsolutePath() + fc.getFileFilter().getDescription().substring(1)); } if (!selectedFile.exists()) { try { //actually export the throughput times to the file replayResult.exportToFile(getSelectedInstances(), selectedFile, timeDivider, timeSort, advancedSettings[0]); } catch (IOException ex) { Message.add("IO exception: " + ex.toString(), 2); } } else { //file already exist, open a confirm dialog containing a //'Yes' Button as well as a 'No' button int overwrite = JOptionPane.showConfirmDialog(this, "File already exists! Overwrite?", "Confirm Dialog", 0); if (overwrite == 0) { //user has selected Yes try { //actually export the throughput times to the file replayResult.exportToFile(getSelectedInstances(), selectedFile, timeDivider, timeSort, advancedSettings[0]); } catch (IOException ex) { Message.add("IO exception: " + ex.toString(), 2); } } } } }
From source file:org.signserver.admin.gui.ViewCertificateFrame.java
private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed if (certificate != null) { final JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setAcceptAllFileFilterUsed(false); final FileFilter pemFilter = new FileNameExtensionFilter("X.509 Certificate (PEM)", "pem"); final FileFilter pemChainFilter = new FileNameExtensionFilter("X.509 Certificate with chain (PEM)", "pem"); final FileFilter derFilter = new FileNameExtensionFilter("X.509 Certificate (DER)", "cer", "crt", "der"); chooser.addChoosableFileFilter(pemFilter); chooser.addChoosableFileFilter(derFilter); chooser.addChoosableFileFilter(pemChainFilter); chooser.setDialogTitle("Save certificate as file"); if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { if (chooser.getFileFilter() == derFilter) { // DER file FileUtils.writeByteArrayToFile(file, certificate.getEncoded()); } else { // PEM file BufferedOutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(file)); PEMWriter pemWriter = new PEMWriter(new OutputStreamWriter(out)); if (chooser.getFileFilter() == pemFilter) { pemWriter.writeObject(certificate); } else { for (X509Certificate cert : certificates) { pemWriter.writeObject(cert); }/*from ww w . j av a 2s . c o m*/ } pemWriter.close(); } finally { IOUtils.closeQuietly(out); } } } catch (IOException ex) { JOptionPane.showMessageDialog(this, "Exporting certificate failed:\n" + ex.getLocalizedMessage(), "Export", JOptionPane.ERROR_MESSAGE); } catch (CertificateEncodingException ex) { JOptionPane.showMessageDialog(this, "Unable to encode certificate:\n" + ex.getLocalizedMessage(), "Export", JOptionPane.ERROR_MESSAGE); } } } }
From source file:org.surmon.pattern.importer.ImportAction.java
/** * Creates and shows import dialog. Also handles user interaction with the * dialog.//from ww w . j a va 2 s . c o m */ public static void createAndShowDialog() { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Import data"); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setAcceptAllFileFilterUsed(true); Collection<? extends PDataImporter> importers = Lookup.getDefault().lookupAll(PDataImporter.class); // find all importers and set the filters for open dialog for (PDataImporter importer : importers) { chooser.addChoosableFileFilter(importer.getExtensionFilter()); } // open and wait for result int returnVal = chooser.showOpenDialog(null); // process the result from open dialog if (returnVal == JFileChooser.APPROVE_OPTION) { final File file = chooser.getSelectedFile(); if (file.exists()) { final String extension = FilenameUtils.getExtension(file.getName()); final PDataImporter importer = selectImporter(importers, extension); if (importer != null) { executeImport(importer, file); } else { NotifyDescriptor nd = new NotifyDescriptor.Message( "File " + extension + " doesn't contain image data or is not supported."); DialogDisplayer.getDefault().notify(nd); } } } }
From source file:org.thelq.stackexchange.dbimport.gui.GUI.java
public GUI(Controller passedController) { //Initialize logger logAppender = new GUILogAppender(this); //Set our Look&Feel try {// w w w . j a v a2s.c o m if (SystemUtils.IS_OS_WINDOWS) UIManager.setLookAndFeel(new WindowsLookAndFeel()); else UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { log.warn("Defaulting to Swing L&F due to exception", e); } this.controller = passedController; frame = new JFrame(); frame.setTitle("Unified StackExchange Data Dump Importer v" + Controller.VERSION); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); //Setup menu JMenuBar menuBar = new JMenuBar(); menuAdd = new JMenuItem("Add Folders/Archives"); menuAdd.setMnemonic(KeyEvent.VK_F); menuBar.add(menuAdd); frame.setJMenuBar(menuBar); //Primary panel FormLayout primaryLayout = new FormLayout("5dlu, pref:grow, 5dlu, 5dlu, pref", "pref, top:pref, pref, fill:140dlu:grow, pref, fill:80dlu"); PanelBuilder primaryBuilder = new PanelBuilder(primaryLayout) .border(BorderFactory.createEmptyBorder(5, 5, 5, 5)); //DB Config panel primaryBuilder.addSeparator("Database Configuration", CC.xyw(1, 1, 2)); FormLayout configLayout = new FormLayout("pref, 3dlu, pref:grow, 6dlu, pref", "pref, pref:grow, 3dlu, pref:grow, 3dlu, pref:grow, 3dlu, pref:grow, 3dlu, pref:grow, 3dlu, pref:grow"); configLayout.setHonorsVisibility(true); final PanelBuilder configBuilder = new PanelBuilder(configLayout); configBuilder.addLabel("Server", CC.xy(1, 2), dbType = new JComboBox<DatabaseOption>(), CC.xy(3, 2)); configBuilder.add(dbAdvanced = new JCheckBox("Show advanced options"), CC.xy(5, 2)); configBuilder.addLabel("JDBC Connection", CC.xy(1, 4), jdbcString = new JTextField(15), CC.xyw(3, 4, 3)); configBuilder.addLabel("Username", CC.xy(1, 6), username = new JTextField(10), CC.xy(3, 6)); configBuilder.addLabel("Password", CC.xy(1, 8), password = new JPasswordField(10), CC.xy(3, 8)); configBuilder.add(importButton = new JButton("Import"), CC.xywh(5, 6, 1, 3)); //Add hidden JLabel dialectLabel = new JLabel("Dialect"); dialectLabel.setVisible(false); configBuilder.add(dialectLabel, CC.xy(1, 10), dialect = new JTextField(10), CC.xyw(3, 10, 3)); dialect.setVisible(false); JLabel driverLabel = new JLabel("Driver"); driverLabel.setVisible(false); configBuilder.add(driverLabel, CC.xy(1, 12), driver = new JTextField(10) { @Override public void setText(String text) { if (StringUtils.isBlank(text)) log.debug("Text is blank", new RuntimeException("Text " + text + " is blank")); super.setText(text); } }, CC.xyw(3, 12, 3)); driver.setVisible(false); primaryBuilder.add(configBuilder.getPanel(), CC.xy(2, 2)); //Options primaryBuilder.addSeparator("Options", CC.xyw(4, 1, 2)); FormLayout optionsLayout = new FormLayout("pref, 3dlu, pref:grow", ""); DefaultFormBuilder optionsBuilder = new DefaultFormBuilder(optionsLayout); optionsBuilder.append(disableCreateTables = new JCheckBox("Disable Creating Tables"), 3); optionsBuilder.append("Global Table Prefix", globalTablePrefix = new JTextField(7)); optionsBuilder.append("Threads", threads = new JSpinner()); //Save a core for the database int numThreads = Runtime.getRuntime().availableProcessors(); numThreads = (numThreads != 1) ? numThreads - 1 : numThreads; threads.setModel(new SpinnerNumberModel(numThreads, 1, 100, 1)); optionsBuilder.append("Batch Size", batchSize = new JSpinner()); batchSize.setModel(new SpinnerNumberModel(500, 1, 500000, 1)); primaryBuilder.add(optionsBuilder.getPanel(), CC.xy(5, 2)); //Locations primaryBuilder.addSeparator("Dump Locations", CC.xyw(1, 3, 5)); FormLayout locationsLayout = new FormLayout("pref, 15dlu, pref, 5dlu, pref, 5dlu, pref:grow, 2dlu, pref", ""); locationsBuilder = new DefaultFormBuilder(locationsLayout, new ScrollablePanel()).background(Color.WHITE) .lineGapSize(Sizes.ZERO); locationsPane = new JScrollPane(locationsBuilder.getPanel()); locationsPane.getViewport().setBackground(Color.white); locationsPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); locationsPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); primaryBuilder.add(locationsPane, CC.xyw(2, 4, 4)); //Logger primaryBuilder.addSeparator("Log", CC.xyw(1, 5, 5)); loggerText = new JTextPane(); loggerText.setEditable(false); JPanel loggerTextPanel = new JPanel(new BorderLayout()); loggerTextPanel.add(loggerText); JScrollPane loggerPane = new JScrollPane(loggerTextPanel); loggerPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); loggerPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); JPanel loggerPanePanel = new JPanel(new BorderLayout()); loggerPanePanel.add(loggerPane); primaryBuilder.add(loggerPanePanel, CC.xyw(2, 6, 4)); menuAdd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //TODO: Allow 7z files but handle corner cases final JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fc.setMultiSelectionEnabled(true); fc.setDialogTitle("Select Folders/Archives"); fc.addChoosableFileFilter(new FileNameExtensionFilter("Archives", "7z", "zip")); fc.addChoosableFileFilter(new FileFilter() { @Getter protected String description = "Folders"; @Override public boolean accept(File file) { return file.isDirectory(); } }); if (fc.showOpenDialog(frame) != JFileChooser.APPROVE_OPTION) return; //Add files and folders in a seperate thread while updating gui in EDT importButton.setEnabled(false); for (File curFile : fc.getSelectedFiles()) { DumpContainer dumpContainer = null; try { if (curFile.isDirectory()) dumpContainer = new FolderDumpContainer(curFile); else dumpContainer = new ArchiveDumpContainer(controller, curFile); controller.addDumpContainer(dumpContainer); } catch (Exception ex) { String type = (dumpContainer != null) ? dumpContainer.getType() : ""; LoggerFactory.getLogger(getClass()).error("Cannot open " + type, ex); String location = (dumpContainer != null) ? Utils.getLongLocation(dumpContainer) : ""; showErrorDialog(ex, "Cannot open " + location, curFile.getAbsolutePath()); continue; } } updateLocations(); importButton.setEnabled(true); } }); //Add options (Could be in a map, but this is cleaner) dbType.addItem(new DatabaseOption().name("MySQL 5.5.3+") .jdbcString("jdbc:mysql://127.0.0.1:3306/stackexchange?rewriteBatchedStatements=true") .dialect("org.hibernate.dialect.MySQL5Dialect").driver("com.mysql.jdbc.Driver")); dbType.addItem(new DatabaseOption().name("PostgreSQL 8.1") .jdbcString("jdbc:postgresql://127.0.0.1:5432/stackexchange") .dialect("org.hibernate.dialect.PostgreSQL81Dialect").driver("org.postgresql.Driver")); dbType.addItem(new DatabaseOption().name("PostgreSQL 8.2+") .jdbcString("jdbc:postgresql://127.0.0.1:5432/stackexchange") .dialect("org.hibernate.dialect.PostgreSQL82Dialect").driver("org.postgresql.Driver")); dbType.addItem(new DatabaseOption().name("SQL Server") .jdbcString("jbdc:jtds:mssql://127.0.0.1:1433/stackexchange") .dialect("org.hibernate.dialect.SQLServerDialect").driver("net.sourceforge.jtds.jdbc.Driver")); dbType.addItem(new DatabaseOption().name("SQL Server 2005+") .jdbcString("jbdc:jtds:mssql://127.0.0.1:1433/stackexchange") .dialect("org.hibernate.dialect.SQLServer2005Dialect").driver("net.sourceforge.jtds.jdbc.Driver")); dbType.addItem(new DatabaseOption().name("SQL Server 2008+") .jdbcString("jbdc:jtds:mssql://127.0.0.1:1433/stackexchange") .dialect("org.hibernate.dialect.SQLServer2008Dialect").driver("net.sourceforge.jtds.jdbc.Driver")); dbType.addItem(new DatabaseOption().name("H2").jdbcString("jdbc:h2:stackexchange") .dialect("org.hibernate.dialect.H2Dialect").driver("org.h2.Driver")); dbType.setSelectedItem(null); dbType.addItemListener(new ItemListener() { boolean shownMysqlWarning = false; public void itemStateChanged(ItemEvent e) { //Don't run this twice for a single select if (e.getStateChange() == ItemEvent.DESELECTED) return; DatabaseOption selectedOption = (DatabaseOption) dbType.getSelectedItem(); if (selectedOption.name().startsWith("MySQL") && !shownMysqlWarning) { //Hide popup so you don't have to click twice on the dialog dbType.setPopupVisible(false); JOptionPane.showMessageDialog(frame, "Warning: Your server must be configured with character_set_server=utf8mb4" + "\nOtherwise, data dumps that contain 4 byte UTF-8 characters will fail", "MySQL Warning", JOptionPane.WARNING_MESSAGE); shownMysqlWarning = true; } setDbOption(selectedOption); } }); //Show and hide advanced options with checkbox dbAdvanced.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean selected = ((JCheckBox) e.getSource()).isSelected(); driver.setVisible(selected); ((JLabel) driver.getClientProperty("labeledBy")).setVisible(selected); dialect.setVisible(selected); ((JLabel) dialect.getClientProperty("labeledBy")).setVisible(selected); } }); importButton.addActionListener(new ActionListener() { protected void showImportError(String error) { JOptionPane.showMessageDialog(frame, error, "Configuration Error", JOptionPane.ERROR_MESSAGE); } protected void showInputErrorDatabase(String error) { if (dbType.getSelectedItem() == null) showImportError("No dbType specified, " + StringUtils.uncapitalize(error)); else showImportError(error); } public void actionPerformed(ActionEvent e) { boolean validationPassed = false; if (controller.getDumpContainers().isEmpty()) showImportError("Please add dump folders/archives"); else if (StringUtils.isBlank(jdbcString.getText())) showInputErrorDatabase("Must specify JDBC String"); else if (StringUtils.isBlank(driver.getText())) showInputErrorDatabase("Must specify driver"); else if (StringUtils.isBlank(dialect.getText())) showInputErrorDatabase("Must specify hibernate dialect"); else validationPassed = true; if (!validationPassed) return; //Disable all GUI components so they can't change anything during processing setGuiEnabled(false); //Run in new thread controller.getGeneralThreadPool().execute(new Runnable() { public void run() { try { start(); } catch (final Exception e) { //Show an error message box SwingUtilities.invokeLater(new Runnable() { public void run() { LoggerFactory.getLogger(getClass()).error("Cannot import", e); showErrorDialog(e, "Cannot import", null); } }); } //Renable GUI SwingUtilities.invokeLater(new Runnable() { public void run() { setGuiEnabled(true); } }); } }); } }); //Done, init logger logAppender.init(); log.info("Finished creating GUI"); //Display frame.setContentPane(primaryBuilder.getPanel()); frame.pack(); frame.setMinimumSize(frame.getSize()); frame.setVisible(true); }
From source file:org.ut.biolab.medsavant.client.view.dialog.SavantExportForm.java
private void chooseFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseFileButtonActionPerformed JFileChooser fc = new JFileChooser(); fc.setDialogTitle("Save Savant Project"); fc.setDialogType(JFileChooser.SAVE_DIALOG); fc.addChoosableFileFilter(new ExtensionsFileFilter(new String[] { "svp" })); fc.setMultiSelectionEnabled(false);/*from ww w.j a va 2 s . co m*/ int result = fc.showDialog(null, null); if (result == JFileChooser.CANCEL_OPTION || result == JFileChooser.ERROR_OPTION) { return; } outputFile = fc.getSelectedFile(); String path = outputFile.getAbsolutePath(); outputFileField.setText(path); exportButton.setEnabled(true); }