Allow OptionsDisplayer open("tabPath") to work when dialog already open
Description
It would be great, if the OptionsDisplayer would have a close functionality. It can be opened via "OptionsDisplayer.getDefault().open();", but not closed. Could you add a close() method?!
Use case/motivation
Once the Options dialog has been opened, it can not be opened on a different tab programmatically, therefore it would be good to have a close method in order to close the Options dialog and open the Options dialog on another tab via OptionsDisplayer.getDefault().open("myTabPath");.
Related issues
No response
Are you willing to submit a pull request?
Yes
I see no reason why we'd want that, and you've left the use case / motivation section without a response. Please fill that in with information on why you think this should be supported and what your requirements are, otherwise I think this should be closed. Thanks!
Once the Options dialog has been opened, it can not be opened on a different tab programmatically via e.g. OptionsDisplayer.getDefault().open("myTabPath");. I think this is also not correct behavior, because in my application I have got several possibilities to open the Options dialog on different tabs. All do not work correct, when the Options dialog is opened already.
Thanks! I'm not sure programmatic closing is right, or what you're really looking for. Being able to trigger opening of different tabs, in a way that takes into account the possibility of pending changes, sounds like it could be a good enhancement to look into.
Being able to trigger opening of different tabs via e.g. OptionsDisplayer.getDefault().open("myNextTabPath"); while the Options dialog is opened, is really what I am looking for. Can this be implemented by the netbeans team?
Have updated the title to reference this instead. Added Contribution welcome label in case anyone is interested in implementing this - I'm not sure if any current committer is likely to look at implementing this.
Can someone add this code to the OptionsDisplayerImpl?
public void showOptionsDialog (String categoryID, String subpath, CategoryModel categoryInstance) {
log.fine("showOptionsDialog(" + categoryID + ", " + subpath+ ")");
if (isOpen()) {
// Close dialog when already opened.
closeOptionsDialog();
//Open dialog with updated categoryID, subpath, categoryInstance.
showOptionsDialog(categoryID, subpath, categoryInstance);
return;
}
DialogDescriptor descriptor = null;
synchronized(lookupListener) {
descriptor = descriptorRef.get ();
}
OptionsPanel optionsPanel = null;
if (descriptor == null) {
optionsPanel = categoryID == null ? new OptionsPanel (categoryInstance) : new OptionsPanel(categoryID, categoryInstance);
bOK = (JButton) loc(new JButton(), "CTL_OK");//NOI18N
bOK.getAccessibleContext().setAccessibleDescription(loc("ACS_OKButton"));//NOI18N
bAPPLY = (JButton) loc(new JButton(), "CTL_APPLY");//NOI18N
bAPPLY.getAccessibleContext().setAccessibleDescription(loc("ACS_APPLYButton"));//NOI18N
bAPPLY.setEnabled(false);
bClassic = (JButton) loc(new JButton(), "CTL_Classic");//NOI18N
bClassic.getAccessibleContext().setAccessibleDescription(loc("ACS_ClassicButton"));//NOI18N
btnExport = (JButton) loc(new JButton(), "CTL_Export");//NOI18N
btnExport.getAccessibleContext().setAccessibleDescription(loc("ACS_Export"));//NOI18N
btnImport = (JButton) loc(new JButton(), "CTL_Import");//NOI18N
btnImport.getAccessibleContext().setAccessibleDescription(loc("ACS_Import"));//NOI18N
updateButtons();
boolean isMac = Utilities.isMac();
Object[] options = new Object[3];
options[0] = isMac ? DialogDescriptor.CANCEL_OPTION : bOK;
options[1] = bAPPLY;
options[2] = isMac ? bOK : DialogDescriptor.CANCEL_OPTION;
descriptor = new DialogDescriptor(optionsPanel,title,modal,options,DialogDescriptor.OK_OPTION,DialogDescriptor.DEFAULT_ALIGN, null, null, false);
// by-passing EqualFlowLayout manager in NbPresenter
JPanel additionalOptionspanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
additionalOptionspanel.setBorder(new EmptyBorder(0, 0, 0, 0));
additionalOptionspanel.add(bClassic);
additionalOptionspanel.add(btnExport);
additionalOptionspanel.add(btnImport);
setUpButtonListeners(optionsPanel);
descriptor.setAdditionalOptions(new Object[] {additionalOptionspanel});
descriptor.setHelpCtx(optionsPanel.getHelpCtx());
OptionsPanelListener listener = new OptionsPanelListener(descriptor, optionsPanel, bOK, bAPPLY);
descriptor.setClosingOptions(new Object[] { DialogDescriptor.CANCEL_OPTION, bOK });
descriptor.setButtonListener(listener);
optionsPanel.addPropertyChangeListener(listener);
synchronized(lookupListener) {
descriptorRef = new WeakReference<DialogDescriptor>(descriptor);
}
log.fine("Create new Options Dialog"); //NOI18N
} else {
optionsPanel = (OptionsPanel) descriptor.getMessage ();
optionsPanel.setCategoryInstance(categoryInstance);
//TODO:
//just in case that switched from advanced
optionsPanel.update();
log.fine("Reopen Options Dialog"); //NOI18N
}
// #213022 - Trying to diagnose why the NPE occurs. For some reason
// after the dialog is created, with DD.getDefault.createDialog(), it is nulled.
Dialog tmpDialog = DialogDisplayer.getDefault ().createDialog (descriptor, WindowManager.getDefault().getMainWindow());
log.fine("Options Dialog created; descriptor.title = " + descriptor.getTitle() +
"; descriptor.message = " + descriptor.getMessage());
optionsPanel.initCurrentCategory(categoryID, subpath);
tmpDialog.addWindowListener (new MyWindowListener (optionsPanel, tmpDialog));
Point userLocation = getUserLocation(optionsPanel);
if (userLocation != null) {
tmpDialog.setLocation(userLocation);
log.fine("userLocation is set to " + userLocation);
}
log.fine("setting Options Dialog visible");
tmpDialog.setVisible (true);
dialog = tmpDialog;
setUpApplyChecker(optionsPanel);
}
/**
* Close Options Dialog.
*/
public void closeOptionsDialog() {
if (log != null) {
log.fine("Options Dialog - Close dialog."); //NOI18N
}
if (optionsPanel != null) {
optionsPanel.cancel();
}
if (bOK != null) {
bOK.setEnabled(true);
}
if (bAPPLY != null) {
bAPPLY.setEnabled(false);
}
if (isOpen()) { //WORKARROUND for some bug in NbPresenter
if (dialog != null) {
dialog.setVisible(false);
dialog.dispose();
dialog = null;
}
}
}
@itzlewitz you are welcome to open a pull request, where the code can be reviewed properly.
How to open a pull request? I get stuck after clicking New pull request on page "https://github.com/apache/netbeans/pulls".