From 27303735445de45cc3252cce1c01f4c72a94efe3 Mon Sep 17 00:00:00 2001 From: Mykhailo Lytvyn Date: Wed, 30 Aug 2023 22:44:30 +0200 Subject: [PATCH] #659 | Added configurable table-like folding for Bean properties --- CHANGELOG.md | 3 + resources/META-INF/lang-dependencies.xml | 76 +++++ .../META-INF/lang/beanSystem-dependencies.xml | 73 +++++ .../lang/businessProcess-dependencies.xml | 29 ++ resources/META-INF/lang/ccv2-dependencies.xml | 36 +++ .../META-INF/lang/cockpitng-dependencies.xml | 63 ++++ .../lang/extensioninfo-dependencies.xml | 28 ++ ...ch.xml => flexibleSearch-dependencies.xml} | 0 ...ional-impex.xml => impex-dependencies.xml} | 0 .../lang/localextensions-dependencies.xml | 28 ++ ...ry.xml => polyglot-query-dependencies.xml} | 0 .../META-INF/lang/typeSystem-dependencies.xml | 77 +++++ .../META-INF/optional-lang-dependencies.xml | 291 ------------------ resources/META-INF/plugin.xml | 16 +- resources/i18n/HybrisBundle.properties | 3 + .../HybrisDeveloperSpecificProjectSettings.kt | 21 ++ .../lang/folding/BeansXmlFoldingBuilder.kt | 34 +- .../BeanSystemConfigurableProvider.kt | 60 ++++ .../bean/settings/BeanSystemSettings.kt | 28 ++ 19 files changed, 568 insertions(+), 298 deletions(-) create mode 100644 resources/META-INF/lang-dependencies.xml create mode 100644 resources/META-INF/lang/beanSystem-dependencies.xml create mode 100644 resources/META-INF/lang/businessProcess-dependencies.xml create mode 100644 resources/META-INF/lang/ccv2-dependencies.xml create mode 100644 resources/META-INF/lang/cockpitng-dependencies.xml create mode 100644 resources/META-INF/lang/extensioninfo-dependencies.xml rename resources/META-INF/lang/{optional-flexibleSearch.xml => flexibleSearch-dependencies.xml} (100%) rename resources/META-INF/lang/{optional-impex.xml => impex-dependencies.xml} (100%) create mode 100644 resources/META-INF/lang/localextensions-dependencies.xml rename resources/META-INF/lang/{optional-polyglot-query.xml => polyglot-query-dependencies.xml} (100%) create mode 100644 resources/META-INF/lang/typeSystem-dependencies.xml delete mode 100644 resources/META-INF/optional-lang-dependencies.xml create mode 100644 src/com/intellij/idea/plugin/hybris/system/bean/settings/BeanSystemConfigurableProvider.kt create mode 100644 src/com/intellij/idea/plugin/hybris/system/bean/settings/BeanSystemSettings.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b2ee8438..92938ae3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## [2023.2.7] +### `beans.xml` enhancements +- Added configurable table-like folding for Bean properties [#659](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/659) + ### `ImpEx` inspection rules - Add missing value groups for value lines [#641](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/641) - Delete blank header parameter [#642](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/642) diff --git a/resources/META-INF/lang-dependencies.xml b/resources/META-INF/lang-dependencies.xml new file mode 100644 index 000000000..56da3ee08 --- /dev/null +++ b/resources/META-INF/lang-dependencies.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/META-INF/lang/beanSystem-dependencies.xml b/resources/META-INF/lang/beanSystem-dependencies.xml new file mode 100644 index 000000000..23ac2a302 --- /dev/null +++ b/resources/META-INF/lang/beanSystem-dependencies.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/META-INF/lang/businessProcess-dependencies.xml b/resources/META-INF/lang/businessProcess-dependencies.xml new file mode 100644 index 000000000..7e4f06e68 --- /dev/null +++ b/resources/META-INF/lang/businessProcess-dependencies.xml @@ -0,0 +1,29 @@ + + + + + + + + + diff --git a/resources/META-INF/lang/ccv2-dependencies.xml b/resources/META-INF/lang/ccv2-dependencies.xml new file mode 100644 index 000000000..5087edc6b --- /dev/null +++ b/resources/META-INF/lang/ccv2-dependencies.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + diff --git a/resources/META-INF/lang/cockpitng-dependencies.xml b/resources/META-INF/lang/cockpitng-dependencies.xml new file mode 100644 index 000000000..4379a7d42 --- /dev/null +++ b/resources/META-INF/lang/cockpitng-dependencies.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/META-INF/lang/extensioninfo-dependencies.xml b/resources/META-INF/lang/extensioninfo-dependencies.xml new file mode 100644 index 000000000..d48e5f48d --- /dev/null +++ b/resources/META-INF/lang/extensioninfo-dependencies.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + diff --git a/resources/META-INF/lang/optional-flexibleSearch.xml b/resources/META-INF/lang/flexibleSearch-dependencies.xml similarity index 100% rename from resources/META-INF/lang/optional-flexibleSearch.xml rename to resources/META-INF/lang/flexibleSearch-dependencies.xml diff --git a/resources/META-INF/lang/optional-impex.xml b/resources/META-INF/lang/impex-dependencies.xml similarity index 100% rename from resources/META-INF/lang/optional-impex.xml rename to resources/META-INF/lang/impex-dependencies.xml diff --git a/resources/META-INF/lang/localextensions-dependencies.xml b/resources/META-INF/lang/localextensions-dependencies.xml new file mode 100644 index 000000000..a398ece14 --- /dev/null +++ b/resources/META-INF/lang/localextensions-dependencies.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + diff --git a/resources/META-INF/lang/optional-polyglot-query.xml b/resources/META-INF/lang/polyglot-query-dependencies.xml similarity index 100% rename from resources/META-INF/lang/optional-polyglot-query.xml rename to resources/META-INF/lang/polyglot-query-dependencies.xml diff --git a/resources/META-INF/lang/typeSystem-dependencies.xml b/resources/META-INF/lang/typeSystem-dependencies.xml new file mode 100644 index 000000000..74a158304 --- /dev/null +++ b/resources/META-INF/lang/typeSystem-dependencies.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/META-INF/optional-lang-dependencies.xml b/resources/META-INF/optional-lang-dependencies.xml deleted file mode 100644 index 8f36e2850..000000000 --- a/resources/META-INF/optional-lang-dependencies.xml +++ /dev/null @@ -1,291 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 8b6672415..c61f5dcf0 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -28,15 +28,23 @@ EPAM_Systems + com.intellij.modules.lang + com.intellij.modules.lang + com.intellij.modules.lang + com.intellij.modules.lang + com.intellij.modules.lang + com.intellij.modules.lang + com.intellij.modules.lang + com.intellij.modules.lang + com.intellij.modules.lang + com.intellij.modules.lang + com.intellij.modules.lang + JUnit AntSupport org.jetbrains.idea.maven org.jetbrains.idea.eclipse org.jetbrains.plugins.gradle - com.intellij.modules.lang - com.intellij.modules.lang - com.intellij.modules.lang - com.intellij.modules.lang com.intellij.spring com.intellij.javaee.web com.intellij.modules.java diff --git a/resources/i18n/HybrisBundle.properties b/resources/i18n/HybrisBundle.properties index bf308503e..15a87b3e5 100644 --- a/resources/i18n/HybrisBundle.properties +++ b/resources/i18n/HybrisBundle.properties @@ -531,6 +531,9 @@ hybris.settings.project.details.platform_version.title=Platform version hybris.settings.project.diagram.title=Diagram Settings hybris.settings.project.diagram.ts.title=Type System Diagram hybris.settings.project.common.title=Common Settings +hybris.settings.project.bs.title=Bean System +hybris.settings.project.ts.title=Type System +hybris.settings.project.bp.title=Business Process hybris.startupActivity.itemsXmlValidation.progress.title=Validating items.xml files... hybris.startupActivity.itemsXmlValidation.progress.subTitle.validating=Validating: {0}... diff --git a/src/com/intellij/idea/plugin/hybris/settings/HybrisDeveloperSpecificProjectSettings.kt b/src/com/intellij/idea/plugin/hybris/settings/HybrisDeveloperSpecificProjectSettings.kt index 920f922da..1d1ccf661 100644 --- a/src/com/intellij/idea/plugin/hybris/settings/HybrisDeveloperSpecificProjectSettings.kt +++ b/src/com/intellij/idea/plugin/hybris/settings/HybrisDeveloperSpecificProjectSettings.kt @@ -1,8 +1,29 @@ +/* + * This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA. + * Copyright (C) 2019-2023 EPAM Systems and contributors + * + * 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 . + */ + package com.intellij.idea.plugin.hybris.settings +import com.intellij.idea.plugin.hybris.system.bean.settings.BeanSystemSettings + data class HybrisDeveloperSpecificProjectSettings( var activeRemoteConnectionID: String? = null, var activeSolrConnectionID: String? = null, var remoteConnectionSettingsList: MutableList = mutableListOf(), var typeSystemDiagramSettings: TSDiagramSettings = TSDiagramSettings(), + var beanSystemSettings: BeanSystemSettings = BeanSystemSettings(), ) \ No newline at end of file diff --git a/src/com/intellij/idea/plugin/hybris/system/bean/lang/folding/BeansXmlFoldingBuilder.kt b/src/com/intellij/idea/plugin/hybris/system/bean/lang/folding/BeansXmlFoldingBuilder.kt index f897135b1..6428bee67 100644 --- a/src/com/intellij/idea/plugin/hybris/system/bean/lang/folding/BeansXmlFoldingBuilder.kt +++ b/src/com/intellij/idea/plugin/hybris/system/bean/lang/folding/BeansXmlFoldingBuilder.kt @@ -1,6 +1,6 @@ /* * This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA. - * Copyright (C) 2023 EPAM Systems and contributors + * Copyright (C) 2019-2023 EPAM Systems and contributors * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -19,6 +19,7 @@ package com.intellij.idea.plugin.hybris.system.bean.lang.folding import ai.grazie.utils.toDistinctTypedArray import com.intellij.idea.plugin.hybris.common.HybrisConstants +import com.intellij.idea.plugin.hybris.settings.HybrisDeveloperSpecificProjectSettingsComponent import com.intellij.idea.plugin.hybris.settings.HybrisProjectSettingsComponent import com.intellij.idea.plugin.hybris.system.bean.meta.BSMetaHelper import com.intellij.idea.plugin.hybris.system.bean.model.* @@ -29,13 +30,17 @@ import com.intellij.lang.folding.FoldingDescriptor import com.intellij.openapi.editor.Document import com.intellij.openapi.editor.FoldingGroup import com.intellij.openapi.project.DumbAware +import com.intellij.openapi.util.Key +import com.intellij.openapi.util.removeUserData import com.intellij.psi.PsiElement import com.intellij.psi.PsiErrorElement import com.intellij.psi.SyntaxTraverser +import com.intellij.psi.util.childrenOfType import com.intellij.psi.xml.XmlFile import com.intellij.psi.xml.XmlTag import com.intellij.psi.xml.XmlToken import com.intellij.util.xml.DomManager +import org.jetbrains.kotlin.psi.psiUtil.getParentOfType class BeansXmlFoldingBuilder : FoldingBuilderEx(), DumbAware { @@ -44,12 +49,21 @@ class BeansXmlFoldingBuilder : FoldingBuilderEx(), DumbAware { private val foldAbstract = "[abstract] " private val filter = BeansXmlFilter() + private val foldTableLikeProperties: Key = Key.create("hybris_fold_table_like_properties") override fun buildFoldRegions(root: PsiElement, document: Document, quick: Boolean): Array { if (!HybrisProjectSettingsComponent.getInstance(root.project).isHybrisProject()) return emptyArray() if (root !is XmlFile) return emptyArray() DomManager.getDomManager(root.project).getFileElement(root, Beans::class.java) ?: return emptyArray() + val foldingSettings = HybrisDeveloperSpecificProjectSettingsComponent.getInstance(root.project).state.beanSystemSettings.folding + + if (!foldingSettings.enabled) { + root.removeUserData(foldTableLikeProperties) + return emptyArray() + } + + root.putUserData(foldTableLikeProperties, foldingSettings.tableLikeProperties) return SyntaxTraverser.psiTraverser(root) .filter { filter.isAccepted(it) } @@ -60,9 +74,17 @@ class BeansXmlFoldingBuilder : FoldingBuilderEx(), DumbAware { .toDistinctTypedArray() } - override fun getPlaceholderText(node: ASTNode) = when (val psi = node.psi) { + override fun getPlaceholderText(node: ASTNode): String = when (val psi = node.psi) { is XmlTag -> when (psi.localName) { - Bean.PROPERTY -> psi.getAttributeValue(Property.NAME) + " : " + + Bean.PROPERTY -> psi.getAttributeValue(Property.NAME) + ?.let { + if (psi.getParentOfType(false)?.getUserData(foldTableLikeProperties) == true) { + val propertyNamePostfix = " ".repeat(getLongestPropertyLength(psi) - it.length) + it + propertyNamePostfix + } else { + it + } + } + " : " + (BSMetaHelper.flattenType(psi.getAttributeValue(Property.TYPE)) ?: "?") Enum.VALUE -> psi.value.trimmedText @@ -125,6 +147,12 @@ class BeansXmlFoldingBuilder : FoldingBuilderEx(), DumbAware { else -> false } + private fun getLongestPropertyLength(psi: PsiElement) = psi.parent.childrenOfType() + .filter { it.localName == Bean.PROPERTY } + .mapNotNull { it.getAttributeValue(Property.NAME) } + .maxOfOrNull { it.length } + ?: 0 + companion object { private const val GROUP_NAME = "BeansXml" private const val FALLBACK_PLACEHOLDER = "..." diff --git a/src/com/intellij/idea/plugin/hybris/system/bean/settings/BeanSystemConfigurableProvider.kt b/src/com/intellij/idea/plugin/hybris/system/bean/settings/BeanSystemConfigurableProvider.kt new file mode 100644 index 000000000..bf5a1385a --- /dev/null +++ b/src/com/intellij/idea/plugin/hybris/system/bean/settings/BeanSystemConfigurableProvider.kt @@ -0,0 +1,60 @@ +/* + * This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA. + * Copyright (C) 2019-2023 EPAM Systems and contributors + * + * 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 . + */ + +package com.intellij.idea.plugin.hybris.system.bean.settings + +import com.intellij.idea.plugin.hybris.common.utils.HybrisI18NBundleUtils.message +import com.intellij.idea.plugin.hybris.settings.HybrisDeveloperSpecificProjectSettingsComponent +import com.intellij.idea.plugin.hybris.settings.HybrisProjectSettingsComponent +import com.intellij.openapi.options.BoundSearchableConfigurable +import com.intellij.openapi.options.ConfigurableProvider +import com.intellij.openapi.project.Project +import com.intellij.ui.dsl.builder.bindSelected +import com.intellij.ui.dsl.builder.panel +import com.intellij.ui.layout.selected +import javax.swing.JCheckBox + +class BeanSystemConfigurableProvider(val project: Project) : ConfigurableProvider() { + + override fun canCreateConfigurable() = HybrisProjectSettingsComponent.getInstance(project).isHybrisProject() + override fun createConfigurable() = SettingsConfigurable(project) + + class SettingsConfigurable(private val project: Project) : BoundSearchableConfigurable( + message("hybris.settings.project.bs.title"), "[y] SAP Commerce plugin Bean System configuration." + ) { + + private val settings = HybrisDeveloperSpecificProjectSettingsComponent.getInstance(project).state.beanSystemSettings + + private lateinit var foldingEnableCheckBox: JCheckBox + + override fun createPanel() = panel { + group("Code Folding") { + row { + foldingEnableCheckBox = checkBox("Enable code folding") + .bindSelected(settings.folding::enabled) + .component + } + row { + checkBox("Use table-like folding for properties") + .bindSelected(settings.folding::tableLikeProperties) + .enabledIf(foldingEnableCheckBox.selected) + } + } + } + } +} \ No newline at end of file diff --git a/src/com/intellij/idea/plugin/hybris/system/bean/settings/BeanSystemSettings.kt b/src/com/intellij/idea/plugin/hybris/system/bean/settings/BeanSystemSettings.kt new file mode 100644 index 000000000..95b92f96e --- /dev/null +++ b/src/com/intellij/idea/plugin/hybris/system/bean/settings/BeanSystemSettings.kt @@ -0,0 +1,28 @@ +/* + * This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA. + * Copyright (C) 2019-2023 EPAM Systems and contributors + * + * 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 . + */ + +package com.intellij.idea.plugin.hybris.system.bean.settings + +data class BeanSystemSettings( + var folding: BeanSystemFoldingSettings = BeanSystemFoldingSettings(), +) + +data class BeanSystemFoldingSettings( + var enabled: Boolean = true, + var tableLikeProperties: Boolean = true, +)