<commit_before>// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ui;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.openapi.wm.ex.ToolWindowManagerListener;
import com.intellij.ui.viewModel.definition.ToolWindowViewModel;
import com.intellij.ui.viewModel.extraction.ToolWindowViewModelExtractor;
import org.jetbrains.annotations.NotNull;

import java.util.List;

//override this class and work with the view model in your protocol-specific code
public abstract class ToolWindowSynchronizer {

  private static final Logger myLogger = Logger.getInstance(ToolWindowSynchronizer.class);

  public ToolWindowSynchronizer(Project project) {
    project.getMessageBus().connect().subscribe(ToolWindowManagerListener.TOPIC, new ToolWindowManagerListener(){
      @Override
      public void toolWindowsRegistered(@NotNull List<String> ids,
                                        @NotNull ToolWindowManager toolWindowManager) {
        for (String id : ids) {
          processToolWindow(id, toolWindowManager);
        }
      }
    });
  }

  public void processToolWindow(String id, @NotNull ToolWindowManager toolWindowManager) {
    final ToolWindowViewModelExtractor[] extractors = ToolWindowViewModelExtractor.EP_NAME.getExtensions();
    for (ToolWindowViewModelExtractor extractor : extractors) {

      if (!extractor.isApplicable(id)) {
        continue;
      }

      ToolWindow window = toolWindowManager.getToolWindow(id);
      myLogger.assertTrue(window != null,  String.format("Tool window with id %s could not be found", id));
      ToolWindowViewModel toolWindowViewModel = extractor.extractViewModel(window);

      passViewModel(toolWindowViewModel);
    }
  }

  abstract void passViewModel(ToolWindowViewModel toolWindowViewModel);
}<commit_msg>basic init for cwm<commit_after>// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ui;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.openapi.wm.ex.ToolWindowManagerListener;
import com.intellij.ui.viewModel.definition.ToolWindowViewModel;
import com.intellij.ui.viewModel.extraction.ToolWindowViewModelExtractor;
import org.jetbrains.annotations.NotNull;

import java.util.List;

//override this class and work with the view model in your protocol-specific code
public abstract class ToolWindowSynchronizer {

  private static final Logger myLogger = Logger.getInstance(ToolWindowSynchronizer.class);

  public ToolWindowSynchronizer(Project project) {
    project.getMessageBus().connect().subscribe(ToolWindowManagerListener.TOPIC, new ToolWindowManagerListener(){
      @Override
      public void toolWindowsRegistered(@NotNull List<String> ids,
                                        @NotNull ToolWindowManager toolWindowManager) {
        for (String id : ids) {
          processToolWindow(id, toolWindowManager);
        }
      }
    });
  }

  public void processToolWindow(String id, @NotNull ToolWindowManager toolWindowManager) {
    final ToolWindowViewModelExtractor[] extractors = ToolWindowViewModelExtractor.EP_NAME.getExtensions();
    for (ToolWindowViewModelExtractor extractor : extractors) {

      if (!extractor.isApplicable(id)) {
        continue;
      }

      ToolWindow window = toolWindowManager.getToolWindow(id);
      myLogger.assertTrue(window != null,  String.format("Tool window with id %s could not be found", id));
      ToolWindowViewModel toolWindowViewModel = extractor.extractViewModel(window);

      passViewModel(toolWindowViewModel);
    }
  }

  public abstract void passViewModel(ToolWindowViewModel toolWindowViewModel);
}
{'fraction_non_alphanumeric': 0.08190289357528201, 'fraction_numerical': 0.004904364884747425, 'mean_word_length': 4.276843467011643, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6347306', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1068, 'n_words': 264}