Skip to content

Commit

Permalink
Add library type to import settings (no action for now).
Browse files Browse the repository at this point in the history
  • Loading branch information
jedesroches committed Jul 27, 2023
1 parent 6f1ca84 commit 7fe5dc1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -30,6 +31,12 @@ class EcospoldImportSettings : PersistentStateComponent<EcospoldImportSettings.S
state.LIBRARY_FILE = value
}

var libraryType: EcospoldLibraryType
get() = state.LIBRARY_TYPE
set(value) {
state.LIBRARY_TYPE = value
}

var rootFolder: String
get() = state.ROOT_FOLDER
set(value) {
Expand Down Expand Up @@ -63,6 +70,9 @@ class EcospoldImportSettings : PersistentStateComponent<EcospoldImportSettings.S
@JvmField
var LIBRARY_FILE: String = ""

@JvmField
var LIBRARY_TYPE: EcospoldLibraryType = EcospoldLibraryType.LCI

@JvmField
var ROOT_FOLDER: String = ProjectManager.getInstance().openProjects.firstOrNull()?.basePath ?: ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,23 @@ class EcospoldImportSettingsPanel(private val settings: EcospoldImportSettings)
private val methodNameModel = DefaultComboBoxModel<String>()
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, "",
Expand All @@ -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(
Expand Down Expand Up @@ -137,6 +135,23 @@ class EcospoldImportSettingsPanel(private val settings: EcospoldImportSettings)
)
}

private fun createLibraryTypeChoiceComponent(): LabeledComponent<ComboBox<EcospoldLibraryType>> {
val myComboBox = ComboBox<EcospoldLibraryType>()

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<TextFieldWithBrowseButton> {
val myLocationField = TextFieldWithBrowseButton()
Expand Down

0 comments on commit 7fe5dc1

Please sign in to comment.