Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecated API - migrate project listeners #101

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions resources/META-INF/lang-optional-dependencies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
topic="com.intellij.openapi.vfs.newvfs.BulkFileListener"/>
</applicationListeners>

<projectListeners>
<listener class="com.intellij.idea.plugin.hybris.startup.event.ItemsXmlFileEditorManagerListener"
topic="com.intellij.openapi.fileEditor.FileEditorManagerListener"/>
<listener class="com.intellij.idea.plugin.hybris.startup.event.HybrisConsoleProjectManagerListener"
topic="com.intellij.openapi.project.ProjectManagerListener"/>
</projectListeners>

<extensions defaultExtensionNs="com.intellij">
<!-- ####################################################################################################### -->
<!-- Hybris Type System -->
Expand Down Expand Up @@ -289,6 +296,8 @@
<postStartupActivity implementation="com.intellij.idea.plugin.hybris.startup.HybrisProjectStructureStartupActivity"/>
<postStartupActivity implementation="com.intellij.idea.plugin.hybris.startup.ItemsXmlFileOpenStartupActivity"/>
<postStartupActivity implementation="com.intellij.idea.plugin.hybris.startup.ImpexHeaderHighlighterStartupActivity"/>

<editorFactoryListener implementation="com.intellij.idea.plugin.hybris.impex.assistance.event.ImpexEditorFactoryListener"/>
</extensions>

<actions>
Expand Down
13 changes: 8 additions & 5 deletions resources/META-INF/plugin-release-info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<description>
<![CDATA[
<p>This plugin is a plugin for SAP Commerce integration.</p>
<p>This plugin is a plugin for SAP Commerce Cloud integration.</p>

<b>If you have any questions you can send an email to:</b>
<ul>
Expand Down Expand Up @@ -88,10 +88,13 @@
<change-notes>
<![CDATA[
<ul>
<li> Introduction the Type System Management - the powerful tool to observe SAP Commerce Cloud type system </li>
<li> Improved performance of the items.xml inspection </li>
<li> Extended/refactored type system rules </li>
<li> Merged ToolsWindows "Hybris" (as Remote Instances) and "Hybris Console" (as Consoles) altogether with "Type system" into "Hybris" as a single entry point for all [y] related actions </li>
<li> Introduction the Bean System Management - the powerful tool to observe SAP Commerce Cloud bean system </li>
<li> Added new beans.xml inspection rules </li>
<li> Added extra visibility filters for Type System view </li>
<li> Inspection for beans.xml rely on whole Bean System, not only current file </li>
<li> Decreased usage of the Deprecated API </li>
<li> Fixed: Business Process Diagram action is not visible </li>
<li> Fixed: Impex config processor inspection rule </li>
</ul>
]]>
</change-notes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ import com.intellij.notification.NotificationType
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.project.DumbAwareRunnable
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.project.ProjectManagerListener
import com.intellij.openapi.project.*
import com.intellij.openapi.startup.StartupActivity
import com.intellij.openapi.startup.StartupManager
import com.intellij.openapi.util.io.FileUtilRt
import com.intellij.spring.settings.SpringGeneralSettings
import org.apache.commons.io.IOUtils
Expand All @@ -48,7 +44,7 @@ import java.io.FileOutputStream
import java.io.IOException
import java.nio.charset.StandardCharsets

class HybrisProjectStructureStartupActivity : StartupActivity {
class HybrisProjectStructureStartupActivity : StartupActivity.DumbAware {

private val logger = Logger.getInstance(HybrisProjectStructureStartupActivity::class.java)

Expand All @@ -57,34 +53,23 @@ class HybrisProjectStructureStartupActivity : StartupActivity {
return
}

ApplicationManager.getApplication().messageBus.connect().subscribe(
ProjectManager.TOPIC,
object : ProjectManagerListener {
override fun projectClosing(project: Project) {
ConsolePersistenceService.getInstance(project).persistQueryRegions()
}
}
)
if (project.isDisposed) return

if (isOldHybrisProject(project)) {
Notifications.create(NotificationType.INFORMATION,
HybrisI18NBundleUtils.message("hybris.notification.project.open.outdated.title"),
HybrisI18NBundleUtils.message("hybris.notification.project.open.outdated.text")
)
.important(true)
.addAction(HybrisI18NBundleUtils.message("hybris.notification.project.open.outdated.action")) { _, _ -> ProjectRefreshAction.triggerAction() }
.notify(project)
}
val commonIdeaService = ApplicationManager.getApplication().getService(CommonIdeaService::class.java)

if (!commonIdeaService.isHybrisProject(project)) return

StartupManager.getInstance(project).runAfterOpened(DumbAwareRunnable {
if (project.isDisposed) return@DumbAwareRunnable

if (isOldHybrisProject(project)) {
Notifications.create(NotificationType.INFORMATION,
HybrisI18NBundleUtils.message("hybris.notification.project.open.outdated.title"),
HybrisI18NBundleUtils.message("hybris.notification.project.open.outdated.text")
)
.important(true)
.addAction(HybrisI18NBundleUtils.message("hybris.notification.project.open.outdated.action")) { _, _ -> ProjectRefreshAction.triggerAction() }
.notify(project)
}
val commonIdeaService = ApplicationManager.getApplication().getService(CommonIdeaService::class.java)

if (!commonIdeaService.isHybrisProject(project)) return@DumbAwareRunnable

logVersion(project)
continueOpening(project)
})
logVersion(project)
continueOpening(project)
}

private fun logVersion(project: Project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ package com.intellij.idea.plugin.hybris.startup

import com.intellij.idea.plugin.hybris.common.services.CommonIdeaService
import com.intellij.idea.plugin.hybris.impex.assistance.event.ImpexColumnHighlightingCaretListener
import com.intellij.idea.plugin.hybris.impex.assistance.event.ImpexEditorFactoryListener
import com.intellij.idea.plugin.hybris.impex.assistance.event.ImpexHeaderHighlightingCaretListener
import com.intellij.idea.plugin.hybris.impex.assistance.event.ImpexPsiTreeChangeListener
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.EditorFactory
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupActivity
import com.intellij.openapi.startup.StartupManager
import com.intellij.psi.PsiManager

class ImpexHeaderHighlighterStartupActivity : StartupActivity, Disposable {
class ImpexHeaderHighlighterStartupActivity : StartupActivity.DumbAware, Disposable {

override fun runActivity(project: Project) {
if (!ApplicationManager.getApplication().getService(CommonIdeaService::class.java).isHybrisProject(project)) {
Expand All @@ -39,14 +37,11 @@ class ImpexHeaderHighlighterStartupActivity : StartupActivity, Disposable {

val disposable = this;

StartupManager.getInstance(project).runAfterOpened {
val eventFactory = EditorFactory.getInstance()
val eventFactory = EditorFactory.getInstance()

PsiManager.getInstance(project).addPsiTreeChangeListener(ImpexPsiTreeChangeListener(), disposable)
eventFactory.addEditorFactoryListener(ImpexEditorFactoryListener(), disposable)
eventFactory.eventMulticaster.addCaretListener(ImpexHeaderHighlightingCaretListener(), disposable)
eventFactory.eventMulticaster.addCaretListener(ImpexColumnHighlightingCaretListener(), disposable)
}
PsiManager.getInstance(project).addPsiTreeChangeListener(ImpexPsiTreeChangeListener(), disposable)
eventFactory.eventMulticaster.addCaretListener(ImpexHeaderHighlightingCaretListener(), disposable)
eventFactory.eventMulticaster.addCaretListener(ImpexColumnHighlightingCaretListener(), disposable)
}

override fun dispose() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,72 +21,37 @@ import com.intellij.idea.plugin.hybris.common.services.CommonIdeaService
import com.intellij.idea.plugin.hybris.common.utils.HybrisI18NBundleUtils
import com.intellij.idea.plugin.hybris.common.utils.HybrisItemsXmlFileType
import com.intellij.idea.plugin.hybris.notifications.Notifications
import com.intellij.idea.plugin.hybris.type.system.validation.ItemsFileValidation
import com.intellij.idea.plugin.hybris.type.system.validation.impl.DefaultItemsFileValidation
import com.intellij.notification.NotificationType
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.FileEditorManagerListener
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupActivity
import com.intellij.openapi.startup.StartupManager
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.search.FileTypeIndex
import com.intellij.psi.search.GlobalSearchScope


private const val NOTIFICATION_TITLE = "hybris.notification.ts.validation.title"
private const val NOTIFICATION_CONTENT = "hybris.notification.ts.validation.content"

class ItemsXmlFileOpenStartupActivity : StartupActivity {

override fun runActivity(project: Project) {
if (!ApplicationManager.getApplication().getService(CommonIdeaService::class.java).isHybrisProject(project)) {
return
}

project.messageBus.connect().subscribe(
FileEditorManagerListener.FILE_EDITOR_MANAGER, ItemsXmlFileEditorManagerListener(project)
val isOutdated = FileTypeIndex.getFiles(
HybrisItemsXmlFileType.INSTANCE,
GlobalSearchScope.projectScope(project)
)

StartupManager.getInstance(project).runAfterOpened {
val isOutdated = FileTypeIndex.getFiles(
HybrisItemsXmlFileType.INSTANCE,
GlobalSearchScope.projectScope(project)
.any { file -> DefaultItemsFileValidation(project).isFileOutOfDate(file) }
if (isOutdated) {
Notifications.create(
NotificationType.WARNING,
HybrisI18NBundleUtils.message("hybris.notification.ts.validation.title"),
HybrisI18NBundleUtils.message("hybris.notification.ts.validation.content")
)
.any { file -> DefaultItemsFileValidation(project).isFileOutOfDate(file) }
if (isOutdated) {
Notifications.create(
NotificationType.WARNING,
HybrisI18NBundleUtils.message(NOTIFICATION_TITLE),
HybrisI18NBundleUtils.message(NOTIFICATION_CONTENT)
)
.important(true)
.delay(10)
.notify(project)
}
.important(true)
.delay(10)
.notify(project)
}
}

private class ItemsXmlFileEditorManagerListener(private val project: Project) : FileEditorManagerListener {
private val validator: ItemsFileValidation

init {
validator = DefaultItemsFileValidation(project)
}

override fun fileOpened(source: FileEditorManager, file: VirtualFile) {
StartupManager.getInstance(project).runAfterOpened {
if (validator.isFileOutOfDate(file)) {
Notifications.create(
NotificationType.WARNING,
HybrisI18NBundleUtils.message(NOTIFICATION_TITLE),
HybrisI18NBundleUtils.message(NOTIFICATION_CONTENT)
)
.delay(10)
.notify(project)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA.
* Copyright (C) 2019 EPAM Systems <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.intellij.idea.plugin.hybris.startup.event

import com.intellij.idea.plugin.hybris.tools.remote.console.persistence.services.ConsolePersistenceService
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManagerListener

class HybrisConsoleProjectManagerListener : ProjectManagerListener {
override fun projectClosing(project: Project) {
ConsolePersistenceService.getInstance(project).persistQueryRegions()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA.
* Copyright (C) 2019 EPAM Systems <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.intellij.idea.plugin.hybris.startup.event

import com.intellij.idea.plugin.hybris.common.utils.HybrisI18NBundleUtils
import com.intellij.idea.plugin.hybris.notifications.Notifications
import com.intellij.idea.plugin.hybris.type.system.validation.ItemsFileValidation
import com.intellij.idea.plugin.hybris.type.system.validation.impl.DefaultItemsFileValidation
import com.intellij.notification.NotificationType
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.FileEditorManagerListener
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupManager
import com.intellij.openapi.vfs.VirtualFile

class ItemsXmlFileEditorManagerListener(private val project: Project) : FileEditorManagerListener {
private val validator: ItemsFileValidation

init {
validator = DefaultItemsFileValidation(project)
}

override fun fileOpened(source: FileEditorManager, file: VirtualFile) {
if (validator.isFileOutOfDate(file)) {
Notifications.create(
NotificationType.WARNING,
HybrisI18NBundleUtils.message("hybris.notification.ts.validation.title"),
HybrisI18NBundleUtils.message("hybris.notification.ts.validation.content")
)
.delay(10)
.notify(project)
}
}
}