| | |
| | | import javax.swing.event.ListSelectionEvent;
|
| | | import javax.swing.event.ListSelectionListener;
|
| | |
|
| | | /**
|
| | | * Displays a list of registrations and allows management of server
|
| | | * registrations.
|
| | | * |
| | | * @author James Moger
|
| | | * |
| | | */
|
| | | public class RegistrationsDialog extends JDialog {
|
| | |
|
| | | interface RegistrationListener {
|
| | | boolean deleteRegistrations(List<GitblitRegistration> list);
|
| | |
|
| | | void loginPrompt(GitblitRegistration reg);
|
| | |
|
| | | void login(GitblitRegistration reg);
|
| | |
|
| | | boolean saveRegistration(String name, GitblitRegistration reg);
|
| | |
|
| | | boolean deleteRegistrations(List<GitblitRegistration> list);
|
| | | }
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
| | |
|
| | | private JTable registrationsTable;
|
| | |
|
| | | private RegistrationsModel model;
|
| | | private RegistrationsTableModel model;
|
| | |
|
| | | public RegistrationsDialog(List<GitblitRegistration> registrations,
|
| | | RegistrationListener listener) {
|
| | |
| | |
|
| | | private void initialize() {
|
| | | NameRenderer nameRenderer = new NameRenderer();
|
| | | model = new RegistrationsModel(registrations);
|
| | | registrationsTable = Utils.newTable(model);
|
| | | model = new RegistrationsTableModel(registrations);
|
| | | registrationsTable = Utils.newTable(model, Utils.DATE_FORMAT);
|
| | | registrationsTable.setRowHeight(nameRenderer.getFont().getSize() + 8);
|
| | |
|
| | | String id = registrationsTable.getColumnName(RegistrationsModel.Columns.Name.ordinal());
|
| | | String id = registrationsTable
|
| | | .getColumnName(RegistrationsTableModel.Columns.Name.ordinal());
|
| | | registrationsTable.getColumn(id).setCellRenderer(nameRenderer);
|
| | | registrationsTable.addMouseListener(new MouseAdapter() {
|
| | | public void mouseClicked(MouseEvent e) {
|
| | | if (e.getClickCount() == 2) {
|
| | | login(false);
|
| | | login();
|
| | | }
|
| | | }
|
| | | });
|
| | |
| | | final JButton create = new JButton(Translation.get("gb.create"));
|
| | | create.addActionListener(new ActionListener() {
|
| | | public void actionPerformed(ActionEvent event) {
|
| | | RegistrationsDialog.this.setVisible(false);
|
| | | listener.loginPrompt(GitblitRegistration.LOCALHOST);
|
| | | create();
|
| | | }
|
| | | });
|
| | |
|
| | |
| | | login.setEnabled(false);
|
| | | login.addActionListener(new ActionListener() {
|
| | | public void actionPerformed(ActionEvent event) {
|
| | | login(false);
|
| | | login();
|
| | | }
|
| | | });
|
| | |
|
| | | final JButton loginPrompt = new JButton(Translation.get("gb.login") + "...");
|
| | | loginPrompt.setEnabled(false);
|
| | | loginPrompt.addActionListener(new ActionListener() {
|
| | | final JButton edit = new JButton(Translation.get("gb.edit"));
|
| | | edit.setEnabled(false);
|
| | | edit.addActionListener(new ActionListener() {
|
| | | public void actionPerformed(ActionEvent event) {
|
| | | login(true);
|
| | | edit();
|
| | | }
|
| | | });
|
| | |
|
| | |
| | | boolean singleSelection = registrationsTable.getSelectedRowCount() == 1;
|
| | | boolean selected = registrationsTable.getSelectedRow() > -1;
|
| | | login.setEnabled(singleSelection);
|
| | | loginPrompt.setEnabled(singleSelection);
|
| | | edit.setEnabled(singleSelection);
|
| | | delete.setEnabled(selected);
|
| | | }
|
| | | });
|
| | |
| | | JPanel controls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
|
| | | controls.add(create);
|
| | | controls.add(login);
|
| | | controls.add(loginPrompt);
|
| | | controls.add(edit);
|
| | | controls.add(delete);
|
| | |
|
| | | final Insets insets = new Insets(5, 5, 5, 5);
|
| | |
| | | return insets;
|
| | | }
|
| | | };
|
| | | centerPanel.add(new HeaderPanel(Translation.get("gb.servers"), null), BorderLayout.NORTH);
|
| | | centerPanel.add(new JScrollPane(registrationsTable), BorderLayout.CENTER);
|
| | | centerPanel.add(controls, BorderLayout.SOUTH);
|
| | |
|
| | |
| | | getContentPane().add(centerPanel, BorderLayout.CENTER);
|
| | | }
|
| | |
|
| | | private void login(boolean prompt) {
|
| | | private void login() {
|
| | | int viewRow = registrationsTable.getSelectedRow();
|
| | | int modelRow = registrationsTable.convertRowIndexToModel(viewRow);
|
| | | GitblitRegistration reg = registrations.get(modelRow);
|
| | | RegistrationsDialog.this.setVisible(false);
|
| | | if (prompt) {
|
| | | listener.loginPrompt(reg);
|
| | | } else {
|
| | | listener.login(reg);
|
| | | listener.login(reg);
|
| | | }
|
| | |
|
| | | private void create() {
|
| | | EditRegistrationDialog dialog = new EditRegistrationDialog(getOwner());
|
| | | dialog.setLocationRelativeTo(this);
|
| | | dialog.setVisible(true);
|
| | | GitblitRegistration reg = dialog.getRegistration();
|
| | | if (reg == null) {
|
| | | return;
|
| | | }
|
| | | if (listener.saveRegistration(reg.name, reg)) {
|
| | | model.list.add(reg);
|
| | | model.fireTableDataChanged();
|
| | | }
|
| | | }
|
| | |
|
| | | private void edit() {
|
| | | int viewRow = registrationsTable.getSelectedRow();
|
| | | int modelRow = registrationsTable.convertRowIndexToModel(viewRow);
|
| | | GitblitRegistration reg = registrations.get(modelRow);
|
| | | String originalName = reg.name;
|
| | | EditRegistrationDialog dialog = new EditRegistrationDialog(getOwner(), reg, false);
|
| | | dialog.setLocationRelativeTo(this);
|
| | | dialog.setVisible(true);
|
| | | reg = dialog.getRegistration();
|
| | | if (reg == null) {
|
| | | return;
|
| | | }
|
| | | if (listener.saveRegistration(originalName, reg)) {
|
| | | model.fireTableDataChanged();
|
| | | }
|
| | | }
|
| | |
|