Java Code Examples for org.openide.NotifyDescriptor#Confirmation
The following examples show how to use
org.openide.NotifyDescriptor#Confirmation .
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: XMLJ2eeEditorSupport.java From netbeans with Apache License 2.0 | 6 votes |
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(XMLJ2eeEditorSupport.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){ Logger.getLogger("global").log(Level.INFO, null, e); } return value; }
Example 2
Source File: NbUtils.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
@Nullable public static MMapURI editURI (@Nullable Component parentComponent, @Nonnull final String title, @Nullable final MMapURI uri) { final UriEditPanel textEditor = new UriEditPanel(uri == null ? null : uri.asString(false, false)); textEditor.doLayout(); textEditor.setPreferredSize(new Dimension(450, textEditor.getPreferredSize().height)); final NotifyDescriptor desc = new NotifyDescriptor.Confirmation(textEditor, title, NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.PLAIN_MESSAGE); if (DialogDisplayer.getDefault().notify(desc) == NotifyDescriptor.OK_OPTION) { final String text = textEditor.getText(); if (text.isEmpty()) { return EMPTY_URI; } try { return new MMapURI(text.trim()); } catch (URISyntaxException ex) { msgError(parentComponent, String.format(java.util.ResourceBundle.getBundle("com/igormaznitsa/nbmindmap/i18n/Bundle").getString("NbUtils.errMsgIllegalURI"), text)); return null; } } else { return null; } }
Example 3
Source File: FileUtils.java From netbeans with Apache License 2.0 | 6 votes |
/** * Save a file. * @param dataObject file to be saved * @since 2.54 */ public static void saveFile(@NonNull DataObject dataObject) { Parameters.notNull("dataObject", dataObject); // NOI18N SaveCookie saveCookie = dataObject.getLookup().lookup(SaveCookie.class); if (saveCookie != null) { try { try { saveCookie.save(); } catch (UserQuestionException uqe) { // #216194 NotifyDescriptor.Confirmation desc = new NotifyDescriptor.Confirmation(uqe.getLocalizedMessage(), NotifyDescriptor.Confirmation.OK_CANCEL_OPTION); if (DialogDisplayer.getDefault().notify(desc).equals(NotifyDescriptor.OK_OPTION)) { uqe.confirmed(); saveCookie.save(); } } } catch (IOException ioe) { LOGGER.log(Level.WARNING, ioe.getLocalizedMessage(), ioe); } } }
Example 4
Source File: SceneComposerTopComponent.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private boolean checkSaved() { if (editorController != null && editorController.isNeedSave()) { Confirmation msg = new NotifyDescriptor.Confirmation( "Your Scene is not saved, do you want to save?", NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE); Object result = DialogDisplayer.getDefault().notify(msg); if (NotifyDescriptor.CANCEL_OPTION.equals(result)) { return false; } else if (NotifyDescriptor.YES_OPTION.equals(result)) { editorController.saveScene(); return true; } else if (NotifyDescriptor.NO_OPTION.equals(result)) { return true; } } return true; }
Example 5
Source File: IncomingSmsAction.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
@Override protected void performAction(Node[] activatedNodes) { EmulatorControlSupport emulatorControl = activatedNodes[0].getLookup().lookup(EmulatorControlSupport.class); if (emulatorControl != null) { SmsPanel smsPanel = new SmsPanel(); NotifyDescriptor nd = new NotifyDescriptor.Confirmation(smsPanel, "Incoming SMS", NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.QUESTION_MESSAGE); Object notify = DialogDisplayer.getDefault().notify(nd); if (NotifyDescriptor.OK_OPTION.equals(notify)) { String ok = emulatorControl.getConsole().sendSms(smsPanel.getPhoneNumber(), smsPanel.getText().replace("\\", "\\\\").replace("\n", "\n")); if (ok != null) { NotifyDescriptor nd1 = new NotifyDescriptor.Message(ok, NotifyDescriptor.ERROR_MESSAGE); DialogDisplayer.getDefault().notifyLater(nd1); } } } }
Example 6
Source File: DeleteLocalAction.java From netbeans with Apache License 2.0 | 6 votes |
protected void performContextAction(final Node[] nodes) { NotifyDescriptor descriptor = new NotifyDescriptor.Confirmation(NbBundle.getMessage(DeleteLocalAction.class, "CTL_DeleteLocal_Prompt")); // NOI18N descriptor.setTitle(NbBundle.getMessage(DeleteLocalAction.class, "CTL_DeleteLocal_Title")); // NOI18N descriptor.setMessageType(JOptionPane.WARNING_MESSAGE); descriptor.setOptionType(NotifyDescriptor.YES_NO_OPTION); Object res = DialogDisplayer.getDefault().notify(descriptor); if (res != NotifyDescriptor.YES_OPTION) { return; } final Context ctx = getContext(nodes); ProgressSupport support = new ContextAction.ProgressSupport(this, nodes, ctx) { public void perform() { performDelete(ctx, this); } }; support.start(createRequestProcessor(ctx)); }
Example 7
Source File: ConvertModel.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public void actionPerformed(ActionEvent ev) { Runnable run = new Runnable() { public void run() { ProgressHandle progressHandle = ProgressHandleFactory.createHandle("Converting Model"); progressHandle.start(); for (SpatialAssetDataObject spatialAssetDataObject : context) { if (!(spatialAssetDataObject instanceof BinaryModelDataObject)) { try { spatialAssetDataObject.loadAsset(); spatialAssetDataObject.saveAsset(); } catch (Exception ex) { Exceptions.printStackTrace(ex); Confirmation msg = new NotifyDescriptor.Confirmation( "Error converting " + spatialAssetDataObject.getName() + "\n" + ex.toString(), NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.ERROR_MESSAGE); DialogDisplayer.getDefault().notifyLater(msg); } } } progressHandle.finish(); } }; new Thread(run).start(); }
Example 8
Source File: RegisterDerby.java From netbeans with Apache License 2.0 | 5 votes |
private boolean waitStart(final ExecSupport execSupport, int waitTime) { boolean started = false; final boolean[] forceExit = new boolean[1]; String waitMessage = NbBundle.getMessage(RegisterDerby.class, "MSG_StartingDerby"); ProgressHandle progress = ProgressHandleFactory.createHandle(waitMessage, new Cancellable() { @Override public boolean cancel() { forceExit[0] = true; return execSupport.interruptWaiting(); } }); progress.start(); try { while (!started) { started = execSupport.waitForMessage(waitTime * 1000); if (!started) { if (waitTime > 0 && (!forceExit[0])) { String title = NbBundle.getMessage(RegisterDerby.class, "LBL_DerbyDatabase"); String message = NbBundle.getMessage(RegisterDerby.class, "MSG_WaitStart", waitTime); NotifyDescriptor waitConfirmation = new NotifyDescriptor.Confirmation(message, title, NotifyDescriptor.YES_NO_OPTION); if (DialogDisplayer.getDefault().notify(waitConfirmation) != NotifyDescriptor.YES_OPTION) { break; } } else { break; } } } if (!started) { execSupport.terminate(); LOGGER.log(Level.WARNING, "Derby server failed to start"); // NOI18N } } finally { progress.finish(); } return started; }
Example 9
Source File: BrokenPlatformCustomizer.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
private void downloadSdkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downloadSdkActionPerformed PanelDownloadToBrokenSDK panelDownloadToBrokenSDK = new PanelDownloadToBrokenSDK(platform); NotifyDescriptor nd = new NotifyDescriptor.Confirmation(panelDownloadToBrokenSDK, "Install Android SDK to broken folder", NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.QUESTION_MESSAGE); Object notify = DialogDisplayer.getDefault().notify(nd); if (NotifyDescriptor.OK_OPTION.equals(notify)) { platform.setSdkRootFolder(platform.getSdkPath()); listener.sdkValid(); } }
Example 10
Source File: Utils.java From netbeans with Apache License 2.0 | 5 votes |
public static boolean displayYesNoDialog(String message) { NotifyDescriptor ndesc = new NotifyDescriptor.Confirmation( message, NotifyDescriptor.YES_NO_OPTION); Object result = DialogDisplayer.getDefault().notify(ndesc); return ( result == NotifyDescriptor.YES_OPTION ); }
Example 11
Source File: SimpleIO.java From netbeans with Apache License 2.0 | 5 votes |
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("payara").log(Level.FINEST, "Process handle unexpectedly null, cancel aborted."); // NOI18N } } } }
Example 12
Source File: FilterTopComponent.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public void addFilterSetting() { NotifyDescriptor.InputLine l = new NotifyDescriptor.InputLine("Enter a name:", "Filter"); if (DialogDisplayer.getDefault().notify(l) == NotifyDescriptor.OK_OPTION) { String name = l.getInputText(); FilterSetting toRemove = null; for (FilterSetting s : filterSettings) { if (s.getName().equals(name)) { NotifyDescriptor.Confirmation conf = new NotifyDescriptor.Confirmation("Filter \"" + name + "\" already exists, to you want to overwrite?", "Filter"); if (DialogDisplayer.getDefault().notify(conf) == NotifyDescriptor.YES_OPTION) { toRemove = s; break; } else { return; } } } if (toRemove != null) { filterSettings.remove(toRemove); } FilterSetting setting = createFilterSetting(name); filterSettings.add(setting); // Sort alphabetically Collections.sort(filterSettings, new Comparator<FilterSetting>() { public int compare(FilterSetting o1, FilterSetting o2) { return o1.getName().compareTo(o2.getName()); } }); updateComboBox(); } }
Example 13
Source File: FilterTopComponent.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void addFilterSetting() { NotifyDescriptor.InputLine l = new NotifyDescriptor.InputLine("Enter a name:", "Filter"); if (DialogDisplayer.getDefault().notify(l) == NotifyDescriptor.OK_OPTION) { String name = l.getInputText(); FilterSetting toRemove = null; for (FilterSetting s : filterSettings) { if (s.getName().equals(name)) { NotifyDescriptor.Confirmation conf = new NotifyDescriptor.Confirmation("Filter \"" + name + "\" already exists, to you want to overwrite?", "Filter"); if (DialogDisplayer.getDefault().notify(conf) == NotifyDescriptor.YES_OPTION) { toRemove = s; break; } else { return; } } } if (toRemove != null) { filterSettings.remove(toRemove); } FilterSetting setting = createFilterSetting(name); filterSettings.add(setting); // Sort alphabetically Collections.sort(filterSettings, new Comparator<FilterSetting>() { public int compare(FilterSetting o1, FilterSetting o2) { return o1.getName().compareTo(o2.getName()); } }); updateComboBox(); } }
Example 14
Source File: ProfilerDialogsProviderImpl.java From visualvm with GNU General Public License v2.0 | 5 votes |
@Override public Boolean displayConfirmation(String message, String caption, boolean cancellable) { NotifyDescriptor nd = new NotifyDescriptor.Confirmation(message, cancellable ? NotifyDescriptor.YES_NO_CANCEL_OPTION : NotifyDescriptor.YES_NO_OPTION); if (caption != null) nd.setTitle(caption); Object ret = DialogDisplayer.getDefault().notify(nd); if (ret == NotifyDescriptor.YES_OPTION) return Boolean.TRUE; if (ret == NotifyDescriptor.NO_OPTION) return Boolean.FALSE; return null; }
Example 15
Source File: AbstractOutputPane.java From netbeans with Apache License 2.0 | 5 votes |
@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 16
Source File: ExternalBindingTablePanel.java From netbeans with Apache License 2.0 | 5 votes |
private boolean confirmDeletion(String fileName) { NotifyDescriptor.Confirmation notifyDesc = new NotifyDescriptor.Confirmation(NbBundle.getMessage (ExternalBindingTablePanel.class, "MSG_CONFIRM_DELETE", fileName), NotifyDescriptor.YES_NO_OPTION); DialogDisplayer.getDefault().notify(notifyDesc); return (notifyDesc.getValue() == NotifyDescriptor.YES_OPTION); }
Example 17
Source File: VersioningMainMenu.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void actionPerformed (ActionEvent e) { NotifyDescriptor nd = new NotifyDescriptor.Confirmation( NbBundle.getMessage(VersioningMainMenu.class, "MSG_ConnectAction.confirmation.text", new Object[] { root.getName(), vs.getDisplayName() }), //NOI18N NbBundle.getMessage(VersioningMainMenu.class, "LBL_ConnectAction.confirmation.title"), //NOI18N NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.QUESTION_MESSAGE); if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.OK_OPTION) { VersioningConfig.getDefault().disconnectRepository(vs, root); VersioningManager.getInstance().versionedRootsChanged(); } }
Example 18
Source File: TplEditorSupport.java From netbeans with Apache License 2.0 | 4 votes |
@NbBundle.Messages({ "warning=Warning", "# {0} document name", "# {1} encoding", "# {2} original encoding of the file when loaded", "MSG_unsupportedEncodingSave=<html>The encoding {1} specified in meta tag of the document {0} is invalid<br> or the document contains characters which cannot be saved using this encoding.<br> Do you want to save the file using <b>{2}</b> encoding?</html>" }) void updateEncoding() throws UserCancelException { //try to find encoding specification in the editor content String documentContent = getDocumentText(); String encoding = TplDataObject.findEncoding(documentContent); String feqEncoding = FileEncodingQuery.getEncoding(getDataObject().getPrimaryFile()).name(); String finalEncoding = null; if (encoding != null) { //found encoding specified in the file content by meta tag if (!isSupportedEncoding(encoding) || !canEncode(documentContent, encoding)) { //test if the file can be saved by the original encoding or if it needs to be saved using utf-8 finalEncoding = canEncode(documentContent, feqEncoding) ? feqEncoding : UTF_8_ENCODING; Integer showEncodingWarnings = getTplDO().getShowEncodingWarnings(); if (showEncodingWarnings == null) { String message = MSG_unsupportedEncodingSave(getDataObject().getPrimaryFile().getNameExt(), encoding, finalEncoding); SaveConfirmationPanel panel = new SaveConfirmationPanel(message); DialogDescriptor dd = new DialogDescriptor(panel, Bundle.warning(), true, DialogDescriptor.YES_NO_OPTION, DialogDescriptor.YES_OPTION, null); DialogDisplayer.getDefault().notify(dd); showEncodingWarnings = (Integer) dd.getValue(); if (panel.isDoNotShowAgainCheckBox() && showEncodingWarnings == NotifyDescriptor.YES_OPTION) { getTplDO().setShowEncodingWarnings(showEncodingWarnings); } } if (!showEncodingWarnings.equals(NotifyDescriptor.YES_OPTION)) { throw new UserCancelException(); } } else { finalEncoding = encoding; } } else { //no encoding specified in the file, use FEQ value if (!canEncode(documentContent, feqEncoding)) { NotifyDescriptor nd = new NotifyDescriptor.Confirmation(NbBundle.getMessage(TplEditorSupport.class, "MSG_badCharConversionSave", new Object[]{getDataObject().getPrimaryFile().getNameExt(), feqEncoding}), NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE); nd.setValue(NotifyDescriptor.NO_OPTION); DialogDisplayer.getDefault().notify(nd); if (nd.getValue() != NotifyDescriptor.YES_OPTION) { throw new UserCancelException(); } else { finalEncoding = UTF_8_ENCODING; } } else { finalEncoding = feqEncoding; } } //FEQ cannot be run in saveFromKitToStream since document is locked for writing, //so setting the FEQ result to document property Document document = getDocument(); if (document != null) { document.putProperty(DOCUMENT_SAVE_ENCODING, finalEncoding); } }
Example 19
Source File: XmlMultiViewEditorSupport.java From netbeans with Apache License 2.0 | 4 votes |
private void doSaveDocument() throws IOException { // code below is basically a copy-paste from XmlJ2eeEditorSupport final StyledDocument doc = getDocument(); // dependency on xml/core String enc = EncodingUtil.detectEncoding(doc); if (enc == null) enc = "UTF8"; //!!! // NOI18N try { //test encoding on dummy stream new OutputStreamWriter(new ByteArrayOutputStream(1), enc); if (!checkCharsetConversion(enc)) { return; } super.saveDocument(); //moved from Env.save() // DataObject.setModified() already called as part of super.saveDocument(). The save action is now asynchronous // in the IDE and super.saveDocument() checks for possible extra document modifications performed during save // and sets the DO.modified flag accordingly. // getDataObject().setModified(false); } catch (UnsupportedEncodingException ex) { // ask user what next? String message = NbBundle.getMessage(XmlMultiViewEditorSupport.class,"TEXT_SAVE_AS_UTF", enc); NotifyDescriptor descriptor = new NotifyDescriptor.Confirmation(message); Object res = DialogDisplayer.getDefault().notify(descriptor); if (res.equals(NotifyDescriptor.YES_OPTION)) { // update prolog to new valid encoding try { final int MAX_PROLOG = 1000; int maxPrologLen = Math.min(MAX_PROLOG, doc.getLength()); final char prolog[] = doc.getText(0, maxPrologLen).toCharArray(); int prologLen = 0; // actual prolog length //parse prolog and get prolog end if (prolog[0] == '<' && prolog[1] == '?' && prolog[2] == 'x') { // look for delimitting ?> for (int i = 3; i<maxPrologLen; i++) { if (prolog[i] == '?' && prolog[i+1] == '>') { prologLen = i + 1; break; } } } final int passPrologLen = prologLen; Runnable edit = new Runnable() { public void run() { try { doc.remove(0, passPrologLen + 1); // +1 it removes exclusive doc.insertString(0, "<?xml version='1.0' encoding='UTF-8' ?> \n<!-- was: " + new String(prolog, 0, passPrologLen + 1) + " -->", null); // NOI18N } catch (BadLocationException e) { if (System.getProperty("netbeans.debug.exceptions") != null) // NOI18N e.printStackTrace(); } } }; NbDocument.runAtomic(doc, edit); super.saveDocument(); //moved from Env.save() // DataObject.setModified() already called as part of super.saveDocument(). The save action is now asynchronous // in the IDE and super.saveDocument() checks for possible extra document modifications performed during save // and sets the DO.modified flag accordingly. // getDataObject().setModified(false); // need to force reloading ((XmlMultiViewDataObject) getDataObject()).getDataCache().reloadData(); } catch (BadLocationException lex) { ErrorManager.getDefault().notify(lex); } } else { // NotifyDescriptor != YES_OPTION return; } } }
Example 20
Source File: NbUtils.java From netbeans-mmd-plugin with Apache License 2.0 | 4 votes |
public static boolean msgConfirmYesNo (@Nullable Component parentComponent,@Nonnull final String title, @Nonnull final String query) { final NotifyDescriptor desc = new NotifyDescriptor.Confirmation(query, title, NotifyDescriptor.YES_NO_OPTION); final Object obj = DialogDisplayer.getDefault().notify(desc); return NotifyDescriptor.YES_OPTION.equals(obj); }