Skip to content

Commit

Permalink
Merge pull request #89 from advanced-security/feature/show_hide_token…
Browse files Browse the repository at this point in the history
…_in_settings

Feature/show hide token in settings
  • Loading branch information
adrienpessu committed May 10, 2024
2 parents b00ed4b + c4fc202 commit 3893eb8
Showing 1 changed file with 73 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,66 @@ import com.intellij.ui.components.JBLabel
import com.intellij.ui.components.JBPasswordField
import com.intellij.ui.components.JBTextField
import com.intellij.util.ui.FormBuilder
import java.awt.GridBagConstraints

Check warning on line 7 in src/main/kotlin/com/github/adrienpessu/sarifviewer/configurable/SettingComponent.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import java.awt.GridBagLayout

Check warning on line 8 in src/main/kotlin/com/github/adrienpessu/sarifviewer/configurable/SettingComponent.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import javax.swing.JComponent
import javax.swing.JPanel
import javax.swing.JTextField
import javax.swing.JToggleButton


class SettingComponent {
private var myMainPanel: JPanel? = null
private val ghTokenText = JBPasswordField()
private var ghTokenTextField: JTextField =JBTextField()
private var ghTokenPasswordField: JTextField = JBPasswordField()
private val ghesHostnameText = JBTextField()
private val ghesTokenText = JBPasswordField()
private var ghesTokenTextField: JTextField = JBTextField()
private var ghesTokenPasswordField: JTextField = JBPasswordField()
private val toggleButton = JToggleButton("Show/Hide PAT")

private var isGhTokenVisible: Boolean = false

init {

ghTokenTextField.isVisible = isGhTokenVisible
ghesTokenTextField.isVisible = isGhTokenVisible
myMainPanel = FormBuilder.createFormBuilder()
.addLabeledComponent(JBLabel("GitHub.com PAT "), ghTokenText, 1, false)
.addSeparator()
.addLabeledComponent(JBLabel("GHES Hostname"), ghesHostnameText, 2, false)
.addLabeledComponent(JBLabel("GHES PAT"), ghesTokenText, 3, false)
.addComponentFillVertically(JPanel(), 0)
.getPanel()
.addComponent(JBLabel("GitHub.com PAT "))
.addComponent(ghTokenTextField)
.addComponent(ghTokenPasswordField)
.addSeparator(48)
.addComponent(JBLabel("GHES Hostname "))

Check warning on line 35 in src/main/kotlin/com/github/adrienpessu/sarifviewer/configurable/SettingComponent.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Incorrect string capitalization

String 'GHES Hostname ' is not properly capitalized. It should have sentence capitalization
.addComponent(ghesHostnameText)
.addComponent(JBLabel("GHES PAT "))
.addComponent(ghesTokenTextField)
.addComponent(ghesTokenPasswordField)
.addComponentFillVertically(JPanel(), 0)
.addSeparator()
.addLabeledComponent("", toggleButton, 1, false)
.panel

toggleButton.addActionListener {
isGhTokenVisible = !isGhTokenVisible
if (isGhTokenVisible) {
ghTokenTextField.text = ghTokenPasswordField.text
ghTokenTextField.isVisible = true
ghTokenPasswordField.isVisible = false

ghesTokenTextField.text = ghesTokenPasswordField.text
ghesTokenTextField.isVisible = true
ghesTokenPasswordField.isVisible = false
} else {
ghTokenPasswordField.text = ghTokenTextField.text
ghTokenTextField.isVisible = false
ghTokenPasswordField.isVisible = true

ghesTokenPasswordField.text = ghesTokenTextField.text
ghesTokenTextField.isVisible = false
ghesTokenPasswordField.isVisible = true
}
myMainPanel!!.revalidate() // Notify the layout manager
myMainPanel!!.repaint() // Redraw the components
}
}


Expand All @@ -30,30 +72,47 @@ class SettingComponent {
}

fun getPreferredFocusedComponent(): JComponent {
return ghTokenText
return if (toggleButton.isSelected) {
ghTokenTextField
} else {
ghTokenPasswordField
}
}

fun getGhTokenText(): String {
return ghTokenText.text
return if (isGhTokenVisible) {
ghTokenTextField.text
} else {
ghTokenPasswordField.text
}
}

fun setGhTokenText(newText: String) {
ghTokenText.text = newText
ghTokenTextField.text = newText
ghTokenPasswordField.text = newText
}

fun getGhesHostnameText(): String {
return ghesHostnameText.text
}

fun getGhesTokenText(): String {
return ghesTokenText.text
return if (isGhTokenVisible) {
ghesTokenTextField.text
} else {
ghesTokenPasswordField.text
}
}

fun setGhesHostnameText(newText: String) {
ghesHostnameText.text = newText
}

fun setGhesTokenText(newText: String) {
ghesTokenText.text = newText
ghesTokenTextField.text = newText
ghesTokenPasswordField.text = newText
}
}
}



0 comments on commit 3893eb8

Please sign in to comment.