From f306ef8552efe1580e9c16e1d944f5ed1dca4aae Mon Sep 17 00:00:00 2001 From: James Moger Date: Mon, 24 Oct 2011 16:33:40 -0400 Subject: [PATCH] Object counts and refresh labels on all header panels --- src/com/gitblit/client/GitblitClient.java | 7 ++- src/com/gitblit/client/GitblitPanel.java | 51 ++++++++++++++++--- src/com/gitblit/client/HeaderPanel.java | 39 +++++++++++--- src/com/gitblit/client/UsersTableModel.java | 8 ++- .../gitblit/wicket/GitBlitWebApp.properties | 3 +- 5 files changed, 90 insertions(+), 18 deletions(-) diff --git a/src/com/gitblit/client/GitblitClient.java b/src/com/gitblit/client/GitblitClient.java index 66675b16..79914232 100644 --- a/src/com/gitblit/client/GitblitClient.java +++ b/src/com/gitblit/client/GitblitClient.java @@ -86,7 +86,7 @@ public class GitblitClient implements Serializable { } try { - settings = RpcUtils.getSettings(url, account, password); + refreshSettings(); status = RpcUtils.getStatus(url, account, password); allowAdministration = true; } catch (UnauthorizedException e) { @@ -136,6 +136,11 @@ public class GitblitClient implements Serializable { allUsers.addAll(users); return allUsers; } + + public ServerSettings refreshSettings() throws IOException { + settings = RpcUtils.getSettings(url, account, password); + return settings; + } public List refreshFederationRegistrations() throws IOException { List list = RpcUtils.getFederationRegistrations(url, account, password); diff --git a/src/com/gitblit/client/GitblitPanel.java b/src/com/gitblit/client/GitblitPanel.java index 31de44ef..a9d7b466 100644 --- a/src/com/gitblit/client/GitblitPanel.java +++ b/src/com/gitblit/client/GitblitPanel.java @@ -107,6 +107,12 @@ public class GitblitPanel extends JPanel implements CloseTabListener { private JButton editRepository; + private HeaderPanel repositoriesHeader; + + private HeaderPanel usersHeader; + + private HeaderPanel settingsHeader; + public GitblitPanel(GitblitRegistration reg) { this(reg.url, reg.account, reg.password); } @@ -259,8 +265,9 @@ public class GitblitPanel extends JPanel implements CloseTabListener { return insets; } }; - repositoriesPanel.add(new HeaderPanel(Translation.get("gb.repositories"), - "gitweb-favicon.png"), BorderLayout.NORTH); + repositoriesHeader = new HeaderPanel(Translation.get("gb.repositories"), + "gitweb-favicon.png"); + repositoriesPanel.add(repositoriesHeader, BorderLayout.NORTH); repositoriesPanel.add(repositoryTablePanel, BorderLayout.CENTER); repositoriesPanel.add(repositoryControls, BorderLayout.SOUTH); @@ -372,8 +379,8 @@ public class GitblitPanel extends JPanel implements CloseTabListener { return insets; } }; - usersPanel.add(new HeaderPanel(Translation.get("gb.users"), "user_16x16.png"), - BorderLayout.NORTH); + usersHeader = new HeaderPanel(Translation.get("gb.users"), "user_16x16.png"); + usersPanel.add(usersHeader, BorderLayout.NORTH); usersPanel.add(userTablePanel, BorderLayout.CENTER); usersPanel.add(userControls, BorderLayout.SOUTH); @@ -381,6 +388,13 @@ public class GitblitPanel extends JPanel implements CloseTabListener { } private JPanel createSettingsPanel() { + JButton refreshSettings = new JButton(Translation.get("gb.refresh")); + refreshSettings.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + refreshSettings(); + } + }); + final SettingPanel settingPanel = new SettingPanel(); settingsModel = new SettingsTableModel(); defaultSettingsSorter = new TableRowSorter(settingsModel); @@ -434,6 +448,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener { settingsTablePanel.add(settingPanel, BorderLayout.SOUTH); JPanel settingsControls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0)); + settingsControls.add(refreshSettings); // TODO update setting? JPanel settingsPanel = new JPanel(new BorderLayout(margin, margin)) { @@ -444,8 +459,8 @@ public class GitblitPanel extends JPanel implements CloseTabListener { return insets; } }; - settingsPanel.add(new HeaderPanel(Translation.get("gb.settings"), "settings_16x16.png"), - BorderLayout.NORTH); + settingsHeader = new HeaderPanel(Translation.get("gb.settings"), "settings_16x16.png"); + settingsPanel.add(settingsHeader, BorderLayout.NORTH); settingsPanel.add(settingsTablePanel, BorderLayout.CENTER); settingsPanel.add(settingsControls, BorderLayout.SOUTH); @@ -478,11 +493,11 @@ public class GitblitPanel extends JPanel implements CloseTabListener { } else { // remove the settings tab String settingsTitle = Translation.get("gb.settings"); - for (int i= 0; i < tabs.getTabCount(); i++) { + for (int i = 0; i < tabs.getTabCount(); i++) { if (tabs.getTitleAt(i).equals(settingsTitle)) { tabs.removeTabAt(i); break; - } + } } } } @@ -491,17 +506,21 @@ public class GitblitPanel extends JPanel implements CloseTabListener { repositoriesModel.list.clear(); repositoriesModel.list.addAll(gitblit.getRepositories()); repositoriesModel.fireTableDataChanged(); + repositoriesHeader.setText(Translation.get("gb.repositories") + " (" + + gitblit.getRepositories().size() + ")"); } private void updateUsersTable() { usersModel.list.clear(); usersModel.list.addAll(gitblit.getUsers()); usersModel.fireTableDataChanged(); + usersHeader.setText(Translation.get("gb.users") + " (" + gitblit.getUsers().size() + ")"); } private void updateSettingsTable() { settingsModel.setSettings(gitblit.getSettings()); settingsModel.fireTableDataChanged(); + settingsHeader.setText(Translation.get("gb.settings")); } private void filterRepositories(final String fragment) { @@ -882,4 +901,20 @@ public class GitblitPanel extends JPanel implements CloseTabListener { worker.execute(); } } + + protected void refreshSettings() { + GitblitWorker worker = new GitblitWorker(GitblitPanel.this, RpcRequest.LIST_SETTINGS) { + @Override + protected Boolean doRequest() throws IOException { + gitblit.refreshSettings(); + return true; + } + + @Override + protected void onSuccess() { + updateSettingsTable(); + } + }; + worker.execute(); + } } \ No newline at end of file diff --git a/src/com/gitblit/client/HeaderPanel.java b/src/com/gitblit/client/HeaderPanel.java index 0df29140..3cd89a70 100644 --- a/src/com/gitblit/client/HeaderPanel.java +++ b/src/com/gitblit/client/HeaderPanel.java @@ -17,13 +17,16 @@ package com.gitblit.client; import java.awt.BasicStroke; import java.awt.Color; -import java.awt.FlowLayout; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.GridLayout; +import java.awt.Insets; import java.awt.Paint; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; +import java.text.SimpleDateFormat; +import java.util.Date; import javax.swing.ImageIcon; import javax.swing.JLabel; @@ -35,20 +38,42 @@ public class HeaderPanel extends JPanel { private static final long serialVersionUID = 1L; + private final Insets insets = new Insets(5, 5, 5, 5); + private Color lightColor = new Color(0, 0, 0x60); + private JLabel headerLabel; + + private JLabel refreshLabel; + public HeaderPanel(String text, String icon) { - super(new FlowLayout(FlowLayout.LEFT), true); + // super(new FlowLayout(FlowLayout.LEFT), true); + super(new GridLayout(1, 2, 5, 5), true); setOpaque(true); setBackground(new Color(0, 0, 0x20)); - JLabel label = new JLabel(text); + headerLabel = new JLabel(text); if (!StringUtils.isEmpty(icon)) { - label.setIcon(new ImageIcon(getClass().getResource("/" + icon))); + headerLabel.setIcon(new ImageIcon(getClass().getResource("/" + icon))); } - label.setForeground(Color.white); - label.setFont(label.getFont().deriveFont(14f)); - add(label); + headerLabel.setForeground(Color.white); + headerLabel.setFont(headerLabel.getFont().deriveFont(14f)); + add(headerLabel); + + refreshLabel = new JLabel("", JLabel.RIGHT); + refreshLabel.setForeground(Color.white); + add(refreshLabel); + } + + public void setText(String text) { + headerLabel.setText(text); + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + refreshLabel.setText("refreshed " + df.format(new Date())); + } + + @Override + public Insets getInsets() { + return insets; } @Override diff --git a/src/com/gitblit/client/UsersTableModel.java b/src/com/gitblit/client/UsersTableModel.java index 57536adc..de282b8e 100644 --- a/src/com/gitblit/client/UsersTableModel.java +++ b/src/com/gitblit/client/UsersTableModel.java @@ -36,7 +36,7 @@ public class UsersTableModel extends AbstractTableModel { List list; enum Columns { - Name; + Name, AccessLevel; @Override public String toString() { @@ -69,6 +69,8 @@ public class UsersTableModel extends AbstractTableModel { switch (col) { case Name: return Translation.get("gb.name"); + case AccessLevel: + return Translation.get("gb.accessLevel"); } return ""; } @@ -91,6 +93,10 @@ public class UsersTableModel extends AbstractTableModel { switch (col) { case Name: return model.username; + case AccessLevel: + if (model.canAdmin) { + return "administrator"; + } } return null; } diff --git a/src/com/gitblit/wicket/GitBlitWebApp.properties b/src/com/gitblit/wicket/GitBlitWebApp.properties index ae6f6cfa..4314cf9e 100644 --- a/src/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/com/gitblit/wicket/GitBlitWebApp.properties @@ -162,4 +162,5 @@ gb.lastLogin = last login gb.skipSizeCalculation = skip size calculation gb.skipSizeCalculationDescription = do not calculate the repository size (reduces page load time) gb.skipSummaryMetrics = skip summary metrics -gb.skipSummaryMetricsDescription = do not calculate metrics on the summary page (reduces page load time) \ No newline at end of file +gb.skipSummaryMetricsDescription = do not calculate metrics on the summary page (reduces page load time) +gb.accessLevel = access level \ No newline at end of file -- 2.39.5