Search in sources :

Example 6 with Workspace

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

the class TknCli method workspaceArgsToList.

private List<String> workspaceArgsToList(Map<String, Workspace> argMap) {
    List<String> args = new ArrayList<>();
    if (argMap != null) {
        argMap.entrySet().forEach(item -> {
            String name = item.getKey();
            Workspace workspace = item.getValue();
            if (workspace.isOptional() && workspace.getKind() == null) {
                return;
            }
            args.add(FLAG_WORKSPACE);
            if (workspace.getKind() == Workspace.Kind.EMPTYDIR) {
                args.add("name=" + name + ",emptyDir=");
            } else if (workspace.getKind() == Workspace.Kind.PVC) {
                if (workspace.getItems() != null && workspace.getItems().containsKey("file")) {
                    args.add("name=" + workspace.getName() + ",volumeClaimTemplateFile=" + workspace.getItems().get("file"));
                } else {
                    args.add("name=" + workspace.getName() + ",claimName=" + workspace.getResource());
                }
            } else if (workspace.getKind() == Workspace.Kind.CONFIGMAP) {
                args.add("name=" + workspace.getName() + ",config=" + workspace.getResource());
            } else if (workspace.getKind() == Workspace.Kind.SECRET) {
                args.add("name=" + workspace.getName() + ",secret=" + workspace.getResource());
            }
        });
    }
    return args;
}
Also used : ArrayList(java.util.ArrayList) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)

Example 7 with Workspace

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

the class WorkspacesStep method setContent.

public void setContent() {
    workspacePanelMapper = new HashMap<>();
    final int[] row = { 1 };
    lblErrorText = new JLabel("Please fill all fields to proceed.");
    lblErrorText.setForeground(Color.red);
    addComponent(lblErrorText, TIMES_PLAIN_12, BORDER_LABEL_NAME, ROW_DIMENSION_ERROR, 0, 0, GridBagConstraints.PAGE_START);
    changeErrorTextVisibility(false);
    model.getWorkspaces().entrySet().forEach(ws -> {
        String workspaceName = ws.getKey();
        Workspace workspace = ws.getValue();
        int innerPanelRow = 0;
        GridBagConstraints workspacePanelConstraint = new GridBagConstraints();
        JPanel panelWrapperWorkspace = new JPanel(new GridBagLayout());
        panelWrapperWorkspace.setBackground(backgroundTheme);
        boolean optional = workspace != null && workspace.isOptional();
        String lblOptional = optional ? "<span style=\"font-family:serif;font-size:10;font-weight:normal;font-style:italic;\">(Optional)</span>" : "";
        JLabel lblWorkspaceName = createLabel(workspaceName, lblOptional, 11, "", null);
        addComponent(lblWorkspaceName, panelWrapperWorkspace, workspacePanelConstraint, null, getBottomBorder(), ROW_DIMENSION, 0, innerPanelRow, GridBagConstraints.NORTH);
        innerPanelRow += 1;
        JComboBox cmbWorkspaceTypes = createCustomCombo("cmbWorkspaceTypes", null, "", EMPTYDIR, CONFIGMAP, SECRET, PVC);
        cmbWorkspaceTypes = (JComboBox) addComponent(cmbWorkspaceTypes, panelWrapperWorkspace, workspacePanelConstraint, TIMES_PLAIN_14, null, ROW_DIMENSION, 0, innerPanelRow, GridBagConstraints.NORTH);
        Workspace.Kind typeToBeSelected = workspace == null ? null : workspace.getKind();
        cmbWorkspaceTypes.setSelectedItem(typeToBeSelected != null ? typeToBeSelected : "");
        innerPanelRow += 1;
        JComboBox cmbWorkspaceTypeValues = createCustomCombo("cmbWorkspaceTypeValues", null);
        cmbWorkspaceTypeValues = (JComboBox) addComponent(cmbWorkspaceTypeValues, panelWrapperWorkspace, workspacePanelConstraint, TIMES_PLAIN_14, null, ROW_DIMENSION, 0, innerPanelRow, GridBagConstraints.NORTH);
        setCmbWorkspaceTypeValues(workspaceName, typeToBeSelected, cmbWorkspaceTypeValues, innerPanelRow - 1);
        addListeners(workspaceName, panelWrapperWorkspace, innerPanelRow - 1);
        innerPanelRow += 1;
        JLabel lblNewPVCName = createLabel("Name:", "", 9, "lblNameNewPVC", null);
        JTextField txtNewPVCName = new JTextField("");
        txtNewPVCName.setName("txtNameNewPVC");
        txtNewPVCName.getDocument().addDocumentListener(new DocumentAdapter() {

            @Override
            protected void textChanged(@NotNull DocumentEvent e) {
                updateWorkspaceModel(panelWrapperWorkspace, workspaceName, PVC, "");
            }
        });
        JPanel newPVCNamePanel = createCompoundComponentAsPanel("newPVCNamePanel", lblNewPVCName, txtNewPVCName, null);
        addComponent(newPVCNamePanel, panelWrapperWorkspace, workspacePanelConstraint, null, NO_BORDER, ROW_DIMENSION, 0, innerPanelRow, GridBagConstraints.NORTH);
        newPVCNamePanel.setVisible(false);
        innerPanelRow += 1;
        JLabel lblNewVolumeAccessMode = createLabel("Mode:", "", 9, "lblAccessMode", null);
        JComboBox cmbNewVolumeAccessMode = createCustomCombo("cmbAccessMode", getBasicComboBoxRenderer(), Pair.create("Single User (RWO)", "ReadWriteOnce"), Pair.create("Shared Access (RWX)", "ReadWriteMany"), Pair.create("Read Only (ROX)", "ReadOnlyMany"));
        JPanel panelNewVolumeAccessMode = createCompoundComponentAsPanel("accessModePanel", lblNewVolumeAccessMode, cmbNewVolumeAccessMode, null);
        setDefaultValueInCmbWithPairs(workspace, cmbNewVolumeAccessMode, "accessMode");
        addComponent(panelNewVolumeAccessMode, panelWrapperWorkspace, workspacePanelConstraint, null, NO_BORDER, ROW_DIMENSION, 0, innerPanelRow, GridBagConstraints.NORTH);
        innerPanelRow += 1;
        JLabel lblNewVolumeSize = createLabel("Size:", "", 9, "lblSize", lblNewPVCName.getPreferredSize());
        String sizeDefaultValue = getVCTItemValue(workspace, "size");
        int sizeDefaultValueAsInteger = sizeDefaultValue.isEmpty() ? 1 : Integer.parseInt(sizeDefaultValue);
        JSpinner spinnerNewVolumeSize = new JSpinner(new SpinnerNumberModel(sizeDefaultValueAsInteger, 1, Integer.MAX_VALUE, 1));
        spinnerNewVolumeSize.setName("txtSize");
        spinnerNewVolumeSize.setEditor(new JSpinner.NumberEditor(spinnerNewVolumeSize, "#"));
        JTextField spinnerTextFieldNewVolumeSize = ((JSpinner.NumberEditor) spinnerNewVolumeSize.getEditor()).getTextField();
        spinnerTextFieldNewVolumeSize.addPropertyChangeListener(evt -> {
            if (evt.getPropertyName().equals("value")) {
                updateFormByTextFieldContent(panelWrapperWorkspace, workspaceName, spinnerTextFieldNewVolumeSize, spinnerNewVolumeSize);
            }
        });
        ((NumberFormatter) ((JFormattedTextField) spinnerTextFieldNewVolumeSize).getFormatter()).setAllowsInvalid(false);
        JComboBox cmbNewVolumeSizeMeasureUnit = createCustomCombo("cmbSizeMeasureUnit", getBasicComboBoxRenderer(), Pair.create("MB", "Mi"), Pair.create("GB", "Gi"), Pair.create("TB", "Ti"));
        setDefaultValueInCmbWithPairs(workspace, cmbNewVolumeSizeMeasureUnit, "unit");
        JPanel panelNewVolumeSize = createCompoundComponentAsPanel("sizePanel", lblNewVolumeSize, spinnerNewVolumeSize, cmbNewVolumeSizeMeasureUnit);
        addComponent(panelNewVolumeSize, panelWrapperWorkspace, workspacePanelConstraint, null, NO_BORDER, ROW_DIMENSION, 0, innerPanelRow, GridBagConstraints.NORTH);
        addComponent(panelWrapperWorkspace, null, NO_BORDER, null, 0, row[0], GridBagConstraints.NORTH);
        if (!isVCT(workspace)) {
            hidePVCAndVCTComponents(panelWrapperWorkspace);
        }
        workspacePanelMapper.put(workspaceName, panelWrapperWorkspace);
        row[0] += 1;
    });
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) DocumentAdapter(com.intellij.ui.DocumentAdapter) JTextField(javax.swing.JTextField) DocumentEvent(javax.swing.event.DocumentEvent) SpinnerNumberModel(javax.swing.SpinnerNumberModel) JSpinner(javax.swing.JSpinner) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace) NumberFormatter(javax.swing.text.NumberFormatter)

Example 8 with Workspace

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

the class WorkspacesStep method setCmbWorkspaceTypeValues.

private void setCmbWorkspaceTypeValues(String workspaceName, Workspace.Kind kind, JComboBox cmbWorkspaceTypeValues, int row) {
    cmbWorkspaceTypeValues.removeAllItems();
    if (kind == null || kind.equals(EMPTYDIR)) {
        cmbWorkspaceTypeValues.setVisible(false);
        return;
    }
    List<String> items = getResources(kind);
    if (items.isEmpty() && !kind.equals(PVC)) {
        // show message no resource exists for this type
        JLabel lblErrorText = new JLabel("There are no resources for this type in the cluster. Please select a different type.");
        lblErrorText.setForeground(Color.red);
        addComponent(lblErrorText, TIMES_PLAIN_10, MARGIN_TOP_35, ROW_DIMENSION_ERROR, 0, row, GridBagConstraints.PAGE_END);
        errorFieldsByRow.put(row, lblErrorText);
        cmbWorkspaceTypeValues.setVisible(false);
        return;
    }
    cmbWorkspaceTypeValues.setVisible(true);
    for (String item : items) {
        cmbWorkspaceTypeValues.addItem(item);
    }
    if (kind.equals(PVC)) {
        cmbWorkspaceTypeValues.insertItemAt(NEW_PVC_TEXT, 0);
        cmbWorkspaceTypeValues.insertItemAt(NEW_VCT_TEXT, 0);
    }
    Workspace workspace = model.getWorkspaces().get(workspaceName);
    if (workspace != null) {
        String resource = workspace.getKind() == kind ? model.getWorkspaces().get(workspaceName).getResource() : "";
        if (Strings.isNullOrEmpty(resource)) {
            if (kind.equals(PVC) && !workspace.getItems().isEmpty() && KIND_VCT.equals(workspace.getItems().get("type"))) {
                cmbWorkspaceTypeValues.setSelectedItem(NEW_VCT_TEXT);
                return;
            }
        } else {
            cmbWorkspaceTypeValues.setSelectedItem(resource);
            return;
        }
    }
    cmbWorkspaceTypeValues.setSelectedIndex(0);
}
Also used : JLabel(javax.swing.JLabel) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)

Example 9 with Workspace

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

the class WorkspacesStep method saveNewVolume.

private Workspace saveNewVolume(String workspaceName, String name, Workspace.Kind kind, JPanel panel, boolean isVCT, boolean isOptional) {
    JPanel accessModePanel = (JPanel) Arrays.stream(panel.getComponents()).filter(component -> "accessModePanel".equals(component.getName())).findFirst().get();
    JComboBox accessModeComboBox = (JComboBox) Arrays.stream(accessModePanel.getComponents()).filter(component -> "cmbAccessMode".equals(component.getName())).findFirst().get();
    JPanel sizePanel = (JPanel) Arrays.stream(panel.getComponents()).filter(component -> "sizePanel".equals(component.getName())).findFirst().get();
    JSpinner sizeSpinner = (JSpinner) Arrays.stream(sizePanel.getComponents()).filter(component -> "txtSize".equals(component.getName())).findFirst().get();
    JComboBox sizeUnitComboBox = (JComboBox) Arrays.stream(sizePanel.getComponents()).filter(component -> "cmbSizeMeasureUnit".equals(component.getName())).findFirst().get();
    boolean isNewItemFormValid = !name.isEmpty();
    String size = ((JSpinner.NumberEditor) sizeSpinner.getEditor()).getTextField().getText();
    if (size.isEmpty() || size.equals("0")) {
        sizeSpinner.setBorder(RED_BORDER_SHOW_ERROR);
        isNewItemFormValid = false;
    } else {
        sizeSpinner.setBorder(NO_BORDER);
    }
    if (!isNewItemFormValid) {
        return null;
    }
    Map<String, String> values = new HashMap<>();
    values.put("name", name);
    if (isVCT) {
        values.put("type", KIND_VCT);
    }
    values.put("accessMode", ((Pair) accessModeComboBox.getSelectedItem()).getSecond().toString());
    values.put("size", size);
    values.put("unit", ((Pair) sizeUnitComboBox.getSelectedItem()).getSecond().toString());
    return new Workspace(workspaceName, kind, "", values, isOptional);
}
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) HashMap(java.util.HashMap) JSpinner(javax.swing.JSpinner) Pair(com.intellij.openapi.util.Pair) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)

Example 10 with Workspace

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

the class ResourceConfigurationModel method findWorkspaces.

protected List<Workspace> findWorkspaces(String configuration) {
    List<Workspace> workspaces = new ArrayList<>();
    try {
        JsonNode workspacesNode = YAMLHelper.getValueFromYAML(configuration, new String[] { "spec", "workspaces" });
        if (workspacesNode != null) {
            for (JsonNode item : workspacesNode) {
                String name = item.has("name") ? item.get("name").asText() : "";
                boolean optional = item.has("optional") && item.get("optional").asBoolean();
                workspaces.add(new Workspace(name, null, null, optional));
            }
        }
    } catch (IOException e) {
        logger.warn(e.getLocalizedMessage(), e);
    }
    return workspaces;
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)

Aggregations

Workspace (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)19 HashMap (java.util.HashMap)11 Test (org.junit.Test)7 ExecHelper (com.redhat.devtools.intellij.common.utils.ExecHelper)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 Pair (com.intellij.openapi.util.Pair)4 DocumentAdapter (com.intellij.ui.DocumentAdapter)4 KIND_VCT (com.redhat.devtools.intellij.tektoncd.Constants.KIND_VCT)4 GridBagConstraints (java.awt.GridBagConstraints)4 GridBagLayout (java.awt.GridBagLayout)4 JComboBox (javax.swing.JComboBox)4 Strings (com.google.common.base.Strings)3 ColorKey (com.intellij.openapi.editor.colors.ColorKey)3 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)3 ComboBox (com.intellij.openapi.ui.ComboBox)3 Input (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input)3 CONFIGMAP (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace.Kind.CONFIGMAP)3