final JButton set = new JButton();
final JButton clear = new JButton();
Mnemonics.setLocalizedText(set, getMessage("changePullPushPath.Set")); //NOI18N
Mnemonics.setLocalizedText(clear, getMessage("changePullPushPath.Clear")); //NOI18N
final GitRepositoryUI repository = new GitRepositoryUI(repoModeMask, title, true);
set.setEnabled(repository.isValid());
clear.setDefaultCapable(false);
final DialogDescriptor dialogDescriptor
= new DialogDescriptor(
GitUtils.addContainerBorder(repository.getPanel()),
title, //title
true, //modal
new Object[] {set,
clear,
CANCEL_OPTION},
set, //default option
DEFAULT_ALIGN, //alignment
new HelpCtx(ClonePathsWizardPanel.class.getName()
+ ".change"), //NOI18N
null); //action listener
dialogDescriptor.setClosingOptions(new Object[] {clear, CANCEL_OPTION});
final NotificationLineSupport notificationLineSupport
= dialogDescriptor.createNotificationLineSupport();
class RepositoryChangeListener implements ChangeListener, ActionListener {
private Dialog dialog;
public void setDialog(Dialog dialog) {
this.dialog = dialog;
}
public void stateChanged(ChangeEvent e) {
assert e.getSource() == repository;
boolean isValid = repository.isValid();
dialogDescriptor.setValid(isValid);
set.setEnabled(isValid);
if (isValid) {
notificationLineSupport.clearMessages();
} else {
String errMsg = repository.getMessage();
if ((errMsg != null) && (errMsg.length() != 0)) {
notificationLineSupport.setErrorMessage(errMsg);
} else {
notificationLineSupport.clearMessages();
}
}
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() != set) {
return;
}
try {
//remember the selected URL:
dialogDescriptor.setValue(repository.getUrl());
/*
* option "set" is not closing so we must handle closing
* of the dialog explictly here:
*/
dialog.setVisible(false);
dialog.dispose();
} catch (MalformedURLException ex) {
repository.setInvalid();
notificationLineSupport.setErrorMessage(ex.getMessage());
} catch (URISyntaxException ex) {
repository.setInvalid();
notificationLineSupport.setErrorMessage(ex.getMessage());
}
}
}
RepositoryChangeListener optionListener = new RepositoryChangeListener();
repository.addChangeListener(optionListener);
dialogDescriptor.setButtonListener(optionListener);
Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
optionListener.setDialog(dialog);