<commit_before>package org.jetbrains.sbt
package project.module

import java.awt.event.{ActionListener, ActionEvent}
import java.util
import javax.swing.table.AbstractTableModel

import com.intellij.openapi.roots.ui.configuration.{ModuleConfigurationState, ModuleElementsEditor}
import com.intellij.ui.CollectionListModel
import com.intellij.util.text.DateFormatUtil
import org.jetbrains.plugins.scala.util.JListCompatibility
import org.jetbrains.plugins.scala.util.JListCompatibility.CollectionListModelWrapper
import org.jetbrains.sbt.project.settings.SbtSettings
import org.jetbrains.sbt.resolvers.{SbtResolverIndexesManager, SbtResolverIndex, SbtResolver}

import scala.collection.JavaConverters._

/**
 * @author <NAME>
 * @since 12/1/14.
 */
class SbtModuleSettingsEditor (state: ModuleConfigurationState) extends ModuleElementsEditor(state) {
  private val myForm = new SbtModuleSettingsForm
  private val modelWrapper = new CollectionListModelWrapper(new CollectionListModel[String](new util.ArrayList[String]))
  private val resolvers = SbtModule.getResolversFrom(getModel.getModule).toSeq

  def getDisplayName = SbtBundle("sbt.settings.sbtModuleSettings")

  def getHelpTopic = null

  def saveData() {}

  def createComponentImpl() = {
    myForm.sbtImportsList.setEmptyText(SbtBundle("sbt.settings.noImplicitImportsFound"))
    JListCompatibility.setModel(myForm.sbtImportsList, modelWrapper.getModelRaw)

    myForm.updateButton.addActionListener(new ActionListener {
      override def actionPerformed(e: ActionEvent): Unit = {
        val resolversToUpdate: Seq[SbtResolver] =
          myForm.resolversTable.getSelectedRows map (resolvers(_))
        SbtResolverIndexesManager().update(if (resolversToUpdate.isEmpty) resolvers else resolversToUpdate)
      }
    })

    myForm.mainPanel
  }

  override def reset() {
    val moduleSettings = Option(SbtSettings.getInstance(state.getProject).getLinkedProjectSettings(getModel.getModule))
    myForm.sbtVersionTextField.setText(moduleSettings.map(_.sbtVersion).getOrElse(SbtBundle("sbt.settings.sbtVersionNotDetected")))

    modelWrapper.getModel.replaceAll(SbtModule.getImportsFrom(getModel.getModule).asJava)

    myForm.resolversTable.setModel(new ResolversModel(resolvers))
    myForm.resolversTable.getColumnModel.getColumn(0).setPreferredWidth(50)
    myForm.resolversTable.getColumnModel.getColumn(1).setPreferredWidth(400)
    myForm.resolversTable.getColumnModel.getColumn(2).setPreferredWidth(20)
  }
}

private class ResolversModel(val resolvers: Seq[SbtResolver]) extends AbstractTableModel {

  private val columns = Seq(
    SbtBundle("sbt.settings.resolvers.name"),
    SbtBundle("sbt.settings.resolvers.url"),
    SbtBundle("sbt.settings.resolvers.updated")
  )

  def getColumnCount = columns.size

  def getRowCount = resolvers.size

  override def getColumnName(columnIndex: Int) = columns(columnIndex)

  def getValueAt(rowIndex: Int, columnIndex: Int) = columnIndex match {
    case 0 => resolvers(rowIndex).name
    case 1 => resolvers(rowIndex).root
    case 2 =>
      val ts: Long = resolvers(rowIndex).associatedIndex.map(_.timestamp).getOrElse(SbtResolverIndex.NO_TIMESTAMP)
      if (ts == SbtResolverIndex.NO_TIMESTAMP)
        SbtBundle("sbt.settings.resolvers.neverUpdated")
      else
        DateFormatUtil.formatDate(ts)
  }
}<commit_msg>= fixed non-working update button in resolvers pane<commit_after>package org.jetbrains.sbt
package project.module

import java.awt.event.{ActionEvent, ActionListener}
import java.util
import javax.swing.table.AbstractTableModel

import com.intellij.openapi.roots.ui.configuration.{ModuleConfigurationState, ModuleElementsEditor}
import com.intellij.ui.CollectionListModel
import com.intellij.util.text.DateFormatUtil
import org.jetbrains.plugins.scala.util.JListCompatibility
import org.jetbrains.plugins.scala.util.JListCompatibility.CollectionListModelWrapper
import org.jetbrains.sbt.project.settings.SbtSettings
import org.jetbrains.sbt.resolvers.{SbtResolver, SbtResolverIndex, SbtResolverIndexesManager}

import scala.collection.JavaConverters._

/**
 * @author <NAME>
 * @since 12/1/14.
 */
class SbtModuleSettingsEditor (state: ModuleConfigurationState) extends ModuleElementsEditor(state) {
  private val myForm = new SbtModuleSettingsForm
  private val modelWrapper = new CollectionListModelWrapper(new CollectionListModel[String](new util.ArrayList[String]))
  private val resolvers = SbtModule.getResolversFrom(getModel.getModule).toSeq

  def getDisplayName = SbtBundle("sbt.settings.sbtModuleSettings")

  def getHelpTopic = null

  def saveData() {}

  def createComponentImpl() = {
    myForm.sbtImportsList.setEmptyText(SbtBundle("sbt.settings.noImplicitImportsFound"))
    JListCompatibility.setModel(myForm.sbtImportsList, modelWrapper.getModelRaw)

    myForm.updateButton.addActionListener(new ActionListener {
      override def actionPerformed(e: ActionEvent): Unit = {
        val resolversToUpdate: Seq[SbtResolver] =
          myForm.resolversTable.getSelectedRows map (resolvers(_))
        SbtResolverIndexesManager().update(resolversToUpdate)
      }
    })

    myForm.mainPanel
  }

  override def reset() {
    val moduleSettings = Option(SbtSettings.getInstance(state.getProject).getLinkedProjectSettings(getModel.getModule))
    myForm.sbtVersionTextField.setText(moduleSettings.map(_.sbtVersion).getOrElse(SbtBundle("sbt.settings.sbtVersionNotDetected")))

    modelWrapper.getModel.replaceAll(SbtModule.getImportsFrom(getModel.getModule).asJava)

    myForm.resolversTable.setModel(new ResolversModel(resolvers))
    myForm.resolversTable.setRowSelectionInterval(0, 0)
    myForm.resolversTable.getColumnModel.getColumn(0).setPreferredWidth(50)
    myForm.resolversTable.getColumnModel.getColumn(1).setPreferredWidth(400)
    myForm.resolversTable.getColumnModel.getColumn(2).setPreferredWidth(20)
  }
}

private class ResolversModel(val resolvers: Seq[SbtResolver]) extends AbstractTableModel {

  private val columns = Seq(
    SbtBundle("sbt.settings.resolvers.name"),
    SbtBundle("sbt.settings.resolvers.url"),
    SbtBundle("sbt.settings.resolvers.updated")
  )

  def getColumnCount = columns.size

  def getRowCount = resolvers.size

  override def getColumnName(columnIndex: Int) = columns(columnIndex)

  def getValueAt(rowIndex: Int, columnIndex: Int) = columnIndex match {
    case 0 => resolvers(rowIndex).name
    case 1 => resolvers(rowIndex).root
    case 2 =>
      val ts: Long = resolvers(rowIndex).associatedIndex.map(_.timestamp).getOrElse(SbtResolverIndex.NO_TIMESTAMP)
      if (ts == SbtResolverIndex.NO_TIMESTAMP)
        SbtBundle("sbt.settings.resolvers.neverUpdated")
      else
        DateFormatUtil.formatDate(ts)
  }
}
{'fraction_non_alphanumeric': 0.09693725840023788, 'fraction_numerical': 0.005649717514124294, 'mean_word_length': 5.480732177263969, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2892680', 'n_tokens_mistral': 2140, 'n_tokens_neox': 2047, 'n_words': 307}