Skip to content

Commit 14b8058

Browse files
Merge pull request #82 from yusufugurozbek/81-disabling-updated-data-source-url-notification
Make it possible to enable/disable Updated data source URL notifications
2 parents 079a0a1 + 11a0f89 commit 14b8058

File tree

8 files changed

+121
-2
lines changed

8 files changed

+121
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Testcontainers Port Updater Changelog
22

33
## [Unreleased]
4+
- Bump dependencies to their latest versions
5+
- Make it possible to enable/disable 'Updated data source URL' notifications via plugin settings
46

57
## [0.1.2]
68
- Improve regex pattern
@@ -42,4 +44,4 @@
4244

4345
## [0.0.2]
4446
### Added
45-
- Create the plugin
47+
- Create the plugin

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ Example log;
4040

4141
After covering these 2 requirements, the plugin automatically will catch the log and update the matched data source URL with the Testcontainers' one.
4242

43+
### Plugin Settings
44+
45+
To adjust Testcontainers Port Updater plugin settings, open IntelliJ preferences and navigate to **Tools | Testcontainers Port Updater**.
46+
47+
Currently, there is only one setting is possible:
48+
49+
- To enable/disable 'Updated data source URL' notifications, check/uncheck "Do you want to get notified from Testcontainers Port Updater?" option.
50+
4351
---
4452
Plugin based on the [IntelliJ Platform Plugin Template][template].
4553

src/main/kotlin/com/github/yusufugurozbek/testcontainers/port/updater/impl/DatasourceUpdaterImpl.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.github.yusufugurozbek.testcontainers.port.updater.DatasourceUrlExtrac
44
import com.github.yusufugurozbek.testcontainers.port.updater.api.DatasourceUpdater
55
import com.github.yusufugurozbek.testcontainers.port.updater.common.TpuNotifier
66
import com.github.yusufugurozbek.testcontainers.port.updater.common.equalsIgnoringPort
7+
import com.github.yusufugurozbek.testcontainers.port.updater.settings.TpuSettingsState
78
import com.intellij.database.dataSource.LocalDataSource
89
import com.intellij.database.psi.DbPsiFacade
910
import com.intellij.database.util.DbImplUtil
@@ -24,6 +25,8 @@ class DatasourceUpdaterImpl(var project: Project) : DatasourceUpdater {
2425

2526
private fun update(localDataSource: LocalDataSource, newUrl: String) {
2627
localDataSource.url = newUrl
27-
TpuNotifier.notify(project, "Updated data source URL: $newUrl")
28+
if (TpuSettingsState.instance.isNotificationsEnabled) {
29+
TpuNotifier.notify(project, "Updated data source URL: $newUrl")
30+
}
2831
}
2932
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.github.yusufugurozbek.testcontainers.port.updater.settings
2+
3+
import com.github.yusufugurozbek.testcontainers.port.updater.common.TpuBundle
4+
import com.intellij.ui.components.JBCheckBox
5+
import com.intellij.util.ui.FormBuilder
6+
import javax.swing.JComponent
7+
import javax.swing.JPanel
8+
9+
class TpuSettingsComponent {
10+
val panel: JPanel
11+
private val isNotificationsEnabledCheckbox = JBCheckBox(TpuBundle.message("settings.isNotificationsEnabledText"))
12+
13+
init {
14+
panel = FormBuilder.createFormBuilder()
15+
.addComponent(isNotificationsEnabledCheckbox, 1)
16+
.addComponentFillVertically(JPanel(), 0)
17+
.panel
18+
}
19+
20+
val preferredFocusedComponent: JComponent
21+
get() = isNotificationsEnabledCheckbox
22+
var isNotificationsEnabled: Boolean
23+
get() = isNotificationsEnabledCheckbox.isSelected
24+
set(value) {
25+
isNotificationsEnabledCheckbox.isSelected = value
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.github.yusufugurozbek.testcontainers.port.updater.settings
2+
3+
import com.github.yusufugurozbek.testcontainers.port.updater.common.TpuBundle
4+
import com.intellij.openapi.options.Configurable
5+
import org.jetbrains.annotations.Nls
6+
import javax.swing.JComponent
7+
8+
class TpuSettingsConfigurable : Configurable {
9+
private var settingsComponent: TpuSettingsComponent? = null
10+
11+
override fun getDisplayName(): @Nls(capitalization = Nls.Capitalization.Title) String {
12+
return TpuBundle.message("name")
13+
}
14+
15+
override fun getPreferredFocusedComponent(): JComponent {
16+
return settingsComponent!!.preferredFocusedComponent
17+
}
18+
19+
override fun createComponent(): JComponent {
20+
settingsComponent = TpuSettingsComponent()
21+
return settingsComponent!!.panel
22+
}
23+
24+
override fun isModified(): Boolean {
25+
val settings: TpuSettingsState = TpuSettingsState.instance
26+
return settingsComponent!!.isNotificationsEnabled != settings.isNotificationsEnabled
27+
}
28+
29+
override fun apply() {
30+
val settings: TpuSettingsState = TpuSettingsState.instance
31+
settings.isNotificationsEnabled = settingsComponent!!.isNotificationsEnabled
32+
}
33+
34+
override fun reset() {
35+
val settings: TpuSettingsState = TpuSettingsState.instance
36+
settingsComponent!!.isNotificationsEnabled = settings.isNotificationsEnabled
37+
}
38+
39+
override fun disposeUIResources() {
40+
settingsComponent = null
41+
}
42+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.github.yusufugurozbek.testcontainers.port.updater.settings
2+
3+
import com.intellij.openapi.application.ApplicationManager
4+
import com.intellij.openapi.components.PersistentStateComponent
5+
import com.intellij.openapi.components.State
6+
import com.intellij.openapi.components.Storage
7+
import com.intellij.util.xmlb.XmlSerializerUtil
8+
9+
@State(
10+
name = "com.github.yusufugurozbek.testcontainers.port.updater.settings.AppSettingsState",
11+
storages = [Storage("TestcontainersPortUpdaterPlugin.xml")]
12+
)
13+
class TpuSettingsState : PersistentStateComponent<TpuSettingsState?> {
14+
var isNotificationsEnabled = true
15+
16+
override fun getState(): TpuSettingsState {
17+
return this
18+
}
19+
20+
override fun loadState(state: TpuSettingsState) {
21+
XmlSerializerUtil.copyBean(state, this)
22+
}
23+
24+
companion object {
25+
val instance: TpuSettingsState
26+
get() = ApplicationManager.getApplication().getService(TpuSettingsState::class.java)
27+
}
28+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,13 @@
1515
<notificationGroup id="Testcontainers Port Updater" displayType="BALLOON"/>
1616
<consoleFilterProvider
1717
implementation="com.github.yusufugurozbek.testcontainers.port.updater.impl.ConsoleFilterProviderImpl"/>
18+
<applicationConfigurable
19+
id="com.github.yusufugurozbek.testcontainers.port.updater.settings.TpuSettingsConfigurable"
20+
parentId="tools"
21+
instance="com.github.yusufugurozbek.testcontainers.port.updater.settings.TpuSettingsConfigurable"
22+
bundle="messages.TpuBundle"
23+
key="name"/>
24+
<applicationService
25+
serviceImplementation="com.github.yusufugurozbek.testcontainers.port.updater.settings.TpuSettingsState"/>
1826
</extensions>
1927
</idea-plugin>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
name=Testcontainers Port Updater
2+
settings.isNotificationsEnabledText=Do you want to get notified from Testcontainers Port Updater?

0 commit comments

Comments
 (0)