<commit_before>/*
 * Copyright 2000-2010 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.ide.scriptingContext;

import com.intellij.ide.scriptingContext.ui.ScriptingLibrariesPanelStub;
import com.intellij.ide.scriptingContext.ui.ScriptingContextsConfigurable;
import com.intellij.ide.scriptingContext.ui.ScriptingLibrariesPanel;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.libraries.scripting.ScriptingLibraryManager;
import org.jetbrains.annotations.Nls;

import javax.swing.*;

/**
 * @author <NAME>
 */
public abstract class LangScriptingContextConfigurable implements Configurable, Configurable.Composite {
  private final ScriptingLibrariesPanelStub myPanel;
  private final ScriptingLibraryManager myLibManager;
  private ScriptingContextsConfigurable myContextsConfigurable;
  private final String productName = System.getProperty("idea.platform.prefix");

  public LangScriptingContextConfigurable(Project project, LangScriptingContextProvider provider) {
    myLibManager = new ScriptingLibraryManager(project, provider.getLibraryType());
    myPanel = useDedicatedLibraryUI() ? new ScriptingLibrariesPanel(provider, project, myLibManager) : new ScriptingLibrariesPanelStub();
    myContextsConfigurable = new ScriptingContextsConfigurable(project, provider.getLibraryMappings(project));
  }

  private boolean useDedicatedLibraryUI() {
    //TODO<rv> Find a better way to check it
    return "WebStorm".equalsIgnoreCase(productName) || "PhpStorm".equalsIgnoreCase(productName);
  }

  @Nls
  @Override
  public String getDisplayName() {
    return "Libraries";
  }

  @Override
  public JComponent createComponent() {
    return myPanel.getPanel();
  }

  @Override
  public boolean isModified() {
    return myPanel.isModified();
  }

  @Override
  public void apply() throws ConfigurationException {
    ApplicationManager.getApplication().runWriteAction(new Runnable() {
      @Override
      public void run() {
        myLibManager.commitChanges();
        myPanel.resetTable();
        myContextsConfigurable.resetMappings();
      }
    });
  }<commit_msg>correctly detect availability of global library configuration UI<commit_after>/*
 * Copyright 2000-2010 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.ide.scriptingContext;

import com.intellij.ide.scriptingContext.ui.ScriptingLibrariesPanelStub;
import com.intellij.ide.scriptingContext.ui.ScriptingContextsConfigurable;
import com.intellij.ide.scriptingContext.ui.ScriptingLibrariesPanel;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.libraries.scripting.ScriptingLibraryManager;
import org.jetbrains.annotations.Nls;

import javax.swing.*;

/**
 * @author <NAME>
 */
public abstract class LangScriptingContextConfigurable implements Configurable, Configurable.Composite {
  private final ScriptingLibrariesPanelStub myPanel;
  private final ScriptingLibraryManager myLibManager;
  private ScriptingContextsConfigurable myContextsConfigurable;

  public LangScriptingContextConfigurable(Project project, LangScriptingContextProvider provider) {
    myLibManager = new ScriptingLibraryManager(project, provider.getLibraryType());
    myPanel = useDedicatedLibraryUI(project) ? new ScriptingLibrariesPanel(provider, project, myLibManager) : new ScriptingLibrariesPanelStub();
    myContextsConfigurable = new ScriptingContextsConfigurable(project, provider.getLibraryMappings(project));
  }

  private static boolean useDedicatedLibraryUI(Project project) {
    return project.getPicoContainer().getComponentInstance("com.intellij.openapi.roots.ui.configuration.projectRoot.GlobalLibrariesConfigurable") == null;
  }

  @Nls
  @Override
  public String getDisplayName() {
    return "Libraries";
  }

  @Override
  public JComponent createComponent() {
    return myPanel.getPanel();
  }

  @Override
  public boolean isModified() {
    return myPanel.isModified();
  }

  @Override
  public void apply() throws ConfigurationException {
    ApplicationManager.getApplication().runWriteAction(new Runnable() {
      @Override
      public void run() {
        myLibManager.commitChanges();
        myPanel.resetTable();
        myContextsConfigurable.resetMappings();
      }
    });
  }
{'fraction_non_alphanumeric': 0.08439265536723164, 'fraction_numerical': 0.00423728813559322, 'mean_word_length': 5.078326180257511, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '6039275', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1517, 'n_words': 394}