<commit_before>/*
 * Copyright 2000-2009 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.openapi.vcs.ui;

import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.vcs.update.AbstractCommonUpdateAction;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

/**
 * Shows a notification balloon over one of version control related tool windows: Changes View or Version Control View.
 * By default the notification is shown over the Changes View.
 * Use the special method or supply additional parameter to the constructor to show the balloon over the Version Control View.
 */
public class VcsBalloonProblemNotifier implements Runnable {
  private final Project myProject;
  private final String myMessage;
  private final MessageType myMessageType;
  private final boolean myShowOverChangesView;

  public VcsBalloonProblemNotifier(final Project project, final String message, final MessageType messageType) {
    this(project, message, messageType, true);
  }

  public VcsBalloonProblemNotifier(final Project project, final String message, final MessageType messageType, boolean showOverChangesView) {
    myProject = project;
    myMessage = message;
    myMessageType = messageType;
    myShowOverChangesView = showOverChangesView;
  }

  public static void showOverChangesView(final Project project, final String message, final MessageType type) {
    show(project, message, type, true);
  }

  public static void showOverVersionControlView(final Project project, final String message, final MessageType type) {
    show(project, message, type, false);
  }

  private static void show(final Project project, final String message, final MessageType type, final boolean showOverChangesView) {
    final Application application = ApplicationManager.getApplication();
    if (application.isHeadlessEnvironment()) return;
    final Runnable showErrorAction = new Runnable() {
      public void run() {
        new VcsBalloonProblemNotifier(project, message, type, showOverChangesView).run();
      }
    };
    if (application.isDispatchThread()) {
      showErrorAction.run();
    }
    else {
      ApplicationManager.getApplication().invokeLater(showErrorAction);
    }
  }

  public void run() {
    final Collection<Project> projects;
    if (myProject != null) {
      projects = Collections.singletonList(myProject);
    } else {
      doForProject(null);
    }
  }

  private void doForProject(final Project project) {
    AbstractCommonUpdateAction.NOTIFICATION_GROUP.createNotification(myMessage, myMessageType).notify(project);
  }
}<commit_msg>fix VcsBalloonProblemNotifier<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.openapi.vcs.ui;

import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.vcs.update.AbstractCommonUpdateAction;

import java.util.Collection;

/**
 * Shows a notification balloon over one of version control related tool windows: Changes View or Version Control View.
 * By default the notification is shown over the Changes View.
 * Use the special method or supply additional parameter to the constructor to show the balloon over the Version Control View.
 */
public class VcsBalloonProblemNotifier implements Runnable {
  private final Project myProject;
  private final String myMessage;
  private final MessageType myMessageType;
  private final boolean myShowOverChangesView;

  public VcsBalloonProblemNotifier(final Project project, final String message, final MessageType messageType) {
    this(project, message, messageType, true);
  }

  public VcsBalloonProblemNotifier(final Project project, final String message, final MessageType messageType, boolean showOverChangesView) {
    myProject = project;
    myMessage = message;
    myMessageType = messageType;
    myShowOverChangesView = showOverChangesView;
  }

  public static void showOverChangesView(final Project project, final String message, final MessageType type) {
    show(project, message, type, true);
  }

  public static void showOverVersionControlView(final Project project, final String message, final MessageType type) {
    show(project, message, type, false);
  }

  private static void show(final Project project, final String message, final MessageType type, final boolean showOverChangesView) {
    final Application application = ApplicationManager.getApplication();
    if (application.isHeadlessEnvironment()) return;
    final Runnable showErrorAction = new Runnable() {
      public void run() {
        new VcsBalloonProblemNotifier(project, message, type, showOverChangesView).run();
      }
    };
    if (application.isDispatchThread()) {
      showErrorAction.run();
    }
    else {
      ApplicationManager.getApplication().invokeLater(showErrorAction);
    }
  }

  public void run() {
    final Collection<Project> projects;
    if (myProject != null) {
      doForProject(myProject);
    } else {
      doForProject(null);
    }
  }

  private void doForProject(final Project project) {
    AbstractCommonUpdateAction.NOTIFICATION_GROUP.createNotification(myMessage, myMessageType).notify(project);
  }
}
{'fraction_non_alphanumeric': 0.07539503386004515, 'fraction_numerical': 0.0036117381489841984, 'mean_word_length': 4.501655629139073, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2773065', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1698, 'n_words': 592}