Search in sources :

Example 1 with TableRendersupport

use of com.mercedesbenz.sechub.developertools.admin.ui.TableRendersupport in project sechub by mercedes-benz.

the class ExecutionProfileDialogUI method createMainPanel.

private void createMainPanel() {
    mainPanel = new JPanel(new GridBagLayout());
    int row = 0;
    /* id */
    idTextField = new JTextField(profile.id);
    mainPanel.add(new JLabel("Id"), createLabelConstraint(row));
    mainPanel.add(idTextField, createComponentConstraint(row++));
    if (idEditAllowed) {
        idTextField.setBorder(BorderFactory.createLineBorder(Color.ORANGE, 2));
        idTextField.setToolTipText("mandatory field");
    } else {
        idTextField.setEditable(false);
    }
    descriptionTextArea = new JTextArea(profile.description);
    mainPanel.add(new JLabel("Description"), createLabelConstraint(row));
    mainPanel.add(descriptionTextArea, createComponentConstraint(row++));
    /* enabled */
    enabledCheckBox = new JCheckBox("", profile.enabled);
    mainPanel.add(new JLabel("Enabled"), createLabelConstraint(row));
    mainPanel.add(enabledCheckBox, createComponentConstraint(row++));
    /* configurations */
    model = new DefaultTableModel() {

        private static final long serialVersionUID = 1L;

        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    model.addColumn("Executor config name");
    model.addColumn("enabled");
    model.addColumn("uuid");
    configurationTable = new JTable(model);
    configurationTable.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() > 1) {
                int row = configurationTable.getSelectedRow();
                Object selectedValue = model.getValueAt(row, 2);
                if (selectedValue instanceof UUID) {
                    UUID uuid = (UUID) selectedValue;
                    boolean changed = editConfigurationAction.executeDirectly(uuid);
                    if (!changed) {
                        return;
                    }
                    reloadChangedDataIntoLocalProfile(uuid);
                } else {
                    throw new IllegalStateException("not a uuid:" + selectedValue);
                }
            }
        }

        private void reloadChangedDataIntoLocalProfile(UUID uuid) {
            TestExecutorConfig found = null;
            for (TestExecutorConfig config : profile.configurations) {
                if (uuid.equals(config.uuid)) {
                    found = config;
                    break;
                }
            }
            if (found == null) {
                getContext().getOutputUI().error("Did not found config again with uuid:" + uuid);
                return;
            }
            profile.configurations.remove(found);
            TestExecutorConfig newConfig = getContext().getAdministration().fetchExecutorConfiguration(uuid);
            profile.configurations.add(newConfig);
            rebuildTableModelRows();
        }
    });
    rebuildTableModelRows();
    if (model.getRowCount() > 0) {
        configurationTable.setRowSelectionInterval(0, 0);
    }
    new TableRendersupport().addStandardTableCellRender(configurationTable);
    GridBagConstraints tableConstraint = createComponentConstraint(row++);
    tableConstraint.gridx = 0;
    tableConstraint.gridwidth++;
    tableConstraint.weighty = 0.5;
    JScrollPane tableScrollPane = new JScrollPane(configurationTable);
    tableScrollPane.setPreferredSize(new Dimension(600, 200));
    mainPanel.add(tableScrollPane, tableConstraint);
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());
    buttonPanel.add(new JButton(new AddConfigAction()));
    buttonPanel.add(new JButton(new RemoveConfigAction()));
    mainPanel.add(buttonPanel, createComponentConstraint(row++));
    /* project ids - label */
    projectIdsLabel = new JLabel();
    GridBagConstraints projectIdLabelConstraint = createComponentConstraint(row++);
    projectIdLabelConstraint.ipady = 0;
    projectIdLabelConstraint.gridx = 0;
    projectIdLabelConstraint.gridwidth++;
    mainPanel.add(projectIdsLabel, projectIdLabelConstraint);
    /* text area for project ids */
    projectIdsTextArea = new JTextArea();
    projectIdsTextArea.setLineWrap(true);
    projectIdsTextArea.setEditable(false);
    projectIdsTextArea.setColumns(200);
    GridBagConstraints textAreaConstraint = createComponentConstraint(row++);
    textAreaConstraint.gridx = 0;
    textAreaConstraint.gridwidth++;
    textAreaConstraint.weighty = 0.5;
    JScrollPane textAreaScrollPane = new JScrollPane(projectIdsTextArea);
    textAreaScrollPane.setPreferredSize(new Dimension(600, 200));
    mainPanel.add(textAreaScrollPane, textAreaConstraint);
    updateProjectIdsAtUI();
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) JTextArea(javax.swing.JTextArea) FlowLayout(java.awt.FlowLayout) GridBagLayout(java.awt.GridBagLayout) DefaultTableModel(javax.swing.table.DefaultTableModel) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) UUID(java.util.UUID) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) TestExecutorConfig(com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JCheckBox(javax.swing.JCheckBox) TableRendersupport(com.mercedesbenz.sechub.developertools.admin.ui.TableRendersupport) JTable(javax.swing.JTable)

Aggregations

TableRendersupport (com.mercedesbenz.sechub.developertools.admin.ui.TableRendersupport)1 TestExecutorConfig (com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig)1 Dimension (java.awt.Dimension)1 FlowLayout (java.awt.FlowLayout)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 UUID (java.util.UUID)1 JButton (javax.swing.JButton)1 JCheckBox (javax.swing.JCheckBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JTable (javax.swing.JTable)1 JTextArea (javax.swing.JTextArea)1 JTextField (javax.swing.JTextField)1 DefaultTableModel (javax.swing.table.DefaultTableModel)1