eccd06580c74e1196258ea6ae4afb66a4e31f786
[idea/community.git] / java / idea-ui / src / com / intellij / openapi / roots / ui / configuration / projectRoot / LibraryJarsDiffDialog.kt
1 // Copyright 2000-2018 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.
2 package com.intellij.openapi.roots.ui.configuration.projectRoot
3
4 import com.intellij.diff.DiffManager
5 import com.intellij.diff.DiffRequestFactory
6 import com.intellij.diff.DiffRequestPanel
7 import com.intellij.diff.requests.ContentDiffRequest
8 import com.intellij.ide.diff.DirDiffSettings
9 import com.intellij.openapi.project.Project
10 import com.intellij.openapi.ui.DialogWrapper
11 import com.intellij.openapi.vfs.VirtualFile
12 import com.intellij.projectModel.ProjectModelBundle
13 import com.intellij.ui.components.JBLabel
14 import com.intellij.xml.util.XmlStringUtil
15 import org.jetbrains.jps.model.library.JpsMavenRepositoryLibraryDescriptor
16 import java.awt.event.ActionEvent
17 import javax.swing.Action
18 import javax.swing.JComponent
19
20 class LibraryJarsDiffDialog(libraryFile: VirtualFile,
21                             downloadedFile: VirtualFile,
22                             private val mavenCoordinates: JpsMavenRepositoryLibraryDescriptor,
23                             private val libraryName: String,
24                             project: Project) : DialogWrapper(project) {
25   companion object {
26     const val CHANGE_COORDINATES_CODE: Int = 2
27   }
28
29   private val panel: DiffRequestPanel
30
31   init {
32     title = ProjectModelBundle.message("dialog.title.replace.library")
33     setOKButtonText(ProjectModelBundle.message("button.text.replace"))
34     val request: ContentDiffRequest = DiffRequestFactory.getInstance().createFromFiles(project, libraryFile, downloadedFile)
35     panel = DiffManager.getInstance().createRequestPanel(project, disposable, window)
36     panel.putContextHints(DirDiffSettings.KEY, DirDiffSettings().apply {
37       enableChoosers = false
38       enableOperations = false
39     })
40     panel.setRequest(request)
41     init()
42   }
43
44   override fun createNorthPanel(): JBLabel = JBLabel(XmlStringUtil.wrapInHtml("${mavenCoordinates.mavenId} JARs differ from '$libraryName' library JARs."))
45
46   override fun createCenterPanel(): JComponent = panel.component
47
48   override fun getPreferredFocusedComponent(): JComponent? = panel.preferredFocusedComponent
49
50   override fun createActions(): Array<Action> {
51     return arrayOf(okAction, ChangeCoordinatesAction(), cancelAction)
52   }
53
54   private inner class ChangeCoordinatesAction : DialogWrapperAction("Change Coordinates...") {
55     override fun doAction(e: ActionEvent?) {
56       close(CHANGE_COORDINATES_CODE)
57     }
58   }
59 }