<commit_before>/*
 * Copyright 2000-2011 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.codeInsight.navigation;

import com.intellij.openapi.progress.PerformInBackgroundOption;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.ui.components.JBList;
import com.intellij.ui.speedSearch.NameFilteringListModel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;

/**
* User: anna
*/
public abstract class ListBackgroundUpdaterTask extends BackgroundUpdaterTask<JBList> {

  public ListBackgroundUpdaterTask(@Nullable final Project project,
                                   @NotNull final String title,
                                   final boolean canBeCancelled,
                                   @Nullable final PerformInBackgroundOption backgroundOption) {
    super(project, title, canBeCancelled, backgroundOption);
  }

  public ListBackgroundUpdaterTask(@Nullable final Project project, @NotNull final String title, final boolean canBeCancelled) {
    super(project, title, canBeCancelled);
  }

  public ListBackgroundUpdaterTask(@Nullable final Project project, @NotNull final String title) {
    super(project, title);
  }

  @Override
  protected void paintBusy(final boolean paintBusy) {
    myComponent.setPaintBusy(paintBusy);
  }

  @Override
  protected void replaceModel(ArrayList<PsiElement> data) {
    ((NameFilteringListModel)myComponent.getModel()).replaceAll(data);
  }
}<commit_msg>background update: preserve selection<commit_after>/*
 * Copyright 2000-2011 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.codeInsight.navigation;

import com.intellij.openapi.progress.PerformInBackgroundOption;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.ui.components.JBList;
import com.intellij.ui.speedSearch.NameFilteringListModel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;

/**
* User: anna
*/
public abstract class ListBackgroundUpdaterTask extends BackgroundUpdaterTask<JBList> {

  public ListBackgroundUpdaterTask(@Nullable final Project project,
                                   @NotNull final String title,
                                   final boolean canBeCancelled,
                                   @Nullable final PerformInBackgroundOption backgroundOption) {
    super(project, title, canBeCancelled, backgroundOption);
  }

  public ListBackgroundUpdaterTask(@Nullable final Project project, @NotNull final String title, final boolean canBeCancelled) {
    super(project, title, canBeCancelled);
  }

  public ListBackgroundUpdaterTask(@Nullable final Project project, @NotNull final String title) {
    super(project, title);
  }

  @Override
  protected void paintBusy(final boolean paintBusy) {
    myComponent.setPaintBusy(paintBusy);
  }

  @Override
  protected void replaceModel(ArrayList<PsiElement> data) {
    final Object selectedValue = myComponent.getSelectedValue();
    final int index = myComponent.getSelectedIndex();
    ((NameFilteringListModel)myComponent.getModel()).replaceAll(data);
    if (index == 0) {
      myComponent.setSelectedIndex(0);
    } else {
      myComponent.setSelectedValue(selectedValue, true);
    }
  }
}
{'fraction_non_alphanumeric': 0.08092224231464738, 'fraction_numerical': 0.005877034358047016, 'mean_word_length': 3.9057649667405765, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '22017', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1164, 'n_words': 354}