Java Code Examples for org.openide.NotifyDescriptor#YES_NO_CANCEL_OPTION

The following examples show how to use org.openide.NotifyDescriptor#YES_NO_CANCEL_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: ImportStep.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the target folder already exists in the repository.
 * If it does exist, user will be asked to confirm the import into the existing folder.
 * @param client
 * @param repositoryFileUrl
 * @return true if the target does not exist or user wishes to import anyway.
 */
private boolean importIntoExisting(SvnClient client, SVNUrl repositoryFileUrl) {
    try {
        ISVNInfo info = client.getInfo(repositoryFileUrl);
        if (info != null) {
            // target folder exists, ask user for confirmation
            final boolean flags[] = {true};
            NotifyDescriptor nd = new NotifyDescriptor(NbBundle.getMessage(ImportStep.class, "MSG_ImportIntoExisting", SvnUtils.decodeToString(repositoryFileUrl)), //NOI18N
                    NbBundle.getMessage(ImportStep.class, "CTL_TargetFolderExists"), NotifyDescriptor.YES_NO_CANCEL_OPTION, //NOI18N
                    NotifyDescriptor.QUESTION_MESSAGE, null, NotifyDescriptor.YES_OPTION);
            if (DialogDisplayer.getDefault().notify(nd) != NotifyDescriptor.YES_OPTION) {
                flags[0] = false;
            }
            return flags[0];
        }
    } catch (SVNClientException ex) {
        // ignore
    }
    return true;
}
 
Example 2
Source File: QueryController.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NbBundle.Messages({"MSG_Changed=The query was changed and has to be saved before refresh.",
                    "LBL_Save=Save",
                    "LBL_Discard=Discard"})
public void onRefresh() {
    if(query.isSaved() && isChanged()) {
        NotifyDescriptor desc = new NotifyDescriptor.Confirmation(
            Bundle.MSG_Changed(), NotifyDescriptor.YES_NO_CANCEL_OPTION
        );
        Object[] choose = { Bundle.LBL_Save(), Bundle.LBL_Discard(), NotifyDescriptor.CANCEL_OPTION };
        desc.setOptions(choose);
        Object ret = DialogDisplayer.getDefault().notify(desc);
        if(ret == choose[0]) {
            saveQuery(); // persist the parameters
        } else if (ret == choose[1]) {
            onCancelChanges();
            return;
        } else {
            return;
        }
    }
    refresh(false, false);
}
 
Example 3
Source File: MotionsDB.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
private boolean confirmCloseMotion(Model model, Storage simmMotionData, boolean allowCancel) {
   int dialogType = NotifyDescriptor.YES_NO_OPTION;
   if (allowCancel)
      dialogType = NotifyDescriptor.YES_NO_CANCEL_OPTION;
   NotifyDescriptor dlg = new NotifyDescriptor.Confirmation("Do you want to save the changes to motion '" + simmMotionData.getName() + "'?",
           "Save Modified Motion?", dialogType);
   Object userSelection = DialogDisplayer.getDefault().notify(dlg);
   if (((Integer)userSelection).intValue() == ((Integer)NotifyDescriptor.OK_OPTION).intValue()) {
      String fileName = FileUtils.getInstance().browseForFilenameToSave(FileUtils.MotionFileFilter, true, "");
      if (fileName != null) {
         MotionsSaveAsAction.saveMotion((model), simmMotionData, fileName);
         saveStorageFileName(simmMotionData, fileName);
         return true;
      } else {
         // The user cancelled out of saving the file, which we interpret as wanting to cancel
         // the closing of the motion. But if allowCancel == false then we have to return true
         // so the close is not cancelled.
         return !allowCancel;
      }
   } else if (((Integer)userSelection).intValue() == ((Integer)NotifyDescriptor.NO_OPTION).intValue()) {
      return true;
   }
   return false;
}
 
Example 4
Source File: VisualGraphTopComponent.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canClose() {
    if (savable.isModified()) {
        final String message = String.format("Graph %s is modified. Save?", getDisplayName());
        final Object[] options = new Object[]{
            SAVE, DISCARD, CANCEL
        };
        final NotifyDescriptor d = new NotifyDescriptor(message, "Close", NotifyDescriptor.YES_NO_CANCEL_OPTION, NotifyDescriptor.QUESTION_MESSAGE, options, "Save");
        final Object o = DialogDisplayer.getDefault().notify(d);

        if (o.equals(DISCARD)) {
            savable.setModified(false);
        } else if (o.equals(SAVE)){
            try {
                savable.handleSave();
                if (!savable.isSaved()){
                    return false;
                }
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
        } else {
            return false;
        }
    }

    return true;
}
 
Example 5
Source File: CloneableEditorSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** @return 0 => cannot close, -1 can close and do not save, 1 can close and save */
private int canCloseImpl() {
	String msg = messageSave();

	ResourceBundle bundle = NbBundle.getBundle(CloneableEditorSupport.class);

	JButton saveOption = new JButton(bundle.getString("CTL_Save")); // NOI18N
	saveOption.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CTL_Save")); // NOI18N
	saveOption.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_CTL_Save")); // NOI18N

	JButton discardOption = new JButton(bundle.getString("CTL_Discard")); // NOI18N
	discardOption.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CTL_Discard")); // NOI18N
	discardOption.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_CTL_Discard")); // NOI18N
	discardOption.setMnemonic(bundle.getString("CTL_Discard_Mnemonic").charAt(0)); // NOI18N

	NotifyDescriptor nd = new NotifyDescriptor(
			msg, bundle.getString("LBL_SaveFile_Title"), NotifyDescriptor.YES_NO_CANCEL_OPTION,
			NotifyDescriptor.QUESTION_MESSAGE,
			new Object[] { saveOption, discardOption, NotifyDescriptor.CANCEL_OPTION }, saveOption
		);

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

	if (NotifyDescriptor.CANCEL_OPTION.equals(ret) || NotifyDescriptor.CLOSED_OPTION.equals(ret)) {
		return 0;
	}

	if (saveOption.equals(ret)) {
		return 1;
	} else {
		return -1;
	}
}
 
Example 6
Source File: ProfilerDialogsProviderImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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 7
Source File: ProfilerDialogsProviderImpl.java    From netbeans with Apache License 2.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 8
Source File: PanelSourceFolders.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void searchClassFiles(File[] folders) throws WizardValidationException {
    List<File> classFiles = new ArrayList<File>();
    for (File folder : folders) {
        findClassFiles(folder, classFiles);
    }
    if (!classFiles.isEmpty()) {
        JButton DELETE_OPTION = new JButton(NbBundle.getMessage(PanelSourceFolders.class, "TXT_DeleteOption")); // NOI18N
        JButton KEEP_OPTION = new JButton(NbBundle.getMessage(PanelSourceFolders.class, "TXT_KeepOption")); // NOI18N
        JButton CANCEL_OPTION = new JButton(NbBundle.getMessage(PanelSourceFolders.class, "TXT_CancelOption")); // NOI18N
        KEEP_OPTION.setMnemonic(NbBundle.getMessage(PanelSourceFolders.class, "MNE_KeepOption").charAt(0)); // NOI18N
        DELETE_OPTION.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PanelSourceFolders.class, "AD_DeleteOption")); // NOI18N
        KEEP_OPTION.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PanelSourceFolders.class, "AD_KeepOption")); // NOI18N
        CANCEL_OPTION.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PanelSourceFolders.class, "AD_CancelOption")); // NOI18N
        NotifyDescriptor desc = new NotifyDescriptor(
                NbBundle.getMessage(PanelSourceFolders.class, "MSG_FoundClassFiles"), // NOI18N
                NbBundle.getMessage(PanelSourceFolders.class, "MSG_FoundClassFiles_Title"), // NOI18N
                NotifyDescriptor.YES_NO_CANCEL_OPTION,
                NotifyDescriptor.QUESTION_MESSAGE,
                new Object[]{DELETE_OPTION, KEEP_OPTION, CANCEL_OPTION},
                DELETE_OPTION);
        Object result = DialogDisplayer.getDefault().notify(desc);
        if (DELETE_OPTION.equals(result)) {
            for (File f : classFiles) {
                f.delete(); // ignore if fails
            }
        } else if (!KEEP_OPTION.equals(result)) {
            // cancel, back to wizard
            throw new WizardValidationException(this.sourcePanel, "", ""); // NOI18N
        }
    }
}
 
Example 9
Source File: StopManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean displayServerRunning() {
    JButton cancelButton = new JButton();
    Mnemonics.setLocalizedText(cancelButton, NbBundle.getMessage(StopManager.class, "StopManager.CancelButton")); // NOI18N
    cancelButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(StopManager.class, "StopManager.CancelButtonA11yDesc")); //NOI18N

    JButton keepWaitingButton = new JButton();
    Mnemonics.setLocalizedText(keepWaitingButton, NbBundle.getMessage(StopManager.class, "StopManager.KeepWaitingButton")); // NOI18N
    keepWaitingButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(StopManager.class, "StopManager.KeepWaitingButtonA11yDesc")); //NOI18N

    JButton propsButton = new JButton();
    Mnemonics.setLocalizedText(propsButton, NbBundle.getMessage(StopManager.class, "StopManager.PropsButton")); // NOI18N
    propsButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(StopManager.class, "StopManager.PropsButtonA11yDesc")); //NOI18N

    String message = NbBundle.getMessage(StopManager.class, "MSG_ServerStillRunning");
    final NotifyDescriptor ndesc = new NotifyDescriptor(message,
            NbBundle.getMessage(StopManager.class, "StopManager.ServerStillRunningTitle"),
            NotifyDescriptor.YES_NO_CANCEL_OPTION,
            NotifyDescriptor.QUESTION_MESSAGE,
            new Object[] {keepWaitingButton, propsButton, cancelButton},
            NotifyDescriptor.CANCEL_OPTION); //NOI18N

    Object ret = Mutex.EVENT.readAccess(new Action<Object>() {
        @Override
        public Object run() {
            return DialogDisplayer.getDefault().notify(ndesc);
        }

    });

    if (cancelButton.equals(ret)) {
        stopRequested.set(false);
        return false;
    } else if (keepWaitingButton.equals(ret)) {
        return true;
    } else {
        displayAdminProperties(server);
        return false;
    }
}
 
Example 10
Source File: XmlMultiViewDataObject.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Object showChangeEncodingDialog(String encoding) {
    String message = NbBundle.getMessage(Utils.class, "TEXT_CHANGE_DECLARED_ENCODING", encoding,
            encodingHelper.getEncoding());
    NotifyDescriptor descriptor = new NotifyDescriptor.Confirmation(message, getPrimaryFile().getPath(),
            NotifyDescriptor.YES_NO_CANCEL_OPTION);
    return DialogDisplayer.getDefault().notify(descriptor);
}
 
Example 11
Source File: ProfilerDialogsProviderImpl.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
@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 12
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 13
Source File: NbUtils.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Boolean msgConfirmYesNoCancel (@Nullable Component parentComponent,@Nonnull final String title, @Nonnull final String query) {
  final NotifyDescriptor desc = new NotifyDescriptor.Confirmation(query, title, NotifyDescriptor.YES_NO_CANCEL_OPTION);
  final Object obj = DialogDisplayer.getDefault().notify(desc);
  if (NotifyDescriptor.CANCEL_OPTION.equals(obj)) {
    return null;
  }
  return NotifyDescriptor.YES_OPTION.equals(obj);
}
 
Example 14
Source File: XmlMultiViewEditorSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public boolean resolveCloseOperation(CloseOperationState[] elements) {
    for (int i = 0; i < elements.length; i++) {
        CloseOperationState element = elements[i];
        if (ToolBarDesignEditor.PROPERTY_FLUSH_DATA.equals(element.getCloseWarningID())) {
            return false;
        }
    }
    if (dObj.isModified()) {
        XmlMultiViewEditorSupport support = dObj.getEditorSupport();
        String msg = support.messageSave();
        
        java.util.ResourceBundle bundle =
                org.openide.util.NbBundle.getBundle(org.openide.text.CloneableEditorSupport.class);
        
        javax.swing.JButton saveOption = new javax.swing.JButton(bundle.getString("CTL_Save")); // NOI18N
        saveOption.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CTL_Save")); // NOI18N
        saveOption.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_CTL_Save")); // NOI18N
        javax.swing.JButton discardOption = new javax.swing.JButton(bundle.getString("CTL_Discard")); // NOI18N
        discardOption.getAccessibleContext()
        .setAccessibleDescription(bundle.getString("ACSD_CTL_Discard")); // NOI18N
        discardOption.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_CTL_Discard")); // NOI18N
        discardOption.setMnemonic(bundle.getString("CTL_Discard_Mnemonic").charAt(0)); // NOI18N
        
        NotifyDescriptor nd = new NotifyDescriptor(
                msg,
                bundle.getString("LBL_SaveFile_Title"),
                NotifyDescriptor.YES_NO_CANCEL_OPTION,
                NotifyDescriptor.QUESTION_MESSAGE,
                new Object[]{saveOption, discardOption, NotifyDescriptor.CANCEL_OPTION},
                saveOption
                );
        
        Object ret = org.openide.DialogDisplayer.getDefault().notify(nd);
        
        if (NotifyDescriptor.CANCEL_OPTION.equals(ret) || NotifyDescriptor.CLOSED_OPTION.equals(ret)) {
            return false;
        }
        
        if (saveOption.equals(ret)) {
            try {
                if (dObj.acceptEncoding() && dObj.verifyDocumentBeforeClose() ) {
                    dObj.getEditorSupport().onCloseSave();
                } else {
                    return false;
                }
            } catch (java.io.IOException e) {
                org.openide.ErrorManager.getDefault().notify(e);
                return false;
            }
        } else if (discardOption.equals(ret)) {
            dObj.getEditorSupport().onCloseDiscard();
        }
    }
    return true;
}