From 6fb51ac62c060eb8d2a40a2e4c92a1a2d24cd00e Mon Sep 17 00:00:00 2001 From: teetangh Date: Tue, 6 Jun 2023 07:09:53 +0530 Subject: [PATCH 01/15] basic UI prototype --- .../intellij/tree/CouchbaseWindowContent.java | 4 +- .../tree/FunctionDeploymentDialog.java | 524 ++++++++++++++++++ 2 files changed, 527 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/couchbase/intellij/tree/FunctionDeploymentDialog.java diff --git a/src/main/java/com/couchbase/intellij/tree/CouchbaseWindowContent.java b/src/main/java/com/couchbase/intellij/tree/CouchbaseWindowContent.java index 920b3eb0..e17267dc 100644 --- a/src/main/java/com/couchbase/intellij/tree/CouchbaseWindowContent.java +++ b/src/main/java/com/couchbase/intellij/tree/CouchbaseWindowContent.java @@ -124,7 +124,7 @@ public void actionPerformed(@NotNull AnActionEvent e) { // Open menu code here JPopupMenu menu = new JPopupMenu(); JMenuItem item1 = new JMenuItem("New Project from Template"); - JMenuItem item2 = new JMenuItem("Test 2"); + JMenuItem item2 = new JMenuItem("Deploy Function"); menu.add(item1); menu.add(item2); @@ -135,6 +135,8 @@ public void actionPerformed(@NotNull AnActionEvent e) { item2.addActionListener(e2 -> { // Code for "Test 2" here + FunctionDeploymentDialog dialog = new FunctionDeploymentDialog(project); + dialog.show(); }); Component component = e.getInputEvent().getComponent(); diff --git a/src/main/java/com/couchbase/intellij/tree/FunctionDeploymentDialog.java b/src/main/java/com/couchbase/intellij/tree/FunctionDeploymentDialog.java new file mode 100644 index 00000000..6df66059 --- /dev/null +++ b/src/main/java/com/couchbase/intellij/tree/FunctionDeploymentDialog.java @@ -0,0 +1,524 @@ + +// This is the UI + +// First line - heading +// Function Scope(Bold) bucket.scope(small greyed out) info icon(on hover displays-A bucket.scope combination used for identifying functions belonging to the same group.) + +// Error label for this(by default when nothing is selected)-> Please specify a scope to which the function belongs. User should have Eventing Manage Scope Functions permission on this scope + +// Second line - two horizontal dropdown boxes +// 1. Select from available buckets (or *) 2. Select from scopes available in that bucket (The first scope gets selected automatically when the bucket is selected) + +// Third line - heading +// Listen to location (Bold) bucket.scope.collection (small greyed out) info icon(on hover displays-The function will listen to this resource for changes. Memcached buckets are not allowed.) + +// Error label for this(by default when nothing is selected)-> Please specify a source location for your function. User should have DCP Data Read permission on this keyspace + +// Fourth line - three horizontal dropdown boxes +// 1. Select from available buckets (or *) 2. Select from scopes available in that bucket (The first scope gets selected automatically when the bucket is selected) 3. Select from collections available in that scope (The first collection gets selected automatically when the scope is selected) + +// Fifth line - heading +// Eventing Storage (Bold) bucket.scope.collection (small greyed out) info icon(on hover displays-This resource is used to store system data and should not be used by other applications.) + +// Error label for this(by default when nothing is selected)-> Please specify a location to store Eventing data. User should have read/write permission on this keyspace + +// Sixth line - three horizontal dropdown boxes +// 1. Select from available buckets (or *) 2. Select from scopes available in that bucket (The first scope gets selected automatically when the bucket is selected) 3. Select from collections available in that scope (The first collection gets selected automatically when the scope is selected) + +// Seventh line - heading +// Function Name (Bold) + +// Eighth line - full line text box +// Text box for Function Name + +// Error label depends on text box validation + +// Ninth line - heading +// Deployment Feed Boundary(Bold) info icon(on hover The preferred Deployment time Feed Boundary for the function.) + +// Tenth line - 1 drop down box with 2 options +// The dropdown box should contain “Everything” and “From now” + +// Eleventh line - heading +// Description(bold) optional(text in small, grayed out and round braces) + +// Twelfth line - Text Area +// Text Area for big paragraph text writing (This is a text area not a text field) + +// Thirteenth line - Openable Settings. +// Settings(bold) +// There is a small right arrow before the word settings. On clicking the right menu. The form fill-up menu opens up +// { +// First line - heading +// System Log Level(Bold) , small info icon(on hover shows: Granularity of system events being captured in the log) + +// Second line - dropdown menu +// Dropdown menu contains: Info, Error, Warning, Debug and Trace + +// Info label - below dropdown menu +// “Application log file for this Function is at:” + +// Third Line - heading +// N1QL Consistency(bold) small info icon(on hover shows: Consistency level of N1QL statements in the function) + +// Fourth line - dropdown menu +// Dropdown menu contains: None and Request + +// Fifth Line - heading +// Workers(bold) small info icon(on hover shows: Number of workers per node to process the events. If no value is specified, a default value of 1 worker is used.) + +// Sixth Line - text field +// Text field can take only a natural number + +// Seventh line - heading +// Language compatibility (Bold) , small info icon(on hover shows: Language compatibility of the function) + +// Eighth line - dropdown menu +// Dropdown menu contains: 6.0.0, 6.5.0, 6.6.2 + +// Ninth Line - heading +// Script Timeout(bold) in seconds (small greyed out text) small info icon(on hover shows: Time after which the Function's execution will be timed out) + +// Tenth Line - text field +// Text field can take only a natural number (default initial value: 60) + +// Eleventh Line - heading +// Timer Context Max Size (bold) small info icon(on hover shows: Maximum allowed value of the Timer Context Size in Bytes. Takes effect immediately.) + +// Twelfth Line - text field +// Text field can take only a natural number (default initial value: 1024) +// } + +// Fourteen Line - Openable Settings. +// Binding Type (Bold left end of line) (Plus minus square buttons on the right end[plus adds a new binding type based on the dropdown menu, minus removes the last binding type]) +// Horizontal line separator. + +// Here we can add any number of 3 types of binding types[from the dropdown menu(s)]. The dropdown menu contains: +// Binding type(default unelectable greyed out), Bucket Alias, URL alias, constant alias. + +// { +// 1. if it is bucket alias, then first line is bucket alias(the dropdown menu itself), and textfield with placeholder text of “alias name” +// Second line contains heading Bucket(bold) bucket.scope.collection (small greyed out) Access(bold) +// Third line contains 3 dropdown boxes for bucket scope collection respectively. And 4th dropdown for Access(2 options of “read only” and “read and write” ) + +// 2. If its URL alias, then first line is URL alias(the dropdown menu itself), and two textfields containing placeholder texts of “Alias name..” and “URL...” Respectively. +// The next line contains two checkboxes: 1. allow cookies 2. validate SSL certificate +// The next line contains dropdown menu of: 1. no auth 2. basic 3. bearer4. digest +// { +// 2a. if the user chooses, basic, the same line as dropdown menu should have two textfields containing placeholder texts of “Username..” and “password…” Respectively. +// 2b. if the user chooses, bearer, the same line as dropdown menu should have 1 textfield containing placeholder texts of “bearer key..” +// 2c. if the user chooses, digest, the same line as dropdown menu should have two textfields containing placeholder texts of “Username..” and “password…” Respectively. +// } + +// if it is constant alias, the first line is constant alias(the dropdown menu itself) and two textfields containing placeholder texts of “Username..” and “password…” Respectively. +// } +package com.couchbase.intellij.tree; + +import java.awt.Color; +import java.awt.Font; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.Set; + +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.JTextField; + +import org.jetbrains.annotations.Nullable; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.DialogWrapper; + +public class FunctionDeploymentDialog extends DialogWrapper { + private Project project; + public Set buckets; + + private JLabel errorLabel; + + private JComboBox bucketComboBox; + private JComboBox scopeComboBox; + private JComboBox collectionComboBox; + private JComboBox deploymentFeedBoundaryComboBox; + private JComboBox systemLogsLevelComboBox; + private JComboBox n1qlConsistencyComboBox; + private JComboBox languageCompatibilityComboBox; + + private JTextField functionNameField; + private JTextArea functionDescriptionArea; + private JTextField workersField; + private JTextField scriptTimeoutField; + private JTextField timerContextMaxSizeField; + + private JPanel settingsPanel; + private JPanel bindingsPanel; + + private boolean settingsPanelExpanded = false; + + public FunctionDeploymentDialog(@Nullable Project project) { + super(project); + this.project = project; + this.buckets = null; + setTitle("Deploy as a Couchbase Function"); + setSize(1000, 2000); + setResizable(true); + init(); + } + + @Nullable + @Override + protected JComponent createCenterPanel() { + JPanel panel = new JPanel(new GridBagLayout()); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.insets = new Insets(5, 5, 5, 5); + gbc.anchor = GridBagConstraints.WEST; + + // Function Scope label + JLabel functionScopeLabel = new JLabel("Function Scope"); + functionScopeLabel.setFont(functionScopeLabel.getFont().deriveFont(Font.BOLD)); + gbc.gridx = 0; + gbc.gridy = 0; + panel.add(functionScopeLabel, gbc); + + JLabel functionScopeInfoLabel = new JLabel("bucket.scope"); + functionScopeInfoLabel.setForeground(Color.GRAY); + gbc.gridx = 1; + gbc.gridy = 0; + panel.add(functionScopeInfoLabel, gbc); + + bucketComboBox = new JComboBox<>(); + bucketComboBox.addActionListener(e -> updateScopes()); + gbc.gridx = 0; + gbc.gridy = 1; + panel.add(bucketComboBox, gbc); + + scopeComboBox = new JComboBox<>(); + scopeComboBox.setEnabled(false); + gbc.gridx = 1; + gbc.gridy = 1; + panel.add(scopeComboBox, gbc); + + // Function Scope error label + + errorLabel = new JLabel( + "Please specify a scope to which the function belongs. User should have Eventing Manage Scope Functions permission on this scope"); + errorLabel.setForeground(Color.RED); + gbc.gridx = 0; + gbc.gridy = 2; + gbc.gridwidth = 3; + panel.add(errorLabel, gbc); + + // Listen to location label + JLabel listenToLocationLabel = new JLabel("Listen to location"); + listenToLocationLabel.setFont(listenToLocationLabel.getFont().deriveFont(Font.BOLD)); + gbc.gridx = 0; + gbc.gridy = 3; + panel.add(listenToLocationLabel, gbc); + + JLabel listenToLocationInfoLabel = new JLabel("bucket.scope.collection"); + listenToLocationInfoLabel.setForeground(Color.GRAY); + gbc.gridx = 1; + gbc.gridy = 3; + panel.add(listenToLocationInfoLabel, gbc); + + bucketComboBox = new JComboBox<>(); + bucketComboBox.addActionListener(e -> updateScopes()); + gbc.gridx = 0; + gbc.gridy = 4; + panel.add(bucketComboBox, gbc); + + scopeComboBox = new JComboBox<>(); + scopeComboBox.setEnabled(false); + gbc.gridx = 1; + gbc.gridy = 4; + panel.add(scopeComboBox, gbc); + + collectionComboBox = new JComboBox<>(); + collectionComboBox.setEnabled(false); + gbc.gridx = 2; + gbc.gridy = 4; + panel.add(collectionComboBox, gbc); + + // Listen to location error label + errorLabel = new JLabel( + "Please specify a source location for your function. User should have DCP Data Read permission on this keyspace"); + errorLabel.setForeground(Color.RED); + gbc.gridx = 0; + gbc.gridy = 5; + gbc.gridwidth = 3; + panel.add(errorLabel, gbc); + + // Eventing Storage label + JLabel eventingStorageLabel = new JLabel("Eventing Storage"); + eventingStorageLabel.setFont(eventingStorageLabel.getFont().deriveFont(Font.BOLD)); + gbc.gridx = 0; + gbc.gridy = 6; + panel.add(eventingStorageLabel, gbc); + + JLabel eventingStorageInfoLabel = new JLabel("bucket.scope.collection"); + eventingStorageInfoLabel.setForeground(Color.GRAY); + gbc.gridx = 1; + gbc.gridy = 6; + gbc.ipadx = 1; + panel.add(eventingStorageInfoLabel, gbc); + + bucketComboBox = new JComboBox<>(); + bucketComboBox.addActionListener(e -> updateScopes()); + gbc.gridx = 0; + gbc.gridy = 7; + panel.add(bucketComboBox, gbc); + + scopeComboBox = new JComboBox<>(); + scopeComboBox.setEnabled(false); + gbc.gridx = 1; + gbc.gridy = 7; + panel.add(scopeComboBox, gbc); + + collectionComboBox = new JComboBox<>(); + collectionComboBox.setEnabled(false); + gbc.gridx = 2; + gbc.gridy = 7; + panel.add(collectionComboBox, gbc); + + // Eventing Storage error label + errorLabel = new JLabel( + "Please specify a location to store Eventing data. User should have read/write permission on this keyspace"); + errorLabel.setForeground(Color.RED); + gbc.gridx = 0; + gbc.gridy = 8; + gbc.gridwidth = 3; + panel.add(errorLabel, gbc); + + // Eventing Storage info label + JLabel eventingStorageInfoLabel2 = new JLabel( + "System data stored in this location will have the document ID prefixed with eventing. Using a persistent bucket type is recommended."); + eventingStorageInfoLabel2.setForeground(Color.GRAY); + gbc.gridx = 0; + gbc.gridy = 9; + gbc.gridwidth = 3; + panel.add(eventingStorageInfoLabel2, gbc); + + // Function Name label and text field + JLabel functionNameLabel = new JLabel("Function Name"); + functionNameLabel.setFont(functionNameLabel.getFont().deriveFont(Font.BOLD)); + gbc.gridx = 0; + gbc.gridy = 10; + panel.add(functionNameLabel, gbc); + + gbc.gridx = 0; + gbc.gridy = 11; + functionNameField = new JTextField(20); + panel.add(functionNameField, gbc); + + // Deployment Feed Boundary label and combo box + // TODO: Add label and combo box for selecting deployment feed boundary + JLabel deploymentFeedBoundaryLabel = new JLabel("Deployment Feed Boundary"); + deploymentFeedBoundaryLabel.setFont(deploymentFeedBoundaryLabel.getFont().deriveFont(Font.BOLD)); + gbc.gridx = 0; + gbc.gridy = 12; + panel.add(deploymentFeedBoundaryLabel, gbc); + + deploymentFeedBoundaryComboBox = new JComboBox<>(); + deploymentFeedBoundaryComboBox.addItem("Everything"); + deploymentFeedBoundaryComboBox.addItem("From Now"); + gbc.gridx = 0; + gbc.gridy = 13; + panel.add(deploymentFeedBoundaryComboBox, gbc); + + // Description label and text area + // TODO: Add label and text area for entering description + JLabel descriptionLabel = new JLabel("Description"); + descriptionLabel.setFont(descriptionLabel.getFont().deriveFont(Font.BOLD)); + gbc.gridx = 0; + gbc.gridy = 14; + panel.add(descriptionLabel, gbc); + + gbc.gridx = 0; + gbc.gridy = 15; + functionDescriptionArea = new JTextArea(5, 100); + panel.add(functionDescriptionArea, gbc); + + // Settings label and expandable panel + // Add a toggle button for the settings panel + JLabel settingsToggleButton = new JLabel("▶"); + settingsToggleButton.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + // Toggle the expanded state of the settings panel + settingsPanelExpanded = !settingsPanelExpanded; + + // Show or hide the settings panel based on its expanded state + if (settingsPanelExpanded) { + settingsToggleButton.setText("▼"); + settingsPanel.setVisible(true); + } else { + settingsToggleButton.setText("▶"); + settingsPanel.setVisible(false); + } + } + }); + gbc.gridx = 0; + gbc.gridy = 16; + panel.add(settingsToggleButton, gbc); + + // TODO: Add label and expandable panel for settings + JLabel settingsLabel = new JLabel("Settings"); + settingsLabel.setFont(settingsLabel.getFont().deriveFont(Font.BOLD)); + gbc.gridx = 1; + gbc.gridy = 16; + panel.add(settingsLabel, gbc); + + settingsPanel = new JPanel(new GridBagLayout()); + GridBagConstraints settingsGbc = new GridBagConstraints(); + settingsGbc.insets = new Insets(5, 5, 5, 5); + settingsGbc.anchor = GridBagConstraints.WEST; + + // System logs level label and combo box + JLabel systemLogsLevelLabel = new JLabel("System Logs Level"); + systemLogsLevelLabel.setFont(systemLogsLevelLabel.getFont().deriveFont(Font.BOLD)); + settingsGbc.gridx = 0; + settingsGbc.gridy = 0; + settingsPanel.add(systemLogsLevelLabel, settingsGbc); + + systemLogsLevelComboBox = new JComboBox<>(); + systemLogsLevelComboBox.addItem("Error"); + systemLogsLevelComboBox.addItem("Warning"); + systemLogsLevelComboBox.addItem("Info"); + systemLogsLevelComboBox.addItem("Debug"); + + settingsGbc.gridx = 0; + settingsGbc.gridy = 1; + settingsGbc.gridwidth = 2; + settingsPanel.add(systemLogsLevelComboBox, settingsGbc); + + JLabel systemLogsLevelInfoLabel = new JLabel( + "Application logs file for this function is at:"); + systemLogsLevelInfoLabel.setForeground(Color.GRAY); + settingsGbc.gridx = 0; + settingsGbc.gridy = 2; + settingsGbc.gridwidth = 2; + settingsPanel.add(systemLogsLevelInfoLabel, settingsGbc); + + // N1QL Consistency label and combo box + JLabel n1QLConsistencyLabel = new JLabel("N1QL Consistency"); + n1QLConsistencyLabel.setFont(n1QLConsistencyLabel.getFont().deriveFont(Font.BOLD)); + settingsGbc.gridx = 0; + settingsGbc.gridy = 3; + settingsPanel.add(n1QLConsistencyLabel, settingsGbc); + + n1qlConsistencyComboBox = new JComboBox<>(); + n1qlConsistencyComboBox.addItem("Error"); + n1qlConsistencyComboBox.addItem("Warning"); + + settingsGbc.gridx = 0; + settingsGbc.gridy = 4; + settingsGbc.gridwidth = 2; + settingsPanel.add(n1qlConsistencyComboBox, settingsGbc); + + // Workers label and text field + JLabel workersLabel = new JLabel("Workers"); + workersLabel.setFont(workersLabel.getFont().deriveFont(Font.BOLD)); + settingsGbc.gridx = 0; + settingsGbc.gridy = 5; + settingsPanel.add(workersLabel, settingsGbc); + + workersField = new JTextField(20); + settingsGbc.gridx = 0; + settingsGbc.gridy = 6; + settingsGbc.gridwidth = 2; + settingsPanel.add(workersField, settingsGbc); + + // Language Compatibility label and combo box + JLabel languageCompatibilityLabel = new JLabel("Language Compatibility"); + languageCompatibilityLabel.setFont(languageCompatibilityLabel.getFont().deriveFont(Font.BOLD)); + settingsGbc.gridx = 0; + settingsGbc.gridy = 7; + settingsPanel.add(languageCompatibilityLabel, settingsGbc); + + languageCompatibilityComboBox = new JComboBox<>(); + languageCompatibilityComboBox.addItem("6.0.0"); + languageCompatibilityComboBox.addItem("6.5.0"); + languageCompatibilityComboBox.addItem("6.6.2"); + + settingsGbc.gridx = 0; + settingsGbc.gridy = 8; + settingsGbc.gridwidth = 2; + settingsPanel.add(languageCompatibilityComboBox, settingsGbc); + + // Script Timeout label and text field + JLabel scriptTimeoutLabel = new JLabel("Script Timeout"); + scriptTimeoutLabel.setFont(scriptTimeoutLabel.getFont().deriveFont(Font.BOLD)); + settingsGbc.gridx = 0; + settingsGbc.gridy = 9; + settingsPanel.add(scriptTimeoutLabel, settingsGbc); + + JLabel scriptTimeoutInfoLabel = new JLabel("in seconds."); + scriptTimeoutInfoLabel.setForeground(Color.GRAY); + settingsGbc.gridx = 1; + settingsGbc.gridy = 9; + settingsPanel.add(scriptTimeoutInfoLabel, settingsGbc); + + scriptTimeoutField = new JTextField(20); + settingsGbc.gridx = 0; + settingsGbc.gridy = 10; + settingsGbc.gridwidth = 2; + settingsPanel.add(scriptTimeoutField, settingsGbc); + + // Timer Context Timeout label and text field + JLabel timerContextMaxSizeLabel = new JLabel("Timer Context Max Size"); + timerContextMaxSizeLabel.setFont(timerContextMaxSizeLabel.getFont().deriveFont(Font.BOLD)); + settingsGbc.gridx = 0; + settingsGbc.gridy = 11; + settingsPanel.add(timerContextMaxSizeLabel, settingsGbc); + + timerContextMaxSizeField = new JTextField(20); + settingsGbc.gridx = 0; + settingsGbc.gridy = 12; + settingsGbc.gridwidth = 2; + settingsPanel.add(timerContextMaxSizeField, settingsGbc); + + gbc.gridx = 0; + gbc.gridy = 17; + panel.add(settingsPanel, gbc); + + // Binding Type label and expandable panel + // TODO: Add label and expandable panel for binding type + + return new JScrollPane(panel); + + } + + private void updateScopes() { + // Get selected bucket + String selectedBucket = (String) bucketComboBox.getSelectedItem(); + + // TODO: Get scopes for selected bucket and update scopeComboBox + // You can use the Couchbase Java SDK to get the list of scopes for the selected + // bucket + // For example: + // List scopes = + // cluster.bucket(selectedBucket).collections().getAllScopes(); + // Then you can update the scopeComboBox with the list of scopes + + // Enable scope combo box + scopeComboBox.setEnabled(true); + } + + public String getSelectedBucket() { + return (String) bucketComboBox.getSelectedItem(); + } + + public String getSelectedScope() { + return (String) scopeComboBox.getSelectedItem(); + } + + public String getFunctionName() { + return functionNameField.getText(); + } +} From 1c60c7e88d8cc7bf5b6fbce52cfed72a5286b893 Mon Sep 17 00:00:00 2001 From: teetangh Date: Tue, 6 Jun 2023 08:02:05 +0530 Subject: [PATCH 02/15] added tooltip texts, fixed description area, padding, scrolling --- .../tree/FunctionDeploymentDialog.java | 875 ++++++++++-------- 1 file changed, 491 insertions(+), 384 deletions(-) diff --git a/src/main/java/com/couchbase/intellij/tree/FunctionDeploymentDialog.java b/src/main/java/com/couchbase/intellij/tree/FunctionDeploymentDialog.java index 6df66059..9ab1492f 100644 --- a/src/main/java/com/couchbase/intellij/tree/FunctionDeploymentDialog.java +++ b/src/main/java/com/couchbase/intellij/tree/FunctionDeploymentDialog.java @@ -115,6 +115,7 @@ package com.couchbase.intellij.tree; import java.awt.Color; +import java.awt.Dimension; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; @@ -137,388 +138,494 @@ import com.intellij.openapi.ui.DialogWrapper; public class FunctionDeploymentDialog extends DialogWrapper { - private Project project; - public Set buckets; - - private JLabel errorLabel; - - private JComboBox bucketComboBox; - private JComboBox scopeComboBox; - private JComboBox collectionComboBox; - private JComboBox deploymentFeedBoundaryComboBox; - private JComboBox systemLogsLevelComboBox; - private JComboBox n1qlConsistencyComboBox; - private JComboBox languageCompatibilityComboBox; - - private JTextField functionNameField; - private JTextArea functionDescriptionArea; - private JTextField workersField; - private JTextField scriptTimeoutField; - private JTextField timerContextMaxSizeField; - - private JPanel settingsPanel; - private JPanel bindingsPanel; - - private boolean settingsPanelExpanded = false; - - public FunctionDeploymentDialog(@Nullable Project project) { - super(project); - this.project = project; - this.buckets = null; - setTitle("Deploy as a Couchbase Function"); - setSize(1000, 2000); - setResizable(true); - init(); - } - - @Nullable - @Override - protected JComponent createCenterPanel() { - JPanel panel = new JPanel(new GridBagLayout()); - GridBagConstraints gbc = new GridBagConstraints(); - gbc.insets = new Insets(5, 5, 5, 5); - gbc.anchor = GridBagConstraints.WEST; - - // Function Scope label - JLabel functionScopeLabel = new JLabel("Function Scope"); - functionScopeLabel.setFont(functionScopeLabel.getFont().deriveFont(Font.BOLD)); - gbc.gridx = 0; - gbc.gridy = 0; - panel.add(functionScopeLabel, gbc); - - JLabel functionScopeInfoLabel = new JLabel("bucket.scope"); - functionScopeInfoLabel.setForeground(Color.GRAY); - gbc.gridx = 1; - gbc.gridy = 0; - panel.add(functionScopeInfoLabel, gbc); - - bucketComboBox = new JComboBox<>(); - bucketComboBox.addActionListener(e -> updateScopes()); - gbc.gridx = 0; - gbc.gridy = 1; - panel.add(bucketComboBox, gbc); - - scopeComboBox = new JComboBox<>(); - scopeComboBox.setEnabled(false); - gbc.gridx = 1; - gbc.gridy = 1; - panel.add(scopeComboBox, gbc); - - // Function Scope error label - - errorLabel = new JLabel( - "Please specify a scope to which the function belongs. User should have Eventing Manage Scope Functions permission on this scope"); - errorLabel.setForeground(Color.RED); - gbc.gridx = 0; - gbc.gridy = 2; - gbc.gridwidth = 3; - panel.add(errorLabel, gbc); - - // Listen to location label - JLabel listenToLocationLabel = new JLabel("Listen to location"); - listenToLocationLabel.setFont(listenToLocationLabel.getFont().deriveFont(Font.BOLD)); - gbc.gridx = 0; - gbc.gridy = 3; - panel.add(listenToLocationLabel, gbc); - - JLabel listenToLocationInfoLabel = new JLabel("bucket.scope.collection"); - listenToLocationInfoLabel.setForeground(Color.GRAY); - gbc.gridx = 1; - gbc.gridy = 3; - panel.add(listenToLocationInfoLabel, gbc); - - bucketComboBox = new JComboBox<>(); - bucketComboBox.addActionListener(e -> updateScopes()); - gbc.gridx = 0; - gbc.gridy = 4; - panel.add(bucketComboBox, gbc); - - scopeComboBox = new JComboBox<>(); - scopeComboBox.setEnabled(false); - gbc.gridx = 1; - gbc.gridy = 4; - panel.add(scopeComboBox, gbc); - - collectionComboBox = new JComboBox<>(); - collectionComboBox.setEnabled(false); - gbc.gridx = 2; - gbc.gridy = 4; - panel.add(collectionComboBox, gbc); - - // Listen to location error label - errorLabel = new JLabel( - "Please specify a source location for your function. User should have DCP Data Read permission on this keyspace"); - errorLabel.setForeground(Color.RED); - gbc.gridx = 0; - gbc.gridy = 5; - gbc.gridwidth = 3; - panel.add(errorLabel, gbc); - - // Eventing Storage label - JLabel eventingStorageLabel = new JLabel("Eventing Storage"); - eventingStorageLabel.setFont(eventingStorageLabel.getFont().deriveFont(Font.BOLD)); - gbc.gridx = 0; - gbc.gridy = 6; - panel.add(eventingStorageLabel, gbc); - - JLabel eventingStorageInfoLabel = new JLabel("bucket.scope.collection"); - eventingStorageInfoLabel.setForeground(Color.GRAY); - gbc.gridx = 1; - gbc.gridy = 6; - gbc.ipadx = 1; - panel.add(eventingStorageInfoLabel, gbc); - - bucketComboBox = new JComboBox<>(); - bucketComboBox.addActionListener(e -> updateScopes()); - gbc.gridx = 0; - gbc.gridy = 7; - panel.add(bucketComboBox, gbc); - - scopeComboBox = new JComboBox<>(); - scopeComboBox.setEnabled(false); - gbc.gridx = 1; - gbc.gridy = 7; - panel.add(scopeComboBox, gbc); - - collectionComboBox = new JComboBox<>(); - collectionComboBox.setEnabled(false); - gbc.gridx = 2; - gbc.gridy = 7; - panel.add(collectionComboBox, gbc); - - // Eventing Storage error label - errorLabel = new JLabel( - "Please specify a location to store Eventing data. User should have read/write permission on this keyspace"); - errorLabel.setForeground(Color.RED); - gbc.gridx = 0; - gbc.gridy = 8; - gbc.gridwidth = 3; - panel.add(errorLabel, gbc); - - // Eventing Storage info label - JLabel eventingStorageInfoLabel2 = new JLabel( - "System data stored in this location will have the document ID prefixed with eventing. Using a persistent bucket type is recommended."); - eventingStorageInfoLabel2.setForeground(Color.GRAY); - gbc.gridx = 0; - gbc.gridy = 9; - gbc.gridwidth = 3; - panel.add(eventingStorageInfoLabel2, gbc); - - // Function Name label and text field - JLabel functionNameLabel = new JLabel("Function Name"); - functionNameLabel.setFont(functionNameLabel.getFont().deriveFont(Font.BOLD)); - gbc.gridx = 0; - gbc.gridy = 10; - panel.add(functionNameLabel, gbc); - - gbc.gridx = 0; - gbc.gridy = 11; - functionNameField = new JTextField(20); - panel.add(functionNameField, gbc); - - // Deployment Feed Boundary label and combo box - // TODO: Add label and combo box for selecting deployment feed boundary - JLabel deploymentFeedBoundaryLabel = new JLabel("Deployment Feed Boundary"); - deploymentFeedBoundaryLabel.setFont(deploymentFeedBoundaryLabel.getFont().deriveFont(Font.BOLD)); - gbc.gridx = 0; - gbc.gridy = 12; - panel.add(deploymentFeedBoundaryLabel, gbc); - - deploymentFeedBoundaryComboBox = new JComboBox<>(); - deploymentFeedBoundaryComboBox.addItem("Everything"); - deploymentFeedBoundaryComboBox.addItem("From Now"); - gbc.gridx = 0; - gbc.gridy = 13; - panel.add(deploymentFeedBoundaryComboBox, gbc); - - // Description label and text area - // TODO: Add label and text area for entering description - JLabel descriptionLabel = new JLabel("Description"); - descriptionLabel.setFont(descriptionLabel.getFont().deriveFont(Font.BOLD)); - gbc.gridx = 0; - gbc.gridy = 14; - panel.add(descriptionLabel, gbc); - - gbc.gridx = 0; - gbc.gridy = 15; - functionDescriptionArea = new JTextArea(5, 100); - panel.add(functionDescriptionArea, gbc); - - // Settings label and expandable panel - // Add a toggle button for the settings panel - JLabel settingsToggleButton = new JLabel("▶"); - settingsToggleButton.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - // Toggle the expanded state of the settings panel - settingsPanelExpanded = !settingsPanelExpanded; - - // Show or hide the settings panel based on its expanded state - if (settingsPanelExpanded) { - settingsToggleButton.setText("▼"); - settingsPanel.setVisible(true); - } else { - settingsToggleButton.setText("▶"); - settingsPanel.setVisible(false); - } - } - }); - gbc.gridx = 0; - gbc.gridy = 16; - panel.add(settingsToggleButton, gbc); - - // TODO: Add label and expandable panel for settings - JLabel settingsLabel = new JLabel("Settings"); - settingsLabel.setFont(settingsLabel.getFont().deriveFont(Font.BOLD)); - gbc.gridx = 1; - gbc.gridy = 16; - panel.add(settingsLabel, gbc); - - settingsPanel = new JPanel(new GridBagLayout()); - GridBagConstraints settingsGbc = new GridBagConstraints(); - settingsGbc.insets = new Insets(5, 5, 5, 5); - settingsGbc.anchor = GridBagConstraints.WEST; - - // System logs level label and combo box - JLabel systemLogsLevelLabel = new JLabel("System Logs Level"); - systemLogsLevelLabel.setFont(systemLogsLevelLabel.getFont().deriveFont(Font.BOLD)); - settingsGbc.gridx = 0; - settingsGbc.gridy = 0; - settingsPanel.add(systemLogsLevelLabel, settingsGbc); - - systemLogsLevelComboBox = new JComboBox<>(); - systemLogsLevelComboBox.addItem("Error"); - systemLogsLevelComboBox.addItem("Warning"); - systemLogsLevelComboBox.addItem("Info"); - systemLogsLevelComboBox.addItem("Debug"); - - settingsGbc.gridx = 0; - settingsGbc.gridy = 1; - settingsGbc.gridwidth = 2; - settingsPanel.add(systemLogsLevelComboBox, settingsGbc); - - JLabel systemLogsLevelInfoLabel = new JLabel( - "Application logs file for this function is at:"); - systemLogsLevelInfoLabel.setForeground(Color.GRAY); - settingsGbc.gridx = 0; - settingsGbc.gridy = 2; - settingsGbc.gridwidth = 2; - settingsPanel.add(systemLogsLevelInfoLabel, settingsGbc); - - // N1QL Consistency label and combo box - JLabel n1QLConsistencyLabel = new JLabel("N1QL Consistency"); - n1QLConsistencyLabel.setFont(n1QLConsistencyLabel.getFont().deriveFont(Font.BOLD)); - settingsGbc.gridx = 0; - settingsGbc.gridy = 3; - settingsPanel.add(n1QLConsistencyLabel, settingsGbc); - - n1qlConsistencyComboBox = new JComboBox<>(); - n1qlConsistencyComboBox.addItem("Error"); - n1qlConsistencyComboBox.addItem("Warning"); - - settingsGbc.gridx = 0; - settingsGbc.gridy = 4; - settingsGbc.gridwidth = 2; - settingsPanel.add(n1qlConsistencyComboBox, settingsGbc); - - // Workers label and text field - JLabel workersLabel = new JLabel("Workers"); - workersLabel.setFont(workersLabel.getFont().deriveFont(Font.BOLD)); - settingsGbc.gridx = 0; - settingsGbc.gridy = 5; - settingsPanel.add(workersLabel, settingsGbc); - - workersField = new JTextField(20); - settingsGbc.gridx = 0; - settingsGbc.gridy = 6; - settingsGbc.gridwidth = 2; - settingsPanel.add(workersField, settingsGbc); - - // Language Compatibility label and combo box - JLabel languageCompatibilityLabel = new JLabel("Language Compatibility"); - languageCompatibilityLabel.setFont(languageCompatibilityLabel.getFont().deriveFont(Font.BOLD)); - settingsGbc.gridx = 0; - settingsGbc.gridy = 7; - settingsPanel.add(languageCompatibilityLabel, settingsGbc); - - languageCompatibilityComboBox = new JComboBox<>(); - languageCompatibilityComboBox.addItem("6.0.0"); - languageCompatibilityComboBox.addItem("6.5.0"); - languageCompatibilityComboBox.addItem("6.6.2"); - - settingsGbc.gridx = 0; - settingsGbc.gridy = 8; - settingsGbc.gridwidth = 2; - settingsPanel.add(languageCompatibilityComboBox, settingsGbc); - - // Script Timeout label and text field - JLabel scriptTimeoutLabel = new JLabel("Script Timeout"); - scriptTimeoutLabel.setFont(scriptTimeoutLabel.getFont().deriveFont(Font.BOLD)); - settingsGbc.gridx = 0; - settingsGbc.gridy = 9; - settingsPanel.add(scriptTimeoutLabel, settingsGbc); - - JLabel scriptTimeoutInfoLabel = new JLabel("in seconds."); - scriptTimeoutInfoLabel.setForeground(Color.GRAY); - settingsGbc.gridx = 1; - settingsGbc.gridy = 9; - settingsPanel.add(scriptTimeoutInfoLabel, settingsGbc); - - scriptTimeoutField = new JTextField(20); - settingsGbc.gridx = 0; - settingsGbc.gridy = 10; - settingsGbc.gridwidth = 2; - settingsPanel.add(scriptTimeoutField, settingsGbc); - - // Timer Context Timeout label and text field - JLabel timerContextMaxSizeLabel = new JLabel("Timer Context Max Size"); - timerContextMaxSizeLabel.setFont(timerContextMaxSizeLabel.getFont().deriveFont(Font.BOLD)); - settingsGbc.gridx = 0; - settingsGbc.gridy = 11; - settingsPanel.add(timerContextMaxSizeLabel, settingsGbc); - - timerContextMaxSizeField = new JTextField(20); - settingsGbc.gridx = 0; - settingsGbc.gridy = 12; - settingsGbc.gridwidth = 2; - settingsPanel.add(timerContextMaxSizeField, settingsGbc); - - gbc.gridx = 0; - gbc.gridy = 17; - panel.add(settingsPanel, gbc); - - // Binding Type label and expandable panel - // TODO: Add label and expandable panel for binding type - - return new JScrollPane(panel); - - } - - private void updateScopes() { - // Get selected bucket - String selectedBucket = (String) bucketComboBox.getSelectedItem(); - - // TODO: Get scopes for selected bucket and update scopeComboBox - // You can use the Couchbase Java SDK to get the list of scopes for the selected - // bucket - // For example: - // List scopes = - // cluster.bucket(selectedBucket).collections().getAllScopes(); - // Then you can update the scopeComboBox with the list of scopes - - // Enable scope combo box - scopeComboBox.setEnabled(true); - } - - public String getSelectedBucket() { - return (String) bucketComboBox.getSelectedItem(); - } - - public String getSelectedScope() { - return (String) scopeComboBox.getSelectedItem(); - } - - public String getFunctionName() { - return functionNameField.getText(); - } + private Project project; + public Set buckets; + + private JLabel errorLabel; + + private JComboBox bucketComboBox; + private JComboBox scopeComboBox; + private JComboBox collectionComboBox; + private JComboBox deploymentFeedBoundaryComboBox; + private JComboBox systemLogsLevelComboBox; + private JComboBox n1qlConsistencyComboBox; + private JComboBox languageCompatibilityComboBox; + + private JTextField functionNameField; + private JTextArea functionDescriptionArea; + private JTextField workersField; + private JTextField scriptTimeoutField; + private JTextField timerContextMaxSizeField; + + private JPanel settingsPanel; + private JPanel bindingsPanel; + + private boolean settingsPanelExpanded = false; + + public FunctionDeploymentDialog(@Nullable Project project) { + super(project); + this.project = project; + this.buckets = null; + setTitle("Deploy as a Couchbase Function"); + setSize(1000, 2000); + setResizable(true); + init(); + } + + @Nullable + @Override + protected JComponent createCenterPanel() { + JPanel panel = new JPanel(new GridBagLayout()); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.insets = new Insets(5, 10, 5, 10); + gbc.anchor = GridBagConstraints.WEST; + + // Function Scope label + JLabel functionScopeLabel = new JLabel("Function Scope"); + functionScopeLabel.setFont(functionScopeLabel.getFont().deriveFont(Font.BOLD)); + gbc.gridx = 0; + gbc.gridy = 0; + panel.add(functionScopeLabel, gbc); + + JLabel functionScopeInfoLabel = new JLabel("bucket.scope"); + functionScopeInfoLabel.setForeground(Color.GRAY); + gbc.gridx = 1; + gbc.gridy = 0; + panel.add(functionScopeInfoLabel, gbc); + + bucketComboBox = new JComboBox<>(); + bucketComboBox.addActionListener(e -> updateScopes()); + gbc.gridx = 0; + gbc.gridy = 1; + panel.add(bucketComboBox, gbc); + + scopeComboBox = new JComboBox<>(); + scopeComboBox.setEnabled(false); + gbc.gridx = 1; + gbc.gridy = 1; + panel.add(scopeComboBox, gbc); + + // Function Scope error label + + errorLabel = new JLabel( + "Please specify a scope to which the function belongs. User should have Eventing Manage Scope Functions permission on this scope"); + errorLabel.setForeground(Color.RED); + gbc.gridx = 0; + gbc.gridy = 2; + gbc.gridwidth = 3; + panel.add(errorLabel, gbc); + + // Listen to location label + JLabel listenToLocationLabel = new JLabel("Listen to location"); + listenToLocationLabel.setFont(listenToLocationLabel.getFont().deriveFont(Font.BOLD)); + gbc.gridx = 0; + gbc.gridy = 3; + panel.add(listenToLocationLabel, gbc); + + JLabel listenToLocationInfoLabel = new JLabel("bucket.scope.collection"); + listenToLocationInfoLabel.setForeground(Color.GRAY); + gbc.gridx = 1; + gbc.gridy = 3; + panel.add(listenToLocationInfoLabel, gbc); + + bucketComboBox = new JComboBox<>(); + bucketComboBox.addActionListener(e -> updateScopes()); + gbc.gridx = 0; + gbc.gridy = 4; + panel.add(bucketComboBox, gbc); + + scopeComboBox = new JComboBox<>(); + scopeComboBox.setEnabled(false); + gbc.gridx = 1; + gbc.gridy = 4; + panel.add(scopeComboBox, gbc); + + collectionComboBox = new JComboBox<>(); + collectionComboBox.setEnabled(false); + gbc.gridx = 2; + gbc.gridy = 4; + panel.add(collectionComboBox, gbc); + + // Listen to location error label + errorLabel = new JLabel( + "Please specify a source location for your function. User should have DCP Data Read permission on this keyspace"); + errorLabel.setForeground(Color.RED); + gbc.gridx = 0; + gbc.gridy = 5; + gbc.gridwidth = 3; + panel.add(errorLabel, gbc); + + // Eventing Storage label + JLabel eventingStorageLabel = new JLabel("Eventing Storage"); + eventingStorageLabel.setFont(eventingStorageLabel.getFont().deriveFont(Font.BOLD)); + gbc.gridx = 0; + gbc.gridy = 6; + panel.add(eventingStorageLabel, gbc); + + JLabel eventingStorageInfoLabel = new JLabel("bucket.scope.collection"); + eventingStorageInfoLabel.setForeground(Color.GRAY); + gbc.gridx = 1; + gbc.gridy = 6; + gbc.gridwidth = 2; + panel.add(eventingStorageInfoLabel, gbc); + + bucketComboBox = new JComboBox<>(); + bucketComboBox.addActionListener(e -> updateScopes()); + gbc.gridx = 0; + gbc.gridy = 7; + panel.add(bucketComboBox, gbc); + + scopeComboBox = new JComboBox<>(); + scopeComboBox.setEnabled(false); + gbc.gridx = 1; + gbc.gridy = 7; + panel.add(scopeComboBox, gbc); + + collectionComboBox = new JComboBox<>(); + collectionComboBox.setEnabled(false); + gbc.gridx = 2; + gbc.gridy = 7; + panel.add(collectionComboBox, gbc); + + // Eventing Storage error label + errorLabel = new JLabel( + "Please specify a location to store Eventing data. User should have read/write permission on this keyspace"); + errorLabel.setForeground(Color.RED); + gbc.gridx = 0; + gbc.gridy = 8; + gbc.gridwidth = 3; + panel.add(errorLabel, gbc); + + // Function Name label and text field + JLabel functionNameLabel = new JLabel("Function Name"); + functionNameLabel.setFont(functionNameLabel.getFont().deriveFont(Font.BOLD)); + gbc.gridx = 0; + gbc.gridy = 9; + panel.add(functionNameLabel, gbc); + + functionNameField = new JTextField(20); + functionNameField.setToolTipText("Enter the name of the function."); + // functionNameField.getDocument().addDocumentListener(new DocumentListener() { + // @Override + // public void insertUpdate(DocumentEvent e) { + // validateFunctionName(); + // } + + // @Override + // public void removeUpdate(DocumentEvent e) { + // validateFunctionName(); + // } + + // @Override + // public void changedUpdate(DocumentEvent e) { + // validateFunctionName(); + // } + // }); + gbc.gridx = 0; + gbc.gridy = 10; + panel.add(functionNameField, gbc); + + // Deployment Feed Boundary label and combo box + JLabel deploymentFeedBoundaryLabel = new JLabel("Deployment Feed Boundary"); + deploymentFeedBoundaryLabel.setFont(deploymentFeedBoundaryLabel.getFont().deriveFont(Font.BOLD)); + deploymentFeedBoundaryLabel.setToolTipText( + "The preferred Deployment time Feed Boundary for the function."); + gbc.gridx = 0; + gbc.gridy = 11; + panel.add(deploymentFeedBoundaryLabel, gbc); + + deploymentFeedBoundaryComboBox = new JComboBox<>(); + deploymentFeedBoundaryComboBox.addItem("Everything"); + deploymentFeedBoundaryComboBox.addItem("From now"); + deploymentFeedBoundaryComboBox.setToolTipText( + "The preferred Deployment time Feed Boundary for the function."); + deploymentFeedBoundaryComboBox.addActionListener(e -> { + if (deploymentFeedBoundaryComboBox.getSelectedItem().equals("From now")) { + errorLabel.setText( + "Warning: Deploying with 'From now' will ignore all past mutations."); + } else { + errorLabel.setText(""); + } + }); + gbc.gridx = 0; + gbc.gridy = 12; + panel.add(deploymentFeedBoundaryComboBox, gbc); + + // Description label and text area + JLabel descriptionLabel = new JLabel("Description"); + descriptionLabel.setFont(descriptionLabel.getFont().deriveFont(Font.BOLD)); + descriptionLabel.setToolTipText("Enter a description for the function (optional)."); + descriptionLabel.setDisplayedMnemonic('D'); + descriptionLabel.setDisplayedMnemonicIndex(0); + descriptionLabel.setLabelFor(functionDescriptionArea); + descriptionLabel.setHorizontalAlignment(JTextField.LEFT); + descriptionLabel.setVerticalAlignment(JTextField.CENTER); + descriptionLabel.setHorizontalTextPosition(JTextField.RIGHT); + descriptionLabel.setVerticalTextPosition(JTextField.CENTER); + gbc.gridx = 0; + gbc.gridy = 13; + panel.add(descriptionLabel, gbc); + + functionDescriptionArea = new JTextArea(5, 100); + functionDescriptionArea.setLineWrap(true); + functionDescriptionArea.setWrapStyleWord(true); + functionDescriptionArea.setToolTipText("Enter a description for the function (optional)."); + + JScrollPane textJScrollPane = new JScrollPane(functionDescriptionArea); + textJScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + textJScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + textJScrollPane.setPreferredSize(new Dimension(800, 200)); + + gbc.gridx = 0; + gbc.gridy = 14; + panel.add(textJScrollPane, gbc); + + // Settings label and expandable panel + // Add a toggle button for the settings panel + JLabel settingsToggleButton = new JLabel("▶"); + settingsToggleButton.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + // Toggle the expanded state of the settings panel + settingsPanelExpanded = !settingsPanelExpanded; + + // Show or hide the settings panel based on its expanded state + if (settingsPanelExpanded) { + settingsToggleButton.setText("▼"); + settingsPanel.setVisible(true); + } else { + settingsToggleButton.setText("▶"); + settingsPanel.setVisible(false); + } + } + }); + gbc.gridx = 0; + gbc.gridy = 15; + panel.add(settingsToggleButton, gbc); + + // TODO: Add label and expandable panel for settings + JLabel settingsLabel = new JLabel("Settings"); + settingsLabel.setFont(settingsLabel.getFont().deriveFont(Font.BOLD)); + settingsLabel.setToolTipText("Click to expand/collapse the Settings section."); + gbc.gridx = 1; + gbc.gridy = 15; + panel.add(settingsLabel, gbc); + + settingsPanel = new JPanel(new GridBagLayout()); + GridBagConstraints settingsGbc = new GridBagConstraints(); + settingsGbc.insets = new Insets(5, 10, 5, 10); + settingsGbc.anchor = GridBagConstraints.WEST; + + // System logs level label and combo box + JLabel systemLogsLevelLabel = new JLabel("System Logs Level"); + systemLogsLevelLabel.setFont(systemLogsLevelLabel.getFont().deriveFont(Font.BOLD)); + systemLogsLevelLabel.setToolTipText( + "Granularity of system events being captured in the log."); + systemLogsLevelLabel.setDisplayedMnemonic('L'); + systemLogsLevelLabel.setDisplayedMnemonicIndex(7); + systemLogsLevelLabel.setLabelFor(systemLogsLevelComboBox); + systemLogsLevelLabel.setHorizontalAlignment(JTextField.LEFT); + systemLogsLevelLabel.setVerticalAlignment(JTextField.CENTER); + systemLogsLevelLabel.setHorizontalTextPosition(JTextField.RIGHT); + systemLogsLevelLabel.setVerticalTextPosition(JTextField.CENTER); + settingsGbc.gridx = 0; + settingsGbc.gridy = 0; + settingsPanel.add(systemLogsLevelLabel, settingsGbc); + + systemLogsLevelComboBox = new JComboBox<>(); + systemLogsLevelComboBox.addItem("Error"); + systemLogsLevelComboBox.addItem("Warning"); + systemLogsLevelComboBox.addItem("Info"); + systemLogsLevelComboBox.addItem("Debug"); + systemLogsLevelComboBox.addItem("Trace"); + systemLogsLevelComboBox.setToolTipText( + "Granularity of system events being captured in the log."); + settingsGbc.gridx = 0; + settingsGbc.gridy = 1; + settingsGbc.gridwidth = 2; + settingsPanel.add(systemLogsLevelComboBox, settingsGbc); + + JLabel systemLogsLevelInfoLabel = new JLabel( + "Application logs file for this function is at:"); + systemLogsLevelInfoLabel.setForeground(Color.GRAY); + settingsGbc.gridx = 0; + settingsGbc.gridy = 2; + settingsGbc.gridwidth = 2; + settingsPanel.add(systemLogsLevelInfoLabel, settingsGbc); + + // N1QL Consistency label and combo box + JLabel n1QLConsistencyLabel = new JLabel("N1QL Consistency"); + n1QLConsistencyLabel.setFont(n1QLConsistencyLabel.getFont().deriveFont(Font.BOLD)); + n1QLConsistencyLabel.setToolTipText( + "Consistency level of N1QL statements in the function."); + n1QLConsistencyLabel.setDisplayedMnemonic('N'); + n1QLConsistencyLabel.setDisplayedMnemonicIndex(0); + n1QLConsistencyLabel.setLabelFor(n1qlConsistencyComboBox); + n1QLConsistencyLabel.setHorizontalAlignment(JTextField.LEFT); + n1QLConsistencyLabel.setVerticalAlignment(JTextField.CENTER); + n1QLConsistencyLabel.setHorizontalTextPosition(JTextField.RIGHT); + n1QLConsistencyLabel.setVerticalTextPosition(JTextField.CENTER); + settingsGbc.gridx = 0; + settingsGbc.gridy = 3; + settingsPanel.add(n1QLConsistencyLabel, settingsGbc); + + n1qlConsistencyComboBox = new JComboBox<>(); + n1qlConsistencyComboBox.addItem("Not bounded"); + n1qlConsistencyComboBox.addItem("Request plus"); + n1qlConsistencyComboBox.setToolTipText( + "Consistency level of N1QL statements in the function."); + settingsGbc.gridx = 0; + settingsGbc.gridy = 4; + settingsGbc.gridwidth = 2; + settingsPanel.add(n1qlConsistencyComboBox, settingsGbc); + + // Workers label and text field + JLabel workersLabel = new JLabel("Workers"); + workersLabel.setFont(workersLabel.getFont().deriveFont(Font.BOLD)); + workersLabel.setToolTipText( + "Number of worker threads processing this function."); + workersLabel.setDisplayedMnemonic('W'); + workersLabel.setDisplayedMnemonicIndex(0); + workersLabel.setLabelFor(workersField); + workersLabel.setHorizontalAlignment(JTextField.LEFT); + workersLabel.setVerticalAlignment(JTextField.CENTER); + workersLabel.setHorizontalTextPosition(JTextField.RIGHT); + workersLabel.setVerticalTextPosition(JTextField.CENTER); + settingsGbc.gridx = 0; + settingsGbc.gridy = 5; + settingsPanel.add(workersLabel, settingsGbc); + + workersField = new JTextField(20); + workersField.setToolTipText( + "Number of worker threads processing this function."); + settingsGbc.gridx = 0; + settingsGbc.gridy = 6; + settingsGbc.gridwidth = 2; + settingsPanel.add(workersField, settingsGbc); + + // Language Compatibility label and combo box + JLabel languageCompatibilityLabel = new JLabel("Language Compatibility"); + languageCompatibilityLabel.setFont(languageCompatibilityLabel.getFont().deriveFont(Font.BOLD)); + languageCompatibilityLabel.setToolTipText( + "Language compatibility version for this function."); + languageCompatibilityLabel.setDisplayedMnemonic('C'); + languageCompatibilityLabel.setDisplayedMnemonicIndex(9); + languageCompatibilityLabel.setLabelFor(languageCompatibilityComboBox); + languageCompatibilityLabel.setHorizontalAlignment(JTextField.LEFT); + languageCompatibilityLabel.setVerticalAlignment(JTextField.CENTER); + languageCompatibilityLabel.setHorizontalTextPosition(JTextField.RIGHT); + languageCompatibilityLabel.setVerticalTextPosition(JTextField.CENTER); + settingsGbc.gridx = 0; + settingsGbc.gridy = 7; + settingsPanel.add(languageCompatibilityLabel, settingsGbc); + + languageCompatibilityComboBox = new JComboBox<>(); + languageCompatibilityComboBox.addItem("6.0.0"); + languageCompatibilityComboBox.addItem("6.5.0"); + languageCompatibilityComboBox.addItem("6.6.2"); + languageCompatibilityComboBox.setToolTipText( + "Language compatibility version for this function."); + settingsGbc.gridx = 0; + settingsGbc.gridy = 8; + settingsGbc.gridwidth = 2; + settingsPanel.add(languageCompatibilityComboBox, settingsGbc); + + // Script Timeout label and text field + JLabel scriptTimeoutLabel = new JLabel("Script Timeout"); + scriptTimeoutLabel.setFont(scriptTimeoutLabel.getFont().deriveFont(Font.BOLD)); + scriptTimeoutLabel.setToolTipText( + "Maximum execution time for each instance of the function."); + scriptTimeoutLabel.setDisplayedMnemonic('S'); + scriptTimeoutLabel.setDisplayedMnemonicIndex(0); + scriptTimeoutLabel.setLabelFor(scriptTimeoutField); + scriptTimeoutLabel.setHorizontalAlignment(JTextField.LEFT); + scriptTimeoutLabel.setVerticalAlignment(JTextField.CENTER); + scriptTimeoutLabel.setHorizontalTextPosition(JTextField.RIGHT); + scriptTimeoutLabel.setVerticalTextPosition(JTextField.CENTER); + settingsGbc.gridx = 0; + settingsGbc.gridy = 9; + settingsPanel.add(scriptTimeoutLabel, settingsGbc); + + JLabel scriptTimeoutInfoLabel = new JLabel("in seconds."); + scriptTimeoutInfoLabel.setForeground(Color.GRAY); + settingsGbc.gridx = 1; + settingsGbc.gridy = 9; + settingsPanel.add(scriptTimeoutInfoLabel, settingsGbc); + + scriptTimeoutField = new JTextField(20); + scriptTimeoutField.setToolTipText( + "Maximum execution time for each instance of the function."); + settingsGbc.gridx = 0; + settingsGbc.gridy = 10; + settingsGbc.gridwidth = 2; + settingsPanel.add(scriptTimeoutField, settingsGbc); + + // Timer Context Timeout label and text field + JLabel timerContextMaxSizeLabel = new JLabel("Timer Context Max Size"); + timerContextMaxSizeLabel.setFont(timerContextMaxSizeLabel.getFont().deriveFont(Font.BOLD)); + timerContextMaxSizeLabel.setToolTipText( + "Maximum size of context object for timers."); + timerContextMaxSizeLabel.setDisplayedMnemonic('T'); + timerContextMaxSizeLabel.setDisplayedMnemonicIndex(0); + timerContextMaxSizeLabel.setLabelFor(timerContextMaxSizeField); + timerContextMaxSizeLabel.setHorizontalAlignment(JTextField.LEFT); + timerContextMaxSizeLabel.setVerticalAlignment(JTextField.CENTER); + timerContextMaxSizeLabel.setHorizontalTextPosition(JTextField.RIGHT); + timerContextMaxSizeLabel.setVerticalTextPosition(JTextField.CENTER); + settingsGbc.gridx = 0; + settingsGbc.gridy = 11; + settingsPanel.add(timerContextMaxSizeLabel, settingsGbc); + + JLabel timerContextMaxSizeInfoLabel = new JLabel("in bytes."); + timerContextMaxSizeInfoLabel.setForeground(Color.GRAY); + settingsGbc.gridx = 1; + settingsGbc.gridy = 11; + settingsPanel.add(timerContextMaxSizeInfoLabel, settingsGbc); + + timerContextMaxSizeField = new JTextField(20); + timerContextMaxSizeField.setToolTipText( + "Maximum size of context object for timers."); + settingsGbc.gridx = 0; + settingsGbc.gridy = 12; + settingsGbc.gridwidth = 2; + settingsPanel.add(timerContextMaxSizeField, settingsGbc); + + gbc.gridx = 0; + gbc.gridy = 16; + panel.add(settingsPanel, gbc); + + // Binding Type label and expandable panel + // TODO: Add label and expandable panel for binding type + + return new JScrollPane(panel); + + } + + private void updateScopes() { + // Get selected bucket + String selectedBucket = (String) bucketComboBox.getSelectedItem(); + + // TODO: Get scopes for selected bucket and update scopeComboBox + // You can use the Couchbase Java SDK to get the list of scopes for the selected + // bucket + // For example: + // List scopes = + // cluster.bucket(selectedBucket).collections().getAllScopes(); + // Then you can update the scopeComboBox with the list of scopes + + // Enable scope combo box + scopeComboBox.setEnabled(true); + } + + public String getSelectedBucket() { + return (String) bucketComboBox.getSelectedItem(); + } + + public String getSelectedScope() { + return (String) scopeComboBox.getSelectedItem(); + } + + public String getFunctionName() { + return functionNameField.getText(); + } } From c9e88a08cdc42a1f6ae114aaffe9f58897c89a35 Mon Sep 17 00:00:00 2001 From: teetangh Date: Tue, 6 Jun 2023 18:54:20 +0530 Subject: [PATCH 03/15] added support for binding types: bucket, URL, Constant with authentication + refactored main code --- .../tree/FunctionDeploymentDialog.java | 508 ++++++++++++++++-- 1 file changed, 462 insertions(+), 46 deletions(-) diff --git a/src/main/java/com/couchbase/intellij/tree/FunctionDeploymentDialog.java b/src/main/java/com/couchbase/intellij/tree/FunctionDeploymentDialog.java index 9ab1492f..b3799ac3 100644 --- a/src/main/java/com/couchbase/intellij/tree/FunctionDeploymentDialog.java +++ b/src/main/java/com/couchbase/intellij/tree/FunctionDeploymentDialog.java @@ -115,6 +115,7 @@ package com.couchbase.intellij.tree; import java.awt.Color; +import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java.awt.GridBagConstraints; @@ -124,9 +125,13 @@ import java.awt.event.MouseEvent; import java.util.Set; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JButton; +import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JLabel; +import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; @@ -138,8 +143,8 @@ import com.intellij.openapi.ui.DialogWrapper; public class FunctionDeploymentDialog extends DialogWrapper { - private Project project; public Set buckets; + private JPanel mainPanel; private JLabel errorLabel; @@ -152,19 +157,20 @@ public class FunctionDeploymentDialog extends DialogWrapper { private JComboBox languageCompatibilityComboBox; private JTextField functionNameField; - private JTextArea functionDescriptionArea; private JTextField workersField; private JTextField scriptTimeoutField; private JTextField timerContextMaxSizeField; + private JTextArea functionDescriptionArea; + private JPanel settingsPanel; private JPanel bindingsPanel; private boolean settingsPanelExpanded = false; + private int bindingTypeCount = 0; public FunctionDeploymentDialog(@Nullable Project project) { super(project); - this.project = project; this.buckets = null; setTitle("Deploy as a Couchbase Function"); setSize(1000, 2000); @@ -175,7 +181,7 @@ public FunctionDeploymentDialog(@Nullable Project project) { @Nullable @Override protected JComponent createCenterPanel() { - JPanel panel = new JPanel(new GridBagLayout()); + mainPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(5, 10, 5, 10); gbc.anchor = GridBagConstraints.WEST; @@ -185,25 +191,25 @@ protected JComponent createCenterPanel() { functionScopeLabel.setFont(functionScopeLabel.getFont().deriveFont(Font.BOLD)); gbc.gridx = 0; gbc.gridy = 0; - panel.add(functionScopeLabel, gbc); + mainPanel.add(functionScopeLabel, gbc); JLabel functionScopeInfoLabel = new JLabel("bucket.scope"); functionScopeInfoLabel.setForeground(Color.GRAY); gbc.gridx = 1; gbc.gridy = 0; - panel.add(functionScopeInfoLabel, gbc); + mainPanel.add(functionScopeInfoLabel, gbc); bucketComboBox = new JComboBox<>(); bucketComboBox.addActionListener(e -> updateScopes()); gbc.gridx = 0; gbc.gridy = 1; - panel.add(bucketComboBox, gbc); + mainPanel.add(bucketComboBox, gbc); scopeComboBox = new JComboBox<>(); scopeComboBox.setEnabled(false); gbc.gridx = 1; gbc.gridy = 1; - panel.add(scopeComboBox, gbc); + mainPanel.add(scopeComboBox, gbc); // Function Scope error label @@ -213,38 +219,38 @@ protected JComponent createCenterPanel() { gbc.gridx = 0; gbc.gridy = 2; gbc.gridwidth = 3; - panel.add(errorLabel, gbc); + mainPanel.add(errorLabel, gbc); // Listen to location label JLabel listenToLocationLabel = new JLabel("Listen to location"); listenToLocationLabel.setFont(listenToLocationLabel.getFont().deriveFont(Font.BOLD)); gbc.gridx = 0; gbc.gridy = 3; - panel.add(listenToLocationLabel, gbc); + mainPanel.add(listenToLocationLabel, gbc); JLabel listenToLocationInfoLabel = new JLabel("bucket.scope.collection"); listenToLocationInfoLabel.setForeground(Color.GRAY); gbc.gridx = 1; gbc.gridy = 3; - panel.add(listenToLocationInfoLabel, gbc); + mainPanel.add(listenToLocationInfoLabel, gbc); bucketComboBox = new JComboBox<>(); bucketComboBox.addActionListener(e -> updateScopes()); gbc.gridx = 0; gbc.gridy = 4; - panel.add(bucketComboBox, gbc); + mainPanel.add(bucketComboBox, gbc); scopeComboBox = new JComboBox<>(); scopeComboBox.setEnabled(false); gbc.gridx = 1; gbc.gridy = 4; - panel.add(scopeComboBox, gbc); + mainPanel.add(scopeComboBox, gbc); collectionComboBox = new JComboBox<>(); collectionComboBox.setEnabled(false); gbc.gridx = 2; gbc.gridy = 4; - panel.add(collectionComboBox, gbc); + mainPanel.add(collectionComboBox, gbc); // Listen to location error label errorLabel = new JLabel( @@ -253,39 +259,39 @@ protected JComponent createCenterPanel() { gbc.gridx = 0; gbc.gridy = 5; gbc.gridwidth = 3; - panel.add(errorLabel, gbc); + mainPanel.add(errorLabel, gbc); // Eventing Storage label JLabel eventingStorageLabel = new JLabel("Eventing Storage"); eventingStorageLabel.setFont(eventingStorageLabel.getFont().deriveFont(Font.BOLD)); gbc.gridx = 0; gbc.gridy = 6; - panel.add(eventingStorageLabel, gbc); + mainPanel.add(eventingStorageLabel, gbc); JLabel eventingStorageInfoLabel = new JLabel("bucket.scope.collection"); eventingStorageInfoLabel.setForeground(Color.GRAY); gbc.gridx = 1; gbc.gridy = 6; gbc.gridwidth = 2; - panel.add(eventingStorageInfoLabel, gbc); + mainPanel.add(eventingStorageInfoLabel, gbc); bucketComboBox = new JComboBox<>(); bucketComboBox.addActionListener(e -> updateScopes()); gbc.gridx = 0; gbc.gridy = 7; - panel.add(bucketComboBox, gbc); + mainPanel.add(bucketComboBox, gbc); scopeComboBox = new JComboBox<>(); scopeComboBox.setEnabled(false); gbc.gridx = 1; gbc.gridy = 7; - panel.add(scopeComboBox, gbc); + mainPanel.add(scopeComboBox, gbc); collectionComboBox = new JComboBox<>(); collectionComboBox.setEnabled(false); gbc.gridx = 2; gbc.gridy = 7; - panel.add(collectionComboBox, gbc); + mainPanel.add(collectionComboBox, gbc); // Eventing Storage error label errorLabel = new JLabel( @@ -294,14 +300,14 @@ protected JComponent createCenterPanel() { gbc.gridx = 0; gbc.gridy = 8; gbc.gridwidth = 3; - panel.add(errorLabel, gbc); + mainPanel.add(errorLabel, gbc); // Function Name label and text field JLabel functionNameLabel = new JLabel("Function Name"); functionNameLabel.setFont(functionNameLabel.getFont().deriveFont(Font.BOLD)); gbc.gridx = 0; gbc.gridy = 9; - panel.add(functionNameLabel, gbc); + mainPanel.add(functionNameLabel, gbc); functionNameField = new JTextField(20); functionNameField.setToolTipText("Enter the name of the function."); @@ -323,7 +329,7 @@ protected JComponent createCenterPanel() { // }); gbc.gridx = 0; gbc.gridy = 10; - panel.add(functionNameField, gbc); + mainPanel.add(functionNameField, gbc); // Deployment Feed Boundary label and combo box JLabel deploymentFeedBoundaryLabel = new JLabel("Deployment Feed Boundary"); @@ -332,7 +338,7 @@ protected JComponent createCenterPanel() { "The preferred Deployment time Feed Boundary for the function."); gbc.gridx = 0; gbc.gridy = 11; - panel.add(deploymentFeedBoundaryLabel, gbc); + mainPanel.add(deploymentFeedBoundaryLabel, gbc); deploymentFeedBoundaryComboBox = new JComboBox<>(); deploymentFeedBoundaryComboBox.addItem("Everything"); @@ -349,7 +355,7 @@ protected JComponent createCenterPanel() { }); gbc.gridx = 0; gbc.gridy = 12; - panel.add(deploymentFeedBoundaryComboBox, gbc); + mainPanel.add(deploymentFeedBoundaryComboBox, gbc); // Description label and text area JLabel descriptionLabel = new JLabel("Description"); @@ -364,7 +370,7 @@ protected JComponent createCenterPanel() { descriptionLabel.setVerticalTextPosition(JTextField.CENTER); gbc.gridx = 0; gbc.gridy = 13; - panel.add(descriptionLabel, gbc); + mainPanel.add(descriptionLabel, gbc); functionDescriptionArea = new JTextArea(5, 100); functionDescriptionArea.setLineWrap(true); @@ -378,18 +384,18 @@ protected JComponent createCenterPanel() { gbc.gridx = 0; gbc.gridy = 14; - panel.add(textJScrollPane, gbc); + mainPanel.add(textJScrollPane, gbc); - // Settings label and expandable panel - // Add a toggle button for the settings panel + // Settings label and expandable mainPanel + // Add a toggle button for the settings mainPanel JLabel settingsToggleButton = new JLabel("▶"); settingsToggleButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - // Toggle the expanded state of the settings panel + // Toggle the expanded state of the settings mainPanel settingsPanelExpanded = !settingsPanelExpanded; - // Show or hide the settings panel based on its expanded state + // Show or hide the settings mainPanel based on its expanded state if (settingsPanelExpanded) { settingsToggleButton.setText("▼"); settingsPanel.setVisible(true); @@ -401,15 +407,15 @@ public void mouseClicked(MouseEvent e) { }); gbc.gridx = 0; gbc.gridy = 15; - panel.add(settingsToggleButton, gbc); + mainPanel.add(settingsToggleButton, gbc); - // TODO: Add label and expandable panel for settings + // TODO: Add label and expandable mainPanel for settings JLabel settingsLabel = new JLabel("Settings"); settingsLabel.setFont(settingsLabel.getFont().deriveFont(Font.BOLD)); settingsLabel.setToolTipText("Click to expand/collapse the Settings section."); gbc.gridx = 1; gbc.gridy = 15; - panel.add(settingsLabel, gbc); + mainPanel.add(settingsLabel, gbc); settingsPanel = new JPanel(new GridBagLayout()); GridBagConstraints settingsGbc = new GridBagConstraints(); @@ -470,8 +476,8 @@ public void mouseClicked(MouseEvent e) { settingsPanel.add(n1QLConsistencyLabel, settingsGbc); n1qlConsistencyComboBox = new JComboBox<>(); - n1qlConsistencyComboBox.addItem("Not bounded"); - n1qlConsistencyComboBox.addItem("Request plus"); + n1qlConsistencyComboBox.addItem("None"); + n1qlConsistencyComboBox.addItem("Request"); n1qlConsistencyComboBox.setToolTipText( "Consistency level of N1QL statements in the function."); settingsGbc.gridx = 0; @@ -498,6 +504,7 @@ public void mouseClicked(MouseEvent e) { workersField = new JTextField(20); workersField.setToolTipText( "Number of worker threads processing this function."); + workersField.setText("1"); settingsGbc.gridx = 0; settingsGbc.gridy = 6; settingsGbc.gridwidth = 2; @@ -555,6 +562,7 @@ public void mouseClicked(MouseEvent e) { scriptTimeoutField = new JTextField(20); scriptTimeoutField.setToolTipText( "Maximum execution time for each instance of the function."); + scriptTimeoutField.setText("60"); settingsGbc.gridx = 0; settingsGbc.gridy = 10; settingsGbc.gridwidth = 2; @@ -576,15 +584,10 @@ public void mouseClicked(MouseEvent e) { settingsGbc.gridy = 11; settingsPanel.add(timerContextMaxSizeLabel, settingsGbc); - JLabel timerContextMaxSizeInfoLabel = new JLabel("in bytes."); - timerContextMaxSizeInfoLabel.setForeground(Color.GRAY); - settingsGbc.gridx = 1; - settingsGbc.gridy = 11; - settingsPanel.add(timerContextMaxSizeInfoLabel, settingsGbc); - timerContextMaxSizeField = new JTextField(20); timerContextMaxSizeField.setToolTipText( "Maximum size of context object for timers."); + timerContextMaxSizeField.setText("1024"); settingsGbc.gridx = 0; settingsGbc.gridy = 12; settingsGbc.gridwidth = 2; @@ -592,15 +595,401 @@ public void mouseClicked(MouseEvent e) { gbc.gridx = 0; gbc.gridy = 16; - panel.add(settingsPanel, gbc); + mainPanel.add(settingsPanel, gbc); + + // Binding Type label and expandable mainPanel + // TODO: Add label and expandable mainPanel for binding type + bindingsPanel = new JPanel(new GridBagLayout()); + GridBagConstraints bindingsPanelGbc = new GridBagConstraints(); + bindingsPanelGbc.insets = new Insets(5, 5, 5, 5); + bindingsPanelGbc.anchor = GridBagConstraints.WEST; + + // Binding Type label + JLabel bindingTypeLabel = new JLabel("Binding Type"); + bindingTypeLabel.setFont(bindingTypeLabel.getFont().deriveFont(Font.BOLD)); + bindingsPanelGbc.gridx = 0; + bindingsPanelGbc.gridy = 0; + bindingsPanel.add(bindingTypeLabel, bindingsPanelGbc); + + // Plus button + JButton plusButton = new JButton("+"); + plusButton.addActionListener(e -> addBindingType()); + bindingsPanelGbc.gridx = 1; + bindingsPanelGbc.gridy = 0; + bindingsPanel.add(plusButton, bindingsPanelGbc); + + // Minus button + JButton minusButton = new JButton("-"); + minusButton.addActionListener(e -> removeBindingType()); + bindingsPanelGbc.gridx = 2; + bindingsPanelGbc.gridy = 0; + bindingsPanel.add(minusButton, bindingsPanelGbc); - // Binding Type label and expandable panel - // TODO: Add label and expandable panel for binding type + gbc.gridx = 0; + gbc.gridy = 17; + mainPanel.add(bindingsPanel, gbc); - return new JScrollPane(panel); + return new JScrollPane(mainPanel); } + private void addBindingType() { + // Increment the binding type count + bindingTypeCount++; + + // Create a new aliasPanel to hold the binding type components + JPanel bindingTypePanel = new JPanel(new GridBagLayout()); + GridBagConstraints bindingsGbc = new GridBagConstraints(); + bindingsGbc.insets = new Insets(5, 5, 5, 5); + bindingsGbc.anchor = GridBagConstraints.WEST; + + // Create the binding type dropdown menu + CustomComboBox bindingTypeComboBox = new CustomComboBox(); + bindingTypeComboBox.setToolTipText("Type of binding for this function."); + bindingTypeComboBox.addItem("Choose Binding Type"); + bindingTypeComboBox.addItem("Bucket Alias"); + bindingTypeComboBox.addItem("URL Alias"); + bindingTypeComboBox.addItem("Constant Alias"); + + bindingsGbc.gridx = 0; + bindingsGbc.gridy = 0; + bindingTypePanel.add(bindingTypeComboBox, bindingsGbc); + + // Create a aliasPanel to hold the alias-specific components + JPanel aliasPanel = new JPanel(new GridBagLayout()); + GridBagConstraints aliasGbc = new GridBagConstraints(); + aliasGbc.insets = new Insets(5, 5, 5, 5); + aliasGbc.anchor = GridBagConstraints.WEST; + bindingsGbc.gridx = 1; + bindingsGbc.gridy = 0; + bindingsGbc.gridwidth = 2; + bindingTypePanel.add(aliasPanel, bindingsGbc); + + // Update the alias aliasPanel when the selected binding type changes + bindingTypeComboBox.addItemListener(e -> { + // Remove all components from the alias aliasPanel + aliasPanel.removeAll(); + + // Get the selected binding type + String selectedBindingType = (String) bindingTypeComboBox.getSelectedItem(); + + if (selectedBindingType.equals("Bucket Alias")) { + // Create the alias name text field + JTextField aliasNameField = new JTextField(20); + aliasNameField.setToolTipText("Enter the alias name."); + aliasGbc.gridx = 0; + aliasGbc.gridy = 0; + aliasGbc.gridwidth = 8; + aliasPanel.add(aliasNameField, aliasGbc); + + // Create the bucket label + JLabel bucketLabel = new JLabel("Bucket"); + bucketLabel.setFont(bucketLabel.getFont().deriveFont(Font.BOLD)); + aliasGbc.gridx = 0; + aliasGbc.gridy = 1; + aliasGbc.gridwidth = 1; + aliasPanel.add(bucketLabel, aliasGbc); + + // Create the bucket info label + JLabel bucketInfoLabel = new JLabel("bucket.scope.collection"); + bucketInfoLabel.setForeground(Color.GRAY); + aliasGbc.gridx = 1; + aliasGbc.gridy = 1; + aliasPanel.add(bucketInfoLabel, aliasGbc); + + // Create the access label + JLabel accessLabel = new JLabel("Access"); + accessLabel.setFont(accessLabel.getFont().deriveFont(Font.BOLD)); + aliasGbc.gridx = 3; + aliasGbc.gridy = 1; + aliasPanel.add(accessLabel, aliasGbc); + + // Create the bucket dropdown menu + JComboBox bucketComboBox = new JComboBox<>(); + // TODO: Populate the bucketComboBox with available buckets + aliasGbc.gridx = 0; + aliasGbc.gridy = 2; + aliasPanel.add(bucketComboBox, aliasGbc); + + // Create the scope dropdown menu + JComboBox scopeComboBox = new JComboBox<>(); + scopeComboBox.setEnabled(false); + // TODO: Update the scopeComboBox when the selected bucket changes + aliasGbc.gridx = 1; + aliasGbc.gridy = 2; + aliasGbc.fill = GridBagConstraints.HORIZONTAL; + aliasPanel.add(scopeComboBox, aliasGbc); + + // Create the collection dropdown menu + JComboBox collectionComboBox = new JComboBox<>(); + collectionComboBox.setEnabled(false); + // TODO: Update the collectionComboBox when the selected scope changes + aliasGbc.gridx = 2; + aliasGbc.gridy = 2; + aliasGbc.fill = GridBagConstraints.NONE; + aliasPanel.add(collectionComboBox, aliasGbc); + + // Create access dropdown menu + JComboBox accessComboBox = new JComboBox<>(); + accessComboBox.addItem("Read Only"); + accessComboBox.addItem("Read and Write"); + accessComboBox.setToolTipText("Select access level for this bucket."); + accessComboBox.setEnabled(true); + accessComboBox.setSelectedIndex(0); + aliasGbc.gridx = 3; + aliasGbc.gridy = 2; + aliasPanel.add(accessComboBox, aliasGbc); + + } else if (selectedBindingType.equals("URL Alias")) { + // Create the alias name text field + JTextField aliasNameField = new JTextField(20); + aliasNameField.setToolTipText("Enter the alias name."); + aliasGbc.gridx = 0; + aliasGbc.gridy = 0; + aliasPanel.add(aliasNameField, aliasGbc); + + // Create the URL text field + JTextField urlField = new JTextField(20); + urlField.setToolTipText("Enter the URL."); + aliasGbc.gridx = 1; + aliasGbc.gridy = 0; + aliasPanel.add(urlField, aliasGbc); + + // Create the allow cookies checkbox + JCheckBox allowCookiesCheckBox = new JCheckBox("Allow cookies"); + allowCookiesCheckBox.setToolTipText("Allow cookies for this URL."); + aliasGbc.gridx = 0; + aliasGbc.gridy = 1; + aliasPanel.add(allowCookiesCheckBox, aliasGbc); + + // Create the validate SSL certificate checkbox + JCheckBox validateSslCertificateCheckBox = new JCheckBox("Validate SSL certificate"); + validateSslCertificateCheckBox.setToolTipText("Validate SSL certificate for this URL."); + aliasGbc.gridx = 1; + aliasGbc.gridy = 1; + aliasPanel.add(validateSslCertificateCheckBox, aliasGbc); + + // Create the authentication label + JLabel authenticationLabel = new JLabel("Authentication"); + authenticationLabel.setFont(authenticationLabel.getFont().deriveFont(Font.BOLD)); + authenticationLabel.setToolTipText("Select authentication method for this URL."); + authenticationLabel.setDisplayedMnemonic('A'); + authenticationLabel.setDisplayedMnemonicIndex(0); + authenticationLabel.setHorizontalAlignment(JTextField.LEFT); + authenticationLabel.setVerticalAlignment(JTextField.CENTER); + authenticationLabel.setHorizontalTextPosition(JTextField.RIGHT); + authenticationLabel.setVerticalTextPosition(JTextField.CENTER); + aliasGbc.gridx = 0; + aliasGbc.gridy = 2; + aliasPanel.add(authenticationLabel, aliasGbc); + + // Create the auth dropdown menu + CustomComboBox authComboBox = new CustomComboBox(); + authComboBox.addItem("No Auth"); + authComboBox.addItem("Basic"); + authComboBox.addItem("Bearer"); + authComboBox.addItem("Digest"); + authComboBox.setToolTipText("Select authentication method for this URL."); + authComboBox.setEnabled(true); + + authComboBox.setSelectedIndex(0); + aliasGbc.gridx = 1; + aliasGbc.gridy = 2; + aliasPanel.add(authComboBox, aliasGbc); + + // Create the username label and text field + JLabel usernameLabel = new JLabel("Username"); + usernameLabel.setFont(usernameLabel.getFont().deriveFont(Font.BOLD)); + usernameLabel.setToolTipText("Enter the username for basic or digest authentication."); + usernameLabel.setDisplayedMnemonic('U'); + usernameLabel.setDisplayedMnemonicIndex(0); + usernameLabel.setHorizontalAlignment(JTextField.LEFT); + usernameLabel.setVerticalAlignment(JTextField.CENTER); + usernameLabel.setHorizontalTextPosition(JTextField.RIGHT); + usernameLabel.setVerticalTextPosition(JTextField.CENTER); + usernameLabel.setVisible(false); + usernameLabel.setEnabled(false); + bindingsGbc.gridx = 0; + bindingsGbc.gridy = 3; + aliasPanel.add(usernameLabel, bindingsGbc); + + JTextField usernameField = new JTextField(20); + usernameField.setToolTipText( + "Enter the username for basic or digest authentication."); + usernameField.setVisible(false); + usernameField.setEnabled(false); + bindingsGbc.gridx = 1; + bindingsGbc.gridy = 3; + aliasPanel.add(usernameField, bindingsGbc); + + // Create the password label and text field + JLabel passwordLabel = new JLabel("Password"); + passwordLabel.setFont(passwordLabel.getFont().deriveFont(Font.BOLD)); + passwordLabel.setToolTipText( + "Enter the password for basic or digest authentication."); + passwordLabel.setDisplayedMnemonic('P'); + passwordLabel.setDisplayedMnemonicIndex(0); + passwordLabel.setHorizontalAlignment(JTextField.LEFT); + passwordLabel.setVerticalAlignment(JTextField.CENTER); + passwordLabel.setHorizontalTextPosition(JTextField.RIGHT); + passwordLabel.setVerticalTextPosition(JTextField.CENTER); + passwordLabel.setVisible(false); + passwordLabel.setEnabled(false); + bindingsGbc.gridx = 0; + bindingsGbc.gridy = 4; + aliasPanel.add(passwordLabel, bindingsGbc); + + JTextField passwordField = new JTextField(20); + passwordField.setToolTipText( + "Enter the password for basic or digest authentication."); + passwordField.setVisible(false); + passwordField.setEnabled(false); + bindingsGbc.gridx = 1; + bindingsGbc.gridy = 4; + aliasPanel.add(passwordField, bindingsGbc); + + // Create the bearer key label and text field + JLabel bearerKeyLabel = new JLabel("Bearer Key"); + bearerKeyLabel.setFont(bearerKeyLabel.getFont().deriveFont(Font.BOLD)); + bearerKeyLabel.setToolTipText( + "Enter the bearer key for bearer token authentication."); + bearerKeyLabel.setDisplayedMnemonic('B'); + bearerKeyLabel.setDisplayedMnemonicIndex(0); + bearerKeyLabel.setHorizontalAlignment(JTextField.LEFT); + bearerKeyLabel.setVerticalAlignment(JTextField.CENTER); + bearerKeyLabel.setHorizontalTextPosition(JTextField.RIGHT); + bearerKeyLabel.setVerticalTextPosition(JTextField.CENTER); + bearerKeyLabel.setVisible(false); + bearerKeyLabel.setEnabled(false); + bindingsGbc.gridx = 0; + bindingsGbc.gridy = 5; + aliasPanel.add(bearerKeyLabel, bindingsGbc); + + JTextField bearerKeyField = new JTextField(20); + bearerKeyField.setToolTipText( + "Enter the bearer key for bearer token authentication."); + bearerKeyField.setVisible(false); + bearerKeyField.setEnabled(false); + bindingsGbc.gridx = 1; + bindingsGbc.gridy = 5; + aliasPanel.add(bearerKeyField, bindingsGbc); + + // Create the auth dropdown menu listener + authComboBox.addActionListener(ee -> { + // Update the visibility of the authentication fields based on the selected + String selectedAuth = (String) authComboBox.getSelectedItem(); + if (selectedAuth.equals("Basic") || selectedAuth.equals("Digest")) { + usernameLabel.setVisible(true); + usernameField.setVisible(true); + usernameLabel.setEnabled(true); + usernameField.setEnabled(true); + + passwordLabel.setVisible(true); + passwordField.setVisible(true); + passwordLabel.setEnabled(true); + passwordField.setEnabled(true); + + bearerKeyLabel.setVisible(false); + bearerKeyField.setVisible(false); + bearerKeyLabel.setEnabled(false); + bearerKeyField.setEnabled(false); + } else if (selectedAuth.equals("Bearer")) { + usernameLabel.setVisible(false); + usernameField.setVisible(false); + usernameLabel.setEnabled(false); + usernameField.setEnabled(false); + + passwordLabel.setVisible(false); + passwordField.setVisible(false); + passwordLabel.setEnabled(false); + passwordField.setEnabled(false); + + bearerKeyLabel.setVisible(true); + bearerKeyField.setVisible(true); + bearerKeyLabel.setEnabled(true); + bearerKeyField.setEnabled(true); + } else { + usernameLabel.setVisible(false); + usernameField.setVisible(false); + usernameLabel.setEnabled(false); + usernameField.setEnabled(false); + + passwordLabel.setVisible(false); + passwordField.setVisible(false); + passwordLabel.setEnabled(false); + passwordField.setEnabled(false); + + bearerKeyLabel.setVisible(false); + bearerKeyField.setVisible(false); + bearerKeyLabel.setEnabled(false); + bearerKeyField.setEnabled(false); + } + + }); + + } else if (selectedBindingType.equals("Constant Alias")) { + // Create the alias name label + JLabel aliasNameLabel = new JLabel("Alias Name:"); + aliasGbc.gridx = 0; + aliasGbc.gridy = 0; + aliasPanel.add(aliasNameLabel, aliasGbc); + + // Create the alias name text field + JTextField aliasNameField = new JTextField(20); + aliasNameField.setToolTipText("Enter the alias name."); + aliasGbc.gridx = 1; + aliasGbc.gridy = 0; + aliasPanel.add(aliasNameField, aliasGbc); + + // Create the value label + JLabel valueLabel = new JLabel("Value:"); + aliasGbc.gridx = 0; + aliasGbc.gridy = 1; + aliasPanel.add(valueLabel, aliasGbc); + + // Create the value text field + JTextField valueField = new JTextField(20); + valueField.setToolTipText("Enter the constant value."); + aliasGbc.gridx = 1; + aliasGbc.gridy = 1; + aliasPanel.add(valueField, aliasGbc); + } + + // Repaint the alias aliasPanel to show the updated components + aliasPanel.revalidate(); + aliasPanel.repaint(); + }); + bindingTypeComboBox.setSelectedIndex(0); + + // Add the binding type aliasPanel to the bindings aliasPanel + GridBagConstraints bindingsPanelGbc = new GridBagConstraints(); + bindingsPanelGbc.insets = new Insets(5, 5, 5, 5); + bindingsPanelGbc.anchor = GridBagConstraints.WEST; + bindingsPanelGbc.gridx = 0; + bindingsPanelGbc.gridy = bindingTypeCount; + bindingsPanelGbc.gridwidth = 3; + bindingsPanel.add(bindingTypePanel, bindingsPanelGbc); + + // Repaint the bindings aliasPanel to show the new binding type + bindingsPanel.revalidate(); + bindingsPanel.repaint(); + } + + private void removeBindingType() { + // Get the number of binding types + int bindingTypeCount = bindingsPanel.getComponentCount(); + + // Check if there are any binding types to remove + if (bindingTypeCount > 0) { + // Remove the last binding type aliasPanel + bindingsPanel.remove(bindingTypeCount - 1); + + // Repaint the bindings aliasPanel to show the removed binding type + bindingsPanel.revalidate(); + bindingsPanel.repaint(); + } + } + private void updateScopes() { // Get selected bucket String selectedBucket = (String) bucketComboBox.getSelectedItem(); @@ -629,3 +1018,30 @@ public String getFunctionName() { return functionNameField.getText(); } } + +class CustomComboBox extends JComboBox { + public CustomComboBox() { + setRenderer(new DefaultListCellRenderer() { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, + boolean isSelected, + boolean cellHasFocus) { + JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, + isSelected, + cellHasFocus); + if (index == 0) { + label.setForeground(Color.GRAY); + } + return label; + } + }); + } + + @Override + public void setPopupVisible(boolean v) { + if (v && getSelectedIndex() == 0) { + return; + } + super.setPopupVisible(v); + } +} \ No newline at end of file From 496f0fe46a7228ebfdc8894825d6fa5c6fff8ce1 Mon Sep 17 00:00:00 2001 From: teetangh Date: Fri, 9 Jun 2023 09:29:48 +0530 Subject: [PATCH 04/15] Added Function Deployment Settings --- .../intellij/eventing/CustomComboBox.java | 31 + .../FunctionDeploymentDialog.java | 32 +- .../eventing/FunctionDeploymentSettings.java | 1039 +++++++++++++++++ .../intellij/tree/CouchbaseWindowContent.java | 11 +- 4 files changed, 1081 insertions(+), 32 deletions(-) create mode 100644 src/main/java/com/couchbase/intellij/eventing/CustomComboBox.java rename src/main/java/com/couchbase/intellij/{tree => eventing}/FunctionDeploymentDialog.java (97%) create mode 100644 src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java diff --git a/src/main/java/com/couchbase/intellij/eventing/CustomComboBox.java b/src/main/java/com/couchbase/intellij/eventing/CustomComboBox.java new file mode 100644 index 00000000..de778b0e --- /dev/null +++ b/src/main/java/com/couchbase/intellij/eventing/CustomComboBox.java @@ -0,0 +1,31 @@ +package com.couchbase.intellij.eventing; + +import javax.swing.*; +import java.awt.*; + +class CustomComboBox extends JComboBox { + public CustomComboBox() { + setRenderer(new DefaultListCellRenderer() { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, + boolean isSelected, + boolean cellHasFocus) { + JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, + isSelected, + cellHasFocus); + if (index == 0) { + label.setForeground(Color.GRAY); + } + return label; + } + }); + } + + @Override + public void setPopupVisible(boolean v) { + if (v && getSelectedIndex() == 0) { + return; + } + super.setPopupVisible(v); + } +} diff --git a/src/main/java/com/couchbase/intellij/tree/FunctionDeploymentDialog.java b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentDialog.java similarity index 97% rename from src/main/java/com/couchbase/intellij/tree/FunctionDeploymentDialog.java rename to src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentDialog.java index b3799ac3..3a44cbc5 100644 --- a/src/main/java/com/couchbase/intellij/tree/FunctionDeploymentDialog.java +++ b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentDialog.java @@ -112,10 +112,9 @@ // if it is constant alias, the first line is constant alias(the dropdown menu itself) and two textfields containing placeholder texts of “Username..” and “password…” Respectively. // } -package com.couchbase.intellij.tree; +package com.couchbase.intellij.eventing; import java.awt.Color; -import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java.awt.GridBagConstraints; @@ -125,13 +124,11 @@ import java.awt.event.MouseEvent; import java.util.Set; -import javax.swing.DefaultListCellRenderer; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JLabel; -import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; @@ -1018,30 +1015,3 @@ public String getFunctionName() { return functionNameField.getText(); } } - -class CustomComboBox extends JComboBox { - public CustomComboBox() { - setRenderer(new DefaultListCellRenderer() { - @Override - public Component getListCellRendererComponent(JList list, Object value, int index, - boolean isSelected, - boolean cellHasFocus) { - JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, - isSelected, - cellHasFocus); - if (index == 0) { - label.setForeground(Color.GRAY); - } - return label; - } - }); - } - - @Override - public void setPopupVisible(boolean v) { - if (v && getSelectedIndex() == 0) { - return; - } - super.setPopupVisible(v); - } -} \ No newline at end of file diff --git a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java new file mode 100644 index 00000000..258ae7b7 --- /dev/null +++ b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java @@ -0,0 +1,1039 @@ +package com.couchbase.intellij.eventing; + +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.HashMap; +import java.util.Map; + +import javax.swing.BorderFactory; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JButton; +// import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JFrame; +// import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +// import javax.swing.JScrollPane; +// import javax.swing.JTextArea; +// import javax.swing.JTextField; +import javax.swing.ListSelectionModel; +import javax.swing.SwingConstants; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +import com.intellij.ui.JBColor; +import com.intellij.ui.JBSplitter; +import com.intellij.ui.components.JBCheckBox; +import com.intellij.ui.components.JBLabel; +import com.intellij.ui.components.JBPasswordField; +import com.intellij.ui.components.JBScrollPane; +import com.intellij.ui.components.JBTextArea; +import com.intellij.ui.components.JBTextField; +import com.intellij.util.ui.JBUI; + +public class FunctionDeploymentSettings extends JFrame { + private JPanel mainPanel; + private JPanel leftPanel; + private JPanel rightPanel; + private JPanel bottomPanel; + private JPanel bindingsPanel; + private JBLabel titleLabel; + + private JButton applyButton; + private JButton cancelButton; + + private CardLayout cardLayout; + private Map changedSettings; + + private Integer bindingTypeCount = 0; + + public FunctionDeploymentSettings() { + // Set up the main frame + setTitle("Project Structure"); + setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + setSize(1000, 800); + setLocationRelativeTo(null); + + // Create and configure the main panel + mainPanel = new JPanel(); + mainPanel.setLayout(new BorderLayout()); + // JScrollPane scrollPane = new JScrollPane(mainPanel); + setContentPane(mainPanel); + + // Create and configure the left panel + leftPanel = new JPanel(); + leftPanel.setLayout(new BorderLayout()); + leftPanel.setPreferredSize(new Dimension(400, 800)); + // leftPanel.setForeground(JBColor.BLACK); + leftPanel.setBackground(Color.BLACK); + + // Add components to the left panel + titleLabel = new JBLabel("Project Structure"); + titleLabel.setHorizontalAlignment(SwingConstants.CENTER); + titleLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); + titleLabel.setBackground(Color.BLACK); + leftPanel.add(titleLabel, BorderLayout.NORTH); + + String[] settings = { "General Settings", "Advanced Settings", "Binding Type" }; + JList settingsList = new JList<>(settings); + settingsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + settingsList.setSelectedIndex(0); + + settingsList.setCellRenderer(new DefaultListCellRenderer() { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, + boolean isSelected, boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + setHorizontalAlignment(SwingConstants.LEFT); + setForeground(Color.WHITE); + if (isSelected) { + setBackground(new Color(98, 181, 229)); + } else { + setBackground(Color.BLACK); + } + return this; + } + }); + + settingsList.addListSelectionListener(e -> { + if (!e.getValueIsAdjusting()) { + String selectedValue = settingsList.getSelectedValue(); + CardLayout cardLayout = (CardLayout) rightPanel.getLayout(); + cardLayout.show(rightPanel, selectedValue); + } + }); + + JBScrollPane leftScrollPane = new JBScrollPane(settingsList); + leftScrollPane.setBorder(BorderFactory.createEmptyBorder()); + leftScrollPane.setBackground(JBColor.BLACK); + leftPanel.add(leftScrollPane, BorderLayout.CENTER); + + // Create and configure the right panel + rightPanel = new JPanel(); + cardLayout = new CardLayout(); + rightPanel.setLayout(cardLayout); + + // Add components to the right panel + JPanel generalSettingsPanel = new JPanel(); + generalSettingsPanel.setLayout(new GridBagLayout()); + generalSettingsPanel.setPreferredSize(new Dimension(600, 800)); + + GridBagConstraints rightPanelConstraints = new GridBagConstraints(); + rightPanelConstraints.gridx = 0; + rightPanelConstraints.gridy = 0; + rightPanelConstraints.anchor = GridBagConstraints.NORTHWEST; + rightPanelConstraints.insets = JBUI.insets(5); + rightPanelConstraints.weightx = 1.0; + rightPanelConstraints.weighty = 1.0; + rightPanelConstraints.fill = GridBagConstraints.HORIZONTAL; + + // Function Scope label + JBLabel functionScopeLabel = new JBLabel("Function scope"); + functionScopeLabel.setFont(functionScopeLabel.getFont().deriveFont(Font.BOLD)); + + JBLabel functionScopeInfoLabel = new JBLabel("bucket.scope"); + functionScopeInfoLabel.setForeground(JBColor.GRAY); + + // Add both labels to a flow layout + JPanel functionScopePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + functionScopePanel.add(functionScopeLabel); + functionScopePanel.add(functionScopeInfoLabel); + rightPanelConstraints.gridx = 0; + rightPanelConstraints.gridy = 0; + generalSettingsPanel.add(functionScopePanel, rightPanelConstraints); + + JComboBox bucketComboBox1 = new JComboBox<>(); + // bucketComboBox1.addActionListener(e -> updateScopes()); + rightPanelConstraints.gridx = 0; + rightPanelConstraints.gridy = 1; + generalSettingsPanel.add(bucketComboBox1, rightPanelConstraints); + + JComboBox scopeComboBox1 = new JComboBox<>(); + scopeComboBox1.setEnabled(false); + rightPanelConstraints.gridx = 1; + rightPanelConstraints.gridy = 1; + generalSettingsPanel.add(scopeComboBox1, rightPanelConstraints); + + // Function Scope error label + + JBLabel helpLabel1 = new JBLabel( + "Please specify a scope to which the function belongs. User should have Eventing Manage Scope Functions permission on this scope"); + helpLabel1.setForeground(JBColor.GRAY); + rightPanelConstraints.gridx = 0; + rightPanelConstraints.gridy = 2; + rightPanelConstraints.gridwidth = 3; + generalSettingsPanel.add(helpLabel1, rightPanelConstraints); + + // Listen to location label + JBLabel listenToLocationLabel = new JBLabel("Listen to location"); + + listenToLocationLabel.setFont(listenToLocationLabel.getFont().deriveFont(Font.BOLD)); + // rightPanelConstraints.gridx = 0; + // rightPanelConstraints.gridy = 3; + // generalSettingsPanel.add(listenToLocationLabel, rightPanelConstraints); + + JBLabel listenToLocationInfoLabel = new JBLabel("bucket.scope.collection"); + listenToLocationInfoLabel.setForeground(JBColor.GRAY); + // rightPanelConstraints.gridx = 1; + // rightPanelConstraints.gridy = 3; + // generalSettingsPanel.add(listenToLocationInfoLabel, rightPanelConstraints); + + // Add both labels to a flow layout + JPanel listenToLocationPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + listenToLocationPanel.add(listenToLocationLabel); + listenToLocationPanel.add(listenToLocationInfoLabel); + rightPanelConstraints.gridx = 0; + rightPanelConstraints.gridy = 3; + generalSettingsPanel.add(listenToLocationPanel, rightPanelConstraints); + + JComboBox bucketComboBox2 = new JComboBox<>(); + // bucketComboBox2.addActionListener(e -> updateScopes()); + rightPanelConstraints.gridx = 0; + rightPanelConstraints.gridy = 4; + rightPanelConstraints.gridwidth = 1; + generalSettingsPanel.add(bucketComboBox2, rightPanelConstraints); + + JComboBox scopeComboBox2 = new JComboBox<>(); + scopeComboBox2.setEnabled(false); + rightPanelConstraints.gridx = 1; + rightPanelConstraints.gridy = 4; + generalSettingsPanel.add(scopeComboBox2, rightPanelConstraints); + + JComboBox collectionComboBox1 = new JComboBox<>(); + collectionComboBox1.setEnabled(false); + rightPanelConstraints.gridx = 2; + rightPanelConstraints.gridy = 4; + generalSettingsPanel.add(collectionComboBox1, rightPanelConstraints); + + // Listen to location error label + JBLabel helpLabel2 = new JBLabel( + "Please specify a source location for your function. User should have DCP Data Read permission on this keyspace"); + helpLabel2.setForeground(JBColor.GRAY); + rightPanelConstraints.gridx = 0; + rightPanelConstraints.gridy = 5; + rightPanelConstraints.gridwidth = 3; + + generalSettingsPanel.add(helpLabel2, rightPanelConstraints); + + // Eventing Storage label + JBLabel eventingStorageLabel = new JBLabel("Eventing Storage"); + eventingStorageLabel.setFont(eventingStorageLabel.getFont().deriveFont(Font.BOLD)); + // rightPanelConstraints.gridx = 0; + // rightPanelConstraints.gridy = 6; + // generalSettingsPanel.add(eventingStorageLabel, rightPanelConstraints); + + JBLabel eventingStorageInfoLabel = new JBLabel("bucket.scope.collection"); + eventingStorageInfoLabel.setForeground(JBColor.GRAY); + // rightPanelConstraints.gridx = 1; + // rightPanelConstraints.gridy = 6; + // rightPanelConstraints.gridwidth = 2; + // generalSettingsPanel.add(eventingStorageInfoLabel, rightPanelConstraints); + + // Add both labels to a flow layout + JPanel eventingStoragePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + eventingStoragePanel.add(eventingStorageLabel); + eventingStoragePanel.add(eventingStorageInfoLabel); + rightPanelConstraints.gridx = 0; + rightPanelConstraints.gridy = 6; + generalSettingsPanel.add(eventingStoragePanel, rightPanelConstraints); + + JComboBox bucketComboBox3 = new JComboBox<>(); + // bucketComboBox3.addActionListener(e -> updateScopes()); + rightPanelConstraints.gridx = 0; + rightPanelConstraints.gridy = 7; + rightPanelConstraints.gridwidth = 1; + generalSettingsPanel.add(bucketComboBox3, rightPanelConstraints); + + JComboBox scopeComboBox3 = new JComboBox<>(); + scopeComboBox3.setEnabled(false); + rightPanelConstraints.gridx = 1; + rightPanelConstraints.gridy = 7; + generalSettingsPanel.add(scopeComboBox3, rightPanelConstraints); + + JComboBox collectionComboBox2 = new JComboBox<>(); + collectionComboBox2.setEnabled(false); + rightPanelConstraints.gridx = 2; + rightPanelConstraints.gridy = 7; + + generalSettingsPanel.add(collectionComboBox2, rightPanelConstraints); + + // Eventing Storage help label + JBLabel helpLabel3 = new JBLabel( + "Please specify a location to store Eventing data. User should have read/write permission on this keyspace"); + helpLabel3.setForeground(JBColor.GRAY); + rightPanelConstraints.gridx = 0; + rightPanelConstraints.gridy = 8; + rightPanelConstraints.gridwidth = 3; + generalSettingsPanel.add(helpLabel3, rightPanelConstraints); + + // Function Name label and text field + JBLabel functionNameLabel = new JBLabel("Function Name"); + functionNameLabel.setFont(functionNameLabel.getFont().deriveFont(Font.BOLD)); + rightPanelConstraints.gridx = 0; + rightPanelConstraints.gridy = 9; + generalSettingsPanel.add(functionNameLabel, rightPanelConstraints); + + JBTextField functionNameField = new JBTextField(20); + functionNameField.setToolTipText("Enter the name of the function."); + rightPanelConstraints.gridx = 0; + rightPanelConstraints.gridy = 10; + generalSettingsPanel.add(functionNameField, rightPanelConstraints); + + // Deployment Feed Boundary label and combo box + JBLabel deploymentFeedBoundaryLabel = new JBLabel("Deployment Feed Boundary"); + + deploymentFeedBoundaryLabel.setFont(deploymentFeedBoundaryLabel.getFont().deriveFont(Font.BOLD)); + deploymentFeedBoundaryLabel.setToolTipText( + "The preferred Deployment time Feed Boundary for the function."); + rightPanelConstraints.gridx = 0; + rightPanelConstraints.gridy = 11; + generalSettingsPanel.add(deploymentFeedBoundaryLabel, rightPanelConstraints); + + JComboBox deploymentFeedBoundaryComboBox = new JComboBox<>(); + deploymentFeedBoundaryComboBox.addItem("Everything"); + deploymentFeedBoundaryComboBox.addItem("From now"); + deploymentFeedBoundaryComboBox.setToolTipText( + "The preferred Deployment time Feed Boundary for the function."); + + rightPanelConstraints.gridx = 0; + rightPanelConstraints.gridy = 12; + rightPanelConstraints.gridwidth = 3; + generalSettingsPanel.add(deploymentFeedBoundaryComboBox, rightPanelConstraints); + + JBLabel warningLabel = new JBLabel(""); + warningLabel.setForeground(JBColor.ORANGE); + rightPanelConstraints.gridx = 0; + rightPanelConstraints.gridy = 13; + generalSettingsPanel.add(warningLabel, rightPanelConstraints); + + deploymentFeedBoundaryComboBox.addActionListener(e -> { + if (deploymentFeedBoundaryComboBox.getSelectedItem().equals("From now")) { + warningLabel.setText( + "Warning: Deploying with 'From now' will ignore all past mutations."); + } else { + warningLabel.setText(""); + } + }); + + // Description label and text area + JBLabel descriptionLabel = new JBLabel("Description"); + + descriptionLabel.setFont(descriptionLabel.getFont().deriveFont(Font.BOLD)); + descriptionLabel.setToolTipText("Enter a description for the function (optional)."); + descriptionLabel.setDisplayedMnemonic('D'); + descriptionLabel.setDisplayedMnemonicIndex(0); + descriptionLabel.setHorizontalAlignment(JBTextField.LEFT); + rightPanelConstraints.gridx = 0; + rightPanelConstraints.gridy = 14; + generalSettingsPanel.add(descriptionLabel, rightPanelConstraints); + + JBTextArea descriptionTextArea = new JBTextArea(5, 20); + descriptionTextArea.setLineWrap(true); + descriptionTextArea.setWrapStyleWord(true); + descriptionTextArea.setToolTipText("Enter a description for the function (optional)."); + descriptionLabel.setLabelFor(descriptionTextArea); + JBScrollPane descriptionScrollPane = new JBScrollPane(descriptionTextArea); + rightPanelConstraints.gridx = 0; + rightPanelConstraints.gridy = 15; + rightPanelConstraints.fill = GridBagConstraints.BOTH; + generalSettingsPanel.add(descriptionScrollPane, rightPanelConstraints); + + // Advanced Settings panel + JPanel advancedSettingsPanel = new JPanel(); + advancedSettingsPanel.setLayout(new GridBagLayout()); + GridBagConstraints advancedSettingsConstraints = new GridBagConstraints(); + advancedSettingsConstraints.gridx = 0; + advancedSettingsConstraints.gridy = 0; + + advancedSettingsConstraints.anchor = GridBagConstraints.NORTHWEST; + advancedSettingsConstraints.insets = new Insets(5, 5, 5, 5); + advancedSettingsConstraints.fill = GridBagConstraints.HORIZONTAL; + + // Add components to the Advanced Settings panel + JBLabel systemLogLevelLabel = new JBLabel("System Log Level"); + systemLogLevelLabel.setFont(systemLogLevelLabel.getFont().deriveFont(Font.BOLD)); + // advancedSettingsConstraints.gridx = 0; + // advancedSettingsConstraints.gridy = 0; + // advancedSettingsPanel.add(systemLogLevelLabel, advancedSettingsConstraints); + + JBLabel systemLogLevelInfoLabel = new JBLabel("Granularity of system events being captured in the log"); + systemLogLevelInfoLabel.setForeground(JBColor.GRAY); + // advancedSettingsConstraints.gridx = 1; + // advancedSettingsConstraints.gridy = 0; + // advancedSettingsPanel.add(systemLogLevelInfoLabel, + // advancedSettingsConstraints); + + // Add both the labels to a panel + JPanel systemLogLevelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + systemLogLevelPanel.add(systemLogLevelLabel); + systemLogLevelPanel.add(systemLogLevelInfoLabel); + advancedSettingsConstraints.gridx = 0; + advancedSettingsConstraints.gridy = 0; + advancedSettingsPanel.add(systemLogLevelPanel, advancedSettingsConstraints); + + JComboBox systemLogLevelComboBox = new JComboBox<>(); + systemLogLevelComboBox.addItem("Info"); + systemLogLevelComboBox.addItem("Error"); + systemLogLevelComboBox.addItem("Warning"); + systemLogLevelComboBox.addItem("Debug"); + systemLogLevelComboBox.addItem("Trace"); + advancedSettingsConstraints.gridx = 0; + advancedSettingsConstraints.gridy = 1; + advancedSettingsPanel.add(systemLogLevelComboBox, advancedSettingsConstraints); + + JBLabel applicationLogFileLabel = new JBLabel( + "Application log file for this Function is at:"); + + advancedSettingsConstraints.gridx = 0; + advancedSettingsConstraints.gridy = 2; + advancedSettingsPanel.add(applicationLogFileLabel, advancedSettingsConstraints); + + JBLabel n1qlConsistencyLabel = new JBLabel("N1QL Consistency"); + n1qlConsistencyLabel.setFont(n1qlConsistencyLabel.getFont().deriveFont(Font.BOLD)); + // advancedSettingsConstraints.gridx = 0; + // advancedSettingsConstraints.gridy = 3; + // advancedSettingsPanel.add(n1qlConsistencyLabel, advancedSettingsConstraints); + + JBLabel n1qlConsistencyInfoLabel = new JBLabel("Consistency level of N1QL statements in the function"); + n1qlConsistencyInfoLabel.setForeground(JBColor.GRAY); + // advancedSettingsConstraints.gridx = 1; + // advancedSettingsConstraints.gridy = 3; + // advancedSettingsPanel.add(n1qlConsistencyInfoLabel, + // advancedSettingsConstraints); + + // Add both the labels to a panel + JPanel n1qlConsistencyPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + n1qlConsistencyPanel.add(n1qlConsistencyLabel); + n1qlConsistencyPanel.add(n1qlConsistencyInfoLabel); + advancedSettingsConstraints.gridx = 0; + advancedSettingsConstraints.gridy = 3; + advancedSettingsPanel.add(n1qlConsistencyPanel, advancedSettingsConstraints); + + JComboBox n1qlConsistencyComboBox = new JComboBox<>(); + n1qlConsistencyComboBox.addItem("None"); + n1qlConsistencyComboBox.addItem("Request"); + advancedSettingsConstraints.gridx = 0; + advancedSettingsConstraints.gridy = 4; + + advancedSettingsPanel.add(n1qlConsistencyComboBox, advancedSettingsConstraints); + + JBLabel workersLabel = new JBLabel("Workers"); + workersLabel.setFont(workersLabel.getFont().deriveFont(Font.BOLD)); + // advancedSettingsConstraints.gridx = 0; + // advancedSettingsConstraints.gridy = 5; + // advancedSettingsPanel.add(workersLabel, advancedSettingsConstraints); + + JBLabel workersInfoLabel = new JBLabel( + "Number of workers per node to process the events. If no value is specified, a default value of 1 worker is used."); + workersInfoLabel.setForeground(JBColor.GRAY); + // advancedSettingsConstraints.gridx = 1; + // advancedSettingsConstraints.gridy = 5; + // advancedSettingsPanel.add(workersInfoLabel, advancedSettingsConstraints); + + // Add both the labels to a panel + JPanel workersPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + workersPanel.add(workersLabel); + workersPanel.add(workersInfoLabel); + advancedSettingsConstraints.gridx = 0; + advancedSettingsConstraints.gridy = 5; + advancedSettingsPanel.add(workersPanel, advancedSettingsConstraints); + + JBTextField workersField = new JBTextField(20); + workersField.setToolTipText("Enter the number of workers per node to process the events."); + // advancedSettingsConstraints.gridx = 0; + // advancedSettingsConstraints.gridy = 6; + // advancedSettingsPanel.add(workersField, advancedSettingsConstraints); + + JBLabel languageCompatibilityLabel = new JBLabel("Language compatibility"); + + languageCompatibilityLabel.setFont(languageCompatibilityLabel.getFont().deriveFont(Font.BOLD)); + // advancedSettingsConstraints.gridx = 0; + // advancedSettingsConstraints.gridy = 7; + // advancedSettingsPanel.add(languageCompatibilityLabel, + // advancedSettingsConstraints); + + JBLabel languageCompatibilityInfoLabel = new JBLabel("Language compatibility of the function"); + languageCompatibilityInfoLabel.setForeground(JBColor.GRAY); + // advancedSettingsConstraints.gridx = 1; + // advancedSettingsConstraints.gridy = 7; + // advancedSettingsPanel.add(languageCompatibilityInfoLabel, + // advancedSettingsConstraints); + + // Add both the labels to a panel + JPanel languageCompatibilityPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + languageCompatibilityPanel.add(languageCompatibilityLabel); + languageCompatibilityPanel.add(languageCompatibilityInfoLabel); + advancedSettingsConstraints.gridx = 0; + advancedSettingsConstraints.gridy = 7; + advancedSettingsPanel.add(languageCompatibilityPanel, advancedSettingsConstraints); + + JComboBox languageCompatibilityComboBox = new JComboBox<>(); + languageCompatibilityComboBox.addItem("6.0.0"); + languageCompatibilityComboBox.addItem("6.5.0"); + languageCompatibilityComboBox.addItem("6.6.2"); + advancedSettingsConstraints.gridx = 0; + advancedSettingsConstraints.gridy = 8; + advancedSettingsPanel.add(languageCompatibilityComboBox, advancedSettingsConstraints); + + JBLabel scriptTimeoutLabel = new JBLabel("Script Timeout"); + + scriptTimeoutLabel.setFont(scriptTimeoutLabel.getFont().deriveFont(Font.BOLD)); + // advancedSettingsConstraints.gridx = 0; + // advancedSettingsConstraints.gridy = 9; + // advancedSettingsPanel.add(scriptTimeoutLabel, advancedSettingsConstraints); + + JBLabel scriptTimeoutInfoLabel = new JBLabel( + "Time after which the Function's execution will be timed out"); + scriptTimeoutInfoLabel.setForeground(JBColor.GRAY); + // advancedSettingsConstraints.gridx = 1; + // advancedSettingsConstraints.gridy = 9; + // advancedSettingsPanel.add(scriptTimeoutInfoLabel, + // advancedSettingsConstraints); + + // Add both the labels to a panel + JPanel scriptTimeoutPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + scriptTimeoutPanel.add(scriptTimeoutLabel); + scriptTimeoutPanel.add(scriptTimeoutInfoLabel); + advancedSettingsConstraints.gridx = 0; + advancedSettingsConstraints.gridy = 9; + advancedSettingsPanel.add(scriptTimeoutPanel, advancedSettingsConstraints); + + JBTextField scriptTimeoutField = new JBTextField(20); + scriptTimeoutField.setText("60"); + scriptTimeoutField.setToolTipText( + "Enter the time after which the Function's execution will be timed out."); + advancedSettingsConstraints.gridx = 0; + advancedSettingsConstraints.gridy = 10; + advancedSettingsPanel.add(scriptTimeoutField, advancedSettingsConstraints); + + JBLabel timerContextMaxSizeLabel = new JBLabel("Timer Context Max Size"); + + timerContextMaxSizeLabel.setFont(timerContextMaxSizeLabel.getFont().deriveFont(Font.BOLD)); + // advancedSettingsConstraints.gridx = 0; + // advancedSettingsConstraints.gridy = 11; + // advancedSettingsPanel.add(timerContextMaxSizeLabel, + // advancedSettingsConstraints); + + JBLabel timerContextMaxSizeInfoLabel = new JBLabel( + "Maximum allowed value of the Timer Context Size in Bytes. Takes effect immediately."); + timerContextMaxSizeInfoLabel.setForeground(JBColor.GRAY); + // advancedSettingsConstraints.gridx = 1; + // advancedSettingsConstraints.gridy = 11; + // advancedSettingsPanel.add(timerContextMaxSizeInfoLabel, + // advancedSettingsConstraints); + + // Add both the labels to a panel + JPanel timerContextMaxSizePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + timerContextMaxSizePanel.add(timerContextMaxSizeLabel); + timerContextMaxSizePanel.add(timerContextMaxSizeInfoLabel); + advancedSettingsConstraints.gridx = 0; + advancedSettingsConstraints.gridy = 11; + advancedSettingsPanel.add(timerContextMaxSizePanel, advancedSettingsConstraints); + + JBTextField timerContextMaxSizeField = new JBTextField(20); + timerContextMaxSizeField.setText("1024"); + timerContextMaxSizeField.setToolTipText( + "Enter the maximum allowed value of the Timer Context Size in Bytes."); + advancedSettingsConstraints.gridx = 0; + advancedSettingsConstraints.gridy = 12; + advancedSettingsPanel.add(timerContextMaxSizeField, advancedSettingsConstraints); + + // Binding Type panel + bindingsPanel = new JPanel(new GridBagLayout()); + GridBagConstraints bindingsPanelGbc = new GridBagConstraints(); + bindingsPanelGbc.insets = new Insets(5, 5, 5, 5); + bindingsPanelGbc.anchor = GridBagConstraints.WEST; + + // Binding Type label + JBLabel bindingTypeLabel = new JBLabel("Binding Type"); + bindingTypeLabel.setFont(bindingTypeLabel.getFont().deriveFont(Font.BOLD)); + bindingsPanelGbc.gridx = 0; + bindingsPanelGbc.gridy = 0; + bindingsPanel.add(bindingTypeLabel, bindingsPanelGbc); + + // Plus button + JButton plusButton = new JButton("+"); + plusButton.addActionListener(e -> addBindingType()); + bindingsPanelGbc.gridx = 1; + bindingsPanelGbc.gridy = 0; + bindingsPanel.add(plusButton, bindingsPanelGbc); + + // Minus button + JButton minusButton = new JButton("-"); + minusButton.addActionListener(e -> removeBindingType()); + bindingsPanelGbc.gridx = 2; + bindingsPanelGbc.gridy = 0; + bindingsPanel.add(minusButton, bindingsPanelGbc); + + // Add the panels to the right panel + rightPanel.add(generalSettingsPanel, "General Settings"); + rightPanel.add(advancedSettingsPanel, "Advanced Settings"); + rightPanel.add(new JBScrollPane(bindingsPanel), "Binding Type"); + + // Create and configure the bottom panel + bottomPanel = new JPanel(); + bottomPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); + + // Add components to the bottom panel + applyButton = new JButton("Apply"); + applyButton.addActionListener(e -> { + // Save changes + dispose(); + }); + bottomPanel.add(applyButton); + + cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(e -> { + // Discard changes + dispose(); + }); + bottomPanel.add(cancelButton); + + // Add the panels to the main panel + JBSplitter splitter = new JBSplitter(false); + splitter.setFirstComponent(leftPanel); + splitter.setSecondComponent(rightPanel); + mainPanel.add(splitter, BorderLayout.CENTER); + mainPanel.add(bottomPanel, BorderLayout.SOUTH); + + // Add a window listener to handle unsaved changes + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + // Check for unsaved changes + if (changedSettings.values().stream().anyMatch(changed -> changed)) { + int result = JOptionPane.showConfirmDialog(FunctionDeploymentSettings.this, + "You have unsaved changes. Do you want to save them before closing?", + "Unsaved Changes", JOptionPane.YES_NO_CANCEL_OPTION); + if (result == JOptionPane.YES_OPTION) { + // Save changes + dispose(); + } else if (result == JOptionPane.NO_OPTION) { + // Discard changes + dispose(); + } + } else { + dispose(); + } + } + }); + + // Initialize the changed settings map + changedSettings = new HashMap<>(); + changedSettings.put("General Settings", false); + changedSettings.put("Advanced Settings", false); + changedSettings.put("Binding Type", false); + + // Add document listeners to track changes + DocumentListener documentListener = new DocumentListener() { + @Override + public void insertUpdate(DocumentEvent e) { + changedSettings.put("General Settings", true); + } + + @Override + public void removeUpdate(DocumentEvent e) { + changedSettings.put("General Settings", true); + } + + @Override + public void changedUpdate(DocumentEvent e) { + changedSettings.put("General Settings", true); + } + }; + functionNameField.getDocument().addDocumentListener(documentListener); + descriptionTextArea.getDocument().addDocumentListener(documentListener); + + ActionListener actionListener = e -> changedSettings.put("General Settings", true); + deploymentFeedBoundaryComboBox.addActionListener(actionListener); + + } + + private void addBindingType() { + // Increment the binding type count + bindingTypeCount++; + + // Create a new aliasPanel to hold the binding type components + JPanel bindingTypePanel = new JPanel(new GridBagLayout()); + GridBagConstraints bindingsGbc = new GridBagConstraints(); + bindingsGbc.insets = new Insets(5, 5, 5, 5); + bindingsGbc.anchor = GridBagConstraints.WEST; + bindingsGbc.fill = GridBagConstraints.HORIZONTAL; + + // Create the binding type dropdown menu + CustomComboBox bindingTypeComboBox = new CustomComboBox(); + bindingTypeComboBox.setToolTipText("Type of binding for this function."); + bindingTypeComboBox.addItem("Choose Binding Type"); + bindingTypeComboBox.addItem("Bucket Alias"); + bindingTypeComboBox.addItem("URL Alias"); + bindingTypeComboBox.addItem("Constant Alias"); + + bindingsGbc.gridx = 0; + bindingsGbc.gridy = 0; + bindingTypePanel.add(bindingTypeComboBox, bindingsGbc); + + // Create a aliasPanel to hold the alias-specific components + JPanel aliasPanel = new JPanel(new GridBagLayout()); + GridBagConstraints aliasGbc = new GridBagConstraints(); + aliasGbc.insets = new Insets(5, 5, 5, 5); + aliasGbc.anchor = GridBagConstraints.WEST; + aliasGbc.fill = GridBagConstraints.HORIZONTAL; + bindingsGbc.gridx = 1; + bindingsGbc.gridy = 0; + bindingsGbc.gridwidth = 2; + bindingTypePanel.add(aliasPanel, bindingsGbc); + + // Update the alias aliasPanel when the selected binding type changes + bindingTypeComboBox.addItemListener(e -> { + // Remove all components from the alias aliasPanel + aliasPanel.removeAll(); + + // Get the selected binding type + String selectedBindingType = (String) bindingTypeComboBox.getSelectedItem(); + + if (selectedBindingType.equals("Bucket Alias")) { + // Create the alias name text field + JBTextField aliasNameField = new JBTextField(20); + aliasNameField.setToolTipText("Enter the alias name."); + aliasNameField.getEmptyText().setText("Enter the alias name."); + aliasGbc.gridx = 0; + aliasGbc.gridy = 0; + aliasGbc.gridwidth = 4; + aliasPanel.add(aliasNameField, aliasGbc); + + // Create the bucket label + JBLabel bucketLabel = new JBLabel("Bucket"); + bucketLabel.setFont(bucketLabel.getFont().deriveFont(Font.BOLD)); + // aliasGbc.gridx = 0; + // aliasGbc.gridy = 1; + // aliasGbc.gridwidth = 1; + // aliasPanel.add(bucketLabel, aliasGbc); + + // Create the bucket info label + JBLabel bucketInfoLabel = new JBLabel("bucket.scope.collection"); + bucketInfoLabel.setForeground(Color.GRAY); + // aliasGbc.gridx = 1; + // aliasGbc.gridy = 1; + // aliasPanel.add(bucketInfoLabel, aliasGbc); + + // Add both labels to a flow layout panel + JPanel bucketPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + bucketPanel.add(bucketLabel); + bucketPanel.add(bucketInfoLabel); + aliasGbc.gridx = 0; + aliasGbc.gridy = 1; + aliasGbc.gridwidth = 3; + aliasPanel.add(bucketPanel, aliasGbc); + + // Create the access label + JBLabel accessLabel = new JBLabel("Access"); + accessLabel.setFont(accessLabel.getFont().deriveFont(Font.BOLD)); + aliasGbc.gridx = 3; + aliasGbc.gridy = 1; + aliasGbc.gridwidth = 1; + aliasPanel.add(accessLabel, aliasGbc); + + // Create the bucket dropdown menu + JComboBox bucketComboBox = new JComboBox<>(); + // TODO: Populate the bucketComboBox with available buckets + aliasGbc.gridx = 0; + aliasGbc.gridy = 2; + aliasPanel.add(bucketComboBox, aliasGbc); + + // Create the scope dropdown menu + JComboBox scopeComboBox = new JComboBox<>(); + scopeComboBox.setEnabled(false); + // TODO: Update the scopeComboBox when the selected bucket changes + aliasGbc.gridx = 1; + aliasGbc.gridy = 2; + aliasPanel.add(scopeComboBox, aliasGbc); + + // Create the collection dropdown menu + JComboBox collectionComboBox = new JComboBox<>(); + collectionComboBox.setEnabled(false); + // TODO: Update the collectionComboBox when the selected scope changes + aliasGbc.gridx = 2; + aliasGbc.gridy = 2; + aliasPanel.add(collectionComboBox, aliasGbc); + + // Create access dropdown menu + JComboBox accessComboBox = new JComboBox<>(); + accessComboBox.addItem("Read Only"); + accessComboBox.addItem("Read and Write"); + accessComboBox.setToolTipText("Select access level for this bucket."); + accessComboBox.setEnabled(true); + accessComboBox.setSelectedIndex(0); + aliasGbc.gridx = 3; + aliasGbc.gridy = 2; + aliasPanel.add(accessComboBox, aliasGbc); + + } else if (selectedBindingType.equals("URL Alias")) { + // Create the alias name text field + JBTextField aliasNameField = new JBTextField(20); + aliasNameField.setToolTipText("Enter the alias name."); + aliasNameField.getEmptyText().setText("Enter the alias name."); + aliasGbc.gridx = 0; + aliasGbc.gridy = 0; + aliasPanel.add(aliasNameField, aliasGbc); + + // Create the URL text field + JBTextField urlField = new JBTextField(20); + urlField.setToolTipText("Enter the URL."); + urlField.getEmptyText().setText("Enter the URL."); + aliasGbc.gridx = 1; + aliasGbc.gridy = 0; + aliasPanel.add(urlField, aliasGbc); + + // Create the allow cookies checkbox + JBCheckBox allowCookiesCheckBox = new JBCheckBox("Allow cookies"); + allowCookiesCheckBox.setToolTipText("Allow cookies for this URL."); + aliasGbc.gridx = 0; + aliasGbc.gridy = 1; + aliasPanel.add(allowCookiesCheckBox, aliasGbc); + + // Create the validate SSL certificate checkbox + JBCheckBox validateSslCertificateCheckBox = new JBCheckBox("Validate SSL certificate"); + validateSslCertificateCheckBox.setToolTipText("Validate SSL certificate for this URL."); + aliasGbc.gridx = 1; + aliasGbc.gridy = 1; + aliasPanel.add(validateSslCertificateCheckBox, aliasGbc); + + // Create the authentication label + JBLabel authenticationLabel = new JBLabel("Authentication"); + authenticationLabel.setFont(authenticationLabel.getFont().deriveFont(Font.BOLD)); + authenticationLabel.setToolTipText("Select authentication method for this URL."); + authenticationLabel.setDisplayedMnemonic('A'); + authenticationLabel.setDisplayedMnemonicIndex(0); + authenticationLabel.setHorizontalAlignment(JBTextField.LEFT); + authenticationLabel.setVerticalAlignment(JBTextField.CENTER); + authenticationLabel.setHorizontalTextPosition(JBTextField.RIGHT); + authenticationLabel.setVerticalTextPosition(JBTextField.CENTER); + aliasGbc.gridx = 0; + aliasGbc.gridy = 2; + aliasPanel.add(authenticationLabel, aliasGbc); + + // Create the auth dropdown menu + CustomComboBox authComboBox = new CustomComboBox(); + authComboBox.addItem("No Auth"); + authComboBox.addItem("Basic"); + authComboBox.addItem("Bearer"); + authComboBox.addItem("Digest"); + authComboBox.setToolTipText("Select authentication method for this URL."); + authComboBox.setEnabled(true); + + authComboBox.setSelectedIndex(0); + aliasGbc.gridx = 1; + aliasGbc.gridy = 2; + aliasPanel.add(authComboBox, aliasGbc); + + // Create the username label and text field + JBLabel usernameLabel = new JBLabel("Username"); + usernameLabel.setFont(usernameLabel.getFont().deriveFont(Font.BOLD)); + usernameLabel.setToolTipText("Enter the username for basic or digest authentication."); + usernameLabel.setDisplayedMnemonic('U'); + usernameLabel.setDisplayedMnemonicIndex(0); + usernameLabel.setHorizontalAlignment(JBTextField.LEFT); + usernameLabel.setVerticalAlignment(JBTextField.CENTER); + usernameLabel.setHorizontalTextPosition(JBTextField.RIGHT); + usernameLabel.setVerticalTextPosition(JBTextField.CENTER); + usernameLabel.setVisible(false); + usernameLabel.setEnabled(false); + bindingsGbc.gridx = 0; + bindingsGbc.gridy = 3; + aliasPanel.add(usernameLabel, bindingsGbc); + + JBTextField usernameField = new JBTextField(20); + usernameField.setToolTipText( + "Enter the username for basic or digest authentication."); + usernameField.getEmptyText().setText("Enter the username."); + usernameField.setVisible(false); + usernameField.setEnabled(false); + bindingsGbc.gridx = 1; + bindingsGbc.gridy = 3; + aliasPanel.add(usernameField, bindingsGbc); + + // Create the password label and text field + JBLabel passwordLabel = new JBLabel("Password"); + passwordLabel.setFont(passwordLabel.getFont().deriveFont(Font.BOLD)); + passwordLabel.setToolTipText( + "Enter the password for basic or digest authentication."); + passwordLabel.setDisplayedMnemonic('P'); + passwordLabel.setDisplayedMnemonicIndex(0); + passwordLabel.setHorizontalAlignment(JBTextField.LEFT); + passwordLabel.setVerticalAlignment(JBTextField.CENTER); + passwordLabel.setHorizontalTextPosition(JBTextField.RIGHT); + passwordLabel.setVerticalTextPosition(JBTextField.CENTER); + passwordLabel.setVisible(false); + passwordLabel.setEnabled(false); + bindingsGbc.gridx = 0; + bindingsGbc.gridy = 4; + aliasPanel.add(passwordLabel, bindingsGbc); + + JBPasswordField passwordField = new JBPasswordField(); + passwordField.setToolTipText( + "Enter the password for basic or digest authentication."); + passwordField.getEmptyText().setText("Enter the password."); + passwordField.setVisible(false); + passwordField.setEnabled(false); + bindingsGbc.gridx = 1; + bindingsGbc.gridy = 4; + aliasPanel.add(passwordField, bindingsGbc); + + // Create the bearer key label and text field + JBLabel bearerKeyLabel = new JBLabel("Bearer Key"); + bearerKeyLabel.setFont(bearerKeyLabel.getFont().deriveFont(Font.BOLD)); + bearerKeyLabel.setToolTipText( + "Enter the bearer key for bearer token authentication."); + bearerKeyLabel.setDisplayedMnemonic('B'); + bearerKeyLabel.setDisplayedMnemonicIndex(0); + bearerKeyLabel.setHorizontalAlignment(JBTextField.LEFT); + bearerKeyLabel.setVerticalAlignment(JBTextField.CENTER); + bearerKeyLabel.setHorizontalTextPosition(JBTextField.RIGHT); + bearerKeyLabel.setVerticalTextPosition(JBTextField.CENTER); + bearerKeyLabel.setVisible(false); + bearerKeyLabel.setEnabled(false); + bindingsGbc.gridx = 0; + bindingsGbc.gridy = 5; + aliasPanel.add(bearerKeyLabel, bindingsGbc); + + JBTextField bearerKeyField = new JBTextField(20); + bearerKeyField.setToolTipText( + "Enter the bearer key for bearer token authentication."); + bearerKeyField.getEmptyText().setText("Enter the bearer key."); + bearerKeyField.setVisible(false); + bearerKeyField.setEnabled(false); + bindingsGbc.gridx = 1; + bindingsGbc.gridy = 5; + aliasPanel.add(bearerKeyField, bindingsGbc); + + // Create the auth dropdown menu listener + authComboBox.addActionListener(ee -> { + // Update the visibility of the authentication fields based on the selected + String selectedAuth = (String) authComboBox.getSelectedItem(); + if (selectedAuth.equals("Basic") || selectedAuth.equals("Digest")) { + usernameLabel.setVisible(true); + usernameField.setVisible(true); + usernameLabel.setEnabled(true); + usernameField.setEnabled(true); + + passwordLabel.setVisible(true); + passwordField.setVisible(true); + passwordLabel.setEnabled(true); + passwordField.setEnabled(true); + + bearerKeyLabel.setVisible(false); + bearerKeyField.setVisible(false); + bearerKeyLabel.setEnabled(false); + bearerKeyField.setEnabled(false); + } else if (selectedAuth.equals("Bearer")) { + usernameLabel.setVisible(false); + usernameField.setVisible(false); + usernameLabel.setEnabled(false); + usernameField.setEnabled(false); + + passwordLabel.setVisible(false); + passwordField.setVisible(false); + passwordLabel.setEnabled(false); + passwordField.setEnabled(false); + + bearerKeyLabel.setVisible(true); + bearerKeyField.setVisible(true); + bearerKeyLabel.setEnabled(true); + bearerKeyField.setEnabled(true); + } else { + usernameLabel.setVisible(false); + usernameField.setVisible(false); + usernameLabel.setEnabled(false); + usernameField.setEnabled(false); + + passwordLabel.setVisible(false); + passwordField.setVisible(false); + passwordLabel.setEnabled(false); + passwordField.setEnabled(false); + + bearerKeyLabel.setVisible(false); + bearerKeyField.setVisible(false); + bearerKeyLabel.setEnabled(false); + bearerKeyField.setEnabled(false); + } + + }); + + } else if (selectedBindingType.equals("Constant Alias")) { + // Create the alias name label + JBLabel aliasNameLabel = new JBLabel("Alias Name:"); + aliasGbc.gridx = 0; + aliasGbc.gridy = 0; + aliasPanel.add(aliasNameLabel, aliasGbc); + + // Create the alias name text field + JBTextField aliasNameField = new JBTextField(20); + aliasNameField.setToolTipText("Enter the alias name."); + aliasNameField.getEmptyText().setText("Enter the alias name."); + aliasGbc.gridx = 1; + aliasGbc.gridy = 0; + aliasPanel.add(aliasNameField, aliasGbc); + + // Create the value label + JBLabel valueLabel = new JBLabel("Value:"); + aliasGbc.gridx = 0; + aliasGbc.gridy = 1; + aliasPanel.add(valueLabel, aliasGbc); + + // Create the value text field + JBTextField valueField = new JBTextField(20); + valueField.setToolTipText("Enter the constant value."); + valueField.getEmptyText().setText("Enter the constant value."); + aliasGbc.gridx = 1; + aliasGbc.gridy = 1; + aliasPanel.add(valueField, aliasGbc); + } + + // Repaint the alias aliasPanel to show the updated components + aliasPanel.revalidate(); + aliasPanel.repaint(); + }); + bindingTypeComboBox.setSelectedIndex(0); + + // Add the binding type aliasPanel to the bindings aliasPanel + GridBagConstraints bindingsPanelGbc = new GridBagConstraints(); + bindingsPanelGbc.insets = new Insets(5, 5, 5, 5); + bindingsPanelGbc.anchor = GridBagConstraints.WEST; + bindingsPanelGbc.gridx = 0; + bindingsPanelGbc.gridy = bindingTypeCount; + bindingsPanelGbc.gridwidth = 3; + bindingsPanel.add(bindingTypePanel, bindingsPanelGbc); + + // Repaint the bindings aliasPanel to show the new binding type + bindingsPanel.revalidate(); + bindingsPanel.repaint(); + } + + private void removeBindingType() { + // Get the number of binding types + int bindingTypeCount = bindingsPanel.getComponentCount(); + + // Check if there are any binding types to remove + if (bindingTypeCount > 0) { + // Remove the last binding type aliasPanel + bindingsPanel.remove(bindingTypeCount - 1); + + // Repaint the bindings aliasPanel to show the removed binding type + bindingsPanel.revalidate(); + bindingsPanel.repaint(); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/couchbase/intellij/tree/CouchbaseWindowContent.java b/src/main/java/com/couchbase/intellij/tree/CouchbaseWindowContent.java index e17267dc..018f437d 100644 --- a/src/main/java/com/couchbase/intellij/tree/CouchbaseWindowContent.java +++ b/src/main/java/com/couchbase/intellij/tree/CouchbaseWindowContent.java @@ -22,6 +22,9 @@ import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; +import com.couchbase.intellij.eventing.FunctionDeploymentDialog; +import com.couchbase.intellij.eventing.FunctionDeploymentSettings; + import org.jetbrains.annotations.NotNull; import com.couchbase.client.java.manager.collection.CollectionSpec; @@ -125,8 +128,10 @@ public void actionPerformed(@NotNull AnActionEvent e) { JPopupMenu menu = new JPopupMenu(); JMenuItem item1 = new JMenuItem("New Project from Template"); JMenuItem item2 = new JMenuItem("Deploy Function"); + JMenuItem item3 = new JMenuItem("Function Settings"); menu.add(item1); menu.add(item2); + menu.add(item3); item1.addActionListener(e1 -> { CardDialog dialog = new CardDialog(project); @@ -134,11 +139,15 @@ public void actionPerformed(@NotNull AnActionEvent e) { }); item2.addActionListener(e2 -> { - // Code for "Test 2" here FunctionDeploymentDialog dialog = new FunctionDeploymentDialog(project); dialog.show(); }); + item3.addActionListener(e3 -> { + FunctionDeploymentSettings settings = new FunctionDeploymentSettings(); + settings.setVisible(true); + }); + Component component = e.getInputEvent().getComponent(); menu.show(component, component.getWidth() / 2, component.getHeight() / 2); } From 595258f99af86bd134f8dc12041765a1956015e4 Mon Sep 17 00:00:00 2001 From: teetangh Date: Mon, 12 Jun 2023 10:18:55 +0530 Subject: [PATCH 05/15] Major Refactor of Code. Both FunctionDeployDialog and FunctionDeploySettings working --- .../eventing/FunctionDeploymentDialog.java | 995 +----------------- .../eventing/FunctionDeploymentSettings.java | 857 +-------------- .../{ => components}/CustomComboBox.java | 8 +- .../eventing/settings/AdvancedSettings.java | 257 +++++ .../eventing/settings/BindingSettings.java | 464 ++++++++ .../eventing/settings/GeneralSettings.java | 282 +++++ 6 files changed, 1082 insertions(+), 1781 deletions(-) rename src/main/java/com/couchbase/intellij/eventing/{ => components}/CustomComboBox.java (75%) create mode 100644 src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java create mode 100644 src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java create mode 100644 src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java diff --git a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentDialog.java b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentDialog.java index 3a44cbc5..8780755a 100644 --- a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentDialog.java +++ b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentDialog.java @@ -1,141 +1,23 @@ - -// This is the UI - -// First line - heading -// Function Scope(Bold) bucket.scope(small greyed out) info icon(on hover displays-A bucket.scope combination used for identifying functions belonging to the same group.) - -// Error label for this(by default when nothing is selected)-> Please specify a scope to which the function belongs. User should have Eventing Manage Scope Functions permission on this scope - -// Second line - two horizontal dropdown boxes -// 1. Select from available buckets (or *) 2. Select from scopes available in that bucket (The first scope gets selected automatically when the bucket is selected) - -// Third line - heading -// Listen to location (Bold) bucket.scope.collection (small greyed out) info icon(on hover displays-The function will listen to this resource for changes. Memcached buckets are not allowed.) - -// Error label for this(by default when nothing is selected)-> Please specify a source location for your function. User should have DCP Data Read permission on this keyspace - -// Fourth line - three horizontal dropdown boxes -// 1. Select from available buckets (or *) 2. Select from scopes available in that bucket (The first scope gets selected automatically when the bucket is selected) 3. Select from collections available in that scope (The first collection gets selected automatically when the scope is selected) - -// Fifth line - heading -// Eventing Storage (Bold) bucket.scope.collection (small greyed out) info icon(on hover displays-This resource is used to store system data and should not be used by other applications.) - -// Error label for this(by default when nothing is selected)-> Please specify a location to store Eventing data. User should have read/write permission on this keyspace - -// Sixth line - three horizontal dropdown boxes -// 1. Select from available buckets (or *) 2. Select from scopes available in that bucket (The first scope gets selected automatically when the bucket is selected) 3. Select from collections available in that scope (The first collection gets selected automatically when the scope is selected) - -// Seventh line - heading -// Function Name (Bold) - -// Eighth line - full line text box -// Text box for Function Name - -// Error label depends on text box validation - -// Ninth line - heading -// Deployment Feed Boundary(Bold) info icon(on hover The preferred Deployment time Feed Boundary for the function.) - -// Tenth line - 1 drop down box with 2 options -// The dropdown box should contain “Everything” and “From now” - -// Eleventh line - heading -// Description(bold) optional(text in small, grayed out and round braces) - -// Twelfth line - Text Area -// Text Area for big paragraph text writing (This is a text area not a text field) - -// Thirteenth line - Openable Settings. -// Settings(bold) -// There is a small right arrow before the word settings. On clicking the right menu. The form fill-up menu opens up -// { -// First line - heading -// System Log Level(Bold) , small info icon(on hover shows: Granularity of system events being captured in the log) - -// Second line - dropdown menu -// Dropdown menu contains: Info, Error, Warning, Debug and Trace - -// Info label - below dropdown menu -// “Application log file for this Function is at:” - -// Third Line - heading -// N1QL Consistency(bold) small info icon(on hover shows: Consistency level of N1QL statements in the function) - -// Fourth line - dropdown menu -// Dropdown menu contains: None and Request - -// Fifth Line - heading -// Workers(bold) small info icon(on hover shows: Number of workers per node to process the events. If no value is specified, a default value of 1 worker is used.) - -// Sixth Line - text field -// Text field can take only a natural number - -// Seventh line - heading -// Language compatibility (Bold) , small info icon(on hover shows: Language compatibility of the function) - -// Eighth line - dropdown menu -// Dropdown menu contains: 6.0.0, 6.5.0, 6.6.2 - -// Ninth Line - heading -// Script Timeout(bold) in seconds (small greyed out text) small info icon(on hover shows: Time after which the Function's execution will be timed out) - -// Tenth Line - text field -// Text field can take only a natural number (default initial value: 60) - -// Eleventh Line - heading -// Timer Context Max Size (bold) small info icon(on hover shows: Maximum allowed value of the Timer Context Size in Bytes. Takes effect immediately.) - -// Twelfth Line - text field -// Text field can take only a natural number (default initial value: 1024) -// } - -// Fourteen Line - Openable Settings. -// Binding Type (Bold left end of line) (Plus minus square buttons on the right end[plus adds a new binding type based on the dropdown menu, minus removes the last binding type]) -// Horizontal line separator. - -// Here we can add any number of 3 types of binding types[from the dropdown menu(s)]. The dropdown menu contains: -// Binding type(default unelectable greyed out), Bucket Alias, URL alias, constant alias. - -// { -// 1. if it is bucket alias, then first line is bucket alias(the dropdown menu itself), and textfield with placeholder text of “alias name” -// Second line contains heading Bucket(bold) bucket.scope.collection (small greyed out) Access(bold) -// Third line contains 3 dropdown boxes for bucket scope collection respectively. And 4th dropdown for Access(2 options of “read only” and “read and write” ) - -// 2. If its URL alias, then first line is URL alias(the dropdown menu itself), and two textfields containing placeholder texts of “Alias name..” and “URL...” Respectively. -// The next line contains two checkboxes: 1. allow cookies 2. validate SSL certificate -// The next line contains dropdown menu of: 1. no auth 2. basic 3. bearer4. digest -// { -// 2a. if the user chooses, basic, the same line as dropdown menu should have two textfields containing placeholder texts of “Username..” and “password…” Respectively. -// 2b. if the user chooses, bearer, the same line as dropdown menu should have 1 textfield containing placeholder texts of “bearer key..” -// 2c. if the user chooses, digest, the same line as dropdown menu should have two textfields containing placeholder texts of “Username..” and “password…” Respectively. -// } - -// if it is constant alias, the first line is constant alias(the dropdown menu itself) and two textfields containing placeholder texts of “Username..” and “password…” Respectively. -// } package com.couchbase.intellij.eventing; -import java.awt.Color; -import java.awt.Dimension; +import java.awt.FlowLayout; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; -import java.awt.Insets; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Set; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.JTextArea; -import javax.swing.JTextField; import org.jetbrains.annotations.Nullable; +import com.couchbase.intellij.eventing.settings.AdvancedSettings; +import com.couchbase.intellij.eventing.settings.BindingSettings; +import com.couchbase.intellij.eventing.settings.GeneralSettings; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; @@ -143,34 +25,17 @@ public class FunctionDeploymentDialog extends DialogWrapper { public Set buckets; private JPanel mainPanel; - private JLabel errorLabel; - - private JComboBox bucketComboBox; - private JComboBox scopeComboBox; - private JComboBox collectionComboBox; - private JComboBox deploymentFeedBoundaryComboBox; - private JComboBox systemLogsLevelComboBox; - private JComboBox n1qlConsistencyComboBox; - private JComboBox languageCompatibilityComboBox; - - private JTextField functionNameField; - private JTextField workersField; - private JTextField scriptTimeoutField; - private JTextField timerContextMaxSizeField; - - private JTextArea functionDescriptionArea; - - private JPanel settingsPanel; + private JPanel generalSettingsPanel; + private JPanel advancedSettingsPanel; private JPanel bindingsPanel; - private boolean settingsPanelExpanded = false; - private int bindingTypeCount = 0; + private boolean advancedSettingsPanelExpanded = false; public FunctionDeploymentDialog(@Nullable Project project) { super(project); this.buckets = null; setTitle("Deploy as a Couchbase Function"); - setSize(1000, 2000); + setSize(1000, 1000); setResizable(true); init(); } @@ -179,209 +44,15 @@ public FunctionDeploymentDialog(@Nullable Project project) { @Override protected JComponent createCenterPanel() { mainPanel = new JPanel(new GridBagLayout()); - GridBagConstraints gbc = new GridBagConstraints(); - gbc.insets = new Insets(5, 10, 5, 10); - gbc.anchor = GridBagConstraints.WEST; - - // Function Scope label - JLabel functionScopeLabel = new JLabel("Function Scope"); - functionScopeLabel.setFont(functionScopeLabel.getFont().deriveFont(Font.BOLD)); - gbc.gridx = 0; - gbc.gridy = 0; - mainPanel.add(functionScopeLabel, gbc); - - JLabel functionScopeInfoLabel = new JLabel("bucket.scope"); - functionScopeInfoLabel.setForeground(Color.GRAY); - gbc.gridx = 1; - gbc.gridy = 0; - mainPanel.add(functionScopeInfoLabel, gbc); - - bucketComboBox = new JComboBox<>(); - bucketComboBox.addActionListener(e -> updateScopes()); - gbc.gridx = 0; - gbc.gridy = 1; - mainPanel.add(bucketComboBox, gbc); - - scopeComboBox = new JComboBox<>(); - scopeComboBox.setEnabled(false); - gbc.gridx = 1; - gbc.gridy = 1; - mainPanel.add(scopeComboBox, gbc); - - // Function Scope error label - - errorLabel = new JLabel( - "Please specify a scope to which the function belongs. User should have Eventing Manage Scope Functions permission on this scope"); - errorLabel.setForeground(Color.RED); - gbc.gridx = 0; - gbc.gridy = 2; - gbc.gridwidth = 3; - mainPanel.add(errorLabel, gbc); - - // Listen to location label - JLabel listenToLocationLabel = new JLabel("Listen to location"); - listenToLocationLabel.setFont(listenToLocationLabel.getFont().deriveFont(Font.BOLD)); - gbc.gridx = 0; - gbc.gridy = 3; - mainPanel.add(listenToLocationLabel, gbc); - - JLabel listenToLocationInfoLabel = new JLabel("bucket.scope.collection"); - listenToLocationInfoLabel.setForeground(Color.GRAY); - gbc.gridx = 1; - gbc.gridy = 3; - mainPanel.add(listenToLocationInfoLabel, gbc); - - bucketComboBox = new JComboBox<>(); - bucketComboBox.addActionListener(e -> updateScopes()); - gbc.gridx = 0; - gbc.gridy = 4; - mainPanel.add(bucketComboBox, gbc); - - scopeComboBox = new JComboBox<>(); - scopeComboBox.setEnabled(false); - gbc.gridx = 1; - gbc.gridy = 4; - mainPanel.add(scopeComboBox, gbc); - - collectionComboBox = new JComboBox<>(); - collectionComboBox.setEnabled(false); - gbc.gridx = 2; - gbc.gridy = 4; - mainPanel.add(collectionComboBox, gbc); - - // Listen to location error label - errorLabel = new JLabel( - "Please specify a source location for your function. User should have DCP Data Read permission on this keyspace"); - errorLabel.setForeground(Color.RED); - gbc.gridx = 0; - gbc.gridy = 5; - gbc.gridwidth = 3; - mainPanel.add(errorLabel, gbc); - - // Eventing Storage label - JLabel eventingStorageLabel = new JLabel("Eventing Storage"); - eventingStorageLabel.setFont(eventingStorageLabel.getFont().deriveFont(Font.BOLD)); - gbc.gridx = 0; - gbc.gridy = 6; - mainPanel.add(eventingStorageLabel, gbc); + GridBagConstraints mainPanelConstraints = new GridBagConstraints(); + mainPanelConstraints.anchor = GridBagConstraints.NORTHWEST; - JLabel eventingStorageInfoLabel = new JLabel("bucket.scope.collection"); - eventingStorageInfoLabel.setForeground(Color.GRAY); - gbc.gridx = 1; - gbc.gridy = 6; - gbc.gridwidth = 2; - mainPanel.add(eventingStorageInfoLabel, gbc); + GeneralSettings generalSettings = new GeneralSettings(); + generalSettingsPanel = generalSettings.getPanel(); - bucketComboBox = new JComboBox<>(); - bucketComboBox.addActionListener(e -> updateScopes()); - gbc.gridx = 0; - gbc.gridy = 7; - mainPanel.add(bucketComboBox, gbc); - - scopeComboBox = new JComboBox<>(); - scopeComboBox.setEnabled(false); - gbc.gridx = 1; - gbc.gridy = 7; - mainPanel.add(scopeComboBox, gbc); - - collectionComboBox = new JComboBox<>(); - collectionComboBox.setEnabled(false); - gbc.gridx = 2; - gbc.gridy = 7; - mainPanel.add(collectionComboBox, gbc); - - // Eventing Storage error label - errorLabel = new JLabel( - "Please specify a location to store Eventing data. User should have read/write permission on this keyspace"); - errorLabel.setForeground(Color.RED); - gbc.gridx = 0; - gbc.gridy = 8; - gbc.gridwidth = 3; - mainPanel.add(errorLabel, gbc); - - // Function Name label and text field - JLabel functionNameLabel = new JLabel("Function Name"); - functionNameLabel.setFont(functionNameLabel.getFont().deriveFont(Font.BOLD)); - gbc.gridx = 0; - gbc.gridy = 9; - mainPanel.add(functionNameLabel, gbc); - - functionNameField = new JTextField(20); - functionNameField.setToolTipText("Enter the name of the function."); - // functionNameField.getDocument().addDocumentListener(new DocumentListener() { - // @Override - // public void insertUpdate(DocumentEvent e) { - // validateFunctionName(); - // } - - // @Override - // public void removeUpdate(DocumentEvent e) { - // validateFunctionName(); - // } - - // @Override - // public void changedUpdate(DocumentEvent e) { - // validateFunctionName(); - // } - // }); - gbc.gridx = 0; - gbc.gridy = 10; - mainPanel.add(functionNameField, gbc); - - // Deployment Feed Boundary label and combo box - JLabel deploymentFeedBoundaryLabel = new JLabel("Deployment Feed Boundary"); - deploymentFeedBoundaryLabel.setFont(deploymentFeedBoundaryLabel.getFont().deriveFont(Font.BOLD)); - deploymentFeedBoundaryLabel.setToolTipText( - "The preferred Deployment time Feed Boundary for the function."); - gbc.gridx = 0; - gbc.gridy = 11; - mainPanel.add(deploymentFeedBoundaryLabel, gbc); - - deploymentFeedBoundaryComboBox = new JComboBox<>(); - deploymentFeedBoundaryComboBox.addItem("Everything"); - deploymentFeedBoundaryComboBox.addItem("From now"); - deploymentFeedBoundaryComboBox.setToolTipText( - "The preferred Deployment time Feed Boundary for the function."); - deploymentFeedBoundaryComboBox.addActionListener(e -> { - if (deploymentFeedBoundaryComboBox.getSelectedItem().equals("From now")) { - errorLabel.setText( - "Warning: Deploying with 'From now' will ignore all past mutations."); - } else { - errorLabel.setText(""); - } - }); - gbc.gridx = 0; - gbc.gridy = 12; - mainPanel.add(deploymentFeedBoundaryComboBox, gbc); - - // Description label and text area - JLabel descriptionLabel = new JLabel("Description"); - descriptionLabel.setFont(descriptionLabel.getFont().deriveFont(Font.BOLD)); - descriptionLabel.setToolTipText("Enter a description for the function (optional)."); - descriptionLabel.setDisplayedMnemonic('D'); - descriptionLabel.setDisplayedMnemonicIndex(0); - descriptionLabel.setLabelFor(functionDescriptionArea); - descriptionLabel.setHorizontalAlignment(JTextField.LEFT); - descriptionLabel.setVerticalAlignment(JTextField.CENTER); - descriptionLabel.setHorizontalTextPosition(JTextField.RIGHT); - descriptionLabel.setVerticalTextPosition(JTextField.CENTER); - gbc.gridx = 0; - gbc.gridy = 13; - mainPanel.add(descriptionLabel, gbc); - - functionDescriptionArea = new JTextArea(5, 100); - functionDescriptionArea.setLineWrap(true); - functionDescriptionArea.setWrapStyleWord(true); - functionDescriptionArea.setToolTipText("Enter a description for the function (optional)."); - - JScrollPane textJScrollPane = new JScrollPane(functionDescriptionArea); - textJScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - textJScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - textJScrollPane.setPreferredSize(new Dimension(800, 200)); - - gbc.gridx = 0; - gbc.gridy = 14; - mainPanel.add(textJScrollPane, gbc); + mainPanelConstraints.gridx = 0; + mainPanelConstraints.gridy = 0; + mainPanel.add(generalSettingsPanel, mainPanelConstraints); // Settings label and expandable mainPanel // Add a toggle button for the settings mainPanel @@ -390,628 +61,76 @@ protected JComponent createCenterPanel() { @Override public void mouseClicked(MouseEvent e) { // Toggle the expanded state of the settings mainPanel - settingsPanelExpanded = !settingsPanelExpanded; + advancedSettingsPanelExpanded = !advancedSettingsPanelExpanded; // Show or hide the settings mainPanel based on its expanded state - if (settingsPanelExpanded) { + if (advancedSettingsPanelExpanded) { settingsToggleButton.setText("▼"); - settingsPanel.setVisible(true); + advancedSettingsPanel.setVisible(true); } else { settingsToggleButton.setText("▶"); - settingsPanel.setVisible(false); + advancedSettingsPanel.setVisible(false); } } }); - gbc.gridx = 0; - gbc.gridy = 15; - mainPanel.add(settingsToggleButton, gbc); // TODO: Add label and expandable mainPanel for settings JLabel settingsLabel = new JLabel("Settings"); settingsLabel.setFont(settingsLabel.getFont().deriveFont(Font.BOLD)); settingsLabel.setToolTipText("Click to expand/collapse the Settings section."); - gbc.gridx = 1; - gbc.gridy = 15; - mainPanel.add(settingsLabel, gbc); - - settingsPanel = new JPanel(new GridBagLayout()); - GridBagConstraints settingsGbc = new GridBagConstraints(); - settingsGbc.insets = new Insets(5, 10, 5, 10); - settingsGbc.anchor = GridBagConstraints.WEST; - - // System logs level label and combo box - JLabel systemLogsLevelLabel = new JLabel("System Logs Level"); - systemLogsLevelLabel.setFont(systemLogsLevelLabel.getFont().deriveFont(Font.BOLD)); - systemLogsLevelLabel.setToolTipText( - "Granularity of system events being captured in the log."); - systemLogsLevelLabel.setDisplayedMnemonic('L'); - systemLogsLevelLabel.setDisplayedMnemonicIndex(7); - systemLogsLevelLabel.setLabelFor(systemLogsLevelComboBox); - systemLogsLevelLabel.setHorizontalAlignment(JTextField.LEFT); - systemLogsLevelLabel.setVerticalAlignment(JTextField.CENTER); - systemLogsLevelLabel.setHorizontalTextPosition(JTextField.RIGHT); - systemLogsLevelLabel.setVerticalTextPosition(JTextField.CENTER); - settingsGbc.gridx = 0; - settingsGbc.gridy = 0; - settingsPanel.add(systemLogsLevelLabel, settingsGbc); - systemLogsLevelComboBox = new JComboBox<>(); - systemLogsLevelComboBox.addItem("Error"); - systemLogsLevelComboBox.addItem("Warning"); - systemLogsLevelComboBox.addItem("Info"); - systemLogsLevelComboBox.addItem("Debug"); - systemLogsLevelComboBox.addItem("Trace"); - systemLogsLevelComboBox.setToolTipText( - "Granularity of system events being captured in the log."); - settingsGbc.gridx = 0; - settingsGbc.gridy = 1; - settingsGbc.gridwidth = 2; - settingsPanel.add(systemLogsLevelComboBox, settingsGbc); + // Add both the toggle button and the label to a FlowLayout + JPanel settingsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + settingsPanel.add(settingsToggleButton); + settingsPanel.add(settingsLabel); + mainPanelConstraints.gridx = 0; + mainPanelConstraints.gridy = 17; + mainPanel.add(settingsPanel, mainPanelConstraints); - JLabel systemLogsLevelInfoLabel = new JLabel( - "Application logs file for this function is at:"); - systemLogsLevelInfoLabel.setForeground(Color.GRAY); - settingsGbc.gridx = 0; - settingsGbc.gridy = 2; - settingsGbc.gridwidth = 2; - settingsPanel.add(systemLogsLevelInfoLabel, settingsGbc); + AdvancedSettings advancedSettings = new AdvancedSettings(); + advancedSettingsPanel = advancedSettings.getPanel(); + advancedSettingsPanel.setVisible(false); - // N1QL Consistency label and combo box - JLabel n1QLConsistencyLabel = new JLabel("N1QL Consistency"); - n1QLConsistencyLabel.setFont(n1QLConsistencyLabel.getFont().deriveFont(Font.BOLD)); - n1QLConsistencyLabel.setToolTipText( - "Consistency level of N1QL statements in the function."); - n1QLConsistencyLabel.setDisplayedMnemonic('N'); - n1QLConsistencyLabel.setDisplayedMnemonicIndex(0); - n1QLConsistencyLabel.setLabelFor(n1qlConsistencyComboBox); - n1QLConsistencyLabel.setHorizontalAlignment(JTextField.LEFT); - n1QLConsistencyLabel.setVerticalAlignment(JTextField.CENTER); - n1QLConsistencyLabel.setHorizontalTextPosition(JTextField.RIGHT); - n1QLConsistencyLabel.setVerticalTextPosition(JTextField.CENTER); - settingsGbc.gridx = 0; - settingsGbc.gridy = 3; - settingsPanel.add(n1QLConsistencyLabel, settingsGbc); - - n1qlConsistencyComboBox = new JComboBox<>(); - n1qlConsistencyComboBox.addItem("None"); - n1qlConsistencyComboBox.addItem("Request"); - n1qlConsistencyComboBox.setToolTipText( - "Consistency level of N1QL statements in the function."); - settingsGbc.gridx = 0; - settingsGbc.gridy = 4; - settingsGbc.gridwidth = 2; - settingsPanel.add(n1qlConsistencyComboBox, settingsGbc); - - // Workers label and text field - JLabel workersLabel = new JLabel("Workers"); - workersLabel.setFont(workersLabel.getFont().deriveFont(Font.BOLD)); - workersLabel.setToolTipText( - "Number of worker threads processing this function."); - workersLabel.setDisplayedMnemonic('W'); - workersLabel.setDisplayedMnemonicIndex(0); - workersLabel.setLabelFor(workersField); - workersLabel.setHorizontalAlignment(JTextField.LEFT); - workersLabel.setVerticalAlignment(JTextField.CENTER); - workersLabel.setHorizontalTextPosition(JTextField.RIGHT); - workersLabel.setVerticalTextPosition(JTextField.CENTER); - settingsGbc.gridx = 0; - settingsGbc.gridy = 5; - settingsPanel.add(workersLabel, settingsGbc); - - workersField = new JTextField(20); - workersField.setToolTipText( - "Number of worker threads processing this function."); - workersField.setText("1"); - settingsGbc.gridx = 0; - settingsGbc.gridy = 6; - settingsGbc.gridwidth = 2; - settingsPanel.add(workersField, settingsGbc); - - // Language Compatibility label and combo box - JLabel languageCompatibilityLabel = new JLabel("Language Compatibility"); - languageCompatibilityLabel.setFont(languageCompatibilityLabel.getFont().deriveFont(Font.BOLD)); - languageCompatibilityLabel.setToolTipText( - "Language compatibility version for this function."); - languageCompatibilityLabel.setDisplayedMnemonic('C'); - languageCompatibilityLabel.setDisplayedMnemonicIndex(9); - languageCompatibilityLabel.setLabelFor(languageCompatibilityComboBox); - languageCompatibilityLabel.setHorizontalAlignment(JTextField.LEFT); - languageCompatibilityLabel.setVerticalAlignment(JTextField.CENTER); - languageCompatibilityLabel.setHorizontalTextPosition(JTextField.RIGHT); - languageCompatibilityLabel.setVerticalTextPosition(JTextField.CENTER); - settingsGbc.gridx = 0; - settingsGbc.gridy = 7; - settingsPanel.add(languageCompatibilityLabel, settingsGbc); - - languageCompatibilityComboBox = new JComboBox<>(); - languageCompatibilityComboBox.addItem("6.0.0"); - languageCompatibilityComboBox.addItem("6.5.0"); - languageCompatibilityComboBox.addItem("6.6.2"); - languageCompatibilityComboBox.setToolTipText( - "Language compatibility version for this function."); - settingsGbc.gridx = 0; - settingsGbc.gridy = 8; - settingsGbc.gridwidth = 2; - settingsPanel.add(languageCompatibilityComboBox, settingsGbc); - - // Script Timeout label and text field - JLabel scriptTimeoutLabel = new JLabel("Script Timeout"); - scriptTimeoutLabel.setFont(scriptTimeoutLabel.getFont().deriveFont(Font.BOLD)); - scriptTimeoutLabel.setToolTipText( - "Maximum execution time for each instance of the function."); - scriptTimeoutLabel.setDisplayedMnemonic('S'); - scriptTimeoutLabel.setDisplayedMnemonicIndex(0); - scriptTimeoutLabel.setLabelFor(scriptTimeoutField); - scriptTimeoutLabel.setHorizontalAlignment(JTextField.LEFT); - scriptTimeoutLabel.setVerticalAlignment(JTextField.CENTER); - scriptTimeoutLabel.setHorizontalTextPosition(JTextField.RIGHT); - scriptTimeoutLabel.setVerticalTextPosition(JTextField.CENTER); - settingsGbc.gridx = 0; - settingsGbc.gridy = 9; - settingsPanel.add(scriptTimeoutLabel, settingsGbc); - - JLabel scriptTimeoutInfoLabel = new JLabel("in seconds."); - scriptTimeoutInfoLabel.setForeground(Color.GRAY); - settingsGbc.gridx = 1; - settingsGbc.gridy = 9; - settingsPanel.add(scriptTimeoutInfoLabel, settingsGbc); - - scriptTimeoutField = new JTextField(20); - scriptTimeoutField.setToolTipText( - "Maximum execution time for each instance of the function."); - scriptTimeoutField.setText("60"); - settingsGbc.gridx = 0; - settingsGbc.gridy = 10; - settingsGbc.gridwidth = 2; - settingsPanel.add(scriptTimeoutField, settingsGbc); - - // Timer Context Timeout label and text field - JLabel timerContextMaxSizeLabel = new JLabel("Timer Context Max Size"); - timerContextMaxSizeLabel.setFont(timerContextMaxSizeLabel.getFont().deriveFont(Font.BOLD)); - timerContextMaxSizeLabel.setToolTipText( - "Maximum size of context object for timers."); - timerContextMaxSizeLabel.setDisplayedMnemonic('T'); - timerContextMaxSizeLabel.setDisplayedMnemonicIndex(0); - timerContextMaxSizeLabel.setLabelFor(timerContextMaxSizeField); - timerContextMaxSizeLabel.setHorizontalAlignment(JTextField.LEFT); - timerContextMaxSizeLabel.setVerticalAlignment(JTextField.CENTER); - timerContextMaxSizeLabel.setHorizontalTextPosition(JTextField.RIGHT); - timerContextMaxSizeLabel.setVerticalTextPosition(JTextField.CENTER); - settingsGbc.gridx = 0; - settingsGbc.gridy = 11; - settingsPanel.add(timerContextMaxSizeLabel, settingsGbc); - - timerContextMaxSizeField = new JTextField(20); - timerContextMaxSizeField.setToolTipText( - "Maximum size of context object for timers."); - timerContextMaxSizeField.setText("1024"); - settingsGbc.gridx = 0; - settingsGbc.gridy = 12; - settingsGbc.gridwidth = 2; - settingsPanel.add(timerContextMaxSizeField, settingsGbc); - - gbc.gridx = 0; - gbc.gridy = 16; - mainPanel.add(settingsPanel, gbc); + mainPanelConstraints.gridx = 0; + mainPanelConstraints.gridy = 18; + mainPanel.add(advancedSettingsPanel, mainPanelConstraints); // Binding Type label and expandable mainPanel // TODO: Add label and expandable mainPanel for binding type - bindingsPanel = new JPanel(new GridBagLayout()); - GridBagConstraints bindingsPanelGbc = new GridBagConstraints(); - bindingsPanelGbc.insets = new Insets(5, 5, 5, 5); - bindingsPanelGbc.anchor = GridBagConstraints.WEST; - - // Binding Type label - JLabel bindingTypeLabel = new JLabel("Binding Type"); - bindingTypeLabel.setFont(bindingTypeLabel.getFont().deriveFont(Font.BOLD)); - bindingsPanelGbc.gridx = 0; - bindingsPanelGbc.gridy = 0; - bindingsPanel.add(bindingTypeLabel, bindingsPanelGbc); - - // Plus button - JButton plusButton = new JButton("+"); - plusButton.addActionListener(e -> addBindingType()); - bindingsPanelGbc.gridx = 1; - bindingsPanelGbc.gridy = 0; - bindingsPanel.add(plusButton, bindingsPanelGbc); + BindingSettings bindingSettings = new BindingSettings(); + bindingsPanel = bindingSettings.getPanel(); - // Minus button - JButton minusButton = new JButton("-"); - minusButton.addActionListener(e -> removeBindingType()); - bindingsPanelGbc.gridx = 2; - bindingsPanelGbc.gridy = 0; - bindingsPanel.add(minusButton, bindingsPanelGbc); - - gbc.gridx = 0; - gbc.gridy = 17; - mainPanel.add(bindingsPanel, gbc); + mainPanelConstraints.gridx = 0; + mainPanelConstraints.gridy = 19; + mainPanel.add(bindingsPanel, mainPanelConstraints); return new JScrollPane(mainPanel); } - private void addBindingType() { - // Increment the binding type count - bindingTypeCount++; - - // Create a new aliasPanel to hold the binding type components - JPanel bindingTypePanel = new JPanel(new GridBagLayout()); - GridBagConstraints bindingsGbc = new GridBagConstraints(); - bindingsGbc.insets = new Insets(5, 5, 5, 5); - bindingsGbc.anchor = GridBagConstraints.WEST; - - // Create the binding type dropdown menu - CustomComboBox bindingTypeComboBox = new CustomComboBox(); - bindingTypeComboBox.setToolTipText("Type of binding for this function."); - bindingTypeComboBox.addItem("Choose Binding Type"); - bindingTypeComboBox.addItem("Bucket Alias"); - bindingTypeComboBox.addItem("URL Alias"); - bindingTypeComboBox.addItem("Constant Alias"); - - bindingsGbc.gridx = 0; - bindingsGbc.gridy = 0; - bindingTypePanel.add(bindingTypeComboBox, bindingsGbc); - - // Create a aliasPanel to hold the alias-specific components - JPanel aliasPanel = new JPanel(new GridBagLayout()); - GridBagConstraints aliasGbc = new GridBagConstraints(); - aliasGbc.insets = new Insets(5, 5, 5, 5); - aliasGbc.anchor = GridBagConstraints.WEST; - bindingsGbc.gridx = 1; - bindingsGbc.gridy = 0; - bindingsGbc.gridwidth = 2; - bindingTypePanel.add(aliasPanel, bindingsGbc); - - // Update the alias aliasPanel when the selected binding type changes - bindingTypeComboBox.addItemListener(e -> { - // Remove all components from the alias aliasPanel - aliasPanel.removeAll(); - - // Get the selected binding type - String selectedBindingType = (String) bindingTypeComboBox.getSelectedItem(); - - if (selectedBindingType.equals("Bucket Alias")) { - // Create the alias name text field - JTextField aliasNameField = new JTextField(20); - aliasNameField.setToolTipText("Enter the alias name."); - aliasGbc.gridx = 0; - aliasGbc.gridy = 0; - aliasGbc.gridwidth = 8; - aliasPanel.add(aliasNameField, aliasGbc); - - // Create the bucket label - JLabel bucketLabel = new JLabel("Bucket"); - bucketLabel.setFont(bucketLabel.getFont().deriveFont(Font.BOLD)); - aliasGbc.gridx = 0; - aliasGbc.gridy = 1; - aliasGbc.gridwidth = 1; - aliasPanel.add(bucketLabel, aliasGbc); - - // Create the bucket info label - JLabel bucketInfoLabel = new JLabel("bucket.scope.collection"); - bucketInfoLabel.setForeground(Color.GRAY); - aliasGbc.gridx = 1; - aliasGbc.gridy = 1; - aliasPanel.add(bucketInfoLabel, aliasGbc); - - // Create the access label - JLabel accessLabel = new JLabel("Access"); - accessLabel.setFont(accessLabel.getFont().deriveFont(Font.BOLD)); - aliasGbc.gridx = 3; - aliasGbc.gridy = 1; - aliasPanel.add(accessLabel, aliasGbc); - - // Create the bucket dropdown menu - JComboBox bucketComboBox = new JComboBox<>(); - // TODO: Populate the bucketComboBox with available buckets - aliasGbc.gridx = 0; - aliasGbc.gridy = 2; - aliasPanel.add(bucketComboBox, aliasGbc); - - // Create the scope dropdown menu - JComboBox scopeComboBox = new JComboBox<>(); - scopeComboBox.setEnabled(false); - // TODO: Update the scopeComboBox when the selected bucket changes - aliasGbc.gridx = 1; - aliasGbc.gridy = 2; - aliasGbc.fill = GridBagConstraints.HORIZONTAL; - aliasPanel.add(scopeComboBox, aliasGbc); - - // Create the collection dropdown menu - JComboBox collectionComboBox = new JComboBox<>(); - collectionComboBox.setEnabled(false); - // TODO: Update the collectionComboBox when the selected scope changes - aliasGbc.gridx = 2; - aliasGbc.gridy = 2; - aliasGbc.fill = GridBagConstraints.NONE; - aliasPanel.add(collectionComboBox, aliasGbc); - - // Create access dropdown menu - JComboBox accessComboBox = new JComboBox<>(); - accessComboBox.addItem("Read Only"); - accessComboBox.addItem("Read and Write"); - accessComboBox.setToolTipText("Select access level for this bucket."); - accessComboBox.setEnabled(true); - accessComboBox.setSelectedIndex(0); - aliasGbc.gridx = 3; - aliasGbc.gridy = 2; - aliasPanel.add(accessComboBox, aliasGbc); - - } else if (selectedBindingType.equals("URL Alias")) { - // Create the alias name text field - JTextField aliasNameField = new JTextField(20); - aliasNameField.setToolTipText("Enter the alias name."); - aliasGbc.gridx = 0; - aliasGbc.gridy = 0; - aliasPanel.add(aliasNameField, aliasGbc); - - // Create the URL text field - JTextField urlField = new JTextField(20); - urlField.setToolTipText("Enter the URL."); - aliasGbc.gridx = 1; - aliasGbc.gridy = 0; - aliasPanel.add(urlField, aliasGbc); - - // Create the allow cookies checkbox - JCheckBox allowCookiesCheckBox = new JCheckBox("Allow cookies"); - allowCookiesCheckBox.setToolTipText("Allow cookies for this URL."); - aliasGbc.gridx = 0; - aliasGbc.gridy = 1; - aliasPanel.add(allowCookiesCheckBox, aliasGbc); - - // Create the validate SSL certificate checkbox - JCheckBox validateSslCertificateCheckBox = new JCheckBox("Validate SSL certificate"); - validateSslCertificateCheckBox.setToolTipText("Validate SSL certificate for this URL."); - aliasGbc.gridx = 1; - aliasGbc.gridy = 1; - aliasPanel.add(validateSslCertificateCheckBox, aliasGbc); - - // Create the authentication label - JLabel authenticationLabel = new JLabel("Authentication"); - authenticationLabel.setFont(authenticationLabel.getFont().deriveFont(Font.BOLD)); - authenticationLabel.setToolTipText("Select authentication method for this URL."); - authenticationLabel.setDisplayedMnemonic('A'); - authenticationLabel.setDisplayedMnemonicIndex(0); - authenticationLabel.setHorizontalAlignment(JTextField.LEFT); - authenticationLabel.setVerticalAlignment(JTextField.CENTER); - authenticationLabel.setHorizontalTextPosition(JTextField.RIGHT); - authenticationLabel.setVerticalTextPosition(JTextField.CENTER); - aliasGbc.gridx = 0; - aliasGbc.gridy = 2; - aliasPanel.add(authenticationLabel, aliasGbc); - - // Create the auth dropdown menu - CustomComboBox authComboBox = new CustomComboBox(); - authComboBox.addItem("No Auth"); - authComboBox.addItem("Basic"); - authComboBox.addItem("Bearer"); - authComboBox.addItem("Digest"); - authComboBox.setToolTipText("Select authentication method for this URL."); - authComboBox.setEnabled(true); - - authComboBox.setSelectedIndex(0); - aliasGbc.gridx = 1; - aliasGbc.gridy = 2; - aliasPanel.add(authComboBox, aliasGbc); - - // Create the username label and text field - JLabel usernameLabel = new JLabel("Username"); - usernameLabel.setFont(usernameLabel.getFont().deriveFont(Font.BOLD)); - usernameLabel.setToolTipText("Enter the username for basic or digest authentication."); - usernameLabel.setDisplayedMnemonic('U'); - usernameLabel.setDisplayedMnemonicIndex(0); - usernameLabel.setHorizontalAlignment(JTextField.LEFT); - usernameLabel.setVerticalAlignment(JTextField.CENTER); - usernameLabel.setHorizontalTextPosition(JTextField.RIGHT); - usernameLabel.setVerticalTextPosition(JTextField.CENTER); - usernameLabel.setVisible(false); - usernameLabel.setEnabled(false); - bindingsGbc.gridx = 0; - bindingsGbc.gridy = 3; - aliasPanel.add(usernameLabel, bindingsGbc); - - JTextField usernameField = new JTextField(20); - usernameField.setToolTipText( - "Enter the username for basic or digest authentication."); - usernameField.setVisible(false); - usernameField.setEnabled(false); - bindingsGbc.gridx = 1; - bindingsGbc.gridy = 3; - aliasPanel.add(usernameField, bindingsGbc); - - // Create the password label and text field - JLabel passwordLabel = new JLabel("Password"); - passwordLabel.setFont(passwordLabel.getFont().deriveFont(Font.BOLD)); - passwordLabel.setToolTipText( - "Enter the password for basic or digest authentication."); - passwordLabel.setDisplayedMnemonic('P'); - passwordLabel.setDisplayedMnemonicIndex(0); - passwordLabel.setHorizontalAlignment(JTextField.LEFT); - passwordLabel.setVerticalAlignment(JTextField.CENTER); - passwordLabel.setHorizontalTextPosition(JTextField.RIGHT); - passwordLabel.setVerticalTextPosition(JTextField.CENTER); - passwordLabel.setVisible(false); - passwordLabel.setEnabled(false); - bindingsGbc.gridx = 0; - bindingsGbc.gridy = 4; - aliasPanel.add(passwordLabel, bindingsGbc); - - JTextField passwordField = new JTextField(20); - passwordField.setToolTipText( - "Enter the password for basic or digest authentication."); - passwordField.setVisible(false); - passwordField.setEnabled(false); - bindingsGbc.gridx = 1; - bindingsGbc.gridy = 4; - aliasPanel.add(passwordField, bindingsGbc); - - // Create the bearer key label and text field - JLabel bearerKeyLabel = new JLabel("Bearer Key"); - bearerKeyLabel.setFont(bearerKeyLabel.getFont().deriveFont(Font.BOLD)); - bearerKeyLabel.setToolTipText( - "Enter the bearer key for bearer token authentication."); - bearerKeyLabel.setDisplayedMnemonic('B'); - bearerKeyLabel.setDisplayedMnemonicIndex(0); - bearerKeyLabel.setHorizontalAlignment(JTextField.LEFT); - bearerKeyLabel.setVerticalAlignment(JTextField.CENTER); - bearerKeyLabel.setHorizontalTextPosition(JTextField.RIGHT); - bearerKeyLabel.setVerticalTextPosition(JTextField.CENTER); - bearerKeyLabel.setVisible(false); - bearerKeyLabel.setEnabled(false); - bindingsGbc.gridx = 0; - bindingsGbc.gridy = 5; - aliasPanel.add(bearerKeyLabel, bindingsGbc); - - JTextField bearerKeyField = new JTextField(20); - bearerKeyField.setToolTipText( - "Enter the bearer key for bearer token authentication."); - bearerKeyField.setVisible(false); - bearerKeyField.setEnabled(false); - bindingsGbc.gridx = 1; - bindingsGbc.gridy = 5; - aliasPanel.add(bearerKeyField, bindingsGbc); - - // Create the auth dropdown menu listener - authComboBox.addActionListener(ee -> { - // Update the visibility of the authentication fields based on the selected - String selectedAuth = (String) authComboBox.getSelectedItem(); - if (selectedAuth.equals("Basic") || selectedAuth.equals("Digest")) { - usernameLabel.setVisible(true); - usernameField.setVisible(true); - usernameLabel.setEnabled(true); - usernameField.setEnabled(true); - - passwordLabel.setVisible(true); - passwordField.setVisible(true); - passwordLabel.setEnabled(true); - passwordField.setEnabled(true); - - bearerKeyLabel.setVisible(false); - bearerKeyField.setVisible(false); - bearerKeyLabel.setEnabled(false); - bearerKeyField.setEnabled(false); - } else if (selectedAuth.equals("Bearer")) { - usernameLabel.setVisible(false); - usernameField.setVisible(false); - usernameLabel.setEnabled(false); - usernameField.setEnabled(false); - - passwordLabel.setVisible(false); - passwordField.setVisible(false); - passwordLabel.setEnabled(false); - passwordField.setEnabled(false); - - bearerKeyLabel.setVisible(true); - bearerKeyField.setVisible(true); - bearerKeyLabel.setEnabled(true); - bearerKeyField.setEnabled(true); - } else { - usernameLabel.setVisible(false); - usernameField.setVisible(false); - usernameLabel.setEnabled(false); - usernameField.setEnabled(false); - - passwordLabel.setVisible(false); - passwordField.setVisible(false); - passwordLabel.setEnabled(false); - passwordField.setEnabled(false); - - bearerKeyLabel.setVisible(false); - bearerKeyField.setVisible(false); - bearerKeyLabel.setEnabled(false); - bearerKeyField.setEnabled(false); - } - - }); - - } else if (selectedBindingType.equals("Constant Alias")) { - // Create the alias name label - JLabel aliasNameLabel = new JLabel("Alias Name:"); - aliasGbc.gridx = 0; - aliasGbc.gridy = 0; - aliasPanel.add(aliasNameLabel, aliasGbc); - - // Create the alias name text field - JTextField aliasNameField = new JTextField(20); - aliasNameField.setToolTipText("Enter the alias name."); - aliasGbc.gridx = 1; - aliasGbc.gridy = 0; - aliasPanel.add(aliasNameField, aliasGbc); - - // Create the value label - JLabel valueLabel = new JLabel("Value:"); - aliasGbc.gridx = 0; - aliasGbc.gridy = 1; - aliasPanel.add(valueLabel, aliasGbc); - - // Create the value text field - JTextField valueField = new JTextField(20); - valueField.setToolTipText("Enter the constant value."); - aliasGbc.gridx = 1; - aliasGbc.gridy = 1; - aliasPanel.add(valueField, aliasGbc); - } - - // Repaint the alias aliasPanel to show the updated components - aliasPanel.revalidate(); - aliasPanel.repaint(); - }); - bindingTypeComboBox.setSelectedIndex(0); - - // Add the binding type aliasPanel to the bindings aliasPanel - GridBagConstraints bindingsPanelGbc = new GridBagConstraints(); - bindingsPanelGbc.insets = new Insets(5, 5, 5, 5); - bindingsPanelGbc.anchor = GridBagConstraints.WEST; - bindingsPanelGbc.gridx = 0; - bindingsPanelGbc.gridy = bindingTypeCount; - bindingsPanelGbc.gridwidth = 3; - bindingsPanel.add(bindingTypePanel, bindingsPanelGbc); - - // Repaint the bindings aliasPanel to show the new binding type - bindingsPanel.revalidate(); - bindingsPanel.repaint(); - } - - private void removeBindingType() { - // Get the number of binding types - int bindingTypeCount = bindingsPanel.getComponentCount(); + // private void updateScopes() { + // // Get selected bucket + // String selectedBucket = (String) bucketComboBox.getSelectedItem(); - // Check if there are any binding types to remove - if (bindingTypeCount > 0) { - // Remove the last binding type aliasPanel - bindingsPanel.remove(bindingTypeCount - 1); + // // TODO: Get scopes for selected bucket and update scopeComboBox + // // You can use the Couchbase Java SDK to get the list of scopes for the + // selected + // // bucket + // // For example: + // // List scopes = + // // cluster.bucket(selectedBucket).collections().getAllScopes(); + // // Then you can update the scopeComboBox with the list of scopes - // Repaint the bindings aliasPanel to show the removed binding type - bindingsPanel.revalidate(); - bindingsPanel.repaint(); - } - } - - private void updateScopes() { - // Get selected bucket - String selectedBucket = (String) bucketComboBox.getSelectedItem(); - - // TODO: Get scopes for selected bucket and update scopeComboBox - // You can use the Couchbase Java SDK to get the list of scopes for the selected - // bucket - // For example: - // List scopes = - // cluster.bucket(selectedBucket).collections().getAllScopes(); - // Then you can update the scopeComboBox with the list of scopes - - // Enable scope combo box - scopeComboBox.setEnabled(true); - } + // // Enable scope combo box + // scopeComboBox.setEnabled(true); + // } - public String getSelectedBucket() { - return (String) bucketComboBox.getSelectedItem(); - } + // public String getSelectedBucket() { + // return (String) bucketComboBox.getSelectedItem(); + // } - public String getSelectedScope() { - return (String) scopeComboBox.getSelectedItem(); - } + // public String getSelectedScope() { + // return (String) scopeComboBox.getSelectedItem(); + // } - public String getFunctionName() { - return functionNameField.getText(); - } } diff --git a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java index 258ae7b7..2d3e7749 100644 --- a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java @@ -6,11 +6,6 @@ import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.HashMap; @@ -19,8 +14,6 @@ import javax.swing.BorderFactory; import javax.swing.DefaultListCellRenderer; import javax.swing.JButton; -// import javax.swing.JCheckBox; -import javax.swing.JComboBox; import javax.swing.JFrame; // import javax.swing.JLabel; import javax.swing.JList; @@ -34,32 +27,31 @@ import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import com.couchbase.intellij.eventing.settings.AdvancedSettings; +import com.couchbase.intellij.eventing.settings.BindingSettings; +import com.couchbase.intellij.eventing.settings.GeneralSettings; import com.intellij.ui.JBColor; import com.intellij.ui.JBSplitter; -import com.intellij.ui.components.JBCheckBox; import com.intellij.ui.components.JBLabel; -import com.intellij.ui.components.JBPasswordField; import com.intellij.ui.components.JBScrollPane; -import com.intellij.ui.components.JBTextArea; -import com.intellij.ui.components.JBTextField; -import com.intellij.util.ui.JBUI; public class FunctionDeploymentSettings extends JFrame { private JPanel mainPanel; private JPanel leftPanel; private JPanel rightPanel; private JPanel bottomPanel; - private JPanel bindingsPanel; private JBLabel titleLabel; + private JPanel generalSettingsPanel; + private JPanel advancedSettingsPanel; + private JPanel bindingsPanel; + private JButton applyButton; private JButton cancelButton; private CardLayout cardLayout; private Map changedSettings; - private Integer bindingTypeCount = 0; - public FunctionDeploymentSettings() { // Set up the main frame setTitle("Project Structure"); @@ -127,456 +119,16 @@ public Component getListCellRendererComponent(JList list, Object value, int i rightPanel.setLayout(cardLayout); // Add components to the right panel - JPanel generalSettingsPanel = new JPanel(); - generalSettingsPanel.setLayout(new GridBagLayout()); - generalSettingsPanel.setPreferredSize(new Dimension(600, 800)); - - GridBagConstraints rightPanelConstraints = new GridBagConstraints(); - rightPanelConstraints.gridx = 0; - rightPanelConstraints.gridy = 0; - rightPanelConstraints.anchor = GridBagConstraints.NORTHWEST; - rightPanelConstraints.insets = JBUI.insets(5); - rightPanelConstraints.weightx = 1.0; - rightPanelConstraints.weighty = 1.0; - rightPanelConstraints.fill = GridBagConstraints.HORIZONTAL; - - // Function Scope label - JBLabel functionScopeLabel = new JBLabel("Function scope"); - functionScopeLabel.setFont(functionScopeLabel.getFont().deriveFont(Font.BOLD)); - - JBLabel functionScopeInfoLabel = new JBLabel("bucket.scope"); - functionScopeInfoLabel.setForeground(JBColor.GRAY); - - // Add both labels to a flow layout - JPanel functionScopePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - functionScopePanel.add(functionScopeLabel); - functionScopePanel.add(functionScopeInfoLabel); - rightPanelConstraints.gridx = 0; - rightPanelConstraints.gridy = 0; - generalSettingsPanel.add(functionScopePanel, rightPanelConstraints); - - JComboBox bucketComboBox1 = new JComboBox<>(); - // bucketComboBox1.addActionListener(e -> updateScopes()); - rightPanelConstraints.gridx = 0; - rightPanelConstraints.gridy = 1; - generalSettingsPanel.add(bucketComboBox1, rightPanelConstraints); - - JComboBox scopeComboBox1 = new JComboBox<>(); - scopeComboBox1.setEnabled(false); - rightPanelConstraints.gridx = 1; - rightPanelConstraints.gridy = 1; - generalSettingsPanel.add(scopeComboBox1, rightPanelConstraints); - - // Function Scope error label - - JBLabel helpLabel1 = new JBLabel( - "Please specify a scope to which the function belongs. User should have Eventing Manage Scope Functions permission on this scope"); - helpLabel1.setForeground(JBColor.GRAY); - rightPanelConstraints.gridx = 0; - rightPanelConstraints.gridy = 2; - rightPanelConstraints.gridwidth = 3; - generalSettingsPanel.add(helpLabel1, rightPanelConstraints); - - // Listen to location label - JBLabel listenToLocationLabel = new JBLabel("Listen to location"); - - listenToLocationLabel.setFont(listenToLocationLabel.getFont().deriveFont(Font.BOLD)); - // rightPanelConstraints.gridx = 0; - // rightPanelConstraints.gridy = 3; - // generalSettingsPanel.add(listenToLocationLabel, rightPanelConstraints); - - JBLabel listenToLocationInfoLabel = new JBLabel("bucket.scope.collection"); - listenToLocationInfoLabel.setForeground(JBColor.GRAY); - // rightPanelConstraints.gridx = 1; - // rightPanelConstraints.gridy = 3; - // generalSettingsPanel.add(listenToLocationInfoLabel, rightPanelConstraints); - - // Add both labels to a flow layout - JPanel listenToLocationPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - listenToLocationPanel.add(listenToLocationLabel); - listenToLocationPanel.add(listenToLocationInfoLabel); - rightPanelConstraints.gridx = 0; - rightPanelConstraints.gridy = 3; - generalSettingsPanel.add(listenToLocationPanel, rightPanelConstraints); - - JComboBox bucketComboBox2 = new JComboBox<>(); - // bucketComboBox2.addActionListener(e -> updateScopes()); - rightPanelConstraints.gridx = 0; - rightPanelConstraints.gridy = 4; - rightPanelConstraints.gridwidth = 1; - generalSettingsPanel.add(bucketComboBox2, rightPanelConstraints); - - JComboBox scopeComboBox2 = new JComboBox<>(); - scopeComboBox2.setEnabled(false); - rightPanelConstraints.gridx = 1; - rightPanelConstraints.gridy = 4; - generalSettingsPanel.add(scopeComboBox2, rightPanelConstraints); - - JComboBox collectionComboBox1 = new JComboBox<>(); - collectionComboBox1.setEnabled(false); - rightPanelConstraints.gridx = 2; - rightPanelConstraints.gridy = 4; - generalSettingsPanel.add(collectionComboBox1, rightPanelConstraints); - - // Listen to location error label - JBLabel helpLabel2 = new JBLabel( - "Please specify a source location for your function. User should have DCP Data Read permission on this keyspace"); - helpLabel2.setForeground(JBColor.GRAY); - rightPanelConstraints.gridx = 0; - rightPanelConstraints.gridy = 5; - rightPanelConstraints.gridwidth = 3; - - generalSettingsPanel.add(helpLabel2, rightPanelConstraints); - - // Eventing Storage label - JBLabel eventingStorageLabel = new JBLabel("Eventing Storage"); - eventingStorageLabel.setFont(eventingStorageLabel.getFont().deriveFont(Font.BOLD)); - // rightPanelConstraints.gridx = 0; - // rightPanelConstraints.gridy = 6; - // generalSettingsPanel.add(eventingStorageLabel, rightPanelConstraints); - - JBLabel eventingStorageInfoLabel = new JBLabel("bucket.scope.collection"); - eventingStorageInfoLabel.setForeground(JBColor.GRAY); - // rightPanelConstraints.gridx = 1; - // rightPanelConstraints.gridy = 6; - // rightPanelConstraints.gridwidth = 2; - // generalSettingsPanel.add(eventingStorageInfoLabel, rightPanelConstraints); - - // Add both labels to a flow layout - JPanel eventingStoragePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - eventingStoragePanel.add(eventingStorageLabel); - eventingStoragePanel.add(eventingStorageInfoLabel); - rightPanelConstraints.gridx = 0; - rightPanelConstraints.gridy = 6; - generalSettingsPanel.add(eventingStoragePanel, rightPanelConstraints); - - JComboBox bucketComboBox3 = new JComboBox<>(); - // bucketComboBox3.addActionListener(e -> updateScopes()); - rightPanelConstraints.gridx = 0; - rightPanelConstraints.gridy = 7; - rightPanelConstraints.gridwidth = 1; - generalSettingsPanel.add(bucketComboBox3, rightPanelConstraints); - - JComboBox scopeComboBox3 = new JComboBox<>(); - scopeComboBox3.setEnabled(false); - rightPanelConstraints.gridx = 1; - rightPanelConstraints.gridy = 7; - generalSettingsPanel.add(scopeComboBox3, rightPanelConstraints); - - JComboBox collectionComboBox2 = new JComboBox<>(); - collectionComboBox2.setEnabled(false); - rightPanelConstraints.gridx = 2; - rightPanelConstraints.gridy = 7; - - generalSettingsPanel.add(collectionComboBox2, rightPanelConstraints); - - // Eventing Storage help label - JBLabel helpLabel3 = new JBLabel( - "Please specify a location to store Eventing data. User should have read/write permission on this keyspace"); - helpLabel3.setForeground(JBColor.GRAY); - rightPanelConstraints.gridx = 0; - rightPanelConstraints.gridy = 8; - rightPanelConstraints.gridwidth = 3; - generalSettingsPanel.add(helpLabel3, rightPanelConstraints); - - // Function Name label and text field - JBLabel functionNameLabel = new JBLabel("Function Name"); - functionNameLabel.setFont(functionNameLabel.getFont().deriveFont(Font.BOLD)); - rightPanelConstraints.gridx = 0; - rightPanelConstraints.gridy = 9; - generalSettingsPanel.add(functionNameLabel, rightPanelConstraints); - - JBTextField functionNameField = new JBTextField(20); - functionNameField.setToolTipText("Enter the name of the function."); - rightPanelConstraints.gridx = 0; - rightPanelConstraints.gridy = 10; - generalSettingsPanel.add(functionNameField, rightPanelConstraints); - - // Deployment Feed Boundary label and combo box - JBLabel deploymentFeedBoundaryLabel = new JBLabel("Deployment Feed Boundary"); - - deploymentFeedBoundaryLabel.setFont(deploymentFeedBoundaryLabel.getFont().deriveFont(Font.BOLD)); - deploymentFeedBoundaryLabel.setToolTipText( - "The preferred Deployment time Feed Boundary for the function."); - rightPanelConstraints.gridx = 0; - rightPanelConstraints.gridy = 11; - generalSettingsPanel.add(deploymentFeedBoundaryLabel, rightPanelConstraints); - - JComboBox deploymentFeedBoundaryComboBox = new JComboBox<>(); - deploymentFeedBoundaryComboBox.addItem("Everything"); - deploymentFeedBoundaryComboBox.addItem("From now"); - deploymentFeedBoundaryComboBox.setToolTipText( - "The preferred Deployment time Feed Boundary for the function."); - - rightPanelConstraints.gridx = 0; - rightPanelConstraints.gridy = 12; - rightPanelConstraints.gridwidth = 3; - generalSettingsPanel.add(deploymentFeedBoundaryComboBox, rightPanelConstraints); - - JBLabel warningLabel = new JBLabel(""); - warningLabel.setForeground(JBColor.ORANGE); - rightPanelConstraints.gridx = 0; - rightPanelConstraints.gridy = 13; - generalSettingsPanel.add(warningLabel, rightPanelConstraints); - - deploymentFeedBoundaryComboBox.addActionListener(e -> { - if (deploymentFeedBoundaryComboBox.getSelectedItem().equals("From now")) { - warningLabel.setText( - "Warning: Deploying with 'From now' will ignore all past mutations."); - } else { - warningLabel.setText(""); - } - }); - - // Description label and text area - JBLabel descriptionLabel = new JBLabel("Description"); - - descriptionLabel.setFont(descriptionLabel.getFont().deriveFont(Font.BOLD)); - descriptionLabel.setToolTipText("Enter a description for the function (optional)."); - descriptionLabel.setDisplayedMnemonic('D'); - descriptionLabel.setDisplayedMnemonicIndex(0); - descriptionLabel.setHorizontalAlignment(JBTextField.LEFT); - rightPanelConstraints.gridx = 0; - rightPanelConstraints.gridy = 14; - generalSettingsPanel.add(descriptionLabel, rightPanelConstraints); - - JBTextArea descriptionTextArea = new JBTextArea(5, 20); - descriptionTextArea.setLineWrap(true); - descriptionTextArea.setWrapStyleWord(true); - descriptionTextArea.setToolTipText("Enter a description for the function (optional)."); - descriptionLabel.setLabelFor(descriptionTextArea); - JBScrollPane descriptionScrollPane = new JBScrollPane(descriptionTextArea); - rightPanelConstraints.gridx = 0; - rightPanelConstraints.gridy = 15; - rightPanelConstraints.fill = GridBagConstraints.BOTH; - generalSettingsPanel.add(descriptionScrollPane, rightPanelConstraints); + GeneralSettings generalSettings = new GeneralSettings(); + generalSettingsPanel = generalSettings.getPanel(); // Advanced Settings panel - JPanel advancedSettingsPanel = new JPanel(); - advancedSettingsPanel.setLayout(new GridBagLayout()); - GridBagConstraints advancedSettingsConstraints = new GridBagConstraints(); - advancedSettingsConstraints.gridx = 0; - advancedSettingsConstraints.gridy = 0; - - advancedSettingsConstraints.anchor = GridBagConstraints.NORTHWEST; - advancedSettingsConstraints.insets = new Insets(5, 5, 5, 5); - advancedSettingsConstraints.fill = GridBagConstraints.HORIZONTAL; - - // Add components to the Advanced Settings panel - JBLabel systemLogLevelLabel = new JBLabel("System Log Level"); - systemLogLevelLabel.setFont(systemLogLevelLabel.getFont().deriveFont(Font.BOLD)); - // advancedSettingsConstraints.gridx = 0; - // advancedSettingsConstraints.gridy = 0; - // advancedSettingsPanel.add(systemLogLevelLabel, advancedSettingsConstraints); - - JBLabel systemLogLevelInfoLabel = new JBLabel("Granularity of system events being captured in the log"); - systemLogLevelInfoLabel.setForeground(JBColor.GRAY); - // advancedSettingsConstraints.gridx = 1; - // advancedSettingsConstraints.gridy = 0; - // advancedSettingsPanel.add(systemLogLevelInfoLabel, - // advancedSettingsConstraints); - - // Add both the labels to a panel - JPanel systemLogLevelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - systemLogLevelPanel.add(systemLogLevelLabel); - systemLogLevelPanel.add(systemLogLevelInfoLabel); - advancedSettingsConstraints.gridx = 0; - advancedSettingsConstraints.gridy = 0; - advancedSettingsPanel.add(systemLogLevelPanel, advancedSettingsConstraints); - - JComboBox systemLogLevelComboBox = new JComboBox<>(); - systemLogLevelComboBox.addItem("Info"); - systemLogLevelComboBox.addItem("Error"); - systemLogLevelComboBox.addItem("Warning"); - systemLogLevelComboBox.addItem("Debug"); - systemLogLevelComboBox.addItem("Trace"); - advancedSettingsConstraints.gridx = 0; - advancedSettingsConstraints.gridy = 1; - advancedSettingsPanel.add(systemLogLevelComboBox, advancedSettingsConstraints); - - JBLabel applicationLogFileLabel = new JBLabel( - "Application log file for this Function is at:"); - - advancedSettingsConstraints.gridx = 0; - advancedSettingsConstraints.gridy = 2; - advancedSettingsPanel.add(applicationLogFileLabel, advancedSettingsConstraints); - - JBLabel n1qlConsistencyLabel = new JBLabel("N1QL Consistency"); - n1qlConsistencyLabel.setFont(n1qlConsistencyLabel.getFont().deriveFont(Font.BOLD)); - // advancedSettingsConstraints.gridx = 0; - // advancedSettingsConstraints.gridy = 3; - // advancedSettingsPanel.add(n1qlConsistencyLabel, advancedSettingsConstraints); - - JBLabel n1qlConsistencyInfoLabel = new JBLabel("Consistency level of N1QL statements in the function"); - n1qlConsistencyInfoLabel.setForeground(JBColor.GRAY); - // advancedSettingsConstraints.gridx = 1; - // advancedSettingsConstraints.gridy = 3; - // advancedSettingsPanel.add(n1qlConsistencyInfoLabel, - // advancedSettingsConstraints); - - // Add both the labels to a panel - JPanel n1qlConsistencyPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - n1qlConsistencyPanel.add(n1qlConsistencyLabel); - n1qlConsistencyPanel.add(n1qlConsistencyInfoLabel); - advancedSettingsConstraints.gridx = 0; - advancedSettingsConstraints.gridy = 3; - advancedSettingsPanel.add(n1qlConsistencyPanel, advancedSettingsConstraints); - - JComboBox n1qlConsistencyComboBox = new JComboBox<>(); - n1qlConsistencyComboBox.addItem("None"); - n1qlConsistencyComboBox.addItem("Request"); - advancedSettingsConstraints.gridx = 0; - advancedSettingsConstraints.gridy = 4; - - advancedSettingsPanel.add(n1qlConsistencyComboBox, advancedSettingsConstraints); - - JBLabel workersLabel = new JBLabel("Workers"); - workersLabel.setFont(workersLabel.getFont().deriveFont(Font.BOLD)); - // advancedSettingsConstraints.gridx = 0; - // advancedSettingsConstraints.gridy = 5; - // advancedSettingsPanel.add(workersLabel, advancedSettingsConstraints); - - JBLabel workersInfoLabel = new JBLabel( - "Number of workers per node to process the events. If no value is specified, a default value of 1 worker is used."); - workersInfoLabel.setForeground(JBColor.GRAY); - // advancedSettingsConstraints.gridx = 1; - // advancedSettingsConstraints.gridy = 5; - // advancedSettingsPanel.add(workersInfoLabel, advancedSettingsConstraints); - - // Add both the labels to a panel - JPanel workersPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - workersPanel.add(workersLabel); - workersPanel.add(workersInfoLabel); - advancedSettingsConstraints.gridx = 0; - advancedSettingsConstraints.gridy = 5; - advancedSettingsPanel.add(workersPanel, advancedSettingsConstraints); - - JBTextField workersField = new JBTextField(20); - workersField.setToolTipText("Enter the number of workers per node to process the events."); - // advancedSettingsConstraints.gridx = 0; - // advancedSettingsConstraints.gridy = 6; - // advancedSettingsPanel.add(workersField, advancedSettingsConstraints); - - JBLabel languageCompatibilityLabel = new JBLabel("Language compatibility"); - - languageCompatibilityLabel.setFont(languageCompatibilityLabel.getFont().deriveFont(Font.BOLD)); - // advancedSettingsConstraints.gridx = 0; - // advancedSettingsConstraints.gridy = 7; - // advancedSettingsPanel.add(languageCompatibilityLabel, - // advancedSettingsConstraints); - - JBLabel languageCompatibilityInfoLabel = new JBLabel("Language compatibility of the function"); - languageCompatibilityInfoLabel.setForeground(JBColor.GRAY); - // advancedSettingsConstraints.gridx = 1; - // advancedSettingsConstraints.gridy = 7; - // advancedSettingsPanel.add(languageCompatibilityInfoLabel, - // advancedSettingsConstraints); - - // Add both the labels to a panel - JPanel languageCompatibilityPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - languageCompatibilityPanel.add(languageCompatibilityLabel); - languageCompatibilityPanel.add(languageCompatibilityInfoLabel); - advancedSettingsConstraints.gridx = 0; - advancedSettingsConstraints.gridy = 7; - advancedSettingsPanel.add(languageCompatibilityPanel, advancedSettingsConstraints); - - JComboBox languageCompatibilityComboBox = new JComboBox<>(); - languageCompatibilityComboBox.addItem("6.0.0"); - languageCompatibilityComboBox.addItem("6.5.0"); - languageCompatibilityComboBox.addItem("6.6.2"); - advancedSettingsConstraints.gridx = 0; - advancedSettingsConstraints.gridy = 8; - advancedSettingsPanel.add(languageCompatibilityComboBox, advancedSettingsConstraints); - - JBLabel scriptTimeoutLabel = new JBLabel("Script Timeout"); - - scriptTimeoutLabel.setFont(scriptTimeoutLabel.getFont().deriveFont(Font.BOLD)); - // advancedSettingsConstraints.gridx = 0; - // advancedSettingsConstraints.gridy = 9; - // advancedSettingsPanel.add(scriptTimeoutLabel, advancedSettingsConstraints); - - JBLabel scriptTimeoutInfoLabel = new JBLabel( - "Time after which the Function's execution will be timed out"); - scriptTimeoutInfoLabel.setForeground(JBColor.GRAY); - // advancedSettingsConstraints.gridx = 1; - // advancedSettingsConstraints.gridy = 9; - // advancedSettingsPanel.add(scriptTimeoutInfoLabel, - // advancedSettingsConstraints); - - // Add both the labels to a panel - JPanel scriptTimeoutPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - scriptTimeoutPanel.add(scriptTimeoutLabel); - scriptTimeoutPanel.add(scriptTimeoutInfoLabel); - advancedSettingsConstraints.gridx = 0; - advancedSettingsConstraints.gridy = 9; - advancedSettingsPanel.add(scriptTimeoutPanel, advancedSettingsConstraints); - - JBTextField scriptTimeoutField = new JBTextField(20); - scriptTimeoutField.setText("60"); - scriptTimeoutField.setToolTipText( - "Enter the time after which the Function's execution will be timed out."); - advancedSettingsConstraints.gridx = 0; - advancedSettingsConstraints.gridy = 10; - advancedSettingsPanel.add(scriptTimeoutField, advancedSettingsConstraints); - - JBLabel timerContextMaxSizeLabel = new JBLabel("Timer Context Max Size"); - - timerContextMaxSizeLabel.setFont(timerContextMaxSizeLabel.getFont().deriveFont(Font.BOLD)); - // advancedSettingsConstraints.gridx = 0; - // advancedSettingsConstraints.gridy = 11; - // advancedSettingsPanel.add(timerContextMaxSizeLabel, - // advancedSettingsConstraints); - - JBLabel timerContextMaxSizeInfoLabel = new JBLabel( - "Maximum allowed value of the Timer Context Size in Bytes. Takes effect immediately."); - timerContextMaxSizeInfoLabel.setForeground(JBColor.GRAY); - // advancedSettingsConstraints.gridx = 1; - // advancedSettingsConstraints.gridy = 11; - // advancedSettingsPanel.add(timerContextMaxSizeInfoLabel, - // advancedSettingsConstraints); - - // Add both the labels to a panel - JPanel timerContextMaxSizePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - timerContextMaxSizePanel.add(timerContextMaxSizeLabel); - timerContextMaxSizePanel.add(timerContextMaxSizeInfoLabel); - advancedSettingsConstraints.gridx = 0; - advancedSettingsConstraints.gridy = 11; - advancedSettingsPanel.add(timerContextMaxSizePanel, advancedSettingsConstraints); - - JBTextField timerContextMaxSizeField = new JBTextField(20); - timerContextMaxSizeField.setText("1024"); - timerContextMaxSizeField.setToolTipText( - "Enter the maximum allowed value of the Timer Context Size in Bytes."); - advancedSettingsConstraints.gridx = 0; - advancedSettingsConstraints.gridy = 12; - advancedSettingsPanel.add(timerContextMaxSizeField, advancedSettingsConstraints); + AdvancedSettings advancedSettings = new AdvancedSettings(); + advancedSettingsPanel = advancedSettings.getPanel(); // Binding Type panel - bindingsPanel = new JPanel(new GridBagLayout()); - GridBagConstraints bindingsPanelGbc = new GridBagConstraints(); - bindingsPanelGbc.insets = new Insets(5, 5, 5, 5); - bindingsPanelGbc.anchor = GridBagConstraints.WEST; - - // Binding Type label - JBLabel bindingTypeLabel = new JBLabel("Binding Type"); - bindingTypeLabel.setFont(bindingTypeLabel.getFont().deriveFont(Font.BOLD)); - bindingsPanelGbc.gridx = 0; - bindingsPanelGbc.gridy = 0; - bindingsPanel.add(bindingTypeLabel, bindingsPanelGbc); - - // Plus button - JButton plusButton = new JButton("+"); - plusButton.addActionListener(e -> addBindingType()); - bindingsPanelGbc.gridx = 1; - bindingsPanelGbc.gridy = 0; - bindingsPanel.add(plusButton, bindingsPanelGbc); - - // Minus button - JButton minusButton = new JButton("-"); - minusButton.addActionListener(e -> removeBindingType()); - bindingsPanelGbc.gridx = 2; - bindingsPanelGbc.gridy = 0; - bindingsPanel.add(minusButton, bindingsPanelGbc); + BindingSettings bindingSettings = new BindingSettings(); + bindingsPanel = bindingSettings.getPanel(); // Add the panels to the right panel rightPanel.add(generalSettingsPanel, "General Settings"); @@ -654,386 +206,13 @@ public void changedUpdate(DocumentEvent e) { changedSettings.put("General Settings", true); } }; - functionNameField.getDocument().addDocumentListener(documentListener); - descriptionTextArea.getDocument().addDocumentListener(documentListener); + // functionNameField.getDocument().addDocumentListener(documentListener); + // descriptionTextArea.getDocument().addDocumentListener(documentListener); - ActionListener actionListener = e -> changedSettings.put("General Settings", true); - deploymentFeedBoundaryComboBox.addActionListener(actionListener); + // ActionListener actionListener = e -> changedSettings.put("General Settings", + // true); + // deploymentFeedBoundaryComboBox.addActionListener(actionListener); } - private void addBindingType() { - // Increment the binding type count - bindingTypeCount++; - - // Create a new aliasPanel to hold the binding type components - JPanel bindingTypePanel = new JPanel(new GridBagLayout()); - GridBagConstraints bindingsGbc = new GridBagConstraints(); - bindingsGbc.insets = new Insets(5, 5, 5, 5); - bindingsGbc.anchor = GridBagConstraints.WEST; - bindingsGbc.fill = GridBagConstraints.HORIZONTAL; - - // Create the binding type dropdown menu - CustomComboBox bindingTypeComboBox = new CustomComboBox(); - bindingTypeComboBox.setToolTipText("Type of binding for this function."); - bindingTypeComboBox.addItem("Choose Binding Type"); - bindingTypeComboBox.addItem("Bucket Alias"); - bindingTypeComboBox.addItem("URL Alias"); - bindingTypeComboBox.addItem("Constant Alias"); - - bindingsGbc.gridx = 0; - bindingsGbc.gridy = 0; - bindingTypePanel.add(bindingTypeComboBox, bindingsGbc); - - // Create a aliasPanel to hold the alias-specific components - JPanel aliasPanel = new JPanel(new GridBagLayout()); - GridBagConstraints aliasGbc = new GridBagConstraints(); - aliasGbc.insets = new Insets(5, 5, 5, 5); - aliasGbc.anchor = GridBagConstraints.WEST; - aliasGbc.fill = GridBagConstraints.HORIZONTAL; - bindingsGbc.gridx = 1; - bindingsGbc.gridy = 0; - bindingsGbc.gridwidth = 2; - bindingTypePanel.add(aliasPanel, bindingsGbc); - - // Update the alias aliasPanel when the selected binding type changes - bindingTypeComboBox.addItemListener(e -> { - // Remove all components from the alias aliasPanel - aliasPanel.removeAll(); - - // Get the selected binding type - String selectedBindingType = (String) bindingTypeComboBox.getSelectedItem(); - - if (selectedBindingType.equals("Bucket Alias")) { - // Create the alias name text field - JBTextField aliasNameField = new JBTextField(20); - aliasNameField.setToolTipText("Enter the alias name."); - aliasNameField.getEmptyText().setText("Enter the alias name."); - aliasGbc.gridx = 0; - aliasGbc.gridy = 0; - aliasGbc.gridwidth = 4; - aliasPanel.add(aliasNameField, aliasGbc); - - // Create the bucket label - JBLabel bucketLabel = new JBLabel("Bucket"); - bucketLabel.setFont(bucketLabel.getFont().deriveFont(Font.BOLD)); - // aliasGbc.gridx = 0; - // aliasGbc.gridy = 1; - // aliasGbc.gridwidth = 1; - // aliasPanel.add(bucketLabel, aliasGbc); - - // Create the bucket info label - JBLabel bucketInfoLabel = new JBLabel("bucket.scope.collection"); - bucketInfoLabel.setForeground(Color.GRAY); - // aliasGbc.gridx = 1; - // aliasGbc.gridy = 1; - // aliasPanel.add(bucketInfoLabel, aliasGbc); - - // Add both labels to a flow layout panel - JPanel bucketPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - bucketPanel.add(bucketLabel); - bucketPanel.add(bucketInfoLabel); - aliasGbc.gridx = 0; - aliasGbc.gridy = 1; - aliasGbc.gridwidth = 3; - aliasPanel.add(bucketPanel, aliasGbc); - - // Create the access label - JBLabel accessLabel = new JBLabel("Access"); - accessLabel.setFont(accessLabel.getFont().deriveFont(Font.BOLD)); - aliasGbc.gridx = 3; - aliasGbc.gridy = 1; - aliasGbc.gridwidth = 1; - aliasPanel.add(accessLabel, aliasGbc); - - // Create the bucket dropdown menu - JComboBox bucketComboBox = new JComboBox<>(); - // TODO: Populate the bucketComboBox with available buckets - aliasGbc.gridx = 0; - aliasGbc.gridy = 2; - aliasPanel.add(bucketComboBox, aliasGbc); - - // Create the scope dropdown menu - JComboBox scopeComboBox = new JComboBox<>(); - scopeComboBox.setEnabled(false); - // TODO: Update the scopeComboBox when the selected bucket changes - aliasGbc.gridx = 1; - aliasGbc.gridy = 2; - aliasPanel.add(scopeComboBox, aliasGbc); - - // Create the collection dropdown menu - JComboBox collectionComboBox = new JComboBox<>(); - collectionComboBox.setEnabled(false); - // TODO: Update the collectionComboBox when the selected scope changes - aliasGbc.gridx = 2; - aliasGbc.gridy = 2; - aliasPanel.add(collectionComboBox, aliasGbc); - - // Create access dropdown menu - JComboBox accessComboBox = new JComboBox<>(); - accessComboBox.addItem("Read Only"); - accessComboBox.addItem("Read and Write"); - accessComboBox.setToolTipText("Select access level for this bucket."); - accessComboBox.setEnabled(true); - accessComboBox.setSelectedIndex(0); - aliasGbc.gridx = 3; - aliasGbc.gridy = 2; - aliasPanel.add(accessComboBox, aliasGbc); - - } else if (selectedBindingType.equals("URL Alias")) { - // Create the alias name text field - JBTextField aliasNameField = new JBTextField(20); - aliasNameField.setToolTipText("Enter the alias name."); - aliasNameField.getEmptyText().setText("Enter the alias name."); - aliasGbc.gridx = 0; - aliasGbc.gridy = 0; - aliasPanel.add(aliasNameField, aliasGbc); - - // Create the URL text field - JBTextField urlField = new JBTextField(20); - urlField.setToolTipText("Enter the URL."); - urlField.getEmptyText().setText("Enter the URL."); - aliasGbc.gridx = 1; - aliasGbc.gridy = 0; - aliasPanel.add(urlField, aliasGbc); - - // Create the allow cookies checkbox - JBCheckBox allowCookiesCheckBox = new JBCheckBox("Allow cookies"); - allowCookiesCheckBox.setToolTipText("Allow cookies for this URL."); - aliasGbc.gridx = 0; - aliasGbc.gridy = 1; - aliasPanel.add(allowCookiesCheckBox, aliasGbc); - - // Create the validate SSL certificate checkbox - JBCheckBox validateSslCertificateCheckBox = new JBCheckBox("Validate SSL certificate"); - validateSslCertificateCheckBox.setToolTipText("Validate SSL certificate for this URL."); - aliasGbc.gridx = 1; - aliasGbc.gridy = 1; - aliasPanel.add(validateSslCertificateCheckBox, aliasGbc); - - // Create the authentication label - JBLabel authenticationLabel = new JBLabel("Authentication"); - authenticationLabel.setFont(authenticationLabel.getFont().deriveFont(Font.BOLD)); - authenticationLabel.setToolTipText("Select authentication method for this URL."); - authenticationLabel.setDisplayedMnemonic('A'); - authenticationLabel.setDisplayedMnemonicIndex(0); - authenticationLabel.setHorizontalAlignment(JBTextField.LEFT); - authenticationLabel.setVerticalAlignment(JBTextField.CENTER); - authenticationLabel.setHorizontalTextPosition(JBTextField.RIGHT); - authenticationLabel.setVerticalTextPosition(JBTextField.CENTER); - aliasGbc.gridx = 0; - aliasGbc.gridy = 2; - aliasPanel.add(authenticationLabel, aliasGbc); - - // Create the auth dropdown menu - CustomComboBox authComboBox = new CustomComboBox(); - authComboBox.addItem("No Auth"); - authComboBox.addItem("Basic"); - authComboBox.addItem("Bearer"); - authComboBox.addItem("Digest"); - authComboBox.setToolTipText("Select authentication method for this URL."); - authComboBox.setEnabled(true); - - authComboBox.setSelectedIndex(0); - aliasGbc.gridx = 1; - aliasGbc.gridy = 2; - aliasPanel.add(authComboBox, aliasGbc); - - // Create the username label and text field - JBLabel usernameLabel = new JBLabel("Username"); - usernameLabel.setFont(usernameLabel.getFont().deriveFont(Font.BOLD)); - usernameLabel.setToolTipText("Enter the username for basic or digest authentication."); - usernameLabel.setDisplayedMnemonic('U'); - usernameLabel.setDisplayedMnemonicIndex(0); - usernameLabel.setHorizontalAlignment(JBTextField.LEFT); - usernameLabel.setVerticalAlignment(JBTextField.CENTER); - usernameLabel.setHorizontalTextPosition(JBTextField.RIGHT); - usernameLabel.setVerticalTextPosition(JBTextField.CENTER); - usernameLabel.setVisible(false); - usernameLabel.setEnabled(false); - bindingsGbc.gridx = 0; - bindingsGbc.gridy = 3; - aliasPanel.add(usernameLabel, bindingsGbc); - - JBTextField usernameField = new JBTextField(20); - usernameField.setToolTipText( - "Enter the username for basic or digest authentication."); - usernameField.getEmptyText().setText("Enter the username."); - usernameField.setVisible(false); - usernameField.setEnabled(false); - bindingsGbc.gridx = 1; - bindingsGbc.gridy = 3; - aliasPanel.add(usernameField, bindingsGbc); - - // Create the password label and text field - JBLabel passwordLabel = new JBLabel("Password"); - passwordLabel.setFont(passwordLabel.getFont().deriveFont(Font.BOLD)); - passwordLabel.setToolTipText( - "Enter the password for basic or digest authentication."); - passwordLabel.setDisplayedMnemonic('P'); - passwordLabel.setDisplayedMnemonicIndex(0); - passwordLabel.setHorizontalAlignment(JBTextField.LEFT); - passwordLabel.setVerticalAlignment(JBTextField.CENTER); - passwordLabel.setHorizontalTextPosition(JBTextField.RIGHT); - passwordLabel.setVerticalTextPosition(JBTextField.CENTER); - passwordLabel.setVisible(false); - passwordLabel.setEnabled(false); - bindingsGbc.gridx = 0; - bindingsGbc.gridy = 4; - aliasPanel.add(passwordLabel, bindingsGbc); - - JBPasswordField passwordField = new JBPasswordField(); - passwordField.setToolTipText( - "Enter the password for basic or digest authentication."); - passwordField.getEmptyText().setText("Enter the password."); - passwordField.setVisible(false); - passwordField.setEnabled(false); - bindingsGbc.gridx = 1; - bindingsGbc.gridy = 4; - aliasPanel.add(passwordField, bindingsGbc); - - // Create the bearer key label and text field - JBLabel bearerKeyLabel = new JBLabel("Bearer Key"); - bearerKeyLabel.setFont(bearerKeyLabel.getFont().deriveFont(Font.BOLD)); - bearerKeyLabel.setToolTipText( - "Enter the bearer key for bearer token authentication."); - bearerKeyLabel.setDisplayedMnemonic('B'); - bearerKeyLabel.setDisplayedMnemonicIndex(0); - bearerKeyLabel.setHorizontalAlignment(JBTextField.LEFT); - bearerKeyLabel.setVerticalAlignment(JBTextField.CENTER); - bearerKeyLabel.setHorizontalTextPosition(JBTextField.RIGHT); - bearerKeyLabel.setVerticalTextPosition(JBTextField.CENTER); - bearerKeyLabel.setVisible(false); - bearerKeyLabel.setEnabled(false); - bindingsGbc.gridx = 0; - bindingsGbc.gridy = 5; - aliasPanel.add(bearerKeyLabel, bindingsGbc); - - JBTextField bearerKeyField = new JBTextField(20); - bearerKeyField.setToolTipText( - "Enter the bearer key for bearer token authentication."); - bearerKeyField.getEmptyText().setText("Enter the bearer key."); - bearerKeyField.setVisible(false); - bearerKeyField.setEnabled(false); - bindingsGbc.gridx = 1; - bindingsGbc.gridy = 5; - aliasPanel.add(bearerKeyField, bindingsGbc); - - // Create the auth dropdown menu listener - authComboBox.addActionListener(ee -> { - // Update the visibility of the authentication fields based on the selected - String selectedAuth = (String) authComboBox.getSelectedItem(); - if (selectedAuth.equals("Basic") || selectedAuth.equals("Digest")) { - usernameLabel.setVisible(true); - usernameField.setVisible(true); - usernameLabel.setEnabled(true); - usernameField.setEnabled(true); - - passwordLabel.setVisible(true); - passwordField.setVisible(true); - passwordLabel.setEnabled(true); - passwordField.setEnabled(true); - - bearerKeyLabel.setVisible(false); - bearerKeyField.setVisible(false); - bearerKeyLabel.setEnabled(false); - bearerKeyField.setEnabled(false); - } else if (selectedAuth.equals("Bearer")) { - usernameLabel.setVisible(false); - usernameField.setVisible(false); - usernameLabel.setEnabled(false); - usernameField.setEnabled(false); - - passwordLabel.setVisible(false); - passwordField.setVisible(false); - passwordLabel.setEnabled(false); - passwordField.setEnabled(false); - - bearerKeyLabel.setVisible(true); - bearerKeyField.setVisible(true); - bearerKeyLabel.setEnabled(true); - bearerKeyField.setEnabled(true); - } else { - usernameLabel.setVisible(false); - usernameField.setVisible(false); - usernameLabel.setEnabled(false); - usernameField.setEnabled(false); - - passwordLabel.setVisible(false); - passwordField.setVisible(false); - passwordLabel.setEnabled(false); - passwordField.setEnabled(false); - - bearerKeyLabel.setVisible(false); - bearerKeyField.setVisible(false); - bearerKeyLabel.setEnabled(false); - bearerKeyField.setEnabled(false); - } - - }); - - } else if (selectedBindingType.equals("Constant Alias")) { - // Create the alias name label - JBLabel aliasNameLabel = new JBLabel("Alias Name:"); - aliasGbc.gridx = 0; - aliasGbc.gridy = 0; - aliasPanel.add(aliasNameLabel, aliasGbc); - - // Create the alias name text field - JBTextField aliasNameField = new JBTextField(20); - aliasNameField.setToolTipText("Enter the alias name."); - aliasNameField.getEmptyText().setText("Enter the alias name."); - aliasGbc.gridx = 1; - aliasGbc.gridy = 0; - aliasPanel.add(aliasNameField, aliasGbc); - - // Create the value label - JBLabel valueLabel = new JBLabel("Value:"); - aliasGbc.gridx = 0; - aliasGbc.gridy = 1; - aliasPanel.add(valueLabel, aliasGbc); - - // Create the value text field - JBTextField valueField = new JBTextField(20); - valueField.setToolTipText("Enter the constant value."); - valueField.getEmptyText().setText("Enter the constant value."); - aliasGbc.gridx = 1; - aliasGbc.gridy = 1; - aliasPanel.add(valueField, aliasGbc); - } - - // Repaint the alias aliasPanel to show the updated components - aliasPanel.revalidate(); - aliasPanel.repaint(); - }); - bindingTypeComboBox.setSelectedIndex(0); - - // Add the binding type aliasPanel to the bindings aliasPanel - GridBagConstraints bindingsPanelGbc = new GridBagConstraints(); - bindingsPanelGbc.insets = new Insets(5, 5, 5, 5); - bindingsPanelGbc.anchor = GridBagConstraints.WEST; - bindingsPanelGbc.gridx = 0; - bindingsPanelGbc.gridy = bindingTypeCount; - bindingsPanelGbc.gridwidth = 3; - bindingsPanel.add(bindingTypePanel, bindingsPanelGbc); - - // Repaint the bindings aliasPanel to show the new binding type - bindingsPanel.revalidate(); - bindingsPanel.repaint(); - } - - private void removeBindingType() { - // Get the number of binding types - int bindingTypeCount = bindingsPanel.getComponentCount(); - - // Check if there are any binding types to remove - if (bindingTypeCount > 0) { - // Remove the last binding type aliasPanel - bindingsPanel.remove(bindingTypeCount - 1); - - // Repaint the bindings aliasPanel to show the removed binding type - bindingsPanel.revalidate(); - bindingsPanel.repaint(); - } - } } \ No newline at end of file diff --git a/src/main/java/com/couchbase/intellij/eventing/CustomComboBox.java b/src/main/java/com/couchbase/intellij/eventing/components/CustomComboBox.java similarity index 75% rename from src/main/java/com/couchbase/intellij/eventing/CustomComboBox.java rename to src/main/java/com/couchbase/intellij/eventing/components/CustomComboBox.java index de778b0e..d203c571 100644 --- a/src/main/java/com/couchbase/intellij/eventing/CustomComboBox.java +++ b/src/main/java/com/couchbase/intellij/eventing/components/CustomComboBox.java @@ -1,15 +1,15 @@ -package com.couchbase.intellij.eventing; +package com.couchbase.intellij.eventing.components; import javax.swing.*; import java.awt.*; -class CustomComboBox extends JComboBox { +public class CustomComboBox extends JComboBox { public CustomComboBox() { setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, - boolean isSelected, - boolean cellHasFocus) { + boolean isSelected, + boolean cellHasFocus) { JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); diff --git a/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java b/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java new file mode 100644 index 00000000..bb9fe554 --- /dev/null +++ b/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java @@ -0,0 +1,257 @@ +package com.couchbase.intellij.eventing.settings; + +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; + +import javax.swing.JComboBox; +import javax.swing.JPanel; + +import com.intellij.ui.JBColor; +import com.intellij.ui.components.JBLabel; +import com.intellij.ui.components.JBTextField; + +public class AdvancedSettings { + + private JPanel advancedSettingsPanel; + private JPanel systemLogLevelPanel; + private JPanel n1qlConsistencyPanel; + private JPanel workersPanel; + private JPanel languageCompatibilityPanel; + private JPanel scriptTimeoutPanel; + private JPanel timerContextMaxSizePanel; + + private JBLabel systemLogLevelLabel; + private JBLabel systemLogLevelInfoLabel; + private JBLabel applicationLogFileLabel; + private JBLabel n1qlConsistencyLabel; + private JBLabel n1qlConsistencyInfoLabel; + private JBLabel workersLabel; + private JBLabel workersInfoLabel; + private JBLabel languageCompatibilityLabel; + private JBLabel languageCompatibilityInfoLabel; + private JBLabel scriptTimeoutLabel; + private JBLabel scriptTimeoutInfoLabel; + private JBLabel timerContextMaxSizeLabel; + private JBLabel timerContextMaxSizeInfoLabel; + + private JComboBox systemLogLevelComboBox; + private JComboBox n1qlConsistencyComboBox; + private JComboBox languageCompatibilityComboBox; + + private JBTextField workersField; + private JBTextField scriptTimeoutField; + private JBTextField timerContextMaxSizeField; + + public AdvancedSettings() { + // Advanced Settings panel + advancedSettingsPanel = new JPanel(); + advancedSettingsPanel.setLayout(new GridBagLayout()); + GridBagConstraints advancedSettingsPanelConstraints = new GridBagConstraints(); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 0; + + advancedSettingsPanelConstraints.anchor = GridBagConstraints.NORTHWEST; + advancedSettingsPanelConstraints.insets = new Insets(5, 5, 5, 5); + advancedSettingsPanelConstraints.fill = GridBagConstraints.HORIZONTAL; + + // Add components to the Advanced Settings panel + systemLogLevelLabel = new JBLabel("System Log Level"); + systemLogLevelLabel.setFont(systemLogLevelLabel.getFont().deriveFont(Font.BOLD)); + // advancedSettingsPanelConstraints.gridx = 0; + // advancedSettingsPanelConstraints.gridy = 0; + // advancedSettingsPanel.add(systemLogLevelLabel, + // advancedSettingsPanelConstraints); + + systemLogLevelInfoLabel = new JBLabel("Granularity of system events being captured in the log"); + systemLogLevelInfoLabel.setForeground(JBColor.GRAY); + // advancedSettingsPanelConstraints.gridx = 1; + // advancedSettingsPanelConstraints.gridy = 0; + // advancedSettingsPanel.add(systemLogLevelInfoLabel, + // advancedSettingsPanelConstraints); + + // Add both the labels to a panel + systemLogLevelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + systemLogLevelPanel.add(systemLogLevelLabel); + systemLogLevelPanel.add(systemLogLevelInfoLabel); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 0; + advancedSettingsPanel.add(systemLogLevelPanel, advancedSettingsPanelConstraints); + + systemLogLevelComboBox = new JComboBox<>(); + systemLogLevelComboBox.addItem("Info"); + systemLogLevelComboBox.addItem("Error"); + systemLogLevelComboBox.addItem("Warning"); + systemLogLevelComboBox.addItem("Debug"); + systemLogLevelComboBox.addItem("Trace"); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 1; + advancedSettingsPanel.add(systemLogLevelComboBox, advancedSettingsPanelConstraints); + + applicationLogFileLabel = new JBLabel( + "Application log file for this Function is at:"); + + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 2; + advancedSettingsPanel.add(applicationLogFileLabel, advancedSettingsPanelConstraints); + + n1qlConsistencyLabel = new JBLabel("N1QL Consistency"); + n1qlConsistencyLabel.setFont(n1qlConsistencyLabel.getFont().deriveFont(Font.BOLD)); + // advancedSettingsPanelConstraints.gridx = 0; + // advancedSettingsPanelConstraints.gridy = 3; + // advancedSettingsPanel.add(n1qlConsistencyLabel, + // advancedSettingsPanelConstraints); + + n1qlConsistencyInfoLabel = new JBLabel("Consistency level of N1QL statements in the function"); + n1qlConsistencyInfoLabel.setForeground(JBColor.GRAY); + // advancedSettingsPanelConstraints.gridx = 1; + // advancedSettingsPanelConstraints.gridy = 3; + // advancedSettingsPanel.add(n1qlConsistencyInfoLabel, + // advancedSettingsPanelConstraints); + + // Add both the labels to a panel + n1qlConsistencyPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + n1qlConsistencyPanel.add(n1qlConsistencyLabel); + n1qlConsistencyPanel.add(n1qlConsistencyInfoLabel); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 3; + advancedSettingsPanel.add(n1qlConsistencyPanel, advancedSettingsPanelConstraints); + + n1qlConsistencyComboBox = new JComboBox<>(); + n1qlConsistencyComboBox.addItem("None"); + n1qlConsistencyComboBox.addItem("Request"); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 4; + + advancedSettingsPanel.add(n1qlConsistencyComboBox, advancedSettingsPanelConstraints); + + workersLabel = new JBLabel("Workers"); + workersLabel.setFont(workersLabel.getFont().deriveFont(Font.BOLD)); + // advancedSettingsPanelConstraints.gridx = 0; + // advancedSettingsPanelConstraints.gridy = 5; + // advancedSettingsPanel.add(workersLabel, advancedSettingsPanelConstraints); + + workersInfoLabel = new JBLabel( + "Number of workers per node to process the events. If no value is specified, a default value of 1 worker is used."); + workersInfoLabel.setForeground(JBColor.GRAY); + // advancedSettingsPanelConstraints.gridx = 1; + // advancedSettingsPanelConstraints.gridy = 5; + // advancedSettingsPanel.add(workersInfoLabel, + // advancedSettingsPanelConstraints); + + // Add both the labels to a panel + workersPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + workersPanel.add(workersLabel); + workersPanel.add(workersInfoLabel); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 5; + advancedSettingsPanel.add(workersPanel, advancedSettingsPanelConstraints); + + workersField = new JBTextField(20); + workersField.setToolTipText("Enter the number of workers per node to process the events."); + // advancedSettingsPanelConstraints.gridx = 0; + // advancedSettingsPanelConstraints.gridy = 6; + // advancedSettingsPanel.add(workersField, advancedSettingsPanelConstraints); + + languageCompatibilityLabel = new JBLabel("Language compatibility"); + + languageCompatibilityLabel.setFont(languageCompatibilityLabel.getFont().deriveFont(Font.BOLD)); + // advancedSettingsPanelConstraints.gridx = 0; + // advancedSettingsPanelConstraints.gridy = 7; + // advancedSettingsPanel.add(languageCompatibilityLabel, + // advancedSettingsPanelConstraints); + + languageCompatibilityInfoLabel = new JBLabel("Language compatibility of the function"); + languageCompatibilityInfoLabel.setForeground(JBColor.GRAY); + // advancedSettingsPanelConstraints.gridx = 1; + // advancedSettingsPanelConstraints.gridy = 7; + // advancedSettingsPanel.add(languageCompatibilityInfoLabel, + // advancedSettingsPanelConstraints); + + // Add both the labels to a panel + languageCompatibilityPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + languageCompatibilityPanel.add(languageCompatibilityLabel); + languageCompatibilityPanel.add(languageCompatibilityInfoLabel); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 7; + advancedSettingsPanel.add(languageCompatibilityPanel, advancedSettingsPanelConstraints); + + languageCompatibilityComboBox = new JComboBox<>(); + languageCompatibilityComboBox.addItem("6.0.0"); + languageCompatibilityComboBox.addItem("6.5.0"); + languageCompatibilityComboBox.addItem("6.6.2"); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 8; + advancedSettingsPanel.add(languageCompatibilityComboBox, advancedSettingsPanelConstraints); + + scriptTimeoutLabel = new JBLabel("Script Timeout"); + + scriptTimeoutLabel.setFont(scriptTimeoutLabel.getFont().deriveFont(Font.BOLD)); + // advancedSettingsPanelConstraints.gridx = 0; + // advancedSettingsPanelConstraints.gridy = 9; + // advancedSettingsPanel.add(scriptTimeoutLabel, + // advancedSettingsPanelConstraints); + + scriptTimeoutInfoLabel = new JBLabel( + "Time after which the Function's execution will be timed out"); + scriptTimeoutInfoLabel.setForeground(JBColor.GRAY); + // advancedSettingsPanelConstraints.gridx = 1; + // advancedSettingsPanelConstraints.gridy = 9; + // advancedSettingsPanel.add(scriptTimeoutInfoLabel, + // advancedSettingsPanelConstraints); + + // Add both the labels to a panel + scriptTimeoutPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + scriptTimeoutPanel.add(scriptTimeoutLabel); + scriptTimeoutPanel.add(scriptTimeoutInfoLabel); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 9; + advancedSettingsPanel.add(scriptTimeoutPanel, advancedSettingsPanelConstraints); + + scriptTimeoutField = new JBTextField(20); + scriptTimeoutField.setText("60"); + scriptTimeoutField.setToolTipText( + "Enter the time after which the Function's execution will be timed out."); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 10; + advancedSettingsPanel.add(scriptTimeoutField, advancedSettingsPanelConstraints); + + timerContextMaxSizeLabel = new JBLabel("Timer Context Max Size"); + + timerContextMaxSizeLabel.setFont(timerContextMaxSizeLabel.getFont().deriveFont(Font.BOLD)); + // advancedSettingsPanelConstraints.gridx = 0; + // advancedSettingsPanelConstraints.gridy = 11; + // advancedSettingsPanel.add(timerContextMaxSizeLabel, + // advancedSettingsPanelConstraints); + + timerContextMaxSizeInfoLabel = new JBLabel( + "Maximum allowed value of the Timer Context Size in Bytes. Takes effect immediately."); + timerContextMaxSizeInfoLabel.setForeground(JBColor.GRAY); + // advancedSettingsPanelConstraints.gridx = 1; + // advancedSettingsPanelConstraints.gridy = 11; + // advancedSettingsPanel.add(timerContextMaxSizeInfoLabel, + // advancedSettingsPanelConstraints); + + // Add both the labels to a panel + timerContextMaxSizePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + timerContextMaxSizePanel.add(timerContextMaxSizeLabel); + timerContextMaxSizePanel.add(timerContextMaxSizeInfoLabel); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 11; + advancedSettingsPanel.add(timerContextMaxSizePanel, advancedSettingsPanelConstraints); + + timerContextMaxSizeField = new JBTextField(20); + timerContextMaxSizeField.setText("1024"); + timerContextMaxSizeField.setToolTipText( + "Enter the maximum allowed value of the Timer Context Size in Bytes."); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 12; + advancedSettingsPanel.add(timerContextMaxSizeField, advancedSettingsPanelConstraints); + } + + public JPanel getPanel() { + return advancedSettingsPanel; + } +} \ No newline at end of file diff --git a/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java b/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java new file mode 100644 index 00000000..56099e70 --- /dev/null +++ b/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java @@ -0,0 +1,464 @@ +package com.couchbase.intellij.eventing.settings; + +import java.awt.Color; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; + +import javax.swing.JButton; +// import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JPanel; + +import com.couchbase.intellij.eventing.components.CustomComboBox; +import com.intellij.ui.components.JBCheckBox; +import com.intellij.ui.components.JBLabel; +import com.intellij.ui.components.JBPasswordField; +import com.intellij.ui.components.JBTextField; + +public class BindingSettings { + + private Integer bindingTypeCount = 0; + + private JPanel bindingsPanel; + private JPanel bindingTypePanel; + private JPanel aliasPanel; + private JPanel bucketPanel; + + private JBLabel bindingTypeLabel; + private JBLabel bucketLabel; + private JBLabel bucketInfoLabel; + private JBLabel accessLabel; + private JBLabel authenticationLabel; + private JBLabel usernameLabel; + private JBLabel passwordLabel; + private JBLabel bearerKeyLabel; + private JBLabel constantAliasNameLabel; + private JBLabel constantValueLabel; + + private JComboBox bucketComboBox; + private JComboBox scopeComboBox; + private JComboBox collectionComboBox; + private JComboBox accessComboBox; + + private JBTextField bucketAliasNameField; + private JBTextField urlAliasNameField; + private JBTextField urlField; + private JBTextField usernameField; + private JBTextField bearerKeyField; + private JBTextField constantAliasNameField; + private JBTextField constantValueField; + + // Constructor + public BindingSettings() { + // Binding Type panel + bindingsPanel = new JPanel(new GridBagLayout()); + GridBagConstraints bindingsPanelGbc = new GridBagConstraints(); + bindingsPanelGbc.insets = new Insets(5, 5, 5, 5); + bindingsPanelGbc.anchor = GridBagConstraints.WEST; + + // Binding Type label + bindingTypeLabel = new JBLabel("Binding Type"); + bindingTypeLabel.setFont(bindingTypeLabel.getFont().deriveFont(Font.BOLD)); + bindingsPanelGbc.gridx = 0; + bindingsPanelGbc.gridy = 0; + bindingsPanel.add(bindingTypeLabel, bindingsPanelGbc); + + // Plus button + JButton plusButton = new JButton("+"); + plusButton.addActionListener(e -> addBindingType()); + bindingsPanelGbc.gridx = 1; + bindingsPanelGbc.gridy = 0; + bindingsPanel.add(plusButton, bindingsPanelGbc); + + // Minus button + JButton minusButton = new JButton("-"); + minusButton.addActionListener(e -> removeBindingType()); + bindingsPanelGbc.gridx = 2; + bindingsPanelGbc.gridy = 0; + bindingsPanel.add(minusButton, bindingsPanelGbc); + } + + private void addBindingType() { + // Increment the binding type count + bindingTypeCount++; + + // Create a new aliasPanel to hold the binding type components + bindingTypePanel = new JPanel(new GridBagLayout()); + GridBagConstraints bindingsGbc = new GridBagConstraints(); + bindingsGbc.insets = new Insets(5, 5, 5, 5); + bindingsGbc.anchor = GridBagConstraints.WEST; + bindingsGbc.fill = GridBagConstraints.HORIZONTAL; + + // Create the binding type dropdown menu + CustomComboBox bindingTypeComboBox = new CustomComboBox(); + bindingTypeComboBox.setToolTipText("Type of binding for this function."); + bindingTypeComboBox.addItem("Choose Binding Type"); + bindingTypeComboBox.addItem("Bucket Alias"); + bindingTypeComboBox.addItem("URL Alias"); + bindingTypeComboBox.addItem("Constant Alias"); + + bindingsGbc.gridx = 0; + bindingsGbc.gridy = 0; + bindingTypePanel.add(bindingTypeComboBox, bindingsGbc); + + // Create a aliasPanel to hold the alias-specific components + aliasPanel = new JPanel(new GridBagLayout()); + GridBagConstraints aliasGbc = new GridBagConstraints(); + aliasGbc.insets = new Insets(5, 5, 5, 5); + aliasGbc.anchor = GridBagConstraints.WEST; + aliasGbc.fill = GridBagConstraints.HORIZONTAL; + bindingsGbc.gridx = 1; + bindingsGbc.gridy = 0; + bindingsGbc.gridwidth = 2; + bindingTypePanel.add(aliasPanel, bindingsGbc); + + // Update the alias aliasPanel when the selected binding type changes + bindingTypeComboBox.addItemListener(e -> { + // Remove all components from the alias aliasPanel + aliasPanel.removeAll(); + + // Get the selected binding type + String selectedBindingType = (String) bindingTypeComboBox.getSelectedItem(); + + if (selectedBindingType.equals("Bucket Alias")) { + // Create the alias name text field + bucketAliasNameField = new JBTextField(20); + bucketAliasNameField.setToolTipText("Enter the alias name."); + bucketAliasNameField.getEmptyText().setText("Enter the alias name."); + aliasGbc.gridx = 0; + aliasGbc.gridy = 0; + aliasGbc.gridwidth = 4; + aliasPanel.add(bucketAliasNameField, aliasGbc); + + // Create the bucket label + bucketLabel = new JBLabel("Bucket"); + bucketLabel.setFont(bucketLabel.getFont().deriveFont(Font.BOLD)); + // aliasGbc.gridx = 0; + // aliasGbc.gridy = 1; + // aliasGbc.gridwidth = 1; + // aliasPanel.add(bucketLabel, aliasGbc); + + // Create the bucket info label + bucketInfoLabel = new JBLabel("bucket.scope.collection"); + bucketInfoLabel.setForeground(Color.GRAY); + // aliasGbc.gridx = 1; + // aliasGbc.gridy = 1; + // aliasPanel.add(bucketInfoLabel, aliasGbc); + + // Add both labels to a flow layout panel + bucketPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + bucketPanel.add(bucketLabel); + bucketPanel.add(bucketInfoLabel); + aliasGbc.gridx = 0; + aliasGbc.gridy = 1; + aliasGbc.gridwidth = 3; + aliasPanel.add(bucketPanel, aliasGbc); + + // Create the access label + accessLabel = new JBLabel("Access"); + accessLabel.setFont(accessLabel.getFont().deriveFont(Font.BOLD)); + aliasGbc.gridx = 3; + aliasGbc.gridy = 1; + aliasGbc.gridwidth = 1; + aliasPanel.add(accessLabel, aliasGbc); + + // Create the bucket dropdown menu + bucketComboBox = new JComboBox<>(); + // TODO: Populate the bucketComboBox with available buckets + aliasGbc.gridx = 0; + aliasGbc.gridy = 2; + aliasPanel.add(bucketComboBox, aliasGbc); + + // Create the scope dropdown menu + scopeComboBox = new JComboBox<>(); + scopeComboBox.setEnabled(false); + // TODO: Update the scopeComboBox when the selected bucket changes + aliasGbc.gridx = 1; + aliasGbc.gridy = 2; + aliasPanel.add(scopeComboBox, aliasGbc); + + // Create the collection dropdown menu + collectionComboBox = new JComboBox<>(); + collectionComboBox.setEnabled(false); + // TODO: Update the collectionComboBox when the selected scope changes + aliasGbc.gridx = 2; + aliasGbc.gridy = 2; + aliasPanel.add(collectionComboBox, aliasGbc); + + // Create access dropdown menu + accessComboBox = new JComboBox<>(); + accessComboBox.addItem("Read Only"); + accessComboBox.addItem("Read and Write"); + accessComboBox.setToolTipText("Select access level for this bucket."); + accessComboBox.setEnabled(true); + accessComboBox.setSelectedIndex(0); + aliasGbc.gridx = 3; + aliasGbc.gridy = 2; + aliasPanel.add(accessComboBox, aliasGbc); + + } else if (selectedBindingType.equals("URL Alias")) { + // Create the alias name text field + urlAliasNameField = new JBTextField(20); + urlAliasNameField.setToolTipText("Enter the alias name."); + urlAliasNameField.getEmptyText().setText("Enter the alias name."); + aliasGbc.gridx = 0; + aliasGbc.gridy = 0; + aliasPanel.add(urlAliasNameField, aliasGbc); + + // Create the URL text field + urlField = new JBTextField(20); + urlField.setToolTipText("Enter the URL."); + urlField.getEmptyText().setText("Enter the URL."); + aliasGbc.gridx = 1; + aliasGbc.gridy = 0; + aliasPanel.add(urlField, aliasGbc); + + // Create the allow cookies checkbox + JBCheckBox allowCookiesCheckBox = new JBCheckBox("Allow cookies"); + allowCookiesCheckBox.setToolTipText("Allow cookies for this URL."); + aliasGbc.gridx = 0; + aliasGbc.gridy = 1; + aliasPanel.add(allowCookiesCheckBox, aliasGbc); + + // Create the validate SSL certificate checkbox + JBCheckBox validateSslCertificateCheckBox = new JBCheckBox("Validate SSL certificate"); + validateSslCertificateCheckBox.setToolTipText("Validate SSL certificate for this URL."); + aliasGbc.gridx = 1; + aliasGbc.gridy = 1; + aliasPanel.add(validateSslCertificateCheckBox, aliasGbc); + + // Create the authentication label + authenticationLabel = new JBLabel("Authentication"); + authenticationLabel.setFont(authenticationLabel.getFont().deriveFont(Font.BOLD)); + authenticationLabel.setToolTipText("Select authentication method for this URL."); + authenticationLabel.setDisplayedMnemonic('A'); + authenticationLabel.setDisplayedMnemonicIndex(0); + authenticationLabel.setHorizontalAlignment(JBTextField.LEFT); + authenticationLabel.setVerticalAlignment(JBTextField.CENTER); + authenticationLabel.setHorizontalTextPosition(JBTextField.RIGHT); + authenticationLabel.setVerticalTextPosition(JBTextField.CENTER); + aliasGbc.gridx = 0; + aliasGbc.gridy = 2; + aliasPanel.add(authenticationLabel, aliasGbc); + + // Create the auth dropdown menu + CustomComboBox authComboBox = new CustomComboBox(); + authComboBox.addItem("No Auth"); + authComboBox.addItem("Basic"); + authComboBox.addItem("Bearer"); + authComboBox.addItem("Digest"); + authComboBox.setToolTipText("Select authentication method for this URL."); + authComboBox.setEnabled(true); + + authComboBox.setSelectedIndex(0); + aliasGbc.gridx = 1; + aliasGbc.gridy = 2; + aliasPanel.add(authComboBox, aliasGbc); + + // Create the username label and text field + usernameLabel = new JBLabel("Username"); + usernameLabel.setFont(usernameLabel.getFont().deriveFont(Font.BOLD)); + usernameLabel.setToolTipText("Enter the username for basic or digest authentication."); + usernameLabel.setDisplayedMnemonic('U'); + usernameLabel.setDisplayedMnemonicIndex(0); + usernameLabel.setHorizontalAlignment(JBTextField.LEFT); + usernameLabel.setVerticalAlignment(JBTextField.CENTER); + usernameLabel.setHorizontalTextPosition(JBTextField.RIGHT); + usernameLabel.setVerticalTextPosition(JBTextField.CENTER); + usernameLabel.setVisible(false); + usernameLabel.setEnabled(false); + bindingsGbc.gridx = 0; + bindingsGbc.gridy = 3; + aliasPanel.add(usernameLabel, bindingsGbc); + + usernameField = new JBTextField(20); + usernameField.setToolTipText( + "Enter the username for basic or digest authentication."); + usernameField.getEmptyText().setText("Enter the username."); + usernameField.setVisible(false); + usernameField.setEnabled(false); + bindingsGbc.gridx = 1; + bindingsGbc.gridy = 3; + aliasPanel.add(usernameField, bindingsGbc); + + // Create the password label and text field + passwordLabel = new JBLabel("Password"); + passwordLabel.setFont(passwordLabel.getFont().deriveFont(Font.BOLD)); + passwordLabel.setToolTipText( + "Enter the password for basic or digest authentication."); + passwordLabel.setDisplayedMnemonic('P'); + passwordLabel.setDisplayedMnemonicIndex(0); + passwordLabel.setHorizontalAlignment(JBTextField.LEFT); + passwordLabel.setVerticalAlignment(JBTextField.CENTER); + passwordLabel.setHorizontalTextPosition(JBTextField.RIGHT); + passwordLabel.setVerticalTextPosition(JBTextField.CENTER); + passwordLabel.setVisible(false); + passwordLabel.setEnabled(false); + bindingsGbc.gridx = 0; + bindingsGbc.gridy = 4; + aliasPanel.add(passwordLabel, bindingsGbc); + + JBPasswordField passwordField = new JBPasswordField(); + passwordField.setToolTipText( + "Enter the password for basic or digest authentication."); + passwordField.getEmptyText().setText("Enter the password."); + passwordField.setVisible(false); + passwordField.setEnabled(false); + bindingsGbc.gridx = 1; + bindingsGbc.gridy = 4; + aliasPanel.add(passwordField, bindingsGbc); + + // Create the bearer key label and text field + bearerKeyLabel = new JBLabel("Bearer Key"); + bearerKeyLabel.setFont(bearerKeyLabel.getFont().deriveFont(Font.BOLD)); + bearerKeyLabel.setToolTipText( + "Enter the bearer key for bearer token authentication."); + bearerKeyLabel.setDisplayedMnemonic('B'); + bearerKeyLabel.setDisplayedMnemonicIndex(0); + bearerKeyLabel.setHorizontalAlignment(JBTextField.LEFT); + bearerKeyLabel.setVerticalAlignment(JBTextField.CENTER); + bearerKeyLabel.setHorizontalTextPosition(JBTextField.RIGHT); + bearerKeyLabel.setVerticalTextPosition(JBTextField.CENTER); + bearerKeyLabel.setVisible(false); + bearerKeyLabel.setEnabled(false); + bindingsGbc.gridx = 0; + bindingsGbc.gridy = 5; + aliasPanel.add(bearerKeyLabel, bindingsGbc); + + bearerKeyField = new JBTextField(20); + bearerKeyField.setToolTipText( + "Enter the bearer key for bearer token authentication."); + bearerKeyField.getEmptyText().setText("Enter the bearer key."); + bearerKeyField.setVisible(false); + bearerKeyField.setEnabled(false); + bindingsGbc.gridx = 1; + bindingsGbc.gridy = 5; + aliasPanel.add(bearerKeyField, bindingsGbc); + + // Create the auth dropdown menu listener + authComboBox.addActionListener(ee -> { + // Update the visibility of the authentication fields based on the selected + String selectedAuth = (String) authComboBox.getSelectedItem(); + if (selectedAuth.equals("Basic") || selectedAuth.equals("Digest")) { + usernameLabel.setVisible(true); + usernameField.setVisible(true); + usernameLabel.setEnabled(true); + usernameField.setEnabled(true); + + passwordLabel.setVisible(true); + passwordField.setVisible(true); + passwordLabel.setEnabled(true); + passwordField.setEnabled(true); + + bearerKeyLabel.setVisible(false); + bearerKeyField.setVisible(false); + bearerKeyLabel.setEnabled(false); + bearerKeyField.setEnabled(false); + } else if (selectedAuth.equals("Bearer")) { + usernameLabel.setVisible(false); + usernameField.setVisible(false); + usernameLabel.setEnabled(false); + usernameField.setEnabled(false); + + passwordLabel.setVisible(false); + passwordField.setVisible(false); + passwordLabel.setEnabled(false); + passwordField.setEnabled(false); + + bearerKeyLabel.setVisible(true); + bearerKeyField.setVisible(true); + bearerKeyLabel.setEnabled(true); + bearerKeyField.setEnabled(true); + } else { + usernameLabel.setVisible(false); + usernameField.setVisible(false); + usernameLabel.setEnabled(false); + usernameField.setEnabled(false); + + passwordLabel.setVisible(false); + passwordField.setVisible(false); + passwordLabel.setEnabled(false); + passwordField.setEnabled(false); + + bearerKeyLabel.setVisible(false); + bearerKeyField.setVisible(false); + bearerKeyLabel.setEnabled(false); + bearerKeyField.setEnabled(false); + } + + }); + + } else if (selectedBindingType.equals("Constant Alias")) { + // Create the alias name label + constantAliasNameLabel = new JBLabel("Alias Name:"); + aliasGbc.gridx = 0; + aliasGbc.gridy = 0; + aliasPanel.add(constantAliasNameLabel, aliasGbc); + + // Create the alias name text field + constantAliasNameField = new JBTextField(20); + constantAliasNameField.setToolTipText("Enter the alias name."); + constantAliasNameField.getEmptyText().setText("Enter the alias name."); + aliasGbc.gridx = 1; + aliasGbc.gridy = 0; + aliasPanel.add(constantAliasNameField, aliasGbc); + + // Create the value label + constantValueLabel = new JBLabel("Value:"); + aliasGbc.gridx = 0; + aliasGbc.gridy = 1; + aliasPanel.add(constantValueLabel, aliasGbc); + + // Create the value text field + constantValueField = new JBTextField(20); + constantValueField.setToolTipText("Enter the constant value."); + constantValueField.getEmptyText().setText("Enter the constant value."); + aliasGbc.gridx = 1; + aliasGbc.gridy = 1; + aliasPanel.add(constantValueField, aliasGbc); + } + + // Repaint the alias aliasPanel to show the updated components + aliasPanel.revalidate(); + aliasPanel.repaint(); + }); + bindingTypeComboBox.setSelectedIndex(0); + + // Add the binding type aliasPanel to the bindings aliasPanel + GridBagConstraints bindingsPanelGbc = new GridBagConstraints(); + bindingsPanelGbc.insets = new Insets(5, 5, 5, 5); + bindingsPanelGbc.anchor = GridBagConstraints.WEST; + bindingsPanelGbc.gridx = 0; + bindingsPanelGbc.gridy = bindingTypeCount; + bindingsPanelGbc.gridwidth = 3; + bindingsPanel.add(bindingTypePanel, bindingsPanelGbc); + + // Repaint the bindings aliasPanel to show the new binding type + bindingsPanel.revalidate(); + bindingsPanel.repaint(); + } + + private void removeBindingType() { + // Get the number of binding types + int bindingTypeCount = bindingsPanel.getComponentCount(); + + // Check if there are any binding types to remove + if (bindingTypeCount > 0) { + // Remove the last binding type aliasPanel + bindingsPanel.remove(bindingTypeCount - 1); + + // Repaint the bindings aliasPanel to show the removed binding type + bindingsPanel.revalidate(); + bindingsPanel.repaint(); + } + } + + // Getters and setters + public JPanel getPanel() { + return bindingsPanel; + } + +} \ No newline at end of file diff --git a/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java b/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java new file mode 100644 index 00000000..a3a4f800 --- /dev/null +++ b/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java @@ -0,0 +1,282 @@ +package com.couchbase.intellij.eventing.settings; + +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; + +import javax.swing.JComboBox; +import javax.swing.JPanel; + +import com.intellij.ui.JBColor; +import com.intellij.ui.components.JBLabel; +import com.intellij.ui.components.JBScrollPane; +import com.intellij.ui.components.JBTextArea; +import com.intellij.ui.components.JBTextField; + +public class GeneralSettings { + + private JPanel generalSettingsPanel; + private JPanel functionScopePanel; + private JPanel listenToLocationPanel; + private JPanel eventingStoragePanel; + + private JBLabel functionScopeLabel; + private JBLabel functionScopeInfoLabel; + private JBLabel helpLabel1; + private JBLabel listenToLocationLabel; + private JBLabel listenToLocationInfoLabel; + private JBLabel helpLabel2; + private JBLabel eventingStorageLabel; + private JBLabel eventingStorageInfoLabel; + private JBLabel helpLabel3; + private JBLabel functionNameLabel; + private JBLabel deploymentFeedBoundaryLabel; + private JBLabel warningLabel; + private JBLabel descriptionLabel; + + private JComboBox functionScopeBucketComboBox; + private JComboBox functionScopeScopeComboBox; + private JComboBox listenToLocationBucketComboBox; + private JComboBox listenToLocationScopeComboBox; + private JComboBox listenToLocationCollectionComboBox; + private JComboBox eventingStorageBucketComboBox; + private JComboBox eventingStorageScopeComboBox; + private JComboBox eventingStorageCollectionComboBox; + private JComboBox deploymentFeedBoundaryComboBox; + + public GeneralSettings() { + generalSettingsPanel = new JPanel(); + generalSettingsPanel.setLayout(new GridBagLayout()); + + GridBagConstraints generalSettingsPanelConstraints = new GridBagConstraints(); + generalSettingsPanelConstraints.gridx = 0; + generalSettingsPanelConstraints.gridy = 0; + generalSettingsPanelConstraints.weightx = 1.0; + // generalSettingsPanelConstraints.weighty = 1.0; + generalSettingsPanelConstraints.insets = new Insets(5, 5, 5, 5); + generalSettingsPanelConstraints.anchor = GridBagConstraints.NORTHWEST; + generalSettingsPanelConstraints.fill = GridBagConstraints.HORIZONTAL; + + // Function Scope label + functionScopeLabel = new JBLabel("Function scope"); + functionScopeLabel.setFont(functionScopeLabel.getFont().deriveFont(Font.BOLD)); + + functionScopeInfoLabel = new JBLabel("bucket.scope"); + functionScopeInfoLabel.setForeground(JBColor.GRAY); + + // Add both labels to a flow layout + functionScopePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + functionScopePanel.add(functionScopeLabel); + functionScopePanel.add(functionScopeInfoLabel); + generalSettingsPanelConstraints.gridx = 0; + generalSettingsPanelConstraints.gridy = 0; + generalSettingsPanel.add(functionScopePanel, generalSettingsPanelConstraints); + + functionScopeBucketComboBox = new JComboBox<>(); + // functionScopeBucketComboBox.addActionListener(e -> updateScopes()); + generalSettingsPanelConstraints.gridx = 0; + generalSettingsPanelConstraints.gridy = 1; + generalSettingsPanel.add(functionScopeBucketComboBox, generalSettingsPanelConstraints); + + functionScopeScopeComboBox = new JComboBox<>(); + functionScopeScopeComboBox.setEnabled(false); + generalSettingsPanelConstraints.gridx = 1; + generalSettingsPanelConstraints.gridy = 1; + generalSettingsPanel.add(functionScopeScopeComboBox, generalSettingsPanelConstraints); + + // Function Scope error label + + helpLabel1 = new JBLabel( + "Please specify a scope to which the function belongs. User should have Eventing Manage Scope Functions permission on this scope"); + helpLabel1.setForeground(JBColor.GRAY); + generalSettingsPanelConstraints.gridx = 0; + generalSettingsPanelConstraints.gridy = 2; + generalSettingsPanelConstraints.gridwidth = 3; + generalSettingsPanel.add(helpLabel1, generalSettingsPanelConstraints); + + // Listen to location label + listenToLocationLabel = new JBLabel("Listen to location"); + + listenToLocationLabel.setFont(listenToLocationLabel.getFont().deriveFont(Font.BOLD)); + // generalSettingsPanelConstraints.gridx = 0; + // generalSettingsPanelConstraints.gridy = 3; + // generalSettingsPanel.add(listenToLocationLabel, + // generalSettingsPanelConstraints); + + listenToLocationInfoLabel = new JBLabel("bucket.scope.collection"); + listenToLocationInfoLabel.setForeground(JBColor.GRAY); + // generalSettingsPanelConstraints.gridx = 1; + // generalSettingsPanelConstraints.gridy = 3; + // generalSettingsPanel.add(listenToLocationInfoLabel, + // generalSettingsPanelConstraints); + + // Add both labels to a flow layout + listenToLocationPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + listenToLocationPanel.add(listenToLocationLabel); + listenToLocationPanel.add(listenToLocationInfoLabel); + generalSettingsPanelConstraints.gridx = 0; + generalSettingsPanelConstraints.gridy = 3; + generalSettingsPanel.add(listenToLocationPanel, generalSettingsPanelConstraints); + + listenToLocationBucketComboBox = new JComboBox<>(); + // listenToLocationBucketComboBox.addActionListener(e -> updateScopes()); + generalSettingsPanelConstraints.gridx = 0; + generalSettingsPanelConstraints.gridy = 4; + generalSettingsPanelConstraints.gridwidth = 1; + generalSettingsPanel.add(listenToLocationBucketComboBox, generalSettingsPanelConstraints); + + listenToLocationScopeComboBox = new JComboBox<>(); + listenToLocationScopeComboBox.setEnabled(false); + generalSettingsPanelConstraints.gridx = 1; + generalSettingsPanelConstraints.gridy = 4; + generalSettingsPanel.add(listenToLocationScopeComboBox, generalSettingsPanelConstraints); + + listenToLocationCollectionComboBox = new JComboBox<>(); + listenToLocationCollectionComboBox.setEnabled(false); + generalSettingsPanelConstraints.gridx = 2; + generalSettingsPanelConstraints.gridy = 4; + generalSettingsPanel.add(listenToLocationCollectionComboBox, generalSettingsPanelConstraints); + + // Listen to location error label + helpLabel2 = new JBLabel( + "Please specify a source location for your function. User should have DCP Data Read permission on this keyspace"); + helpLabel2.setForeground(JBColor.GRAY); + generalSettingsPanelConstraints.gridx = 0; + generalSettingsPanelConstraints.gridy = 5; + generalSettingsPanelConstraints.gridwidth = 3; + + generalSettingsPanel.add(helpLabel2, generalSettingsPanelConstraints); + + // Eventing Storage label + eventingStorageLabel = new JBLabel("Eventing Storage"); + eventingStorageLabel.setFont(eventingStorageLabel.getFont().deriveFont(Font.BOLD)); + // generalSettingsPanelConstraints.gridx = 0; + // generalSettingsPanelConstraints.gridy = 6; + // generalSettingsPanel.add(eventingStorageLabel, + // generalSettingsPanelConstraints); + + eventingStorageInfoLabel = new JBLabel("bucket.scope.collection"); + eventingStorageInfoLabel.setForeground(JBColor.GRAY); + // generalSettingsPanelConstraints.gridx = 1; + // generalSettingsPanelConstraints.gridy = 6; + // generalSettingsPanelConstraints.gridwidth = 2; + // generalSettingsPanel.add(eventingStorageInfoLabel, + // generalSettingsPanelConstraints); + + // Add both labels to a flow layout + eventingStoragePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + eventingStoragePanel.add(eventingStorageLabel); + eventingStoragePanel.add(eventingStorageInfoLabel); + generalSettingsPanelConstraints.gridx = 0; + generalSettingsPanelConstraints.gridy = 6; + generalSettingsPanel.add(eventingStoragePanel, generalSettingsPanelConstraints); + + eventingStorageBucketComboBox = new JComboBox<>(); + // eventingStorageBucketComboBox.addActionListener(e -> updateScopes()); + generalSettingsPanelConstraints.gridx = 0; + generalSettingsPanelConstraints.gridy = 7; + generalSettingsPanelConstraints.gridwidth = 1; + generalSettingsPanel.add(eventingStorageBucketComboBox, generalSettingsPanelConstraints); + + eventingStorageScopeComboBox = new JComboBox<>(); + eventingStorageScopeComboBox.setEnabled(false); + generalSettingsPanelConstraints.gridx = 1; + generalSettingsPanelConstraints.gridy = 7; + generalSettingsPanel.add(eventingStorageScopeComboBox, generalSettingsPanelConstraints); + + eventingStorageCollectionComboBox = new JComboBox<>(); + eventingStorageCollectionComboBox.setEnabled(false); + generalSettingsPanelConstraints.gridx = 2; + generalSettingsPanelConstraints.gridy = 7; + + generalSettingsPanel.add(eventingStorageCollectionComboBox, generalSettingsPanelConstraints); + + // Eventing Storage help label + helpLabel3 = new JBLabel( + "Please specify a location to store Eventing data. User should have read/write permission on this keyspace"); + helpLabel3.setForeground(JBColor.GRAY); + generalSettingsPanelConstraints.gridx = 0; + generalSettingsPanelConstraints.gridy = 8; + generalSettingsPanelConstraints.gridwidth = 3; + generalSettingsPanel.add(helpLabel3, generalSettingsPanelConstraints); + + // Function Name label and text field + functionNameLabel = new JBLabel("Function Name"); + functionNameLabel.setFont(functionNameLabel.getFont().deriveFont(Font.BOLD)); + generalSettingsPanelConstraints.gridx = 0; + generalSettingsPanelConstraints.gridy = 9; + generalSettingsPanel.add(functionNameLabel, generalSettingsPanelConstraints); + + JBTextField functionNameField = new JBTextField(20); + functionNameField.setToolTipText("Enter the name of the function."); + generalSettingsPanelConstraints.gridx = 0; + generalSettingsPanelConstraints.gridy = 10; + generalSettingsPanel.add(functionNameField, generalSettingsPanelConstraints); + + // Deployment Feed Boundary label and combo box + deploymentFeedBoundaryLabel = new JBLabel("Deployment Feed Boundary"); + + deploymentFeedBoundaryLabel.setFont(deploymentFeedBoundaryLabel.getFont().deriveFont(Font.BOLD)); + deploymentFeedBoundaryLabel.setToolTipText( + "The preferred Deployment time Feed Boundary for the function."); + generalSettingsPanelConstraints.gridx = 0; + generalSettingsPanelConstraints.gridy = 11; + generalSettingsPanel.add(deploymentFeedBoundaryLabel, generalSettingsPanelConstraints); + + deploymentFeedBoundaryComboBox = new JComboBox<>(); + deploymentFeedBoundaryComboBox.addItem("Everything"); + deploymentFeedBoundaryComboBox.addItem("From now"); + deploymentFeedBoundaryComboBox.setToolTipText( + "The preferred Deployment time Feed Boundary for the function."); + + generalSettingsPanelConstraints.gridx = 0; + generalSettingsPanelConstraints.gridy = 12; + generalSettingsPanelConstraints.gridwidth = 3; + generalSettingsPanel.add(deploymentFeedBoundaryComboBox, generalSettingsPanelConstraints); + + warningLabel = new JBLabel(""); + warningLabel.setForeground(JBColor.ORANGE); + generalSettingsPanelConstraints.gridx = 0; + generalSettingsPanelConstraints.gridy = 13; + generalSettingsPanel.add(warningLabel, generalSettingsPanelConstraints); + + deploymentFeedBoundaryComboBox.addActionListener(e -> { + if (deploymentFeedBoundaryComboBox.getSelectedItem().equals("From now")) { + warningLabel.setText( + "Warning: Deploying with 'From now' will ignore all past mutations."); + } else { + warningLabel.setText(""); + } + }); + + // Description label and text area + descriptionLabel = new JBLabel("Description"); + + descriptionLabel.setFont(descriptionLabel.getFont().deriveFont(Font.BOLD)); + descriptionLabel.setToolTipText("Enter a description for the function (optional)."); + descriptionLabel.setDisplayedMnemonic('D'); + descriptionLabel.setDisplayedMnemonicIndex(0); + descriptionLabel.setHorizontalAlignment(JBTextField.LEFT); + generalSettingsPanelConstraints.gridx = 0; + generalSettingsPanelConstraints.gridy = 14; + generalSettingsPanel.add(descriptionLabel, generalSettingsPanelConstraints); + + JBTextArea descriptionTextArea = new JBTextArea(20, 20); + descriptionTextArea.setLineWrap(true); + descriptionTextArea.setWrapStyleWord(true); + descriptionTextArea.setToolTipText("Enter a description for the function (optional)."); + descriptionLabel.setLabelFor(descriptionTextArea); + JBScrollPane descriptionScrollPane = new JBScrollPane(descriptionTextArea); + generalSettingsPanelConstraints.gridx = 0; + generalSettingsPanelConstraints.gridy = 15; + generalSettingsPanelConstraints.fill = GridBagConstraints.BOTH; + generalSettingsPanel.add(descriptionScrollPane, generalSettingsPanelConstraints); + + } + + public JPanel getPanel() { + return generalSettingsPanel; + } +} \ No newline at end of file From 00aacaf7a162b7d4c1cf5438aa51f03cdfebcb70 Mon Sep 17 00:00:00 2001 From: teetangh Date: Mon, 12 Jun 2023 21:13:25 +0530 Subject: [PATCH 06/15] Add a horizontal seperator and refactored code in Bindings Settings --- .../eventing/settings/AdvancedSettings.java | 479 +++++++++--------- .../eventing/settings/BindingSettings.java | 85 ++-- 2 files changed, 289 insertions(+), 275 deletions(-) diff --git a/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java b/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java index bb9fe554..7f9b3517 100644 --- a/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java @@ -15,243 +15,244 @@ public class AdvancedSettings { - private JPanel advancedSettingsPanel; - private JPanel systemLogLevelPanel; - private JPanel n1qlConsistencyPanel; - private JPanel workersPanel; - private JPanel languageCompatibilityPanel; - private JPanel scriptTimeoutPanel; - private JPanel timerContextMaxSizePanel; - - private JBLabel systemLogLevelLabel; - private JBLabel systemLogLevelInfoLabel; - private JBLabel applicationLogFileLabel; - private JBLabel n1qlConsistencyLabel; - private JBLabel n1qlConsistencyInfoLabel; - private JBLabel workersLabel; - private JBLabel workersInfoLabel; - private JBLabel languageCompatibilityLabel; - private JBLabel languageCompatibilityInfoLabel; - private JBLabel scriptTimeoutLabel; - private JBLabel scriptTimeoutInfoLabel; - private JBLabel timerContextMaxSizeLabel; - private JBLabel timerContextMaxSizeInfoLabel; - - private JComboBox systemLogLevelComboBox; - private JComboBox n1qlConsistencyComboBox; - private JComboBox languageCompatibilityComboBox; - - private JBTextField workersField; - private JBTextField scriptTimeoutField; - private JBTextField timerContextMaxSizeField; - - public AdvancedSettings() { - // Advanced Settings panel - advancedSettingsPanel = new JPanel(); - advancedSettingsPanel.setLayout(new GridBagLayout()); - GridBagConstraints advancedSettingsPanelConstraints = new GridBagConstraints(); - advancedSettingsPanelConstraints.gridx = 0; - advancedSettingsPanelConstraints.gridy = 0; - - advancedSettingsPanelConstraints.anchor = GridBagConstraints.NORTHWEST; - advancedSettingsPanelConstraints.insets = new Insets(5, 5, 5, 5); - advancedSettingsPanelConstraints.fill = GridBagConstraints.HORIZONTAL; - - // Add components to the Advanced Settings panel - systemLogLevelLabel = new JBLabel("System Log Level"); - systemLogLevelLabel.setFont(systemLogLevelLabel.getFont().deriveFont(Font.BOLD)); - // advancedSettingsPanelConstraints.gridx = 0; - // advancedSettingsPanelConstraints.gridy = 0; - // advancedSettingsPanel.add(systemLogLevelLabel, - // advancedSettingsPanelConstraints); - - systemLogLevelInfoLabel = new JBLabel("Granularity of system events being captured in the log"); - systemLogLevelInfoLabel.setForeground(JBColor.GRAY); - // advancedSettingsPanelConstraints.gridx = 1; - // advancedSettingsPanelConstraints.gridy = 0; - // advancedSettingsPanel.add(systemLogLevelInfoLabel, - // advancedSettingsPanelConstraints); - - // Add both the labels to a panel - systemLogLevelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - systemLogLevelPanel.add(systemLogLevelLabel); - systemLogLevelPanel.add(systemLogLevelInfoLabel); - advancedSettingsPanelConstraints.gridx = 0; - advancedSettingsPanelConstraints.gridy = 0; - advancedSettingsPanel.add(systemLogLevelPanel, advancedSettingsPanelConstraints); - - systemLogLevelComboBox = new JComboBox<>(); - systemLogLevelComboBox.addItem("Info"); - systemLogLevelComboBox.addItem("Error"); - systemLogLevelComboBox.addItem("Warning"); - systemLogLevelComboBox.addItem("Debug"); - systemLogLevelComboBox.addItem("Trace"); - advancedSettingsPanelConstraints.gridx = 0; - advancedSettingsPanelConstraints.gridy = 1; - advancedSettingsPanel.add(systemLogLevelComboBox, advancedSettingsPanelConstraints); - - applicationLogFileLabel = new JBLabel( - "Application log file for this Function is at:"); - - advancedSettingsPanelConstraints.gridx = 0; - advancedSettingsPanelConstraints.gridy = 2; - advancedSettingsPanel.add(applicationLogFileLabel, advancedSettingsPanelConstraints); - - n1qlConsistencyLabel = new JBLabel("N1QL Consistency"); - n1qlConsistencyLabel.setFont(n1qlConsistencyLabel.getFont().deriveFont(Font.BOLD)); - // advancedSettingsPanelConstraints.gridx = 0; - // advancedSettingsPanelConstraints.gridy = 3; - // advancedSettingsPanel.add(n1qlConsistencyLabel, - // advancedSettingsPanelConstraints); - - n1qlConsistencyInfoLabel = new JBLabel("Consistency level of N1QL statements in the function"); - n1qlConsistencyInfoLabel.setForeground(JBColor.GRAY); - // advancedSettingsPanelConstraints.gridx = 1; - // advancedSettingsPanelConstraints.gridy = 3; - // advancedSettingsPanel.add(n1qlConsistencyInfoLabel, - // advancedSettingsPanelConstraints); - - // Add both the labels to a panel - n1qlConsistencyPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - n1qlConsistencyPanel.add(n1qlConsistencyLabel); - n1qlConsistencyPanel.add(n1qlConsistencyInfoLabel); - advancedSettingsPanelConstraints.gridx = 0; - advancedSettingsPanelConstraints.gridy = 3; - advancedSettingsPanel.add(n1qlConsistencyPanel, advancedSettingsPanelConstraints); - - n1qlConsistencyComboBox = new JComboBox<>(); - n1qlConsistencyComboBox.addItem("None"); - n1qlConsistencyComboBox.addItem("Request"); - advancedSettingsPanelConstraints.gridx = 0; - advancedSettingsPanelConstraints.gridy = 4; - - advancedSettingsPanel.add(n1qlConsistencyComboBox, advancedSettingsPanelConstraints); - - workersLabel = new JBLabel("Workers"); - workersLabel.setFont(workersLabel.getFont().deriveFont(Font.BOLD)); - // advancedSettingsPanelConstraints.gridx = 0; - // advancedSettingsPanelConstraints.gridy = 5; - // advancedSettingsPanel.add(workersLabel, advancedSettingsPanelConstraints); - - workersInfoLabel = new JBLabel( - "Number of workers per node to process the events. If no value is specified, a default value of 1 worker is used."); - workersInfoLabel.setForeground(JBColor.GRAY); - // advancedSettingsPanelConstraints.gridx = 1; - // advancedSettingsPanelConstraints.gridy = 5; - // advancedSettingsPanel.add(workersInfoLabel, - // advancedSettingsPanelConstraints); - - // Add both the labels to a panel - workersPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - workersPanel.add(workersLabel); - workersPanel.add(workersInfoLabel); - advancedSettingsPanelConstraints.gridx = 0; - advancedSettingsPanelConstraints.gridy = 5; - advancedSettingsPanel.add(workersPanel, advancedSettingsPanelConstraints); - - workersField = new JBTextField(20); - workersField.setToolTipText("Enter the number of workers per node to process the events."); - // advancedSettingsPanelConstraints.gridx = 0; - // advancedSettingsPanelConstraints.gridy = 6; - // advancedSettingsPanel.add(workersField, advancedSettingsPanelConstraints); - - languageCompatibilityLabel = new JBLabel("Language compatibility"); - - languageCompatibilityLabel.setFont(languageCompatibilityLabel.getFont().deriveFont(Font.BOLD)); - // advancedSettingsPanelConstraints.gridx = 0; - // advancedSettingsPanelConstraints.gridy = 7; - // advancedSettingsPanel.add(languageCompatibilityLabel, - // advancedSettingsPanelConstraints); - - languageCompatibilityInfoLabel = new JBLabel("Language compatibility of the function"); - languageCompatibilityInfoLabel.setForeground(JBColor.GRAY); - // advancedSettingsPanelConstraints.gridx = 1; - // advancedSettingsPanelConstraints.gridy = 7; - // advancedSettingsPanel.add(languageCompatibilityInfoLabel, - // advancedSettingsPanelConstraints); - - // Add both the labels to a panel - languageCompatibilityPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - languageCompatibilityPanel.add(languageCompatibilityLabel); - languageCompatibilityPanel.add(languageCompatibilityInfoLabel); - advancedSettingsPanelConstraints.gridx = 0; - advancedSettingsPanelConstraints.gridy = 7; - advancedSettingsPanel.add(languageCompatibilityPanel, advancedSettingsPanelConstraints); - - languageCompatibilityComboBox = new JComboBox<>(); - languageCompatibilityComboBox.addItem("6.0.0"); - languageCompatibilityComboBox.addItem("6.5.0"); - languageCompatibilityComboBox.addItem("6.6.2"); - advancedSettingsPanelConstraints.gridx = 0; - advancedSettingsPanelConstraints.gridy = 8; - advancedSettingsPanel.add(languageCompatibilityComboBox, advancedSettingsPanelConstraints); - - scriptTimeoutLabel = new JBLabel("Script Timeout"); - - scriptTimeoutLabel.setFont(scriptTimeoutLabel.getFont().deriveFont(Font.BOLD)); - // advancedSettingsPanelConstraints.gridx = 0; - // advancedSettingsPanelConstraints.gridy = 9; - // advancedSettingsPanel.add(scriptTimeoutLabel, - // advancedSettingsPanelConstraints); - - scriptTimeoutInfoLabel = new JBLabel( - "Time after which the Function's execution will be timed out"); - scriptTimeoutInfoLabel.setForeground(JBColor.GRAY); - // advancedSettingsPanelConstraints.gridx = 1; - // advancedSettingsPanelConstraints.gridy = 9; - // advancedSettingsPanel.add(scriptTimeoutInfoLabel, - // advancedSettingsPanelConstraints); - - // Add both the labels to a panel - scriptTimeoutPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - scriptTimeoutPanel.add(scriptTimeoutLabel); - scriptTimeoutPanel.add(scriptTimeoutInfoLabel); - advancedSettingsPanelConstraints.gridx = 0; - advancedSettingsPanelConstraints.gridy = 9; - advancedSettingsPanel.add(scriptTimeoutPanel, advancedSettingsPanelConstraints); - - scriptTimeoutField = new JBTextField(20); - scriptTimeoutField.setText("60"); - scriptTimeoutField.setToolTipText( - "Enter the time after which the Function's execution will be timed out."); - advancedSettingsPanelConstraints.gridx = 0; - advancedSettingsPanelConstraints.gridy = 10; - advancedSettingsPanel.add(scriptTimeoutField, advancedSettingsPanelConstraints); - - timerContextMaxSizeLabel = new JBLabel("Timer Context Max Size"); - - timerContextMaxSizeLabel.setFont(timerContextMaxSizeLabel.getFont().deriveFont(Font.BOLD)); - // advancedSettingsPanelConstraints.gridx = 0; - // advancedSettingsPanelConstraints.gridy = 11; - // advancedSettingsPanel.add(timerContextMaxSizeLabel, - // advancedSettingsPanelConstraints); - - timerContextMaxSizeInfoLabel = new JBLabel( - "Maximum allowed value of the Timer Context Size in Bytes. Takes effect immediately."); - timerContextMaxSizeInfoLabel.setForeground(JBColor.GRAY); - // advancedSettingsPanelConstraints.gridx = 1; - // advancedSettingsPanelConstraints.gridy = 11; - // advancedSettingsPanel.add(timerContextMaxSizeInfoLabel, - // advancedSettingsPanelConstraints); - - // Add both the labels to a panel - timerContextMaxSizePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - timerContextMaxSizePanel.add(timerContextMaxSizeLabel); - timerContextMaxSizePanel.add(timerContextMaxSizeInfoLabel); - advancedSettingsPanelConstraints.gridx = 0; - advancedSettingsPanelConstraints.gridy = 11; - advancedSettingsPanel.add(timerContextMaxSizePanel, advancedSettingsPanelConstraints); - - timerContextMaxSizeField = new JBTextField(20); - timerContextMaxSizeField.setText("1024"); - timerContextMaxSizeField.setToolTipText( - "Enter the maximum allowed value of the Timer Context Size in Bytes."); - advancedSettingsPanelConstraints.gridx = 0; - advancedSettingsPanelConstraints.gridy = 12; - advancedSettingsPanel.add(timerContextMaxSizeField, advancedSettingsPanelConstraints); - } - - public JPanel getPanel() { - return advancedSettingsPanel; - } + private JPanel advancedSettingsPanel; + private JPanel systemLogLevelPanel; + private JPanel n1qlConsistencyPanel; + private JPanel workersPanel; + private JPanel languageCompatibilityPanel; + private JPanel scriptTimeoutPanel; + private JPanel timerContextMaxSizePanel; + + private JBLabel systemLogLevelLabel; + private JBLabel systemLogLevelInfoLabel; + private JBLabel applicationLogFileLabel; + private JBLabel n1qlConsistencyLabel; + private JBLabel n1qlConsistencyInfoLabel; + private JBLabel workersLabel; + private JBLabel workersInfoLabel; + private JBLabel languageCompatibilityLabel; + private JBLabel languageCompatibilityInfoLabel; + private JBLabel scriptTimeoutLabel; + private JBLabel scriptTimeoutInfoLabel; + private JBLabel timerContextMaxSizeLabel; + private JBLabel timerContextMaxSizeInfoLabel; + + private JComboBox systemLogLevelComboBox; + private JComboBox n1qlConsistencyComboBox; + private JComboBox languageCompatibilityComboBox; + + private JBTextField workersField; + private JBTextField scriptTimeoutField; + private JBTextField timerContextMaxSizeField; + + public AdvancedSettings() { + // Advanced Settings panel + advancedSettingsPanel = new JPanel(); + advancedSettingsPanel.setLayout(new GridBagLayout()); + GridBagConstraints advancedSettingsPanelConstraints = new GridBagConstraints(); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 0; + + advancedSettingsPanelConstraints.anchor = GridBagConstraints.NORTHWEST; + advancedSettingsPanelConstraints.insets = new Insets(5, 5, 5, 5); + advancedSettingsPanelConstraints.fill = GridBagConstraints.HORIZONTAL; + + // Add components to the Advanced Settings panel + systemLogLevelLabel = new JBLabel("System Log Level"); + systemLogLevelLabel.setFont(systemLogLevelLabel.getFont().deriveFont(Font.BOLD)); + // advancedSettingsPanelConstraints.gridx = 0; + // advancedSettingsPanelConstraints.gridy = 0; + // advancedSettingsPanel.add(systemLogLevelLabel, + // advancedSettingsPanelConstraints); + + systemLogLevelInfoLabel = new JBLabel("Granularity of system events being captured in the log"); + systemLogLevelInfoLabel.setForeground(JBColor.GRAY); + // advancedSettingsPanelConstraints.gridx = 1; + // advancedSettingsPanelConstraints.gridy = 0; + // advancedSettingsPanel.add(systemLogLevelInfoLabel, + // advancedSettingsPanelConstraints); + + // Add both the labels to a panel + systemLogLevelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + systemLogLevelPanel.add(systemLogLevelLabel); + systemLogLevelPanel.add(systemLogLevelInfoLabel); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 0; + advancedSettingsPanel.add(systemLogLevelPanel, advancedSettingsPanelConstraints); + + systemLogLevelComboBox = new JComboBox<>(); + systemLogLevelComboBox.addItem("Info"); + systemLogLevelComboBox.addItem("Error"); + systemLogLevelComboBox.addItem("Warning"); + systemLogLevelComboBox.addItem("Debug"); + systemLogLevelComboBox.addItem("Trace"); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 1; + advancedSettingsPanel.add(systemLogLevelComboBox, advancedSettingsPanelConstraints); + + applicationLogFileLabel = new JBLabel( + "Application log file for this Function is at:"); + + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 2; + advancedSettingsPanel.add(applicationLogFileLabel, advancedSettingsPanelConstraints); + + n1qlConsistencyLabel = new JBLabel("N1QL Consistency"); + n1qlConsistencyLabel.setFont(n1qlConsistencyLabel.getFont().deriveFont(Font.BOLD)); + // advancedSettingsPanelConstraints.gridx = 0; + // advancedSettingsPanelConstraints.gridy = 3; + // advancedSettingsPanel.add(n1qlConsistencyLabel, + // advancedSettingsPanelConstraints); + + n1qlConsistencyInfoLabel = new JBLabel("Consistency level of N1QL statements in the function"); + n1qlConsistencyInfoLabel.setForeground(JBColor.GRAY); + // advancedSettingsPanelConstraints.gridx = 1; + // advancedSettingsPanelConstraints.gridy = 3; + // advancedSettingsPanel.add(n1qlConsistencyInfoLabel, + // advancedSettingsPanelConstraints); + + // Add both the labels to a panel + n1qlConsistencyPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + n1qlConsistencyPanel.add(n1qlConsistencyLabel); + n1qlConsistencyPanel.add(n1qlConsistencyInfoLabel); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 3; + advancedSettingsPanel.add(n1qlConsistencyPanel, advancedSettingsPanelConstraints); + + n1qlConsistencyComboBox = new JComboBox<>(); + n1qlConsistencyComboBox.addItem("None"); + n1qlConsistencyComboBox.addItem("Request"); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 4; + + advancedSettingsPanel.add(n1qlConsistencyComboBox, advancedSettingsPanelConstraints); + + workersLabel = new JBLabel("Workers"); + workersLabel.setFont(workersLabel.getFont().deriveFont(Font.BOLD)); + // advancedSettingsPanelConstraints.gridx = 0; + // advancedSettingsPanelConstraints.gridy = 5; + // advancedSettingsPanel.add(workersLabel, advancedSettingsPanelConstraints); + + workersInfoLabel = new JBLabel( + "Number of workers per node to process the events. If no value is specified, a default value of 1 worker is used."); + workersInfoLabel.setForeground(JBColor.GRAY); + // advancedSettingsPanelConstraints.gridx = 1; + // advancedSettingsPanelConstraints.gridy = 5; + // advancedSettingsPanel.add(workersInfoLabel, + // advancedSettingsPanelConstraints); + + // Add both the labels to a panel + workersPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + workersPanel.add(workersLabel); + workersPanel.add(workersInfoLabel); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 5; + advancedSettingsPanel.add(workersPanel, advancedSettingsPanelConstraints); + + workersField = new JBTextField(20); + workersField.setToolTipText("Enter the number of workers per node to process the events."); + workersField.setText("1"); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 6; + advancedSettingsPanel.add(workersField, advancedSettingsPanelConstraints); + + languageCompatibilityLabel = new JBLabel("Language compatibility"); + + languageCompatibilityLabel.setFont(languageCompatibilityLabel.getFont().deriveFont(Font.BOLD)); + // advancedSettingsPanelConstraints.gridx = 0; + // advancedSettingsPanelConstraints.gridy = 7; + // advancedSettingsPanel.add(languageCompatibilityLabel, + // advancedSettingsPanelConstraints); + + languageCompatibilityInfoLabel = new JBLabel("Language compatibility of the function"); + languageCompatibilityInfoLabel.setForeground(JBColor.GRAY); + // advancedSettingsPanelConstraints.gridx = 1; + // advancedSettingsPanelConstraints.gridy = 7; + // advancedSettingsPanel.add(languageCompatibilityInfoLabel, + // advancedSettingsPanelConstraints); + + // Add both the labels to a panel + languageCompatibilityPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + languageCompatibilityPanel.add(languageCompatibilityLabel); + languageCompatibilityPanel.add(languageCompatibilityInfoLabel); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 7; + advancedSettingsPanel.add(languageCompatibilityPanel, advancedSettingsPanelConstraints); + + languageCompatibilityComboBox = new JComboBox<>(); + languageCompatibilityComboBox.addItem("6.0.0"); + languageCompatibilityComboBox.addItem("6.5.0"); + languageCompatibilityComboBox.addItem("6.6.2"); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 8; + advancedSettingsPanel.add(languageCompatibilityComboBox, advancedSettingsPanelConstraints); + + scriptTimeoutLabel = new JBLabel("Script Timeout"); + + scriptTimeoutLabel.setFont(scriptTimeoutLabel.getFont().deriveFont(Font.BOLD)); + // advancedSettingsPanelConstraints.gridx = 0; + // advancedSettingsPanelConstraints.gridy = 9; + // advancedSettingsPanel.add(scriptTimeoutLabel, + // advancedSettingsPanelConstraints); + + scriptTimeoutInfoLabel = new JBLabel( + "Time after which the Function's execution will be timed out"); + scriptTimeoutInfoLabel.setForeground(JBColor.GRAY); + // advancedSettingsPanelConstraints.gridx = 1; + // advancedSettingsPanelConstraints.gridy = 9; + // advancedSettingsPanel.add(scriptTimeoutInfoLabel, + // advancedSettingsPanelConstraints); + + // Add both the labels to a panel + scriptTimeoutPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + scriptTimeoutPanel.add(scriptTimeoutLabel); + scriptTimeoutPanel.add(scriptTimeoutInfoLabel); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 9; + advancedSettingsPanel.add(scriptTimeoutPanel, advancedSettingsPanelConstraints); + + scriptTimeoutField = new JBTextField(20); + scriptTimeoutField.setText("60"); + scriptTimeoutField.setToolTipText( + "Enter the time after which the Function's execution will be timed out."); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 10; + advancedSettingsPanel.add(scriptTimeoutField, advancedSettingsPanelConstraints); + + timerContextMaxSizeLabel = new JBLabel("Timer Context Max Size"); + + timerContextMaxSizeLabel.setFont(timerContextMaxSizeLabel.getFont().deriveFont(Font.BOLD)); + // advancedSettingsPanelConstraints.gridx = 0; + // advancedSettingsPanelConstraints.gridy = 11; + // advancedSettingsPanel.add(timerContextMaxSizeLabel, + // advancedSettingsPanelConstraints); + + timerContextMaxSizeInfoLabel = new JBLabel( + "Maximum allowed value of the Timer Context Size in Bytes. Takes effect immediately."); + timerContextMaxSizeInfoLabel.setForeground(JBColor.GRAY); + // advancedSettingsPanelConstraints.gridx = 1; + // advancedSettingsPanelConstraints.gridy = 11; + // advancedSettingsPanel.add(timerContextMaxSizeInfoLabel, + // advancedSettingsPanelConstraints); + + // Add both the labels to a panel + timerContextMaxSizePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + timerContextMaxSizePanel.add(timerContextMaxSizeLabel); + timerContextMaxSizePanel.add(timerContextMaxSizeInfoLabel); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 11; + advancedSettingsPanel.add(timerContextMaxSizePanel, advancedSettingsPanelConstraints); + + timerContextMaxSizeField = new JBTextField(20); + timerContextMaxSizeField.setText("1024"); + timerContextMaxSizeField.setToolTipText( + "Enter the maximum allowed value of the Timer Context Size in Bytes."); + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 12; + advancedSettingsPanel.add(timerContextMaxSizeField, advancedSettingsPanelConstraints); + } + + public JPanel getPanel() { + return advancedSettingsPanel; + } } \ No newline at end of file diff --git a/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java b/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java index 56099e70..7a3a9598 100644 --- a/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java @@ -11,6 +11,7 @@ // import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JPanel; +import javax.swing.JSeparator; import com.couchbase.intellij.eventing.components.CustomComboBox; import com.intellij.ui.components.JBCheckBox; @@ -20,7 +21,7 @@ public class BindingSettings { - private Integer bindingTypeCount = 0; + private Integer bindingTypeLineIndex = 0; private JPanel bindingsPanel; private JPanel bindingTypePanel; @@ -82,15 +83,13 @@ public BindingSettings() { } private void addBindingType() { - // Increment the binding type count - bindingTypeCount++; // Create a new aliasPanel to hold the binding type components bindingTypePanel = new JPanel(new GridBagLayout()); - GridBagConstraints bindingsGbc = new GridBagConstraints(); - bindingsGbc.insets = new Insets(5, 5, 5, 5); - bindingsGbc.anchor = GridBagConstraints.WEST; - bindingsGbc.fill = GridBagConstraints.HORIZONTAL; + GridBagConstraints bindingsTypeGbc = new GridBagConstraints(); + bindingsTypeGbc.insets = new Insets(5, 5, 5, 5); + bindingsTypeGbc.anchor = GridBagConstraints.WEST; + bindingsTypeGbc.fill = GridBagConstraints.HORIZONTAL; // Create the binding type dropdown menu CustomComboBox bindingTypeComboBox = new CustomComboBox(); @@ -100,9 +99,9 @@ private void addBindingType() { bindingTypeComboBox.addItem("URL Alias"); bindingTypeComboBox.addItem("Constant Alias"); - bindingsGbc.gridx = 0; - bindingsGbc.gridy = 0; - bindingTypePanel.add(bindingTypeComboBox, bindingsGbc); + bindingsTypeGbc.gridx = 0; + bindingsTypeGbc.gridy = 0; + bindingTypePanel.add(bindingTypeComboBox, bindingsTypeGbc); // Create a aliasPanel to hold the alias-specific components aliasPanel = new JPanel(new GridBagLayout()); @@ -110,10 +109,10 @@ private void addBindingType() { aliasGbc.insets = new Insets(5, 5, 5, 5); aliasGbc.anchor = GridBagConstraints.WEST; aliasGbc.fill = GridBagConstraints.HORIZONTAL; - bindingsGbc.gridx = 1; - bindingsGbc.gridy = 0; - bindingsGbc.gridwidth = 2; - bindingTypePanel.add(aliasPanel, bindingsGbc); + bindingsTypeGbc.gridx = 1; + bindingsTypeGbc.gridy = 0; + bindingsTypeGbc.gridwidth = 2; + bindingTypePanel.add(aliasPanel, bindingsTypeGbc); // Update the alias aliasPanel when the selected binding type changes bindingTypeComboBox.addItemListener(e -> { @@ -270,9 +269,9 @@ private void addBindingType() { usernameLabel.setVerticalTextPosition(JBTextField.CENTER); usernameLabel.setVisible(false); usernameLabel.setEnabled(false); - bindingsGbc.gridx = 0; - bindingsGbc.gridy = 3; - aliasPanel.add(usernameLabel, bindingsGbc); + aliasGbc.gridx = 0; + aliasGbc.gridy = 3; + aliasPanel.add(usernameLabel, aliasGbc); usernameField = new JBTextField(20); usernameField.setToolTipText( @@ -280,9 +279,9 @@ private void addBindingType() { usernameField.getEmptyText().setText("Enter the username."); usernameField.setVisible(false); usernameField.setEnabled(false); - bindingsGbc.gridx = 1; - bindingsGbc.gridy = 3; - aliasPanel.add(usernameField, bindingsGbc); + aliasGbc.gridx = 1; + aliasGbc.gridy = 3; + aliasPanel.add(usernameField, aliasGbc); // Create the password label and text field passwordLabel = new JBLabel("Password"); @@ -297,9 +296,9 @@ private void addBindingType() { passwordLabel.setVerticalTextPosition(JBTextField.CENTER); passwordLabel.setVisible(false); passwordLabel.setEnabled(false); - bindingsGbc.gridx = 0; - bindingsGbc.gridy = 4; - aliasPanel.add(passwordLabel, bindingsGbc); + aliasGbc.gridx = 0; + aliasGbc.gridy = 4; + aliasPanel.add(passwordLabel, aliasGbc); JBPasswordField passwordField = new JBPasswordField(); passwordField.setToolTipText( @@ -307,9 +306,9 @@ private void addBindingType() { passwordField.getEmptyText().setText("Enter the password."); passwordField.setVisible(false); passwordField.setEnabled(false); - bindingsGbc.gridx = 1; - bindingsGbc.gridy = 4; - aliasPanel.add(passwordField, bindingsGbc); + aliasGbc.gridx = 1; + aliasGbc.gridy = 4; + aliasPanel.add(passwordField, aliasGbc); // Create the bearer key label and text field bearerKeyLabel = new JBLabel("Bearer Key"); @@ -324,9 +323,9 @@ private void addBindingType() { bearerKeyLabel.setVerticalTextPosition(JBTextField.CENTER); bearerKeyLabel.setVisible(false); bearerKeyLabel.setEnabled(false); - bindingsGbc.gridx = 0; - bindingsGbc.gridy = 5; - aliasPanel.add(bearerKeyLabel, bindingsGbc); + aliasGbc.gridx = 0; + aliasGbc.gridy = 5; + aliasPanel.add(bearerKeyLabel, aliasGbc); bearerKeyField = new JBTextField(20); bearerKeyField.setToolTipText( @@ -334,9 +333,9 @@ private void addBindingType() { bearerKeyField.getEmptyText().setText("Enter the bearer key."); bearerKeyField.setVisible(false); bearerKeyField.setEnabled(false); - bindingsGbc.gridx = 1; - bindingsGbc.gridy = 5; - aliasPanel.add(bearerKeyField, bindingsGbc); + aliasGbc.gridx = 1; + aliasGbc.gridy = 5; + aliasPanel.add(bearerKeyField, aliasGbc); // Create the auth dropdown menu listener authComboBox.addActionListener(ee -> { @@ -419,11 +418,13 @@ private void addBindingType() { aliasGbc.gridx = 1; aliasGbc.gridy = 1; aliasPanel.add(constantValueField, aliasGbc); + } // Repaint the alias aliasPanel to show the updated components aliasPanel.revalidate(); aliasPanel.repaint(); + }); bindingTypeComboBox.setSelectedIndex(0); @@ -432,10 +433,19 @@ private void addBindingType() { bindingsPanelGbc.insets = new Insets(5, 5, 5, 5); bindingsPanelGbc.anchor = GridBagConstraints.WEST; bindingsPanelGbc.gridx = 0; - bindingsPanelGbc.gridy = bindingTypeCount; + bindingsPanelGbc.gridy = ++bindingTypeLineIndex; bindingsPanelGbc.gridwidth = 3; bindingsPanel.add(bindingTypePanel, bindingsPanelGbc); + // Add a separator to the bindings aliasPanel + JSeparator separator = new JSeparator(); + separator.setForeground(Color.GRAY); + bindingsPanelGbc.gridx = 0; + bindingsPanelGbc.gridy = ++bindingTypeLineIndex; + bindingsPanelGbc.gridwidth = 3; + bindingsPanelGbc.fill = GridBagConstraints.HORIZONTAL; + bindingsPanel.add(separator, bindingsPanelGbc); + // Repaint the bindings aliasPanel to show the new binding type bindingsPanel.revalidate(); bindingsPanel.repaint(); @@ -443,12 +453,15 @@ private void addBindingType() { private void removeBindingType() { // Get the number of binding types - int bindingTypeCount = bindingsPanel.getComponentCount(); + int bindingTypeLineIndex = bindingsPanel.getComponentCount(); // Check if there are any binding types to remove - if (bindingTypeCount > 0) { + if (bindingTypeLineIndex >= 2) { + // Remove the last horizontal separator + bindingsPanel.remove(bindingTypeLineIndex - 1); + // Remove the last binding type aliasPanel - bindingsPanel.remove(bindingTypeCount - 1); + bindingsPanel.remove(bindingTypeLineIndex - 2); // Repaint the bindings aliasPanel to show the removed binding type bindingsPanel.revalidate(); From 9b4e2adfb52dc27e8db312f353998fbdb5e2b73f Mon Sep 17 00:00:00 2001 From: teetangh Date: Mon, 12 Jun 2023 22:04:19 +0530 Subject: [PATCH 07/15] fixed background color issue of left scroll pane. --- .../eventing/FunctionDeploymentSettings.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java index 2d3e7749..5923e8fc 100644 --- a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java @@ -30,7 +30,6 @@ import com.couchbase.intellij.eventing.settings.AdvancedSettings; import com.couchbase.intellij.eventing.settings.BindingSettings; import com.couchbase.intellij.eventing.settings.GeneralSettings; -import com.intellij.ui.JBColor; import com.intellij.ui.JBSplitter; import com.intellij.ui.components.JBLabel; import com.intellij.ui.components.JBScrollPane; @@ -62,7 +61,6 @@ public FunctionDeploymentSettings() { // Create and configure the main panel mainPanel = new JPanel(); mainPanel.setLayout(new BorderLayout()); - // JScrollPane scrollPane = new JScrollPane(mainPanel); setContentPane(mainPanel); // Create and configure the left panel @@ -70,19 +68,19 @@ public FunctionDeploymentSettings() { leftPanel.setLayout(new BorderLayout()); leftPanel.setPreferredSize(new Dimension(400, 800)); // leftPanel.setForeground(JBColor.BLACK); - leftPanel.setBackground(Color.BLACK); + leftPanel.setBackground(new Color(62, 67, 76, 255)); // Jetbrains Darcula background color // Add components to the left panel titleLabel = new JBLabel("Project Structure"); - titleLabel.setHorizontalAlignment(SwingConstants.CENTER); + titleLabel.setHorizontalAlignment(SwingConstants.LEFT); titleLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - titleLabel.setBackground(Color.BLACK); leftPanel.add(titleLabel, BorderLayout.NORTH); String[] settings = { "General Settings", "Advanced Settings", "Binding Type" }; JList settingsList = new JList<>(settings); settingsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); settingsList.setSelectedIndex(0); + settingsList.setBackground(new Color(62, 67, 76, 255)); // Jetbrains Darcula background color settingsList.setCellRenderer(new DefaultListCellRenderer() { @Override @@ -92,10 +90,11 @@ public Component getListCellRendererComponent(JList list, Object value, int i setHorizontalAlignment(SwingConstants.LEFT); setForeground(Color.WHITE); if (isSelected) { - setBackground(new Color(98, 181, 229)); + setBackground(new Color(98, 181, 229)); // Jetbrains Darcula selection color } else { - setBackground(Color.BLACK); + setBackground(new Color(62, 67, 76, 255)); // Jetbrains Darcula background color } + setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0)); // Add left padding return this; } }); @@ -110,7 +109,6 @@ public Component getListCellRendererComponent(JList list, Object value, int i JBScrollPane leftScrollPane = new JBScrollPane(settingsList); leftScrollPane.setBorder(BorderFactory.createEmptyBorder()); - leftScrollPane.setBackground(JBColor.BLACK); leftPanel.add(leftScrollPane, BorderLayout.CENTER); // Create and configure the right panel @@ -154,11 +152,14 @@ public Component getListCellRendererComponent(JList list, Object value, int i }); bottomPanel.add(cancelButton); - // Add the panels to the main panel + // Add the panels to the main panel with a splitter in the middle JBSplitter splitter = new JBSplitter(false); splitter.setFirstComponent(leftPanel); splitter.setSecondComponent(rightPanel); + splitter.setDividerWidth(1); + splitter.getDivider().setBackground(new Color(62, 67, 76, 255)); mainPanel.add(splitter, BorderLayout.CENTER); + mainPanel.add(bottomPanel, BorderLayout.SOUTH); // Add a window listener to handle unsaved changes From 7ae3c7bd6d9bdc366d3aa777f3f4ca726057cb53 Mon Sep 17 00:00:00 2001 From: teetangh Date: Wed, 14 Jun 2023 12:32:12 +0530 Subject: [PATCH 08/15] fixed card layout for the right panel + added delete functionality for each binding --- .../eventing/FunctionDeploymentSettings.java | 36 ++++----- .../eventing/settings/BindingSettings.java | 74 ++++++++++++++++++- .../eventing/settings/GeneralSettings.java | 2 + 3 files changed, 91 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java index 5923e8fc..e0ba3ce1 100644 --- a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java @@ -19,6 +19,7 @@ import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JScrollPane; // import javax.swing.JScrollPane; // import javax.swing.JTextArea; // import javax.swing.JTextField; @@ -48,14 +49,14 @@ public class FunctionDeploymentSettings extends JFrame { private JButton applyButton; private JButton cancelButton; - private CardLayout cardLayout; private Map changedSettings; public FunctionDeploymentSettings() { // Set up the main frame setTitle("Project Structure"); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - setSize(1000, 800); + // setSize(1000, 800); + setMinimumSize(new Dimension(1000, 800)); setLocationRelativeTo(null); // Create and configure the main panel @@ -98,40 +99,39 @@ public Component getListCellRendererComponent(JList list, Object value, int i return this; } }); - - settingsList.addListSelectionListener(e -> { - if (!e.getValueIsAdjusting()) { - String selectedValue = settingsList.getSelectedValue(); - CardLayout cardLayout = (CardLayout) rightPanel.getLayout(); - cardLayout.show(rightPanel, selectedValue); - } - }); - JBScrollPane leftScrollPane = new JBScrollPane(settingsList); leftScrollPane.setBorder(BorderFactory.createEmptyBorder()); leftPanel.add(leftScrollPane, BorderLayout.CENTER); // Create and configure the right panel - rightPanel = new JPanel(); - cardLayout = new CardLayout(); - rightPanel.setLayout(cardLayout); + rightPanel = new JPanel(new CardLayout()); // Add components to the right panel GeneralSettings generalSettings = new GeneralSettings(); generalSettingsPanel = generalSettings.getPanel(); + JPanel generalSettingsWrapper = new JPanel(new BorderLayout()); + generalSettingsWrapper.add(generalSettingsPanel, BorderLayout.NORTH); + rightPanel.add(generalSettingsWrapper, "General Settings"); // Advanced Settings panel AdvancedSettings advancedSettings = new AdvancedSettings(); advancedSettingsPanel = advancedSettings.getPanel(); + JPanel advancedSettingsWrapper = new JPanel(new BorderLayout()); + advancedSettingsWrapper.add(advancedSettingsPanel, BorderLayout.NORTH); + rightPanel.add(advancedSettingsWrapper, "Advanced Settings"); // Binding Type panel BindingSettings bindingSettings = new BindingSettings(); bindingsPanel = bindingSettings.getPanel(); + rightPanel.add(new JScrollPane(bindingsPanel), "Binding Type"); // No need to wrap this panel - // Add the panels to the right panel - rightPanel.add(generalSettingsPanel, "General Settings"); - rightPanel.add(advancedSettingsPanel, "Advanced Settings"); - rightPanel.add(new JBScrollPane(bindingsPanel), "Binding Type"); + settingsList.addListSelectionListener(e -> { + if (!e.getValueIsAdjusting()) { + String selectedValue = settingsList.getSelectedValue(); + CardLayout cardLayout = (CardLayout) rightPanel.getLayout(); + cardLayout.show(rightPanel, selectedValue); + } + }); // Create and configure the bottom panel bottomPanel = new JPanel(); diff --git a/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java b/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java index 7a3a9598..a47e2048 100644 --- a/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java @@ -6,6 +6,10 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import javax.swing.JButton; // import javax.swing.JCheckBox; @@ -24,7 +28,7 @@ public class BindingSettings { private Integer bindingTypeLineIndex = 0; private JPanel bindingsPanel; - private JPanel bindingTypePanel; + // private JPanel bindingTypePanel; private JPanel aliasPanel; private JPanel bucketPanel; @@ -52,6 +56,9 @@ public class BindingSettings { private JBTextField constantAliasNameField; private JBTextField constantValueField; + private Map separatorMap = new HashMap<>(); + private List bindingTypePanels = new ArrayList<>(); + // Constructor public BindingSettings() { // Binding Type panel @@ -85,7 +92,7 @@ public BindingSettings() { private void addBindingType() { // Create a new aliasPanel to hold the binding type components - bindingTypePanel = new JPanel(new GridBagLayout()); + final JPanel bindingTypePanel = new JPanel(new GridBagLayout()); GridBagConstraints bindingsTypeGbc = new GridBagConstraints(); bindingsTypeGbc.insets = new Insets(5, 5, 5, 5); bindingsTypeGbc.anchor = GridBagConstraints.WEST; @@ -103,13 +110,38 @@ private void addBindingType() { bindingsTypeGbc.gridy = 0; bindingTypePanel.add(bindingTypeComboBox, bindingsTypeGbc); + // Create a delete button + JButton deleteButton = new JButton("Delete"); + deleteButton.addActionListener(e -> { + // Remove the binding type panel and its associated separator + JSeparator separator = separatorMap.get(bindingTypePanel); + if (separator != null) { + bindingsPanel.remove(separator); + separatorMap.remove(bindingTypePanel); + } + bindingsPanel.remove(bindingTypePanel); + + // Remove the binding type panel from the bindingTypePanels list + bindingTypePanels.remove(bindingTypePanel); + + // Rebuild the bindings panel + rebuildBindingsPanel(); + + // Repaint the bindings panel to show the removed binding type + bindingsPanel.revalidate(); + bindingsPanel.repaint(); + }); + bindingsTypeGbc.gridx = 1; + bindingsTypeGbc.gridy = 0; + bindingTypePanel.add(deleteButton, bindingsTypeGbc); + // Create a aliasPanel to hold the alias-specific components aliasPanel = new JPanel(new GridBagLayout()); GridBagConstraints aliasGbc = new GridBagConstraints(); aliasGbc.insets = new Insets(5, 5, 5, 5); aliasGbc.anchor = GridBagConstraints.WEST; aliasGbc.fill = GridBagConstraints.HORIZONTAL; - bindingsTypeGbc.gridx = 1; + bindingsTypeGbc.gridx = 2; bindingsTypeGbc.gridy = 0; bindingsTypeGbc.gridwidth = 2; bindingTypePanel.add(aliasPanel, bindingsTypeGbc); @@ -446,6 +478,12 @@ private void addBindingType() { bindingsPanelGbc.fill = GridBagConstraints.HORIZONTAL; bindingsPanel.add(separator, bindingsPanelGbc); + // Add the binding type panel to the bindingTypePanels list + bindingTypePanels.add(bindingTypePanel); + + // Store a reference to the separator in the separatorMap + separatorMap.put(bindingTypePanel, separator); + // Repaint the bindings aliasPanel to show the new binding type bindingsPanel.revalidate(); bindingsPanel.repaint(); @@ -469,6 +507,36 @@ private void removeBindingType() { } } + private void rebuildBindingsPanel() { + // Remove all components from the bindings panel except for the first row + for (int i = bindingsPanel.getComponentCount() - 1; i >= 3; i--) { + bindingsPanel.remove(i); + } + + // Reset the binding type line index + bindingTypeLineIndex = 0; + + // Add all remaining binding type panels to the bindings panel + for (JPanel bindingTypePanel : bindingTypePanels) { + GridBagConstraints bindingsPanelGbc = new GridBagConstraints(); + bindingsPanelGbc.insets = new Insets(5, 5, 5, 5); + bindingsPanelGbc.anchor = GridBagConstraints.WEST; + bindingsPanelGbc.gridx = 0; + bindingsPanelGbc.gridy = ++bindingTypeLineIndex; + bindingsPanelGbc.gridwidth = 3; + bindingsPanel.add(bindingTypePanel, bindingsPanelGbc); + + JSeparator separator = separatorMap.get(bindingTypePanel); + if (separator != null) { + bindingsPanelGbc.gridx = 0; + bindingsPanelGbc.gridy = ++bindingTypeLineIndex; + bindingsPanelGbc.gridwidth = 3; + bindingsPanelGbc.fill = GridBagConstraints.HORIZONTAL; + bindingsPanel.add(separator, bindingsPanelGbc); + } + } + } + // Getters and setters public JPanel getPanel() { return bindingsPanel; diff --git a/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java b/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java index a3a4f800..c4eb310f 100644 --- a/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java @@ -1,5 +1,6 @@ package com.couchbase.intellij.eventing.settings; +import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.GridBagConstraints; @@ -267,6 +268,7 @@ public GeneralSettings() { descriptionTextArea.setLineWrap(true); descriptionTextArea.setWrapStyleWord(true); descriptionTextArea.setToolTipText("Enter a description for the function (optional)."); + descriptionTextArea.setPreferredSize(new Dimension(200, 100)); descriptionLabel.setLabelFor(descriptionTextArea); JBScrollPane descriptionScrollPane = new JBScrollPane(descriptionTextArea); generalSettingsPanelConstraints.gridx = 0; From 1bd67449e26c51872e89b23ce11325bdf641424b Mon Sep 17 00:00:00 2001 From: Kaustav Ghosh <44238657+teetangh@users.noreply.github.com> Date: Wed, 14 Jun 2023 12:38:55 +0530 Subject: [PATCH 09/15] Delete Run IDE with Plugin.run.xml --- .run/Run IDE with Plugin.run.xml | 44 ++++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/.run/Run IDE with Plugin.run.xml b/.run/Run IDE with Plugin.run.xml index 7747a294..390c7532 100644 --- a/.run/Run IDE with Plugin.run.xml +++ b/.run/Run IDE with Plugin.run.xml @@ -1,24 +1,24 @@ - - - - - - - true - true - false - - + + + + + + + true + true + false + + \ No newline at end of file From d2828f2ff10d6616b5ed9104babc16736e51af28 Mon Sep 17 00:00:00 2001 From: teetangh Date: Wed, 14 Jun 2023 13:36:49 +0530 Subject: [PATCH 10/15] Added action listeners to the combo boxes --- .../eventing/FunctionDeploymentDialog.java | 25 --- .../eventing/settings/GeneralSettings.java | 197 +++++++++++++++++- 2 files changed, 195 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentDialog.java b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentDialog.java index 8780755a..df34db8d 100644 --- a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentDialog.java +++ b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentDialog.java @@ -108,29 +108,4 @@ public void mouseClicked(MouseEvent e) { } - // private void updateScopes() { - // // Get selected bucket - // String selectedBucket = (String) bucketComboBox.getSelectedItem(); - - // // TODO: Get scopes for selected bucket and update scopeComboBox - // // You can use the Couchbase Java SDK to get the list of scopes for the - // selected - // // bucket - // // For example: - // // List scopes = - // // cluster.bucket(selectedBucket).collections().getAllScopes(); - // // Then you can update the scopeComboBox with the list of scopes - - // // Enable scope combo box - // scopeComboBox.setEnabled(true); - // } - - // public String getSelectedBucket() { - // return (String) bucketComboBox.getSelectedItem(); - // } - - // public String getSelectedScope() { - // return (String) scopeComboBox.getSelectedItem(); - // } - } diff --git a/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java b/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java index c4eb310f..47b7ac40 100644 --- a/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java @@ -6,10 +6,20 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; import javax.swing.JComboBox; import javax.swing.JPanel; +import com.couchbase.client.java.Bucket; +import com.couchbase.client.java.Cluster; +import com.couchbase.client.java.manager.bucket.BucketSettings; +import com.couchbase.client.java.manager.collection.CollectionManager; +import com.couchbase.client.java.manager.collection.CollectionSpec; +import com.couchbase.client.java.manager.collection.ScopeSpec; +import com.couchbase.intellij.database.ActiveCluster; import com.intellij.ui.JBColor; import com.intellij.ui.components.JBLabel; import com.intellij.ui.components.JBScrollPane; @@ -48,6 +58,10 @@ public class GeneralSettings { private JComboBox deploymentFeedBoundaryComboBox; public GeneralSettings() { + + // Connect to the Couchbase cluster + Cluster cluster = Cluster.connect("couchbase://localhost", "kaustav", "password"); + generalSettingsPanel = new JPanel(); generalSettingsPanel.setLayout(new GridBagLayout()); @@ -86,9 +100,7 @@ public GeneralSettings() { generalSettingsPanelConstraints.gridx = 1; generalSettingsPanelConstraints.gridy = 1; generalSettingsPanel.add(functionScopeScopeComboBox, generalSettingsPanelConstraints); - // Function Scope error label - helpLabel1 = new JBLabel( "Please specify a scope to which the function belongs. User should have Eventing Manage Scope Functions permission on this scope"); helpLabel1.setForeground(JBColor.GRAY); @@ -276,6 +288,187 @@ public GeneralSettings() { generalSettingsPanelConstraints.fill = GridBagConstraints.BOTH; generalSettingsPanel.add(descriptionScrollPane, generalSettingsPanelConstraints); + // Adding all the event listeners + // Get the list of buckets in the cluster + Map buckets = cluster.buckets().getAllBuckets(); + + // Populate the bucket combo boxes + functionScopeBucketComboBox.addItem("*"); + listenToLocationBucketComboBox.addItem("*"); + eventingStorageBucketComboBox.addItem("*"); + for (String bucketName : buckets.keySet()) { + functionScopeBucketComboBox.addItem(bucketName); + listenToLocationBucketComboBox.addItem(bucketName); + eventingStorageBucketComboBox.addItem(bucketName); + } + + // Add action listeners to the bucket combo boxes + functionScopeBucketComboBox.addActionListener(e -> { + // Get the selected bucket + String selectedBucket = (String) functionScopeBucketComboBox.getSelectedItem(); + + // Clear and repopulate the functionScopeScopeComboBox + functionScopeScopeComboBox.removeAllItems(); + if (selectedBucket != null && !selectedBucket.equals("*")) { + // Get the list of scopes for the selected bucket + List scopes = cluster.bucket(selectedBucket).collections().getAllScopes(); + + functionScopeScopeComboBox.addItem("*"); + for (ScopeSpec scope : scopes) { + functionScopeScopeComboBox.addItem(scope.name()); + } + + // Enable the functionScopeScopeComboBox + functionScopeScopeComboBox.setEnabled(true); + } else { + // Disable the functionScopeScopeComboBox + functionScopeScopeComboBox.setEnabled(false); + } + }); + listenToLocationBucketComboBox.addActionListener(e -> { + // Get the selected bucket + String selectedBucket = (String) listenToLocationBucketComboBox.getSelectedItem(); + + // Clear and repopulate the listenToLocationScopeComboBox + listenToLocationScopeComboBox.removeAllItems(); + if (selectedBucket != null && !selectedBucket.equals("*")) { + // Get the list of scopes for the selected bucket + List scopes = cluster.bucket(selectedBucket).collections().getAllScopes(); + + listenToLocationScopeComboBox.addItem("*"); + for (ScopeSpec scope : scopes) { + listenToLocationScopeComboBox.addItem(scope.name()); + } + + // Enable the listenToLocationScopeComboBox + listenToLocationScopeComboBox.setEnabled(true); + } else { + // Disable the listenToLocationScopeComboBox + listenToLocationScopeComboBox.setEnabled(false); + } + }); + eventingStorageBucketComboBox.addActionListener(e -> { + // Get the selected bucket + String selectedBucket = (String) eventingStorageBucketComboBox.getSelectedItem(); + + // Clear and repopulate the eventingStorageScopeComboBox + eventingStorageScopeComboBox.removeAllItems(); + if (selectedBucket != null && !selectedBucket.equals("*")) { + // Get the list of scopes for the selected bucket + List scopes = cluster.bucket(selectedBucket).collections().getAllScopes(); + + eventingStorageScopeComboBox.addItem("*"); + for (ScopeSpec scope : scopes) { + eventingStorageScopeComboBox.addItem(scope.name()); + } + + // Enable the eventingStorageScopeComboBox + eventingStorageScopeComboBox.setEnabled(true); + } else { + // Disable the eventingStorageScopeComboBox + eventingStorageScopeComboBox.setEnabled(false); + } + }); + + listenToLocationScopeComboBox.addActionListener(e -> { + // Get the selected bucket and scope + String selectedBucket = (String) listenToLocationBucketComboBox.getSelectedItem(); + String selectedScope = (String) listenToLocationScopeComboBox.getSelectedItem(); + + // Clear and repopulate the listenToLocationCollectionComboBox + listenToLocationCollectionComboBox.removeAllItems(); + if (selectedBucket != null && !selectedBucket.equals("*") && selectedScope != null + && !selectedScope.equals("*")) { + // Get the list of collections for the selected scope + Cluster activeCluster = ActiveCluster.getInstance().get(); + if (activeCluster != null) { + Bucket bucket = activeCluster.bucket(selectedBucket); + if (bucket != null) { + CollectionManager collectionManager = bucket.collections(); + if (collectionManager != null) { + List scopes = collectionManager.getAllScopes(); + if (scopes != null) { + List collections = scopes.stream() + .filter(scope -> scope.name().equals(selectedScope)) + .flatMap(scope -> scope.collections().stream()) + .collect(Collectors.toList()); + + listenToLocationCollectionComboBox.addItem("*"); + for (CollectionSpec collection : collections) { + listenToLocationCollectionComboBox.addItem(collection.name()); + } + } + } + } + } + + // Enable the listenToLocationCollectionComboBox + listenToLocationCollectionComboBox.setEnabled(true); + } else { + // Disable the listenToLocationCollectionComboBox + listenToLocationCollectionComboBox.setEnabled(false); + } + }); + eventingStorageScopeComboBox.addActionListener(e -> { + // Get the selected bucket and scope + String selectedBucket = (String) eventingStorageBucketComboBox.getSelectedItem(); + String selectedScope = (String) eventingStorageScopeComboBox.getSelectedItem(); + + // Clear and repopulate the eventingStorageCollectionComboBox + eventingStorageCollectionComboBox.removeAllItems(); + if (selectedBucket != null && !selectedBucket.equals("*") && selectedScope != null + && !selectedScope.equals("*")) { + // Get the list of collections for the selected scope + Cluster activeCluster = ActiveCluster.getInstance().get(); + if (activeCluster != null) { + Bucket bucket = activeCluster.bucket(selectedBucket); + if (bucket != null) { + CollectionManager collectionManager = bucket.collections(); + if (collectionManager != null) { + List scopes = collectionManager.getAllScopes(); + if (scopes != null) { + List collections = scopes.stream() + .filter(scope -> scope.name().equals(selectedScope)) + .flatMap(scope -> scope.collections().stream()) + .collect(Collectors.toList()); + + eventingStorageCollectionComboBox.addItem("*"); + for (CollectionSpec collection : collections) { + eventingStorageCollectionComboBox.addItem(collection.name()); + } + } + } + } + } + + // Enable the eventingStorageCollectionComboBox + eventingStorageCollectionComboBox.setEnabled(true); + } else { + // Disable the eventingStorageCollectionComboBox + eventingStorageCollectionComboBox.setEnabled(false); + } + }); + + listenToLocationCollectionComboBox.addActionListener(e -> { + // Get the selected bucket, scope, and collection + String selectedBucket = (String) listenToLocationBucketComboBox.getSelectedItem(); + String selectedScope = (String) listenToLocationScopeComboBox.getSelectedItem(); + String selectedCollection = (String) listenToLocationCollectionComboBox.getSelectedItem(); + + // Perform any necessary actions when the selected collection changes + // ... + + }); + eventingStorageCollectionComboBox.addActionListener(e -> { + // Get the selected bucket, scope, and collection + String selectedBucket = (String) eventingStorageBucketComboBox.getSelectedItem(); + String selectedScope = (String) eventingStorageScopeComboBox.getSelectedItem(); + String selectedCollection = (String) eventingStorageCollectionComboBox.getSelectedItem(); + + // Perform any necessary actions when the selected collection changes + // ... + }); + } public JPanel getPanel() { From c2d7b104667b9366e9fd62f9499571f3310329b6 Mon Sep 17 00:00:00 2001 From: teetangh Date: Mon, 19 Jun 2023 05:54:13 +0530 Subject: [PATCH 11/15] Fixed the binding settings UI --- .../eventing/FunctionDeploymentSettings.java | 34 +++-- .../eventing/settings/BindingSettings.java | 136 ++++++++++-------- 2 files changed, 92 insertions(+), 78 deletions(-) diff --git a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java index e0ba3ce1..b9225b73 100644 --- a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java @@ -53,7 +53,7 @@ public class FunctionDeploymentSettings extends JFrame { public FunctionDeploymentSettings() { // Set up the main frame - setTitle("Project Structure"); + setTitle("Function Configuration"); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // setSize(1000, 800); setMinimumSize(new Dimension(1000, 800)); @@ -72,12 +72,16 @@ public FunctionDeploymentSettings() { leftPanel.setBackground(new Color(62, 67, 76, 255)); // Jetbrains Darcula background color // Add components to the left panel - titleLabel = new JBLabel("Project Structure"); + titleLabel = new JBLabel("Function Configuration"); titleLabel.setHorizontalAlignment(SwingConstants.LEFT); titleLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); leftPanel.add(titleLabel, BorderLayout.NORTH); - String[] settings = { "General Settings", "Advanced Settings", "Binding Type" }; + String[] settings = { + "General", // General settings + "Settings", // Advanced settings + "Binding Types" // Binding settings + }; JList settingsList = new JList<>(settings); settingsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); settingsList.setSelectedIndex(0); @@ -111,19 +115,19 @@ public Component getListCellRendererComponent(JList list, Object value, int i generalSettingsPanel = generalSettings.getPanel(); JPanel generalSettingsWrapper = new JPanel(new BorderLayout()); generalSettingsWrapper.add(generalSettingsPanel, BorderLayout.NORTH); - rightPanel.add(generalSettingsWrapper, "General Settings"); + rightPanel.add(generalSettingsWrapper, "General"); - // Advanced Settings panel + // Settings panel AdvancedSettings advancedSettings = new AdvancedSettings(); advancedSettingsPanel = advancedSettings.getPanel(); JPanel advancedSettingsWrapper = new JPanel(new BorderLayout()); advancedSettingsWrapper.add(advancedSettingsPanel, BorderLayout.NORTH); - rightPanel.add(advancedSettingsWrapper, "Advanced Settings"); + rightPanel.add(advancedSettingsWrapper, "Settings"); - // Binding Type panel + // Binding Types panel BindingSettings bindingSettings = new BindingSettings(); bindingsPanel = bindingSettings.getPanel(); - rightPanel.add(new JScrollPane(bindingsPanel), "Binding Type"); // No need to wrap this panel + rightPanel.add(new JScrollPane(bindingsPanel), "Binding Types"); // No need to wrap this panel settingsList.addListSelectionListener(e -> { if (!e.getValueIsAdjusting()) { @@ -186,31 +190,31 @@ public void windowClosing(WindowEvent e) { // Initialize the changed settings map changedSettings = new HashMap<>(); - changedSettings.put("General Settings", false); - changedSettings.put("Advanced Settings", false); - changedSettings.put("Binding Type", false); + changedSettings.put("General", false); + changedSettings.put("Settings", false); + changedSettings.put("Binding Types", false); // Add document listeners to track changes DocumentListener documentListener = new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { - changedSettings.put("General Settings", true); + changedSettings.put("General", true); } @Override public void removeUpdate(DocumentEvent e) { - changedSettings.put("General Settings", true); + changedSettings.put("General", true); } @Override public void changedUpdate(DocumentEvent e) { - changedSettings.put("General Settings", true); + changedSettings.put("General", true); } }; // functionNameField.getDocument().addDocumentListener(documentListener); // descriptionTextArea.getDocument().addDocumentListener(documentListener); - // ActionListener actionListener = e -> changedSettings.put("General Settings", + // ActionListener actionListener = e -> changedSettings.put("General", // true); // deploymentFeedBoundaryComboBox.addActionListener(actionListener); diff --git a/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java b/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java index a47e2048..280bbfd9 100644 --- a/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java @@ -1,6 +1,8 @@ package com.couchbase.intellij.eventing.settings; import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.GridBagConstraints; @@ -11,9 +13,12 @@ import java.util.List; import java.util.Map; +import javax.swing.DefaultListCellRenderer; import javax.swing.JButton; // import javax.swing.JCheckBox; import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JSeparator; @@ -28,20 +33,8 @@ public class BindingSettings { private Integer bindingTypeLineIndex = 0; private JPanel bindingsPanel; - // private JPanel bindingTypePanel; - private JPanel aliasPanel; - private JPanel bucketPanel; private JBLabel bindingTypeLabel; - private JBLabel bucketLabel; - private JBLabel bucketInfoLabel; - private JBLabel accessLabel; - private JBLabel authenticationLabel; - private JBLabel usernameLabel; - private JBLabel passwordLabel; - private JBLabel bearerKeyLabel; - private JBLabel constantAliasNameLabel; - private JBLabel constantValueLabel; private JComboBox bucketComboBox; private JComboBox scopeComboBox; @@ -59,6 +52,9 @@ public class BindingSettings { private Map separatorMap = new HashMap<>(); private List bindingTypePanels = new ArrayList<>(); + // Keep track of all the aliasPanels + private List aliasPanels = new ArrayList<>(); + // Constructor public BindingSettings() { // Binding Type panel @@ -131,21 +127,52 @@ private void addBindingType() { bindingsPanel.revalidate(); bindingsPanel.repaint(); }); - bindingsTypeGbc.gridx = 1; + bindingsTypeGbc.gridx = 4; // because of the wide alias panel bindingsTypeGbc.gridy = 0; + bindingsTypeGbc.anchor = GridBagConstraints.NORTHWEST; bindingTypePanel.add(deleteButton, bindingsTypeGbc); + deleteButton.setVisible(false); // initially hide the delete button // Create a aliasPanel to hold the alias-specific components - aliasPanel = new JPanel(new GridBagLayout()); + JPanel aliasPanel = new JPanel(new GridBagLayout()); GridBagConstraints aliasGbc = new GridBagConstraints(); aliasGbc.insets = new Insets(5, 5, 5, 5); aliasGbc.anchor = GridBagConstraints.WEST; - aliasGbc.fill = GridBagConstraints.HORIZONTAL; - bindingsTypeGbc.gridx = 2; + aliasGbc.fill = GridBagConstraints.BOTH; + + bindingsTypeGbc.gridx = 1; bindingsTypeGbc.gridy = 0; - bindingsTypeGbc.gridwidth = 2; + bindingsTypeGbc.gridwidth = 1; // initially set to 1, will set to 3 when a binding type is selected + bindingsTypeGbc.gridheight = 2; bindingTypePanel.add(aliasPanel, bindingsTypeGbc); + // Add the aliasPanel to the list of aliasPanels + aliasPanels.add(aliasPanel); + + // Set a custom renderer for the bindingTypeComboBox + bindingTypeComboBox.setRenderer(new DefaultListCellRenderer() { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, + boolean isSelected, boolean cellHasFocus) { + JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, + cellHasFocus); + + if ("Choose Binding Type".equals(value)) { + label.setEnabled(false); + bindingsTypeGbc.gridwidth = 1; // set a smaller gridwidth value when nothing is selected + deleteButton.setVisible(false); + deleteButton.setEnabled(false); + } else { + label.setEnabled(true); + bindingsTypeGbc.gridwidth = 3; + deleteButton.setVisible(true); + deleteButton.setEnabled(true); + } + + return label; + } + }); + // Update the alias aliasPanel when the selected binding type changes bindingTypeComboBox.addItemListener(e -> { // Remove all components from the alias aliasPanel @@ -154,6 +181,15 @@ private void addBindingType() { // Get the selected binding type String selectedBindingType = (String) bindingTypeComboBox.getSelectedItem(); + // Show or hide the delete button based on the selected item + if (!selectedBindingType.equals("Choose Binding Type")) { + deleteButton.setVisible(true); // show the delete button + deleteButton.setEnabled(true); // enable the delete button + } else { + deleteButton.setVisible(false); // hide the delete button + deleteButton.setEnabled(false); // disable the delete button + } + if (selectedBindingType.equals("Bucket Alias")) { // Create the alias name text field bucketAliasNameField = new JBTextField(20); @@ -165,22 +201,13 @@ private void addBindingType() { aliasPanel.add(bucketAliasNameField, aliasGbc); // Create the bucket label - bucketLabel = new JBLabel("Bucket"); + JBLabel bucketLabel = new JBLabel("Bucket"); bucketLabel.setFont(bucketLabel.getFont().deriveFont(Font.BOLD)); - // aliasGbc.gridx = 0; - // aliasGbc.gridy = 1; - // aliasGbc.gridwidth = 1; - // aliasPanel.add(bucketLabel, aliasGbc); - // Create the bucket info label - bucketInfoLabel = new JBLabel("bucket.scope.collection"); + JBLabel bucketInfoLabel = new JBLabel("bucket.scope.collection"); bucketInfoLabel.setForeground(Color.GRAY); - // aliasGbc.gridx = 1; - // aliasGbc.gridy = 1; - // aliasPanel.add(bucketInfoLabel, aliasGbc); - // Add both labels to a flow layout panel - bucketPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + JPanel bucketPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); bucketPanel.add(bucketLabel); bucketPanel.add(bucketInfoLabel); aliasGbc.gridx = 0; @@ -188,38 +215,30 @@ private void addBindingType() { aliasGbc.gridwidth = 3; aliasPanel.add(bucketPanel, aliasGbc); - // Create the access label - accessLabel = new JBLabel("Access"); + JBLabel accessLabel = new JBLabel("Access"); accessLabel.setFont(accessLabel.getFont().deriveFont(Font.BOLD)); aliasGbc.gridx = 3; aliasGbc.gridy = 1; aliasGbc.gridwidth = 1; aliasPanel.add(accessLabel, aliasGbc); - // Create the bucket dropdown menu bucketComboBox = new JComboBox<>(); - // TODO: Populate the bucketComboBox with available buckets aliasGbc.gridx = 0; aliasGbc.gridy = 2; aliasPanel.add(bucketComboBox, aliasGbc); - // Create the scope dropdown menu scopeComboBox = new JComboBox<>(); scopeComboBox.setEnabled(false); - // TODO: Update the scopeComboBox when the selected bucket changes aliasGbc.gridx = 1; aliasGbc.gridy = 2; aliasPanel.add(scopeComboBox, aliasGbc); - // Create the collection dropdown menu collectionComboBox = new JComboBox<>(); collectionComboBox.setEnabled(false); - // TODO: Update the collectionComboBox when the selected scope changes aliasGbc.gridx = 2; aliasGbc.gridy = 2; aliasPanel.add(collectionComboBox, aliasGbc); - // Create access dropdown menu accessComboBox = new JComboBox<>(); accessComboBox.addItem("Read Only"); accessComboBox.addItem("Read and Write"); @@ -230,8 +249,9 @@ private void addBindingType() { aliasGbc.gridy = 2; aliasPanel.add(accessComboBox, aliasGbc); + aliasPanel.setPreferredSize(new Dimension(500, 120)); + } else if (selectedBindingType.equals("URL Alias")) { - // Create the alias name text field urlAliasNameField = new JBTextField(20); urlAliasNameField.setToolTipText("Enter the alias name."); urlAliasNameField.getEmptyText().setText("Enter the alias name."); @@ -239,7 +259,6 @@ private void addBindingType() { aliasGbc.gridy = 0; aliasPanel.add(urlAliasNameField, aliasGbc); - // Create the URL text field urlField = new JBTextField(20); urlField.setToolTipText("Enter the URL."); urlField.getEmptyText().setText("Enter the URL."); @@ -247,22 +266,19 @@ private void addBindingType() { aliasGbc.gridy = 0; aliasPanel.add(urlField, aliasGbc); - // Create the allow cookies checkbox JBCheckBox allowCookiesCheckBox = new JBCheckBox("Allow cookies"); allowCookiesCheckBox.setToolTipText("Allow cookies for this URL."); aliasGbc.gridx = 0; aliasGbc.gridy = 1; aliasPanel.add(allowCookiesCheckBox, aliasGbc); - // Create the validate SSL certificate checkbox JBCheckBox validateSslCertificateCheckBox = new JBCheckBox("Validate SSL certificate"); validateSslCertificateCheckBox.setToolTipText("Validate SSL certificate for this URL."); aliasGbc.gridx = 1; aliasGbc.gridy = 1; aliasPanel.add(validateSslCertificateCheckBox, aliasGbc); - // Create the authentication label - authenticationLabel = new JBLabel("Authentication"); + JBLabel authenticationLabel = new JBLabel("Authentication"); authenticationLabel.setFont(authenticationLabel.getFont().deriveFont(Font.BOLD)); authenticationLabel.setToolTipText("Select authentication method for this URL."); authenticationLabel.setDisplayedMnemonic('A'); @@ -275,7 +291,6 @@ private void addBindingType() { aliasGbc.gridy = 2; aliasPanel.add(authenticationLabel, aliasGbc); - // Create the auth dropdown menu CustomComboBox authComboBox = new CustomComboBox(); authComboBox.addItem("No Auth"); authComboBox.addItem("Basic"); @@ -289,8 +304,7 @@ private void addBindingType() { aliasGbc.gridy = 2; aliasPanel.add(authComboBox, aliasGbc); - // Create the username label and text field - usernameLabel = new JBLabel("Username"); + JBLabel usernameLabel = new JBLabel("Username"); usernameLabel.setFont(usernameLabel.getFont().deriveFont(Font.BOLD)); usernameLabel.setToolTipText("Enter the username for basic or digest authentication."); usernameLabel.setDisplayedMnemonic('U'); @@ -315,8 +329,7 @@ private void addBindingType() { aliasGbc.gridy = 3; aliasPanel.add(usernameField, aliasGbc); - // Create the password label and text field - passwordLabel = new JBLabel("Password"); + JBLabel passwordLabel = new JBLabel("Password"); passwordLabel.setFont(passwordLabel.getFont().deriveFont(Font.BOLD)); passwordLabel.setToolTipText( "Enter the password for basic or digest authentication."); @@ -342,8 +355,7 @@ private void addBindingType() { aliasGbc.gridy = 4; aliasPanel.add(passwordField, aliasGbc); - // Create the bearer key label and text field - bearerKeyLabel = new JBLabel("Bearer Key"); + JBLabel bearerKeyLabel = new JBLabel("Bearer Key"); bearerKeyLabel.setFont(bearerKeyLabel.getFont().deriveFont(Font.BOLD)); bearerKeyLabel.setToolTipText( "Enter the bearer key for bearer token authentication."); @@ -356,7 +368,7 @@ private void addBindingType() { bearerKeyLabel.setVisible(false); bearerKeyLabel.setEnabled(false); aliasGbc.gridx = 0; - aliasGbc.gridy = 5; + aliasGbc.gridy = 3; // should be in the same row as usernameLabel aliasPanel.add(bearerKeyLabel, aliasGbc); bearerKeyField = new JBTextField(20); @@ -366,12 +378,11 @@ private void addBindingType() { bearerKeyField.setVisible(false); bearerKeyField.setEnabled(false); aliasGbc.gridx = 1; - aliasGbc.gridy = 5; + aliasGbc.gridy = 3; // should be in the same row as usernameField aliasPanel.add(bearerKeyField, aliasGbc); + aliasPanel.setPreferredSize(new Dimension(500, 160)); - // Create the auth dropdown menu listener authComboBox.addActionListener(ee -> { - // Update the visibility of the authentication fields based on the selected String selectedAuth = (String) authComboBox.getSelectedItem(); if (selectedAuth.equals("Basic") || selectedAuth.equals("Digest")) { usernameLabel.setVisible(true); @@ -388,6 +399,7 @@ private void addBindingType() { bearerKeyField.setVisible(false); bearerKeyLabel.setEnabled(false); bearerKeyField.setEnabled(false); + aliasPanel.setPreferredSize(new Dimension(500, 200)); } else if (selectedAuth.equals("Bearer")) { usernameLabel.setVisible(false); usernameField.setVisible(false); @@ -403,6 +415,7 @@ private void addBindingType() { bearerKeyField.setVisible(true); bearerKeyLabel.setEnabled(true); bearerKeyField.setEnabled(true); + aliasPanel.setPreferredSize(new Dimension(500, 180)); } else { usernameLabel.setVisible(false); usernameField.setVisible(false); @@ -418,18 +431,15 @@ private void addBindingType() { bearerKeyField.setVisible(false); bearerKeyLabel.setEnabled(false); bearerKeyField.setEnabled(false); + aliasPanel.setPreferredSize(new Dimension(500, 160)); } - }); - } else if (selectedBindingType.equals("Constant Alias")) { - // Create the alias name label - constantAliasNameLabel = new JBLabel("Alias Name:"); + JBLabel constantAliasNameLabel = new JBLabel("Alias Name:"); aliasGbc.gridx = 0; aliasGbc.gridy = 0; aliasPanel.add(constantAliasNameLabel, aliasGbc); - // Create the alias name text field constantAliasNameField = new JBTextField(20); constantAliasNameField.setToolTipText("Enter the alias name."); constantAliasNameField.getEmptyText().setText("Enter the alias name."); @@ -437,13 +447,11 @@ private void addBindingType() { aliasGbc.gridy = 0; aliasPanel.add(constantAliasNameField, aliasGbc); - // Create the value label - constantValueLabel = new JBLabel("Value:"); + JBLabel constantValueLabel = new JBLabel("Value:"); aliasGbc.gridx = 0; aliasGbc.gridy = 1; aliasPanel.add(constantValueLabel, aliasGbc); - // Create the value text field constantValueField = new JBTextField(20); constantValueField.setToolTipText("Enter the constant value."); constantValueField.getEmptyText().setText("Enter the constant value."); @@ -451,6 +459,8 @@ private void addBindingType() { aliasGbc.gridy = 1; aliasPanel.add(constantValueField, aliasGbc); + aliasPanel.setPreferredSize(new Dimension(500, 80)); + } // Repaint the alias aliasPanel to show the updated components From 11c6cd71f4f1f5c3b1f0ef27b0e6d7cefbe70b7c Mon Sep 17 00:00:00 2001 From: teetangh Date: Wed, 21 Jun 2023 09:23:31 +0530 Subject: [PATCH 12/15] added padding on general settings and replaced delete icon with svg --- .../eventing/FunctionDeploymentSettings.java | 2 + .../eventing/settings/BindingSettings.java | 64 +++++++++++++------ .../eventing/settings/GeneralSettings.java | 3 +- .../resources/assets/icons/delete_button.svg | 25 ++++++++ 4 files changed, 72 insertions(+), 22 deletions(-) create mode 100644 src/main/resources/assets/icons/delete_button.svg diff --git a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java index b9225b73..4ffda4c1 100644 --- a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java @@ -25,6 +25,7 @@ // import javax.swing.JTextField; import javax.swing.ListSelectionModel; import javax.swing.SwingConstants; +import javax.swing.border.EmptyBorder; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; @@ -115,6 +116,7 @@ public Component getListCellRendererComponent(JList list, Object value, int i generalSettingsPanel = generalSettings.getPanel(); JPanel generalSettingsWrapper = new JPanel(new BorderLayout()); generalSettingsWrapper.add(generalSettingsPanel, BorderLayout.NORTH); + generalSettingsWrapper.setBorder(new EmptyBorder(10, 10, 10, 10)); rightPanel.add(generalSettingsWrapper, "General"); // Settings panel diff --git a/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java b/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java index 280bbfd9..c52e98a3 100644 --- a/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java @@ -14,6 +14,7 @@ import java.util.Map; import javax.swing.DefaultListCellRenderer; +import javax.swing.Icon; import javax.swing.JButton; // import javax.swing.JCheckBox; import javax.swing.JComboBox; @@ -23,10 +24,13 @@ import javax.swing.JSeparator; import com.couchbase.intellij.eventing.components.CustomComboBox; +import com.intellij.openapi.util.IconLoader; import com.intellij.ui.components.JBCheckBox; import com.intellij.ui.components.JBLabel; import com.intellij.ui.components.JBPasswordField; import com.intellij.ui.components.JBTextField; +import com.intellij.util.IconUtil; +import com.intellij.util.ui.JBUI; public class BindingSettings { @@ -78,11 +82,11 @@ public BindingSettings() { bindingsPanel.add(plusButton, bindingsPanelGbc); // Minus button - JButton minusButton = new JButton("-"); - minusButton.addActionListener(e -> removeBindingType()); - bindingsPanelGbc.gridx = 2; - bindingsPanelGbc.gridy = 0; - bindingsPanel.add(minusButton, bindingsPanelGbc); + // JButton minusButton = new JButton("-"); + // minusButton.addActionListener(e -> removeBindingType()); + // bindingsPanelGbc.gridx = 2; + // bindingsPanelGbc.gridy = 0; + // bindingsPanel.add(minusButton, bindingsPanelGbc); } private void addBindingType() { @@ -106,8 +110,26 @@ private void addBindingType() { bindingsTypeGbc.gridy = 0; bindingTypePanel.add(bindingTypeComboBox, bindingsTypeGbc); - // Create a delete button - JButton deleteButton = new JButton("Delete"); + // Create an ImageIcon from the SVG file + // ImageIcon deleteIcon = new + // ImageIcon("src/main/resources/assets/icons/delete_button.svg"); + + // Create the delete button and set its icon + + // ... + + // Load the SVG icon and scale it to the desired size + Icon deleteIcon = IconLoader.findIcon("./assets/icons/delete_button.svg"); + int iconSize = JBUI.scale(16); // Set the desired icon size + deleteIcon = IconUtil.scale(deleteIcon, null, (float) iconSize / deleteIcon.getIconWidth()); + + // Create the delete button and set its icon + JButton deleteButton = new JButton(deleteIcon); + + // Transform the button from rectangular to square + deleteButton.setPreferredSize(new Dimension(20, 20)); + + // Create the delete button and set its icon deleteButton.addActionListener(e -> { // Remove the binding type panel and its associated separator JSeparator separator = separatorMap.get(bindingTypePanel); @@ -499,23 +521,23 @@ public Component getListCellRendererComponent(JList list, Object value, int i bindingsPanel.repaint(); } - private void removeBindingType() { - // Get the number of binding types - int bindingTypeLineIndex = bindingsPanel.getComponentCount(); + // private void removeBindingType() { + // // Get the number of binding types + // int bindingTypeLineIndex = bindingsPanel.getComponentCount(); - // Check if there are any binding types to remove - if (bindingTypeLineIndex >= 2) { - // Remove the last horizontal separator - bindingsPanel.remove(bindingTypeLineIndex - 1); + // // Check if there are any binding types to remove + // if (bindingTypeLineIndex >= 2) { + // // Remove the last horizontal separator + // bindingsPanel.remove(bindingTypeLineIndex - 1); - // Remove the last binding type aliasPanel - bindingsPanel.remove(bindingTypeLineIndex - 2); + // // Remove the last binding type aliasPanel + // bindingsPanel.remove(bindingTypeLineIndex - 2); - // Repaint the bindings aliasPanel to show the removed binding type - bindingsPanel.revalidate(); - bindingsPanel.repaint(); - } - } + // // Repaint the bindings aliasPanel to show the removed binding type + // bindingsPanel.revalidate(); + // bindingsPanel.repaint(); + // } + // } private void rebuildBindingsPanel() { // Remove all components from the bindings panel except for the first row diff --git a/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java b/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java index 47b7ac40..308f6c7a 100644 --- a/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java @@ -280,12 +280,13 @@ public GeneralSettings() { descriptionTextArea.setLineWrap(true); descriptionTextArea.setWrapStyleWord(true); descriptionTextArea.setToolTipText("Enter a description for the function (optional)."); - descriptionTextArea.setPreferredSize(new Dimension(200, 100)); + descriptionTextArea.setPreferredSize(new Dimension(200, 200)); descriptionLabel.setLabelFor(descriptionTextArea); JBScrollPane descriptionScrollPane = new JBScrollPane(descriptionTextArea); generalSettingsPanelConstraints.gridx = 0; generalSettingsPanelConstraints.gridy = 15; generalSettingsPanelConstraints.fill = GridBagConstraints.BOTH; + generalSettingsPanelConstraints.weighty = 1.0; // Set weighty to a non-zero value generalSettingsPanel.add(descriptionScrollPane, generalSettingsPanelConstraints); // Adding all the event listeners diff --git a/src/main/resources/assets/icons/delete_button.svg b/src/main/resources/assets/icons/delete_button.svg new file mode 100644 index 00000000..3899abdd --- /dev/null +++ b/src/main/resources/assets/icons/delete_button.svg @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file From bc23cfb7970f4b9cb4399617aa21698e48ccc3b2 Mon Sep 17 00:00:00 2001 From: teetangh Date: Thu, 29 Jun 2023 14:12:06 +0530 Subject: [PATCH 13/15] fixed the left and right panel size and alignments + introduced help context + introduced form validation and error generation --- .../eventing/FunctionDeploymentSettings.java | 22 +- .../eventing/components/HelpIcon.java | 33 ++ .../eventing/settings/AdvancedSettings.java | 311 ++++++++++++------ .../eventing/settings/BindingSettings.java | 170 +++++++++- .../eventing/settings/GeneralSettings.java | 166 ++++++---- 5 files changed, 514 insertions(+), 188 deletions(-) create mode 100644 src/main/java/com/couchbase/intellij/eventing/components/HelpIcon.java diff --git a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java index 4ffda4c1..390cc567 100644 --- a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java @@ -68,7 +68,8 @@ public FunctionDeploymentSettings() { // Create and configure the left panel leftPanel = new JPanel(); leftPanel.setLayout(new BorderLayout()); - leftPanel.setPreferredSize(new Dimension(400, 800)); + leftPanel.setMaximumSize(new Dimension(200, 800)); + leftPanel.setPreferredSize(new Dimension(200, 800)); // leftPanel.setForeground(JBColor.BLACK); leftPanel.setBackground(new Color(62, 67, 76, 255)); // Jetbrains Darcula background color @@ -110,13 +111,16 @@ public Component getListCellRendererComponent(JList list, Object value, int i // Create and configure the right panel rightPanel = new JPanel(new CardLayout()); + rightPanel.setMaximumSize(new Dimension(800, 800)); + rightPanel.setPreferredSize(new Dimension(800, 800)); // Add components to the right panel GeneralSettings generalSettings = new GeneralSettings(); generalSettingsPanel = generalSettings.getPanel(); JPanel generalSettingsWrapper = new JPanel(new BorderLayout()); generalSettingsWrapper.add(generalSettingsPanel, BorderLayout.NORTH); - generalSettingsWrapper.setBorder(new EmptyBorder(10, 10, 10, 10)); + generalSettingsWrapper.setBorder(new EmptyBorder(20, 20, 20, 20)); + generalSettingsWrapper.setMinimumSize(new Dimension(800, 800)); rightPanel.add(generalSettingsWrapper, "General"); // Settings panel @@ -124,12 +128,17 @@ public Component getListCellRendererComponent(JList list, Object value, int i advancedSettingsPanel = advancedSettings.getPanel(); JPanel advancedSettingsWrapper = new JPanel(new BorderLayout()); advancedSettingsWrapper.add(advancedSettingsPanel, BorderLayout.NORTH); + advancedSettingsWrapper.setBorder(new EmptyBorder(20, 20, 20, 20)); + advancedSettingsWrapper.setMinimumSize(new Dimension(800, 800)); rightPanel.add(advancedSettingsWrapper, "Settings"); // Binding Types panel BindingSettings bindingSettings = new BindingSettings(); bindingsPanel = bindingSettings.getPanel(); - rightPanel.add(new JScrollPane(bindingsPanel), "Binding Types"); // No need to wrap this panel + JPanel bindingsWrapper = new JPanel(new BorderLayout()); + bindingsWrapper.add(bindingsPanel, BorderLayout.NORTH); + bindingsWrapper.setMinimumSize(new Dimension(800, 800)); + rightPanel.add(new JScrollPane(bindingsWrapper), "Binding Types"); // No need to wrap this panel settingsList.addListSelectionListener(e -> { if (!e.getValueIsAdjusting()) { @@ -141,7 +150,8 @@ public Component getListCellRendererComponent(JList list, Object value, int i // Create and configure the bottom panel bottomPanel = new JPanel(); - bottomPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); + bottomPanel.setLayout(new BorderLayout()); + bottomPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); // Add a margin of 10 pixels around the panel // Add components to the bottom panel applyButton = new JButton("Apply"); @@ -149,14 +159,14 @@ public Component getListCellRendererComponent(JList list, Object value, int i // Save changes dispose(); }); - bottomPanel.add(applyButton); + bottomPanel.add(applyButton, BorderLayout.EAST); cancelButton = new JButton("Cancel"); cancelButton.addActionListener(e -> { // Discard changes dispose(); }); - bottomPanel.add(cancelButton); + bottomPanel.add(cancelButton, BorderLayout.WEST); // Add the panels to the main panel with a splitter in the middle JBSplitter splitter = new JBSplitter(false); diff --git a/src/main/java/com/couchbase/intellij/eventing/components/HelpIcon.java b/src/main/java/com/couchbase/intellij/eventing/components/HelpIcon.java new file mode 100644 index 00000000..d6de8cda --- /dev/null +++ b/src/main/java/com/couchbase/intellij/eventing/components/HelpIcon.java @@ -0,0 +1,33 @@ +package com.couchbase.intellij.eventing.components; + +import java.awt.event.*; +import javax.swing.JComponent; + +import com.intellij.icons.AllIcons; +import com.intellij.openapi.ui.popup.Balloon; +import com.intellij.openapi.ui.popup.JBPopupFactory; +import com.intellij.ui.JBColor; +import com.intellij.ui.components.JBLabel; + +public class HelpIcon { + + public static JBLabel createHelpIcon(String tooltipText) { + JBLabel helpIcon = new JBLabel(); + helpIcon.setIcon(AllIcons.General.ContextHelp); + helpIcon.addMouseListener(new MouseAdapter() { + @Override + public void mouseEntered(MouseEvent e) { + super.mouseEntered(e); + JComponent component = (JComponent) e.getComponent(); + Balloon balloon = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder( + tooltipText, + null, + JBColor.background(), + null).setFadeoutTime(1500).createBalloon(); + balloon.showInCenterOf(component); + } + }); + return helpIcon; + } + +} diff --git a/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java b/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java index 7f9b3517..c6b59a41 100644 --- a/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java @@ -1,17 +1,29 @@ + package com.couchbase.intellij.eventing.settings; +import java.awt.Color; import java.awt.FlowLayout; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; - +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; import javax.swing.JComboBox; +import javax.swing.JFormattedTextField; +import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.UIManager; +import javax.swing.text.NumberFormatter; -import com.intellij.ui.JBColor; +import com.couchbase.intellij.eventing.components.HelpIcon; import com.intellij.ui.components.JBLabel; -import com.intellij.ui.components.JBTextField; public class AdvancedSettings { @@ -22,28 +34,22 @@ public class AdvancedSettings { private JPanel languageCompatibilityPanel; private JPanel scriptTimeoutPanel; private JPanel timerContextMaxSizePanel; + private JPanel errorPanel; private JBLabel systemLogLevelLabel; - private JBLabel systemLogLevelInfoLabel; - private JBLabel applicationLogFileLabel; private JBLabel n1qlConsistencyLabel; - private JBLabel n1qlConsistencyInfoLabel; private JBLabel workersLabel; - private JBLabel workersInfoLabel; private JBLabel languageCompatibilityLabel; - private JBLabel languageCompatibilityInfoLabel; private JBLabel scriptTimeoutLabel; - private JBLabel scriptTimeoutInfoLabel; private JBLabel timerContextMaxSizeLabel; - private JBLabel timerContextMaxSizeInfoLabel; private JComboBox systemLogLevelComboBox; private JComboBox n1qlConsistencyComboBox; private JComboBox languageCompatibilityComboBox; - private JBTextField workersField; - private JBTextField scriptTimeoutField; - private JBTextField timerContextMaxSizeField; + private JFormattedTextField workersField; + private JFormattedTextField scriptTimeoutField; + private JFormattedTextField timerContextMaxSizeField; public AdvancedSettings() { // Advanced Settings panel @@ -60,22 +66,12 @@ public AdvancedSettings() { // Add components to the Advanced Settings panel systemLogLevelLabel = new JBLabel("System Log Level"); systemLogLevelLabel.setFont(systemLogLevelLabel.getFont().deriveFont(Font.BOLD)); - // advancedSettingsPanelConstraints.gridx = 0; - // advancedSettingsPanelConstraints.gridy = 0; - // advancedSettingsPanel.add(systemLogLevelLabel, - // advancedSettingsPanelConstraints); - - systemLogLevelInfoLabel = new JBLabel("Granularity of system events being captured in the log"); - systemLogLevelInfoLabel.setForeground(JBColor.GRAY); - // advancedSettingsPanelConstraints.gridx = 1; - // advancedSettingsPanelConstraints.gridy = 0; - // advancedSettingsPanel.add(systemLogLevelInfoLabel, - // advancedSettingsPanelConstraints); // Add both the labels to a panel systemLogLevelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); systemLogLevelPanel.add(systemLogLevelLabel); - systemLogLevelPanel.add(systemLogLevelInfoLabel); + systemLogLevelPanel + .add(HelpIcon.createHelpIcon("Granularity of system events being captured in the log")); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 0; advancedSettingsPanel.add(systemLogLevelPanel, advancedSettingsPanelConstraints); @@ -90,31 +86,14 @@ public AdvancedSettings() { advancedSettingsPanelConstraints.gridy = 1; advancedSettingsPanel.add(systemLogLevelComboBox, advancedSettingsPanelConstraints); - applicationLogFileLabel = new JBLabel( - "Application log file for this Function is at:"); - - advancedSettingsPanelConstraints.gridx = 0; - advancedSettingsPanelConstraints.gridy = 2; - advancedSettingsPanel.add(applicationLogFileLabel, advancedSettingsPanelConstraints); - n1qlConsistencyLabel = new JBLabel("N1QL Consistency"); n1qlConsistencyLabel.setFont(n1qlConsistencyLabel.getFont().deriveFont(Font.BOLD)); - // advancedSettingsPanelConstraints.gridx = 0; - // advancedSettingsPanelConstraints.gridy = 3; - // advancedSettingsPanel.add(n1qlConsistencyLabel, - // advancedSettingsPanelConstraints); - - n1qlConsistencyInfoLabel = new JBLabel("Consistency level of N1QL statements in the function"); - n1qlConsistencyInfoLabel.setForeground(JBColor.GRAY); - // advancedSettingsPanelConstraints.gridx = 1; - // advancedSettingsPanelConstraints.gridy = 3; - // advancedSettingsPanel.add(n1qlConsistencyInfoLabel, - // advancedSettingsPanelConstraints); // Add both the labels to a panel n1qlConsistencyPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); n1qlConsistencyPanel.add(n1qlConsistencyLabel); - n1qlConsistencyPanel.add(n1qlConsistencyInfoLabel); + n1qlConsistencyPanel + .add(HelpIcon.createHelpIcon("Consistency level of N1QL statements in the function:")); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 3; advancedSettingsPanel.add(n1qlConsistencyPanel, advancedSettingsPanelConstraints); @@ -129,52 +108,57 @@ public AdvancedSettings() { workersLabel = new JBLabel("Workers"); workersLabel.setFont(workersLabel.getFont().deriveFont(Font.BOLD)); - // advancedSettingsPanelConstraints.gridx = 0; - // advancedSettingsPanelConstraints.gridy = 5; - // advancedSettingsPanel.add(workersLabel, advancedSettingsPanelConstraints); - - workersInfoLabel = new JBLabel( - "Number of workers per node to process the events. If no value is specified, a default value of 1 worker is used."); - workersInfoLabel.setForeground(JBColor.GRAY); - // advancedSettingsPanelConstraints.gridx = 1; - // advancedSettingsPanelConstraints.gridy = 5; - // advancedSettingsPanel.add(workersInfoLabel, - // advancedSettingsPanelConstraints); // Add both the labels to a panel workersPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); workersPanel.add(workersLabel); - workersPanel.add(workersInfoLabel); + workersPanel.add(HelpIcon.createHelpIcon("Number of workers per node to process the events:")); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 5; advancedSettingsPanel.add(workersPanel, advancedSettingsPanelConstraints); - workersField = new JBTextField(20); + NumberFormat format = NumberFormat.getInstance(); + NumberFormatter formatter = new NumberFormatter(format); + formatter.setValueClass(Integer.class); + formatter.setMinimum(0); + formatter.setMaximum(Integer.MAX_VALUE); + formatter.setAllowsInvalid(false); + formatter.setCommitsOnValidEdit(true); + + workersField = new JFormattedTextField(formatter); + workersField.setColumns(20); + workersField.setValue(1); workersField.setToolTipText("Enter the number of workers per node to process the events."); - workersField.setText("1"); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 6; + advancedSettingsPanelConstraints.gridwidth = 3; advancedSettingsPanel.add(workersField, advancedSettingsPanelConstraints); - languageCompatibilityLabel = new JBLabel("Language compatibility"); + // Add a focus listener to the workersField + workersField.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + validateForm(); // Validate the form for error generation + // Validate the worker count + if (!validateWorkerCount()) { + // Worker count is invalid, so set the border and label to red + workersField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + workersLabel.setForeground(Color.decode("#FF4444")); + } else { + // Worker count is valid, so set the border and label back to their normal state + workersField.setBorder(UIManager.getBorder("TextField.border")); + workersLabel.setForeground(UIManager.getColor("Label.foreground")); + } + } + }); + languageCompatibilityLabel = new JBLabel("Language compatibility"); languageCompatibilityLabel.setFont(languageCompatibilityLabel.getFont().deriveFont(Font.BOLD)); - // advancedSettingsPanelConstraints.gridx = 0; - // advancedSettingsPanelConstraints.gridy = 7; - // advancedSettingsPanel.add(languageCompatibilityLabel, - // advancedSettingsPanelConstraints); - - languageCompatibilityInfoLabel = new JBLabel("Language compatibility of the function"); - languageCompatibilityInfoLabel.setForeground(JBColor.GRAY); - // advancedSettingsPanelConstraints.gridx = 1; - // advancedSettingsPanelConstraints.gridy = 7; - // advancedSettingsPanel.add(languageCompatibilityInfoLabel, - // advancedSettingsPanelConstraints); // Add both the labels to a panel languageCompatibilityPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); languageCompatibilityPanel.add(languageCompatibilityLabel); - languageCompatibilityPanel.add(languageCompatibilityInfoLabel); + languageCompatibilityPanel.add(HelpIcon.createHelpIcon("Language compatibility of the function:")); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 7; advancedSettingsPanel.add(languageCompatibilityPanel, advancedSettingsPanelConstraints); @@ -188,71 +172,184 @@ public AdvancedSettings() { advancedSettingsPanel.add(languageCompatibilityComboBox, advancedSettingsPanelConstraints); scriptTimeoutLabel = new JBLabel("Script Timeout"); - scriptTimeoutLabel.setFont(scriptTimeoutLabel.getFont().deriveFont(Font.BOLD)); - // advancedSettingsPanelConstraints.gridx = 0; - // advancedSettingsPanelConstraints.gridy = 9; - // advancedSettingsPanel.add(scriptTimeoutLabel, - // advancedSettingsPanelConstraints); - - scriptTimeoutInfoLabel = new JBLabel( - "Time after which the Function's execution will be timed out"); - scriptTimeoutInfoLabel.setForeground(JBColor.GRAY); - // advancedSettingsPanelConstraints.gridx = 1; - // advancedSettingsPanelConstraints.gridy = 9; - // advancedSettingsPanel.add(scriptTimeoutInfoLabel, - // advancedSettingsPanelConstraints); // Add both the labels to a panel scriptTimeoutPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); scriptTimeoutPanel.add(scriptTimeoutLabel); - scriptTimeoutPanel.add(scriptTimeoutInfoLabel); + scriptTimeoutPanel.add(HelpIcon + .createHelpIcon("Time after which the Function's execution will be timed out:")); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 9; advancedSettingsPanel.add(scriptTimeoutPanel, advancedSettingsPanelConstraints); - scriptTimeoutField = new JBTextField(20); - scriptTimeoutField.setText("60"); + scriptTimeoutField = new JFormattedTextField(formatter); + scriptTimeoutField.setColumns(20); + scriptTimeoutField.setValue(60); scriptTimeoutField.setToolTipText( "Enter the time after which the Function's execution will be timed out."); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 10; + advancedSettingsPanelConstraints.gridwidth = 3; advancedSettingsPanel.add(scriptTimeoutField, advancedSettingsPanelConstraints); - timerContextMaxSizeLabel = new JBLabel("Timer Context Max Size"); + // Add a focus listener to the scriptTimeoutField + scriptTimeoutField.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + validateForm(); // Validate the form for error generation + // Validate the script timeout + if (!validateScriptTimeout()) { + // Script timeout is invalid, so set the border and label to red + scriptTimeoutField.setBorder( + BorderFactory.createLineBorder(Color.decode("#FF4444"))); + scriptTimeoutLabel.setForeground(Color.decode("#FF4444")); + } else { + // Script timeout is valid, so set the border and label back to their normal + // state + scriptTimeoutField.setBorder(UIManager.getBorder("TextField.border")); + scriptTimeoutLabel.setForeground(UIManager.getColor("Label.foreground")); + } + } + }); + timerContextMaxSizeLabel = new JBLabel("Timer Context Max Size"); timerContextMaxSizeLabel.setFont(timerContextMaxSizeLabel.getFont().deriveFont(Font.BOLD)); - // advancedSettingsPanelConstraints.gridx = 0; - // advancedSettingsPanelConstraints.gridy = 11; - // advancedSettingsPanel.add(timerContextMaxSizeLabel, - // advancedSettingsPanelConstraints); - - timerContextMaxSizeInfoLabel = new JBLabel( - "Maximum allowed value of the Timer Context Size in Bytes. Takes effect immediately."); - timerContextMaxSizeInfoLabel.setForeground(JBColor.GRAY); - // advancedSettingsPanelConstraints.gridx = 1; - // advancedSettingsPanelConstraints.gridy = 11; - // advancedSettingsPanel.add(timerContextMaxSizeInfoLabel, - // advancedSettingsPanelConstraints); // Add both the labels to a panel timerContextMaxSizePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); timerContextMaxSizePanel.add(timerContextMaxSizeLabel); - timerContextMaxSizePanel.add(timerContextMaxSizeInfoLabel); + timerContextMaxSizePanel.add(HelpIcon.createHelpIcon( + "Timer Context Size in Bytes. If the size of the Timer Context exceeds this value, the Timer Context will be cleared")); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 11; advancedSettingsPanel.add(timerContextMaxSizePanel, advancedSettingsPanelConstraints); - - timerContextMaxSizeField = new JBTextField(20); - timerContextMaxSizeField.setText("1024"); - timerContextMaxSizeField.setToolTipText( - "Enter the maximum allowed value of the Timer Context Size in Bytes."); + timerContextMaxSizeField = new JFormattedTextField(formatter); + timerContextMaxSizeField.setColumns(20); + timerContextMaxSizeField.setValue(1024); + timerContextMaxSizeField + .setToolTipText("Enter the maximum allowed value of the Timer Context Size in Bytes."); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 12; advancedSettingsPanel.add(timerContextMaxSizeField, advancedSettingsPanelConstraints); + + // Add a focus listener to the timerContextMaxSizeField + timerContextMaxSizeField.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + validateForm(); // Validate the form for error generation + // Validate the timer context max size + if (!validateTimerContextMaxSize()) { + // Timer context max size is invalid, so set the border and label to red + timerContextMaxSizeField.setBorder( + BorderFactory.createLineBorder(Color.decode("#FF4444"))); + timerContextMaxSizeLabel.setForeground(Color.decode("#FF4444")); + } else { + // Timer context max size is valid, so set the border and label back to their + // normal state + timerContextMaxSizeField.setBorder(UIManager.getBorder("TextField.border")); + timerContextMaxSizeLabel.setForeground(UIManager.getColor("Label.foreground")); + } + } + }); + + errorPanel = new JPanel(); + errorPanel.setLayout(new BoxLayout(errorPanel, BoxLayout.Y_AXIS)); + + // Add the error panel to the advanced settings panel + advancedSettingsPanelConstraints.gridx = 0; + advancedSettingsPanelConstraints.gridy = 13; + advancedSettingsPanelConstraints.gridwidth = 3; + advancedSettingsPanel.add(errorPanel, advancedSettingsPanelConstraints); + } public JPanel getPanel() { return advancedSettingsPanel; } -} \ No newline at end of file + + private List validateForm() { + List errors = new ArrayList<>(); + + // Validate function name + if (!validateWorkerCount()) { + errors.add("Workers count should be a positive integer"); + } + + if (!validateScriptTimeout()) { + errors.add("Script timeout should be a positive integer"); + } + + if (!validateTimerContextMaxSize()) { + errors.add("Timer context max size should be a positive integer"); + } + + // Update the error panel to display the validation errors + errorPanel.removeAll(); + for (String error : errors) { + JLabel errorLabel = new JLabel(error); + errorLabel.setForeground(Color.decode("#FF4444")); + errorPanel.add(errorLabel); + } + errorPanel.revalidate(); + errorPanel.repaint(); + + return errors; + } + + private boolean validateWorkerCount() { + + String workerCount = workersField.getText(); + // remove commas from the string + workerCount = workerCount.replaceAll(",", ""); + if (workerCount == null || workerCount.isEmpty()) { + return false; + } + try { + int count = Integer.parseInt(workerCount); + if (count < 1) { + return false; + } + } catch (NumberFormatException e) { + return false; + } + return true; + } + + private boolean validateScriptTimeout() { + String scriptTimeout = scriptTimeoutField.getText(); + // remove commas from the string + scriptTimeout = scriptTimeout.replaceAll(",", ""); + if (scriptTimeout == null || scriptTimeout.isEmpty()) { + return false; + } + try { + int timeout = Integer.parseInt(scriptTimeout); + if (timeout < 1) { + return false; + } + } catch (NumberFormatException e) { + return false; + } + return true; + } + + private boolean validateTimerContextMaxSize() { + String timerContextMaxSize = timerContextMaxSizeField.getText(); + // remove commas from the string + timerContextMaxSize = timerContextMaxSize.replaceAll(",", ""); + if (timerContextMaxSize == null || timerContextMaxSize.isEmpty()) { + return false; + } + try { + int maxSize = Integer.parseInt(timerContextMaxSize); + if (maxSize < 1) { + return false; + } + } catch (NumberFormatException e) { + return false; + } + return true; + } + +} diff --git a/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java b/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java index c52e98a3..97eb01fa 100644 --- a/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java @@ -8,11 +8,14 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.swing.BorderFactory; import javax.swing.DefaultListCellRenderer; import javax.swing.Icon; import javax.swing.JButton; @@ -22,6 +25,7 @@ import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JSeparator; +import javax.swing.UIManager; import com.couchbase.intellij.eventing.components.CustomComboBox; import com.intellij.openapi.util.IconLoader; @@ -217,6 +221,17 @@ public Component getListCellRendererComponent(JList list, Object value, int i bucketAliasNameField = new JBTextField(20); bucketAliasNameField.setToolTipText("Enter the alias name."); bucketAliasNameField.getEmptyText().setText("Enter the alias name."); + bucketAliasNameField.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + validateForm(); + if (!validateBucketAliasName()) { + bucketAliasNameField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + } else { + bucketAliasNameField.setBorder(UIManager.getBorder("TextField.border")); + } + } + }); aliasGbc.gridx = 0; aliasGbc.gridy = 0; aliasGbc.gridwidth = 4; @@ -271,12 +286,23 @@ public Component getListCellRendererComponent(JList list, Object value, int i aliasGbc.gridy = 2; aliasPanel.add(accessComboBox, aliasGbc); - aliasPanel.setPreferredSize(new Dimension(500, 120)); + aliasPanel.setPreferredSize(new Dimension(500, 150)); } else if (selectedBindingType.equals("URL Alias")) { urlAliasNameField = new JBTextField(20); urlAliasNameField.setToolTipText("Enter the alias name."); urlAliasNameField.getEmptyText().setText("Enter the alias name."); + urlAliasNameField.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + validateForm(); + if (!validateUrlAliasName()) { + urlAliasNameField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + } else { + urlAliasNameField.setBorder(UIManager.getBorder("TextField.border")); + } + } + }); aliasGbc.gridx = 0; aliasGbc.gridy = 0; aliasPanel.add(urlAliasNameField, aliasGbc); @@ -284,6 +310,17 @@ public Component getListCellRendererComponent(JList list, Object value, int i urlField = new JBTextField(20); urlField.setToolTipText("Enter the URL."); urlField.getEmptyText().setText("Enter the URL."); + urlField.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + validateForm(); + if (!validateUrl()) { + urlField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + } else { + urlField.setBorder(UIManager.getBorder("TextField.border")); + } + } + }); aliasGbc.gridx = 1; aliasGbc.gridy = 0; aliasPanel.add(urlField, aliasGbc); @@ -347,6 +384,18 @@ public Component getListCellRendererComponent(JList list, Object value, int i usernameField.getEmptyText().setText("Enter the username."); usernameField.setVisible(false); usernameField.setEnabled(false); + usernameField.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + validateForm(); + if (!validateUsername()) { + usernameField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + } else { + usernameField.setBorder(UIManager.getBorder("TextField.border")); + } + } + }); + aliasGbc.gridx = 1; aliasGbc.gridy = 3; aliasPanel.add(usernameField, aliasGbc); @@ -385,6 +434,7 @@ public Component getListCellRendererComponent(JList list, Object value, int i bearerKeyLabel.setDisplayedMnemonicIndex(0); bearerKeyLabel.setHorizontalAlignment(JBTextField.LEFT); bearerKeyLabel.setVerticalAlignment(JBTextField.CENTER); + bearerKeyLabel.setHorizontalTextPosition(JBTextField.RIGHT); bearerKeyLabel.setVerticalTextPosition(JBTextField.CENTER); bearerKeyLabel.setVisible(false); @@ -399,6 +449,17 @@ public Component getListCellRendererComponent(JList list, Object value, int i bearerKeyField.getEmptyText().setText("Enter the bearer key."); bearerKeyField.setVisible(false); bearerKeyField.setEnabled(false); + bearerKeyField.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + validateForm(); + if (!validateBearerKey()) { + bearerKeyField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + } else { + bearerKeyField.setBorder(UIManager.getBorder("TextField.border")); + } + } + }); aliasGbc.gridx = 1; aliasGbc.gridy = 3; // should be in the same row as usernameField aliasPanel.add(bearerKeyField, aliasGbc); @@ -465,6 +526,17 @@ public Component getListCellRendererComponent(JList list, Object value, int i constantAliasNameField = new JBTextField(20); constantAliasNameField.setToolTipText("Enter the alias name."); constantAliasNameField.getEmptyText().setText("Enter the alias name."); + constantAliasNameField.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + validateForm(); + if (!validateConstantAliasName()) { + constantAliasNameField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + } else { + constantAliasNameField.setBorder(UIManager.getBorder("TextField.border")); + } + } + }); aliasGbc.gridx = 1; aliasGbc.gridy = 0; aliasPanel.add(constantAliasNameField, aliasGbc); @@ -477,11 +549,22 @@ public Component getListCellRendererComponent(JList list, Object value, int i constantValueField = new JBTextField(20); constantValueField.setToolTipText("Enter the constant value."); constantValueField.getEmptyText().setText("Enter the constant value."); + constantValueField.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + validateForm(); + if (!validateConstantValue()) { + constantValueField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + } else { + constantValueField.setBorder(UIManager.getBorder("TextField.border")); + } + } + }); aliasGbc.gridx = 1; aliasGbc.gridy = 1; aliasPanel.add(constantValueField, aliasGbc); - aliasPanel.setPreferredSize(new Dimension(500, 80)); + aliasPanel.setPreferredSize(new Dimension(500, 120)); } @@ -574,4 +657,85 @@ public JPanel getPanel() { return bindingsPanel; } -} \ No newline at end of file + private void validateForm() { + // Validate all the fields in all the aliasPanels + for (JPanel aliasPanel : aliasPanels) { + if (!validateBucketAliasName()) { + bucketAliasNameField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + } else { + bucketAliasNameField.setBorder(UIManager.getBorder("TextField.border")); + } + + if (!validateUrlAliasName()) { + urlAliasNameField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + } else { + urlAliasNameField.setBorder(UIManager.getBorder("TextField.border")); + } + + if (!validateUrl()) { + urlField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + } else { + urlField.setBorder(UIManager.getBorder("TextField.border")); + } + + if (!validateUsername()) { + usernameField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + } else { + usernameField.setBorder(UIManager.getBorder("TextField.border")); + } + + if (!validateBearerKey()) { + bearerKeyField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + } else { + bearerKeyField.setBorder(UIManager.getBorder("TextField.border")); + } + + if (!validateConstantAliasName()) { + constantAliasNameField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + } else { + constantAliasNameField.setBorder(UIManager.getBorder("TextField.border")); + } + + if (!validateConstantValue()) { + constantValueField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + } else { + constantValueField.setBorder(UIManager.getBorder("TextField.border")); + } + } + } + + private boolean validateBucketAliasName() { + String aliasName = bucketAliasNameField.getText(); + return aliasName != null && !aliasName.trim().isEmpty(); + } + + private boolean validateUrlAliasName() { + String aliasName = urlAliasNameField.getText(); + return aliasName != null && !aliasName.trim().isEmpty(); + } + + private boolean validateUrl() { + String url = urlField.getText(); + return url != null && !url.trim().isEmpty(); + } + + private boolean validateUsername() { + String username = usernameField.getText(); + return username != null && !username.trim().isEmpty(); + } + + private boolean validateBearerKey() { + String bearerKey = bearerKeyField.getText(); + return bearerKey != null && !bearerKey.trim().isEmpty(); + } + + private boolean validateConstantAliasName() { + String aliasName = constantAliasNameField.getText(); + return aliasName != null && !aliasName.trim().isEmpty(); + } + + private boolean validateConstantValue() { + String value = constantValueField.getText(); + return value != null && !value.trim().isEmpty(); + } +} diff --git a/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java b/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java index 308f6c7a..bb88f1bf 100644 --- a/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java @@ -1,17 +1,24 @@ package com.couchbase.intellij.eventing.settings; -import java.awt.Dimension; +import java.awt.Color; import java.awt.FlowLayout; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; import javax.swing.JComboBox; +import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.UIManager; import com.couchbase.client.java.Bucket; import com.couchbase.client.java.Cluster; @@ -20,6 +27,7 @@ import com.couchbase.client.java.manager.collection.CollectionSpec; import com.couchbase.client.java.manager.collection.ScopeSpec; import com.couchbase.intellij.database.ActiveCluster; +import com.couchbase.intellij.eventing.components.HelpIcon; import com.intellij.ui.JBColor; import com.intellij.ui.components.JBLabel; import com.intellij.ui.components.JBScrollPane; @@ -32,21 +40,21 @@ public class GeneralSettings { private JPanel functionScopePanel; private JPanel listenToLocationPanel; private JPanel eventingStoragePanel; + private JPanel errorPanel; private JBLabel functionScopeLabel; private JBLabel functionScopeInfoLabel; - private JBLabel helpLabel1; private JBLabel listenToLocationLabel; private JBLabel listenToLocationInfoLabel; - private JBLabel helpLabel2; private JBLabel eventingStorageLabel; private JBLabel eventingStorageInfoLabel; - private JBLabel helpLabel3; private JBLabel functionNameLabel; private JBLabel deploymentFeedBoundaryLabel; private JBLabel warningLabel; private JBLabel descriptionLabel; + private JBTextField functionNameField; + private JComboBox functionScopeBucketComboBox; private JComboBox functionScopeScopeComboBox; private JComboBox listenToLocationBucketComboBox; @@ -85,6 +93,8 @@ public GeneralSettings() { functionScopePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); functionScopePanel.add(functionScopeLabel); functionScopePanel.add(functionScopeInfoLabel); + functionScopePanel.add(HelpIcon.createHelpIcon( + "Please specify a scope to which the function belongs. User should have Eventing Manage Scope Functions permission on this scope")); generalSettingsPanelConstraints.gridx = 0; generalSettingsPanelConstraints.gridy = 0; generalSettingsPanel.add(functionScopePanel, generalSettingsPanelConstraints); @@ -100,134 +110,111 @@ public GeneralSettings() { generalSettingsPanelConstraints.gridx = 1; generalSettingsPanelConstraints.gridy = 1; generalSettingsPanel.add(functionScopeScopeComboBox, generalSettingsPanelConstraints); - // Function Scope error label - helpLabel1 = new JBLabel( - "Please specify a scope to which the function belongs. User should have Eventing Manage Scope Functions permission on this scope"); - helpLabel1.setForeground(JBColor.GRAY); - generalSettingsPanelConstraints.gridx = 0; - generalSettingsPanelConstraints.gridy = 2; - generalSettingsPanelConstraints.gridwidth = 3; - generalSettingsPanel.add(helpLabel1, generalSettingsPanelConstraints); // Listen to location label listenToLocationLabel = new JBLabel("Listen to location"); - listenToLocationLabel.setFont(listenToLocationLabel.getFont().deriveFont(Font.BOLD)); - // generalSettingsPanelConstraints.gridx = 0; - // generalSettingsPanelConstraints.gridy = 3; - // generalSettingsPanel.add(listenToLocationLabel, - // generalSettingsPanelConstraints); - listenToLocationInfoLabel = new JBLabel("bucket.scope.collection"); listenToLocationInfoLabel.setForeground(JBColor.GRAY); - // generalSettingsPanelConstraints.gridx = 1; - // generalSettingsPanelConstraints.gridy = 3; - // generalSettingsPanel.add(listenToLocationInfoLabel, - // generalSettingsPanelConstraints); // Add both labels to a flow layout listenToLocationPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); listenToLocationPanel.add(listenToLocationLabel); listenToLocationPanel.add(listenToLocationInfoLabel); + listenToLocationPanel.add(HelpIcon.createHelpIcon( + "Please specify a source location for your function. User should have DCP Data Read permission on this keyspace")); generalSettingsPanelConstraints.gridx = 0; - generalSettingsPanelConstraints.gridy = 3; + generalSettingsPanelConstraints.gridy = 2; generalSettingsPanel.add(listenToLocationPanel, generalSettingsPanelConstraints); listenToLocationBucketComboBox = new JComboBox<>(); // listenToLocationBucketComboBox.addActionListener(e -> updateScopes()); generalSettingsPanelConstraints.gridx = 0; - generalSettingsPanelConstraints.gridy = 4; + generalSettingsPanelConstraints.gridy = 3; generalSettingsPanelConstraints.gridwidth = 1; generalSettingsPanel.add(listenToLocationBucketComboBox, generalSettingsPanelConstraints); listenToLocationScopeComboBox = new JComboBox<>(); listenToLocationScopeComboBox.setEnabled(false); generalSettingsPanelConstraints.gridx = 1; - generalSettingsPanelConstraints.gridy = 4; + generalSettingsPanelConstraints.gridy = 3; generalSettingsPanel.add(listenToLocationScopeComboBox, generalSettingsPanelConstraints); listenToLocationCollectionComboBox = new JComboBox<>(); listenToLocationCollectionComboBox.setEnabled(false); generalSettingsPanelConstraints.gridx = 2; - generalSettingsPanelConstraints.gridy = 4; + generalSettingsPanelConstraints.gridy = 3; generalSettingsPanel.add(listenToLocationCollectionComboBox, generalSettingsPanelConstraints); - // Listen to location error label - helpLabel2 = new JBLabel( - "Please specify a source location for your function. User should have DCP Data Read permission on this keyspace"); - helpLabel2.setForeground(JBColor.GRAY); - generalSettingsPanelConstraints.gridx = 0; - generalSettingsPanelConstraints.gridy = 5; - generalSettingsPanelConstraints.gridwidth = 3; - - generalSettingsPanel.add(helpLabel2, generalSettingsPanelConstraints); - // Eventing Storage label eventingStorageLabel = new JBLabel("Eventing Storage"); eventingStorageLabel.setFont(eventingStorageLabel.getFont().deriveFont(Font.BOLD)); - // generalSettingsPanelConstraints.gridx = 0; - // generalSettingsPanelConstraints.gridy = 6; - // generalSettingsPanel.add(eventingStorageLabel, - // generalSettingsPanelConstraints); - eventingStorageInfoLabel = new JBLabel("bucket.scope.collection"); eventingStorageInfoLabel.setForeground(JBColor.GRAY); - // generalSettingsPanelConstraints.gridx = 1; - // generalSettingsPanelConstraints.gridy = 6; - // generalSettingsPanelConstraints.gridwidth = 2; - // generalSettingsPanel.add(eventingStorageInfoLabel, - // generalSettingsPanelConstraints); // Add both labels to a flow layout eventingStoragePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); eventingStoragePanel.add(eventingStorageLabel); eventingStoragePanel.add(eventingStorageInfoLabel); + eventingStoragePanel.add(HelpIcon.createHelpIcon( + "Please specify a location to store Eventing data. User should have read/write permission on this keyspace")); generalSettingsPanelConstraints.gridx = 0; - generalSettingsPanelConstraints.gridy = 6; + generalSettingsPanelConstraints.gridy = 4; generalSettingsPanel.add(eventingStoragePanel, generalSettingsPanelConstraints); eventingStorageBucketComboBox = new JComboBox<>(); // eventingStorageBucketComboBox.addActionListener(e -> updateScopes()); generalSettingsPanelConstraints.gridx = 0; - generalSettingsPanelConstraints.gridy = 7; + generalSettingsPanelConstraints.gridy = 5; generalSettingsPanelConstraints.gridwidth = 1; generalSettingsPanel.add(eventingStorageBucketComboBox, generalSettingsPanelConstraints); eventingStorageScopeComboBox = new JComboBox<>(); eventingStorageScopeComboBox.setEnabled(false); generalSettingsPanelConstraints.gridx = 1; - generalSettingsPanelConstraints.gridy = 7; + generalSettingsPanelConstraints.gridy = 5; generalSettingsPanel.add(eventingStorageScopeComboBox, generalSettingsPanelConstraints); eventingStorageCollectionComboBox = new JComboBox<>(); eventingStorageCollectionComboBox.setEnabled(false); generalSettingsPanelConstraints.gridx = 2; - generalSettingsPanelConstraints.gridy = 7; + generalSettingsPanelConstraints.gridy = 5; generalSettingsPanel.add(eventingStorageCollectionComboBox, generalSettingsPanelConstraints); - // Eventing Storage help label - helpLabel3 = new JBLabel( - "Please specify a location to store Eventing data. User should have read/write permission on this keyspace"); - helpLabel3.setForeground(JBColor.GRAY); - generalSettingsPanelConstraints.gridx = 0; - generalSettingsPanelConstraints.gridy = 8; - generalSettingsPanelConstraints.gridwidth = 3; - generalSettingsPanel.add(helpLabel3, generalSettingsPanelConstraints); - // Function Name label and text field functionNameLabel = new JBLabel("Function Name"); functionNameLabel.setFont(functionNameLabel.getFont().deriveFont(Font.BOLD)); generalSettingsPanelConstraints.gridx = 0; - generalSettingsPanelConstraints.gridy = 9; + generalSettingsPanelConstraints.gridy = 6; generalSettingsPanel.add(functionNameLabel, generalSettingsPanelConstraints); - JBTextField functionNameField = new JBTextField(20); + functionNameField = new JBTextField(20); functionNameField.setToolTipText("Enter the name of the function."); generalSettingsPanelConstraints.gridx = 0; - generalSettingsPanelConstraints.gridy = 10; + generalSettingsPanelConstraints.gridy = 7; + generalSettingsPanelConstraints.gridwidth = 3; generalSettingsPanel.add(functionNameField, generalSettingsPanelConstraints); + // Add a focus listener to the functionNameField + functionNameField.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + validateForm(); // Validate the form for error generation + // Validate the function name + if (!validateFunctionName()) { + // Function name is invalid, so set the border and label to red + functionNameField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + functionNameLabel.setForeground(Color.decode("#FF4444")); + } else { + // Function name is valid, so set the border and label back to their normal + // state + functionNameField.setBorder(UIManager.getBorder("TextField.border")); + functionNameLabel.setForeground(UIManager.getColor("Label.foreground")); + } + } + }); + // Deployment Feed Boundary label and combo box deploymentFeedBoundaryLabel = new JBLabel("Deployment Feed Boundary"); @@ -235,7 +222,7 @@ public GeneralSettings() { deploymentFeedBoundaryLabel.setToolTipText( "The preferred Deployment time Feed Boundary for the function."); generalSettingsPanelConstraints.gridx = 0; - generalSettingsPanelConstraints.gridy = 11; + generalSettingsPanelConstraints.gridy = 8; generalSettingsPanel.add(deploymentFeedBoundaryLabel, generalSettingsPanelConstraints); deploymentFeedBoundaryComboBox = new JComboBox<>(); @@ -245,14 +232,14 @@ public GeneralSettings() { "The preferred Deployment time Feed Boundary for the function."); generalSettingsPanelConstraints.gridx = 0; - generalSettingsPanelConstraints.gridy = 12; + generalSettingsPanelConstraints.gridy = 9; generalSettingsPanelConstraints.gridwidth = 3; generalSettingsPanel.add(deploymentFeedBoundaryComboBox, generalSettingsPanelConstraints); warningLabel = new JBLabel(""); warningLabel.setForeground(JBColor.ORANGE); generalSettingsPanelConstraints.gridx = 0; - generalSettingsPanelConstraints.gridy = 13; + generalSettingsPanelConstraints.gridy = 10; generalSettingsPanel.add(warningLabel, generalSettingsPanelConstraints); deploymentFeedBoundaryComboBox.addActionListener(e -> { @@ -273,26 +260,34 @@ public GeneralSettings() { descriptionLabel.setDisplayedMnemonicIndex(0); descriptionLabel.setHorizontalAlignment(JBTextField.LEFT); generalSettingsPanelConstraints.gridx = 0; - generalSettingsPanelConstraints.gridy = 14; + generalSettingsPanelConstraints.gridy = 11; generalSettingsPanel.add(descriptionLabel, generalSettingsPanelConstraints); - JBTextArea descriptionTextArea = new JBTextArea(20, 20); + JBTextArea descriptionTextArea = new JBTextArea(15, 20); descriptionTextArea.setLineWrap(true); descriptionTextArea.setWrapStyleWord(true); descriptionTextArea.setToolTipText("Enter a description for the function (optional)."); - descriptionTextArea.setPreferredSize(new Dimension(200, 200)); descriptionLabel.setLabelFor(descriptionTextArea); JBScrollPane descriptionScrollPane = new JBScrollPane(descriptionTextArea); generalSettingsPanelConstraints.gridx = 0; - generalSettingsPanelConstraints.gridy = 15; - generalSettingsPanelConstraints.fill = GridBagConstraints.BOTH; - generalSettingsPanelConstraints.weighty = 1.0; // Set weighty to a non-zero value + generalSettingsPanelConstraints.gridy = 12; + generalSettingsPanelConstraints.weighty = 1; + generalSettingsPanelConstraints.gridheight = 2; generalSettingsPanel.add(descriptionScrollPane, generalSettingsPanelConstraints); + // Create the error panel + errorPanel = new JPanel(); + errorPanel.setLayout(new BoxLayout(errorPanel, BoxLayout.Y_AXIS)); + + // Add the error panel to the generalSettingsPanel + generalSettingsPanelConstraints.gridx = 0; + generalSettingsPanelConstraints.gridy = 14; + generalSettingsPanelConstraints.gridwidth = 3; + generalSettingsPanel.add(errorPanel, generalSettingsPanelConstraints); + // Adding all the event listeners // Get the list of buckets in the cluster Map buckets = cluster.buckets().getAllBuckets(); - // Populate the bucket combo boxes functionScopeBucketComboBox.addItem("*"); listenToLocationBucketComboBox.addItem("*"); @@ -475,4 +470,31 @@ public GeneralSettings() { public JPanel getPanel() { return generalSettingsPanel; } + + private List validateForm() { + List errors = new ArrayList<>(); + + // Validate function name + if (!validateFunctionName()) { + errors.add("Function name is required."); + } + + // Update the error panel to display the validation errors + errorPanel.removeAll(); + for (String error : errors) { + JLabel errorLabel = new JLabel(error); + errorLabel.setForeground(Color.decode("#FF4444")); + errorPanel.add(errorLabel); + } + errorPanel.revalidate(); + errorPanel.repaint(); + + return errors; + } + + private boolean validateFunctionName() { + String functionName = functionNameField.getText(); + return functionName != null && !functionName.trim().isEmpty(); + } + } \ No newline at end of file From 3999c3a7731a21adf9e0247e9ce070fdd564ae59 Mon Sep 17 00:00:00 2001 From: teetangh Date: Fri, 30 Jun 2023 11:33:32 +0530 Subject: [PATCH 14/15] fixed cancel button + weightx of adavanced settings + insets for label and fields --- .../eventing/FunctionDeploymentSettings.java | 28 +++++++++++-------- .../eventing/settings/AdvancedSettings.java | 26 +++++++++++++++-- .../eventing/settings/GeneralSettings.java | 14 ++++++++-- 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java index 390cc567..a44d5636 100644 --- a/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/FunctionDeploymentSettings.java @@ -68,8 +68,8 @@ public FunctionDeploymentSettings() { // Create and configure the left panel leftPanel = new JPanel(); leftPanel.setLayout(new BorderLayout()); - leftPanel.setMaximumSize(new Dimension(200, 800)); - leftPanel.setPreferredSize(new Dimension(200, 800)); + // leftPanel.setMaximumSize(new Dimension(200, 800)); + // leftPanel.setPreferredSize(new Dimension(200, 800)); // leftPanel.setForeground(JBColor.BLACK); leftPanel.setBackground(new Color(62, 67, 76, 255)); // Jetbrains Darcula background color @@ -111,8 +111,8 @@ public Component getListCellRendererComponent(JList list, Object value, int i // Create and configure the right panel rightPanel = new JPanel(new CardLayout()); - rightPanel.setMaximumSize(new Dimension(800, 800)); - rightPanel.setPreferredSize(new Dimension(800, 800)); + // rightPanel.setMaximumSize(new Dimension(800, 800)); + // rightPanel.setPreferredSize(new Dimension(800, 800)); // Add components to the right panel GeneralSettings generalSettings = new GeneralSettings(); @@ -153,20 +153,26 @@ public Component getListCellRendererComponent(JList list, Object value, int i bottomPanel.setLayout(new BorderLayout()); bottomPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); // Add a margin of 10 pixels around the panel + // Create a new panel with a FlowLayout + JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + // Add components to the bottom panel + cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(e -> { + // Discard changes + dispose(); + }); + buttonsPanel.add(cancelButton); + applyButton = new JButton("Apply"); applyButton.addActionListener(e -> { // Save changes dispose(); }); - bottomPanel.add(applyButton, BorderLayout.EAST); + buttonsPanel.add(applyButton); - cancelButton = new JButton("Cancel"); - cancelButton.addActionListener(e -> { - // Discard changes - dispose(); - }); - bottomPanel.add(cancelButton, BorderLayout.WEST); + // Add the buttons panel to the EAST region of the bottom panel + bottomPanel.add(buttonsPanel, BorderLayout.EAST); // Add the panels to the main panel with a splitter in the middle JBSplitter splitter = new JBSplitter(false); diff --git a/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java b/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java index c6b59a41..0ab23fa7 100644 --- a/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java @@ -24,6 +24,7 @@ import com.couchbase.intellij.eventing.components.HelpIcon; import com.intellij.ui.components.JBLabel; +import com.intellij.util.ui.JBUI; public class AdvancedSettings { @@ -52,15 +53,18 @@ public class AdvancedSettings { private JFormattedTextField timerContextMaxSizeField; public AdvancedSettings() { + // Advanced Settings panel advancedSettingsPanel = new JPanel(); advancedSettingsPanel.setLayout(new GridBagLayout()); + GridBagConstraints advancedSettingsPanelConstraints = new GridBagConstraints(); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 0; + advancedSettingsPanelConstraints.weightx = 1; + advancedSettingsPanelConstraints.insets = JBUI.insets(5, 5, 5, 5); advancedSettingsPanelConstraints.anchor = GridBagConstraints.NORTHWEST; - advancedSettingsPanelConstraints.insets = new Insets(5, 5, 5, 5); advancedSettingsPanelConstraints.fill = GridBagConstraints.HORIZONTAL; // Add components to the Advanced Settings panel @@ -74,6 +78,7 @@ public AdvancedSettings() { .add(HelpIcon.createHelpIcon("Granularity of system events being captured in the log")); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 0; + advancedSettingsPanelConstraints.insets = JBUI.insets(5, 2, 2, 2); // Change the top inset to be larger advancedSettingsPanel.add(systemLogLevelPanel, advancedSettingsPanelConstraints); systemLogLevelComboBox = new JComboBox<>(); @@ -84,6 +89,8 @@ public AdvancedSettings() { systemLogLevelComboBox.addItem("Trace"); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 1; + advancedSettingsPanelConstraints.insets = JBUI.insets(2, 2, 5, 2); // Change the bottom inset to be + // larger advancedSettingsPanel.add(systemLogLevelComboBox, advancedSettingsPanelConstraints); n1qlConsistencyLabel = new JBLabel("N1QL Consistency"); @@ -96,6 +103,7 @@ public AdvancedSettings() { .add(HelpIcon.createHelpIcon("Consistency level of N1QL statements in the function:")); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 3; + advancedSettingsPanelConstraints.insets = JBUI.insets(5, 2, 2, 2); // Change the top inset to be larger advancedSettingsPanel.add(n1qlConsistencyPanel, advancedSettingsPanelConstraints); n1qlConsistencyComboBox = new JComboBox<>(); @@ -103,7 +111,8 @@ public AdvancedSettings() { n1qlConsistencyComboBox.addItem("Request"); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 4; - + advancedSettingsPanelConstraints.insets = JBUI.insets(2, 2, 5, 2); // Change the bottom inset to be + // larger advancedSettingsPanel.add(n1qlConsistencyComboBox, advancedSettingsPanelConstraints); workersLabel = new JBLabel("Workers"); @@ -115,6 +124,7 @@ public AdvancedSettings() { workersPanel.add(HelpIcon.createHelpIcon("Number of workers per node to process the events:")); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 5; + advancedSettingsPanelConstraints.insets = JBUI.insets(5, 2, 2, 2); // Change the top inset to be larger advancedSettingsPanel.add(workersPanel, advancedSettingsPanelConstraints); NumberFormat format = NumberFormat.getInstance(); @@ -132,6 +142,8 @@ public AdvancedSettings() { advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 6; advancedSettingsPanelConstraints.gridwidth = 3; + advancedSettingsPanelConstraints.insets = JBUI.insets(2, 2, 5, 2); // Change the bottom inset to be + // larger advancedSettingsPanel.add(workersField, advancedSettingsPanelConstraints); // Add a focus listener to the workersField @@ -161,6 +173,7 @@ public void focusLost(FocusEvent e) { languageCompatibilityPanel.add(HelpIcon.createHelpIcon("Language compatibility of the function:")); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 7; + advancedSettingsPanelConstraints.insets = JBUI.insets(5, 2, 2, 2); // Change the top inset to be larger advancedSettingsPanel.add(languageCompatibilityPanel, advancedSettingsPanelConstraints); languageCompatibilityComboBox = new JComboBox<>(); @@ -169,6 +182,8 @@ public void focusLost(FocusEvent e) { languageCompatibilityComboBox.addItem("6.6.2"); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 8; + advancedSettingsPanelConstraints.insets = JBUI.insets(2, 2, 5, 2); // Change the bottom inset to be + // larger advancedSettingsPanel.add(languageCompatibilityComboBox, advancedSettingsPanelConstraints); scriptTimeoutLabel = new JBLabel("Script Timeout"); @@ -181,6 +196,7 @@ public void focusLost(FocusEvent e) { .createHelpIcon("Time after which the Function's execution will be timed out:")); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 9; + advancedSettingsPanelConstraints.insets = JBUI.insets(5, 2, 2, 2); // Change the top inset to be larger advancedSettingsPanel.add(scriptTimeoutPanel, advancedSettingsPanelConstraints); scriptTimeoutField = new JFormattedTextField(formatter); @@ -191,6 +207,8 @@ public void focusLost(FocusEvent e) { advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 10; advancedSettingsPanelConstraints.gridwidth = 3; + advancedSettingsPanelConstraints.insets = JBUI.insets(2, 2, 5, 2); // Change the bottom inset to be + // larger advancedSettingsPanel.add(scriptTimeoutField, advancedSettingsPanelConstraints); // Add a focus listener to the scriptTimeoutField @@ -223,7 +241,9 @@ public void focusLost(FocusEvent e) { "Timer Context Size in Bytes. If the size of the Timer Context exceeds this value, the Timer Context will be cleared")); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 11; + advancedSettingsPanelConstraints.insets = JBUI.insets(5, 2, 2, 2); // Change the top inset to be larger advancedSettingsPanel.add(timerContextMaxSizePanel, advancedSettingsPanelConstraints); + timerContextMaxSizeField = new JFormattedTextField(formatter); timerContextMaxSizeField.setColumns(20); timerContextMaxSizeField.setValue(1024); @@ -231,6 +251,8 @@ public void focusLost(FocusEvent e) { .setToolTipText("Enter the maximum allowed value of the Timer Context Size in Bytes."); advancedSettingsPanelConstraints.gridx = 0; advancedSettingsPanelConstraints.gridy = 12; + advancedSettingsPanelConstraints.insets = JBUI.insets(2, 2, 5, 2); // Change the bottom inset to be + // larger advancedSettingsPanel.add(timerContextMaxSizeField, advancedSettingsPanelConstraints); // Add a focus listener to the timerContextMaxSizeField diff --git a/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java b/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java index bb88f1bf..d8f5dfd7 100644 --- a/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/settings/GeneralSettings.java @@ -5,7 +5,6 @@ import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; -import java.awt.Insets; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.util.ArrayList; @@ -33,6 +32,7 @@ import com.intellij.ui.components.JBScrollPane; import com.intellij.ui.components.JBTextArea; import com.intellij.ui.components.JBTextField; +import com.intellij.util.ui.JBUI; public class GeneralSettings { @@ -78,7 +78,6 @@ public GeneralSettings() { generalSettingsPanelConstraints.gridy = 0; generalSettingsPanelConstraints.weightx = 1.0; // generalSettingsPanelConstraints.weighty = 1.0; - generalSettingsPanelConstraints.insets = new Insets(5, 5, 5, 5); generalSettingsPanelConstraints.anchor = GridBagConstraints.NORTHWEST; generalSettingsPanelConstraints.fill = GridBagConstraints.HORIZONTAL; @@ -97,12 +96,14 @@ public GeneralSettings() { "Please specify a scope to which the function belongs. User should have Eventing Manage Scope Functions permission on this scope")); generalSettingsPanelConstraints.gridx = 0; generalSettingsPanelConstraints.gridy = 0; + generalSettingsPanelConstraints.insets = JBUI.insets(5, 2, 2, 2); // Change the top inset to be larger generalSettingsPanel.add(functionScopePanel, generalSettingsPanelConstraints); functionScopeBucketComboBox = new JComboBox<>(); // functionScopeBucketComboBox.addActionListener(e -> updateScopes()); generalSettingsPanelConstraints.gridx = 0; generalSettingsPanelConstraints.gridy = 1; + generalSettingsPanelConstraints.insets = JBUI.insets(2, 2, 5, 2); // Change the bottom inset to be larger generalSettingsPanel.add(functionScopeBucketComboBox, generalSettingsPanelConstraints); functionScopeScopeComboBox = new JComboBox<>(); @@ -125,6 +126,7 @@ public GeneralSettings() { "Please specify a source location for your function. User should have DCP Data Read permission on this keyspace")); generalSettingsPanelConstraints.gridx = 0; generalSettingsPanelConstraints.gridy = 2; + generalSettingsPanelConstraints.insets = JBUI.insets(5, 2, 2, 2); // Change the top inset to be larger generalSettingsPanel.add(listenToLocationPanel, generalSettingsPanelConstraints); listenToLocationBucketComboBox = new JComboBox<>(); @@ -132,6 +134,7 @@ public GeneralSettings() { generalSettingsPanelConstraints.gridx = 0; generalSettingsPanelConstraints.gridy = 3; generalSettingsPanelConstraints.gridwidth = 1; + generalSettingsPanelConstraints.insets = JBUI.insets(2, 2, 5, 2); // Change the bottom inset to be larger generalSettingsPanel.add(listenToLocationBucketComboBox, generalSettingsPanelConstraints); listenToLocationScopeComboBox = new JComboBox<>(); @@ -160,6 +163,7 @@ public GeneralSettings() { "Please specify a location to store Eventing data. User should have read/write permission on this keyspace")); generalSettingsPanelConstraints.gridx = 0; generalSettingsPanelConstraints.gridy = 4; + generalSettingsPanelConstraints.insets = JBUI.insets(5, 2, 2, 2); // Change the top inset to be larger generalSettingsPanel.add(eventingStoragePanel, generalSettingsPanelConstraints); eventingStorageBucketComboBox = new JComboBox<>(); @@ -167,6 +171,7 @@ public GeneralSettings() { generalSettingsPanelConstraints.gridx = 0; generalSettingsPanelConstraints.gridy = 5; generalSettingsPanelConstraints.gridwidth = 1; + generalSettingsPanelConstraints.insets = JBUI.insets(2, 2, 5, 2); // Change the bottom inset to be larger generalSettingsPanel.add(eventingStorageBucketComboBox, generalSettingsPanelConstraints); eventingStorageScopeComboBox = new JComboBox<>(); @@ -187,6 +192,7 @@ public GeneralSettings() { functionNameLabel.setFont(functionNameLabel.getFont().deriveFont(Font.BOLD)); generalSettingsPanelConstraints.gridx = 0; generalSettingsPanelConstraints.gridy = 6; + generalSettingsPanelConstraints.insets = JBUI.insets(5, 2, 2, 2); // Change the top inset to be larger generalSettingsPanel.add(functionNameLabel, generalSettingsPanelConstraints); functionNameField = new JBTextField(20); @@ -194,6 +200,7 @@ public GeneralSettings() { generalSettingsPanelConstraints.gridx = 0; generalSettingsPanelConstraints.gridy = 7; generalSettingsPanelConstraints.gridwidth = 3; + generalSettingsPanelConstraints.insets = JBUI.insets(2, 2, 5, 2); // Change the bottom inset to be larger generalSettingsPanel.add(functionNameField, generalSettingsPanelConstraints); // Add a focus listener to the functionNameField @@ -223,6 +230,7 @@ public void focusLost(FocusEvent e) { "The preferred Deployment time Feed Boundary for the function."); generalSettingsPanelConstraints.gridx = 0; generalSettingsPanelConstraints.gridy = 8; + generalSettingsPanelConstraints.insets = JBUI.insets(5, 2, 2, 2); // Change the top inset to be larger generalSettingsPanel.add(deploymentFeedBoundaryLabel, generalSettingsPanelConstraints); deploymentFeedBoundaryComboBox = new JComboBox<>(); @@ -234,6 +242,7 @@ public void focusLost(FocusEvent e) { generalSettingsPanelConstraints.gridx = 0; generalSettingsPanelConstraints.gridy = 9; generalSettingsPanelConstraints.gridwidth = 3; + generalSettingsPanelConstraints.insets = JBUI.insets(2, 2, 5, 2); // Change the bottom inset to be larger generalSettingsPanel.add(deploymentFeedBoundaryComboBox, generalSettingsPanelConstraints); warningLabel = new JBLabel(""); @@ -261,6 +270,7 @@ public void focusLost(FocusEvent e) { descriptionLabel.setHorizontalAlignment(JBTextField.LEFT); generalSettingsPanelConstraints.gridx = 0; generalSettingsPanelConstraints.gridy = 11; + generalSettingsPanelConstraints.insets = JBUI.insets(5, 2, 2, 2); // Change the top inset to be larger generalSettingsPanel.add(descriptionLabel, generalSettingsPanelConstraints); JBTextArea descriptionTextArea = new JBTextArea(15, 20); From fd7715238b488aac2c623c2ad0fbdd4b48223702 Mon Sep 17 00:00:00 2001 From: teetangh Date: Tue, 4 Jul 2023 15:06:16 +0530 Subject: [PATCH 15/15] added selective validation in binding settings --- .../eventing/settings/AdvancedSettings.java | 1 - .../eventing/settings/BindingSettings.java | 298 +++++++++++++----- 2 files changed, 220 insertions(+), 79 deletions(-) diff --git a/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java b/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java index 0ab23fa7..f350db18 100644 --- a/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/settings/AdvancedSettings.java @@ -6,7 +6,6 @@ import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; -import java.awt.Insets; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.text.NumberFormat; diff --git a/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java b/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java index 97eb01fa..bab8064b 100644 --- a/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java +++ b/src/main/java/com/couchbase/intellij/eventing/settings/BindingSettings.java @@ -16,6 +16,7 @@ import java.util.Map; import javax.swing.BorderFactory; +import javax.swing.BoxLayout; import javax.swing.DefaultListCellRenderer; import javax.swing.Icon; import javax.swing.JButton; @@ -57,11 +58,14 @@ public class BindingSettings { private JBTextField constantAliasNameField; private JBTextField constantValueField; + private JBPasswordField passwordField; + private Map separatorMap = new HashMap<>(); private List bindingTypePanels = new ArrayList<>(); // Keep track of all the aliasPanels private List aliasPanels = new ArrayList<>(); + private Map bindingTypeMap = new HashMap<>(); // Constructor public BindingSettings() { @@ -114,14 +118,6 @@ private void addBindingType() { bindingsTypeGbc.gridy = 0; bindingTypePanel.add(bindingTypeComboBox, bindingsTypeGbc); - // Create an ImageIcon from the SVG file - // ImageIcon deleteIcon = new - // ImageIcon("src/main/resources/assets/icons/delete_button.svg"); - - // Create the delete button and set its icon - - // ... - // Load the SVG icon and scale it to the desired size Icon deleteIcon = IconLoader.findIcon("./assets/icons/delete_button.svg"); int iconSize = JBUI.scale(16); // Set the desired icon size @@ -161,15 +157,17 @@ private void addBindingType() { // Create a aliasPanel to hold the alias-specific components JPanel aliasPanel = new JPanel(new GridBagLayout()); + GridBagConstraints aliasGbc = new GridBagConstraints(); aliasGbc.insets = new Insets(5, 5, 5, 5); - aliasGbc.anchor = GridBagConstraints.WEST; + aliasGbc.anchor = GridBagConstraints.NORTHWEST; aliasGbc.fill = GridBagConstraints.BOTH; + aliasGbc.weightx = 1.0; bindingsTypeGbc.gridx = 1; bindingsTypeGbc.gridy = 0; bindingsTypeGbc.gridwidth = 1; // initially set to 1, will set to 3 when a binding type is selected - bindingsTypeGbc.gridheight = 2; + bindingsTypeGbc.gridheight = 3; bindingTypePanel.add(aliasPanel, bindingsTypeGbc); // Add the aliasPanel to the list of aliasPanels @@ -217,6 +215,20 @@ public Component getListCellRendererComponent(JList list, Object value, int i } if (selectedBindingType.equals("Bucket Alias")) { + + // Create error panel + JPanel bucketAliasErrorPanel = new JPanel(); + bucketAliasErrorPanel.setLayout(new BoxLayout(bucketAliasErrorPanel, BoxLayout.Y_AXIS)); + bucketAliasErrorPanel.setPreferredSize(new Dimension(500, 50)); + + // Create error label + JLabel bucketAliasErrorLabel = new JLabel(); + bucketAliasErrorLabel.setForeground(Color.decode("#FF4444")); + bucketAliasErrorLabel.setText(""); + + // Add error label to error panel + bucketAliasErrorPanel.add(bucketAliasErrorLabel); + // Create the alias name text field bucketAliasNameField = new JBTextField(20); bucketAliasNameField.setToolTipText("Enter the alias name."); @@ -224,11 +236,13 @@ public Component getListCellRendererComponent(JList list, Object value, int i bucketAliasNameField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { - validateForm(); - if (!validateBucketAliasName()) { + validateBucketAliasForm(bucketAliasErrorPanel, bucketAliasNameField); + if (!validateBucketAliasName(bucketAliasNameField)) { bucketAliasNameField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + bucketAliasNameField.setForeground(Color.decode("#FF4444")); } else { bucketAliasNameField.setBorder(UIManager.getBorder("TextField.border")); + bucketAliasNameField.setForeground(UIManager.getColor("TextField.foreground")); } } }); @@ -286,25 +300,44 @@ public void focusLost(FocusEvent e) { aliasGbc.gridy = 2; aliasPanel.add(accessComboBox, aliasGbc); - aliasPanel.setPreferredSize(new Dimension(500, 150)); + aliasGbc.gridx = 0; + aliasGbc.gridy = 3; + aliasGbc.gridwidth = 4; + aliasPanel.add(bucketAliasErrorPanel, aliasGbc); + + aliasPanel.setPreferredSize(new Dimension(500, 180)); } else if (selectedBindingType.equals("URL Alias")) { + JPanel urlAliasErrorPanel = new JPanel(); + urlAliasErrorPanel.setLayout(new BoxLayout(urlAliasErrorPanel, BoxLayout.Y_AXIS)); + urlAliasErrorPanel.setPreferredSize(new Dimension(500, 50)); + + JLabel urlAliasErrorLabel = new JLabel(); + urlAliasErrorLabel.setForeground(Color.decode("#FF4444")); + urlAliasErrorLabel.setText(""); + + urlAliasErrorPanel.add(urlAliasErrorLabel); + urlAliasNameField = new JBTextField(20); urlAliasNameField.setToolTipText("Enter the alias name."); urlAliasNameField.getEmptyText().setText("Enter the alias name."); urlAliasNameField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { - validateForm(); - if (!validateUrlAliasName()) { + validateUrlAliasForm(urlAliasErrorPanel, null, urlAliasNameField, urlField, + usernameField, passwordField, bearerKeyField); + if (!validateUrlAliasName(urlAliasNameField)) { urlAliasNameField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + urlAliasNameField.setForeground(Color.decode("#FF4444")); } else { urlAliasNameField.setBorder(UIManager.getBorder("TextField.border")); + urlAliasNameField.setForeground(UIManager.getColor("TextField.foreground")); } } }); aliasGbc.gridx = 0; aliasGbc.gridy = 0; + aliasGbc.gridwidth = 1; aliasPanel.add(urlAliasNameField, aliasGbc); urlField = new JBTextField(20); @@ -313,28 +346,34 @@ public void focusLost(FocusEvent e) { urlField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { - validateForm(); - if (!validateUrl()) { + validateUrlAliasForm(urlAliasErrorPanel, null, urlAliasNameField, urlField, + usernameField, passwordField, bearerKeyField); + if (!validateUrl(urlField)) { urlField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + urlField.setForeground(Color.decode("#FF4444")); } else { urlField.setBorder(UIManager.getBorder("TextField.border")); + urlField.setForeground(UIManager.getColor("TextField.foreground")); } } }); aliasGbc.gridx = 1; aliasGbc.gridy = 0; + aliasGbc.gridwidth = 3; aliasPanel.add(urlField, aliasGbc); JBCheckBox allowCookiesCheckBox = new JBCheckBox("Allow cookies"); allowCookiesCheckBox.setToolTipText("Allow cookies for this URL."); aliasGbc.gridx = 0; aliasGbc.gridy = 1; + aliasGbc.gridwidth = 1; aliasPanel.add(allowCookiesCheckBox, aliasGbc); JBCheckBox validateSslCertificateCheckBox = new JBCheckBox("Validate SSL certificate"); validateSslCertificateCheckBox.setToolTipText("Validate SSL certificate for this URL."); aliasGbc.gridx = 1; aliasGbc.gridy = 1; + aliasGbc.gridwidth = 1; aliasPanel.add(validateSslCertificateCheckBox, aliasGbc); JBLabel authenticationLabel = new JBLabel("Authentication"); @@ -348,6 +387,8 @@ public void focusLost(FocusEvent e) { authenticationLabel.setVerticalTextPosition(JBTextField.CENTER); aliasGbc.gridx = 0; aliasGbc.gridy = 2; + aliasGbc.gridwidth = 4; + aliasGbc.fill = GridBagConstraints.HORIZONTAL; aliasPanel.add(authenticationLabel, aliasGbc); CustomComboBox authComboBox = new CustomComboBox(); @@ -387,11 +428,14 @@ public void focusLost(FocusEvent e) { usernameField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { - validateForm(); - if (!validateUsername()) { + validateUrlAliasForm(urlAliasErrorPanel, authComboBox, urlAliasNameField, urlField, + usernameField, passwordField, bearerKeyField); + if (!validateUsername(usernameField)) { usernameField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + usernameField.setForeground(Color.decode("#FF4444")); } else { usernameField.setBorder(UIManager.getBorder("TextField.border")); + usernameField.setForeground(UIManager.getColor("TextField.foreground")); } } }); @@ -416,12 +460,26 @@ public void focusLost(FocusEvent e) { aliasGbc.gridy = 4; aliasPanel.add(passwordLabel, aliasGbc); - JBPasswordField passwordField = new JBPasswordField(); + passwordField = new JBPasswordField(); passwordField.setToolTipText( "Enter the password for basic or digest authentication."); passwordField.getEmptyText().setText("Enter the password."); passwordField.setVisible(false); passwordField.setEnabled(false); + passwordField.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent e) { + validateUrlAliasForm(urlAliasErrorPanel, authComboBox, urlAliasNameField, urlField, + usernameField, passwordField, bearerKeyField); + if (!validatePassword(passwordField)) { + passwordField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + passwordField.setForeground(Color.decode("#FF4444")); + } else { + passwordField.setBorder(UIManager.getBorder("TextField.border")); + passwordField.setForeground(UIManager.getColor("TextField.foreground")); + } + } + }); aliasGbc.gridx = 1; aliasGbc.gridy = 4; aliasPanel.add(passwordField, aliasGbc); @@ -452,19 +510,28 @@ public void focusLost(FocusEvent e) { bearerKeyField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { - validateForm(); - if (!validateBearerKey()) { + validateUrlAliasForm(urlAliasErrorPanel, authComboBox, urlAliasNameField, urlField, + usernameField, passwordField, bearerKeyField); + if (!validateBearerKey(bearerKeyField)) { bearerKeyField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + bearerKeyField.setForeground(Color.decode("#FF4444")); } else { bearerKeyField.setBorder(UIManager.getBorder("TextField.border")); + bearerKeyField.setForeground(UIManager.getColor("TextField.foreground")); } } }); aliasGbc.gridx = 1; aliasGbc.gridy = 3; // should be in the same row as usernameField aliasPanel.add(bearerKeyField, aliasGbc); - aliasPanel.setPreferredSize(new Dimension(500, 160)); + // Add the error label + aliasGbc.gridx = 0; + aliasGbc.gridy = 5; + aliasGbc.gridwidth = 4; + aliasPanel.add(urlAliasErrorPanel, aliasGbc); + + aliasPanel.setPreferredSize(new Dimension(500, 220)); authComboBox.addActionListener(ee -> { String selectedAuth = (String) authComboBox.getSelectedItem(); if (selectedAuth.equals("Basic") || selectedAuth.equals("Digest")) { @@ -482,7 +549,7 @@ public void focusLost(FocusEvent e) { bearerKeyField.setVisible(false); bearerKeyLabel.setEnabled(false); bearerKeyField.setEnabled(false); - aliasPanel.setPreferredSize(new Dimension(500, 200)); + aliasPanel.setPreferredSize(new Dimension(500, 280)); } else if (selectedAuth.equals("Bearer")) { usernameLabel.setVisible(false); usernameField.setVisible(false); @@ -498,7 +565,7 @@ public void focusLost(FocusEvent e) { bearerKeyField.setVisible(true); bearerKeyLabel.setEnabled(true); bearerKeyField.setEnabled(true); - aliasPanel.setPreferredSize(new Dimension(500, 180)); + aliasPanel.setPreferredSize(new Dimension(500, 260)); } else { usernameLabel.setVisible(false); usernameField.setVisible(false); @@ -514,13 +581,24 @@ public void focusLost(FocusEvent e) { bearerKeyField.setVisible(false); bearerKeyLabel.setEnabled(false); bearerKeyField.setEnabled(false); - aliasPanel.setPreferredSize(new Dimension(500, 160)); + aliasPanel.setPreferredSize(new Dimension(500, 240)); } }); } else if (selectedBindingType.equals("Constant Alias")) { + JPanel constantAliasErrorPanel = new JPanel(); + constantAliasErrorPanel.setLayout(new BoxLayout(constantAliasErrorPanel, BoxLayout.Y_AXIS)); + constantAliasErrorPanel.setPreferredSize(new Dimension(500, 50)); + + JLabel constantAliasErrorLabel = new JLabel(); + constantAliasErrorLabel.setForeground(Color.decode("#FF4444")); + constantAliasErrorLabel.setText(""); + + constantAliasErrorPanel.add(constantAliasErrorLabel); + JBLabel constantAliasNameLabel = new JBLabel("Alias Name:"); aliasGbc.gridx = 0; aliasGbc.gridy = 0; + aliasGbc.gridwidth = 1; aliasPanel.add(constantAliasNameLabel, aliasGbc); constantAliasNameField = new JBTextField(20); @@ -529,11 +607,13 @@ public void focusLost(FocusEvent e) { constantAliasNameField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { - validateForm(); - if (!validateConstantAliasName()) { + validateConstantAliasForm(constantAliasErrorPanel, constantAliasNameField, constantValueField); + if (!validateConstantAliasName(constantAliasNameField)) { constantAliasNameField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + constantAliasNameField.setForeground(Color.decode("#FF4444")); } else { constantAliasNameField.setBorder(UIManager.getBorder("TextField.border")); + constantAliasNameField.setForeground(UIManager.getColor("TextField.foreground")); } } }); @@ -552,11 +632,13 @@ public void focusLost(FocusEvent e) { constantValueField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { - validateForm(); - if (!validateConstantValue()) { + validateConstantAliasForm(constantAliasErrorPanel, constantAliasNameField, constantValueField); + if (!validateConstantValue(constantValueField)) { constantValueField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); + constantValueField.setForeground(Color.decode("#FF4444")); } else { constantValueField.setBorder(UIManager.getBorder("TextField.border")); + constantValueField.setForeground(UIManager.getColor("TextField.foreground")); } } }); @@ -564,8 +646,13 @@ public void focusLost(FocusEvent e) { aliasGbc.gridy = 1; aliasPanel.add(constantValueField, aliasGbc); - aliasPanel.setPreferredSize(new Dimension(500, 120)); + // Add the error label + aliasGbc.gridx = 0; + aliasGbc.gridy = 2; + aliasGbc.gridwidth = 2; + aliasPanel.add(constantAliasErrorPanel, aliasGbc); + aliasPanel.setPreferredSize(new Dimension(500, 160)); } // Repaint the alias aliasPanel to show the updated components @@ -652,90 +739,145 @@ private void rebuildBindingsPanel() { } } - // Getters and setters - public JPanel getPanel() { - return bindingsPanel; + ////////////////////////// VALIDATION ////////////////////////// + + private List validateBucketAliasForm(JPanel errorPanel, JBTextField bucketAliasNameField) { + List errors = new ArrayList<>(); + + if (!validateBucketAliasName(bucketAliasNameField)) { + errors.add("Please enter a valid bucket alias name."); + } + + // Update the error panel to display the validation errors + errorPanel.removeAll(); + for (String error : errors) { + JLabel errorLabel = new JLabel(error); + errorLabel.setForeground(Color.decode("#FF4444")); + errorPanel.add(errorLabel); + } + errorPanel.revalidate(); + errorPanel.repaint(); + + return errors; } - private void validateForm() { - // Validate all the fields in all the aliasPanels - for (JPanel aliasPanel : aliasPanels) { - if (!validateBucketAliasName()) { - bucketAliasNameField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); - } else { - bucketAliasNameField.setBorder(UIManager.getBorder("TextField.border")); - } + private List validateUrlAliasForm( + JPanel errorPanel, + CustomComboBox authComboBox, + JBTextField urlAliasNameField, + JBTextField urlField, + JBTextField usernameField, + JBPasswordField passwordField, + JBTextField bearerKeyField) { - if (!validateUrlAliasName()) { - urlAliasNameField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); - } else { - urlAliasNameField.setBorder(UIManager.getBorder("TextField.border")); - } + List errors = new ArrayList<>(); - if (!validateUrl()) { - urlField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); - } else { - urlField.setBorder(UIManager.getBorder("TextField.border")); - } + if (!validateUrlAliasName(urlAliasNameField)) { + errors.add("Please enter a valid URL alias name."); + } - if (!validateUsername()) { - usernameField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); - } else { - usernameField.setBorder(UIManager.getBorder("TextField.border")); - } + if (!validateUrl(urlField)) { + errors.add("Please enter a valid URL."); + } - if (!validateBearerKey()) { - bearerKeyField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); - } else { - bearerKeyField.setBorder(UIManager.getBorder("TextField.border")); - } + if (authComboBox != null) { + String selectedAuth = (String) authComboBox.getSelectedItem(); + if (selectedAuth.equals("Basic") || selectedAuth.equals("Digest")) { + if (!validateUsername(usernameField)) { + errors.add("Please enter a valid username."); + } - if (!validateConstantAliasName()) { - constantAliasNameField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); - } else { - constantAliasNameField.setBorder(UIManager.getBorder("TextField.border")); - } + if (!validatePassword(passwordField)) { + errors.add("Please enter a valid password."); + } - if (!validateConstantValue()) { - constantValueField.setBorder(BorderFactory.createLineBorder(Color.decode("#FF4444"))); - } else { - constantValueField.setBorder(UIManager.getBorder("TextField.border")); + } else if (selectedAuth.equals("Bearer")) { + if (!validateBearerKey(bearerKeyField)) { + errors.add("Please enter a valid bearer key."); + } } } + + // Update the error panel to display the validation errors + errorPanel.removeAll(); + for (String error : errors) { + JLabel errorLabel = new JLabel(error); + errorLabel.setForeground(Color.decode("#FF4444")); + errorPanel.add(errorLabel); + } + errorPanel.revalidate(); + errorPanel.repaint(); + + return errors; } - private boolean validateBucketAliasName() { + private List validateConstantAliasForm(JPanel errorPanel, JBTextField constantAliasNameField, + JBTextField constantValueField) { + List errors = new ArrayList<>(); + + if (!validateConstantAliasName(constantAliasNameField)) { + errors.add("Please enter a valid constant alias name."); + } + + if (!validateConstantValue(constantValueField)) { + errors.add("Please enter a valid constant value."); + } + + // Update the error panel to display the validation errors + errorPanel.removeAll(); + for (String error : errors) { + JLabel errorLabel = new JLabel(error); + errorLabel.setForeground(Color.decode("#FF4444")); + errorPanel.add(errorLabel); + } + errorPanel.revalidate(); + errorPanel.repaint(); + + return errors; + } + + private boolean validateBucketAliasName(JBTextField bucketAliasNameField) { String aliasName = bucketAliasNameField.getText(); return aliasName != null && !aliasName.trim().isEmpty(); } - private boolean validateUrlAliasName() { + private boolean validateUrlAliasName(JBTextField urlAliasNameField) { String aliasName = urlAliasNameField.getText(); return aliasName != null && !aliasName.trim().isEmpty(); } - private boolean validateUrl() { + private boolean validateUrl(JBTextField urlField) { String url = urlField.getText(); return url != null && !url.trim().isEmpty(); } - private boolean validateUsername() { + private boolean validateUsername(JBTextField usernameField) { String username = usernameField.getText(); return username != null && !username.trim().isEmpty(); } - private boolean validateBearerKey() { + private boolean validatePassword(JBPasswordField passwordField) { + String password = new String(passwordField.getPassword()); + return password != null && !password.trim().isEmpty(); + } + + private boolean validateBearerKey(JBTextField bearerKeyField) { String bearerKey = bearerKeyField.getText(); return bearerKey != null && !bearerKey.trim().isEmpty(); } - private boolean validateConstantAliasName() { + private boolean validateConstantAliasName(JBTextField constantAliasNameField) { String aliasName = constantAliasNameField.getText(); return aliasName != null && !aliasName.trim().isEmpty(); } - private boolean validateConstantValue() { + private boolean validateConstantValue(JBTextField constantValueField) { String value = constantValueField.getText(); return value != null && !value.trim().isEmpty(); } + + // Getters and setters + public JPanel getPanel() { + return bindingsPanel; + } }