@Override
 public void profileSelectionChanged(final Optional<MutableProfile> profile) {
   okButton.setEnabled(model.isSaveAllowed());
   deleteProfile.setEnabled(model.getSelectedProfile().isPresent());
   if (profile.isPresent()) {
     final int index = profilesModel.indexOf(profile.get());
     selectionModel.setLeadSelectionIndex(index);
   } else {
     selectionModel.setLeadSelectionIndex(-1);
   }
   addNickname.setEnabled(model.getSelectedProfile().isPresent());
   editNickname.setEnabled(model.getSelectedProfile().isPresent());
   addHighlight.setEnabled(model.getSelectedProfile().isPresent());
   editHighlight.setEnabled(model.getSelectedProfile().isPresent());
   name.setEnabled(model.getSelectedProfile().isPresent());
   name.setText(model.getSelectedProfileName().orElse(""));
   nicknames.setEnabled(model.getSelectedProfile().isPresent());
   nicknamesModel.clear();
   nicknamesModel.addAll(model.getSelectedProfileNicknames().orElse(Lists.newArrayList()));
   highlights.setEnabled(model.getSelectedProfile().isPresent());
   highlightsModel.clear();
   highlightsModel.addAll(model.getSelectedProfileHighlights().orElse(Lists.newArrayList()));
   realname.setEnabled(model.getSelectedProfile().isPresent());
   realname.setText(model.getSelectedProfileRealname().orElse(""));
   ident.setEnabled(model.getSelectedProfile().isPresent());
   ident.setText(model.getSelectedProfileIdent().orElse(""));
 }
 @Override
 public void selectedProfileNicknameEdited(final String oldNickname, final String newNickname) {
   okButton.setEnabled(model.isSaveAllowed());
   nicknamesModel.set(nicknamesModel.indexOf(oldNickname), newNickname);
   addNickname.setEnabled(model.isSelectedProfileNicknamesValid());
   editNickname.setEnabled(model.isSelectedProfileNicknamesValid());
 }
 @Override
 public void selectedProfileHighlightEdited(final String oldHighlight, final String newHighlight) {
   okButton.setEnabled(model.isSaveAllowed());
   highlightsModel.set(highlightsModel.indexOf(oldHighlight), newHighlight);
   deleteHighlight.setEnabled(model.isSelectedProfileHighlightsValid());
   editHighlight.setEnabled(model.isSelectedProfileHighlightsValid());
 }
 private void setupProfileName(final JTextField name) {
   name.setEnabled(model.getSelectedProfileName().isPresent());
   name.setText(model.getSelectedProfileName().orElse(""));
   name.getDocument()
       .addDocumentListener(
           new ConsumerDocumentListener(s -> model.setSelectedProfileName(Optional.of(s))));
 }
 @Override
 public void selectedProfileHighlightAdded(final String highlight) {
   okButton.setEnabled(model.isSaveAllowed());
   highlightsModel.add(highlight);
   deleteHighlight.setEnabled(model.isSelectedProfileHighlightsValid());
   editHighlight.setEnabled(model.isSelectedProfileHighlightsValid());
 }
 @Override
 public void profileRemoved(final MutableProfile profile) {
   addNickname.setEnabled(model.isProfileListValid());
   addHighlight.setEnabled(model.isProfileListValid());
   okButton.setEnabled(model.isSaveAllowed());
   profilesModel.remove(profile);
 }
 private void setupDeleteNickname(final JButton deleteNickname) {
   deleteNickname.setEnabled(model.getSelectedProfileSelectedNickname().isPresent());
   deleteNickname.addActionListener(
       l ->
           model
               .getSelectedProfileSelectedNickname()
               .ifPresent(model::removeSelectedProfileNickname));
 }
 private void setupOKButton(final JButton okButton) {
   okButton.setEnabled(model.isSaveAllowed());
   okButton.addActionListener(
       l -> {
         model.save();
         dialog.dispose();
       });
 }
 private void setupDeleteHighlight(final JButton deleteHighlight) {
   deleteHighlight.setEnabled(model.getSelectedProfileSelectedHighlight().isPresent());
   deleteHighlight.addActionListener(
       l ->
           model
               .getSelectedProfileSelectedHighlight()
               .ifPresent(model::removeSelectedProfileHighlight));
 }
 private void setupProfileNicknames(final ReorderableJList<String> nicknames) {
   nicknamesModel = nicknames.getModel();
   nicknamesModel.addAll(model.getSelectedProfileNicknames().orElse(Lists.newArrayList()));
   nicknames.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   nicknames.setEnabled(model.getSelectedProfileNicknames().isPresent());
   nicknames.addListSelectionListener(
       l ->
           model.setSelectedProfileSelectedNickname(
               Optional.ofNullable(nicknames.getSelectedValue())));
 }
 private void setupProfileHighlights(final ReorderableJList<String> highlights) {
   highlightsModel = highlights.getModel();
   highlightsModel.addAll(model.getSelectedProfileHighlights().orElse(Lists.newArrayList()));
   highlights.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   highlights.setEnabled(model.getSelectedProfileHighlights().isPresent());
   highlights.addListSelectionListener(
       l ->
           model.setSelectedProfileSelectedHighlight(
               Optional.ofNullable(highlights.getSelectedValue())));
 }
 private void setupProfileIdent(final JTextField ident) {
   ident.setEnabled(model.getSelectedProfileIdent().isPresent());
   ident.setText(model.getSelectedProfileIdent().orElse(""));
   ident
       .getDocument()
       .addDocumentListener(
           new ConsumerDocumentListener(
               s -> {
                 if (model.getSelectedProfile().isPresent()) {
                   model.setSelectedProfileIdent(Optional.of(s));
                 }
               }));
 }
 private void setupAddHighlight(final JButton addHighlight) {
   addHighlight.setEnabled(!model.getProfileList().isEmpty());
   addHighlight.addActionListener(
       e ->
           new StandardInputDialog(
                   dialog,
                   Dialog.ModalityType.DOCUMENT_MODAL,
                   iconManager,
                   "Profile Manager: Add Highlight",
                   "Enter highlight to add",
                   model.getSelectedProfileAddHighlightValidator(),
                   model::addSelectedProfileHighlight)
               .display());
 }
 public void init(
     final JList<MutableProfile> profileList,
     final JButton addProfile,
     final JButton deleteProfile,
     final JTextField name,
     final ReorderableJList<String> nicknames,
     final JButton addNickname,
     final JButton editNickname,
     final JButton deleteNickname,
     final JTextField realname,
     final JTextField ident,
     final ReorderableJList<String> highlights,
     final JButton addHighlight,
     final JButton editHighlight,
     final JButton deleteHighlight,
     final JButton okButton,
     final JButton cancelButton) {
   this.deleteProfile = deleteProfile;
   this.name = name;
   this.nicknames = nicknames;
   this.addNickname = addNickname;
   this.editNickname = editNickname;
   this.deleteNickname = deleteNickname;
   this.realname = realname;
   this.ident = ident;
   this.highlights = highlights;
   this.addHighlight = addHighlight;
   this.editHighlight = editHighlight;
   this.deleteHighlight = deleteHighlight;
   this.okButton = okButton;
   model.loadModel();
   setupOKButton(okButton);
   setupCancelButton(cancelButton);
   setupProfileList(profileList);
   setupAddProfile(addProfile);
   setupDeleteProfile(deleteProfile);
   setupEditNickname(editNickname);
   setupAddNickname(addNickname);
   setupDeleteNickname(deleteNickname);
   setupProfileName(name);
   setupProfileNicknames(nicknames);
   setupProfileRealname(realname);
   setupProfileIdent(ident);
   setupProfileHighlights(highlights);
   setupAddHighlight(addHighlight);
   setupEditHighlight(editHighlight);
   setupDeleteHighlight(deleteHighlight);
   model.addListener(this);
 }
 private void setupProfileList(final JList<MutableProfile> profileList) {
   selectionModel = new VetoableListSelectionModel();
   profilesModel = (GenericListModel<MutableProfile>) profileList.getModel();
   profilesModel.addAll(model.getProfileList());
   profileList.setSelectionModel(selectionModel);
   selectionModel.addVetoableSelectionListener(
       e -> {
         if (!model.canSwitchProfiles()) {
           throw new PropertyVetoException("Cannot switch with invalid profile", e);
         }
       });
   profileList.addListSelectionListener(
       l -> {
         if (!selectionModel.isSelectionEmpty()) {
           model.setSelectedProfile(Optional.ofNullable(profileList.getSelectedValue()));
         }
       });
 }
 private void setupEditHighlight(final JButton editHighlight) {
   editHighlight.setEnabled(model.getSelectedProfileSelectedHighlight().isPresent());
   editHighlight.addActionListener(
       l ->
           model
               .getSelectedProfileSelectedHighlight()
               .ifPresent(
                   (String oldName) ->
                       new StandardInputDialog(
                               dialog,
                               Dialog.ModalityType.DOCUMENT_MODAL,
                               iconManager,
                               "Profile Manager: Edit Highlight",
                               "Enter new highlight",
                               model.getSelectedProfileEditHighlightValidator(),
                               (String newName) ->
                                   model.editSelectedProfileHighlight(oldName, newName))
                           .display()));
 }
 private void setupAddProfile(final JButton addProfile) {
   addProfile.addActionListener(
       e ->
           new StandardInputDialog(
                   dialog,
                   Dialog.ModalityType.DOCUMENT_MODAL,
                   iconManager,
                   "Profile Manager: Add Profile",
                   "Enter the new profile's name",
                   model.getNewProfileNameValidator(),
                   (Consumer<String>) model::addProfile)
               .display());
 }
 @Override
 public void selectedProfileHighlightRemoved(final String highlight) {
   okButton.setEnabled(model.isSaveAllowed());
   highlightsModel.remove(highlight);
 }
 @Override
 public void selectedHighlightChanged(final Optional<String> highlight) {
   deleteHighlight.setEnabled(model.isSelectedProfileHighlightsValid());
   editHighlight.setEnabled(model.isSelectedProfileHighlightsValid());
 }
 @Override
 public void selectedProfileNicknameRemoved(final String nickname) {
   okButton.setEnabled(model.isSaveAllowed());
   nicknamesModel.remove(nickname);
 }
 @Override
 public void selectedNicknameChanged(final Optional<String> nickname) {
   okButton.setEnabled(model.isSaveAllowed());
   deleteNickname.setEnabled(model.isSelectedProfileNicknamesValid());
   editNickname.setEnabled(model.isSelectedProfileNicknamesValid());
 }
 @Override
 public void profileEdited(final MutableProfile profile) {
   okButton.setEnabled(model.isSaveAllowed());
 }