import java.awt.Insets;\r
import java.awt.event.ActionEvent;\r
import java.awt.event.ActionListener;\r
+import java.awt.event.KeyEvent;\r
import java.text.MessageFormat;\r
import java.util.ArrayList;\r
import java.util.Arrays;\r
import javax.swing.JList;\r
import javax.swing.JOptionPane;\r
import javax.swing.JPanel;\r
+import javax.swing.JRootPane;\r
import javax.swing.JTabbedPane;\r
import javax.swing.JTextField;\r
+import javax.swing.KeyStroke;\r
import javax.swing.ListCellRenderer;\r
\r
import com.gitblit.Constants.AccessRestrictionType;\r
setTitle(Translation.get("gb.edit") + ": " + aRepository.name);\r
setIconImage(new ImageIcon(getClass().getResource("/gitblt-favicon.png")).getImage());\r
}\r
+ \r
+ @Override\r
+ protected JRootPane createRootPane() {\r
+ KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);\r
+ JRootPane rootPane = new JRootPane();\r
+ rootPane.registerKeyboardAction(new ActionListener() {\r
+ public void actionPerformed(ActionEvent actionEvent) {\r
+ setVisible(false);\r
+ }\r
+ }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);\r
+ return rootPane;\r
+ }\r
\r
private void initialize(RepositoryModel anRepository) {\r
nameField = new JTextField(anRepository.name == null ? "" : anRepository.name, 35);\r
getContentPane().setLayout(new BorderLayout(5, 5));\r
getContentPane().add(centerPanel, BorderLayout.CENTER);\r
pack();\r
- setLocationRelativeTo(null);\r
}\r
\r
private JPanel newFieldPanel(String label, JComponent comp) {\r
import java.awt.Insets;\r
import java.awt.event.ActionEvent;\r
import java.awt.event.ActionListener;\r
+import java.awt.event.KeyEvent;\r
import java.text.MessageFormat;\r
import java.util.ArrayList;\r
import java.util.Arrays;\r
import javax.swing.JOptionPane;\r
import javax.swing.JPanel;\r
import javax.swing.JPasswordField;\r
+import javax.swing.JRootPane;\r
import javax.swing.JTextField;\r
+import javax.swing.KeyStroke;\r
\r
import com.gitblit.Constants.AccessRestrictionType;\r
import com.gitblit.IStoredSettings;\r
setTitle(Translation.get("gb.edit") + ": " + anUser.username);\r
setIconImage(new ImageIcon(getClass().getResource("/gitblt-favicon.png")).getImage());\r
}\r
+ \r
+ @Override\r
+ protected JRootPane createRootPane() {\r
+ KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);\r
+ JRootPane rootPane = new JRootPane();\r
+ rootPane.registerKeyboardAction(new ActionListener() {\r
+ public void actionPerformed(ActionEvent actionEvent) {\r
+ setVisible(false);\r
+ }\r
+ }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);\r
+ return rootPane;\r
+ }\r
\r
private void initialize(UserModel anUser) {\r
usernameField = new JTextField(anUser.username == null ? "" : anUser.username, 25);\r
getContentPane().setLayout(new BorderLayout(5, 5));\r
getContentPane().add(centerPanel, BorderLayout.CENTER);\r
pack();\r
- setLocationRelativeTo(null);\r
}\r
\r
private JPanel newFieldPanel(String label, JComponent comp) {\r
package com.gitblit.client;\r
\r
import java.awt.BorderLayout;\r
+import java.awt.Cursor;\r
import java.awt.Dimension;\r
import java.awt.EventQueue;\r
import java.awt.Font;\r
import java.io.File;\r
import java.io.IOException;\r
import java.text.MessageFormat;\r
+import java.text.SimpleDateFormat;\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.Comparator;\r
+import java.util.Date;\r
import java.util.LinkedHashMap;\r
+import java.util.List;\r
+import java.util.Locale;\r
import java.util.Map;\r
import java.util.Set;\r
+import java.util.TimeZone;\r
\r
import javax.swing.ImageIcon;\r
import javax.swing.JFrame;\r
import javax.swing.JTabbedPane;\r
import javax.swing.JTextField;\r
import javax.swing.KeyStroke;\r
+import javax.swing.SwingWorker;\r
import javax.swing.UIManager;\r
\r
import org.eclipse.jgit.errors.ConfigInvalidException;\r
* @author James Moger\r
* \r
*/\r
-public class GitblitManager extends JFrame {\r
+public class GitblitManager extends JFrame implements RegistrationsDialog.RegistrationListener {\r
\r
private static final long serialVersionUID = 1L;\r
+ private final SimpleDateFormat dateFormat;\r
private JTabbedPane serverTabs;\r
private File configFile = new File(System.getProperty("user.home"), ".gitblit/config");\r
- private GitblitRegistration localhost = new GitblitRegistration("default",\r
- "https://localhost:8443", "admin", "admin".toCharArray());\r
\r
private Map<String, GitblitRegistration> registrations = new LinkedHashMap<String, GitblitRegistration>();\r
private JMenu recentMenu;\r
+ private int maxRecentCount = 5;\r
\r
private GitblitManager() {\r
super();\r
+ dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);\r
+ dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));\r
}\r
\r
private void initialize() {\r
}\r
}\r
\r
- public void setVisible(boolean value) {\r
- if (value) {\r
- if (registrations.size() == 0) {\r
- // default prompt\r
- loginPrompt(localhost);\r
- } else if (registrations.size() == 1) {\r
- // single registration prompt\r
- GitblitRegistration reg = registrations.values().iterator().next();\r
- loginPrompt(reg);\r
- }\r
- super.setVisible(value);\r
- }\r
- }\r
-\r
private JMenuBar setupMenu() {\r
JMenuBar menuBar = new JMenuBar();\r
JMenu serversMenu = new JMenu(Translation.get("gb.servers"));\r
menuBar.add(serversMenu);\r
recentMenu = new JMenu(Translation.get("gb.recent"));\r
serversMenu.add(recentMenu);\r
+\r
+ JMenuItem manage = new JMenuItem(Translation.get("gb.manage") + "...");\r
+ manage.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, KeyEvent.CTRL_DOWN_MASK, false));\r
+ manage.addActionListener(new ActionListener() {\r
+ public void actionPerformed(ActionEvent event) {\r
+ manageRegistrations();\r
+ }\r
+ });\r
+ serversMenu.add(manage);\r
+\r
JMenuItem login = new JMenuItem(Translation.get("gb.login") + "...");\r
login.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, KeyEvent.CTRL_DOWN_MASK, false));\r
login.addActionListener(new ActionListener() {\r
public void actionPerformed(ActionEvent event) {\r
- loginPrompt(localhost);\r
+ loginPrompt(GitblitRegistration.LOCALHOST);\r
}\r
});\r
serversMenu.add(login);\r
return panel;\r
}\r
\r
- private boolean loginPrompt(GitblitRegistration reg) {\r
+ private void manageRegistrations() {\r
+ RegistrationsDialog dialog = new RegistrationsDialog(new ArrayList<GitblitRegistration>(\r
+ registrations.values()), this);\r
+ dialog.setLocationRelativeTo(GitblitManager.this);\r
+ dialog.setVisible(true);\r
+ }\r
+\r
+ @Override\r
+ public void loginPrompt(GitblitRegistration reg) {\r
JTextField urlField = new JTextField(reg.url, 30);\r
JTextField nameField = new JTextField(reg.name);\r
JTextField accountField = new JTextField(reg.account);\r
int result = JOptionPane.showConfirmDialog(GitblitManager.this, panel,\r
Translation.get("gb.login"), JOptionPane.OK_CANCEL_OPTION);\r
if (result != JOptionPane.OK_OPTION) {\r
- return false;\r
+ return;\r
}\r
String url = urlField.getText();\r
if (StringUtils.isEmpty(url)) {\r
- return false;\r
+ return;\r
}\r
+ String originalName = reg.name;\r
reg = new GitblitRegistration(nameField.getText(), url, accountField.getText(),\r
passwordField.getPassword());\r
- boolean success = login(reg);\r
- registrations.put(reg.name, reg);\r
- rebuildRecentMenu();\r
- return success;\r
+ if (!StringUtils.isEmpty(originalName) && !originalName.equals(reg.name)) {\r
+ // delete old registration\r
+ try {\r
+ StoredConfig config = getConfig();\r
+ config.unsetSection("servers", originalName);\r
+ config.save();\r
+ } catch (Throwable t) {\r
+ Utils.showException(GitblitManager.this, t);\r
+ }\r
+ }\r
+ login(reg);\r
}\r
\r
- private boolean login(GitblitRegistration reg) {\r
- try {\r
- GitblitPanel panel = new GitblitPanel(reg);\r
- panel.login();\r
- serverTabs.addTab(reg.name, panel);\r
- int idx = serverTabs.getTabCount() - 1;\r
- serverTabs.setSelectedIndex(idx);\r
- serverTabs.setTabComponentAt(idx, new ClosableTabComponent(reg.name, null, serverTabs,\r
- panel));\r
- saveRegistration(reg);\r
- return true;\r
- } catch (IOException e) {\r
- JOptionPane.showMessageDialog(GitblitManager.this, e.getMessage(),\r
- Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE);\r
- }\r
- return false;\r
+ @Override\r
+ public void login(final GitblitRegistration reg) {\r
+ setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));\r
+ final GitblitPanel panel = new GitblitPanel(reg);\r
+ SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {\r
+\r
+ @Override\r
+ protected Boolean doInBackground() throws IOException {\r
+ panel.login();\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ protected void done() {\r
+ try {\r
+ boolean success = get();\r
+ serverTabs.addTab(reg.name, panel);\r
+ int idx = serverTabs.getTabCount() - 1;\r
+ serverTabs.setSelectedIndex(idx);\r
+ serverTabs.setTabComponentAt(idx, new ClosableTabComponent(reg.name, null,\r
+ serverTabs, panel));\r
+ reg.lastLogin = new Date();\r
+ saveRegistration(reg);\r
+ registrations.put(reg.name, reg);\r
+ rebuildRecentMenu();\r
+ } catch (Throwable t) {\r
+ Utils.showException(GitblitManager.this, t);\r
+ } finally {\r
+ setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));\r
+ }\r
+ }\r
+ };\r
+ worker.execute();\r
}\r
\r
private void rebuildRecentMenu() {\r
recentMenu.removeAll();\r
ImageIcon icon = new ImageIcon(getClass().getResource("/gitblt-favicon.png"));\r
- for (final GitblitRegistration reg : registrations.values()) {\r
+ List<GitblitRegistration> list = new ArrayList<GitblitRegistration>(registrations.values());\r
+ Collections.sort(list, new Comparator<GitblitRegistration>() {\r
+ @Override\r
+ public int compare(GitblitRegistration o1, GitblitRegistration o2) {\r
+ return o2.lastLogin.compareTo(o1.lastLogin);\r
+ }\r
+ });\r
+ if (list.size() > maxRecentCount) {\r
+ list = list.subList(0, maxRecentCount);\r
+ }\r
+ for (final GitblitRegistration reg : list) {\r
JMenuItem item = new JMenuItem(reg.name, icon);\r
item.addActionListener(new ActionListener() {\r
public void actionPerformed(ActionEvent e) {\r
- loginPrompt(reg);\r
+ login(reg);\r
}\r
});\r
recentMenu.add(item);\r
StoredConfig config = getConfig();\r
Set<String> servers = config.getSubsections("servers");\r
for (String server : servers) {\r
+ Date lastLogin = dateFormat.parse(config.getString("servers", server, "lastLogin"));\r
String url = config.getString("servers", server, "url");\r
String account = config.getString("servers", server, "account");\r
+ // FIXME this is pretty lame\r
char[] password = new String(Base64.decode(config.getString("servers", server,\r
"password"))).toCharArray();\r
GitblitRegistration reg = new GitblitRegistration(server, url, account, password);\r
+ reg.lastLogin = lastLogin;\r
registrations.put(reg.name, reg);\r
}\r
} catch (Throwable t) {\r
StoredConfig config = getConfig();\r
config.setString("servers", reg.name, "url", reg.url);\r
config.setString("servers", reg.name, "account", reg.account);\r
+ // FIXME this is pretty lame\r
config.setString("servers", reg.name, "password",\r
Base64.encodeBytes(new String(reg.password).getBytes("UTF-8")));\r
+ config.setString("servers", reg.name, "lastLogin", dateFormat.format(reg.lastLogin));\r
config.save();\r
} catch (Throwable t) {\r
Utils.showException(GitblitManager.this, t);\r
}\r
}\r
\r
+ public boolean deleteRegistrations(List<GitblitRegistration> list) {\r
+ boolean success = false;\r
+ try {\r
+ StoredConfig config = getConfig();\r
+ for (GitblitRegistration reg : list) {\r
+ config.unsetSection("servers", reg.name);\r
+ }\r
+ config.save();\r
+ success = true;\r
+ } catch (Throwable t) {\r
+ Utils.showException(GitblitManager.this, t);\r
+ }\r
+ return success;\r
+ }\r
+\r
private StoredConfig getConfig() throws IOException, ConfigInvalidException {\r
FileBasedConfig config = new FileBasedConfig(configFile, FS.detect());\r
config.load();\r
import java.awt.event.ActionListener;\r
import java.awt.event.KeyAdapter;\r
import java.awt.event.KeyEvent;\r
+import java.awt.event.MouseAdapter;\r
+import java.awt.event.MouseEvent;\r
import java.io.IOException;\r
import java.net.URI;\r
import java.text.MessageFormat;\r
}\r
}\r
});\r
+ \r
+ repositoriesTable.addMouseListener(new MouseAdapter() {\r
+ public void mouseClicked(MouseEvent e) {\r
+ if (e.getClickCount() == 2) {\r
+ editRepository(getSelectedRepositories().get(0));\r
+ }\r
+ }\r
+ });\r
\r
final JTextField repositoryFilter = new JTextField();\r
repositoryFilter.addActionListener(new ActionListener() {\r
delUser.setEnabled(selected);\r
}\r
});\r
+ \r
+ usersTable.addMouseListener(new MouseAdapter() {\r
+ public void mouseClicked(MouseEvent e) {\r
+ if (e.getClickCount() == 2) {\r
+ editUser(getSelectedUsers().get(0));\r
+ }\r
+ }\r
+ });\r
\r
final JTextField userFilter = new JTextField();\r
userFilter.addActionListener(new ActionListener() {\r
gitblit = null;\r
}\r
\r
- protected void refreshRepositories() {\r
+ protected void refreshRepositories() { \r
GitblitWorker worker = new GitblitWorker(GitblitPanel.this, RpcRequest.LIST_REPOSITORIES) {\r
@Override\r
protected Boolean doRequest() throws IOException {\r
*/\r
protected void createRepository() {\r
EditRepositoryDialog dialog = new EditRepositoryDialog();\r
+ dialog.setLocationRelativeTo(GitblitPanel.this);\r
dialog.setUsers(null, gitblit.getUsernames(), null);\r
dialog.setRepositories(gitblit.getRepositories());\r
dialog.setVisible(true);\r
*/\r
protected void editRepository(final RepositoryModel repository) {\r
EditRepositoryDialog dialog = new EditRepositoryDialog(repository);\r
+ dialog.setLocationRelativeTo(GitblitPanel.this);\r
List<String> usernames = gitblit.getUsernames();\r
List<String> members = gitblit.getPermittedUsernames(repository);\r
dialog.setUsers(repository.owner, usernames, members);\r
*/\r
protected void createUser() {\r
EditUserDialog dialog = new EditUserDialog(gitblit.getSettings());\r
+ dialog.setLocationRelativeTo(GitblitPanel.this);\r
dialog.setUsers(gitblit.getUsers());\r
dialog.setRepositories(gitblit.getRepositories(), null);\r
dialog.setVisible(true);\r
*/\r
protected void editUser(final UserModel user) {\r
EditUserDialog dialog = new EditUserDialog(user, gitblit.getSettings());\r
+ dialog.setLocationRelativeTo(GitblitPanel.this);\r
dialog.setRepositories(gitblit.getRepositories(), new ArrayList<String>(user.repositories));\r
dialog.setVisible(true);\r
final UserModel revisedUser = dialog.getUser();\r
package com.gitblit.client;\r
\r
import java.io.Serializable;\r
+import java.util.Date;\r
\r
import com.gitblit.utils.StringUtils;\r
\r
* @author James Moger\r
* \r
*/\r
-public class GitblitRegistration implements Serializable {\r
- \r
+public class GitblitRegistration implements Serializable, Comparable<GitblitRegistration> {\r
+\r
+ public static final GitblitRegistration LOCALHOST = new GitblitRegistration("localhost",\r
+ "https://localhost:8443", "admin", "admin".toCharArray());\r
private static final long serialVersionUID = 1L;\r
- \r
+\r
String name;\r
String url;\r
String account;\r
char[] password;\r
+ Date lastLogin;\r
\r
public GitblitRegistration(String name, String url, String account, char[] password) {\r
this.url = url;\r
this.name = name;\r
}\r
}\r
+\r
+ @Override\r
+ public int compareTo(GitblitRegistration o) {\r
+ return name.compareTo(o.name);\r
+ }\r
}\r
--- /dev/null
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.client;\r
+\r
+import java.awt.BorderLayout;\r
+import java.awt.FlowLayout;\r
+import java.awt.Insets;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+import java.awt.event.KeyEvent;\r
+import java.awt.event.MouseAdapter;\r
+import java.awt.event.MouseEvent;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import javax.swing.ImageIcon;\r
+import javax.swing.JButton;\r
+import javax.swing.JComponent;\r
+import javax.swing.JDialog;\r
+import javax.swing.JPanel;\r
+import javax.swing.JRootPane;\r
+import javax.swing.JScrollPane;\r
+import javax.swing.JTable;\r
+import javax.swing.KeyStroke;\r
+import javax.swing.event.ListSelectionEvent;\r
+import javax.swing.event.ListSelectionListener;\r
+\r
+public class RegistrationsDialog extends JDialog {\r
+\r
+ interface RegistrationListener {\r
+ boolean deleteRegistrations(List<GitblitRegistration> list);\r
+\r
+ void loginPrompt(GitblitRegistration reg);\r
+\r
+ void login(GitblitRegistration reg);\r
+ }\r
+\r
+ private static final long serialVersionUID = 1L;\r
+\r
+ private final List<GitblitRegistration> registrations;\r
+\r
+ private final RegistrationListener listener;\r
+\r
+ private JTable registrationsTable;\r
+\r
+ private RegistrationsModel model;\r
+\r
+ public RegistrationsDialog(List<GitblitRegistration> registrations,\r
+ RegistrationListener listener) {\r
+ super();\r
+ this.registrations = registrations;\r
+ this.listener = listener;\r
+ setTitle(Translation.get("gb.manage"));\r
+ setIconImage(new ImageIcon(getClass().getResource("/gitblt-favicon.png")).getImage());\r
+ initialize();\r
+ setSize(600, 400);\r
+ }\r
+\r
+ @Override\r
+ protected JRootPane createRootPane() {\r
+ KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);\r
+ JRootPane rootPane = new JRootPane();\r
+ rootPane.registerKeyboardAction(new ActionListener() {\r
+ public void actionPerformed(ActionEvent actionEvent) {\r
+ setVisible(false);\r
+ }\r
+ }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);\r
+ return rootPane;\r
+ }\r
+\r
+ private void initialize() {\r
+ NameRenderer nameRenderer = new NameRenderer();\r
+ model = new RegistrationsModel(registrations);\r
+ registrationsTable = Utils.newTable(model);\r
+ registrationsTable.setRowHeight(nameRenderer.getFont().getSize() + 8);\r
+\r
+ String id = registrationsTable.getColumnName(RegistrationsModel.Columns.Name.ordinal());\r
+ registrationsTable.getColumn(id).setCellRenderer(nameRenderer);\r
+ registrationsTable.addMouseListener(new MouseAdapter() {\r
+ public void mouseClicked(MouseEvent e) {\r
+ if (e.getClickCount() == 2) {\r
+ login(false);\r
+ }\r
+ }\r
+ });\r
+\r
+ final JButton create = new JButton(Translation.get("gb.create"));\r
+ create.addActionListener(new ActionListener() {\r
+ public void actionPerformed(ActionEvent event) {\r
+ listener.loginPrompt(GitblitRegistration.LOCALHOST);\r
+ }\r
+ });\r
+\r
+ final JButton login = new JButton(Translation.get("gb.login"));\r
+ login.setEnabled(false);\r
+ login.addActionListener(new ActionListener() {\r
+ public void actionPerformed(ActionEvent event) {\r
+ login(false);\r
+ }\r
+ });\r
+\r
+ final JButton loginPrompt = new JButton(Translation.get("gb.login") + "...");\r
+ loginPrompt.setEnabled(false);\r
+ loginPrompt.addActionListener(new ActionListener() {\r
+ public void actionPerformed(ActionEvent event) {\r
+ login(true);\r
+ }\r
+ });\r
+\r
+ final JButton delete = new JButton(Translation.get("gb.delete"));\r
+ delete.setEnabled(false);\r
+ delete.addActionListener(new ActionListener() {\r
+ public void actionPerformed(ActionEvent event) {\r
+ delete();\r
+ }\r
+ });\r
+\r
+ registrationsTable.getSelectionModel().addListSelectionListener(\r
+ new ListSelectionListener() {\r
+ @Override\r
+ public void valueChanged(ListSelectionEvent e) {\r
+ if (e.getValueIsAdjusting()) {\r
+ return;\r
+ }\r
+ boolean singleSelection = registrationsTable.getSelectedRowCount() == 1;\r
+ boolean selected = registrationsTable.getSelectedRow() > -1;\r
+ login.setEnabled(singleSelection);\r
+ loginPrompt.setEnabled(singleSelection);\r
+ delete.setEnabled(selected);\r
+ }\r
+ });\r
+\r
+ JPanel controls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));\r
+ controls.add(create);\r
+ controls.add(login);\r
+ controls.add(loginPrompt);\r
+ controls.add(delete);\r
+\r
+ final Insets insets = new Insets(5, 5, 5, 5);\r
+ JPanel centerPanel = new JPanel(new BorderLayout(5, 5)) {\r
+\r
+ private static final long serialVersionUID = 1L;\r
+\r
+ public Insets getInsets() {\r
+ return insets;\r
+ }\r
+ };\r
+ centerPanel.add(new JScrollPane(registrationsTable), BorderLayout.CENTER);\r
+ centerPanel.add(controls, BorderLayout.SOUTH);\r
+\r
+ getContentPane().setLayout(new BorderLayout(5, 5));\r
+ getContentPane().add(centerPanel, BorderLayout.CENTER);\r
+ }\r
+\r
+ private void login(boolean prompt) {\r
+ int viewRow = registrationsTable.getSelectedRow();\r
+ int modelRow = registrationsTable.convertRowIndexToModel(viewRow);\r
+ GitblitRegistration reg = registrations.get(modelRow);\r
+ RegistrationsDialog.this.setVisible(false);\r
+ if (prompt) {\r
+ listener.loginPrompt(reg);\r
+ } else {\r
+ listener.login(reg);\r
+ }\r
+ }\r
+\r
+ private void delete() {\r
+ List<GitblitRegistration> list = new ArrayList<GitblitRegistration>();\r
+ for (int i : registrationsTable.getSelectedRows()) {\r
+ int model = registrationsTable.convertRowIndexToModel(i);\r
+ GitblitRegistration reg = registrations.get(model);\r
+ list.add(reg);\r
+ }\r
+ if (listener.deleteRegistrations(list)) {\r
+ registrations.removeAll(list);\r
+ model.fireTableDataChanged();\r
+ }\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.client;\r
+\r
+import java.util.Collections;\r
+import java.util.Date;\r
+import java.util.List;\r
+\r
+import javax.swing.table.AbstractTableModel;\r
+\r
+/**\r
+ * Table model of a list of Gitblit server registrations.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public class RegistrationsModel extends AbstractTableModel {\r
+\r
+ private static final long serialVersionUID = 1L;\r
+\r
+ List<GitblitRegistration> list;\r
+\r
+ enum Columns {\r
+ Name, URL, Last_Login;\r
+\r
+ @Override\r
+ public String toString() {\r
+ return name().replace('_', ' ');\r
+ }\r
+ }\r
+\r
+ public RegistrationsModel(List<GitblitRegistration> list) {\r
+ this.list = list;\r
+ Collections.sort(this.list);\r
+ }\r
+\r
+ @Override\r
+ public int getRowCount() {\r
+ return list.size();\r
+ }\r
+\r
+ @Override\r
+ public int getColumnCount() {\r
+ return Columns.values().length;\r
+ }\r
+\r
+ @Override\r
+ public String getColumnName(int column) {\r
+ Columns col = Columns.values()[column];\r
+ switch (col) {\r
+ case Name:\r
+ return Translation.get("gb.name");\r
+ case URL:\r
+ return Translation.get("gb.url");\r
+ case Last_Login:\r
+ return Translation.get("gb.lastLogin");\r
+ }\r
+ return "";\r
+ }\r
+\r
+ /**\r
+ * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.\r
+ * \r
+ * @param columnIndex\r
+ * the column being queried\r
+ * @return the Object.class\r
+ */\r
+ public Class<?> getColumnClass(int columnIndex) {\r
+ if (columnIndex == Columns.Last_Login.ordinal()) {\r
+ return Date.class;\r
+ }\r
+ return String.class;\r
+ }\r
+\r
+ @Override\r
+ public Object getValueAt(int rowIndex, int columnIndex) {\r
+ GitblitRegistration model = list.get(rowIndex);\r
+ Columns col = Columns.values()[columnIndex];\r
+ switch (col) {\r
+ case Name:\r
+ return model.name;\r
+ case URL:\r
+ return model.url;\r
+ case Last_Login:\r
+ return model.lastLogin;\r
+ }\r
+ return null;\r
+ }\r
+}\r
gb.loading = loading\r
gb.starting = starting\r
gb.general = general\r
-gb.settings = settings
\ No newline at end of file
+gb.settings = settings\r
+gb.manage = manage\r
+gb.lastLogin = last login
\ No newline at end of file