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

UI improvements #20

Merged
merged 1 commit into from
Apr 29, 2024
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
15 changes: 9 additions & 6 deletions src/rider/main/kotlin/ru/ellizio/odatacliui/dialogs/CliDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ru.ellizio.odatacliui.UiBundle
import ru.ellizio.odatacliui.extensions.emptyText
import ru.ellizio.odatacliui.extensions.humanize
import ru.ellizio.odatacliui.models.CliDialogModel
import ru.ellizio.odatacliui.models.validators.CliDialogValidators
import javax.swing.JComponent

class CliDialog(private val model: CliDialogModel) : DialogWrapper(false) {
Expand Down Expand Up @@ -61,16 +62,16 @@ class CliDialog(private val model: CliDialogModel) : DialogWrapper(false) {
textField()
.align(AlignX.FILL)
.bindText(model.serviceName)
.validationOnInput(model.validator.serviceNameValidation())
.validationOnApply(model.validator.serviceNameValidation())
.validationOnInput(CliDialogValidators.serviceNameValidator())
.validationOnApply(CliDialogValidators.serviceNameValidator())
}
row(UiBundle.text("cli.metadata-source.row")) {
textFieldWithBrowseButton(fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFileDescriptor("xml"))
.align(AlignX.FILL)
.comment(UiBundle.text("cli.metadata-source.comment"), Int.MAX_VALUE)
.bindText(model.metadataUri)
.validationOnInput(model.validator.metadataUriValidation())
.validationOnApply(model.validator.metadataUriValidation())
.validationOnInput(CliDialogValidators.metadataUriValidator())
.validationOnApply(CliDialogValidators.metadataUriValidator())
}.bottomGap(BottomGap.SMALL)
row {
cell(tabbedPane)
Expand All @@ -91,8 +92,8 @@ class CliDialog(private val model: CliDialogModel) : DialogWrapper(false) {
.align(AlignX.FILL)
.comment(UiBundle.text("cli.namespace-prefix.comment"))
.bindText(model.namespacePrefix)
.validationOnInput(model.validator.namespacePrefixValidation())
.validationOnApply(model.validator.namespacePrefixValidation())
.validationOnInput(CliDialogValidators.namespacePrefixValidator())
.validationOnApply(CliDialogValidators.namespacePrefixValidator())
}
row("--excluded-operation-imports") {
textField()
Expand Down Expand Up @@ -158,6 +159,8 @@ class CliDialog(private val model: CliDialogModel) : DialogWrapper(false) {
.emptyText(UiBundle.text("cli.proxy.empty-text"))
.comment(UiBundle.text("cli.proxy.comment"))
.bindText(model.proxy)
.validationOnInput(CliDialogValidators.proxyValidator())
.validationOnApply(CliDialogValidators.proxyValidator())
}
}.apply {
registerValidators(disposable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.jetbrains.rd.ide.model.protocolModel
import com.jetbrains.rider.model.dotNetActiveRuntimeModel
import ru.ellizio.odatacliui.Constants
import ru.ellizio.odatacliui.extensions.dotnetAddPackageCommand
import ru.ellizio.odatacliui.models.validators.CliDialogModelValidator
import ru.ellizio.odatacliui.terminal.BatchCommandLine
import ru.ellizio.odatacliui.terminal.builders.BatchCommandLineBuilder
import com.jetbrains.rider.projectView.solution
Expand All @@ -19,8 +18,6 @@ private const val CONNECTED_SERVICES = "Connected Services"
private const val CSDL_NAME = "OData ServiceCsdl.xml"

class CliDialogModel(project: Project, private val actionMetadata: ActionMetadata) {
val validator = CliDialogModelValidator()

val odataCliTool: DotnetToolDefinition
val dotnetCliPath: String?

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ru.ellizio.odatacliui.models.validators

import com.intellij.openapi.ui.TextFieldWithBrowseButton
import com.intellij.openapi.ui.ValidationInfo
import com.intellij.ui.layout.ValidationInfoBuilder
import javax.swing.JTextField

object CliDialogValidators {
private val proxyRegex = Regex("^(\\w+\\\\\\w+(:\\w+)?@)?\\w+:\\d+\$")

fun serviceNameValidator(): ValidationInfoBuilder.(JTextField) -> ValidationInfo? = {
if (it.text.isBlank())
error("Service name must not be empty")
else if (it.text.startsWith(' '))
error("Service name must not start with a space")
else if (it.text.endsWith(' '))
error("Service name must not end with a space")
else
null
}

fun metadataUriValidator(): ValidationInfoBuilder.(TextFieldWithBrowseButton) -> ValidationInfo? = {
if (it.text.isBlank())
error("Metadata source must not be empty")
else
null
}

fun namespacePrefixValidator(): ValidationInfoBuilder.(JTextField) -> ValidationInfo? = {
if (it.text.contains(' '))
error("Namespace prefix must not contain spaces")
else
null
}

fun proxyValidator(): ValidationInfoBuilder.(JTextField) -> ValidationInfo? = {
if (!proxyRegex.matches(it.text))
error("Proxy must be in a valid format")
else
null
}
}
8 changes: 4 additions & 4 deletions src/rider/main/resources/UiBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ action.odatacliui.OpenCliDialogAction.text=OData Reference\u2026

# Dialog
cli.tab.generation=Generation Arguments
cli.tab.request=Generation Arguments
cli.cli-version.label=OData CLI Version:
cli.tab.request=Request Arguments
cli.cli-version.label=OData CLI version:
cli.cli-version.label-value.not-installed=Not installed
cli.cli-version.label-value.global=Global
cli.cli-version.comment=Not installed? Follow <a href='https://learn.microsoft.com/en-us/odata/odatacli/getting-started#install'>instruction</a>
cli.cli-version.comment=Not installed? Follow <a href='https://github.com/ellizio/rider--plugin--odata-cli-ui/blob/master/README.md#installation'>instructions</a>
cli.service-name.row=Service name:
cli.metadata-source.row=Metadata source:
cli.metadata-source.comment=The URI of the metadata document. The value must be set to a valid service document URI or a local file path
Expand All @@ -26,7 +26,7 @@ cli.ignore-unexpected-elements.comment=This flag indicates whether to ignore une
cli.upper-camel-case.comment=Transforms names (class and property names) to upper camel-case so that to better conform with C# naming conventions
cli.custom-headers.empty-text=Example: Header1:HeaderValue, Header2:HeaderValue
cli.custom-headers.comment=Headers that will get sent along with the request when fetching the metadata document from the service
cli.proxy.empty-text=Example: domain\\user:password@SERVER:PORT
cli.proxy.empty-text=Format: SERVER:PORT or domain\\user@SERVER:PORT or domain\\user:password@SERVER:PORT
cli.proxy.comment=Proxy settings
cli.ok-action-button.tooltip.not-installed=OData CLI not installed

Expand Down
Loading