]> source.dussan.org Git - gitblit.git/commitdiff
Use separate project and name field models in the RepositoryNamePanel 96/96/1
authorJames Moger <james.moger@gitblit.com>
Mon, 9 Jun 2014 13:10:13 +0000 (09:10 -0400)
committerJames Moger <james.moger@gitblit.com>
Mon, 9 Jun 2014 13:10:13 +0000 (09:10 -0400)
src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java
src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java
src/main/java/com/gitblit/wicket/panels/RepositoryNamePanel.java

index a0e6e7bab9c6946b2259b362bcd9fc0a7f2525c6..a1c373851d7f70a071b55c3d952a0fedcce3aa11 100644 (file)
@@ -70,8 +70,8 @@ import com.gitblit.wicket.StringChoiceRenderer;
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.panels.AccessPolicyPanel;\r
 import com.gitblit.wicket.panels.BasePanel.JavascriptEventConfirmation;\r
-import com.gitblit.wicket.panels.BulletListPanel;\r
 import com.gitblit.wicket.panels.BooleanOption;\r
+import com.gitblit.wicket.panels.BulletListPanel;\r
 import com.gitblit.wicket.panels.ChoiceOption;\r
 import com.gitblit.wicket.panels.RegistrantPermissionsPanel;\r
 import com.gitblit.wicket.panels.RepositoryNamePanel;\r
@@ -383,7 +383,6 @@ public class EditRepositoryPage extends RootSubPage {
                                        }\r
                                } catch (GitBlitException e) {\r
                                        error(e.getMessage());\r
-                                       namePanel.resetModel(repositoryModel);\r
                                        return;\r
                                }\r
                                setRedirect(false);\r
index b8752e330b068e3aad145e3ce31b07342a7b22c1..4687716831bcf7590de4b9e6cc88279f8ceb8652 100644 (file)
@@ -56,8 +56,8 @@ import com.gitblit.utils.StringUtils;
 import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.panels.AccessPolicyPanel;\r
-import com.gitblit.wicket.panels.BooleanOption;\r
 import com.gitblit.wicket.panels.BooleanChoiceOption;\r
+import com.gitblit.wicket.panels.BooleanOption;\r
 import com.gitblit.wicket.panels.RepositoryNamePanel;\r
 \r
 public class NewRepositoryPage extends RootSubPage {\r
@@ -142,7 +142,6 @@ public class NewRepositoryPage extends RootSubPage {
 \r
                                } catch (GitBlitException e) {\r
                                        error(e.getMessage());\r
-                                       namePanel.resetModel(repositoryModel);\r
                                        return;\r
                                }\r
                                setRedirect(true);\r
index 358ff59b5460dd6eaf2878472395bb5b677a5dcf..d3e493ed60d697c7c3e111fc2b5fdbef8176a456 100644 (file)
@@ -22,6 +22,8 @@ import java.util.TreeSet;
 \r
 import org.apache.wicket.markup.html.form.DropDownChoice;\r
 import org.apache.wicket.markup.html.form.TextField;\r
+import org.apache.wicket.model.IModel;\r
+import org.apache.wicket.model.Model;\r
 \r
 import com.gitblit.models.ProjectModel;\r
 import com.gitblit.models.RepositoryModel;\r
@@ -41,7 +43,11 @@ public class RepositoryNamePanel extends BasePanel {
 \r
        private String fullName;\r
 \r
-       private DropDownChoice<String> projectChoice;\r
+       private final IModel<String> projectPath;\r
+\r
+       private DropDownChoice<String> pathChoice;\r
+\r
+       private final IModel<String> repoName;\r
 \r
        private TextField<String> nameField;\r
 \r
@@ -52,84 +58,82 @@ public class RepositoryNamePanel extends BasePanel {
                UserModel user = session.getUser();\r
 \r
                // build project set for repository destination\r
-               String defaultProject = null;\r
-               Set<String> projectNames = new TreeSet<String>();\r
+               String defaultPath = null;\r
+               String defaultName = null;\r
+               Set<String> pathNames = new TreeSet<String>();\r
 \r
                // add the registered/known projects\r
                for (ProjectModel project : app().projects().getProjectModels(user, false)) {\r
                        // TODO issue-351: user.canAdmin(project)\r
                        if (user.canAdmin()) {\r
                                if (project.isRoot) {\r
-                                       projectNames.add("/");\r
+                                       pathNames.add("/");\r
                                } else {\r
-                                       projectNames.add(project.name + "/");\r
+                                       pathNames.add(project.name + "/");\r
                                }\r
                        }\r
                }\r
 \r
                // add the user's personal project namespace\r
                if (user.canAdmin() || user.canCreate()) {\r
-                       projectNames.add(user.getPersonalPath() + "/");\r
+                       pathNames.add(user.getPersonalPath() + "/");\r
                }\r
 \r
                if (!StringUtils.isEmpty(repository.name)) {\r
                        // editing a repository name\r
                        // set the defaultProject to the current repository project\r
-                       defaultProject = repository.projectPath;\r
-                       if (StringUtils.isEmpty(defaultProject)) {\r
-                               defaultProject = "/";\r
+                       if (StringUtils.isEmpty(repository.projectPath)) {\r
+                               defaultPath = "/";\r
                        } else {\r
-                               defaultProject += "/";\r
+                               defaultPath = repository.projectPath + "/";\r
                        }\r
-\r
-                       projectNames.add(defaultProject);\r
+                       defaultName = repository.name.substring(defaultPath.length());\r
+                       pathNames.add(defaultPath);\r
                }\r
 \r
                // if default project is not already set, set preference based on the user permissions\r
-               if (defaultProject == null) {\r
+               if (defaultPath == null) {\r
                        if (user.canAdmin()) {\r
-                               defaultProject = "/";\r
+                               defaultPath = "/";\r
                        } else if (user.canCreate()) {\r
-                               defaultProject = user.getPersonalPath() + "/";\r
+                               defaultPath = user.getPersonalPath() + "/";\r
                        }\r
                }\r
 \r
-               // update the model which is reflectively mapped to the Wicket fields by name\r
-               repository.projectPath = defaultProject;\r
-               if (repository.projectPath.length() > 1 && !StringUtils.isEmpty(repository.name)) {\r
-                       repository.name = repository.name.substring(repository.projectPath.length());\r
-               }\r
-               projectChoice = new DropDownChoice<String>("projectPath", new ArrayList<String>(projectNames));\r
-               nameField = new TextField<String>("name");\r
+               projectPath = Model.of(defaultPath);\r
+               pathChoice = new DropDownChoice<String>("projectPath", projectPath, new ArrayList<String>(pathNames));\r
+               repoName = Model.of(defaultName);\r
+               nameField = new TextField<String>("name", repoName);\r
 \r
                // only enable project selection if we actually have multiple choices\r
-               add(projectChoice.setEnabled(projectNames.size() > 1));\r
+               add(pathChoice.setEnabled(pathNames.size() > 1));\r
                add(nameField);\r
                add(new TextField<String>("description"));\r
        }\r
 \r
        public void setEditable(boolean editable) {\r
                // only enable project selection if we actually have multiple choices\r
-               projectChoice.setEnabled(projectChoice.getChoices().size() > 1 && editable);\r
+               pathChoice.setEnabled(pathChoice.getChoices().size() > 1 && editable);\r
                nameField.setEnabled(editable);\r
        }\r
 \r
        public boolean updateModel(RepositoryModel repositoryModel) {\r
-               // confirm a project was selected\r
-               if (StringUtils.isEmpty(repositoryModel.projectPath)) {\r
+               // confirm a project path was selected\r
+               if (StringUtils.isEmpty(projectPath.getObject())) {\r
                        error(getString("gb.pleaseSelectProject"));\r
                        return false;\r
                }\r
 \r
                // confirm a repository name was entered\r
-               if (StringUtils.isEmpty(repositoryModel.name)) {\r
+               if (StringUtils.isEmpty(repoName.getObject())) {\r
                        error(getString("gb.pleaseSetRepositoryName"));\r
                        return false;\r
                }\r
 \r
-               String project = repositoryModel.projectPath;\r
+               String project = projectPath.getObject();\r
+               String name = repoName.getObject();\r
 \r
-               fullName = (project + repositoryModel.name).trim();\r
+               fullName = (project + name).trim();\r
                fullName = fullName.replace('\\', '/');\r
                fullName = fullName.replace("//", "/");\r
                if (fullName.charAt(0) == '/') {\r
@@ -156,21 +160,12 @@ public class RepositoryNamePanel extends BasePanel {
                }\r
 \r
                repositoryModel.name = fullName;\r
-               repositoryModel.projectPath = null;\r
 \r
                return true;\r
        }\r
 \r
-       public void resetModel(RepositoryModel repositoryModel) {\r
-               // restore project and name fields on error condition\r
-               repositoryModel.projectPath = StringUtils.getFirstPathElement(fullName) + "/";\r
-               if (repositoryModel.projectPath.length() > 1) {\r
-                       repositoryModel.name = fullName.substring(repositoryModel.projectPath.length());\r
-               }\r
-       }\r
-\r
        @Override\r
        protected boolean getStatelessHint() {\r
                return false;\r
        }\r
-}\r
+}
\ No newline at end of file