public static void addHistoryOnExpansion(final @NotNull TextFieldWithHistory textFieldWithHistory,
                                           final @NotNull NotNullProducer<? extends List<String>> historyProvider) {
    textFieldWithHistory.addPopupMenuListener(new PopupMenuListener() {
      @Override
      public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
        List<String> history = historyProvider.produce();
        setHistory(textFieldWithHistory, ContainerUtil.notNullize(history), true);
        // one-time initialization
        textFieldWithHistory.removePopupMenuListener(this);
      }

      @Override
      public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
      }

      @Override
      public void popupMenuCanceled(PopupMenuEvent e) {
      }
    });
  }
public static void addHistoryOnExpansion(final @NotNull TextFieldWithHistory textFieldWithHistory,
                                           final @NotNull NotNullProducer<? extends List<String>> historyProvider)