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