From 7fe5dc145c41e66c66d051d7442834c86a2b36e9 Mon Sep 17 00:00:00 2001 From: Joachim Desroches Date: Thu, 27 Jul 2023 09:57:39 +0200 Subject: [PATCH] Add library type to import settings (no action for now). --- .../ecospold/EcospoldImportSettings.kt | 10 +++++ .../ecospold/EcospoldImportSettingsPanel.kt | 37 +++++++++++++------ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/ch/kleis/lcaplugin/ide/imports/ecospold/EcospoldImportSettings.kt b/src/main/kotlin/ch/kleis/lcaplugin/ide/imports/ecospold/EcospoldImportSettings.kt index 108dd75bc..8ffb17c04 100644 --- a/src/main/kotlin/ch/kleis/lcaplugin/ide/imports/ecospold/EcospoldImportSettings.kt +++ b/src/main/kotlin/ch/kleis/lcaplugin/ide/imports/ecospold/EcospoldImportSettings.kt @@ -1,5 +1,6 @@ package ch.kleis.lcaplugin.ide.imports.ecospold +import ch.kleis.lcaplugin.imports.ecospold.EcospoldLibraryType import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.PersistentStateComponent import com.intellij.openapi.components.State @@ -30,6 +31,12 @@ class EcospoldImportSettings : PersistentStateComponent() private val warning = JBLabel() - // FIXME - private val libType: EcospoldLibraryType = EcospoldLibraryType.LCIA - init { val builder = FormBuilder() + val locComp = createLocationComponent() builder.addLabeledComponent(locComp.label, locComp.component) + val packCom = createPackageComponent() packageField = packCom.component builder.addLabeledComponent(packCom.label, packCom.component) + + val libTypeComp = createLibraryTypeChoiceComponent() + builder.addLabeledComponent(libTypeComp.label, libTypeComp.component) + val libComp = createLibraryFileComponent() libField = libComp.component.textField builder.addLabeledComponent(libComp.label, libComp.component) + warning.foreground = JBColor.ORANGE val warningLabelled = LabeledComponent.create( warning, "", @@ -64,15 +68,9 @@ class EcospoldImportSettingsPanel(private val settings: EcospoldImportSettings) val methodLabelled = createMethodComponent() methodNameField = methodLabelled.component - when (libType) { - EcospoldLibraryType.LCIA -> { - builder.addLabeledComponent(methodLabelled.label, methodLabelled.component) - } + builder.addLabeledComponent(methodLabelled.component, methodLabelled.label) - EcospoldLibraryType.LCI -> { - // TODO: add component letting user choose the substance mapping - } - } + // TODO: add component letting user choose the substance mapping builder.addComponent( @@ -137,6 +135,23 @@ class EcospoldImportSettingsPanel(private val settings: EcospoldImportSettings) ) } + private fun createLibraryTypeChoiceComponent(): LabeledComponent> { + val myComboBox = ComboBox() + + EcospoldLibraryType.values().forEach(myComboBox::addItem) + myComboBox.addActionListener { + if (it.actionCommand == "comboBoxChanged") { + val newLibraryType = myComboBox.selectedItem as EcospoldLibraryType + settings.libraryType = newLibraryType + } + } + + return LabeledComponent.create( + myComboBox, + BundleBase.replaceMnemonicAmpersand("&Library type:"), + BorderLayout.EAST + ) + } private fun createLocationComponent(): LabeledComponent { val myLocationField = TextFieldWithBrowseButton()