Search in sources :

Example 1 with EMPTYDIR

use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.EMPTYDIR in project intellij-tekton by redhat-developer.

the class WorkspacesStep method updateWorkspaceModel.

private void updateWorkspaceModel(JPanel panel, String workspaceName, Workspace.Kind kind, String resource) {
    Workspace workspace = model.getWorkspaces().get(workspaceName);
    boolean isOptional = workspace.isOptional();
    if (kind == PVC) {
        JComboBox cmbWorkspaceTypeValues = (JComboBox) Arrays.stream(panel.getComponents()).filter(component -> "cmbWorkspaceTypeValues".equals(component.getName())).findFirst().get();
        String valueSelected = cmbWorkspaceTypeValues.getSelectedItem().toString();
        if (valueSelected.equals(NEW_PVC_TEXT)) {
            JPanel newPVCNamePanel = (JPanel) Arrays.stream(panel.getComponents()).filter(component -> "newPVCNamePanel".equals(component.getName())).findFirst().get();
            JTextField newPVCNameTextField = (JTextField) Arrays.stream(newPVCNamePanel.getComponents()).filter(component -> "txtNameNewPVC".equals(component.getName())).findFirst().get();
            String nameNewPVC = newPVCNameTextField.getText();
            newPVCNameTextField.setBorder(nameNewPVC.isEmpty() ? RED_BORDER_SHOW_ERROR : NO_BORDER);
            workspace = saveNewVolume(workspaceName, nameNewPVC, PVC, panel, isOptional);
        } else if (valueSelected.equals(NEW_VCT_TEXT)) {
            workspace = saveNewVolume(workspaceName, workspaceName + "-vct", PVC, panel, true, isOptional);
        } else {
            workspace = new Workspace(workspaceName, kind, resource);
        }
    } else if (resource.isEmpty() && !isOptional && kind != EMPTYDIR) {
        workspace = new Workspace(workspaceName, null, null, isOptional);
    } else {
        workspace = new Workspace(workspaceName, kind, resource, isOptional);
    }
    model.getWorkspaces().put(workspaceName, workspace);
    fireStateChanged();
}
Also used : Color(java.awt.Color) ActionToRunModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.ActionToRunModel) Arrays(java.util.Arrays) KIND_VCT(com.redhat.devtools.intellij.tektoncd.Constants.KIND_VCT) TIMES_PLAIN_14(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_14) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) MatteBorder(javax.swing.border.MatteBorder) NumberFormatter(javax.swing.text.NumberFormatter) Border(javax.swing.border.Border) RED_BORDER_SHOW_ERROR(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.RED_BORDER_SHOW_ERROR) ROW_DIMENSION(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.ROW_DIMENSION) ColorKey(com.intellij.openapi.editor.colors.ColorKey) Map(java.util.Map) TIMES_PLAIN_10(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_10) TIMES_PLAIN_12(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_12) JComboBox(javax.swing.JComboBox) BorderLayout(java.awt.BorderLayout) Font(java.awt.Font) BorderFactory(javax.swing.BorderFactory) BasicComboBoxRenderer(javax.swing.plaf.basic.BasicComboBoxRenderer) GridBagConstraints(java.awt.GridBagConstraints) Component(java.awt.Component) Dimension(java.awt.Dimension) List(java.util.List) EmptyBorder(javax.swing.border.EmptyBorder) PVC(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.PVC) NotNull(org.jetbrains.annotations.NotNull) GridBagLayout(java.awt.GridBagLayout) DocumentAdapter(com.intellij.ui.DocumentAdapter) CONFIGMAP(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.CONFIGMAP) JPanel(javax.swing.JPanel) NO_BORDER(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.NO_BORDER) JTextField(javax.swing.JTextField) SpinnerNumberModel(javax.swing.SpinnerNumberModel) SECRET(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.SECRET) HashMap(java.util.HashMap) ROW_DIMENSION_ERROR(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.ROW_DIMENSION_ERROR) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) DocumentEvent(javax.swing.event.DocumentEvent) MARGIN_TOP_35(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.MARGIN_TOP_35) BORDER_LABEL_NAME(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.BORDER_LABEL_NAME) ComboBox(com.intellij.openapi.ui.ComboBox) JComponent(javax.swing.JComponent) EMPTYDIR(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.EMPTYDIR) JFormattedTextField(javax.swing.JFormattedTextField) JSpinner(javax.swing.JSpinner) JList(javax.swing.JList) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace) ListCellRenderer(javax.swing.ListCellRenderer) JLabel(javax.swing.JLabel) Pair(com.intellij.openapi.util.Pair) JPanel(javax.swing.JPanel) JComboBox(javax.swing.JComboBox) JTextField(javax.swing.JTextField) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)

Example 2 with EMPTYDIR

use of com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.EMPTYDIR in project intellij-tekton by redhat-developer.

the class WorkspacesStep method addListeners.

private void addListeners(String workspace, JPanel parent, int row) {
    JComboBox cmbWorkspaceTypes = (JComboBox) Arrays.stream(parent.getComponents()).filter(component -> component.getName() != null && component.getName().equals("cmbWorkspaceTypes")).findFirst().get();
    JComboBox cmbWorkspaceTypeValues = (JComboBox) Arrays.stream(parent.getComponents()).filter(component -> component.getName() != null && component.getName().equals("cmbWorkspaceTypeValues")).findFirst().get();
    cmbWorkspaceTypes.addItemListener(itemEvent -> {
        if (itemEvent.getStateChange() == 1) {
            // when cmbWorkspaceTypes combo box value changes, a type (secret, emptyDir, pvcs ..) is chosen and cmbWorkspaceTypeValues combo box is filled with all existing resources of that kind
            hidePVCAndVCTComponents(parent);
            Workspace.Kind kindSelected = cmbWorkspaceTypes.getSelectedItem().equals("") ? null : (Workspace.Kind) cmbWorkspaceTypes.getSelectedItem();
            setCmbWorkspaceTypeValues(workspace, kindSelected, cmbWorkspaceTypeValues, row);
            String resource = getSelectedWorkspaceType(cmbWorkspaceTypeValues);
            updateWorkspaceModel(parent, workspace, kindSelected, resource);
            // reset error graphics if error occurred earlier
            if (isValid(workspace, cmbWorkspaceTypes)) {
                changeErrorTextVisibility(false);
                cmbWorkspaceTypes.setBorder(new JComboBox().getBorder());
            }
            fireStateChanged();
        }
    });
    cmbWorkspaceTypeValues.addItemListener(itemEvent -> {
        if (itemEvent.getStateChange() == 1) {
            changeErrorTextVisibility(false);
            // when wsCB combo box value changes, wsTypesCB combo box is filled with all possible options
            String itemSelected = itemEvent.getItem().toString();
            hidePVCAndVCTComponents(parent);
            if (itemSelected.equals(NEW_VCT_TEXT)) {
                changeNewVCTComponentsVisibility(parent, true);
                updateWorkspaceModel(parent, workspace, PVC, "");
            } else if (itemSelected.equals(NEW_PVC_TEXT)) {
                changeNewPVCComponentsVisibility(parent, true);
                updateWorkspaceModel(parent, workspace, PVC, "");
            } else {
                updateWorkspaceModel(parent, workspace, (Workspace.Kind) cmbWorkspaceTypes.getSelectedItem(), itemEvent.getItem().toString());
            }
            fireStateChanged();
        }
    });
}
Also used : Color(java.awt.Color) ActionToRunModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.ActionToRunModel) Arrays(java.util.Arrays) KIND_VCT(com.redhat.devtools.intellij.tektoncd.Constants.KIND_VCT) TIMES_PLAIN_14(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_14) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) MatteBorder(javax.swing.border.MatteBorder) NumberFormatter(javax.swing.text.NumberFormatter) Border(javax.swing.border.Border) RED_BORDER_SHOW_ERROR(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.RED_BORDER_SHOW_ERROR) ROW_DIMENSION(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.ROW_DIMENSION) ColorKey(com.intellij.openapi.editor.colors.ColorKey) Map(java.util.Map) TIMES_PLAIN_10(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_10) TIMES_PLAIN_12(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_12) JComboBox(javax.swing.JComboBox) BorderLayout(java.awt.BorderLayout) Font(java.awt.Font) BorderFactory(javax.swing.BorderFactory) BasicComboBoxRenderer(javax.swing.plaf.basic.BasicComboBoxRenderer) GridBagConstraints(java.awt.GridBagConstraints) Component(java.awt.Component) Dimension(java.awt.Dimension) List(java.util.List) EmptyBorder(javax.swing.border.EmptyBorder) PVC(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.PVC) NotNull(org.jetbrains.annotations.NotNull) GridBagLayout(java.awt.GridBagLayout) DocumentAdapter(com.intellij.ui.DocumentAdapter) CONFIGMAP(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.CONFIGMAP) JPanel(javax.swing.JPanel) NO_BORDER(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.NO_BORDER) JTextField(javax.swing.JTextField) SpinnerNumberModel(javax.swing.SpinnerNumberModel) SECRET(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.SECRET) HashMap(java.util.HashMap) ROW_DIMENSION_ERROR(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.ROW_DIMENSION_ERROR) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) DocumentEvent(javax.swing.event.DocumentEvent) MARGIN_TOP_35(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.MARGIN_TOP_35) BORDER_LABEL_NAME(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.BORDER_LABEL_NAME) ComboBox(com.intellij.openapi.ui.ComboBox) JComponent(javax.swing.JComponent) EMPTYDIR(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.EMPTYDIR) JFormattedTextField(javax.swing.JFormattedTextField) JSpinner(javax.swing.JSpinner) JList(javax.swing.JList) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace) ListCellRenderer(javax.swing.ListCellRenderer) JLabel(javax.swing.JLabel) Pair(com.intellij.openapi.util.Pair) JComboBox(javax.swing.JComboBox) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)

Aggregations

Strings (com.google.common.base.Strings)2 ColorKey (com.intellij.openapi.editor.colors.ColorKey)2 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)2 ComboBox (com.intellij.openapi.ui.ComboBox)2 Pair (com.intellij.openapi.util.Pair)2 DocumentAdapter (com.intellij.ui.DocumentAdapter)2 KIND_VCT (com.redhat.devtools.intellij.tektoncd.Constants.KIND_VCT)2 Workspace (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)2 CONFIGMAP (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.CONFIGMAP)2 EMPTYDIR (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.EMPTYDIR)2 PVC (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.PVC)2 SECRET (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.SECRET)2 BORDER_LABEL_NAME (com.redhat.devtools.intellij.tektoncd.ui.UIConstants.BORDER_LABEL_NAME)2 MARGIN_TOP_35 (com.redhat.devtools.intellij.tektoncd.ui.UIConstants.MARGIN_TOP_35)2 NO_BORDER (com.redhat.devtools.intellij.tektoncd.ui.UIConstants.NO_BORDER)2 RED_BORDER_SHOW_ERROR (com.redhat.devtools.intellij.tektoncd.ui.UIConstants.RED_BORDER_SHOW_ERROR)2 ROW_DIMENSION (com.redhat.devtools.intellij.tektoncd.ui.UIConstants.ROW_DIMENSION)2 ROW_DIMENSION_ERROR (com.redhat.devtools.intellij.tektoncd.ui.UIConstants.ROW_DIMENSION_ERROR)2 TIMES_PLAIN_10 (com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_10)2 TIMES_PLAIN_12 (com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_12)2