List of usage examples for javax.swing JOptionPane QUESTION_MESSAGE
int QUESTION_MESSAGE
To view the source code for javax.swing JOptionPane QUESTION_MESSAGE.
Click Source Link
From source file:org.apache.cayenne.modeler.ProjectFileChangeTracker.java
/** * Shows confirmation dialog//from w w w .jav a 2 s. c o m */ private boolean showConfirmation(String message) { return JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(Application.getFrame(), message, "File changed", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); }
From source file:org.apache.jmeter.gui.action.Save.java
@Override public void doAction(ActionEvent e) throws IllegalUserActionException { HashTree subTree = null;/*from www. j av a 2 s . com*/ boolean fullSave = false; // are we saving the whole tree? if (!commands.contains(e.getActionCommand())) { throw new IllegalUserActionException("Invalid user command:" + e.getActionCommand()); } if (e.getActionCommand().equals(ActionNames.SAVE_AS)) { JMeterTreeNode[] nodes = GuiPackage.getInstance().getTreeListener().getSelectedNodes(); if (nodes.length > 1) { JMeterUtils.reportErrorToUser(JMeterUtils.getResString("save_as_error"), // $NON-NLS-1$ JMeterUtils.getResString("save_as")); // $NON-NLS-1$ return; } subTree = GuiPackage.getInstance().getCurrentSubTree(); } else if (e.getActionCommand().equals(ActionNames.SAVE_AS_TEST_FRAGMENT)) { JMeterTreeNode[] nodes = GuiPackage.getInstance().getTreeListener().getSelectedNodes(); if (checkAcceptableForTestFragment(nodes)) { subTree = GuiPackage.getInstance().getCurrentSubTree(); // Create Test Fragment node TestElement element = GuiPackage.getInstance() .createTestElement(TestFragmentControllerGui.class.getName()); HashTree hashTree = new ListedHashTree(); HashTree tfTree = hashTree.add(new JMeterTreeNode(element, null)); for (JMeterTreeNode node : nodes) { // Clone deeply current node TreeCloner cloner = new TreeCloner(false); GuiPackage.getInstance().getTreeModel().getCurrentSubTree(node).traverse(cloner); // Add clone to tfTree tfTree.add(cloner.getClonedTree()); } subTree = hashTree; } else { JMeterUtils.reportErrorToUser(JMeterUtils.getResString("save_as_test_fragment_error"), // $NON-NLS-1$ JMeterUtils.getResString("save_as_test_fragment")); // $NON-NLS-1$ return; } } else { fullSave = true; HashTree testPlan = GuiPackage.getInstance().getTreeModel().getTestPlan(); // If saveWorkBench if (isWorkbenchSaveable()) { HashTree workbench = GuiPackage.getInstance().getTreeModel().getWorkBench(); testPlan.add(workbench); } subTree = testPlan; } String updateFile = GuiPackage.getInstance().getTestPlanFile(); if (!ActionNames.SAVE.equals(e.getActionCommand()) || updateFile == null) { JFileChooser chooser = FileDialoger.promptToSaveFile(updateFile == null ? GuiPackage.getInstance().getTreeListener().getCurrentNode().getName() + JMX_FILE_EXTENSION : updateFile); if (chooser == null) { return; } updateFile = chooser.getSelectedFile().getAbsolutePath(); // Make sure the file ends with proper extension if (FilenameUtils.getExtension(updateFile).isEmpty()) { updateFile = updateFile + JMX_FILE_EXTENSION; } // Check if the user is trying to save to an existing file File f = new File(updateFile); if (f.exists()) { int response = JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(), JMeterUtils.getResString("save_overwrite_existing_file"), // $NON-NLS-1$ JMeterUtils.getResString("save?"), // $NON-NLS-1$ JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.CLOSED_OPTION || response == JOptionPane.NO_OPTION) { return; // Do not save, user does not want to overwrite } } if (!e.getActionCommand().equals(ActionNames.SAVE_AS)) { GuiPackage.getInstance().setTestPlanFile(updateFile); } } // backup existing file according to jmeter/user.properties settings List<File> expiredBackupFiles = EMPTY_FILE_LIST; File fileToBackup = new File(updateFile); try { expiredBackupFiles = createBackupFile(fileToBackup); } catch (Exception ex) { log.error("Failed to create a backup for " + fileToBackup.getName(), ex); //$NON-NLS-1$ } try { convertSubTree(subTree); } catch (Exception err) { log.warn("Error converting subtree " + err); } FileOutputStream ostream = null; try { ostream = new FileOutputStream(updateFile); SaveService.saveTree(subTree, ostream); if (fullSave) { // Only update the stored copy of the tree for a full save subTree = GuiPackage.getInstance().getTreeModel().getTestPlan(); // refetch, because convertSubTree affects it if (isWorkbenchSaveable()) { HashTree workbench = GuiPackage.getInstance().getTreeModel().getWorkBench(); subTree.add(workbench); } ActionRouter.getInstance() .doActionNow(new ActionEvent(subTree, e.getID(), ActionNames.SUB_TREE_SAVED)); } // delete expired backups : here everything went right so we can // proceed to deletion for (File expiredBackupFile : expiredBackupFiles) { try { FileUtils.deleteQuietly(expiredBackupFile); } catch (Exception ex) { log.warn("Failed to delete backup file " + expiredBackupFile.getName()); //$NON-NLS-1$ } } } catch (Throwable ex) { log.error("Error saving tree:", ex); if (ex instanceof Error) { throw (Error) ex; } if (ex instanceof RuntimeException) { throw (RuntimeException) ex; } throw new IllegalUserActionException("Couldn't save test plan to file: " + updateFile, ex); } finally { JOrphanUtils.closeQuietly(ostream); } GuiPackage.getInstance().updateCurrentGui(); }
From source file:org.apache.syncope.ide.netbeans.view.ResourceExplorerTopComponent.java
private void openMailEditor(final String name) throws IOException { String formatStr = (String) JOptionPane.showInputDialog(null, "Select File Format", "File format", JOptionPane.QUESTION_MESSAGE, null, PluginConstants.MAIL_TEMPLATE_FORMATS, MailTemplateFormat.TEXT.name()); if (StringUtils.isNotBlank(formatStr)) { MailTemplateFormat format = MailTemplateFormat.valueOf(formatStr); String type = null;//from w w w . j a va 2 s . c o m InputStream is = null; try { switch (format) { case HTML: type = "html"; is = (InputStream) mailTemplateManagerService.getFormat(name, MailTemplateFormat.HTML); break; case TEXT: type = "txt"; is = (InputStream) mailTemplateManagerService.getFormat(name, MailTemplateFormat.TEXT); break; default: LOG.log(Level.SEVERE, String.format("Format [%s] not supported", format)); break; } } catch (SyncopeClientException e) { LOG.log(Level.SEVERE, String.format("Unable to get [%s] mail template in [%s] format", name, format), e); if (ClientExceptionType.NotFound.equals(e.getType())) { LOG.log(Level.SEVERE, String.format("Report template in [%s] format not found, create an empty one", format)); } else { JOptionPane.showMessageDialog(null, String.format("Unable to get [%s] report template in [%s] format", name, format), "Connection Error", JOptionPane.ERROR_MESSAGE); } } catch (Exception e) { LOG.log(Level.SEVERE, String.format("Unable to get [%s] mail template in [%s] format", name, format), e); JOptionPane.showMessageDialog(null, String.format("Unable to get [%s] mail template in [%s] format", name, format), "Error", JOptionPane.ERROR_MESSAGE); } String content = is == null ? StringUtils.EMPTY : IOUtils.toString(is, encodingPattern); String mailTemplatesDirName = System.getProperty("java.io.tmpdir") + "/Templates/Mail/"; File mailTemplatesDir = new File(mailTemplatesDirName); if (!mailTemplatesDir.exists()) { mailTemplatesDir.mkdirs(); } File file = new File(mailTemplatesDirName + name + "." + type); FileWriter fw = new FileWriter(file); fw.write(content); fw.flush(); FileObject fob = FileUtil.toFileObject(file.getAbsoluteFile()); fob.setAttribute("description", "TEXT"); DataObject data = DataObject.find(fob); data.getLookup().lookup(OpenCookie.class).open(); data.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent evt) { if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) { //save item remotely LOG.info(String.format("Saving Mail template [%s]", name)); saveContent(); } } }); } }
From source file:org.apache.syncope.ide.netbeans.view.ResourceExplorerTopComponent.java
private void openReportEditor(final String name) throws IOException { String formatStr = (String) JOptionPane.showInputDialog(null, "Select File Format", "File format", JOptionPane.QUESTION_MESSAGE, null, PluginConstants.REPORT_TEMPLATE_FORMATS, ReportTemplateFormat.FO.name()); if (StringUtils.isNotBlank(formatStr)) { ReportTemplateFormat format = ReportTemplateFormat.valueOf(formatStr); InputStream is = null;// w w w. j a va2s. c o m try { switch (format) { case HTML: is = (InputStream) reportTemplateManagerService.getFormat(name, ReportTemplateFormat.HTML); break; case CSV: is = (InputStream) reportTemplateManagerService.getFormat(name, ReportTemplateFormat.CSV); break; case FO: is = (InputStream) reportTemplateManagerService.getFormat(name, ReportTemplateFormat.FO); break; default: LOG.log(Level.SEVERE, String.format("Format [%s] not supported", format)); break; } } catch (SyncopeClientException e) { LOG.log(Level.SEVERE, String.format("Unable to get [%s] report template in [%s] format", name, format), e); if (ClientExceptionType.NotFound.equals(e.getType())) { LOG.log(Level.SEVERE, String.format("Report template [%s] not found, create an empty one", name)); } else { JOptionPane.showMessageDialog(null, String.format("Unable to get [%s] report template in [%s] format", name, format), "Connection Error", JOptionPane.ERROR_MESSAGE); } } catch (Exception e) { LOG.log(Level.SEVERE, String.format("Unable to get [%s] report template in [%s] format", name, format), e); JOptionPane.showMessageDialog(null, String.format("Unable to get [%s] report template in [%s] format", name, format), "Generic Error", JOptionPane.ERROR_MESSAGE); } String content = is == null ? StringUtils.EMPTY : IOUtils.toString(is, encodingPattern); String reportTemplatesDirName = System.getProperty("java.io.tmpdir") + "/Templates/Report/"; File reportTemplatesDir = new File(reportTemplatesDirName); if (!reportTemplatesDir.exists()) { reportTemplatesDir.mkdirs(); } File file = new File(reportTemplatesDirName + name + "." + format.name().toLowerCase()); FileWriter fw = new FileWriter(file); fw.write(content); fw.flush(); FileObject fob = FileUtil.toFileObject(file.getAbsoluteFile()); DataObject data = DataObject.find(fob); data.getLookup().lookup(OpenCookie.class).open(); data.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent evt) { if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) { //save item remotely LOG.info(String.format("Saving Report template [%s]", name)); saveContent(); } } }); } }
From source file:org.colombbus.tangara.CommandSelection.java
private boolean userConfirmOverride(File destinationFile) { String title;//from w ww. j a v a 2 s. c o m String pattern; if (mode == MODE_PROGRAM_CREATION) { title = Messages.getString("CommandSelection.programCreation.override.title"); pattern = Messages.getString("CommandSelection.programCreation.override.message"); } else { title = Messages.getString("CommandSelection.fileCreation.override.title"); pattern = Messages.getString("CommandSelection.fileCreation.override.message"); } String message = MessageFormat.format(pattern, destinationFile.getName()); Object[] options = { Messages.getString("tangara.yes"), Messages.getString("tangara.cancel") }; int optionType = JOptionPane.OK_CANCEL_OPTION; int messageType = JOptionPane.QUESTION_MESSAGE; Icon icon = null; int answer = JOptionPane.showOptionDialog(this, message, title, optionType, messageType, icon, options, options[0]); return answer == JOptionPane.OK_OPTION; }
From source file:org.colombbus.tangara.EditorFrame.java
private boolean userConfirmFileOverride(File destinationFile) { String messagePattern = Messages.getString("EditorFrame.program.override.message"); //$NON-NLS-1$ String message = MessageFormat.format(messagePattern, destinationFile.getName()); String title = Messages.getString("EditorFrame.program.override.title"); //$NON-NLS-1$ Object[] options = { Messages.getString("tangara.yes"), Messages.getString("tangara.cancel") }; //$NON-NLS-1$ //$NON-NLS-2$ Icon icon = null;/*from w w w .j a va 2 s . c o m*/ int messageType = JOptionPane.QUESTION_MESSAGE; int answer = JOptionPane.showOptionDialog(EditorFrame.this, message, title, optionType, messageType, icon, options, options[0]); return answer == JOptionPane.OK_OPTION; }
From source file:org.colombbus.tangara.EditorFrame.java
/** * Quit Tangara (close the window and the program). * *//*from ww w. j a v a 2s .co m*/ public void exit() { graphicsPane.freeze(true); String title = Messages.getString("EditorFrame.exit.title"); //$NON-NLS-1$ String message = Messages.getString("EditorFrame.exit.message"); //$NON-NLS-1$ Object[] options = { Messages.getString("tangara.yes"), //$NON-NLS-1$ Messages.getString("tangara.cancel") }; //$NON-NLS-1$ int answer = JOptionPane.showOptionDialog(this, message, title, optionType, JOptionPane.QUESTION_MESSAGE, null, // do not use a custom Icon options, // the titles of buttons options[0]); if (answer == JOptionPane.OK_OPTION) { if (getProgramManager().checkProgramChanged()) { dispose(); Program.instance().exit(); } } else graphicsPane.freeze(false); }
From source file:org.colombbus.tangara.EditorFrame.java
/** * This method initializes refreshButton * * @return javax.swing.JButton/*from ww w . j ava2 s . co m*/ */ private JButton getRefreshButton() { if (refreshButton == null) { refreshButton = new JButton(); refreshButton.setBackground(new Color(156, 199, 213)); refreshButton.setText(Messages.getString("EditorFrame.button.clean")); //$NON-NLS-1$ refreshButton.setFont(new Font("Lucida Grande", Font.PLAIN, 13)); //$NON-NLS-1$ refreshButton.setIcon(new ImageIcon(getClass().getResource("/org/colombbus/tangara/cross.png"))); //$NON-NLS-1$ refreshButton.setPreferredSize(new Dimension(75, 30)); refreshButton.setForeground(new Color(51, 51, 51)); refreshButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { graphicsPane.freeze(true); String message = Messages.getString("EditorFrame.confirmClean.text"); //$NON-NLS-1$ String title = Messages.getString("EditorFrame.confirmClean.title"); //$NON-NLS-1$ Object[] options = { Messages.getString("tangara.yes"), Messages.getString("tangara.cancel") }; //$NON-NLS-1$ //$NON-NLS-2$ int answer = JOptionPane.showOptionDialog(EditorFrame.this, message, title, optionType, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (answer == JOptionPane.OK_OPTION) { refresh(); } graphicsPane.freeze(false); commandPane.requestFocus(); } }); } return refreshButton; }
From source file:org.colombbus.tangara.net.FileReceptionDialog.java
/** * This method initializes this//from w w w . ja v a 2 s . co m * */ public void setVisible() { final String[] options = { Messages.getString("FileReceptionDialog.saveButton"), Messages.getString("FileReceptionDialog.cancelButton") }; final String title = Messages.getString("FileReceptionDialog.title"); final int optionType = JOptionPane.OK_CANCEL_OPTION; final int messageType = JOptionPane.QUESTION_MESSAGE; final Icon icon = null; int choosenOption = JOptionPane.showOptionDialog(owner, message, title, optionType, messageType, icon, options, options[0]); if (choosenOption == JOptionPane.OK_OPTION) setTargetFile(); }
From source file:org.colombbus.tangara.net.FileReceptionDialog.java
private void setTargetFile() { File targetDir = Configuration.instance().getUserHome(); JFileChooser chooserDlg = new JFileChooser(targetDir); String filterMsg = Messages.getString("FileReceptionDialog.filter.allFiles"); SimpleFileFilter filter = new SimpleFileFilter(filterMsg); chooserDlg.setFileFilter(filter);/*from w ww.j a v a 2s .c o m*/ File originalSelFile = new File(targetDir, sourceFilename); File curSelFile = originalSelFile; boolean showDialog = true; while (showDialog) { chooserDlg.setSelectedFile(curSelFile); int userAction = chooserDlg.showSaveDialog(owner); curSelFile = chooserDlg.getSelectedFile(); switch (userAction) { case JFileChooser.CANCEL_OPTION: showDialog = false; break; case JFileChooser.APPROVE_OPTION: if (curSelFile.exists()) { String title = Messages.getString("FileReceptionDialog.overwrite.title"); String msgPattern = Messages.getString("FileReceptionDialog.overwrite.message"); String overwriteMsg = MessageFormat.format(msgPattern, curSelFile.getName()); Object[] options = { Messages.getString("FileReceptionDialog.yes"), Messages.getString("FileReceptionDialog.no") }; int userChoice = JOptionPane.showOptionDialog(owner, overwriteMsg, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, // do not use a // custom Icon options, // the titles of buttons options[0]); if (userChoice == JOptionPane.OK_OPTION) { if (saveFileAs(curSelFile)) { showDialog = false; } } } else if (saveFileAs(curSelFile)) { showDialog = false; } break; case JFileChooser.ERROR_OPTION: LOG.error("Error in file chooser dialog"); // TODO what to do in case of error ? Retry ? showDialog = false; break; } } }