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
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
\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
\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
}\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
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
}\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
\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
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
// 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
}\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
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
\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
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
--- /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.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