<commit_before>/*
 * Copyright (c) 2012-2017 Red Hat, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Red Hat, Inc. - initial API and implementation
 */
package org.eclipse.che.ide.ext.git.client;

import static org.eclipse.che.ide.api.vcs.VcsStatus.ADDED;
import static org.eclipse.che.ide.api.vcs.VcsStatus.MODIFIED;
import static org.eclipse.che.ide.api.vcs.VcsStatus.NOT_MODIFIED;
import static org.eclipse.che.ide.api.vcs.VcsStatus.UNTRACKED;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator;
import org.eclipse.che.api.git.shared.Status;
import org.eclipse.che.api.project.shared.dto.event.GitChangeEventDto;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.editor.EditorAgent;
import org.eclipse.che.ide.api.parts.EditorMultiPartStack;
import org.eclipse.che.ide.api.parts.EditorTab;
import org.eclipse.che.ide.api.resources.File;
import org.eclipse.che.ide.api.resources.Resource;
import org.eclipse.che.ide.api.vcs.VcsStatus;
import org.eclipse.che.ide.part.explorer.project.ProjectExplorerPresenter;
import org.eclipse.che.ide.resource.Path;
import org.eclipse.che.ide.resources.tree.FileNode;
import org.eclipse.che.ide.resources.tree.ResourceNode;
import org.eclipse.che.ide.ui.smartTree.Tree;

/**
 * Receives and handel's git changes notifications caught by server side VFS file watching system.
 *
 * @author <NAME>
 */
@Singleton
public class GitChangesHandler {

  private final AppContext appContext;
  private final Provider<EditorAgent> editorAgentProvider;
  private final Provider<ProjectExplorerPresenter> projectExplorerPresenterProvider;
  private final Provider<EditorMultiPartStack> multiPartStackProvider;

  @Inject
  public GitChangesHandler(
      RequestHandlerConfigurator configurator,
      AppContext appContext,
      Provider<EditorAgent> editorAgentProvider,
      Provider<ProjectExplorerPresenter> projectExplorerPresenterProvider,
      Provider<EditorMultiPartStack> multiPartStackProvider) {
    this.appContext = appContext;
    this.editorAgentProvider = editorAgentProvider;
    this.projectExplorerPresenterProvider = projectExplorerPresenterProvider;
    this.multiPartStackProvider = multiPartStackProvider;

    configureHandler(configurator);
  }

  private void configureHandler(RequestHandlerConfigurator configurator) {
    configurator
        .newConfiguration()
        .methodName("event/git-change")
        .paramsAsDto(GitChangeEventDto.class)
        .noResult()
        .withBiConsumer(this::apply);

    configurator
        .newConfiguration()
        .methodName("event/git/indexChanged")
        .paramsAsDto(Status.class)
        .noResult()
        .withBiConsumer(this::apply);
  }

  public void apply(String endpointId, GitChangeEventDto dto) {
    Tree tree = projectExplorerPresenterProvider.get().getTree();
    tree.getNodeStorage()
        .getAll()
        .stream()
        .filter(
            node ->
                node instanceof FileNode
                    && ((ResourceNode) node)
                        .getData()
                        .getLocation()
                        .equals(Path.valueOf(dto.getPath())))
        .forEach(
            node -> {
              ((ResourceNode) node)
                  .getData()
                  .asFile()
                  .setVcsStatus(VcsStatus.from(dto.getType().toString()));
              tree.refresh(node);
            });

    editorAgentProvider
        .get()
        .getOpenedEditors()
        .stream()
        .filter(
            editor ->
                editor.getEditorInput().getFile().getLocation().equals(Path.valueOf(dto.getPath())))
        .forEach(
            editor -> {
              VcsStatus vcsStatus = VcsStatus.from(dto.getType().toString());
              EditorTab tab = multiPartStackProvider.get().getTabByPart(editor);
              if (vcsStatus != null) {
                tab.setTitleColor(vcsStatus.getColor());
              }
            });

    appContext.getWorkspaceRoot().synchronize();
  }

  public void apply(String endpointId, Status status) {
    Tree tree = projectExplorerPresenterProvider.get().getTree();
    tree.getNodeStorage()
        .getAll()
        .stream()<commit_msg>Workaround for fixing freeze browser for big project (#6341)<commit_after>/*
 * Copyright (c) 2012-2017 Red Hat, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Red Hat, Inc. - initial API and implementation
 */
package org.eclipse.che.ide.ext.git.client;

import static org.eclipse.che.ide.api.vcs.VcsStatus.ADDED;
import static org.eclipse.che.ide.api.vcs.VcsStatus.MODIFIED;
import static org.eclipse.che.ide.api.vcs.VcsStatus.NOT_MODIFIED;
import static org.eclipse.che.ide.api.vcs.VcsStatus.UNTRACKED;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator;
import org.eclipse.che.api.git.shared.Status;
import org.eclipse.che.api.project.shared.dto.event.GitChangeEventDto;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.editor.EditorAgent;
import org.eclipse.che.ide.api.parts.EditorMultiPartStack;
import org.eclipse.che.ide.api.parts.EditorTab;
import org.eclipse.che.ide.api.resources.File;
import org.eclipse.che.ide.api.resources.Resource;
import org.eclipse.che.ide.api.vcs.VcsStatus;
import org.eclipse.che.ide.part.explorer.project.ProjectExplorerPresenter;
import org.eclipse.che.ide.resource.Path;
import org.eclipse.che.ide.resources.tree.FileNode;
import org.eclipse.che.ide.resources.tree.ResourceNode;
import org.eclipse.che.ide.ui.smartTree.Tree;

/**
 * Receives and handel's git changes notifications caught by server side VFS file watching system.
 *
 * @author <NAME>
 */
@Singleton
public class GitChangesHandler {

  private final AppContext appContext;
  private final Provider<EditorAgent> editorAgentProvider;
  private final Provider<ProjectExplorerPresenter> projectExplorerPresenterProvider;
  private final Provider<EditorMultiPartStack> multiPartStackProvider;

  @Inject
  public GitChangesHandler(
      RequestHandlerConfigurator configurator,
      AppContext appContext,
      Provider<EditorAgent> editorAgentProvider,
      Provider<ProjectExplorerPresenter> projectExplorerPresenterProvider,
      Provider<EditorMultiPartStack> multiPartStackProvider) {
    this.appContext = appContext;
    this.editorAgentProvider = editorAgentProvider;
    this.projectExplorerPresenterProvider = projectExplorerPresenterProvider;
    this.multiPartStackProvider = multiPartStackProvider;

    configureHandler(configurator);
  }

  private void configureHandler(RequestHandlerConfigurator configurator) {
    configurator
        .newConfiguration()
        .methodName("event/git-change")
        .paramsAsDto(GitChangeEventDto.class)
        .noResult()
        .withBiConsumer(this::apply);

    configurator
        .newConfiguration()
        .methodName("event/git/indexChanged")
        .paramsAsDto(Status.class)
        .noResult()
        .withBiConsumer(this::apply);
  }

  public void apply(String endpointId, GitChangeEventDto dto) {
    Tree tree = projectExplorerPresenterProvider.get().getTree();
    tree.getNodeStorage()
        .getAll()
        .stream()
        .filter(
            node ->
                node instanceof FileNode
                    && ((ResourceNode) node)
                        .getData()
                        .getLocation()
                        .equals(Path.valueOf(dto.getPath())))
        .forEach(
            node -> {
              ((ResourceNode) node)
                  .getData()
                  .asFile()
                  .setVcsStatus(VcsStatus.from(dto.getType().toString()));
              tree.refresh(node);
            });

    editorAgentProvider
        .get()
        .getOpenedEditors()
        .stream()
        .filter(
            editor ->
                editor.getEditorInput().getFile().getLocation().equals(Path.valueOf(dto.getPath())))
        .forEach(
            editor -> {
              VcsStatus vcsStatus = VcsStatus.from(dto.getType().toString());
              EditorTab tab = multiPartStackProvider.get().getTabByPart(editor);
              if (vcsStatus != null) {
                tab.setTitleColor(vcsStatus.getColor());
              }
            });

    //TODO: temporary comment this line because its freeze browser for big project details see in che#6208
    //appContext.getWorkspaceRoot().synchronize();
  }

  public void apply(String endpointId, Status status) {
    Tree tree = projectExplorerPresenterProvider.get().getTree();
    tree.getNodeStorage()
        .getAll()
        .stream()
{'fraction_non_alphanumeric': 0.10489283394674172, 'fraction_numerical': 0.0034639532366313053, 'mean_word_length': 2.980611805256355, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 25, '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': '5401947', 'n_tokens_mistral': 2657, 'n_tokens_neox': 2582, 'n_words': 485}