]> source.dussan.org Git - gitblit.git/commitdiff
Users JList to JTable. Fixed indicator tooltip. Users Tab.
authorJames Moger <james.moger@gitblit.com>
Sun, 16 Oct 2011 12:43:52 +0000 (08:43 -0400)
committerJames Moger <james.moger@gitblit.com>
Sun, 16 Oct 2011 12:43:52 +0000 (08:43 -0400)
src/com/gitblit/client/GitblitClient.java
src/com/gitblit/client/GitblitPanel.java
src/com/gitblit/client/IndicatorsRenderer.java
src/com/gitblit/client/UsersModel.java [new file with mode: 0644]
src/com/gitblit/client/Utils.java
src/com/gitblit/models/UserModel.java

index d66fdeaddc54f90ff5c0b9662986eeae104e2b41..ed6c1610a4b25c98f497d69170e6a36383c26115 100644 (file)
@@ -70,21 +70,17 @@ public class GitblitClient extends JFrame {
 \r
                setTitle("Gitblit RPC Client v" + Constants.VERSION + " (" + Constants.VERSION_DATE + ")");\r
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r
-               setSize(950, 600);\r
+               setSize(800, 500);\r
        }\r
 \r
        public void setVisible(boolean value) {\r
                if (value) {\r
                        if (registrations.size() == 0) {\r
                                // default prompt\r
-                               if (loginPrompt(localhost)) {\r
-                                       pack();\r
-                               }\r
+                               loginPrompt(localhost);\r
                        } else if (registrations.size() == 1) {\r
                                // single registration prompt\r
-                               if (loginPrompt(registrations.get(0))) {\r
-                                       pack();\r
-                               }\r
+                               loginPrompt(registrations.get(0));\r
                        }\r
                        super.setVisible(value);\r
                        setLocationRelativeTo(null);\r
index 05ba415bd49fe66ac8d7202628e695b784cb1484..9e10d2d790163209b460f3b35cfb68d55ff94527 100644 (file)
@@ -19,8 +19,6 @@ import java.awt.BorderLayout;
 import java.awt.Color;\r
 import java.awt.Component;\r
 import java.awt.Desktop;\r
-import java.awt.Dimension;\r
-import java.awt.GridLayout;\r
 import java.awt.Insets;\r
 import java.awt.event.ActionEvent;\r
 import java.awt.event.ActionListener;\r
@@ -28,12 +26,10 @@ import java.io.IOException;
 import java.net.URI;\r
 import java.text.MessageFormat;\r
 import java.util.ArrayList;\r
-import java.util.Date;\r
 import java.util.List;\r
 \r
 import javax.swing.JButton;\r
 import javax.swing.JLabel;\r
-import javax.swing.JList;\r
 import javax.swing.JOptionPane;\r
 import javax.swing.JPanel;\r
 import javax.swing.JScrollPane;\r
@@ -77,7 +73,9 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
 \r
        private RepositoriesModel repositoriesModel;\r
 \r
-       private JList usersList;\r
+       private JTable usersTable;\r
+\r
+       private UsersModel usersModel;\r
 \r
        private JPanel usersPanel;\r
 \r
@@ -93,7 +91,11 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
 \r
        private DefaultTableCellRenderer sizeRenderer;\r
 \r
-       private TableRowSorter<RepositoriesModel> defaultSorter;\r
+       private TableRowSorter<RepositoriesModel> defaultRepositoriesSorter;\r
+\r
+       private TableRowSorter<UsersModel> defaultUsersSorter;\r
+\r
+       private JButton editRepository;\r
 \r
        public GitblitPanel(GitblitRegistration reg) {\r
                this(reg.url, reg.account, reg.password);\r
@@ -131,7 +133,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                        }\r
                });\r
 \r
-               final JButton editRepository = new JButton(Translation.get("gb.edit"));\r
+               editRepository = new JButton(Translation.get("gb.edit"));\r
                editRepository.setEnabled(false);\r
                editRepository.addActionListener(new ActionListener() {\r
                        public void actionPerformed(ActionEvent e) {\r
@@ -169,23 +171,16 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                ownerRenderer.setHorizontalAlignment(SwingConstants.CENTER);\r
 \r
                repositoriesModel = new RepositoriesModel();\r
-               defaultSorter = new TableRowSorter<RepositoriesModel>(repositoriesModel);\r
-               repositoriesTable = new JTable(repositoriesModel);\r
-               repositoriesTable.setRowSorter(defaultSorter);\r
+               defaultRepositoriesSorter = new TableRowSorter<RepositoriesModel>(repositoriesModel);\r
+               repositoriesTable = Utils.newTable(repositoriesModel);\r
+               repositoriesTable.setRowHeight(nameRenderer.getFont().getSize() + 8);\r
+               repositoriesTable.setRowSorter(defaultRepositoriesSorter);\r
                repositoriesTable.getRowSorter().toggleSortOrder(RepositoriesModel.Columns.Name.ordinal());\r
 \r
-               repositoriesTable.setCellSelectionEnabled(false);\r
-               repositoriesTable.setRowSelectionAllowed(true);\r
-               repositoriesTable.setRowHeight(nameRenderer.getFont().getSize() + 8);\r
-               repositoriesTable.getTableHeader().setReorderingAllowed(false);\r
-               repositoriesTable.setGridColor(new Color(0xd9d9d9));\r
-               repositoriesTable.setBackground(Color.white);\r
-               repositoriesTable.setDefaultRenderer(Date.class,\r
-                               new DateCellRenderer(null, Color.orange.darker()));\r
-               setRenderer(RepositoriesModel.Columns.Name, nameRenderer);\r
-               setRenderer(RepositoriesModel.Columns.Indicators, typeRenderer);\r
-               setRenderer(RepositoriesModel.Columns.Owner, ownerRenderer);\r
-               setRenderer(RepositoriesModel.Columns.Size, sizeRenderer);\r
+               setRepositoryRenderer(RepositoriesModel.Columns.Name, nameRenderer);\r
+               setRepositoryRenderer(RepositoriesModel.Columns.Indicators, typeRenderer);\r
+               setRepositoryRenderer(RepositoriesModel.Columns.Owner, ownerRenderer);\r
+               setRepositoryRenderer(RepositoriesModel.Columns.Size, sizeRenderer);\r
 \r
                repositoriesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {\r
                        @Override\r
@@ -270,22 +265,29 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                        }\r
                });\r
 \r
-               usersList = new JList();\r
-               usersList.addListSelectionListener(new ListSelectionListener() {\r
+               usersModel = new UsersModel();\r
+               defaultUsersSorter = new TableRowSorter<UsersModel>(usersModel);\r
+               usersTable = Utils.newTable(usersModel);\r
+               String name = usersTable.getColumnName(UsersModel.Columns.Name.ordinal());\r
+               usersTable.setRowHeight(nameRenderer.getFont().getSize() + 8);\r
+               usersTable.getColumn(name).setCellRenderer(nameRenderer);\r
+               usersTable.setRowSorter(defaultUsersSorter);\r
+               usersTable.getRowSorter().toggleSortOrder(UsersModel.Columns.Name.ordinal());\r
+               usersTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {\r
 \r
                        @Override\r
                        public void valueChanged(ListSelectionEvent e) {\r
                                if (e.getValueIsAdjusting()) {\r
                                        return;\r
                                }\r
-                               boolean selected = usersList.getSelectedIndex() > -1;\r
-                               boolean singleSelection = usersList.getSelectedIndices().length == 1;\r
+                               boolean selected = usersTable.getSelectedRow() > -1;\r
+                               boolean singleSelection = usersTable.getSelectedRows().length == 1;\r
                                editUser.setEnabled(singleSelection && selected);\r
                                delUser.setEnabled(selected);\r
                        }\r
                });\r
 \r
-               JPanel userControls = new JPanel(new GridLayout(0, 2));\r
+               JPanel userControls = new JPanel();\r
                userControls.add(refreshUsers);\r
                userControls.add(createUser);\r
                userControls.add(editUser);\r
@@ -293,18 +295,12 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
 \r
                usersPanel = new JPanel(new BorderLayout(margin, margin));\r
                usersPanel.add(newHeaderLabel(Translation.get("gb.users")), BorderLayout.NORTH);\r
-               usersPanel.add(new JScrollPane(usersList), BorderLayout.CENTER);\r
+               usersPanel.add(new JScrollPane(usersTable), BorderLayout.CENTER);\r
                usersPanel.add(userControls, BorderLayout.SOUTH);\r
 \r
-               /*\r
-                * Assemble the main panel\r
-                */\r
-               JPanel mainPanel = new JPanel(new BorderLayout(margin, margin));\r
-               mainPanel.add(repositoriesPanel, BorderLayout.CENTER);\r
-               mainPanel.add(usersPanel, BorderLayout.EAST);\r
-\r
                tabs = new JTabbedPane(JTabbedPane.BOTTOM);\r
-               tabs.addTab(Translation.get("gb.repositories"), mainPanel);\r
+               tabs.addTab(Translation.get("gb.repositories"), repositoriesPanel);\r
+               tabs.addTab(Translation.get("gb.users"), usersPanel);\r
                tabs.addTab(Translation.get("gb.federation"), new JPanel());\r
 \r
                setLayout(new BorderLayout());\r
@@ -320,7 +316,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                return label;\r
        }\r
 \r
-       private void setRenderer(RepositoriesModel.Columns col, TableCellRenderer renderer) {\r
+       private void setRepositoryRenderer(RepositoriesModel.Columns col, TableCellRenderer renderer) {\r
                String name = repositoriesTable.getColumnName(col.ordinal());\r
                repositoriesTable.getColumn(name).setCellRenderer(renderer);\r
        }\r
@@ -337,13 +333,16 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                        // user does not have administrator privileges\r
                        // hide admin repository buttons\r
                        createRepository.setVisible(false);\r
+                       editRepository.setVisible(false);\r
                        delRepository.setVisible(false);\r
 \r
                        // hide users panel\r
                        usersPanel.setVisible(false);\r
 \r
-                       // remove federation tab\r
-                       tabs.removeTabAt(1);\r
+                       while (tabs.getTabCount() > 1) {\r
+                               // remove admin tabs\r
+                               tabs.removeTabAt(1);\r
+                       }\r
                }\r
        }\r
 \r
@@ -354,12 +353,14 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
        }\r
 \r
        private void updateUsersTable() {\r
-               usersList.setListData(gitblit.getUsers().toArray());\r
+               usersModel.list.clear();\r
+               usersModel.list.addAll(gitblit.getUsers());\r
+               usersModel.fireTableDataChanged();\r
        }\r
 \r
        private void filterRepositories(final String fragment) {\r
                if (StringUtils.isEmpty(fragment)) {\r
-                       repositoriesTable.setRowSorter(defaultSorter);\r
+                       repositoriesTable.setRowSorter(defaultRepositoriesSorter);\r
                        return;\r
                }\r
                RowFilter<RepositoriesModel, Object> containsFilter = new RowFilter<RepositoriesModel, Object>() {\r
@@ -382,8 +383,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                List<RepositoryModel> repositories = new ArrayList<RepositoryModel>();\r
                for (int viewRow : repositoriesTable.getSelectedRows()) {\r
                        int modelRow = repositoriesTable.convertRowIndexToModel(viewRow);\r
-                       RepositoryModel model = ((RepositoriesModel) repositoriesTable.getModel()).list\r
-                                       .get(modelRow);\r
+                       RepositoryModel model = repositoriesModel.list.get(modelRow);\r
                        repositories.add(model);\r
                }\r
                return repositories;\r
@@ -391,8 +391,9 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
 \r
        private List<UserModel> getSelectedUsers() {\r
                List<UserModel> users = new ArrayList<UserModel>();\r
-               for (int viewRow : usersList.getSelectedIndices()) {\r
-                       UserModel model = (UserModel) usersList.getModel().getElementAt(viewRow);\r
+               for (int viewRow : usersTable.getSelectedRows()) {\r
+                       int modelRow = usersTable.convertRowIndexToModel(viewRow);\r
+                       UserModel model = usersModel.list.get(modelRow);\r
                        users.add(model);\r
                }\r
                return users;\r
@@ -403,14 +404,6 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                return insets;\r
        }\r
 \r
-       @Override\r
-       public Dimension getPreferredSize() {\r
-               if (gitblit.allowAdmin()) {\r
-                       return new Dimension(950, 550);\r
-               }\r
-               return new Dimension(775, 450);\r
-       }\r
-\r
        @Override\r
        public void closeTab(Component c) {\r
                gitblit = null;\r
index 8c13122fe49a08403c8d4b1dbf9ab0e74445951d..e8be0ad2e2ee6ca16cedae5c70262a8f2e3e197c 100644 (file)
@@ -119,7 +119,7 @@ public class IndicatorsRenderer extends JPanel implements TableCellRenderer, Ser
                        }\r
                        case CLONE: {\r
                                JLabel icon = new JLabel(pullIcon);\r
-                               tooltip.append(Translation.get("gb.pullRestricted")).append("<br/>");\r
+                               tooltip.append(Translation.get("gb.cloneRestricted")).append("<br/>");\r
                                add(icon);\r
                                break;\r
                        }\r
diff --git a/src/com/gitblit/client/UsersModel.java b/src/com/gitblit/client/UsersModel.java
new file mode 100644 (file)
index 0000000..2b3c644
--- /dev/null
@@ -0,0 +1,97 @@
+/*\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.ArrayList;\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+import javax.swing.table.AbstractTableModel;\r
+\r
+import com.gitblit.models.UserModel;\r
+\r
+/**\r
+ * Table model of a list of users.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public class UsersModel extends AbstractTableModel {\r
+\r
+       private static final long serialVersionUID = 1L;\r
+\r
+       List<UserModel> list;\r
+\r
+       enum Columns {\r
+               Name;\r
+\r
+               @Override\r
+               public String toString() {\r
+                       return name().replace('_', ' ');\r
+               }\r
+       }\r
+\r
+       public UsersModel() {\r
+               this(new ArrayList<UserModel>());\r
+       }\r
+\r
+       public UsersModel(List<UserModel> users) {\r
+               this.list = users;\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
+               }\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
+               return String.class;\r
+       }\r
+\r
+       @Override\r
+       public Object getValueAt(int rowIndex, int columnIndex) {\r
+               UserModel model = list.get(rowIndex);\r
+               Columns col = Columns.values()[columnIndex];\r
+               switch (col) {\r
+               case Name:\r
+                       return model.username;\r
+               }\r
+               return null;\r
+       }\r
+}\r
index c33c11016e86dc75048e307d8a7b6457591bfdc5..1ce6d7dc79408158f155508b5c645be84b0f0040 100644 (file)
  */\r
 package com.gitblit.client;\r
 \r
+import java.awt.Color;\r
 import java.awt.Component;\r
 import java.text.MessageFormat;\r
+import java.util.Date;\r
 \r
 import javax.swing.JOptionPane;\r
 import javax.swing.JTable;\r
 import javax.swing.table.DefaultTableColumnModel;\r
 import javax.swing.table.TableCellRenderer;\r
 import javax.swing.table.TableColumn;\r
+import javax.swing.table.TableModel;\r
 \r
 import com.gitblit.Constants.RpcRequest;\r
 \r
 public class Utils {\r
 \r
+       public static JTable newTable(TableModel model) {\r
+               JTable table = new JTable(model);\r
+               table.setCellSelectionEnabled(false);\r
+               table.setRowSelectionAllowed(true);\r
+               table.getTableHeader().setReorderingAllowed(false);\r
+               table.setGridColor(new Color(0xd9d9d9));\r
+               table.setBackground(Color.white);\r
+               table.setDefaultRenderer(Date.class, new DateCellRenderer(null, Color.orange.darker()));\r
+               return table;\r
+       }\r
+\r
        public static void explainForbidden(Component c, RpcRequest request) {\r
                String msg = MessageFormat.format(\r
                                "The request \"{0}\" has been forbidden by the Gitblit server.", request.name());\r
index 0d88ce2d6cdd5ab77b076221e4f7b8b975fc46bd..fcf2b263b55da0582a747a6d29622b5fce0bc543 100644 (file)
@@ -28,7 +28,7 @@ import java.util.Set;
  * @author James Moger\r
  * \r
  */\r
-public class UserModel implements Principal, Serializable {\r
+public class UserModel implements Principal, Serializable, Comparable<UserModel> {\r
 \r
        private static final long serialVersionUID = 1L;\r
 \r
@@ -60,4 +60,9 @@ public class UserModel implements Principal, Serializable {
        public String toString() {\r
                return username;\r
        }\r
+\r
+       @Override\r
+       public int compareTo(UserModel o) {\r
+               return username.compareTo(o.username);\r
+       }\r
 }\r