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