summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/gitblit/client/GitblitClient.java10
-rw-r--r--src/com/gitblit/client/GitblitPanel.java99
-rw-r--r--src/com/gitblit/client/IndicatorsRenderer.java2
-rw-r--r--src/com/gitblit/client/UsersModel.java97
-rw-r--r--src/com/gitblit/client/Utils.java14
-rw-r--r--src/com/gitblit/models/UserModel.java7
6 files changed, 167 insertions, 62 deletions
diff --git a/src/com/gitblit/client/GitblitClient.java b/src/com/gitblit/client/GitblitClient.java
index d66fdead..ed6c1610 100644
--- a/src/com/gitblit/client/GitblitClient.java
+++ b/src/com/gitblit/client/GitblitClient.java
@@ -70,21 +70,17 @@ public class GitblitClient extends JFrame {
setTitle("Gitblit RPC Client v" + Constants.VERSION + " (" + Constants.VERSION_DATE + ")");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setSize(950, 600);
+ setSize(800, 500);
}
public void setVisible(boolean value) {
if (value) {
if (registrations.size() == 0) {
// default prompt
- if (loginPrompt(localhost)) {
- pack();
- }
+ loginPrompt(localhost);
} else if (registrations.size() == 1) {
// single registration prompt
- if (loginPrompt(registrations.get(0))) {
- pack();
- }
+ loginPrompt(registrations.get(0));
}
super.setVisible(value);
setLocationRelativeTo(null);
diff --git a/src/com/gitblit/client/GitblitPanel.java b/src/com/gitblit/client/GitblitPanel.java
index 05ba415b..9e10d2d7 100644
--- a/src/com/gitblit/client/GitblitPanel.java
+++ b/src/com/gitblit/client/GitblitPanel.java
@@ -19,8 +19,6 @@ import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Desktop;
-import java.awt.Dimension;
-import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -28,12 +26,10 @@ import java.io.IOException;
import java.net.URI;
import java.text.MessageFormat;
import java.util.ArrayList;
-import java.util.Date;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JLabel;
-import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
@@ -77,7 +73,9 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
private RepositoriesModel repositoriesModel;
- private JList usersList;
+ private JTable usersTable;
+
+ private UsersModel usersModel;
private JPanel usersPanel;
@@ -93,7 +91,11 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
private DefaultTableCellRenderer sizeRenderer;
- private TableRowSorter<RepositoriesModel> defaultSorter;
+ private TableRowSorter<RepositoriesModel> defaultRepositoriesSorter;
+
+ private TableRowSorter<UsersModel> defaultUsersSorter;
+
+ private JButton editRepository;
public GitblitPanel(GitblitRegistration reg) {
this(reg.url, reg.account, reg.password);
@@ -131,7 +133,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
}
});
- final JButton editRepository = new JButton(Translation.get("gb.edit"));
+ editRepository = new JButton(Translation.get("gb.edit"));
editRepository.setEnabled(false);
editRepository.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
@@ -169,23 +171,16 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
ownerRenderer.setHorizontalAlignment(SwingConstants.CENTER);
repositoriesModel = new RepositoriesModel();
- defaultSorter = new TableRowSorter<RepositoriesModel>(repositoriesModel);
- repositoriesTable = new JTable(repositoriesModel);
- repositoriesTable.setRowSorter(defaultSorter);
+ defaultRepositoriesSorter = new TableRowSorter<RepositoriesModel>(repositoriesModel);
+ repositoriesTable = Utils.newTable(repositoriesModel);
+ repositoriesTable.setRowHeight(nameRenderer.getFont().getSize() + 8);
+ repositoriesTable.setRowSorter(defaultRepositoriesSorter);
repositoriesTable.getRowSorter().toggleSortOrder(RepositoriesModel.Columns.Name.ordinal());
- repositoriesTable.setCellSelectionEnabled(false);
- repositoriesTable.setRowSelectionAllowed(true);
- repositoriesTable.setRowHeight(nameRenderer.getFont().getSize() + 8);
- repositoriesTable.getTableHeader().setReorderingAllowed(false);
- repositoriesTable.setGridColor(new Color(0xd9d9d9));
- repositoriesTable.setBackground(Color.white);
- repositoriesTable.setDefaultRenderer(Date.class,
- new DateCellRenderer(null, Color.orange.darker()));
- setRenderer(RepositoriesModel.Columns.Name, nameRenderer);
- setRenderer(RepositoriesModel.Columns.Indicators, typeRenderer);
- setRenderer(RepositoriesModel.Columns.Owner, ownerRenderer);
- setRenderer(RepositoriesModel.Columns.Size, sizeRenderer);
+ setRepositoryRenderer(RepositoriesModel.Columns.Name, nameRenderer);
+ setRepositoryRenderer(RepositoriesModel.Columns.Indicators, typeRenderer);
+ setRepositoryRenderer(RepositoriesModel.Columns.Owner, ownerRenderer);
+ setRepositoryRenderer(RepositoriesModel.Columns.Size, sizeRenderer);
repositoriesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
@@ -270,22 +265,29 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
}
});
- usersList = new JList();
- usersList.addListSelectionListener(new ListSelectionListener() {
+ usersModel = new UsersModel();
+ defaultUsersSorter = new TableRowSorter<UsersModel>(usersModel);
+ usersTable = Utils.newTable(usersModel);
+ String name = usersTable.getColumnName(UsersModel.Columns.Name.ordinal());
+ usersTable.setRowHeight(nameRenderer.getFont().getSize() + 8);
+ usersTable.getColumn(name).setCellRenderer(nameRenderer);
+ usersTable.setRowSorter(defaultUsersSorter);
+ usersTable.getRowSorter().toggleSortOrder(UsersModel.Columns.Name.ordinal());
+ usersTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
- boolean selected = usersList.getSelectedIndex() > -1;
- boolean singleSelection = usersList.getSelectedIndices().length == 1;
+ boolean selected = usersTable.getSelectedRow() > -1;
+ boolean singleSelection = usersTable.getSelectedRows().length == 1;
editUser.setEnabled(singleSelection && selected);
delUser.setEnabled(selected);
}
});
- JPanel userControls = new JPanel(new GridLayout(0, 2));
+ JPanel userControls = new JPanel();
userControls.add(refreshUsers);
userControls.add(createUser);
userControls.add(editUser);
@@ -293,18 +295,12 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
usersPanel = new JPanel(new BorderLayout(margin, margin));
usersPanel.add(newHeaderLabel(Translation.get("gb.users")), BorderLayout.NORTH);
- usersPanel.add(new JScrollPane(usersList), BorderLayout.CENTER);
+ usersPanel.add(new JScrollPane(usersTable), BorderLayout.CENTER);
usersPanel.add(userControls, BorderLayout.SOUTH);
- /*
- * Assemble the main panel
- */
- JPanel mainPanel = new JPanel(new BorderLayout(margin, margin));
- mainPanel.add(repositoriesPanel, BorderLayout.CENTER);
- mainPanel.add(usersPanel, BorderLayout.EAST);
-
tabs = new JTabbedPane(JTabbedPane.BOTTOM);
- tabs.addTab(Translation.get("gb.repositories"), mainPanel);
+ tabs.addTab(Translation.get("gb.repositories"), repositoriesPanel);
+ tabs.addTab(Translation.get("gb.users"), usersPanel);
tabs.addTab(Translation.get("gb.federation"), new JPanel());
setLayout(new BorderLayout());
@@ -320,7 +316,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
return label;
}
- private void setRenderer(RepositoriesModel.Columns col, TableCellRenderer renderer) {
+ private void setRepositoryRenderer(RepositoriesModel.Columns col, TableCellRenderer renderer) {
String name = repositoriesTable.getColumnName(col.ordinal());
repositoriesTable.getColumn(name).setCellRenderer(renderer);
}
@@ -337,13 +333,16 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
// user does not have administrator privileges
// hide admin repository buttons
createRepository.setVisible(false);
+ editRepository.setVisible(false);
delRepository.setVisible(false);
// hide users panel
usersPanel.setVisible(false);
- // remove federation tab
- tabs.removeTabAt(1);
+ while (tabs.getTabCount() > 1) {
+ // remove admin tabs
+ tabs.removeTabAt(1);
+ }
}
}
@@ -354,12 +353,14 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
}
private void updateUsersTable() {
- usersList.setListData(gitblit.getUsers().toArray());
+ usersModel.list.clear();
+ usersModel.list.addAll(gitblit.getUsers());
+ usersModel.fireTableDataChanged();
}
private void filterRepositories(final String fragment) {
if (StringUtils.isEmpty(fragment)) {
- repositoriesTable.setRowSorter(defaultSorter);
+ repositoriesTable.setRowSorter(defaultRepositoriesSorter);
return;
}
RowFilter<RepositoriesModel, Object> containsFilter = new RowFilter<RepositoriesModel, Object>() {
@@ -382,8 +383,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
List<RepositoryModel> repositories = new ArrayList<RepositoryModel>();
for (int viewRow : repositoriesTable.getSelectedRows()) {
int modelRow = repositoriesTable.convertRowIndexToModel(viewRow);
- RepositoryModel model = ((RepositoriesModel) repositoriesTable.getModel()).list
- .get(modelRow);
+ RepositoryModel model = repositoriesModel.list.get(modelRow);
repositories.add(model);
}
return repositories;
@@ -391,8 +391,9 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
private List<UserModel> getSelectedUsers() {
List<UserModel> users = new ArrayList<UserModel>();
- for (int viewRow : usersList.getSelectedIndices()) {
- UserModel model = (UserModel) usersList.getModel().getElementAt(viewRow);
+ for (int viewRow : usersTable.getSelectedRows()) {
+ int modelRow = usersTable.convertRowIndexToModel(viewRow);
+ UserModel model = usersModel.list.get(modelRow);
users.add(model);
}
return users;
@@ -404,14 +405,6 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
}
@Override
- public Dimension getPreferredSize() {
- if (gitblit.allowAdmin()) {
- return new Dimension(950, 550);
- }
- return new Dimension(775, 450);
- }
-
- @Override
public void closeTab(Component c) {
gitblit = null;
}
diff --git a/src/com/gitblit/client/IndicatorsRenderer.java b/src/com/gitblit/client/IndicatorsRenderer.java
index 8c13122f..e8be0ad2 100644
--- a/src/com/gitblit/client/IndicatorsRenderer.java
+++ b/src/com/gitblit/client/IndicatorsRenderer.java
@@ -119,7 +119,7 @@ public class IndicatorsRenderer extends JPanel implements TableCellRenderer, Ser
}
case CLONE: {
JLabel icon = new JLabel(pullIcon);
- tooltip.append(Translation.get("gb.pullRestricted")).append("<br/>");
+ tooltip.append(Translation.get("gb.cloneRestricted")).append("<br/>");
add(icon);
break;
}
diff --git a/src/com/gitblit/client/UsersModel.java b/src/com/gitblit/client/UsersModel.java
new file mode 100644
index 00000000..2b3c6443
--- /dev/null
+++ b/src/com/gitblit/client/UsersModel.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2011 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.client;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.swing.table.AbstractTableModel;
+
+import com.gitblit.models.UserModel;
+
+/**
+ * Table model of a list of users.
+ *
+ * @author James Moger
+ *
+ */
+public class UsersModel extends AbstractTableModel {
+
+ private static final long serialVersionUID = 1L;
+
+ List<UserModel> list;
+
+ enum Columns {
+ Name;
+
+ @Override
+ public String toString() {
+ return name().replace('_', ' ');
+ }
+ }
+
+ public UsersModel() {
+ this(new ArrayList<UserModel>());
+ }
+
+ public UsersModel(List<UserModel> users) {
+ this.list = users;
+ Collections.sort(this.list);
+ }
+
+ @Override
+ public int getRowCount() {
+ return list.size();
+ }
+
+ @Override
+ public int getColumnCount() {
+ return Columns.values().length;
+ }
+
+ @Override
+ public String getColumnName(int column) {
+ Columns col = Columns.values()[column];
+ switch (col) {
+ case Name:
+ return Translation.get("gb.name");
+ }
+ return "";
+ }
+
+ /**
+ * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.
+ *
+ * @param columnIndex
+ * the column being queried
+ * @return the Object.class
+ */
+ public Class<?> getColumnClass(int columnIndex) {
+ return String.class;
+ }
+
+ @Override
+ public Object getValueAt(int rowIndex, int columnIndex) {
+ UserModel model = list.get(rowIndex);
+ Columns col = Columns.values()[columnIndex];
+ switch (col) {
+ case Name:
+ return model.username;
+ }
+ return null;
+ }
+}
diff --git a/src/com/gitblit/client/Utils.java b/src/com/gitblit/client/Utils.java
index c33c1101..1ce6d7dc 100644
--- a/src/com/gitblit/client/Utils.java
+++ b/src/com/gitblit/client/Utils.java
@@ -15,19 +15,33 @@
*/
package com.gitblit.client;
+import java.awt.Color;
import java.awt.Component;
import java.text.MessageFormat;
+import java.util.Date;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
+import javax.swing.table.TableModel;
import com.gitblit.Constants.RpcRequest;
public class Utils {
+ public static JTable newTable(TableModel model) {
+ JTable table = new JTable(model);
+ table.setCellSelectionEnabled(false);
+ table.setRowSelectionAllowed(true);
+ table.getTableHeader().setReorderingAllowed(false);
+ table.setGridColor(new Color(0xd9d9d9));
+ table.setBackground(Color.white);
+ table.setDefaultRenderer(Date.class, new DateCellRenderer(null, Color.orange.darker()));
+ return table;
+ }
+
public static void explainForbidden(Component c, RpcRequest request) {
String msg = MessageFormat.format(
"The request \"{0}\" has been forbidden by the Gitblit server.", request.name());
diff --git a/src/com/gitblit/models/UserModel.java b/src/com/gitblit/models/UserModel.java
index 0d88ce2d..fcf2b263 100644
--- a/src/com/gitblit/models/UserModel.java
+++ b/src/com/gitblit/models/UserModel.java
@@ -28,7 +28,7 @@ import java.util.Set;
* @author James Moger
*
*/
-public class UserModel implements Principal, Serializable {
+public class UserModel implements Principal, Serializable, Comparable<UserModel> {
private static final long serialVersionUID = 1L;
@@ -60,4 +60,9 @@ public class UserModel implements Principal, Serializable {
public String toString() {
return username;
}
+
+ @Override
+ public int compareTo(UserModel o) {
+ return username.compareTo(o.username);
+ }
}