<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 org.jetbrains.plugins.gradle.config;

import com.intellij.ide.util.PropertiesComponent;
import com.intellij.ide.util.projectWizard.NamePathComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.Alarm;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.gradle.util.GradleBundle;
import org.jetbrains.plugins.gradle.util.GradleIcons;
import org.jetbrains.plugins.gradle.util.GradleLibraryManager;
import org.jetbrains.plugins.gradle.util.GradleUtil;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.io.File;
import java.util.concurrent.TimeUnit;

/**
 * @author peter
 */
public class GradleConfigurable implements SearchableConfigurable {

  @NonNls public static final String HELP_TOPIC = "reference.settingsdialog.project.gradle";

  /**
   * There is a possible case that end-user defines gradle home while particular project is open. We want to use that gradle
   * home for the default project as well until that is manually changed for the default project.
   * <p/>
   * Current constant holds key of the value that defines if gradle home for default project should be tracked from
   * the non-default one.
   * <p/>
   * This property has a form of 'not-propagate' in order to default to 'propagate'.
   */
  @NonNls private static final String NOT_PROPAGATE_GRADLE_HOME_TO_DEFAULT_PROJECT = "gradle.not.propagate.home.to.default.project";

  private final Alarm myAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD);

  private final GradleLibraryManager myLibraryManager;
  private final Project              myProject;

  private GradleHomeSettingType myGradleHomeSettingType = GradleHomeSettingType.UNKNOWN;

  private JComponent         myComponent;
  private NamePathComponent  myGradleHomeComponent;
  private boolean            myPathManuallyModified;

  public GradleConfigurable(@Nullable Project project) {
    this(project, ServiceManager.getService(GradleLibraryManager.class));
  }

  public GradleConfigurable(@Nullable Project project, @NotNull GradleLibraryManager gradleLibraryManager) {
    myLibraryManager = gradleLibraryManager;
    myProject = project;
    doCreateComponent();
  }

  @NotNull
  @Override
  public String getId() {
    return getHelpTopic();
  }

  @Override
  public Runnable enableSearch(String option) {
    return null;
  }

  @Nls
  @Override
  public String getDisplayName() {
    return GradleBundle.message("gradle.name");
  }

  @Override
  public JComponent createComponent() {
    if (myComponent == null) {
      doCreateComponent();
    }
    return myComponent;
  }

  private void doCreateComponent() {
    myComponent = new JPanel(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.NORTH;

    myGradleHomeComponent = new NamePathComponent(
      "", GradleBundle.message("gradle.import.text.home.path"), GradleBundle.message("gradle.import.text.home.path"), "",
      false,
      false
    );
    myGradleHomeComponent.getPathComponent().getDocument().addDocumentListener(new DocumentListener() {
      @Override
      public void insertUpdate(DocumentEvent e) {
        useNormalColorForPath();
        myPathManuallyModified = true;
      }
      @Override
      public void removeUpdate(DocumentEvent e) {
        useNormalColorForPath();
        myPathManuallyModified = true;
      }
      @Override
      public void changedUpdate(DocumentEvent e) {
      }
    });
    myGradleHomeComponent.setNameComponentVisible(false);
    myComponent.add(myGradleHomeComponent, constraints);
    myComponent.add(Box.createVerticalGlue());
  }

  @Override
  public boolean isModified() {
    if (!myPathManuallyModified) {
      return false;
    }<commit_msg>IDEA-53476 Gradle integration (Maven's level - dependencies, modules, repositories)<commit_after>/*
 * 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 org.jetbrains.plugins.gradle.config;

import com.intellij.ide.util.PropertiesComponent;
import com.intellij.ide.util.projectWizard.NamePathComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.Alarm;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.gradle.util.GradleBundle;
import org.jetbrains.plugins.gradle.util.GradleIcons;
import org.jetbrains.plugins.gradle.util.GradleLibraryManager;
import org.jetbrains.plugins.gradle.util.GradleUtil;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.io.File;
import java.util.concurrent.TimeUnit;

/**
 * @author peter
 */
public class GradleConfigurable implements SearchableConfigurable {

  @NonNls public static final String HELP_TOPIC = "reference.settingsdialog.project.gradle";

  /**
   * There is a possible case that end-user defines gradle home while particular project is open. We want to use that gradle
   * home for the default project as well until that is manually changed for the default project.
   * <p/>
   * Current constant holds key of the value that defines if gradle home for default project should be tracked from
   * the non-default one.
   * <p/>
   * This property has a form of 'not-propagate' in order to default to 'propagate'.
   */
  @NonNls private static final String NOT_PROPAGATE_GRADLE_HOME_TO_DEFAULT_PROJECT = "gradle.not.propagate.home.to.default.project";

  private final Alarm myAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD);

  private final GradleLibraryManager myLibraryManager;
  private final Project              myProject;

  private GradleHomeSettingType myGradleHomeSettingType = GradleHomeSettingType.UNKNOWN;

  private JComponent         myComponent;
  private NamePathComponent  myGradleHomeComponent;
  private boolean            myPathManuallyModified;
  private boolean            myShowBalloonIfNecessary;

  public GradleConfigurable(@Nullable Project project) {
    this(project, ServiceManager.getService(GradleLibraryManager.class));
  }

  public GradleConfigurable(@Nullable Project project, @NotNull GradleLibraryManager gradleLibraryManager) {
    myLibraryManager = gradleLibraryManager;
    myProject = project;
    doCreateComponent();
  }

  @NotNull
  @Override
  public String getId() {
    return getHelpTopic();
  }

  @Override
  public Runnable enableSearch(String option) {
    return null;
  }

  @Nls
  @Override
  public String getDisplayName() {
    return GradleBundle.message("gradle.name");
  }

  @Override
  public JComponent createComponent() {
    if (myComponent == null) {
      doCreateComponent();
    }
    return myComponent;
  }

  private void doCreateComponent() {
    myComponent = new JPanel(new GridBagLayout()) {
      @Override
      public void paint(Graphics g) {
        super.paint(g);
        if (!myShowBalloonIfNecessary) {
          return;
        }
        myShowBalloonIfNecessary = false;
        MessageType messageType = null;
        switch (myGradleHomeSettingType) {
          case DEDUCED: messageType = MessageType.WARNING; break;
          case EXPLICIT_INCORRECT:
          case UNKNOWN: messageType = MessageType.ERROR; break;
          default:
        }
        if (messageType != null) {
          new DelayedBalloonInfo(messageType, myGradleHomeSettingType).run();
        }
      }
    };
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.NORTH;

    myGradleHomeComponent = new NamePathComponent(
      "", GradleBundle.message("gradle.import.text.home.path"), GradleBundle.message("gradle.import.text.home.path"), "",
      false,
      false
    );
    myGradleHomeComponent.getPathComponent().getDocument().addDocumentListener(new DocumentListener() {
      @Override
      public void insertUpdate(DocumentEvent e) {
        useNormalColorForPath();
        myPathManuallyModified = true;
      }
      @Override
      public void removeUpdate(DocumentEvent e) {
        useNormalColorForPath();
        myPathManuallyModified = true;
      }
      @Override
      public void changedUpdate(DocumentEvent e) {
      }
    });
    myGradleHomeComponent.setNameComponentVisible(false);
    myComponent.add(myGradleHomeComponent, constraints);
    myComponent.add(Box.createVerticalGlue());
  }

  @Override
  public boolean isModified() {
    myShowBalloonIfNecessary = true;
    if (!myPathManuallyModified) {
      return false;
    }
{'fraction_non_alphanumeric': 0.08531948437355096, 'fraction_numerical': 0.0030603728090512843, 'mean_word_length': 3.9287020109689212, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6037687', 'n_tokens_mistral': 3089, 'n_tokens_neox': 2980, 'n_words': 777}