From: James Moger Date: Sat, 22 Oct 2011 13:01:20 +0000 (-0400) Subject: Documentation. Refactoring class names. Re-encapsulate settings. X-Git-Tag: v0.7.0~60 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=84c1d5c1527183a4e2830deab5b177d880914f1c;p=gitblit.git Documentation. Refactoring class names. Re-encapsulate settings. --- diff --git a/docs/01_setup.mkd b/docs/01_setup.mkd index c7a8ff61..b2c5b2f8 100644 --- a/docs/01_setup.mkd +++ b/docs/01_setup.mkd @@ -134,6 +134,7 @@ All repository settings are stored within the repository `.git/config` file unde showReadme = false federationStrategy = FEDERATE_THIS isFederated = false + skipSizeCalculation = false federationSets = #### Repository Names diff --git a/docs/02_rpc.mkd b/docs/02_rpc.mkd index b01eb679..94739ca3 100644 --- a/docs/02_rpc.mkd +++ b/docs/02_rpc.mkd @@ -30,7 +30,8 @@ The Gitblit RPC mechanism, like the Gitblit JGit servlet, syndication/feed servl LIST_FEDERATION_RESULTS-admin-List<FederationModel> LIST_FEDERATION_PROPOSALS-admin-List<FederationProposal> LIST_FEDERATION_SETS-admin-List<FederationSet> -LIST_SETTINGS-admin-Map<String, SettingModel> +LIST_SETTINGS-admin-ServerSettings (see example below) +LIST_STATUS-admin-ServerStatus (see example below) ### RPC/HTTP Response Codes @@ -55,6 +56,8 @@ One obvious goal of a Gitblit RPC mechanism would be to have an EGit Feature tha This particular project should not be difficult as the only external dependency for `com.gitblit.utils.RpcUtils` is [google-gson](http://google-gson.googlecode.com) which is already a dependency of the EGit/GitHub Mylyn feature. +One proposal from the EGit team is to define a common JSON RPC method for enumeration of repositories which can be implemented by Git hosts. The EGit team would then implement the UI and the client-side enumeration code. This idea was raised as part of this [feature request for EGit](https://bugs.eclipse.org/bugs/show_bug.cgi?id=361251). + Currently this project is in the planning stage. ### Example: LIST_REPOSITORIES @@ -80,6 +83,7 @@ Currently this project is in the planning stage. "libraries" ], "isFederated": false, + "skipSizeCalculation": false, "size": "102 KB" }, "https://localhost/git/libraries/smack.git": { @@ -97,6 +101,7 @@ Currently this project is in the planning stage. "federationStrategy": "FEDERATE_THIS", "federationSets": [], "isFederated": false, + "skipSizeCalculation": false, "size": "4.8 MB" } } @@ -157,28 +162,58 @@ The original repository name is specified in the *name* url parameter. The new ### Example: LIST_SETTINGS **url**: https://localhost/rpc?req=LIST_SETTINGS -**response body**: Map<String, SettingModel> +**response body**: ServerSettings
 {
-  "web.siteName": {
-    "name": "web.siteName",
-    "currentValue": "",
-    "defaultValue": "",
-    "description": "Gitblit Web Settings\nIf blank Gitblit is displayed.",
-    "since": "0.5.0",
-    "caseSensitive": false,
-    "restartRequired": false,
-    "spaceDelimited": false
-  },
-  "web.summaryCommitCount": {
-    "name": "web.summaryCommitCount",
-    "currentValue": "16",
-    "defaultValue": "16",
-    "description": "The number of commits to display on the summary page\nValue must exceed 0 else default of 16 is used",
-    "since": "0.5.0",
-    "caseSensitive": false,
-    "restartRequired": false,
-    "spaceDelimited": false
+  "settings": {
+      "web.siteName": {
+        "name": "web.siteName",
+        "currentValue": "",
+        "defaultValue": "",
+        "description": "Gitblit Web Settings\nIf blank Gitblit is displayed.",
+        "since": "0.5.0",
+        "caseSensitive": false,
+        "restartRequired": false,
+        "spaceDelimited": false
+      },
+      "web.summaryCommitCount": {
+        "name": "web.summaryCommitCount",
+        "currentValue": "16",
+        "defaultValue": "16",
+        "description": "The number of commits to display on the summary page\nValue must exceed 0 else default of 16 is used",
+        "since": "0.5.0",
+        "caseSensitive": false,
+        "restartRequired": false,
+        "spaceDelimited": false
+      }
   }
 }
+
+ +### Example: LIST_STATUS +**url**: https://localhost/rpc?req=LIST_STATUS +**response body**: ServerStatus +
+{
+  "bootDate": "2011-10-22T12:13:00Z",
+  "systemProperties": {
+    "file.encoding": "Cp1252",
+    "java.home": "C:\\Program Files\\Java\\jdk1.6.0_26\\jre",
+    "java.io.tmpdir": "C:\\Users\\JAMESM~1\\AppData\\Local\\Temp\\",
+    "java.runtime.name": "Java(TM) SE Runtime Environment",
+    "java.runtime.version": "1.6.0_26-b03",
+    "java.vendor": "Sun Microsystems Inc.",
+    "java.version": "1.6.0_26",
+    "java.vm.info": "mixed mode",
+    "java.vm.name": "Java HotSpot(TM) 64-Bit Server VM",
+    "java.vm.vendor": "Sun Microsystems Inc.",
+    "java.vm.version": "20.1-b02",
+    "os.arch": "amd64",
+    "os.name": "Windows 7",
+    "os.version": "6.1"
+  },
+  "heapAllocated": 128057344,
+  "heapFree": 120399168,
+  "heapSize": 1899560960
+}
 
\ No newline at end of file diff --git a/src/com/gitblit/Constants.java b/src/com/gitblit/Constants.java index f3ff6c44..79dfaf6a 100644 --- a/src/com/gitblit/Constants.java +++ b/src/com/gitblit/Constants.java @@ -205,7 +205,7 @@ public class Constants { LIST_USERS, CREATE_USER, EDIT_USER, DELETE_USER, LIST_REPOSITORY_MEMBERS, SET_REPOSITORY_MEMBERS, LIST_FEDERATION_REGISTRATIONS, LIST_FEDERATION_RESULTS, LIST_FEDERATION_PROPOSALS, LIST_FEDERATION_SETS, LIST_SETTINGS, - LIST_SERVER_STATUS; + LIST_STATUS; public static RpcRequest fromName(String name) { for (RpcRequest type : values()) { diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index 238c01f7..eaf6a957 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -30,7 +30,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -70,6 +69,7 @@ import com.gitblit.models.ObjectCache; import com.gitblit.models.RepositoryModel; import com.gitblit.models.ServerStatus; import com.gitblit.models.SettingModel; +import com.gitblit.models.ServerSettings; import com.gitblit.models.UserModel; import com.gitblit.utils.ByteFormat; import com.gitblit.utils.FederationUtils; @@ -123,7 +123,7 @@ public class GitBlit implements ServletContextListener { private IStoredSettings settings; - private Map settingModels; + private ServerSettings settingsModel; private ServerStatus serverStatus; @@ -1275,16 +1275,12 @@ public class GitBlit implements ServletContextListener { /** * Returns the descriptions/comments of the Gitblit config settings. * - * @return Map + * @return SettingsModel */ - public Map getSettingModels() { + public ServerSettings getSettingsModel() { // ensure that the current values are updated in the setting models - for (String key : settings.getAllKeys(null)) { - if (settingModels.containsKey(key)) { - settingModels.get(key).currentValue = settings.getString(key, ""); - } - } - return settingModels; + settingsModel.updateCurrentValues(settings); + return settingsModel; } /** @@ -1294,8 +1290,8 @@ public class GitBlit implements ServletContextListener { * * @return Map */ - private Map loadSettingModels() { - Map map = new TreeMap(); + private ServerSettings loadSettingModels() { + ServerSettings settingsModel = new ServerSettings(); try { // Read bundled Gitblit properties to extract setting descriptions. // This copy is pristine and only used for populating the setting @@ -1337,7 +1333,7 @@ public class GitBlit implements ServletContextListener { setting.defaultValue = kvp[1].trim(); setting.currentValue = setting.defaultValue; setting.description = description.toString().trim(); - map.put(key, setting); + settingsModel.add(setting); description.setLength(0); setting = new SettingModel(); } @@ -1349,7 +1345,7 @@ public class GitBlit implements ServletContextListener { } catch (IOException e) { logger.error("Failed to load resource copy of gitblit.properties"); } - return map; + return settingsModel; } /** @@ -1409,7 +1405,7 @@ public class GitBlit implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent contextEvent) { servletContext = contextEvent.getServletContext(); - settingModels = loadSettingModels(); + settingsModel = loadSettingModels(); if (settings == null) { // Gitblit WAR is running in a servlet container WebXmlSettings webxmlSettings = new WebXmlSettings(contextEvent.getServletContext()); diff --git a/src/com/gitblit/RpcServlet.java b/src/com/gitblit/RpcServlet.java index 6a8c2c59..ceed35e1 100644 --- a/src/com/gitblit/RpcServlet.java +++ b/src/com/gitblit/RpcServlet.java @@ -182,8 +182,8 @@ public class RpcServlet extends JsonServlet { } } else if (RpcRequest.LIST_SETTINGS.equals(reqType)) { // return the server's settings - result = GitBlit.self().getSettingModels(); - } else if (RpcRequest.LIST_SERVER_STATUS.equals(reqType)) { + result = GitBlit.self().getSettingsModel(); + } else if (RpcRequest.LIST_STATUS.equals(reqType)) { // return the server's status information result = GitBlit.self().getStatus(); } diff --git a/src/com/gitblit/client/EditUserDialog.java b/src/com/gitblit/client/EditUserDialog.java index 0a1ddd93..988f8fb0 100644 --- a/src/com/gitblit/client/EditUserDialog.java +++ b/src/com/gitblit/client/EditUserDialog.java @@ -29,7 +29,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; import javax.swing.ImageIcon; @@ -48,7 +47,7 @@ import javax.swing.KeyStroke; import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.Keys; import com.gitblit.models.RepositoryModel; -import com.gitblit.models.SettingModel; +import com.gitblit.models.ServerSettings; import com.gitblit.models.UserModel; import com.gitblit.utils.StringUtils; @@ -58,10 +57,10 @@ public class EditUserDialog extends JDialog { private final UserModel user; - private final Map settings; + private final ServerSettings settings; private boolean isCreate; - + private boolean canceled = true; private JTextField usernameField; @@ -78,13 +77,13 @@ public class EditUserDialog extends JDialog { private Set usernames; - public EditUserDialog(Map settings) { + public EditUserDialog(ServerSettings settings) { this(new UserModel(""), settings); this.isCreate = true; - setTitle(Translation.get("gb.newUser")); + setTitle(Translation.get("gb.newUser")); } - public EditUserDialog(UserModel anUser, Map settings) { + public EditUserDialog(UserModel anUser, ServerSettings settings) { super(); this.user = new UserModel(""); this.settings = settings; @@ -95,7 +94,7 @@ public class EditUserDialog extends JDialog { setTitle(Translation.get("gb.edit") + ": " + anUser.username); setIconImage(new ImageIcon(getClass().getResource("/gitblt-favicon.png")).getImage()); } - + @Override protected JRootPane createRootPane() { KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); @@ -203,8 +202,8 @@ public class EditUserDialog extends JDialog { } char[] pw = passwordField.getPassword(); if (pw == null || pw.length < minLength) { - error(MessageFormat.format( - "Password is too short. Minimum length is {0} characters.", minLength)); + error(MessageFormat.format("Password is too short. Minimum length is {0} characters.", + minLength)); return false; } char[] cpw = confirmPasswordField.getPassword(); diff --git a/src/com/gitblit/client/GitblitClient.java b/src/com/gitblit/client/GitblitClient.java new file mode 100644 index 00000000..76a67316 --- /dev/null +++ b/src/com/gitblit/client/GitblitClient.java @@ -0,0 +1,200 @@ +/* + * 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.io.IOException; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import com.gitblit.GitBlitException.ForbiddenException; +import com.gitblit.GitBlitException.UnauthorizedException; +import com.gitblit.Keys; +import com.gitblit.models.FederationModel; +import com.gitblit.models.RepositoryModel; +import com.gitblit.models.ServerSettings; +import com.gitblit.models.ServerStatus; +import com.gitblit.models.UserModel; +import com.gitblit.utils.RpcUtils; + +/** + * GitblitClient is a object that retrieves data from a Gitblit server, caches + * it for local operations, and allows updating or creating Gitblit objects. + * + * @author James Moger + * + */ +public class GitblitClient implements Serializable { + + private static final long serialVersionUID = 1L; + + public final String url; + + public final String account; + + private final char[] password; + + private volatile boolean isAdmin; + + private volatile ServerSettings settings; + + private final List allRepositories; + + private final List allUsers; + + private final List federationRegistrations; + + private ServerStatus status; + + public GitblitClient(String url, String account, char[] password) { + this.url = url; + this.account = account; + this.password = password; + + this.allUsers = new ArrayList(); + this.allRepositories = new ArrayList(); + this.federationRegistrations = new ArrayList(); + } + + public void login() throws IOException { + refreshRepositories(); + + try { + settings = RpcUtils.getSettings(url, account, password); + status = RpcUtils.getStatus(url, account, password); + refreshUsers(); + isAdmin = true; + } catch (UnauthorizedException e) { + } catch (ForbiddenException e) { + } catch (IOException e) { + System.err.println(e.getMessage()); + } + } + + public boolean allowAdmin() { + return isAdmin; + } + + public boolean isOwner(RepositoryModel model) { + return account != null && account.equalsIgnoreCase(model.owner); + } + + public ServerSettings getSettings() { + return settings; + } + + public ServerStatus getStatus() { + return status; + } + + public String getSettingDescription(String key) { + return settings.get(key).description; + } + + public List refreshRepositories() throws IOException { + Map repositories = RpcUtils + .getRepositories(url, account, password); + allRepositories.clear(); + allRepositories.addAll(repositories.values()); + Collections.sort(allRepositories); + return allRepositories; + } + + public List refreshUsers() throws IOException { + List users = RpcUtils.getUsers(url, account, password); + allUsers.clear(); + allUsers.addAll(users); + return allUsers; + } + + public List refreshFederationRegistrations() throws IOException { + List list = RpcUtils.getFederationRegistrations(url, account, password); + federationRegistrations.clear(); + federationRegistrations.addAll(list); + return federationRegistrations; + } + + public List getUsers() { + return allUsers; + } + + public List getUsernames() { + List usernames = new ArrayList(); + for (UserModel user : this.allUsers) { + usernames.add(user.username); + } + Collections.sort(usernames); + return usernames; + } + + public List getPermittedUsernames(RepositoryModel repository) { + List usernames = new ArrayList(); + for (UserModel user : this.allUsers) { + if (user.repositories.contains(repository.name)) { + usernames.add(user.username); + } + } + return usernames; + } + + public List getFederationSets() { + return settings.get(Keys.federation.sets).getStrings(); + } + + public List getRepositories() { + return allRepositories; + } + + public boolean createRepository(RepositoryModel repository, List permittedUsers) + throws IOException { + boolean success = true; + success &= RpcUtils.createRepository(repository, url, account, password); + if (permittedUsers.size() > 0) { + // if new repository has named members, set them + success &= RpcUtils.setRepositoryMembers(repository, permittedUsers, url, account, + password); + } + return success; + } + + public boolean updateRepository(String name, RepositoryModel repository, + List permittedUsers) throws IOException { + boolean success = true; + success &= RpcUtils.updateRepository(name, repository, url, account, password); + // always set the repository members + success &= RpcUtils + .setRepositoryMembers(repository, permittedUsers, url, account, password); + return success; + } + + public boolean deleteRepository(RepositoryModel repository) throws IOException { + return RpcUtils.deleteRepository(repository, url, account, password); + } + + public boolean createUser(UserModel user) throws IOException { + return RpcUtils.createUser(user, url, account, password); + } + + public boolean updateUser(String name, UserModel user) throws IOException { + return RpcUtils.updateUser(name, user, url, account, password); + } + + public boolean deleteUser(UserModel user) throws IOException { + return RpcUtils.deleteUser(user, url, account, password); + } +} diff --git a/src/com/gitblit/client/GitblitModel.java b/src/com/gitblit/client/GitblitModel.java deleted file mode 100644 index 55e74b9c..00000000 --- a/src/com/gitblit/client/GitblitModel.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * 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.io.IOException; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import com.gitblit.GitBlitException.ForbiddenException; -import com.gitblit.GitBlitException.UnauthorizedException; -import com.gitblit.Keys; -import com.gitblit.models.FederationModel; -import com.gitblit.models.RepositoryModel; -import com.gitblit.models.ServerStatus; -import com.gitblit.models.SettingModel; -import com.gitblit.models.UserModel; -import com.gitblit.utils.RpcUtils; - -public class GitblitModel implements Serializable { - - private static final long serialVersionUID = 1L; - - public final String url; - - public final String account; - - private final char[] password; - - private volatile boolean isAdmin; - - private volatile Map settings; - - private final List allRepositories; - - private final List allUsers; - - private final List federationRegistrations; - - private ServerStatus status; - - public GitblitModel(String url, String account, char[] password) { - this.url = url; - this.account = account; - this.password = password; - - this.allUsers = new ArrayList(); - this.allRepositories = new ArrayList(); - this.federationRegistrations = new ArrayList(); - } - - public void login() throws IOException { - refreshRepositories(); - - try { - settings = RpcUtils.getSettings(url, account, password); - status = RpcUtils.getStatus(url, account, password); - refreshUsers(); - isAdmin = true; - } catch (UnauthorizedException e) { - } catch (ForbiddenException e) { - } catch (IOException e) { - System.err.println(e.getMessage()); - } - } - - public boolean allowAdmin() { - return isAdmin; - } - - public boolean isOwner(RepositoryModel model) { - return account != null && account.equalsIgnoreCase(model.owner); - } - - public Map getSettings() { - return settings; - } - - public String getSettingDescription(String key) { - return settings.get(key).description; - } - - public List refreshRepositories() throws IOException { - Map repositories = RpcUtils - .getRepositories(url, account, password); - allRepositories.clear(); - allRepositories.addAll(repositories.values()); - Collections.sort(allRepositories); - return allRepositories; - } - - public List refreshUsers() throws IOException { - List users = RpcUtils.getUsers(url, account, password); - allUsers.clear(); - allUsers.addAll(users); - return allUsers; - } - - public List refreshFederationRegistrations() throws IOException { - List list = RpcUtils.getFederationRegistrations(url, account, password); - federationRegistrations.clear(); - federationRegistrations.addAll(list); - return federationRegistrations; - } - - public List getUsers() { - return allUsers; - } - - public List getUsernames() { - List usernames = new ArrayList(); - for (UserModel user : this.allUsers) { - usernames.add(user.username); - } - Collections.sort(usernames); - return usernames; - } - - public List getPermittedUsernames(RepositoryModel repository) { - List usernames = new ArrayList(); - for (UserModel user : this.allUsers) { - if (user.repositories.contains(repository.name)) { - usernames.add(user.username); - } - } - return usernames; - } - - public List getFederationSets() { - return settings.get(Keys.federation.sets).getStrings(); - } - - public List getRepositories() { - return allRepositories; - } - - public boolean createRepository(RepositoryModel repository, List permittedUsers) - throws IOException { - boolean success = true; - success &= RpcUtils.createRepository(repository, url, account, password); - if (permittedUsers.size() > 0) { - // if new repository has named members, set them - success &= RpcUtils.setRepositoryMembers(repository, permittedUsers, url, account, - password); - } - return success; - } - - public boolean updateRepository(String name, RepositoryModel repository, - List permittedUsers) throws IOException { - boolean success = true; - success &= RpcUtils.updateRepository(name, repository, url, account, password); - // always set the repository members - success &= RpcUtils - .setRepositoryMembers(repository, permittedUsers, url, account, password); - return success; - } - - public boolean deleteRepository(RepositoryModel repository) throws IOException { - return RpcUtils.deleteRepository(repository, url, account, password); - } - - public boolean createUser(UserModel user) throws IOException { - return RpcUtils.createUser(user, url, account, password); - } - - public boolean updateUser(String name, UserModel user) throws IOException { - return RpcUtils.updateUser(name, user, url, account, password); - } - - public boolean deleteUser(UserModel user) throws IOException { - return RpcUtils.deleteUser(user, url, account, password); - } -} diff --git a/src/com/gitblit/client/GitblitPanel.java b/src/com/gitblit/client/GitblitPanel.java index 8635b006..e4c6e76c 100644 --- a/src/com/gitblit/client/GitblitPanel.java +++ b/src/com/gitblit/client/GitblitPanel.java @@ -71,21 +71,21 @@ public class GitblitPanel extends JPanel implements CloseTabListener { private final Insets insets = new Insets(margin, margin, margin, margin); - private GitblitModel gitblit; + private GitblitClient gitblit; private JTabbedPane tabs; private JTable repositoriesTable; - private RepositoriesModel repositoriesModel; + private RepositoriesTableModel repositoriesModel; private JTable usersTable; - private UsersModel usersModel; + private UsersTableModel usersModel; private JTable settingsTable; - private SettingsModel settingsModel; + private SettingsTableModel settingsModel; private JButton createRepository; @@ -99,11 +99,11 @@ public class GitblitPanel extends JPanel implements CloseTabListener { private DefaultTableCellRenderer sizeRenderer; - private TableRowSorter defaultRepositoriesSorter; + private TableRowSorter defaultRepositoriesSorter; - private TableRowSorter defaultUsersSorter; + private TableRowSorter defaultUsersSorter; - private TableRowSorter defaultSettingsSorter; + private TableRowSorter defaultSettingsSorter; private JButton editRepository; @@ -112,7 +112,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener { } public GitblitPanel(String url, String account, char[] password) { - this.gitblit = new GitblitModel(url, account, password); + this.gitblit = new GitblitClient(url, account, password); tabs = new JTabbedPane(JTabbedPane.BOTTOM); tabs.addTab(Translation.get("gb.repositories"), createRepositoriesPanel()); @@ -180,17 +180,17 @@ public class GitblitPanel extends JPanel implements CloseTabListener { ownerRenderer.setForeground(Color.gray); ownerRenderer.setHorizontalAlignment(SwingConstants.CENTER); - repositoriesModel = new RepositoriesModel(); - defaultRepositoriesSorter = new TableRowSorter(repositoriesModel); + repositoriesModel = new RepositoriesTableModel(); + defaultRepositoriesSorter = new TableRowSorter(repositoriesModel); repositoriesTable = Utils.newTable(repositoriesModel); repositoriesTable.setRowHeight(nameRenderer.getFont().getSize() + 8); repositoriesTable.setRowSorter(defaultRepositoriesSorter); - repositoriesTable.getRowSorter().toggleSortOrder(RepositoriesModel.Columns.Name.ordinal()); + repositoriesTable.getRowSorter().toggleSortOrder(RepositoriesTableModel.Columns.Name.ordinal()); - setRepositoryRenderer(RepositoriesModel.Columns.Name, nameRenderer, -1); - setRepositoryRenderer(RepositoriesModel.Columns.Indicators, typeRenderer, 100); - setRepositoryRenderer(RepositoriesModel.Columns.Owner, ownerRenderer, -1); - setRepositoryRenderer(RepositoriesModel.Columns.Size, sizeRenderer, 60); + setRepositoryRenderer(RepositoriesTableModel.Columns.Name, nameRenderer, -1); + setRepositoryRenderer(RepositoriesTableModel.Columns.Indicators, typeRenderer, 100); + setRepositoryRenderer(RepositoriesTableModel.Columns.Owner, ownerRenderer, -1); + setRepositoryRenderer(RepositoriesTableModel.Columns.Size, sizeRenderer, 60); repositoriesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override @@ -205,7 +205,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener { if (selected) { int viewRow = repositoriesTable.getSelectedRow(); int modelRow = repositoriesTable.convertRowIndexToModel(viewRow); - RepositoryModel model = ((RepositoriesModel) repositoriesTable.getModel()).list + RepositoryModel model = ((RepositoriesTableModel) repositoriesTable.getModel()).list .get(modelRow); editRepository.setEnabled(singleSelection && (gitblit.allowAdmin() || gitblit.isOwner(model))); @@ -266,7 +266,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener { return repositoriesPanel; } - private void setRepositoryRenderer(RepositoriesModel.Columns col, TableCellRenderer renderer, + private void setRepositoryRenderer(RepositoriesTableModel.Columns col, TableCellRenderer renderer, int maxWidth) { String name = repositoriesTable.getColumnName(col.ordinal()); repositoriesTable.getColumn(name).setCellRenderer(renderer); @@ -307,14 +307,14 @@ public class GitblitPanel extends JPanel implements CloseTabListener { } }); - usersModel = new UsersModel(); - defaultUsersSorter = new TableRowSorter(usersModel); + usersModel = new UsersTableModel(); + defaultUsersSorter = new TableRowSorter(usersModel); usersTable = Utils.newTable(usersModel); - String name = usersTable.getColumnName(UsersModel.Columns.Name.ordinal()); + String name = usersTable.getColumnName(UsersTableModel.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.getRowSorter().toggleSortOrder(UsersTableModel.Columns.Name.ordinal()); usersTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override @@ -381,15 +381,15 @@ public class GitblitPanel extends JPanel implements CloseTabListener { private JPanel createSettingsPanel() { final SettingPanel settingPanel = new SettingPanel(); - settingsModel = new SettingsModel(); - defaultSettingsSorter = new TableRowSorter(settingsModel); + settingsModel = new SettingsTableModel(); + defaultSettingsSorter = new TableRowSorter(settingsModel); settingsTable = Utils.newTable(settingsModel); settingsTable.setDefaultRenderer(SettingModel.class, new SettingCellRenderer()); - String name = settingsTable.getColumnName(UsersModel.Columns.Name.ordinal()); + String name = settingsTable.getColumnName(UsersTableModel.Columns.Name.ordinal()); settingsTable.setRowHeight(nameRenderer.getFont().getSize() + 8); settingsTable.getColumn(name).setCellRenderer(nameRenderer); settingsTable.setRowSorter(defaultSettingsSorter); - settingsTable.getRowSorter().toggleSortOrder(SettingsModel.Columns.Name.ordinal()); + settingsTable.getRowSorter().toggleSortOrder(SettingsTableModel.Columns.Name.ordinal()); settingsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override @@ -496,8 +496,8 @@ public class GitblitPanel extends JPanel implements CloseTabListener { repositoriesTable.setRowSorter(defaultRepositoriesSorter); return; } - RowFilter containsFilter = new RowFilter() { - public boolean include(Entry entry) { + RowFilter containsFilter = new RowFilter() { + public boolean include(Entry entry) { for (int i = entry.getValueCount() - 1; i >= 0; i--) { if (entry.getStringValue(i).toLowerCase().contains(fragment.toLowerCase())) { return true; @@ -506,7 +506,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener { return false; } }; - TableRowSorter sorter = new TableRowSorter( + TableRowSorter sorter = new TableRowSorter( repositoriesModel); sorter.setRowFilter(containsFilter); repositoriesTable.setRowSorter(sorter); @@ -517,8 +517,8 @@ public class GitblitPanel extends JPanel implements CloseTabListener { usersTable.setRowSorter(defaultUsersSorter); return; } - RowFilter containsFilter = new RowFilter() { - public boolean include(Entry entry) { + RowFilter containsFilter = new RowFilter() { + public boolean include(Entry entry) { for (int i = entry.getValueCount() - 1; i >= 0; i--) { if (entry.getStringValue(i).toLowerCase().contains(fragment.toLowerCase())) { return true; @@ -527,7 +527,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener { return false; } }; - TableRowSorter sorter = new TableRowSorter(usersModel); + TableRowSorter sorter = new TableRowSorter(usersModel); sorter.setRowFilter(containsFilter); usersTable.setRowSorter(sorter); } @@ -537,8 +537,8 @@ public class GitblitPanel extends JPanel implements CloseTabListener { settingsTable.setRowSorter(defaultSettingsSorter); return; } - RowFilter containsFilter = new RowFilter() { - public boolean include(Entry entry) { + RowFilter containsFilter = new RowFilter() { + public boolean include(Entry entry) { for (int i = entry.getValueCount() - 1; i >= 0; i--) { if (entry.getStringValue(i).toLowerCase().contains(fragment.toLowerCase())) { return true; @@ -547,7 +547,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener { return false; } }; - TableRowSorter sorter = new TableRowSorter(settingsModel); + TableRowSorter sorter = new TableRowSorter(settingsModel); sorter.setRowFilter(containsFilter); settingsTable.setRowSorter(sorter); } diff --git a/src/com/gitblit/client/RegistrationsDialog.java b/src/com/gitblit/client/RegistrationsDialog.java index ae53d5fa..71178f30 100644 --- a/src/com/gitblit/client/RegistrationsDialog.java +++ b/src/com/gitblit/client/RegistrationsDialog.java @@ -56,7 +56,7 @@ public class RegistrationsDialog extends JDialog { private JTable registrationsTable; - private RegistrationsModel model; + private RegistrationsTableModel model; public RegistrationsDialog(List registrations, RegistrationListener listener) { @@ -83,11 +83,11 @@ public class RegistrationsDialog extends JDialog { private void initialize() { NameRenderer nameRenderer = new NameRenderer(); - model = new RegistrationsModel(registrations); + model = new RegistrationsTableModel(registrations); registrationsTable = Utils.newTable(model); registrationsTable.setRowHeight(nameRenderer.getFont().getSize() + 8); - String id = registrationsTable.getColumnName(RegistrationsModel.Columns.Name.ordinal()); + String id = registrationsTable.getColumnName(RegistrationsTableModel.Columns.Name.ordinal()); registrationsTable.getColumn(id).setCellRenderer(nameRenderer); registrationsTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { diff --git a/src/com/gitblit/client/RegistrationsModel.java b/src/com/gitblit/client/RegistrationsModel.java deleted file mode 100644 index 8b4966ca..00000000 --- a/src/com/gitblit/client/RegistrationsModel.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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.Collections; -import java.util.Date; -import java.util.List; - -import javax.swing.table.AbstractTableModel; - -/** - * Table model of a list of Gitblit server registrations. - * - * @author James Moger - * - */ -public class RegistrationsModel extends AbstractTableModel { - - private static final long serialVersionUID = 1L; - - List list; - - enum Columns { - Name, URL, Last_Login; - - @Override - public String toString() { - return name().replace('_', ' '); - } - } - - public RegistrationsModel(List list) { - this.list = list; - 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"); - case URL: - return Translation.get("gb.url"); - case Last_Login: - return Translation.get("gb.lastLogin"); - } - return ""; - } - - /** - * Returns Object.class regardless of columnIndex. - * - * @param columnIndex - * the column being queried - * @return the Object.class - */ - public Class getColumnClass(int columnIndex) { - if (columnIndex == Columns.Last_Login.ordinal()) { - return Date.class; - } - return String.class; - } - - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - GitblitRegistration model = list.get(rowIndex); - Columns col = Columns.values()[columnIndex]; - switch (col) { - case Name: - return model.name; - case URL: - return model.url; - case Last_Login: - return model.lastLogin; - } - return null; - } -} diff --git a/src/com/gitblit/client/RegistrationsTableModel.java b/src/com/gitblit/client/RegistrationsTableModel.java new file mode 100644 index 00000000..8c6b34ff --- /dev/null +++ b/src/com/gitblit/client/RegistrationsTableModel.java @@ -0,0 +1,102 @@ +/* + * 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.Collections; +import java.util.Date; +import java.util.List; + +import javax.swing.table.AbstractTableModel; + +/** + * Table model of a list of Gitblit server registrations. + * + * @author James Moger + * + */ +public class RegistrationsTableModel extends AbstractTableModel { + + private static final long serialVersionUID = 1L; + + List list; + + enum Columns { + Name, URL, Last_Login; + + @Override + public String toString() { + return name().replace('_', ' '); + } + } + + public RegistrationsTableModel(List list) { + this.list = list; + 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"); + case URL: + return Translation.get("gb.url"); + case Last_Login: + return Translation.get("gb.lastLogin"); + } + return ""; + } + + /** + * Returns Object.class regardless of columnIndex. + * + * @param columnIndex + * the column being queried + * @return the Object.class + */ + public Class getColumnClass(int columnIndex) { + if (columnIndex == Columns.Last_Login.ordinal()) { + return Date.class; + } + return String.class; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + GitblitRegistration model = list.get(rowIndex); + Columns col = Columns.values()[columnIndex]; + switch (col) { + case Name: + return model.name; + case URL: + return model.url; + case Last_Login: + return model.lastLogin; + } + return null; + } +} diff --git a/src/com/gitblit/client/RepositoriesModel.java b/src/com/gitblit/client/RepositoriesModel.java deleted file mode 100644 index c1fead91..00000000 --- a/src/com/gitblit/client/RepositoriesModel.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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.Date; -import java.util.List; - -import javax.swing.table.AbstractTableModel; - -import com.gitblit.models.RepositoryModel; - -/** - * Table model of a list of repositories. - * - * @author James Moger - * - */ -public class RepositoriesModel extends AbstractTableModel { - - private static final long serialVersionUID = 1L; - - List list; - - enum Columns { - Name, Description, Owner, Indicators, Last_Change, Size; - - @Override - public String toString() { - return name().replace('_', ' '); - } - } - - public RepositoriesModel() { - this(new ArrayList()); - } - - public RepositoriesModel(List repositories) { - this.list = repositories; - 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"); - case Description: - return Translation.get("gb.description"); - case Owner: - return Translation.get("gb.owner"); - case Last_Change: - return Translation.get("gb.lastChange"); - case Size: - return Translation.get("gb.size"); - } - return ""; - } - - /** - * Returns Object.class regardless of columnIndex. - * - * @param columnIndex - * the column being queried - * @return the Object.class - */ - public Class getColumnClass(int columnIndex) { - Columns col = Columns.values()[columnIndex]; - switch (col) { - case Name: - case Indicators: - return RepositoryModel.class; - case Last_Change: - return Date.class; - } - return String.class; - } - - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - RepositoryModel model = list.get(rowIndex); - Columns col = Columns.values()[columnIndex]; - switch (col) { - case Name: - return model; - case Description: - return model.description; - case Owner: - return model.owner; - case Indicators: - return model; - case Last_Change: - return model.lastChange; - case Size: - return model.size; - } - return null; - } -} diff --git a/src/com/gitblit/client/RepositoriesTableModel.java b/src/com/gitblit/client/RepositoriesTableModel.java new file mode 100644 index 00000000..9dd1a998 --- /dev/null +++ b/src/com/gitblit/client/RepositoriesTableModel.java @@ -0,0 +1,124 @@ +/* + * 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.Date; +import java.util.List; + +import javax.swing.table.AbstractTableModel; + +import com.gitblit.models.RepositoryModel; + +/** + * Table model of a list of repositories. + * + * @author James Moger + * + */ +public class RepositoriesTableModel extends AbstractTableModel { + + private static final long serialVersionUID = 1L; + + List list; + + enum Columns { + Name, Description, Owner, Indicators, Last_Change, Size; + + @Override + public String toString() { + return name().replace('_', ' '); + } + } + + public RepositoriesTableModel() { + this(new ArrayList()); + } + + public RepositoriesTableModel(List repositories) { + this.list = repositories; + 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"); + case Description: + return Translation.get("gb.description"); + case Owner: + return Translation.get("gb.owner"); + case Last_Change: + return Translation.get("gb.lastChange"); + case Size: + return Translation.get("gb.size"); + } + return ""; + } + + /** + * Returns Object.class regardless of columnIndex. + * + * @param columnIndex + * the column being queried + * @return the Object.class + */ + public Class getColumnClass(int columnIndex) { + Columns col = Columns.values()[columnIndex]; + switch (col) { + case Name: + case Indicators: + return RepositoryModel.class; + case Last_Change: + return Date.class; + } + return String.class; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + RepositoryModel model = list.get(rowIndex); + Columns col = Columns.values()[columnIndex]; + switch (col) { + case Name: + return model; + case Description: + return model.description; + case Owner: + return model.owner; + case Indicators: + return model; + case Last_Change: + return model.lastChange; + case Size: + return model.size; + } + return null; + } +} diff --git a/src/com/gitblit/client/SettingsModel.java b/src/com/gitblit/client/SettingsModel.java deleted file mode 100644 index af3c1b60..00000000 --- a/src/com/gitblit/client/SettingsModel.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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 java.util.Map; - -import javax.swing.table.AbstractTableModel; - -import com.gitblit.models.SettingModel; - -/** - * Table model of Map. - * - * @author James Moger - * - */ -public class SettingsModel extends AbstractTableModel { - - private static final long serialVersionUID = 1L; - - Map settings; - - List keys; - - enum Columns { - Name, Value; - - @Override - public String toString() { - return name().replace('_', ' '); - } - } - - public SettingsModel() { - this(null); - } - - public SettingsModel(Map settings) { - setSettings(settings); - } - - public void setSettings(Map settings) { - this.settings = settings; - if (settings == null) { - keys = new ArrayList(); - } else { - keys = new ArrayList(settings.keySet()); - Collections.sort(keys); - } - } - - @Override - public int getRowCount() { - return keys.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 Object.class regardless of columnIndex. - * - * @param columnIndex - * the column being queried - * @return the Object.class - */ - public Class getColumnClass(int columnIndex) { - if (Columns.Value.ordinal() == columnIndex) { - return SettingModel.class; - } - return String.class; - } - - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - String key = keys.get(rowIndex); - SettingModel setting = settings.get(key); - Columns col = Columns.values()[columnIndex]; - switch (col) { - case Name: - return key; - case Value: - return setting; - } - return null; - } - - public SettingModel get(int modelRow) { - String key = keys.get(modelRow); - return settings.get(key); - } -} diff --git a/src/com/gitblit/client/SettingsTableModel.java b/src/com/gitblit/client/SettingsTableModel.java new file mode 100644 index 00000000..e6d23135 --- /dev/null +++ b/src/com/gitblit/client/SettingsTableModel.java @@ -0,0 +1,120 @@ +/* + * 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.ServerSettings; +import com.gitblit.models.SettingModel; + +/** + * Table model of Map. + * + * @author James Moger + * + */ +public class SettingsTableModel extends AbstractTableModel { + + private static final long serialVersionUID = 1L; + + ServerSettings settings; + + List keys; + + enum Columns { + Name, Value; + + @Override + public String toString() { + return name().replace('_', ' '); + } + } + + public SettingsTableModel() { + this(null); + } + + public SettingsTableModel(ServerSettings settings) { + setSettings(settings); + } + + public void setSettings(ServerSettings settings) { + this.settings = settings; + if (settings == null) { + keys = new ArrayList(); + } else { + keys = new ArrayList(settings.getKeys()); + Collections.sort(keys); + } + } + + @Override + public int getRowCount() { + return keys.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 Object.class regardless of columnIndex. + * + * @param columnIndex + * the column being queried + * @return the Object.class + */ + public Class getColumnClass(int columnIndex) { + if (Columns.Value.ordinal() == columnIndex) { + return SettingModel.class; + } + return String.class; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + String key = keys.get(rowIndex); + SettingModel setting = settings.get(key); + Columns col = Columns.values()[columnIndex]; + switch (col) { + case Name: + return key; + case Value: + return setting; + } + return null; + } + + public SettingModel get(int modelRow) { + String key = keys.get(modelRow); + return settings.get(key); + } +} diff --git a/src/com/gitblit/client/UsersModel.java b/src/com/gitblit/client/UsersModel.java deleted file mode 100644 index 2b3c6443..00000000 --- a/src/com/gitblit/client/UsersModel.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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 list; - - enum Columns { - Name; - - @Override - public String toString() { - return name().replace('_', ' '); - } - } - - public UsersModel() { - this(new ArrayList()); - } - - public UsersModel(List 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 Object.class regardless of columnIndex. - * - * @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/UsersTableModel.java b/src/com/gitblit/client/UsersTableModel.java new file mode 100644 index 00000000..57536adc --- /dev/null +++ b/src/com/gitblit/client/UsersTableModel.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 UsersTableModel extends AbstractTableModel { + + private static final long serialVersionUID = 1L; + + List list; + + enum Columns { + Name; + + @Override + public String toString() { + return name().replace('_', ' '); + } + } + + public UsersTableModel() { + this(new ArrayList()); + } + + public UsersTableModel(List 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 Object.class regardless of columnIndex. + * + * @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/models/ServerSettings.java b/src/com/gitblit/models/ServerSettings.java new file mode 100644 index 00000000..47148d32 --- /dev/null +++ b/src/com/gitblit/models/ServerSettings.java @@ -0,0 +1,63 @@ +/* + * 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.models; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import com.gitblit.IStoredSettings; + +/** + * Server settings represents the settings of the Gitblit server including all + * setting metadata such as name, current value, default value, description, and + * directives. It is a model class for serialization and presentation, but not + * for persistence. + * + * @author James Moger + */ +public class ServerSettings implements Serializable { + + private final Map settings; + + private static final long serialVersionUID = 1L; + + public ServerSettings() { + settings = new TreeMap(); + } + + public List getKeys() { + return new ArrayList(settings.keySet()); + } + + public void add(SettingModel setting) { + settings.put(setting.name, setting); + } + + public SettingModel get(String key) { + return settings.get(key); + } + + public void updateCurrentValues(IStoredSettings storedSettings) { + for (String key : storedSettings.getAllKeys(null)) { + if (settings.containsKey(key)) { + settings.get(key).currentValue = storedSettings.getString(key, ""); + } + } + } +} diff --git a/src/com/gitblit/models/ServerStatus.java b/src/com/gitblit/models/ServerStatus.java index b1dc52dd..8dfc0fbc 100644 --- a/src/com/gitblit/models/ServerStatus.java +++ b/src/com/gitblit/models/ServerStatus.java @@ -17,12 +17,12 @@ package com.gitblit.models; import java.io.Serializable; import java.util.Date; -import java.util.HashMap; import java.util.Map; +import java.util.TreeMap; /** * ServerStatus encapsulates runtime status information about the server - * including the system environment. + * including some information about the system environment. * * @author James Moger * @@ -33,10 +33,10 @@ public class ServerStatus implements Serializable { public final Date bootDate; + public final Map systemProperties; + public final long heapSize; - public final Map systemProperties; - public volatile long heapAllocated; public volatile long heapFree; @@ -46,7 +46,7 @@ public class ServerStatus implements Serializable { heapSize = Runtime.getRuntime().maxMemory(); - systemProperties = new HashMap(); + systemProperties = new TreeMap(); put("file.encoding"); put("java.home"); put("java.io.tmpdir"); diff --git a/src/com/gitblit/utils/RpcUtils.java b/src/com/gitblit/utils/RpcUtils.java index 440dabdb..2d409a0a 100644 --- a/src/com/gitblit/utils/RpcUtils.java +++ b/src/com/gitblit/utils/RpcUtils.java @@ -29,7 +29,7 @@ import com.gitblit.models.FederationProposal; import com.gitblit.models.FederationSet; import com.gitblit.models.RepositoryModel; import com.gitblit.models.ServerStatus; -import com.gitblit.models.SettingModel; +import com.gitblit.models.ServerSettings; import com.gitblit.models.UserModel; import com.google.gson.reflect.TypeToken; @@ -59,9 +59,6 @@ public class RpcUtils { private static final Type SETS_TYPE = new TypeToken>() { }.getType(); - private static final Type SETTINGS_TYPE = new TypeToken>() { - }.getType(); - /** * * @param remoteURL @@ -341,14 +338,13 @@ public class RpcUtils { * @param serverUrl * @param account * @param password - * @return an Map object + * @return an Settings object * @throws IOException */ - public static Map getSettings(String serverUrl, String account, - char[] password) throws IOException { + public static ServerSettings getSettings(String serverUrl, String account, char[] password) + throws IOException { String url = asLink(serverUrl, RpcRequest.LIST_SETTINGS); - Map settings = JsonUtils.retrieveJson(url, SETTINGS_TYPE, account, - password); + ServerSettings settings = JsonUtils.retrieveJson(url, ServerSettings.class, account, password); return settings; } @@ -363,7 +359,7 @@ public class RpcUtils { */ public static ServerStatus getStatus(String serverUrl, String account, char[] password) throws IOException { - String url = asLink(serverUrl, RpcRequest.LIST_SERVER_STATUS); + String url = asLink(serverUrl, RpcRequest.LIST_STATUS); ServerStatus status = JsonUtils.retrieveJson(url, ServerStatus.class, account, password); return status; } diff --git a/tests/com/gitblit/tests/RpcTests.java b/tests/com/gitblit/tests/RpcTests.java index 3c2f61f9..11a340a9 100644 --- a/tests/com/gitblit/tests/RpcTests.java +++ b/tests/com/gitblit/tests/RpcTests.java @@ -27,8 +27,8 @@ import com.gitblit.models.FederationModel; import com.gitblit.models.FederationProposal; import com.gitblit.models.FederationSet; import com.gitblit.models.RepositoryModel; +import com.gitblit.models.ServerSettings; import com.gitblit.models.ServerStatus; -import com.gitblit.models.SettingModel; import com.gitblit.models.UserModel; import com.gitblit.utils.RpcUtils; @@ -207,7 +207,7 @@ public class RpcTests extends TestCase { } public void testSettings() throws Exception { - Map settings = RpcUtils.getSettings(url, account, password.toCharArray()); + ServerSettings settings = RpcUtils.getSettings(url, account, password.toCharArray()); assertTrue("No settings were retrieved!", settings != null); }