Java Code Examples for org.openide.util.Exceptions#attachLocalizedMessage()

The following examples show how to use org.openide.util.Exceptions#attachLocalizedMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultInstancePropertiesImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void setProperty(String propname, String value) throws IllegalStateException {
    try {
        String oldValue = getProperty(propname);
        if (InstanceProperties.PASSWORD_ATTR.equals(propname)) {
            ServerRegistry.savePassword(url, value,
                    NbBundle.getMessage(DefaultInstancePropertiesImpl.class, "MSG_KeyringDefaultDisplayName"));
            getFileObject().setAttribute(propname, null);
        } else {
            getFileObject().setAttribute(propname, value);
        }
        firePropertyChange(new PropertyChangeEvent(this, propname, oldValue, value));
    } catch (IOException ioe) {
        String message = NbBundle.getMessage(DefaultInstancePropertiesImpl.class, "MSG_InstanceNotExists", url);
        throw new IllegalStateException(Exceptions.attachLocalizedMessage(ioe, message));
    }
}
 
Example 2
Source File: UIExceptions.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static void annotateUser(
    Throwable t,
    String msg,
    String locMsg,
    Throwable stackTrace,
    Date date
) {
    AnnException ex = AnnException.findOrCreate(t, true);
    LogRecord rec = new LogRecord(OwnLevel.USER, msg);
    if (stackTrace != null) {
        rec.setThrown(stackTrace);
    }
    ex.addRecord(rec);
    
    if (locMsg != null) {
        Exceptions.attachLocalizedMessage(t, locMsg);
    }
}
 
Example 3
Source File: PersistenceManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Checks for some persistence errors and notifies the user if some
 * persistence errors occured. Should be called after serialization
 * and deserialization of window manager.
 */
public void checkPersistenceErrors(boolean reading) {
    if(failedCompsMap == null || failedCompsMap.isEmpty()) {
        return;
    }

    for (Exception e : failedCompsMap.keySet()) {
        String name = failedCompsMap.get(e);
        // create message
        String message = NbBundle.getMessage(PersistenceManager.class, 
                (reading ? "FMT_TCReadError" : "FMT_TCWriteError"),
                name);
        Exceptions.attachLocalizedMessage(e, message);
        LOG.log(Level.INFO, null, e);
    }
    
    // clear for futher use
    failedCompsMap = null;
}
 
Example 4
Source File: OptionsExportModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Copy files from source (zip or userdir) into target userdir or fip file
 * according to current state of model. i.e. only include/exclude patterns from
 * enabled items are considered.
 * @throws IOException if copying fails
 */
private void copyFiles() throws IOException {
    if (source.isFile()) {
        try {
            // zip file
            copyZipFile();
        } catch (IOException ex) {
            Exceptions.attachLocalizedMessage(ex, NbBundle.getMessage(OptionsExportModel.class, "OptionsExportModel.invalid.zipfile", source));
            Exceptions.printStackTrace(ex);
        }
    } else {
        // userdir
        copyFolder(source);
    }
}
 
Example 5
Source File: CloneableEditor143143Test.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void markModified() throws IOException {
    if (cannotBeModified != null) {
        final String notify = cannotBeModified;
        IOException e = new IOException () {
            public String getLocalizedMessage () {
                return notify;
            }
        };
        Exceptions.attachLocalizedMessage(e, cannotBeModified);
        throw e;
    }
    
    modified = true;
}
 
Example 6
Source File: CloneableEditorUserQuestionTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void markModified() throws IOException {
    if (cannotBeModified != null) {
        final String notify = cannotBeModified;
        IOException e = new IOException () {
            public @Override String getLocalizedMessage() {
                return notify;
            }
        };
        Exceptions.attachLocalizedMessage(e, cannotBeModified);
        throw e;
    }
    
    modified = true;
}
 
Example 7
Source File: PersistenceManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Copy settings file from Module Components module folder (Windows2/Components)
 * to Local Components folder (Windows2Local/Components). */
private void copySettingsFile (FileObject fo) throws IOException {
    if (DEBUG) Debug.log(PersistenceManager.class, "copySettingsFile fo:" + fo);
    FileObject destFolder = getComponentsLocalFolder();
    try {
        fo.copy(destFolder,fo.getName(),fo.getExt());
    } catch (IOException exc) {
        String annotation = NbBundle.getMessage(PersistenceManager.class,
            "EXC_CopyFails", destFolder);
        Exceptions.attachLocalizedMessage(exc, annotation);
        LOG.log(Level.INFO, null, exc);
    }
}
 
Example 8
Source File: Starvation37045Test.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void markModified() throws java.io.IOException {
    if (cannotBeModified != null) {
        IOException e = new IOException ();
        Exceptions.attachLocalizedMessage(e, cannotBeModified);
        throw e;
    }
    
    modified = true;
}
 
Example 9
Source File: FilesystemInterceptor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void doCopy (final File from, final File to) throws IOException {
    LOG.log(Level.FINE, "doCopy {0}->{1}", new Object[] { from, to }); //NOI18N
    if (from == null || to == null || to.exists()) return;

    Git git = Git.getInstance();
    File root = git.getRepositoryRoot(from);
    File dstRoot = git.getRepositoryRoot(to);

    if (from.isDirectory()) {
        FileUtils.copyDirFiles(from, to);
    } else {
        FileUtils.copyFile(from, to);
    }

    if (root == null || cache.getStatus(to).containsStatus(Status.NOTVERSIONED_EXCLUDED)) {
        // target lies under ignored folder, do not add it
        return;
    }
    GitClient client = null;
    try {
        if (root.equals(dstRoot)) {
            client = git.getClient(root);
            client.copyAfter(from, to, GitUtils.NULL_PROGRESS_MONITOR);
        }
    } catch (GitException e) {
        IOException ex = new IOException();
        Exceptions.attachLocalizedMessage(e, NbBundle.getMessage(FilesystemInterceptor.class, "MSG_CopyFailed", new Object[] { from, to, e.getLocalizedMessage() })); //NOI18N
        ex.initCause(e);
        throw ex;
    } finally {
        if (client != null) {
            client.release();
        }
    }
}
 
Example 10
Source File: CloneableEditorSupportDoubleSaveTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void markModified() throws IOException {
    if (cannotBeModified != null) {
        final String notify = cannotBeModified;
        IOException e = new IOException () {
            @Override
            public String getLocalizedMessage () {
                return notify;
            }
        };
        Exceptions.attachLocalizedMessage(e, cannotBeModified);
        throw e;
    }
    
    modified = true;
}
 
Example 11
Source File: CloneableEditorUserQuestionAsync2Test.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void markModified() throws IOException {
    if (cannotBeModified != null) {
        final String notify = cannotBeModified;
        IOException e = new IOException () {
            public @Override String getLocalizedMessage() {
                return notify;
            }
        };
        Exceptions.attachLocalizedMessage(e, cannotBeModified);
        throw e;
    }
    
    modified = true;
}
 
Example 12
Source File: RendererDisplayerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setAsText(String val) {
    //System.err.println("SetAsText");
    if (val.equals("Value")) {
        myVal = val;
    } else {
        IllegalArgumentException iae = new IllegalArgumentException("No!");
        Exceptions.attachLocalizedMessage(iae, "Localized message");
        throw iae;
    }
}
 
Example 13
Source File: CloneableEditorSupportTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void markModified() throws java.io.IOException {
    if (cannotBeModified != null) {
        final String notify = cannotBeModified;
        IOException e = new IOException () {
            public String getLocalizedMessage () {
                return notify;
            }
        };
        Exceptions.attachLocalizedMessage(e, cannotBeModified);
        throw e;
    }
    
    modified = true;
}
 
Example 14
Source File: Deadlock40766Test.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void markModified() throws java.io.IOException {
    if (cannotBeModified != null) {
        IOException e = new IOException ();
        Exceptions.attachLocalizedMessage(e, cannotBeModified);
        throw e;
    }
    
    modified = true;
}
 
Example 15
Source File: CloneableEditorUserQuestionAsyncTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void markModified() throws IOException {
    if (cannotBeModified != null) {
        final String notify = cannotBeModified;
        IOException e = new IOException () {
            public @Override String getLocalizedMessage() {
                return notify;
            }
        };
        Exceptions.attachLocalizedMessage(e, cannotBeModified);
        throw e;
    }
    
    modified = true;
}
 
Example 16
Source File: CloseButtonTabbedPane.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void processMouseEvent (MouseEvent me) {
    try {
        super.processMouseEvent (me);
    } catch (ArrayIndexOutOfBoundsException aioobe) {
        //Bug in BasicTabbedPaneUI$Handler:  The focusIndex field is not
        //updated when tabs are removed programmatically, so it will try to
        //repaint a tab that's not there
        Exceptions.attachLocalizedMessage(aioobe,
                                          "Suppressed AIOOBE bug in BasicTabbedPaneUI"); //NOI18N
        Logger.getAnonymousLogger().log(Level.WARNING, null, aioobe);
    }
}
 
Example 17
Source File: OptionsChooserPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@NbBundle.Messages({
    "OPT_RestartAfterImport=false"
})
/** Shows panel for import of options. */
public static void showImportDialog() {
    LOGGER.fine("showImportDialog");  //NOI18N
    OptionsChooserPanel optionsChooserPanel = new OptionsChooserPanel();
    optionsChooserPanel.txtFile.setEditable(false);
    Mnemonics.setLocalizedText(optionsChooserPanel.lblFile, NbBundle.getMessage(OptionsChooserPanel.class, "OptionsChooserPanel.import.lblFile.text"));
    Mnemonics.setLocalizedText(optionsChooserPanel.lblHint, NbBundle.getMessage(OptionsChooserPanel.class, "OptionsChooserPanel.import.lblHint.text"));
    optionsChooserPanel.panelType = PanelType.IMPORT;

    DialogDescriptor dd = new DialogDescriptor(
            optionsChooserPanel,
            NbBundle.getMessage(OptionsChooserPanel.class, "OptionsChooserPanel.import.title"),
            true,
            new Object[]{DialogDescriptor.OK_OPTION, DialogDescriptor.CANCEL_OPTION},
            DialogDescriptor.OK_OPTION,
            DialogDescriptor.DEFAULT_ALIGN,
            null,
            null);
    dd.createNotificationLineSupport();
    dd.setValid(false);
    boolean ok;
    final boolean willRestart = "true".equals(Bundle.OPT_RestartAfterImport()); // NOI18N
    final ImportConfirmationPanel confirmationPanel = new ImportConfirmationPanel();
    dd.setButtonListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (willRestart && e.getSource() == DialogDescriptor.OK_OPTION) {
                // show confirmation dialog when user click OK
                confirmationPanel.showConfirmation();
            }
        }
    });
    optionsChooserPanel.setDialogDescriptor(dd);
    DialogDisplayer.getDefault().createDialog(dd).setVisible(true);
    ok = DialogDescriptor.OK_OPTION.equals(dd.getValue());
    if (willRestart) {
        if (!confirmationPanel.confirmed()) {
            LOGGER.fine("Import canceled.");  //NOI18N
            ok = false;
        }
    }

    if (ok) {
        // do import
        File targetUserdir = Places.getUserDirectory();
        try {
            optionsChooserPanel.getOptionsExportModel().doImport(targetUserdir);
        } catch (IOException ioe) {
            // report exception and return if import failed
            Exceptions.attachLocalizedMessage(ioe,
                    NbBundle.getMessage(OptionsChooserPanel.class, "OptionsChooserPanel.import.error"));
            LOGGER.log(Level.SEVERE, ioe.getMessage(), ioe);
            return;
        }
        LOGGER.fine("Import finished.");  //NOI18N
        if (willRestart) { // NOI18N
            // restart IDE
            LifecycleManager.getDefault().markForRestart();
            LifecycleManager.getDefault().exit();
        }
        try {
            FileUtil.getConfigRoot().getFileSystem().refresh(true);
        } catch (FileStateInvalidException ex) {
            Exceptions.printStackTrace(ex);
        }
        Action reload = Actions.forID("Window", "org.netbeans.core.windows.actions.ReloadWindowsAction");
        if (reload != null) {
            reload.actionPerformed(new ActionEvent(optionsChooserPanel, 0, ""));
        }
    }
}
 
Example 18
Source File: FocusAfterBadEditTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void setAsText(String txt) {
    IllegalArgumentException iae = new IllegalArgumentException("Bad, bad, bad");
    Exceptions.attachLocalizedMessage(iae, "I can\'t be nice, I\'m the evil property editor.");
    throw iae;
}
 
Example 19
Source File: DefaultProjectOperationsImplementation.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * @return true if success
 */
private static void performDelete(Project project, List<FileObject> toDelete, ProgressHandle handle) throws Exception {
    try {
        handle.start(toDelete.size() + 1 /*clean*/);
        
        int done = 0;
        
        handle.progress(NbBundle.getMessage(DefaultProjectOperationsImplementation.class, "LBL_Progress_Cleaning_Project"));
        
        ProjectOperations.notifyDeleting(project);
        
        handle.progress(++done);
        
        for (FileObject f : toDelete) {
            handle.progress(NbBundle.getMessage(DefaultProjectOperationsImplementation.class, "LBL_Progress_Deleting_File", FileUtil.getFileDisplayName(f)));
            
            if (f != null && f.isValid()) {
                f.delete();
            }
            
            handle.progress(++done);
        }
        
        FileObject projectFolder = project.getProjectDirectory();
        projectFolder.refresh(); // #190983
        
        if (!projectFolder.isValid()) {
            LOG.log(Level.WARNING, "invalid project folder: {0}", projectFolder);
        } else if (projectFolder.getChildren().length == 0) {
            projectFolder.delete();
        } else {
            LOG.log(Level.WARNING, "project folder {0} was not empty: {1}", new Object[] {projectFolder, Arrays.asList(projectFolder.getChildren())});
        }
        
        handle.finish();
        
        ProjectOperations.notifyDeleted(project);
    } catch (Exception e) {
        String displayName = getDisplayName(project);
        String message     = NbBundle.getMessage(DefaultProjectOperationsImplementation.class, "LBL_Project_cannot_be_deleted.", displayName);

        Exceptions.attachLocalizedMessage(e, message);
        throw e;
    }
}
 
Example 20
Source File: ExternalUtil.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Annotates the exception with a message.
 */
public static void annotate(Throwable ex, String msg) {
    Exceptions.attachLocalizedMessage(ex, msg);
}