Search in sources :

Example 91 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project dwoss by gg-net.

the class RedTapeView method initComponents.

/**
 * This method is called from within the constructor to
 * initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
private // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
void initComponents() {
    GridBagConstraints gridBagConstraints;
    jLabel1 = new JLabel();
    jScrollPane1 = new JScrollPane();
    searchResultList = new JList();
    searchCommandField = new JTextField();
    positionPanel = new JPanel();
    jLabel2 = new JLabel();
    jLabel3 = new JLabel();
    priceSumLabel = new JLabel();
    afterTaxSumLabel = new JLabel();
    jLabel4 = new JLabel();
    positionAmountLabel = new JLabel();
    positionFxPanel = new JPanel();
    documentCreationPanel = new JPanel();
    jScrollPane5 = new JScrollPane();
    documentList = new JList();
    dossierTableViewPanel = new JPanel();
    jScrollPane8 = new JScrollPane();
    customerDetailArea = new JEditorPane();
    newCustomerButton = new JButton();
    dossierButtonPanel = new JPanel();
    jPanel2 = new JPanel();
    jScrollPane4 = new JScrollPane();
    dossierCommentArea = new JTextArea();
    editCommentButton = new JButton();
    actionBar = new JToolBar();
    setLayout(new GridBagLayout());
    // NOI18N
    jLabel1.setFont(new Font("DejaVu Sans", 0, 14));
    jLabel1.setText("Kundensuche");
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
    add(jLabel1, gridBagConstraints);
    jScrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    jScrollPane1.setToolTipText("");
    jScrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    searchResultList.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED, new Color(204, 204, 255), Color.black));
    searchResultList.setModel(new AbstractListModel() {

        String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };

        public int getSize() {
            return strings.length;
        }

        public Object getElementAt(int i) {
            return strings[i];
        }
    });
    searchResultList.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent evt) {
            searchResultSelectionChanged(evt);
        }
    });
    jScrollPane1.setViewportView(searchResultList);
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = 2;
    gridBagConstraints.gridheight = 5;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weighty = 10.0;
    gridBagConstraints.insets = new Insets(45, 0, 0, 0);
    add(jScrollPane1, gridBagConstraints);
    // NOI18N
    searchCommandField.setName("");
    searchCommandField.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            searchCommandFieldActionPerformed(evt);
        }
    });
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.weightx = 2.0;
    add(searchCommandField, gridBagConstraints);
    positionPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED, new Color(204, 204, 255), Color.black), "Positionen"));
    positionPanel.setMaximumSize(new Dimension(400, 32767));
    positionPanel.setMinimumSize(new Dimension(400, 33));
    positionPanel.setPreferredSize(new Dimension(400, 33));
    jLabel2.setText("Nettosumme:");
    jLabel3.setText("Bruttosumme:");
    priceSumLabel.setPreferredSize(new Dimension(0, 15));
    afterTaxSumLabel.setPreferredSize(new Dimension(0, 15));
    jLabel4.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel4.setText("Positionen");
    positionAmountLabel.setHorizontalAlignment(SwingConstants.CENTER);
    positionFxPanel.setLayout(new BorderLayout());
    GroupLayout positionPanelLayout = new GroupLayout(positionPanel);
    positionPanel.setLayout(positionPanelLayout);
    positionPanelLayout.setHorizontalGroup(positionPanelLayout.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING, positionPanelLayout.createSequentialGroup().addGroup(positionPanelLayout.createParallelGroup(Alignment.LEADING, false).addComponent(jLabel3, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jLabel2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addPreferredGap(ComponentPlacement.UNRELATED).addGroup(positionPanelLayout.createParallelGroup(Alignment.LEADING, false).addComponent(priceSumLabel, GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE).addComponent(afterTaxSumLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addPreferredGap(ComponentPlacement.RELATED).addGroup(positionPanelLayout.createParallelGroup(Alignment.LEADING).addComponent(jLabel4, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(positionAmountLabel, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addContainerGap()).addComponent(positionFxPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
    positionPanelLayout.setVerticalGroup(positionPanelLayout.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING, positionPanelLayout.createSequentialGroup().addComponent(positionFxPanel, GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE).addPreferredGap(ComponentPlacement.RELATED).addGroup(positionPanelLayout.createParallelGroup(Alignment.LEADING).addComponent(priceSumLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(jLabel2).addComponent(jLabel4)).addPreferredGap(ComponentPlacement.RELATED).addGroup(positionPanelLayout.createParallelGroup(Alignment.LEADING).addGroup(positionPanelLayout.createParallelGroup(Alignment.BASELINE).addComponent(jLabel3).addComponent(afterTaxSumLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addComponent(positionAmountLabel, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)).addContainerGap()));
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 3;
    gridBagConstraints.gridy = 5;
    gridBagConstraints.gridwidth = 4;
    gridBagConstraints.gridheight = 10;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weighty = 5.0;
    add(positionPanel, gridBagConstraints);
    documentCreationPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED, new Color(204, 204, 255), Color.black), "Dokumente"));
    documentCreationPanel.setMaximumSize(new Dimension(400, 2147483647));
    documentCreationPanel.setMinimumSize(new Dimension(400, 14));
    // NOI18N
    documentCreationPanel.setName("");
    documentCreationPanel.setPreferredSize(new Dimension(400, 100));
    documentCreationPanel.setLayout(new GridBagLayout());
    jScrollPane5.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    documentList.setModel(new AbstractListModel() {

        String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };

        public int getSize() {
            return strings.length;
        }

        public Object getElementAt(int i) {
            return strings[i];
        }
    });
    documentList.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent evt) {
            editDocumentMouseActionPerformed(evt);
        }
    });
    documentList.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent evt) {
            documentListSelectionChanged(evt);
        }
    });
    jScrollPane5.setViewportView(documentList);
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = 2;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 0.1;
    gridBagConstraints.weighty = 0.1;
    documentCreationPanel.add(jScrollPane5, gridBagConstraints);
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 3;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = 4;
    gridBagConstraints.gridheight = 4;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weighty = 5.0;
    add(documentCreationPanel, gridBagConstraints);
    dossierTableViewPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED, new Color(204, 204, 255), Color.black));
    dossierTableViewPanel.setLayout(new BorderLayout());
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 5;
    gridBagConstraints.gridheight = 13;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 10.0;
    gridBagConstraints.weighty = 8.0;
    gridBagConstraints.insets = new Insets(7, 0, 2, 0);
    add(dossierTableViewPanel, gridBagConstraints);
    customerDetailArea.setEditable(false);
    customerDetailArea.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED, new Color(204, 204, 255), Color.black));
    // NOI18N
    customerDetailArea.setContentType("text/html");
    jScrollPane8.setViewportView(customerDetailArea);
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridheight = 4;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 10.0;
    gridBagConstraints.weighty = 10.0;
    gridBagConstraints.insets = new Insets(5, 0, 0, 0);
    add(jScrollPane8, gridBagConstraints);
    newCustomerButton.setText("Neuer Kunde");
    newCustomerButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            newCustomerButtonActionPerformed(evt);
        }
    });
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.anchor = GridBagConstraints.NORTHEAST;
    add(newCustomerButton, gridBagConstraints);
    dossierButtonPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED, new Color(204, 204, 255), Color.black), "Auftrag fortführen"));
    dossierButtonPanel.setMaximumSize(new Dimension(400, 32767));
    dossierButtonPanel.setMinimumSize(new Dimension(400, 33));
    dossierButtonPanel.setPreferredSize(new Dimension(400, 33));
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 3;
    gridBagConstraints.gridy = 15;
    gridBagConstraints.gridwidth = 4;
    gridBagConstraints.gridheight = 3;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weighty = 3.0;
    add(dossierButtonPanel, gridBagConstraints);
    jPanel2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED, new Color(204, 204, 255), Color.black)));
    jPanel2.setMaximumSize(new Dimension(300, 32767));
    jScrollPane4.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    jScrollPane4.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    dossierCommentArea.setEditable(false);
    dossierCommentArea.setColumns(20);
    dossierCommentArea.setLineWrap(true);
    dossierCommentArea.setRows(5);
    dossierCommentArea.setWrapStyleWord(true);
    dossierCommentArea.setBorder(BorderFactory.createTitledBorder(BorderFactory.createTitledBorder(""), "Bemerkungen"));
    jScrollPane4.setViewportView(dossierCommentArea);
    editCommentButton.setText("bearbeiten");
    editCommentButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            editCommentButtonActionPerformed(evt);
        }
    });
    GroupLayout jPanel2Layout = new GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(Alignment.LEADING).addComponent(jScrollPane4, GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE).addGroup(Alignment.TRAILING, jPanel2Layout.createSequentialGroup().addGap(0, 238, Short.MAX_VALUE).addComponent(editCommentButton, GroupLayout.PREFERRED_SIZE, 110, GroupLayout.PREFERRED_SIZE)));
    jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(Alignment.LEADING).addGroup(jPanel2Layout.createSequentialGroup().addComponent(jScrollPane4, GroupLayout.DEFAULT_SIZE, 377, Short.MAX_VALUE).addPreferredGap(ComponentPlacement.RELATED).addComponent(editCommentButton)));
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 5;
    gridBagConstraints.gridwidth = 2;
    gridBagConstraints.gridheight = 13;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weighty = 1.0;
    gridBagConstraints.insets = new Insets(7, 0, 2, 0);
    add(jPanel2, gridBagConstraints);
    actionBar.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));
    actionBar.setFloatable(false);
    actionBar.setRollover(true);
    actionBar.setMinimumSize(new Dimension(4, 30));
    actionBar.setPreferredSize(new Dimension(4, 30));
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.gridwidth = 5;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.insets = new Insets(5, 0, 0, 0);
    add(actionBar, gridBagConstraints);
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 92 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project gitblit by gitblit.

the class GitblitAuthority method getUI.

private Container getUI() {
    userCertificatePanel = new UserCertificatePanel(this) {

        private static final long serialVersionUID = 1L;

        @Override
        public Insets getInsets() {
            return Utils.INSETS;
        }

        @Override
        public boolean isAllowEmail() {
            return mail.isReady();
        }

        @Override
        public Date getDefaultExpiration() {
            Calendar c = Calendar.getInstance();
            c.add(Calendar.DATE, defaultDuration);
            c.set(Calendar.HOUR_OF_DAY, 0);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.SECOND, 0);
            c.set(Calendar.MILLISECOND, 0);
            return c.getTime();
        }

        @Override
        public boolean saveUser(String username, UserCertificateModel ucm) {
            return userService.updateUserModel(username, ucm.user);
        }

        @Override
        public boolean newCertificate(UserCertificateModel ucm, X509Metadata metadata, boolean sendEmail) {
            if (!prepareX509Infrastructure()) {
                return false;
            }
            Date notAfter = metadata.notAfter;
            setMetadataDefaults(metadata);
            metadata.notAfter = notAfter;
            // set user's specified OID values
            UserModel user = ucm.user;
            if (!StringUtils.isEmpty(user.organizationalUnit)) {
                metadata.oids.put("OU", user.organizationalUnit);
            }
            if (!StringUtils.isEmpty(user.organization)) {
                metadata.oids.put("O", user.organization);
            }
            if (!StringUtils.isEmpty(user.locality)) {
                metadata.oids.put("L", user.locality);
            }
            if (!StringUtils.isEmpty(user.stateProvince)) {
                metadata.oids.put("ST", user.stateProvince);
            }
            if (!StringUtils.isEmpty(user.countryCode)) {
                metadata.oids.put("C", user.countryCode);
            }
            File caKeystoreFile = new File(folder, X509Utils.CA_KEY_STORE);
            File zip = X509Utils.newClientBundle(user, metadata, caKeystoreFile, caKeystorePassword, GitblitAuthority.this);
            // save latest expiration date
            if (ucm.expires == null || metadata.notAfter.before(ucm.expires)) {
                ucm.expires = metadata.notAfter;
            }
            updateAuthorityConfig(ucm);
            // refresh user
            ucm.certs = null;
            int selectedIndex = table.getSelectedRow();
            tableModel.fireTableDataChanged();
            table.getSelectionModel().setSelectionInterval(selectedIndex, selectedIndex);
            if (sendEmail) {
                sendEmail(user, metadata, zip);
            }
            return true;
        }

        @Override
        public boolean revoke(UserCertificateModel ucm, X509Certificate cert, RevocationReason reason) {
            if (!prepareX509Infrastructure()) {
                return false;
            }
            File caRevocationList = new File(folder, X509Utils.CA_REVOCATION_LIST);
            File caKeystoreFile = new File(folder, X509Utils.CA_KEY_STORE);
            if (X509Utils.revoke(cert, reason, caRevocationList, caKeystoreFile, caKeystorePassword, GitblitAuthority.this)) {
                File certificatesConfigFile = new File(folder, X509Utils.CA_CONFIG);
                FileBasedConfig config = new FileBasedConfig(certificatesConfigFile, FS.detect());
                if (certificatesConfigFile.exists()) {
                    try {
                        config.load();
                    } catch (Exception e) {
                        Utils.showException(GitblitAuthority.this, e);
                    }
                }
                // add serial to revoked list
                ucm.revoke(cert.getSerialNumber(), reason);
                ucm.update(config);
                try {
                    config.save();
                } catch (Exception e) {
                    Utils.showException(GitblitAuthority.this, e);
                }
                // refresh user
                ucm.certs = null;
                int modelIndex = table.convertRowIndexToModel(table.getSelectedRow());
                tableModel.fireTableDataChanged();
                table.getSelectionModel().setSelectionInterval(modelIndex, modelIndex);
                return true;
            }
            return false;
        }
    };
    table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
    table.setRowSorter(defaultSorter);
    table.setDefaultRenderer(CertificateStatus.class, new CertificateStatusRenderer());
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            int row = table.getSelectedRow();
            if (row < 0) {
                return;
            }
            int modelIndex = table.convertRowIndexToModel(row);
            UserCertificateModel ucm = tableModel.get(modelIndex);
            if (ucm.certs == null) {
                ucm.certs = findCerts(folder, ucm.user.username);
            }
            userCertificatePanel.setUserCertificateModel(ucm);
        }
    });
    JPanel usersPanel = new JPanel(new BorderLayout()) {

        private static final long serialVersionUID = 1L;

        @Override
        public Insets getInsets() {
            return Utils.INSETS;
        }
    };
    usersPanel.add(new HeaderPanel(Translation.get("gb.users"), "users_16x16.png"), BorderLayout.NORTH);
    usersPanel.add(new JScrollPane(table), BorderLayout.CENTER);
    usersPanel.setMinimumSize(new Dimension(400, 10));
    certificateDefaultsButton = new JButton(new ImageIcon(getClass().getResource("/settings_16x16.png")));
    certificateDefaultsButton.setFocusable(false);
    certificateDefaultsButton.setToolTipText(Translation.get("gb.newCertificateDefaults"));
    certificateDefaultsButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            X509Metadata metadata = new X509Metadata("whocares", "whocares");
            File certificatesConfigFile = new File(folder, X509Utils.CA_CONFIG);
            FileBasedConfig config = new FileBasedConfig(certificatesConfigFile, FS.detect());
            NewCertificateConfig certificateConfig = null;
            if (certificatesConfigFile.exists()) {
                try {
                    config.load();
                } catch (Exception x) {
                    Utils.showException(GitblitAuthority.this, x);
                }
                certificateConfig = NewCertificateConfig.KEY.parse(config);
                certificateConfig.update(metadata);
            }
            InputVerifier verifier = new InputVerifier() {

                @Override
                public boolean verify(JComponent comp) {
                    boolean returnValue;
                    JTextField textField = (JTextField) comp;
                    try {
                        Integer.parseInt(textField.getText());
                        returnValue = true;
                    } catch (NumberFormatException e) {
                        returnValue = false;
                    }
                    return returnValue;
                }
            };
            JTextField siteNameTF = new JTextField(20);
            siteNameTF.setText(gitblitSettings.getString(Keys.web.siteName, "Gitblit"));
            JPanel siteNamePanel = Utils.newFieldPanel(Translation.get("gb.siteName"), siteNameTF, Translation.get("gb.siteNameDescription"));
            JTextField validityTF = new JTextField(4);
            validityTF.setInputVerifier(verifier);
            validityTF.setVerifyInputWhenFocusTarget(true);
            validityTF.setText("" + certificateConfig.duration);
            JPanel validityPanel = Utils.newFieldPanel(Translation.get("gb.validity"), validityTF, Translation.get("gb.duration.days").replace("{0}", "").trim());
            JPanel p1 = new JPanel(new GridLayout(0, 1, 5, 2));
            p1.add(siteNamePanel);
            p1.add(validityPanel);
            DefaultOidsPanel oids = new DefaultOidsPanel(metadata);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(p1, BorderLayout.NORTH);
            panel.add(oids, BorderLayout.CENTER);
            int result = JOptionPane.showConfirmDialog(GitblitAuthority.this, panel, Translation.get("gb.newCertificateDefaults"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, new ImageIcon(getClass().getResource("/settings_32x32.png")));
            if (result == JOptionPane.OK_OPTION) {
                try {
                    oids.update(metadata);
                    certificateConfig.duration = Integer.parseInt(validityTF.getText());
                    certificateConfig.store(config, metadata);
                    config.save();
                    Map<String, String> updates = new HashMap<String, String>();
                    updates.put(Keys.web.siteName, siteNameTF.getText());
                    gitblitSettings.saveSettings(updates);
                } catch (Exception e1) {
                    Utils.showException(GitblitAuthority.this, e1);
                }
            }
        }
    });
    newSSLCertificate = new JButton(new ImageIcon(getClass().getResource("/rosette_16x16.png")));
    newSSLCertificate.setFocusable(false);
    newSSLCertificate.setToolTipText(Translation.get("gb.newSSLCertificate"));
    newSSLCertificate.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Date defaultExpiration = new Date(System.currentTimeMillis() + 10 * TimeUtils.ONEYEAR);
            NewSSLCertificateDialog dialog = new NewSSLCertificateDialog(GitblitAuthority.this, defaultExpiration);
            dialog.setModal(true);
            dialog.setVisible(true);
            if (dialog.isCanceled()) {
                return;
            }
            final Date expires = dialog.getExpiration();
            final String hostname = dialog.getHostname();
            final boolean serveCertificate = dialog.isServeCertificate();
            AuthorityWorker worker = new AuthorityWorker(GitblitAuthority.this) {

                @Override
                protected Boolean doRequest() throws IOException {
                    if (!prepareX509Infrastructure()) {
                        return false;
                    }
                    // read CA private key and certificate
                    File caKeystoreFile = new File(folder, X509Utils.CA_KEY_STORE);
                    PrivateKey caPrivateKey = X509Utils.getPrivateKey(X509Utils.CA_ALIAS, caKeystoreFile, caKeystorePassword);
                    X509Certificate caCert = X509Utils.getCertificate(X509Utils.CA_ALIAS, caKeystoreFile, caKeystorePassword);
                    // generate new SSL certificate
                    X509Metadata metadata = new X509Metadata(hostname, caKeystorePassword);
                    setMetadataDefaults(metadata);
                    metadata.notAfter = expires;
                    File serverKeystoreFile = new File(folder, X509Utils.SERVER_KEY_STORE);
                    X509Certificate cert = X509Utils.newSSLCertificate(metadata, caPrivateKey, caCert, serverKeystoreFile, GitblitAuthority.this);
                    boolean hasCert = cert != null;
                    if (hasCert && serveCertificate) {
                        // update Gitblit https connector alias
                        Map<String, String> updates = new HashMap<String, String>();
                        updates.put(Keys.server.certificateAlias, metadata.commonName);
                        gitblitSettings.saveSettings(updates);
                    }
                    return hasCert;
                }

                @Override
                protected void onSuccess() {
                    if (serveCertificate) {
                        JOptionPane.showMessageDialog(GitblitAuthority.this, MessageFormat.format(Translation.get("gb.sslCertificateGeneratedRestart"), hostname), Translation.get("gb.newSSLCertificate"), JOptionPane.INFORMATION_MESSAGE);
                    } else {
                        JOptionPane.showMessageDialog(GitblitAuthority.this, MessageFormat.format(Translation.get("gb.sslCertificateGenerated"), hostname), Translation.get("gb.newSSLCertificate"), JOptionPane.INFORMATION_MESSAGE);
                    }
                }
            };
            worker.execute();
        }
    });
    JButton emailBundle = new JButton(new ImageIcon(getClass().getResource("/mail_16x16.png")));
    emailBundle.setFocusable(false);
    emailBundle.setToolTipText(Translation.get("gb.emailCertificateBundle"));
    emailBundle.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int row = table.getSelectedRow();
            if (row < 0) {
                return;
            }
            int modelIndex = table.convertRowIndexToModel(row);
            final UserCertificateModel ucm = tableModel.get(modelIndex);
            if (ArrayUtils.isEmpty(ucm.certs)) {
                JOptionPane.showMessageDialog(GitblitAuthority.this, MessageFormat.format(Translation.get("gb.pleaseGenerateClientCertificate"), ucm.user.getDisplayName()));
            }
            final File zip = new File(folder, X509Utils.CERTS + File.separator + ucm.user.username + File.separator + ucm.user.username + ".zip");
            if (!zip.exists()) {
                return;
            }
            AuthorityWorker worker = new AuthorityWorker(GitblitAuthority.this) {

                @Override
                protected Boolean doRequest() throws IOException {
                    X509Metadata metadata = new X509Metadata(ucm.user.username, "whocares");
                    metadata.serverHostname = gitblitSettings.getString(Keys.web.siteName, Constants.NAME);
                    if (StringUtils.isEmpty(metadata.serverHostname)) {
                        metadata.serverHostname = Constants.NAME;
                    }
                    metadata.userDisplayname = ucm.user.getDisplayName();
                    return sendEmail(ucm.user, metadata, zip);
                }

                @Override
                protected void onSuccess() {
                    JOptionPane.showMessageDialog(GitblitAuthority.this, MessageFormat.format(Translation.get("gb.clientCertificateBundleSent"), ucm.user.getDisplayName()));
                }
            };
            worker.execute();
        }
    });
    JButton logButton = new JButton(new ImageIcon(getClass().getResource("/script_16x16.png")));
    logButton.setFocusable(false);
    logButton.setToolTipText(Translation.get("gb.log"));
    logButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            File log = new File(folder, X509Utils.CERTS + File.separator + "log.txt");
            if (log.exists()) {
                String content = FileUtils.readContent(log, "\n");
                JTextArea textarea = new JTextArea(content);
                JScrollPane scrollPane = new JScrollPane(textarea);
                scrollPane.setPreferredSize(new Dimension(700, 400));
                JOptionPane.showMessageDialog(GitblitAuthority.this, scrollPane, log.getAbsolutePath(), JOptionPane.INFORMATION_MESSAGE);
            }
        }
    });
    final JTextField filterTextfield = new JTextField(15);
    filterTextfield.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            filterUsers(filterTextfield.getText());
        }
    });
    filterTextfield.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            filterUsers(filterTextfield.getText());
        }
    });
    JToolBar buttonControls = new JToolBar(JToolBar.HORIZONTAL);
    buttonControls.setFloatable(false);
    buttonControls.add(certificateDefaultsButton);
    buttonControls.add(newSSLCertificate);
    buttonControls.add(emailBundle);
    buttonControls.add(logButton);
    JPanel userControls = new JPanel(new FlowLayout(FlowLayout.RIGHT, Utils.MARGIN, Utils.MARGIN));
    userControls.add(new JLabel(Translation.get("gb.filter")));
    userControls.add(filterTextfield);
    JPanel topPanel = new JPanel(new BorderLayout(0, 0));
    topPanel.add(buttonControls, BorderLayout.WEST);
    topPanel.add(userControls, BorderLayout.EAST);
    JPanel leftPanel = new JPanel(new BorderLayout());
    leftPanel.add(topPanel, BorderLayout.NORTH);
    leftPanel.add(usersPanel, BorderLayout.CENTER);
    userCertificatePanel.setMinimumSize(new Dimension(375, 10));
    JLabel statusLabel = new JLabel();
    statusLabel.setHorizontalAlignment(SwingConstants.RIGHT);
    if (X509Utils.unlimitedStrength) {
        statusLabel.setText("JCE Unlimited Strength Jurisdiction Policy");
    } else {
        statusLabel.setText("JCE Standard Encryption Policy");
    }
    JPanel root = new JPanel(new BorderLayout()) {

        private static final long serialVersionUID = 1L;

        @Override
        public Insets getInsets() {
            return Utils.INSETS;
        }
    };
    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, userCertificatePanel);
    splitPane.setDividerLocation(1d);
    root.add(splitPane, BorderLayout.CENTER);
    root.add(statusLabel, BorderLayout.SOUTH);
    return root;
}
Also used : JPanel(javax.swing.JPanel) PrivateKey(java.security.PrivateKey) JTextArea(javax.swing.JTextArea) X509Metadata(com.gitblit.utils.X509Utils.X509Metadata) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) BorderLayout(java.awt.BorderLayout) X509Certificate(java.security.cert.X509Certificate) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) JSplitPane(javax.swing.JSplitPane) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) ImageIcon(javax.swing.ImageIcon) Insets(java.awt.Insets) FlowLayout(java.awt.FlowLayout) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) UserModel(com.gitblit.models.UserModel) KeyEvent(java.awt.event.KeyEvent) GridLayout(java.awt.GridLayout) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) RevocationReason(com.gitblit.utils.X509Utils.RevocationReason) JScrollPane(javax.swing.JScrollPane) Calendar(java.util.Calendar) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) IOException(java.io.IOException) JToolBar(javax.swing.JToolBar) InputVerifier(javax.swing.InputVerifier) Date(java.util.Date) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) IOException(java.io.IOException) HeaderPanel(com.gitblit.client.HeaderPanel)

Example 93 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project gitblit by gitblit.

the class FeedsPanel method initialize.

private void initialize() {
    prev = new JButton("<");
    prev.setToolTipText(Translation.get("gb.pagePrevious"));
    prev.setEnabled(false);
    prev.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            refreshFeeds(--page);
        }
    });
    next = new JButton(">");
    next.setToolTipText(Translation.get("gb.pageNext"));
    next.setEnabled(false);
    next.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            refreshFeeds(++page);
        }
    });
    JButton refreshFeeds = new JButton(Translation.get("gb.refresh"));
    refreshFeeds.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            refreshFeeds(0);
        }
    });
    final JButton viewCommit = new JButton(Translation.get("gb.view"));
    viewCommit.setEnabled(false);
    viewCommit.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            viewCommit();
        }
    });
    final JButton viewCommitDiff = new JButton(Translation.get("gb.commitdiff"));
    viewCommitDiff.setEnabled(false);
    viewCommitDiff.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            viewCommitDiff();
        }
    });
    final JButton viewTree = new JButton(Translation.get("gb.tree"));
    viewTree.setEnabled(false);
    viewTree.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            viewTree();
        }
    });
    JButton subscribeFeeds = new JButton(Translation.get("gb.subscribe") + "...");
    subscribeFeeds.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            subscribeFeeds(gitblit.getAvailableFeeds());
        }
    });
    JPanel controls = new JPanel(new FlowLayout(FlowLayout.CENTER, Utils.MARGIN, 0));
    controls.add(refreshFeeds);
    controls.add(subscribeFeeds);
    controls.add(viewCommit);
    controls.add(viewCommitDiff);
    controls.add(viewTree);
    NameRenderer nameRenderer = new NameRenderer();
    tableModel = new FeedEntryTableModel();
    header = new HeaderPanel(Translation.get("gb.activity"), "feed_16x16.png");
    table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
    defaultSorter = new TableRowSorter<FeedEntryTableModel>(tableModel);
    String name = table.getColumnName(FeedEntryTableModel.Columns.Author.ordinal());
    table.getColumn(name).setCellRenderer(nameRenderer);
    name = table.getColumnName(FeedEntryTableModel.Columns.Repository.ordinal());
    table.getColumn(name).setCellRenderer(nameRenderer);
    name = table.getColumnName(FeedEntryTableModel.Columns.Branch.ordinal());
    table.getColumn(name).setCellRenderer(new BranchRenderer());
    name = table.getColumnName(FeedEntryTableModel.Columns.Message.ordinal());
    table.getColumn(name).setCellRenderer(new MessageRenderer(gitblit));
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                if (e.isControlDown()) {
                    viewCommitDiff();
                } else {
                    viewCommit();
                }
            }
        }
    });
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            boolean singleSelection = table.getSelectedRowCount() == 1;
            viewCommit.setEnabled(singleSelection);
            viewCommitDiff.setEnabled(singleSelection);
            viewTree.setEnabled(singleSelection);
        }
    });
    repositoryChoices = new DefaultComboBoxModel();
    repositorySelector = new JComboBox(repositoryChoices);
    repositorySelector.setRenderer(nameRenderer);
    repositorySelector.setForeground(nameRenderer.getForeground());
    repositorySelector.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            // repopulate the author list based on repository selection
            // preserve author selection, if possible
            String selectedAuthor = null;
            if (authorSelector.getSelectedIndex() > -1) {
                selectedAuthor = authorSelector.getSelectedItem().toString();
            }
            updateAuthors();
            if (selectedAuthor != null) {
                if (authorChoices.getIndexOf(selectedAuthor) > -1) {
                    authorChoices.setSelectedItem(selectedAuthor);
                }
            }
            filterFeeds();
        }
    });
    authorChoices = new DefaultComboBoxModel();
    authorSelector = new JComboBox(authorChoices);
    authorSelector.setRenderer(nameRenderer);
    authorSelector.setForeground(nameRenderer.getForeground());
    authorSelector.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            filterFeeds();
        }
    });
    JPanel northControls = new JPanel(new FlowLayout(FlowLayout.LEFT, Utils.MARGIN, 0));
    northControls.add(new JLabel(Translation.get("gb.repository")));
    northControls.add(repositorySelector);
    northControls.add(new JLabel(Translation.get("gb.author")));
    northControls.add(authorSelector);
    // northControls.add(prev);
    // northControls.add(next);
    JPanel northPanel = new JPanel(new BorderLayout(0, Utils.MARGIN));
    northPanel.add(header, BorderLayout.NORTH);
    northPanel.add(northControls, BorderLayout.CENTER);
    setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    add(northPanel, BorderLayout.NORTH);
    add(new JScrollPane(table), BorderLayout.CENTER);
    add(controls, BorderLayout.SOUTH);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) MouseEvent(java.awt.event.MouseEvent) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) MouseAdapter(java.awt.event.MouseAdapter) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JLabel(javax.swing.JLabel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) BorderLayout(java.awt.BorderLayout)

Example 94 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project gitblit by gitblit.

the class SearchDialog method initialize.

private void initialize() {
    prev = new JButton("<");
    prev.setToolTipText(Translation.get("gb.pagePrevious"));
    prev.setEnabled(false);
    prev.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            search(--page);
        }
    });
    next = new JButton(">");
    next.setToolTipText(Translation.get("gb.pageNext"));
    next.setEnabled(false);
    next.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            search(++page);
        }
    });
    final JButton search = new JButton(Translation.get(isSearch ? "gb.search" : "gb.refresh"));
    search.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            search(0);
        }
    });
    final JButton viewCommit = new JButton(Translation.get("gb.view"));
    viewCommit.setEnabled(false);
    viewCommit.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            viewCommit();
        }
    });
    final JButton viewCommitDiff = new JButton(Translation.get("gb.commitdiff"));
    viewCommitDiff.setEnabled(false);
    viewCommitDiff.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            viewCommitDiff();
        }
    });
    final JButton viewTree = new JButton(Translation.get("gb.tree"));
    viewTree.setEnabled(false);
    viewTree.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            viewTree();
        }
    });
    JPanel controls = new JPanel(new FlowLayout(FlowLayout.CENTER, Utils.MARGIN, 0));
    controls.add(viewCommit);
    controls.add(viewCommitDiff);
    controls.add(viewTree);
    NameRenderer nameRenderer = new NameRenderer();
    tableModel = new FeedEntryTableModel();
    header = new HeaderPanel(Translation.get(isSearch ? "gb.search" : "gb.log"), isSearch ? "search-icon.png" : "commit_changes_16x16.png");
    table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
    String name = table.getColumnName(FeedEntryTableModel.Columns.Author.ordinal());
    table.getColumn(name).setCellRenderer(nameRenderer);
    name = table.getColumnName(FeedEntryTableModel.Columns.Repository.ordinal());
    table.getColumn(name).setCellRenderer(nameRenderer);
    name = table.getColumnName(FeedEntryTableModel.Columns.Branch.ordinal());
    table.getColumn(name).setCellRenderer(new BranchRenderer());
    name = table.getColumnName(FeedEntryTableModel.Columns.Message.ordinal());
    table.getColumn(name).setCellRenderer(new MessageRenderer());
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                if (e.isControlDown()) {
                    viewCommitDiff();
                } else {
                    viewCommit();
                }
            }
        }
    });
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            boolean singleSelection = table.getSelectedRowCount() == 1;
            viewCommit.setEnabled(singleSelection);
            viewCommitDiff.setEnabled(singleSelection);
            viewTree.setEnabled(singleSelection);
        }
    });
    repositorySelector = new JComboBox(gitblit.getRepositories().toArray());
    repositorySelector.setRenderer(nameRenderer);
    repositorySelector.setForeground(nameRenderer.getForeground());
    repositorySelector.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            // repopulate the branch list based on repository selection
            // preserve branch selection, if possible
            String selectedBranch = null;
            if (branchSelector.getSelectedIndex() > -1) {
                selectedBranch = branchSelector.getSelectedItem().toString();
            }
            updateBranches();
            if (StringUtils.isEmpty(selectedBranch)) {
                // do not select branch
                branchSelector.setSelectedIndex(-1);
            } else {
                if (branchChoices.getIndexOf(selectedBranch) > -1) {
                    // select branch
                    branchChoices.setSelectedItem(selectedBranch);
                } else {
                    // branch does not exist, do not select branch
                    branchSelector.setSelectedIndex(-1);
                }
            }
        }
    });
    branchChoices = new DefaultComboBoxModel();
    branchSelector = new JComboBox(branchChoices);
    branchSelector.setRenderer(new BranchRenderer());
    searchTypeSelector = new JComboBox(Constants.SearchType.values());
    searchTypeSelector.setSelectedItem(Constants.SearchType.COMMIT);
    maxHitsSelector = new JComboBox(new Integer[] { 25, 50, 75, 100 });
    maxHitsSelector.setSelectedIndex(0);
    searchFragment = new JTextField(25);
    searchFragment.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            search(0);
        }
    });
    JPanel queryPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, Utils.MARGIN, 0));
    queryPanel.add(new JLabel(Translation.get("gb.repository")));
    queryPanel.add(repositorySelector);
    queryPanel.add(new JLabel(Translation.get("gb.branch")));
    queryPanel.add(branchSelector);
    if (isSearch) {
        queryPanel.add(new JLabel(Translation.get("gb.type")));
        queryPanel.add(searchTypeSelector);
    }
    queryPanel.add(new JLabel(Translation.get("gb.maxHits")));
    queryPanel.add(maxHitsSelector);
    JPanel actionsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, Utils.MARGIN, 0));
    actionsPanel.add(search);
    actionsPanel.add(prev);
    actionsPanel.add(next);
    JPanel northControls = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    northControls.add(queryPanel, BorderLayout.WEST);
    if (isSearch) {
        northControls.add(searchFragment, BorderLayout.CENTER);
    }
    northControls.add(actionsPanel, BorderLayout.EAST);
    JPanel northPanel = new JPanel(new BorderLayout(0, Utils.MARGIN));
    northPanel.add(header, BorderLayout.NORTH);
    northPanel.add(northControls, BorderLayout.CENTER);
    JPanel contentPanel = new JPanel() {

        private static final long serialVersionUID = 1L;

        @Override
        public Insets getInsets() {
            return Utils.INSETS;
        }
    };
    contentPanel.setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    contentPanel.add(northPanel, BorderLayout.NORTH);
    contentPanel.add(new JScrollPane(table), BorderLayout.CENTER);
    contentPanel.add(controls, BorderLayout.SOUTH);
    setLayout(new BorderLayout());
    add(contentPanel, BorderLayout.CENTER);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowOpened(WindowEvent event) {
            if (isSearch) {
                searchFragment.requestFocus();
            } else {
                search(0);
            }
        }

        @Override
        public void windowActivated(WindowEvent event) {
            if (isSearch) {
                searchFragment.requestFocus();
            }
        }
    });
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) WindowAdapter(java.awt.event.WindowAdapter) JTextField(javax.swing.JTextField) BorderLayout(java.awt.BorderLayout) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) JComboBox(javax.swing.JComboBox) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) WindowEvent(java.awt.event.WindowEvent)

Example 95 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project gitblit by gitblit.

the class SettingsPanel method initialize.

private void initialize() {
    JButton refreshSettings = new JButton(Translation.get("gb.refresh"));
    refreshSettings.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            refreshSettings();
        }
    });
    final JButton editSetting = new JButton(Translation.get("gb.edit"));
    editSetting.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int viewRow = table.getSelectedRow();
            int modelRow = table.convertRowIndexToModel(viewRow);
            String key = tableModel.keys.get(modelRow);
            SettingModel setting = tableModel.settings.get(key);
            editSetting(setting);
        }
    });
    NameRenderer nameRenderer = new NameRenderer();
    final SettingPanel settingPanel = new SettingPanel();
    tableModel = new SettingsTableModel();
    defaultSorter = new TableRowSorter<SettingsTableModel>(tableModel);
    table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
    table.setDefaultRenderer(SettingModel.class, new SettingCellRenderer());
    String name = table.getColumnName(UsersTableModel.Columns.Name.ordinal());
    table.getColumn(name).setCellRenderer(nameRenderer);
    table.setRowSorter(defaultSorter);
    table.getRowSorter().toggleSortOrder(SettingsTableModel.Columns.Name.ordinal());
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            boolean singleSelection = table.getSelectedRows().length == 1;
            editSetting.setEnabled(singleSelection);
            if (singleSelection) {
                int viewRow = table.getSelectedRow();
                int modelRow = table.convertRowIndexToModel(viewRow);
                SettingModel setting = tableModel.get(modelRow);
                settingPanel.setSetting(setting);
            } else {
                settingPanel.clear();
            }
        }
    });
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                int viewRow = table.getSelectedRow();
                int modelRow = table.convertRowIndexToModel(viewRow);
                SettingModel setting = tableModel.get(modelRow);
                editSetting(setting);
            }
        }
    });
    filterTextfield = new JTextField();
    filterTextfield.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            filterSettings(filterTextfield.getText());
        }
    });
    filterTextfield.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            filterSettings(filterTextfield.getText());
        }
    });
    JPanel settingFilterPanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    settingFilterPanel.add(new JLabel(Translation.get("gb.filter")), BorderLayout.WEST);
    settingFilterPanel.add(filterTextfield, BorderLayout.CENTER);
    JPanel settingsTablePanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    settingsTablePanel.add(settingFilterPanel, BorderLayout.NORTH);
    settingsTablePanel.add(new JScrollPane(table), BorderLayout.CENTER);
    settingsTablePanel.add(settingPanel, BorderLayout.SOUTH);
    JPanel settingsControls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
    settingsControls.add(refreshSettings);
    settingsControls.add(editSetting);
    setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    header = new HeaderPanel(Translation.get("gb.settings"), "settings_16x16.png");
    add(header, BorderLayout.NORTH);
    add(settingsTablePanel, BorderLayout.CENTER);
    add(settingsControls, BorderLayout.SOUTH);
}
Also used : SettingModel(com.gitblit.models.SettingModel) JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) ListSelectionListener(javax.swing.event.ListSelectionListener) KeyEvent(java.awt.event.KeyEvent) ActionListener(java.awt.event.ActionListener) BorderLayout(java.awt.BorderLayout)

Aggregations

ListSelectionListener (javax.swing.event.ListSelectionListener)216 ListSelectionEvent (javax.swing.event.ListSelectionEvent)210 ActionEvent (java.awt.event.ActionEvent)90 ActionListener (java.awt.event.ActionListener)76 JScrollPane (javax.swing.JScrollPane)72 JPanel (javax.swing.JPanel)67 JButton (javax.swing.JButton)61 BorderLayout (java.awt.BorderLayout)53 MouseEvent (java.awt.event.MouseEvent)47 Dimension (java.awt.Dimension)44 JLabel (javax.swing.JLabel)40 MouseAdapter (java.awt.event.MouseAdapter)37 JTable (javax.swing.JTable)36 FlowLayout (java.awt.FlowLayout)28 Insets (java.awt.Insets)28 JList (javax.swing.JList)27 List (java.util.List)24 ArrayList (java.util.ArrayList)22 KeyEvent (java.awt.event.KeyEvent)21 GridBagConstraints (java.awt.GridBagConstraints)20