Java Code Examples for org.openide.NotifyDescriptor#YES_NO_OPTION

The following examples show how to use org.openide.NotifyDescriptor#YES_NO_OPTION . 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: SQLEditorSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void saveAs(FileObject folder, String fileName) throws IOException {
    String fn = FileUtil.getFileDisplayName(folder) + File.separator + fileName; 
    File existingFile = FileUtil.normalizeFile(new File(fn));
    if (existingFile.exists()) {
        NotifyDescriptor confirm = new NotifyDescriptor.Confirmation(
                NbBundle.getMessage(SQLEditorSupport.class,
                "MSG_ConfirmReplace", fileName),
                NbBundle.getMessage(SQLEditorSupport.class,
                "MSG_ConfirmReplaceFileTitle"),
                NotifyDescriptor.YES_NO_OPTION);
        DialogDisplayer.getDefault().notify(confirm);
        if (!confirm.getValue().equals(NotifyDescriptor.YES_OPTION)) {
            return;
        }
    }
    if (isConsole()) {
        // #166370 - if console, need to save document before copying
        saveDocument();
    }
    super.saveAs(folder, fileName);
}
 
Example 2
Source File: TerminateAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected void performAction(Node[] nodes) {
    for (int i = 0; i < nodes.length; i++) {
        TomcatInstanceNode cookie = (TomcatInstanceNode)nodes[i].getCookie(TomcatInstanceNode.class);
        if (cookie != null) {
            final TomcatManager tm = cookie.getTomcatManager();
            String name = tm.getTomcatProperties().getDisplayName();
            NotifyDescriptor nd = new NotifyDescriptor.Confirmation(
                    NbBundle.getMessage(TerminateAction.class, "MSG_terminate", name),
                    NotifyDescriptor.YES_NO_OPTION);
            Object retValue = DialogDisplayer.getDefault().notify(nd);
            if (retValue == DialogDescriptor.YES_OPTION) {
                RequestProcessor.getDefault().post(new Runnable() {
                    public void run() {
                        tm.terminate();
                        // wait a sec before refreshing the state
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException ie) {}
                        tm.getInstanceProperties().refreshServerInstance();
                    }
                });
            }
        }
    }
}
 
Example 3
Source File: WarnPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Display GlassFish process kill warning message and handle <i>Show this
 * warning next time</i> check box.
 * <p/>
 * @param serverName GlassFish server display name.
 * @return Value of <code>true</code> when <code>YES</code> button
 *         was selected or Value of <code>false</code> when <code>NO/code>
 *         button was selected. Always returns true after <i>Show this
 *         warning next time</i> check box was turned on.
 */
public static boolean gfKillWarning(final String serverName) {
    boolean showAgain = GlassFishSettings.getGfKillWarningShowAgain();
    if (showAgain) {
        String warning = NbBundle.getMessage(
                WarnPanel.class, "WarnPanel.GfKillWarning", serverName);
        String title = NbBundle.getMessage(
                WarnPanel.class, "WarnPanel.GfKillTitle");
        WarnPanel panel =  new WarnPanel(warning, showAgain);
        NotifyDescriptor notifyDescriptor = new NotifyDescriptor(
            panel, title, NotifyDescriptor.YES_NO_OPTION,
            NotifyDescriptor.PLAIN_MESSAGE, null, null);
        Object button
                = DialogDisplayer.getDefault().notify(notifyDescriptor);
        GlassFishSettings.setGfKillWarningShowAgain(panel.showAgain());
        return button == YES_OPTION;
    } else {
        return true;
    }
}
 
Example 4
Source File: DatabaseNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NbBundle.Messages({
    "# {0} - Database name",
    "MSG_Confirm_DB_Delete=Really delete database {0}?",
    "MSG_Confirm_DB_Delete_Title=Delete Database"})
@Override
public void destroy() {
    NotifyDescriptor d =
            new NotifyDescriptor.Confirmation(
            Bundle.MSG_Confirm_DB_Delete(model.getDbName()),
            Bundle.MSG_Confirm_DB_Delete_Title(),
            NotifyDescriptor.YES_NO_OPTION);
    Object result = DialogDisplayer.getDefault().notify(d);
    if (!NotifyDescriptor.OK_OPTION.equals(result)) {
        return;
    }
    DatabaseServer server = model.getServer();
    String dbname = model.getDbName();

    server.dropDatabase(dbname);
}
 
Example 5
Source File: XmlMultiViewEditorSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean checkCharsetConversion(final String encoding) {
    boolean value = true;
    try {
        CharsetEncoder coder = Charset.forName(encoding).newEncoder();
        if (!coder.canEncode(getDocument().getText(0, getDocument().getLength()))){
            NotifyDescriptor nd = new NotifyDescriptor.Confirmation(
                    NbBundle.getMessage(XmlMultiViewEditorSupport.class, "MSG_BadCharConversion",
                    new Object [] { getDataObject().getPrimaryFile().getNameExt(),
                    encoding}),
                    NotifyDescriptor.YES_NO_OPTION,
                    NotifyDescriptor.WARNING_MESSAGE);
            nd.setValue(NotifyDescriptor.NO_OPTION);
            DialogDisplayer.getDefault().notify(nd);
            if(nd.getValue() != NotifyDescriptor.YES_OPTION) {
                value = false;
            }
        }
    } catch (BadLocationException e){
        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
    }
    return value;
}
 
Example 6
Source File: SQLHistoryPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void deleteAllSQL() {
    NotifyDescriptor d = new NotifyDescriptor.Confirmation(
            NbBundle.getMessage(SQLHistoryPanel.class, "DESC_DeleteAll"),
            NbBundle.getMessage(SQLHistoryPanel.class, "LBL_DeleteAll"),
            NotifyDescriptor.YES_NO_OPTION);
    if (DialogDisplayer.getDefault().notify(d) == NotifyDescriptor.YES_OPTION) {
        SQLHistoryManager shm = SQLHistoryManager.getInstance();
        SQLHistory history = shm.getSQLHistory();
        history.clear();
        shm.save();
        htm.refresh();
    }
}
 
Example 7
Source File: SaveAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void performAction(Savable sc, Node n) {
    UserQuestionException userEx = null;
    for (;;) {
        try {
            if (userEx == null) {
                sc.save();
            } else {
                userEx.confirmed();
            }
            StatusDisplayer.getDefault().setStatusText(
                NbBundle.getMessage(SaveAction.class, "MSG_saved", getSaveMessage(sc, n))
            );
        } catch (UserQuestionException ex) {
            NotifyDescriptor nd = new NotifyDescriptor.Confirmation(ex.getLocalizedMessage(),
                    NotifyDescriptor.YES_NO_OPTION);
            Object res = DialogDisplayer.getDefault().notify(nd);

            if (NotifyDescriptor.OK_OPTION.equals(res)) {
                userEx = ex;
                continue;
            }
        } catch (IOException e) {
            Exceptions.attachLocalizedMessage(e,
                                              NbBundle.getMessage(SaveAction.class,
                                                                  "EXC_notsaved",
                                                                  getSaveMessage(sc, n),
                                                                  e.getLocalizedMessage ()));
            Logger.getLogger (getClass ().getName ()).log (Level.SEVERE, null, e);
        }
        break;
    }
}
 
Example 8
Source File: AbstractOutputPane.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NbBundle.Messages({
    "MSG_TerminateProcess=Terminate the process?"
})
private void askTerminate(KeyEvent keyEvent) {
    Container parent = getParent();
    if (parent instanceof AbstractOutputTab) {
        Caret c = getCaret();
        if (c.getDot() != c.getMark()) {
            return; // some text is selected, copy action will handle this
        }
        AbstractOutputTab tab = (AbstractOutputTab) parent;
        Action[] actions = tab.getToolbarActions();
        for (Action a : actions) {
            if ("stop".equals(a.getValue("OUTPUT_ACTION_TYPE"))     //NOI18N
                    && a.isEnabled()) {
                NotifyDescriptor desc = new NotifyDescriptor.Confirmation(
                        Bundle.MSG_TerminateProcess(),
                        NotifyDescriptor.YES_NO_OPTION);
                Object res = DialogDisplayer.getDefault().notify(desc);
                if (NotifyDescriptor.YES_OPTION.equals(res)) {
                    a.actionPerformed(
                            new ActionEvent(this, 0, "stop"));      //NOI18N
                }
                keyEvent.consume();
                break;
            }
        }
    }
}
 
Example 9
Source File: PushTagAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NbBundle.Messages({
    "# {0} - image name",
    "MSG_PushQuestion=Do you really want to push the image {0} to the registry?"
})
private void perform(final DockerTag tag) {
    NotifyDescriptor desc = new NotifyDescriptor.Confirmation(
            Bundle.MSG_PushQuestion(tag.getTag()), NotifyDescriptor.YES_NO_OPTION);
    if (DialogDisplayer.getDefault().notify(desc) != NotifyDescriptor.YES_OPTION) {
        return;
    }

    RequestProcessor.getDefault().post(new Push(tag));
}
 
Example 10
Source File: RefreshClientDialog.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static RefreshClientDialog.Result open(boolean downloadWsdl, String url) {
    String title = NbBundle.getMessage(RefreshClientDialog.class, "MSG_ConfirmClientRefresh");
    RefreshClientDialog refreshDialog = new RefreshClientDialog(downloadWsdl, url);
    NotifyDescriptor desc = new NotifyDescriptor.Confirmation(refreshDialog, title, NotifyDescriptor.YES_NO_OPTION);
    Object result = DialogDisplayer.getDefault().notify(desc);
    if (result.equals(NotifyDescriptor.CLOSED_OPTION) || result.equals(NotifyDescriptor.NO_OPTION)) {
        return Result.CLOSE;
    } else if (refreshDialog.downloadWsdl()) {
        Result res = Result.DOWNLOAD_AND_REFRESH;
        res.setWsdlUrl(refreshDialog.getWsdlUrl());
        return res;
    } else return Result.REFRESH_ONLY;
    
}
 
Example 11
Source File: SimpleIO.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    if(process.get() != null) {
        String message = NbBundle.getMessage(SimpleIO.class, "MSG_QueryCancel", name); // NOI18N
        NotifyDescriptor nd = new NotifyDescriptor.Confirmation(message,
                NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.QUESTION_MESSAGE);
        if(DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.YES_OPTION) {
            Process p = process.getAndSet(null);
            if(p != null) {
                p.destroy();
            } else {
                Logger.getLogger("glassfish").log(Level.FINEST, "Process handle unexpectedly null, cancel aborted."); // NOI18N
            }
        }
    }
}
 
Example 12
Source File: CloneableEditorSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Handles the actual reload of document.
* @param doReload false if we should first ask the user
*/
private void checkReload(JEditorPane[] openedPanes, boolean doReload) {
    StyledDocument d;

    synchronized (getLock()) {
        d = getDoc(); // Hold reference to document being reloaded
    }

    if (!doReload && !reloadDialogOpened) {
        String msg = NbBundle.getMessage(
                CloneableEditorSupport.class, "FMT_External_change", // NOI18N
                d.getProperty(javax.swing.text.Document.TitleProperty)
            );

        NotifyDescriptor nd = new NotifyDescriptor.Confirmation(msg, NotifyDescriptor.YES_NO_OPTION);

        reloadDialogOpened = true;

        try {
            Object ret = DialogDisplayer.getDefault().notify(nd);

            if (NotifyDescriptor.YES_OPTION.equals(ret)) {
                doReload = true;
            }
        } finally {
            reloadDialogOpened = false;
        }
    }

    if (doReload) {
        openClose.reload(openedPanes);

        // Call just for compatibility but this has no effect since the code will not wait
        // for the returned task anyway
        reloadDocument();
    }
}
 
Example 13
Source File: ExplorerActionsImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Messages({
    "# {0} - name", "MSG_ConfirmDeleteObject=Are you sure you want to delete {0}?",
    "MSG_ConfirmDeleteObjectTitle=Confirm Object Deletion",
    "# {0} - number of objects", "MSG_ConfirmDeleteObjects=Are you sure you want to delete these {0} items?",
    "MSG_ConfirmDeleteObjectsTitle=Confirm Multiple Object Deletion"
})
private boolean doConfirm(Node[] sel) {
    String message;
    String title;
    boolean customDelete = true;

    for (int i = 0; i < sel.length; i++) {
        if (!Boolean.TRUE.equals(sel[i].getValue("customDelete"))) { // NOI18N
            customDelete = false;

            break;
        }
    }

    if (customDelete) {
        return true;
    }

    if (sel.length == 1) {
        message = MSG_ConfirmDeleteObject(
                sel[0].getDisplayName()
            );
        title = MSG_ConfirmDeleteObjectTitle();
    } else {
        message = MSG_ConfirmDeleteObjects(
                Integer.valueOf(sel.length)
            );
        title = MSG_ConfirmDeleteObjectsTitle();
    }

    NotifyDescriptor desc = new NotifyDescriptor.Confirmation(message, title, NotifyDescriptor.YES_NO_OPTION);

    return NotifyDescriptor.YES_OPTION.equals(DialogDisplayer.getDefault().notify(desc));
}
 
Example 14
Source File: ProfilerDialogsProviderImpl.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Boolean displayConfirmationDNSA(String message, String caption, String dnsaMessage, boolean cancellable, String key, boolean dnsaDefault) {
    ProfilerDialogs.DNSAConfirmation dnsa = new ProfilerDialogs.DNSAConfirmation(
            key, message, cancellable ? NotifyDescriptor.YES_NO_CANCEL_OPTION : NotifyDescriptor.YES_NO_OPTION);
    if (caption != null) dnsa.setTitle(caption);
    if (dnsaMessage != null) dnsa.setDNSAMessage(dnsaMessage);
    dnsa.setDNSADefault(dnsaDefault);
    Object ret = ProfilerDialogs.notify(dnsa);
    if (ret == NotifyDescriptor.YES_OPTION) return Boolean.TRUE;
    if (ret == NotifyDescriptor.NO_OPTION) return Boolean.FALSE;
    return null;
}
 
Example 15
Source File: LocalTask.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NbBundle.Messages({
    "LBL_LocalTask.copyAttToCentralStorage.title=Copy Attachment",
    "# {0} - number of attachments",
    "MSG_LocalTask.copyAttToCentralStorage.text=You are trying to add {0} attachments to the local task.\n"
            + "The attachments will be kept in their original locations and linked from the task\n\n"
            + "Do you want to copy the files to a central storage to make sure they will be accessible "
            + "even after their original location is deleted?"
})
private boolean askCopyToCentralStorage (int attachmentCount) {
    NotifyDescriptor nd = new NotifyDescriptor.Confirmation(
            Bundle.MSG_LocalTask_copyAttToCentralStorage_text(attachmentCount),
            Bundle.LBL_LocalTask_copyAttToCentralStorage_title(),
            NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.QUESTION_MESSAGE);
    return DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.YES_OPTION;
}
 
Example 16
Source File: TubesProjectConfigPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private boolean confirmDeletion(String className) {
    NotifyDescriptor.Confirmation notifyDesc = new NotifyDescriptor.Confirmation(NbBundle.getMessage(TubesConfigPanel.class, "MSG_CONFIRM_DELETE", className), NbBundle.getMessage(TubesConfigPanel.class, "TTL_CONFIRM_DELETE"), NotifyDescriptor.YES_NO_OPTION);
    DialogDisplayer.getDefault().notify(notifyDesc);
    return notifyDesc.getValue() == NotifyDescriptor.YES_OPTION;
}
 
Example 17
Source File: ProxyClient.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
void connect() {
    while (true) {
        try {
            connectImpl();
            break;
        } catch (SecurityException e) {
            LOGGER.log(Level.INFO, "connect", e);   // NOI18N
            if (hasSSLStubCheck()) {
                Storage storage = app.getStorage();
                String noSSLProp = JmxApplicationProvider.PROPERTY_RETRY_WITHOUT_SSL;
                String noSSL = storage.getCustomProperty(noSSLProp);
                if (noSSL != null && Boolean.parseBoolean(noSSL)) { // NOI18N
                    setInsecure();
                    continue;
                } else {
                    String conn = storage.getCustomProperty(DataSourceDescriptor.PROPERTY_NAME);
                    if (conn == null) conn = storage.getCustomProperty(ApplicationType.PROPERTY_SUGGESTED_NAME);
                    if (conn == null) conn = getUrl().toString();
                    String msg = NbBundle.getMessage(ProxyClient.class, "MSG_Insecure_SSL", conn);  // NOI18N
                    String title = NbBundle.getMessage(ProxyClient.class, "Title_Insecure_SSL");   // NOI18N
                    String retry = NbBundle.getMessage(ProxyClient.class, "Retry_Insecure_SSL");   // NOI18N
                    JLabel l = new JLabel(msg);
                    JCheckBox c = new JCheckBox();
                    Mnemonics.setLocalizedText(c, retry);
                    c.setSelected(noSSL == null);
                    JPanel p = new JPanel(new BorderLayout(0, 20));
                    p.add(l, BorderLayout.CENTER);
                    p.add(c, BorderLayout.SOUTH);
                    NotifyDescriptor dd = new NotifyDescriptor.Confirmation(p, title, NotifyDescriptor.YES_NO_OPTION);
                    if (DialogDisplayer.getDefault().notify(dd) == NotifyDescriptor.YES_OPTION) {
                        storage.setCustomProperty(noSSLProp, Boolean.toString(c.isSelected()));
                        setInsecure();
                        continue;
                    } else {
                        break;
                    }
                }
            }
            if (supplyCredentials() == null) {
                break;
            }
        }
    }
}
 
Example 18
Source File: FormEditorSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean notifyModified () {
    boolean alreadyModified = isModified();
    boolean retVal = super.notifyModified();
    
    if (retVal) { // java source modification
        addSaveCookie();
    }
    
    if (!alreadyModified) {
        FileObject formFile = formDataObject.getFormFile();
        if (!formFile.canWrite()) { // Issue 74092
            FileLock lock = null;
            try {
                lock = formFile.lock();
            } catch (UserQuestionException uqex) {
                NotifyDescriptor nd = new NotifyDescriptor.Confirmation(
                        uqex.getLocalizedMessage(),
                        FormUtils.getBundleString("TITLE_UserQuestion"), // NOI18N
                        NotifyDescriptor.YES_NO_OPTION);
                DialogDisplayer.getDefault().notify(nd);
                if (NotifyDescriptor.YES_OPTION.equals(nd.getValue())) {
                    try {
                        uqex.confirmed();
                        EventQueue.invokeLater(new Runnable() {
                            @Override
                            public void run()  {
                                reloadForm();
                            }
                        });
                    } catch (IOException ioex) {
                        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioex);
                    }
                }
            } catch (IOException ex) {
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
            } finally {
                if (lock != null) {
                    lock.releaseLock();
                }
            }
        }
        updateMVTCDisplayName();
    }
    return retVal;
}
 
Example 19
Source File: TubesConfigPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private boolean confirmDeletion(String className) {
    NotifyDescriptor.Confirmation notifyDesc = new NotifyDescriptor.Confirmation(NbBundle.getMessage(TubesConfigPanel.class, "MSG_CONFIRM_DELETE", className), NbBundle.getMessage(TubesConfigPanel.class, "TTL_CONFIRM_DELETE"), NotifyDescriptor.YES_NO_OPTION);
    DialogDisplayer.getDefault().notify(notifyDesc);
    return notifyDesc.getValue() == NotifyDescriptor.YES_OPTION;
}
 
Example 20
Source File: ProjectDependencyUpgrader.java    From netbeans with Apache License 2.0 3 votes vote down vote up
protected final boolean showDependencyUpgradeDialog(Project p, String dep, SpecificationVersion currentDependency, SpecificationVersion spec, boolean newDepenency, boolean canShowUI) {
    if (!canShowUI) return true;
    
    NotifyDescriptor nd = new NotifyDescriptor.Confirmation("New version: " + spec, "Update spec version.", NotifyDescriptor.YES_NO_OPTION);

    return DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.YES_OPTION;
}