From 6fa6abf07be67bba86e9781a4028c4b3863b50f7 Mon Sep 17 00:00:00 2001 From: James Moger Date: Mon, 5 Mar 2012 16:32:18 -0500 Subject: [PATCH] Replace ChoiceRenderer with StringChoiceRenderer (issue 71) --- docs/04_releases.mkd | 1 + .../gitblit/wicket/StringChoiceRenderer.java | 43 +++++++++++++++++++ .../wicket/pages/EditRepositoryPage.java | 12 +++--- .../gitblit/wicket/pages/EditTeamPage.java | 14 +++--- .../gitblit/wicket/pages/EditUserPage.java | 6 +-- 5 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 src/com/gitblit/wicket/StringChoiceRenderer.java diff --git a/docs/04_releases.mkd b/docs/04_releases.mkd index da886334..fed78166 100644 --- a/docs/04_releases.mkd +++ b/docs/04_releases.mkd @@ -30,6 +30,7 @@ Push requests to these repositories will be rejected. #### fixes +- Uppercase repositories not selectable in edit palettes (issue 71) - Activity page now displays all local branches (issue 65) - Fixed (harmless) nullpointer on pushing to an empty repository (issue 69) - Fixed possible nullpointer from the servlet container on startup (issue 67) diff --git a/src/com/gitblit/wicket/StringChoiceRenderer.java b/src/com/gitblit/wicket/StringChoiceRenderer.java new file mode 100644 index 00000000..58ed4798 --- /dev/null +++ b/src/com/gitblit/wicket/StringChoiceRenderer.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012 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.wicket; + +import org.apache.wicket.markup.html.form.ChoiceRenderer; + +/** + * Choice renderer for a palette or list of string values. This renderer + * controls the id value of each option such that palettes are case insensitive. + * + * @author James Moger + * + */ +public class StringChoiceRenderer extends ChoiceRenderer { + + private static final long serialVersionUID = 1L; + + public StringChoiceRenderer() { + super("", ""); + } + + /** + * @see org.apache.wicket.markup.html.form.IChoiceRenderer#getIdValue(java.lang.Object, int) + */ + @Override + public String getIdValue(String object, int index) + { + return object.toLowerCase(); + } +} diff --git a/src/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/com/gitblit/wicket/pages/EditRepositoryPage.java index 0361da3e..1eae2c98 100644 --- a/src/com/gitblit/wicket/pages/EditRepositoryPage.java +++ b/src/com/gitblit/wicket/pages/EditRepositoryPage.java @@ -30,7 +30,6 @@ import org.apache.wicket.behavior.SimpleAttributeModifier; import org.apache.wicket.extensions.markup.html.form.palette.Palette; import org.apache.wicket.markup.html.form.Button; import org.apache.wicket.markup.html.form.CheckBox; -import org.apache.wicket.markup.html.form.ChoiceRenderer; import org.apache.wicket.markup.html.form.DropDownChoice; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.IChoiceRenderer; @@ -51,6 +50,7 @@ import com.gitblit.models.UserModel; import com.gitblit.utils.ArrayUtils; import com.gitblit.utils.StringUtils; import com.gitblit.wicket.GitBlitWebSession; +import com.gitblit.wicket.StringChoiceRenderer; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.panels.BulletListPanel; @@ -104,18 +104,18 @@ public class EditRepositoryPage extends RootSubPage { // users palette final Palette usersPalette = new Palette("users", new ListModel( repositoryUsers), new CollectionModel(GitBlit.self().getAllUsernames()), - new ChoiceRenderer("", ""), 10, false); + new StringChoiceRenderer(), 10, false); // teams palette final Palette teamsPalette = new Palette("teams", new ListModel( repositoryTeams), new CollectionModel(GitBlit.self().getAllTeamnames()), - new ChoiceRenderer("", ""), 5, false); + new StringChoiceRenderer(), 5, false); // federation sets palette List sets = GitBlit.getStrings(Keys.federation.sets); final Palette federationSetsPalette = new Palette("federationSets", new ListModel(federationSets), new CollectionModel(sets), - new ChoiceRenderer("", ""), 5, false); + new StringChoiceRenderer(), 5, false); // pre-receive palette if (!ArrayUtils.isEmpty(repositoryModel.preReceiveScripts)) { @@ -124,7 +124,7 @@ public class EditRepositoryPage extends RootSubPage { final Palette preReceivePalette = new Palette("preReceiveScripts", new ListModel(preReceiveScripts), new CollectionModel(GitBlit .self().getPreReceiveScriptsUnused(repositoryModel)), - new ChoiceRenderer("", ""), 12, true); + new StringChoiceRenderer(), 12, true); // post-receive palette if (!ArrayUtils.isEmpty(repositoryModel.postReceiveScripts)) { @@ -133,7 +133,7 @@ public class EditRepositoryPage extends RootSubPage { final Palette postReceivePalette = new Palette("postReceiveScripts", new ListModel(postReceiveScripts), new CollectionModel(GitBlit .self().getPostReceiveScriptsUnused(repositoryModel)), - new ChoiceRenderer("", ""), 12, true); + new StringChoiceRenderer(), 12, true); CompoundPropertyModel model = new CompoundPropertyModel( repositoryModel); diff --git a/src/com/gitblit/wicket/pages/EditTeamPage.java b/src/com/gitblit/wicket/pages/EditTeamPage.java index 57e97351..2ed5fba6 100644 --- a/src/com/gitblit/wicket/pages/EditTeamPage.java +++ b/src/com/gitblit/wicket/pages/EditTeamPage.java @@ -27,7 +27,6 @@ import org.apache.wicket.PageParameters; import org.apache.wicket.behavior.SimpleAttributeModifier; import org.apache.wicket.extensions.markup.html.form.palette.Palette; import org.apache.wicket.markup.html.form.Button; -import org.apache.wicket.markup.html.form.ChoiceRenderer; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.model.CompoundPropertyModel; @@ -43,6 +42,7 @@ import com.gitblit.models.RepositoryModel; import com.gitblit.models.TeamModel; import com.gitblit.utils.StringUtils; import com.gitblit.wicket.RequiresAdminRole; +import com.gitblit.wicket.StringChoiceRenderer; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.panels.BulletListPanel; @@ -97,12 +97,12 @@ public class EditTeamPage extends RootSubPage { // repositories palette final Palette repositories = new Palette("repositories", new ListModel(new ArrayList(teamModel.repositories)), - new CollectionModel(repos), new ChoiceRenderer("", ""), 10, false); + new CollectionModel(repos), new StringChoiceRenderer(), 10, false); // users palette final Palette users = new Palette("users", new ListModel( new ArrayList(teamUsers)), new CollectionModel(GitBlit.self() - .getAllUsernames()), new ChoiceRenderer("", ""), 10, false); + .getAllUsernames()), new StringChoiceRenderer(), 10, false); // pre-receive palette if (teamModel.preReceiveScripts != null) { @@ -110,8 +110,8 @@ public class EditTeamPage extends RootSubPage { } final Palette preReceivePalette = new Palette("preReceiveScripts", new ListModel(preReceiveScripts), new CollectionModel(GitBlit - .self().getPreReceiveScriptsUnused(null)), new ChoiceRenderer("", - ""), 12, true); + .self().getPreReceiveScriptsUnused(null)), new StringChoiceRenderer(), + 12, true); // post-receive palette if (teamModel.postReceiveScripts != null) { @@ -119,8 +119,8 @@ public class EditTeamPage extends RootSubPage { } final Palette postReceivePalette = new Palette("postReceiveScripts", new ListModel(postReceiveScripts), new CollectionModel(GitBlit - .self().getPostReceiveScriptsUnused(null)), new ChoiceRenderer("", - ""), 12, true); + .self().getPostReceiveScriptsUnused(null)), new StringChoiceRenderer(), + 12, true); Form form = new Form("editForm", model) { diff --git a/src/com/gitblit/wicket/pages/EditUserPage.java b/src/com/gitblit/wicket/pages/EditUserPage.java index 62d955e2..3e14d083 100644 --- a/src/com/gitblit/wicket/pages/EditUserPage.java +++ b/src/com/gitblit/wicket/pages/EditUserPage.java @@ -26,7 +26,6 @@ import org.apache.wicket.behavior.SimpleAttributeModifier; import org.apache.wicket.extensions.markup.html.form.palette.Palette; import org.apache.wicket.markup.html.form.Button; import org.apache.wicket.markup.html.form.CheckBox; -import org.apache.wicket.markup.html.form.ChoiceRenderer; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.PasswordTextField; import org.apache.wicket.markup.html.form.TextField; @@ -44,6 +43,7 @@ import com.gitblit.models.TeamModel; import com.gitblit.models.UserModel; import com.gitblit.utils.StringUtils; import com.gitblit.wicket.RequiresAdminRole; +import com.gitblit.wicket.StringChoiceRenderer; import com.gitblit.wicket.WicketUtils; @RequiresAdminRole @@ -94,10 +94,10 @@ public class EditUserPage extends RootSubPage { final String oldName = userModel.username; final Palette repositories = new Palette("repositories", new ListModel(new ArrayList(userModel.repositories)), - new CollectionModel(repos), new ChoiceRenderer("", ""), 10, false); + new CollectionModel(repos), new StringChoiceRenderer(), 10, false); final Palette teams = new Palette("teams", new ListModel( new ArrayList(userTeams)), new CollectionModel(GitBlit.self() - .getAllTeamnames()), new ChoiceRenderer("", ""), 10, false); + .getAllTeamnames()), new StringChoiceRenderer(), 10, false); Form form = new Form("editForm", model) { private static final long serialVersionUID = 1L; -- 2.39.5