/** * Tries to find an annotation with localized message(primarily) or general * message in all exception annotations. If the annotation with the message * is found it is notified with original severity. If the message is not * found the exception is notified with informational severity. * * @param e exception to notify */ private static void notifyUser(Exception e) { String userMessage = Exceptions.findLocalizedMessage(e); if (userMessage != null) { Exceptions.printStackTrace(e); } else { // if there is not user message don't bother user, just log an // exception Logger.getLogger(PropertyDialogManager.class.getName()).log(Level.INFO, null, e); } }
String msg = Exceptions.findLocalizedMessage(throwable); if (msg != null) { return msg;
/** Processes <code>Throwable</code> thrown from <code>setAsText</code> * or <code>setValue</code> call on <code>editor</code>. Helper method. */ private static void processThrowable(Throwable throwable, String title, Object newValue) { //Copied from old PropertyPanel impl if (throwable instanceof ThreadDeath) { throw (ThreadDeath) throwable; } String locMsg = Exceptions.findLocalizedMessage(throwable); if (locMsg != null && (throwable.getLocalizedMessage() != throwable.getMessage())) { //XXX See issue 34569 String msg = NbBundle.getMessage( PropUtils.class, "FMT_ErrorSettingProperty", newValue, title); //NOI18N Exceptions.attachLocalizedMessage(throwable, msg); } else if (throwable instanceof NumberFormatException) { //Handle NFE's from the core sun.beans property editors w/o raising stack traces Exceptions.attachLocalizedMessage(throwable, NbBundle.getMessage(PropUtils.class, "FMT_BAD_NUMBER_FORMAT", newValue)); } String msg = Exceptions.findLocalizedMessage(throwable); if( null == msg || msg.isEmpty() ) { msg = throwable.getMessage(); } NotifyDescriptor d = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notifyLater(d); }
/** Processes <code>Throwable</code> thrown from <code>setAsText</code> * or <code>setValue</code> call on <code>editor</code>. Helper method. * Almost copied from PropUtils */ private static void processThrowable(Throwable throwable, String title, Object newValue) { //Copied from old PropertyPanel impl if (throwable instanceof ThreadDeath) { throw (ThreadDeath) throwable; } String locMsg = Exceptions.findLocalizedMessage(throwable); if (locMsg != null && (throwable.getLocalizedMessage() != throwable.getMessage())) { //XXX See issue 34569 String msg = NbBundle.getMessage( PropertiesRowModel.class, "FMT_ErrorSettingValue", newValue, title); //NOI18N Exceptions.attachLocalizedMessage(throwable, msg); } else if (throwable instanceof NumberFormatException) { //Handle NFE's from the core sun.beans property editors w/o raising stack traces Exceptions.attachLocalizedMessage(throwable, NbBundle.getMessage(PropertiesRowModel.class, "FMT_BAD_NUMBER_FORMAT", newValue)); } String msg = Exceptions.findLocalizedMessage(throwable); if (msg == null) { msg = NbBundle.getMessage( PropertiesRowModel.class, "FMT_ErrorSettingValue", newValue, title); //NOI18N } NotifyDescriptor d = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notifyLater(d); }
/** Try to update a property editor with a value object (presumably) * provided by an InplaceEditor. If exceptions are thrown, returns them * for the caller to do with as it wishes (for example a panel that * commits multiple values from several editors at once will probably want to * aggregate them into a single error message) */ static Exception updatePropertyEditor(PropertyEditor ed, Object value) { // System.err.println("UpdatePropertyEditor " + ed + " to " + value ); Exception result = null; try { if (value instanceof String) { try { ed.setAsText((String) value); } catch( IllegalArgumentException iaE ) { //#137706 - always treat iae from setAsText as a an invalid //user input instead of broken code and display nice error message to the user if( null == Exceptions.findLocalizedMessage(iaE) ) Exceptions.attachLocalizedMessage(iaE, NbBundle.getMessage(PropUtils.class, "MSG_SetAsText_InvalidValue", value)); result = iaE; } } else { ed.setValue(value); } } catch (Exception e) { result = e; } // System.err.println("returning " + result); return result; }
static void nodeRename(final Node n, final String newStr) { // bugfix #21589 don't update name if there is not any change if (n.getName().equals(newStr)) { return; } if (EventQueue.isDispatchThread() && Boolean.TRUE.equals(n.getValue("slowRename"))) { // NOI18N RP.post(new Runnable() { @Override public void run() { nodeRename(n, newStr); } }); return; } try { n.setName(newStr); } catch (IllegalArgumentException exc) { boolean needToAnnotate = Exceptions.findLocalizedMessage(exc) == null; // annotate new localized message only if there is no localized message yet if (needToAnnotate) { String msg = NbBundle.getMessage( TreeViewCellEditor.class, "RenameFailed", n.getName(), newStr ); Exceptions.attachLocalizedMessage(exc, msg); } Exceptions.printStackTrace(exc); } }
/** Tries to save given data object using its save cookie. * Notifies user if excetions appear. */ private void save (Savable sc) { try { if (sc != null) { sc.save(); } // only remove the object if the save succeeded listModel.removeElement(sc); } catch (java.io.IOException exc) { Throwable t = exc; if (Exceptions.findLocalizedMessage(exc) == null) { t = Exceptions.attachLocalizedMessage(exc, NbBundle.getBundle(ExitDialog.class).getString("EXC_Save")); } Exceptions.printStackTrace(t); } }
/** * Do runnable within model transaction. * * @param model model where to run * @param job runnable to do * @return {@code true} if the run was successful, {@code false} otherwise */ public static boolean doInTransaction(JSFConfigModel model, Runnable job) { model.startTransaction(); try { job.run(); } finally { try { model.endTransaction(); } catch (IllegalStateException ex) { StatusDisplayer.getDefault().setStatusText( NbBundle.getMessage(JSFConfigModelUtilities.class, "ERR_UpdateFacesConfigModel", //NOI18N Exceptions.findLocalizedMessage(ex))); return false; } } return true; }
message = e.getLocalizedMessage(); } else { message = Exceptions.findLocalizedMessage(e);
/** * A setter that should be used by the property editor * to change the state of the environment. * Even the state property is bound, changes made from the editor itself * are allowed without restrictions. */ public void setState(Object newState) { if (getState().equals(newState)) { // no change, no fire vetoable and property change return; } try { getSupport().fireVetoableChange(PROP_STATE, getState(), newState); state = newState; // always notify state change getChange().firePropertyChange(PROP_STATE, null, newState); } catch (PropertyVetoException pve) { // and notify the user that the change cannot happen String msg = Exceptions.findLocalizedMessage(pve); if (msg == null) { msg = pve.getLocalizedMessage(); } if (msg != null) { DialogDisplayer.getDefault().notify( new NotifyDescriptor.Message(msg, NotifyDescriptor.WARNING_MESSAGE)); } else { // no message for the user, log the exception the standard way PropertyDialogManager.notify(pve); } } }
throw Exceptions.attachLocalizedMessage(io, NbBundle.getMessage(JSFConfigModelUtilities.class, "ERR_Save_FacesConfig", Exceptions.findLocalizedMessage(ex)));
@Override public void setName(String s) { String oldDisplayName = getDisplayName(); try { if (!pc.isPageInAnyFacesConfig(oldDisplayName)) { original.setName(s); } else { renaming = true; original.setName(s); String newDisplayName = original.getDisplayName(); if (isDataNode()) { newDisplayName = getFolderDisplayName(pc.getWebFolder(), ((DataNode) original).getDataObject().getPrimaryFile()); } pc.saveLocation(oldDisplayName, newDisplayName); renaming = false; pc.renamePageInModel(oldDisplayName, newDisplayName); } } catch (IllegalArgumentException iae) { // determine if "printStackTrace" and "new annotation" of this exception is needed boolean needToAnnotate = Exceptions.findLocalizedMessage(iae) == null; // annotate new localized message only if there is no localized message yet if (needToAnnotate) { Exceptions.attachLocalizedMessage(iae, NbBundle.getMessage(Page.class, "MSG_BadFormat", oldDisplayName, s)); } Exceptions.printStackTrace(iae); } }
IOException io = new IOException("Cannot update faces-config.xml", ex); throw Exceptions.attachLocalizedMessage(io, NbBundle.getMessage(JSFFrameworkProvider.class, "ERR_WRITE_FACES_CONFIG", Exceptions.findLocalizedMessage(ex)));