/** * Displays an error message with the default title "Error". * * @param parent the parent, to make the dialog modal; can be null * @param msg the error message to display */ public static void showErrorMessage(Component parent, String msg) { showErrorMessage(parent, msg, "Error"); }
/** * Displays an error message with the default title "Error". * * @param parent the parent, to make the dialog modal; can be null * @param msg the error message to display * @param t the exception to append to the message */ public static void showErrorMessage(Component parent, String msg, Throwable t) { showErrorMessage(parent, msg + "\n" + Utils.throwableToString(t), "Error"); }
public void actionPerformed(ActionEvent e) { String msg = checkInput(); if (msg == null) { m_Option = APPROVE_OPTION; setVisible(false); } else { GUIHelper.showErrorMessage(ApprovalDialog.this, msg); } } });
/** * Pops up a print dialog. */ public void printText() { String msg; try { print(null, null, true, null, null, true); } catch (Exception ex) { ex.printStackTrace(); msg = "Failed to print:\n" + ex; if (getParentDialog() != null) GUIHelper.showErrorMessage(getParentDialog(), msg); else GUIHelper.showErrorMessage(getParentFrame(), msg); } }
GUIHelper.showErrorMessage( this, "Error processing clipboard content:\n" + e);
GUIHelper.showErrorMessage(this, "Failed to create temporary file for script!\nCannot execute script!", e); notifyJShellListeners(new JShellEvent(this, EventType.SCRIPT_RUN_SETUP_FAILURE)); return; if (msg != null) { tmpFile.delete(); GUIHelper.showErrorMessage(this, "Failed to write script to temporary file: " + tmpFile + "\n" + msg); notifyJShellListeners(new JShellEvent(this, EventType.SCRIPT_RUN_SETUP_FAILURE)); return;
/** * Loads the specified file. * * @param script the script to load */ public void loadScript(File script) { List<String> lines; try { lines = Files.readAllLines(script.toPath()); m_TextCode.setText(Utils.flatten(lines, "\n")); notifyJShellListeners(new JShellEvent(this, EventType.SCRIPT_LOAD_SUCCESS)); } catch (Exception e) { GUIHelper.showErrorMessage(this, "Failed to load script from: " + script, e); notifyJShellListeners(new JShellEvent(this, EventType.SCRIPT_LOAD_FAILURE)); } updateButtons(); }
/** * Loads properties from a file, prompts the user to select props file. */ protected void loadProperties() { int retVal; Properties props; FileReader freader; BufferedReader breader; retVal = getFileChooser().showOpenDialog(this); if (retVal != BaseFileChooser.APPROVE_OPTION) return; freader = null; breader = null; props = new Properties(); try { freader = new FileReader(getFileChooser().getSelectedFile().getAbsolutePath()); breader = new BufferedReader(freader); props.load(breader); } catch (Exception e) { GUIHelper.showErrorMessage(this, "Failed to load properties from: " + getFileChooser().getSelectedFile()); return; } finally { FileUtils.closeQuietly(breader); FileUtils.closeQuietly(freader); } setProperties(props); }
/** * 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(); }
/** * 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 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(); }
@Override public void run() { try { m_Execution.monitor(builder); if (m_Execution.getExitCode() != 0) notifyJShellListeners(new JShellEvent(JShellPanel.this, EventType.SCRIPT_RUN_FAILURE)); else notifyJShellListeners(new JShellEvent(JShellPanel.this, EventType.SCRIPT_RUN_SUCCESS)); } catch (Exception e) { GUIHelper.showErrorMessage(JShellPanel.this, "Failed to execute script!", e); notifyJShellListeners(new JShellEvent(JShellPanel.this, EventType.SCRIPT_RUN_FAILURE)); } notifyJShellListeners(new JShellEvent(JShellPanel.this, EventType.SCRIPT_FINISHED)); m_Execution = null; tmpFile.delete(); updateButtons(); } };