/** * Saves properties to a file, prompts the user to select props file. */ protected void saveProperties() { int retVal; Properties props; FileWriter fwriter; BufferedWriter bwriter; retVal = getFileChooser().showSaveDialog(this); if (retVal != BaseFileChooser.APPROVE_OPTION) return; fwriter = null; bwriter = null; props = getProperties(); try { fwriter = new FileWriter(getFileChooser().getSelectedFile().getAbsolutePath()); bwriter = new BufferedWriter(fwriter); props.store(bwriter, null); } catch (Exception e) { GUIHelper.showErrorMessage(this, "Failed to save properties to: " + getFileChooser().getSelectedFile()); } finally { FileUtils.closeQuietly(bwriter); FileUtils.closeQuietly(fwriter); } }
/** * Lets the user save the script output to a file. */ public void saveScriptOutput() { int retVal; String msg; retVal = m_FileChooserOutput.showSaveDialog(this); if (retVal != BaseFileChooser.APPROVE_OPTION) return; msg = FileUtils.writeToFileMsg(m_FileChooserOutput.getSelectedFile().getAbsolutePath(), m_TextOutput.getText(), false, null); if (msg != null) { GUIHelper.showErrorMessage(this, msg, "Failed saving output"); notifyJShellListeners(new JShellEvent(this, EventType.OUTPUT_SAVE_FAILURE)); } else { notifyJShellListeners(new JShellEvent(this, EventType.OUTPUT_SAVE_SUCESS)); } updateButtons(); }
/** * Performs the actual choosing of an object. * * @return the chosen object or null if none chosen */ @Override protected File doChoose() { m_FileChooser.setSelectedFile(getCurrent()); if (m_UseSaveDialog) { if (m_FileChooser.showSaveDialog(m_Self) == BaseFileChooser.APPROVE_OPTION) { return m_FileChooser.getSelectedFile(); } else { return null; } } else { if (m_FileChooser.showOpenDialog(m_Self) == BaseFileChooser.APPROVE_OPTION) { return m_FileChooser.getSelectedFile(); } else { return null; } } }
/** * Lets the user save the script to a file. */ public void saveScript() { int retVal; File script; String msg; retVal = m_FileChooserScript.showSaveDialog(this); if (retVal != BaseFileChooser.APPROVE_OPTION) return; script = m_FileChooserScript.getSelectedFile(); msg = FileUtils.writeToFileMsg(script.getAbsolutePath(), m_TextCode.getText(), false, null); if (msg != null) { GUIHelper.showErrorMessage(this, "Failed to save script to : " + script + "\n" + msg); notifyJShellListeners(new JShellEvent(this, EventType.SCRIPT_SAVE_FAILURE)); } else { notifyJShellListeners(new JShellEvent(this, EventType.SCRIPT_SAVE_SUCCESS)); } updateButtons(); }
setSelectedFile(currentFile); result = super.showSaveDialog(parent);