Skip to content

Commit

Permalink
Add tooltip for mapping file
Browse files Browse the repository at this point in the history
  • Loading branch information
jedesroches committed Aug 11, 2023
1 parent 30f7148 commit 3a5bc62
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ch.kleis.lcaplugin.ide.imports.ecospold.settings.LCISettings
import ch.kleis.lcaplugin.imports.Importer
import ch.kleis.lcaplugin.imports.ecospold.EcospoldImporter
import com.intellij.BundleBase
import com.intellij.icons.AllIcons
import com.intellij.ide.IdeBundle
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
Expand Down Expand Up @@ -80,6 +81,9 @@ class EcospoldImportSettingsPanel(
methodNameField = null

val mappingFile = createMappingFileComponent(settings)
mappingFile.label.icon = AllIcons.General.ContextHelp
mappingFile.label.toolTipText = MyBundle.message("lca.dialog.import.ecospold.lci.mappingFile.toolTip")
mappingFile.label.horizontalTextPosition = JBLabel.LEFT
mappingFileField = mappingFile.component
builder.addLabeledComponent(mappingFile.label, mappingFile.component)

Expand All @@ -89,11 +93,18 @@ class EcospoldImportSettingsPanel(
}


builder.addComponent(CheckBoxWithDescription(JBCheckBox(BundleBase.replaceMnemonicAmpersand(MyBundle.message("lca.dialog.import.units.label")), settings.importUnits).apply {
addItemListener { e ->
settings.importUnits = e.stateChange == ItemEvent.SELECTED
}
}, MyBundle.message("lca.dialog.import.units.desc")))
builder.addComponent(
CheckBoxWithDescription(
JBCheckBox(
BundleBase.replaceMnemonicAmpersand(MyBundle.message("lca.dialog.import.units.label")),
settings.importUnits
).apply {
addItemListener { e ->
settings.importUnits = e.stateChange == ItemEvent.SELECTED
}
}, MyBundle.message("lca.dialog.import.units.desc")
)
)
this.add(builder.panel)
}

Expand Down Expand Up @@ -132,7 +143,11 @@ class EcospoldImportSettingsPanel(
}
})

return LabeledComponent.create(pack, BundleBase.replaceMnemonicAmpersand(MyBundle.message("lca.dialog.import.package.label")), BorderLayout.WEST)
return LabeledComponent.create(
pack,
BundleBase.replaceMnemonicAmpersand(MyBundle.message("lca.dialog.import.package.label")),
BorderLayout.WEST
)
}

private fun createLocationComponent(): LabeledComponent<TextFieldWithBrowseButton> {
Expand All @@ -147,14 +162,23 @@ class EcospoldImportSettingsPanel(
val projectLocation: String = myProjectDirectory.toString()
myLocationField.text = projectLocation
val descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor()
myLocationField.addBrowseFolderListener(MyBundle.message("lca.dialog.import.root.folder.label"), MyBundle.message("lca.dialog.import.root.folder.desc"), null, descriptor)
myLocationField.addBrowseFolderListener(
MyBundle.message("lca.dialog.import.root.folder.label"),
MyBundle.message("lca.dialog.import.root.folder.desc"),
null,
descriptor
)
myLocationField.textField.addFocusListener(object : FocusAdapter() {
override fun focusLost(e: FocusEvent?) {
settings.rootFolder = myLocationField.textField.text
}
})

return LabeledComponent.create(myLocationField, BundleBase.replaceMnemonicAmpersand(IdeBundle.message("directory.project.location.label")), BorderLayout.WEST)
return LabeledComponent.create(
myLocationField,
BundleBase.replaceMnemonicAmpersand(IdeBundle.message("directory.project.location.label")),
BorderLayout.WEST
)
}


Expand All @@ -163,26 +187,29 @@ class EcospoldImportSettingsPanel(
val file = Path.of(settings.libraryFile)
myLocationField.text = if (file.isRegularFile() && file.exists()) file.toString() else ""
val descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor()
myLocationField.addBrowseFolderListener(MyBundle.message("lca.dialog.import.library.file.label"), MyBundle.message("lca.dialog.import.library.file.desc"), null, descriptor)
myLocationField.addBrowseFolderListener(
MyBundle.message("lca.dialog.import.library.file.label"),
MyBundle.message("lca.dialog.import.library.file.desc"),
null,
descriptor
)
fun checkLibName() {
val name = myLocationField.textField.text.lowercase()
if (name.takeLast(2) != "7z") {
warning.text = MyBundle.message("lca.dialog.import.ecospold.7zwarning")
} else {
when (settings) {
is LCIASettings ->
if (name.contains("lcia")) {
warning.text = ""
} else {
warning.text = MyBundle.message("lca.dialog.import.ecospold.lcia.warning")
}

is LCISettings ->
if (name.contains("lci")) {
warning.text = ""
} else {
warning.text = MyBundle.message("lca.dialog.import.ecospold.lci.warning")
}
is LCIASettings -> if (name.contains("lcia")) {
warning.text = ""
} else {
warning.text = MyBundle.message("lca.dialog.import.ecospold.lcia.warning")
}

is LCISettings -> if (name.contains("lci")) {
warning.text = ""
} else {
warning.text = MyBundle.message("lca.dialog.import.ecospold.lci.warning")
}
}
}
}
Expand All @@ -197,7 +224,11 @@ class EcospoldImportSettingsPanel(
checkLibName()
updateMethodModelFromLib()

return LabeledComponent.create(myLocationField, BundleBase.replaceMnemonicAmpersand(MyBundle.message("lca.dialog.import.library.file.label")), BorderLayout.WEST)
return LabeledComponent.create(
myLocationField,
BundleBase.replaceMnemonicAmpersand(MyBundle.message("lca.dialog.import.library.file.label")),
BorderLayout.WEST
)
}

private fun createMappingFileComponent(settings: LCISettings): LabeledComponent<TextFieldWithBrowseButton> {
Expand All @@ -206,7 +237,12 @@ class EcospoldImportSettingsPanel(
myMappingFileField.text = if (file.exists() && file.isRegularFile()) file.toString() else ""
val descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor()

myMappingFileField.addBrowseFolderListener(MyBundle.message("lca.dialog.import.ecospold.lci.mappingFile.label"), MyBundle.message("lca.dialog.import.ecospold.lci.mappingFile.desc"), null, descriptor)
myMappingFileField.addBrowseFolderListener(
MyBundle.message("lca.dialog.import.ecospold.lci.mappingFile.label"),
MyBundle.message("lca.dialog.import.ecospold.lci.mappingFile.desc"),
null,
descriptor
)

myMappingFileField.textField.document.addDocumentListener(object : DocumentAdapter() {
override fun textChanged(e: DocumentEvent) {
Expand Down Expand Up @@ -244,7 +280,8 @@ class EcospoldImportSettingsPanel(
}

override fun doValidate(): ValidationInfo? {
val genericValidations = listOf({ LcaImportDialog.validateRegularFile(settings.libraryFile, libField) }, { LcaImportDialog.validatePackageIsValid(settings.rootPackage, packageField) })
val genericValidations = listOf({ LcaImportDialog.validateRegularFile(settings.libraryFile, libField) },
{ LcaImportDialog.validatePackageIsValid(settings.rootPackage, packageField) })

@Suppress("MoveLambdaOutsideParentheses") val specificValidations = when (settings) {
is LCIASettings -> listOf(
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/messages/MyBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ lca.dialog.export.filename.label=File name
lca.dialog.export.warning=Result is too huge to be displayed, save it as file if you want.
lca.dialog.export.info=Save result in CSV file.
lca.dialog.export.tooltip=Right click to save content in CSV File.<br>You can copy/paste content to Excel too.
lca.dialog.import.ecospold.lci.mappingFile.label=Method Mapping File
lca.dialog.import.ecospold.lci.mappingFile.desc=A CSV file of an Ecoinvent "mapped" file for a specific method, if you wish to have automatic name/compartment/subcompartment conversion.
lca.dialog.import.ecospold.lci.mappingFile.label=Method Mapping File
lca.dialog.import.ecospold.lci.mappingFile.toolTip=Use this field with a `Mapped` file provided by Ecoinvent to automatically convert Elementary Exchange properties (name, compartment, etc) to those used by a certain method. Expected is a UTF-8 encoded CSV file generated from the original Ecoinvent excel sheet.
lca.dialog.import.ecospold.lci.builtinLibrary.label=Add builtin library import statement:

0 comments on commit 3a5bc62

Please sign in to comment.