Skip to content

Commit abf2bf5

Browse files
committed
migrate getData to uiDataSnapshot: platform
1 parent 3ff9d51 commit abf2bf5

File tree

3 files changed

+80
-76
lines changed

3 files changed

+80
-76
lines changed

src/main/kotlin/bitlap/sbt/analyzer/jbexternal/DependencyAnalyzerViewImpl.kt

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.intellij.icons.AllIcons
1515
import com.intellij.openapi.Disposable
1616
import com.intellij.openapi.actionSystem.CommonDataKeys
1717
import com.intellij.openapi.actionSystem.DataProvider
18+
import com.intellij.openapi.actionSystem.DataSink
1819
import com.intellij.openapi.actionSystem.PlatformCoreDataKeys
1920
import com.intellij.openapi.application.invokeLater
2021
import com.intellij.openapi.application.runInEdt
@@ -53,7 +54,7 @@ import com.intellij.openapi.externalSystem.dependency.analyzer.DependencyAnalyze
5354
*/
5455
class DependencyAnalyzerViewImpl(
5556
private val project: Project, private val systemId: ProjectSystemId, private val parentDisposable: Disposable
56-
) : DataProvider, DependencyAnalyzerView {
57+
) : DependencyAnalyzerView {
5758

5859
private val iconsProvider = ExternalSystemIconProvider.getExtension(systemId)
5960
private val contributor =
@@ -142,22 +143,19 @@ class DependencyAnalyzerViewImpl(
142143
return externalProjects.find(predicate)
143144
}
144145

145-
override fun getData(dataId: String): Any? {
146-
return when (dataId) {
147-
DependencyAnalyzerView.VIEW.name -> this
148-
CommonDataKeys.PROJECT.name -> project
149-
ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID.name -> systemId
150-
PlatformCoreDataKeys.MODULE.name -> externalProject?.module
151-
else -> null
152-
}
153-
}
154-
155146
private fun updateViewModel() {
156147
executeLoadingTaskOnEdt {
157148
updateExternalProjectsModel()
158149
}
159150
}
160151

152+
override fun uiDataSnapshot(sink: DataSink) {
153+
sink[DependencyAnalyzerView.VIEW] = this
154+
sink[CommonDataKeys.PROJECT] = project
155+
sink[ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID] = systemId
156+
sink[PlatformCoreDataKeys.MODULE] = externalProject?.module
157+
}
158+
161159
private fun Iterable<Dependency>.filterDependencies(): List<Dependency> {
162160
val dependencyDataFilter = dependencyDataFilter
163161
val dependencyScopeFilter = dependencyScopeFilter.filter { it.isSelected }.map { it.scope }
@@ -352,14 +350,22 @@ class DependencyAnalyzerViewImpl(
352350
}.asActionButton(ACTION_PLACE).bindVisible(reloadNotificationProperty)
353351

354352
val dependencyTitle = label(ExternalSystemBundle.message("external.system.dependency.analyzer.resolved.title"))
355-
val dependencyList = DependencyList(
356-
dependencyListModel, showDependencyGroupIdProperty, showDependencySizeProperty, this
357-
).bindEmptyText(dependencyEmptyTextProperty).bindDependency(dependencyProperty)
358-
.bindEnabled(!dependencyLoadingProperty)
359-
val dependencyTree = DependencyTree(
360-
dependencyTreeModel, showDependencyGroupIdProperty, showDependencySizeProperty, this
361-
).bindEmptyText(dependencyEmptyTextProperty).bindDependency(dependencyProperty)
362-
.bindEnabled(!dependencyLoadingProperty)
353+
val dependencyList =
354+
object : DependencyList(dependencyListModel, showDependencyGroupIdProperty, showDependencySizeProperty) {
355+
override fun uiDataSnapshot(sink: DataSink) {
356+
super.uiDataSnapshot(sink)
357+
DataSink.uiDataSnapshot(sink, this@DependencyAnalyzerViewImpl)
358+
}
359+
}.bindEmptyText(dependencyEmptyTextProperty).bindDependency(dependencyProperty)
360+
.bindEnabled(!dependencyLoadingProperty)
361+
val dependencyTree =
362+
object : DependencyTree(dependencyTreeModel, showDependencyGroupIdProperty, showDependencySizeProperty) {
363+
override fun uiDataSnapshot(sink: DataSink) {
364+
super.uiDataSnapshot(sink)
365+
DataSink.uiDataSnapshot(sink, this@DependencyAnalyzerViewImpl)
366+
}
367+
}.bindEmptyText(dependencyEmptyTextProperty).bindDependency(dependencyProperty)
368+
.bindEnabled(!dependencyLoadingProperty)
363369
val dependencyPanel = cardPanel<Boolean> {
364370
ScrollPaneFactory.createScrollPane(if (it) dependencyTree else dependencyList, true)
365371
}.bind(showDependencyTreeProperty)
@@ -378,9 +384,13 @@ class DependencyAnalyzerViewImpl(
378384
.bindEnabled(showDependencyTreeProperty and !dependencyLoadingProperty)
379385

380386
val usagesTitle = label(usagesTitleProperty)
381-
val usagesTree = UsagesTree(
382-
usagesTreeModel, showDependencyGroupIdProperty, showDependencySizeProperty, this
383-
).apply { emptyText.text = "" }.bindEnabled(!dependencyLoadingProperty)
387+
val usagesTree =
388+
object : UsagesTree(usagesTreeModel, showDependencyGroupIdProperty, showDependencySizeProperty) {
389+
override fun uiDataSnapshot(sink: DataSink) {
390+
super.uiDataSnapshot(sink)
391+
DataSink.uiDataSnapshot(sink, this@DependencyAnalyzerViewImpl)
392+
}
393+
}.apply { emptyText.text = "" }.bindEnabled(!dependencyLoadingProperty)
384394
val expandUsagesTreeButton =
385395
expandTreeAction(usagesTree).asActionButton(ACTION_PLACE).bindEnabled(!dependencyLoadingProperty)
386396
val collapseUsagesTreeButton =

src/main/kotlin/bitlap/sbt/analyzer/jbexternal/util/DependencyUiUtil.kt

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import javax.swing.tree.TreeModel
1010
import bitlap.sbt.analyzer.jbexternal.SbtDAArtifact
1111

1212
import com.intellij.icons.AllIcons
13-
import com.intellij.openapi.actionSystem.DataProvider
13+
import com.intellij.openapi.actionSystem.DataSink
14+
import com.intellij.openapi.actionSystem.UiDataProvider
1415
import com.intellij.openapi.application.invokeLater
1516
import com.intellij.openapi.externalSystem.dependency.analyzer.DependencyAnalyzerView
1617
import com.intellij.openapi.externalSystem.util.ExternalSystemBundle
@@ -86,8 +87,8 @@ private fun SimpleColoredComponent.customizeCellRenderer(
8687
}
8788

8889
internal abstract class AbstractDependencyList(
89-
model: ListModel<DependencyGroup>, private val dataProvider: DataProvider
90-
) : JBList<DependencyGroup>(model), DataProvider {
90+
model: ListModel<DependencyGroup>
91+
) : JBList<DependencyGroup>(model), UiDataProvider {
9192

9293
private val dependencyProperty = AtomicProperty<Dependency?>(null)
9394
private val dependencyGroupProperty = AtomicProperty<DependencyGroup?>(null)
@@ -96,12 +97,9 @@ internal abstract class AbstractDependencyList(
9697
dependencyProperty.bind(property)
9798
}
9899

99-
override fun getData(dataId: String): Any? {
100-
return when (dataId) {
101-
DependencyAnalyzerView.DEPENDENCY.name -> dependencyProperty.get()
102-
DependencyAnalyzerView.DEPENDENCIES.name -> dependencyGroupProperty.get()
103-
else -> dataProvider.getData(dataId)
104-
}
100+
override fun uiDataSnapshot(sink: DataSink) {
101+
sink[DependencyAnalyzerView.DEPENDENCY] = dependencyProperty.get()
102+
sink[DependencyAnalyzerView.DEPENDENCIES] = dependencyGroupProperty.get()?.variances
105103
}
106104

107105
init {
@@ -113,8 +111,8 @@ internal abstract class AbstractDependencyList(
113111
}
114112

115113
internal abstract class AbstractDependencyTree(
116-
model: TreeModel, private val dataProvider: DataProvider
117-
) : SimpleTree(model), DataProvider {
114+
model: TreeModel
115+
) : SimpleTree(model), UiDataProvider {
118116

119117
private val dependencyProperty = AtomicProperty<Dependency?>(null)
120118
private val dependencyGroupProperty = AtomicProperty<DependencyGroup?>(null)
@@ -123,12 +121,9 @@ internal abstract class AbstractDependencyTree(
123121
dependencyProperty.bind(property)
124122
}
125123

126-
override fun getData(dataId: String): Any? {
127-
return when (dataId) {
128-
DependencyAnalyzerView.DEPENDENCY.name -> dependencyProperty.get()
129-
DependencyAnalyzerView.DEPENDENCIES.name -> dependencyGroupProperty.get()
130-
else -> dataProvider.getData(dataId)
131-
}
124+
override fun uiDataSnapshot(sink: DataSink) {
125+
sink[DependencyAnalyzerView.DEPENDENCY] = dependencyProperty.get()
126+
sink[DependencyAnalyzerView.DEPENDENCIES] = dependencyGroupProperty.get()?.variances
132127
}
133128

134129
init {
@@ -140,12 +135,11 @@ internal abstract class AbstractDependencyTree(
140135
}
141136
}
142137

143-
internal class DependencyList(
138+
internal open class DependencyList(
144139
model: ListModel<DependencyGroup>,
145140
showGroupIdProperty: ObservableProperty<Boolean>,
146141
showSizeProperty: ObservableProperty<Boolean>,
147-
dataProvider: DataProvider
148-
) : AbstractDependencyList(model, dataProvider) {
142+
) : AbstractDependencyList(model) {
149143
init {
150144
ListUiUtil.Selection.installSelectionOnRightClick(this)
151145
PopupHandler.installPopupMenu(
@@ -155,12 +149,11 @@ internal class DependencyList(
155149
}
156150
}
157151

158-
internal class DependencyTree(
152+
internal open class DependencyTree(
159153
model: TreeModel,
160154
showGroupIdProperty: ObservableProperty<Boolean>,
161155
showSizeProperty: ObservableProperty<Boolean>,
162-
dataProvider: DataProvider
163-
) : AbstractDependencyTree(model, dataProvider) {
156+
) : AbstractDependencyTree(model) {
164157
init {
165158
PopupHandler.installPopupMenu(
166159
this, "ExternalSystem.DependencyAnalyzer.DependencyTreeGroup", DependencyAnalyzerView.ACTION_PLACE
@@ -169,12 +162,11 @@ internal class DependencyTree(
169162
}
170163
}
171164

172-
internal class UsagesTree(
165+
internal open class UsagesTree(
173166
model: TreeModel,
174167
showGroupIdProperty: ObservableProperty<Boolean>,
175168
showSizeProperty: ObservableProperty<Boolean>,
176-
dataProvider: DataProvider
177-
) : AbstractDependencyTree(model, dataProvider) {
169+
) : AbstractDependencyTree(model) {
178170
init {
179171
PopupHandler.installPopupMenu(
180172
this, "ExternalSystem.DependencyAnalyzer.UsagesTreeGroup", DependencyAnalyzerView.ACTION_PLACE

src/main/scala/bitlap/sbt/analyzer/action/SbtDependencyAnalyzerExcludeAction.scala

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,36 @@ final class SbtDependencyAnalyzerExcludeAction extends BaseRefreshDependenciesAc
2020
override def actionPerformed(e: AnActionEvent): Unit = {
2121
Option(SbtDependencyAnalyzerActionUtil.getModifiableDependency(e)).foreach { modifiableDependency =>
2222
val parent = getUnifiedCoordinates(modifiableDependency.parentDependency)
23-
val unifiedDependency =
24-
new UnifiedDependency(parent, modifiableDependency.parentDependency.getParent.getScope.getTitle)
25-
val coordinates: UnifiedCoordinates = modifiableDependency.coordinates
26-
if (coordinates == parent) {
27-
// remove declared dependency
28-
try {
29-
SbtDependencyModifier.removeDependency(modifiableDependency.module, unifiedDependency)
30-
Notifications.notifyDependencyChanged(
31-
modifiableDependency.module.getProject,
32-
coordinates.getDisplayName,
33-
true
34-
)
35-
} catch {
36-
case e: AnalyzerCommandNotFoundException =>
37-
LOG.error(s"Cannot remove declared dependency: ${coordinates.getDisplayName}", e)
38-
case ignore: Exception => throw ignore
39-
}
40-
41-
} else {
42-
// add exclude coordinates
43-
val ret =
44-
SbtDependencyModifier.addExcludeToDependency(modifiableDependency.module, unifiedDependency, coordinates)
45-
if (ret) {
46-
Notifications.notifyDependencyChanged(
47-
modifiableDependency.module.getProject,
48-
coordinates.getDisplayName,
49-
false
50-
)
23+
if (modifiableDependency.parentDependency.getParent != null) {
24+
val unifiedDependency =
25+
new UnifiedDependency(parent, modifiableDependency.parentDependency.getParent.getScope.getTitle)
26+
val coordinates: UnifiedCoordinates = modifiableDependency.coordinates
27+
if (coordinates == parent) {
28+
try {
29+
// remove declared dependency
30+
SbtDependencyModifier.removeDependency(modifiableDependency.module, unifiedDependency)
31+
Notifications.notifyDependencyChanged(
32+
modifiableDependency.module.getProject,
33+
coordinates.getDisplayName,
34+
true
35+
)
36+
} catch {
37+
case e: AnalyzerCommandNotFoundException =>
38+
LOG.error(s"Cannot remove declared dependency: ${coordinates.getDisplayName}", e)
39+
case ignore: Exception => throw ignore
40+
}
41+
42+
} else {
43+
// add exclude coordinates
44+
val ret =
45+
SbtDependencyModifier.addExcludeToDependency(modifiableDependency.module, unifiedDependency, coordinates)
46+
if (ret) {
47+
Notifications.notifyDependencyChanged(
48+
modifiableDependency.module.getProject,
49+
coordinates.getDisplayName,
50+
false
51+
)
52+
}
5153
}
5254
}
5355
}

0 commit comments

Comments
 (0)