<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.execution.ui;

import com.intellij.execution.RunnerAndConfigurationSettings;
import com.intellij.execution.configurations.RunConfigurationBase;
import com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.util.Disposer;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

public class RunnerAndConfigurationSettingsEditor extends SettingsEditor<RunnerAndConfigurationSettings> {

  private final RunConfigurationFragmentedEditor<RunConfigurationBase<?>> myConfigurationEditor;

  public RunnerAndConfigurationSettingsEditor(RunnerAndConfigurationSettings settings,
                                              RunConfigurationFragmentedEditor<RunConfigurationBase<?>> configurationEditor) {
    super(settings.createFactory());
    myConfigurationEditor = configurationEditor;
    myConfigurationEditor.addSettingsEditorListener(editor -> fireEditorStateChanged());
    Disposer.register(this, myConfigurationEditor);
  }

  @Override
  protected void resetEditorFrom(@NotNull RunnerAndConfigurationSettings s) {
    myConfigurationEditor.resetEditorFrom((RunnerAndConfigurationSettingsImpl)s);
    myConfigurationEditor.resetFrom((RunConfigurationBase<?>)s.getConfiguration());
  }

  @Override
  protected void applyEditorTo(@NotNull RunnerAndConfigurationSettings s) throws ConfigurationException {
    myConfigurationEditor.applyEditorTo((RunnerAndConfigurationSettingsImpl)s);
    myConfigurationEditor.applyTo((RunConfigurationBase<?>)s.getConfiguration());
  }

  @Override
  protected @NotNull JComponent createEditor() {
    return myConfigurationEditor.getComponent();<commit_msg>IDEA-65915 (wip) added 'Store as file' checkbox for RunConfigurationFragmentedEditor when it's used for RC template<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.execution.ui;

import com.intellij.execution.RunnerAndConfigurationSettings;
import com.intellij.execution.configurations.RunConfigurationBase;
import com.intellij.execution.impl.RunConfigurationStorageUi;
import com.intellij.execution.impl.RunManagerImpl;
import com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.util.ui.JBUI;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;

public class RunnerAndConfigurationSettingsEditor extends SettingsEditor<RunnerAndConfigurationSettings> {

  private final RunConfigurationFragmentedEditor<RunConfigurationBase<?>> myConfigurationEditor;
  private final @Nullable RunConfigurationStorageUi myRCStorageUi;

  public RunnerAndConfigurationSettingsEditor(RunnerAndConfigurationSettings settings,
                                              RunConfigurationFragmentedEditor<RunConfigurationBase<?>> configurationEditor) {
    super(settings.createFactory());
    myConfigurationEditor = configurationEditor;
    myConfigurationEditor.addSettingsEditorListener(editor -> fireEditorStateChanged());
    Disposer.register(this, myConfigurationEditor);

    Project project = settings.getConfiguration().getProject();
    // RunConfigurationStorageUi for non-template settings is managed by com.intellij.execution.impl.SingleConfigurationConfigurable
    myRCStorageUi = !project.isDefault() && settings.isTemplate()
                    ? new RunConfigurationStorageUi(project, () -> fireEditorStateChanged())
                    : null;
  }

  @Override
  protected void resetEditorFrom(@NotNull RunnerAndConfigurationSettings s) {
    myConfigurationEditor.resetEditorFrom((RunnerAndConfigurationSettingsImpl)s);
    myConfigurationEditor.resetFrom((RunConfigurationBase<?>)s.getConfiguration());

    if (myRCStorageUi != null) {
      myRCStorageUi.reset(s);
    }
  }

  @Override
  protected void applyEditorTo(@NotNull RunnerAndConfigurationSettings s) throws ConfigurationException {
    myConfigurationEditor.applyEditorTo((RunnerAndConfigurationSettingsImpl)s);
    myConfigurationEditor.applyTo((RunConfigurationBase<?>)s.getConfiguration());

    if (myRCStorageUi != null) {
      // editing a template run configuration
      myRCStorageUi.apply(s);
      RunManagerImpl.getInstanceImpl(s.getConfiguration().getProject()).addConfiguration(s);
    }
  }

  @Override
  protected @NotNull JComponent createEditor() {
    if (myRCStorageUi == null) return myConfigurationEditor.getComponent();

    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.EAST;
    c.insets = JBUI.insets(5, 0, 10, 0);
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0;
    c.weighty = 0;
    panel.add(myRCStorageUi.createComponent(), c);

    c.gridx = 0;
    c.gridy = 1;
    c.anchor = GridBagConstraints.NORTH;
    c.insets = JBUI.emptyInsets();
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1;
    c.weighty = 1;
    panel.add(myConfigurationEditor.getComponent(), c);

    return panel;
{'fraction_non_alphanumeric': 0.08804581245526127, 'fraction_numerical': 0.006800286327845383, 'mean_word_length': 5.162072767364939, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3756250', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1416, 'n_words': 289}