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;
}
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;
});
}
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);
}
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);
}
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;
}
Aggregations