Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DA-311: Deploy as a Function #4

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6fb51ac
basic UI prototype
teetangh Jun 6, 2023
1c60c7e
added tooltip texts, fixed description area, padding, scrolling
teetangh Jun 6, 2023
c9e88a0
added support for binding types: bucket, URL, Constant with authentic…
teetangh Jun 6, 2023
496f0fe
Added Function Deployment Settings
teetangh Jun 9, 2023
595258f
Major Refactor of Code. Both FunctionDeployDialog and FunctionDeployS…
teetangh Jun 12, 2023
00aacaf
Add a horizontal seperator and refactored code in Bindings Settings
teetangh Jun 12, 2023
9b4e2ad
fixed background color issue of left scroll pane.
teetangh Jun 12, 2023
7ae3c7b
fixed card layout for the right panel + added delete functionality fo…
teetangh Jun 14, 2023
bf27a80
Merge branch 'main' into DA-311-deploy-as-a-function
teetangh Jun 14, 2023
1bd6744
Delete Run IDE with Plugin.run.xml
teetangh Jun 14, 2023
d2828f2
Added action listeners to the combo boxes
teetangh Jun 14, 2023
c2d7b10
Fixed the binding settings UI
teetangh Jun 19, 2023
5e29eb2
Merge branch 'main' into DA-311-deploy-as-a-function
teetangh Jun 20, 2023
11c6cd7
added padding on general settings and replaced delete icon with svg
teetangh Jun 21, 2023
650d491
Merge branch 'main' into DA-311-deploy-as-a-function
teetangh Jun 21, 2023
7fc0d16
Merge branch 'main' into DA-311-deploy-as-a-function
teetangh Jun 22, 2023
48d83a3
Merge branch 'main' into DA-311-deploy-as-a-function
teetangh Jun 23, 2023
bc23cfb
fixed the left and right panel size and alignments + introduced help …
teetangh Jun 29, 2023
e01bf00
Merge branch 'main' into DA-311-deploy-as-a-function
teetangh Jun 29, 2023
3999c3a
fixed cancel button + weightx of adavanced settings + insets for labe…
teetangh Jun 30, 2023
fd77152
added selective validation in binding settings
teetangh Jul 4, 2023
1f9bd92
Merge branch 'main' into DA-311-deploy-as-a-function
teetangh Jul 4, 2023
5fe6dd6
Merge branch 'main' into DA-311-deploy-as-a-function
teetangh Jul 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.couchbase.intellij.eventing;

import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Set;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

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;

public class FunctionDeploymentDialog extends DialogWrapper {
public Set<String> buckets;
private JPanel mainPanel;

private JPanel generalSettingsPanel;
private JPanel advancedSettingsPanel;
private JPanel bindingsPanel;

private boolean advancedSettingsPanelExpanded = false;

public FunctionDeploymentDialog(@Nullable Project project) {
super(project);
this.buckets = null;
setTitle("Deploy as a Couchbase Function");
setSize(1000, 1000);
setResizable(true);
init();
}

@Nullable
@Override
protected JComponent createCenterPanel() {
mainPanel = new JPanel(new GridBagLayout());
GridBagConstraints mainPanelConstraints = new GridBagConstraints();
mainPanelConstraints.anchor = GridBagConstraints.NORTHWEST;

GeneralSettings generalSettings = new GeneralSettings();
generalSettingsPanel = generalSettings.getPanel();

mainPanelConstraints.gridx = 0;
mainPanelConstraints.gridy = 0;
mainPanel.add(generalSettingsPanel, mainPanelConstraints);

// 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 mainPanel
advancedSettingsPanelExpanded = !advancedSettingsPanelExpanded;

// Show or hide the settings mainPanel based on its expanded state
if (advancedSettingsPanelExpanded) {
settingsToggleButton.setText("▼");
advancedSettingsPanel.setVisible(true);
} else {
settingsToggleButton.setText("▶");
advancedSettingsPanel.setVisible(false);
}
}
});

// 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.");

// 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);

AdvancedSettings advancedSettings = new AdvancedSettings();
advancedSettingsPanel = advancedSettings.getPanel();
advancedSettingsPanel.setVisible(false);

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
BindingSettings bindingSettings = new BindingSettings();
bindingsPanel = bindingSettings.getPanel();

mainPanelConstraints.gridx = 0;
mainPanelConstraints.gridy = 19;
mainPanel.add(bindingsPanel, mainPanelConstraints);

return new JScrollPane(mainPanel);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
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.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.JFrame;
// import javax.swing.JLabel;
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;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
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.JBSplitter;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBScrollPane;

public class FunctionDeploymentSettings extends JFrame {
private JPanel mainPanel;
private JPanel leftPanel;
private JPanel rightPanel;
private JPanel bottomPanel;
private JBLabel titleLabel;

private JPanel generalSettingsPanel;
private JPanel advancedSettingsPanel;
private JPanel bindingsPanel;

private JButton applyButton;
private JButton cancelButton;

private Map<String, Boolean> changedSettings;

public FunctionDeploymentSettings() {
// Set up the main frame
setTitle("Function Configuration");
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
// setSize(1000, 800);
setMinimumSize(new Dimension(1000, 800));
setLocationRelativeTo(null);

// Create and configure the main panel
mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
setContentPane(mainPanel);

// 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.setForeground(JBColor.BLACK);
leftPanel.setBackground(new Color(62, 67, 76, 255)); // Jetbrains Darcula background color

// Add components to the left panel
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", // General settings
"Settings", // Advanced settings
"Binding Types" // Binding settings
};
JList<String> 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
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)); // Jetbrains Darcula selection color
} else {
setBackground(new Color(62, 67, 76, 255)); // Jetbrains Darcula background color
}
setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0)); // Add left padding
return this;
}
});
JBScrollPane leftScrollPane = new JBScrollPane(settingsList);
leftScrollPane.setBorder(BorderFactory.createEmptyBorder());
leftPanel.add(leftScrollPane, BorderLayout.CENTER);

// 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(20, 20, 20, 20));
generalSettingsWrapper.setMinimumSize(new Dimension(800, 800));
rightPanel.add(generalSettingsWrapper, "General");

// Settings panel
AdvancedSettings advancedSettings = new AdvancedSettings();
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();
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()) {
String selectedValue = settingsList.getSelectedValue();
CardLayout cardLayout = (CardLayout) rightPanel.getLayout();
cardLayout.show(rightPanel, selectedValue);
}
});

// Create and configure the bottom panel
bottomPanel = new JPanel();
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();
});
buttonsPanel.add(applyButton);

// 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);
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
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", 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", true);
}

@Override
public void removeUpdate(DocumentEvent e) {
changedSettings.put("General", true);
}

@Override
public void changedUpdate(DocumentEvent e) {
changedSettings.put("General", true);
}
};
// functionNameField.getDocument().addDocumentListener(documentListener);
// descriptionTextArea.getDocument().addDocumentListener(documentListener);

// ActionListener actionListener = e -> changedSettings.put("General",
// true);
// deploymentFeedBoundaryComboBox.addActionListener(actionListener);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.couchbase.intellij.eventing.components;

import javax.swing.*;
import java.awt.*;

public class CustomComboBox extends JComboBox<String> {
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);
}
}
Loading