import java.text.MessageFormat;\r
import java.util.ArrayList;\r
import java.util.Arrays;\r
-import java.util.HashMap;\r
+import java.util.LinkedHashMap;\r
import java.util.List;\r
import java.util.Map;\r
\r
import org.apache.wicket.markup.html.form.DropDownChoice;\r
import org.apache.wicket.markup.html.form.StatelessForm;\r
import org.apache.wicket.markup.html.form.TextField;\r
-import org.apache.wicket.markup.html.link.BookmarkablePageLink;\r
import org.apache.wicket.markup.html.link.ExternalLink;\r
import org.apache.wicket.markup.html.panel.Fragment;\r
-import org.apache.wicket.markup.repeater.Item;\r
-import org.apache.wicket.markup.repeater.data.DataView;\r
-import org.apache.wicket.markup.repeater.data.ListDataProvider;\r
import org.apache.wicket.model.IModel;\r
import org.apache.wicket.model.Model;\r
import org.eclipse.jgit.diff.DiffEntry.ChangeType;\r
import com.gitblit.utils.StringUtils;\r
import com.gitblit.utils.TicgitUtils;\r
import com.gitblit.wicket.GitBlitWebSession;\r
+import com.gitblit.wicket.PageRegistration;\r
import com.gitblit.wicket.WicketUtils;\r
import com.gitblit.wicket.panels.LinkPanel;\r
+import com.gitblit.wicket.panels.NavigationPanel;\r
import com.gitblit.wicket.panels.RefsPanel;\r
\r
public abstract class RepositoryPage extends BasePage {\r
\r
private RepositoryModel m;\r
\r
- private final Map<String, PageRegistration> registeredPages = new HashMap<String, PageRegistration>() {\r
-\r
- private static final long serialVersionUID = 1L;\r
-\r
- {\r
- put("repositories", new PageRegistration("gb.repositories", RepositoriesPage.class, false));\r
- put("summary", new PageRegistration("gb.summary", SummaryPage.class));\r
- put("log", new PageRegistration("gb.log", LogPage.class));\r
- put("branches", new PageRegistration("gb.branches", BranchesPage.class));\r
- put("tags", new PageRegistration("gb.tags", TagsPage.class));\r
- put("tree", new PageRegistration("gb.tree", TreePage.class));\r
- put("tickets", new PageRegistration("gb.tickets", TicketsPage.class));\r
- put("edit", new PageRegistration("gb.edit", EditRepositoryPage.class));\r
- put("docs", new PageRegistration("gb.docs", DocsPage.class));\r
- }\r
- };\r
+ private final Map<String, PageRegistration> registeredPages;\r
\r
public RepositoryPage(PageParameters params) {\r
super(params);\r
error(MessageFormat.format("Repository not specified for {0}!", getPageName()), true);\r
}\r
\r
- Repository r = getRepository();\r
- RepositoryModel model = getRepositoryModel();\r
+ // register the available page links for this page and user\r
+ registeredPages = registerPages();\r
\r
// standard page links\r
- addRegisteredPageLink("repositories");\r
- addRegisteredPageLink("summary");\r
- addRegisteredPageLink("log");\r
- addRegisteredPageLink("branches");\r
- addRegisteredPageLink("tags");\r
- addRegisteredPageLink("tree");\r
+ List<PageRegistration> pages = new ArrayList<PageRegistration>(registeredPages.values());\r
+ NavigationPanel navigationPanel = new NavigationPanel("navPanel", getClass(), pages);\r
+ add(navigationPanel);\r
+\r
+ add(new ExternalLink("syndication", SyndicationServlet.asLink(getRequest()\r
+ .getRelativePathPrefixToContextRoot(), repositoryName, null, 0)));\r
+\r
+ // add floating search form\r
+ SearchForm searchForm = new SearchForm("searchForm", repositoryName);\r
+ add(searchForm);\r
+ searchForm.setTranslatedAttributes();\r
+\r
+ // set stateless page preference\r
+ setStatelessHint(true);\r
+ }\r
+\r
+ private Map<String, PageRegistration> registerPages() {\r
+ PageParameters params = null;\r
+ if (!StringUtils.isEmpty(repositoryName)) {\r
+ params = WicketUtils.newRepositoryParameter(repositoryName);\r
+ }\r
+ Map<String, PageRegistration> pages = new LinkedHashMap<String, PageRegistration>();\r
+\r
+ // standard links\r
+ pages.put("repositories", new PageRegistration("gb.repositories", RepositoriesPage.class));\r
+ pages.put("summary", new PageRegistration("gb.summary", SummaryPage.class, params));\r
+ pages.put("log", new PageRegistration("gb.log", LogPage.class, params));\r
+ pages.put("branches", new PageRegistration("gb.branches", BranchesPage.class, params));\r
+ pages.put("tags", new PageRegistration("gb.tags", TagsPage.class, params));\r
+ pages.put("tree", new PageRegistration("gb.tree", TreePage.class, params));\r
+\r
+ // conditional links\r
+ Repository r = getRepository();\r
+ RepositoryModel model = getRepositoryModel();\r
\r
// per-repository extra page links\r
- List<String> extraPageLinks = new ArrayList<String>();\r
if (model.useTickets && TicgitUtils.getTicketsBranch(r) != null) {\r
- extraPageLinks.add("tickets");\r
+ pages.put("tickets", new PageRegistration("gb.tickets", TicketsPage.class, params));\r
}\r
if (model.useDocs) {\r
- extraPageLinks.add("docs");\r
+ pages.put("docs", new PageRegistration("gb.docs", DocsPage.class, params));\r
}\r
-\r
+ // Conditionally add edit link\r
final boolean showAdmin;\r
if (GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) {\r
boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);\r
} else {\r
showAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);\r
}\r
-\r
- // Conditionally add edit link\r
if (showAdmin\r
|| GitBlitWebSession.get().isLoggedIn()\r
&& (model.owner != null && model.owner.equalsIgnoreCase(GitBlitWebSession.get()\r
.getUser().username))) {\r
- extraPageLinks.add("edit");\r
+ pages.put("edit", new PageRegistration("gb.edit", EditRepositoryPage.class, params));\r
}\r
-\r
- final String pageName = getPageName();\r
- final String pageWicketId = getLinkWicketId(pageName);\r
- ListDataProvider<String> extrasDp = new ListDataProvider<String>(extraPageLinks);\r
- DataView<String> extrasView = new DataView<String>("extra", extrasDp) {\r
- private static final long serialVersionUID = 1L;\r
-\r
- public void populateItem(final Item<String> item) {\r
- String extra = item.getModelObject();\r
- PageRegistration pageReg = registeredPages.get(extra);\r
- item.add(new LinkPanel("extraLink", null, getString(pageReg.translationKey),\r
- pageReg.pageClass, WicketUtils.newRepositoryParameter(repositoryName)));\r
- }\r
- };\r
- add(extrasView);\r
-\r
- add(new ExternalLink("syndication", SyndicationServlet.asLink(getRequest()\r
- .getRelativePathPrefixToContextRoot(), repositoryName, null, 0)));\r
-\r
- // disable current page\r
- disableRegisteredPageLink(pageName);\r
-\r
- // add floating search form\r
- SearchForm searchForm = new SearchForm("searchForm", repositoryName);\r
- add(searchForm);\r
- searchForm.setTranslatedAttributes();\r
-\r
- // set stateless page preference\r
- setStatelessHint(true);\r
+ return pages;\r
}\r
- \r
+\r
@Override\r
protected void setupPage(String repositoryName, String pageName) {\r
add(new LinkPanel("repositoryName", null, repositoryName, SummaryPage.class,\r
super.setupPage(repositoryName, pageName);\r
}\r
\r
- public String getLinkWicketId(String pageName) {\r
- for (String wicketId : registeredPages.keySet()) {\r
- String key = registeredPages.get(wicketId).translationKey;\r
- String linkName = getString(key);\r
- if (linkName.equals(pageName)) {\r
- return wicketId;\r
- }\r
- }\r
- return null;\r
- }\r
-\r
- public void disableRegisteredPageLink(String pageName) {\r
- String wicketId = getLinkWicketId(pageName);\r
- if (!StringUtils.isEmpty(wicketId)) {\r
- Component c = get(wicketId);\r
- if (c != null) {\r
-// c.setEnabled(false);\r
-// WicketUtils.setCssClass(c, "selected");\r
- }\r
- }\r
- }\r
-\r
- private void addRegisteredPageLink(String key) {\r
- PageRegistration pageReg = registeredPages.get(key);\r
- if (pageReg.repositoryLink) {\r
- add(new BookmarkablePageLink<Void>(key, pageReg.pageClass,\r
- WicketUtils.newRepositoryParameter(repositoryName)));\r
- } else {\r
- add(new BookmarkablePageLink<Void>(key, pageReg.pageClass));\r
- }\r
- }\r
-\r
protected void addSyndicationDiscoveryLink() {\r
add(WicketUtils.syndicationDiscoveryLink(SyndicationServlet.getTitle(repositoryName,\r
objectId), SyndicationServlet.asLink(getRequest()\r
return WicketUtils.newObjectParameter(repositoryName, commitId);\r
}\r
\r
- private static class PageRegistration implements Serializable {\r
- private static final long serialVersionUID = 1L;\r
-\r
- final String translationKey;\r
- final Class<? extends BasePage> pageClass;\r
- final boolean repositoryLink;\r
-\r
- PageRegistration(String translationKey, Class<? extends BasePage> pageClass) {\r
- this(translationKey, pageClass, true);\r
- }\r
- \r
- PageRegistration(String translationKey, Class<? extends BasePage> pageClass, boolean repositoryLink) {\r
- this.translationKey = translationKey;\r
- this.pageClass = pageClass;\r
- this.repositoryLink = repositoryLink;\r
- }\r
- }\r
-\r
private static class SearchForm extends StatelessForm<Void> implements Serializable {\r
private static final long serialVersionUID = 1L;\r
\r
\r
void setTranslatedAttributes() {\r
WicketUtils.setHtmlTooltip(get("searchType"), getString("gb.searchTypeTooltip"));\r
- WicketUtils.setHtmlTooltip(get("searchBox"), MessageFormat.format(getString("gb.searchTooltip"), repositoryName));\r
+ WicketUtils.setHtmlTooltip(get("searchBox"),\r
+ MessageFormat.format(getString("gb.searchTooltip"), repositoryName));\r
WicketUtils.setInputPlaceholder(get("searchBox"), getString("gb.search"));\r
}\r
\r