19
19
import java .text .MessageFormat ;
20
20
import java .util .ArrayList ;
21
21
import java .util .Arrays ;
22
- import java .util .HashMap ;
22
+ import java .util .LinkedHashMap ;
23
23
import java .util .List ;
24
24
import java .util .Map ;
25
25
29
29
import org .apache .wicket .markup .html .form .DropDownChoice ;
30
30
import org .apache .wicket .markup .html .form .StatelessForm ;
31
31
import org .apache .wicket .markup .html .form .TextField ;
32
- import org .apache .wicket .markup .html .link .BookmarkablePageLink ;
33
32
import org .apache .wicket .markup .html .link .ExternalLink ;
34
33
import org .apache .wicket .markup .html .panel .Fragment ;
35
- import org .apache .wicket .markup .repeater .Item ;
36
- import org .apache .wicket .markup .repeater .data .DataView ;
37
- import org .apache .wicket .markup .repeater .data .ListDataProvider ;
38
34
import org .apache .wicket .model .IModel ;
39
35
import org .apache .wicket .model .Model ;
40
36
import org .eclipse .jgit .diff .DiffEntry .ChangeType ;
51
47
import com .gitblit .utils .StringUtils ;
52
48
import com .gitblit .utils .TicgitUtils ;
53
49
import com .gitblit .wicket .GitBlitWebSession ;
50
+ import com .gitblit .wicket .PageRegistration ;
54
51
import com .gitblit .wicket .WicketUtils ;
55
52
import com .gitblit .wicket .panels .LinkPanel ;
53
+ import com .gitblit .wicket .panels .NavigationPanel ;
56
54
import com .gitblit .wicket .panels .RefsPanel ;
57
55
58
56
public abstract class RepositoryPage extends BasePage {
@@ -64,22 +62,7 @@ public abstract class RepositoryPage extends BasePage {
64
62
65
63
private RepositoryModel m ;
66
64
67
- private final Map <String , PageRegistration > registeredPages = new HashMap <String , PageRegistration >() {
68
-
69
- private static final long serialVersionUID = 1L ;
70
-
71
- {
72
- put ("repositories" , new PageRegistration ("gb.repositories" , RepositoriesPage .class , false ));
73
- put ("summary" , new PageRegistration ("gb.summary" , SummaryPage .class ));
74
- put ("log" , new PageRegistration ("gb.log" , LogPage .class ));
75
- put ("branches" , new PageRegistration ("gb.branches" , BranchesPage .class ));
76
- put ("tags" , new PageRegistration ("gb.tags" , TagsPage .class ));
77
- put ("tree" , new PageRegistration ("gb.tree" , TreePage .class ));
78
- put ("tickets" , new PageRegistration ("gb.tickets" , TicketsPage .class ));
79
- put ("edit" , new PageRegistration ("gb.edit" , EditRepositoryPage .class ));
80
- put ("docs" , new PageRegistration ("gb.docs" , DocsPage .class ));
81
- }
82
- };
65
+ private final Map <String , PageRegistration > registeredPages ;
83
66
84
67
public RepositoryPage (PageParameters params ) {
85
68
super (params );
@@ -90,72 +73,69 @@ public RepositoryPage(PageParameters params) {
90
73
error (MessageFormat .format ("Repository not specified for {0}!" , getPageName ()), true );
91
74
}
92
75
93
- Repository r = getRepository ();
94
- RepositoryModel model = getRepositoryModel ();
76
+ // register the available page links for this page and user
77
+ registeredPages = registerPages ();
95
78
96
79
// standard page links
97
- addRegisteredPageLink ("repositories" );
98
- addRegisteredPageLink ("summary" );
99
- addRegisteredPageLink ("log" );
100
- addRegisteredPageLink ("branches" );
101
- addRegisteredPageLink ("tags" );
102
- addRegisteredPageLink ("tree" );
80
+ List <PageRegistration > pages = new ArrayList <PageRegistration >(registeredPages .values ());
81
+ NavigationPanel navigationPanel = new NavigationPanel ("navPanel" , getClass (), pages );
82
+ add (navigationPanel );
83
+
84
+ add (new ExternalLink ("syndication" , SyndicationServlet .asLink (getRequest ()
85
+ .getRelativePathPrefixToContextRoot (), repositoryName , null , 0 )));
86
+
87
+ // add floating search form
88
+ SearchForm searchForm = new SearchForm ("searchForm" , repositoryName );
89
+ add (searchForm );
90
+ searchForm .setTranslatedAttributes ();
91
+
92
+ // set stateless page preference
93
+ setStatelessHint (true );
94
+ }
95
+
96
+ private Map <String , PageRegistration > registerPages () {
97
+ PageParameters params = null ;
98
+ if (!StringUtils .isEmpty (repositoryName )) {
99
+ params = WicketUtils .newRepositoryParameter (repositoryName );
100
+ }
101
+ Map <String , PageRegistration > pages = new LinkedHashMap <String , PageRegistration >();
102
+
103
+ // standard links
104
+ pages .put ("repositories" , new PageRegistration ("gb.repositories" , RepositoriesPage .class ));
105
+ pages .put ("summary" , new PageRegistration ("gb.summary" , SummaryPage .class , params ));
106
+ pages .put ("log" , new PageRegistration ("gb.log" , LogPage .class , params ));
107
+ pages .put ("branches" , new PageRegistration ("gb.branches" , BranchesPage .class , params ));
108
+ pages .put ("tags" , new PageRegistration ("gb.tags" , TagsPage .class , params ));
109
+ pages .put ("tree" , new PageRegistration ("gb.tree" , TreePage .class , params ));
110
+
111
+ // conditional links
112
+ Repository r = getRepository ();
113
+ RepositoryModel model = getRepositoryModel ();
103
114
104
115
// per-repository extra page links
105
- List <String > extraPageLinks = new ArrayList <String >();
106
116
if (model .useTickets && TicgitUtils .getTicketsBranch (r ) != null ) {
107
- extraPageLinks . add ("tickets" );
117
+ pages . put ("tickets" , new PageRegistration ( "gb.tickets" , TicketsPage . class , params ) );
108
118
}
109
119
if (model .useDocs ) {
110
- extraPageLinks . add ("docs" );
120
+ pages . put ("docs" , new PageRegistration ( "gb.docs" , DocsPage . class , params ) );
111
121
}
112
-
122
+ // Conditionally add edit link
113
123
final boolean showAdmin ;
114
124
if (GitBlit .getBoolean (Keys .web .authenticateAdminPages , true )) {
115
125
boolean allowAdmin = GitBlit .getBoolean (Keys .web .allowAdministration , false );
116
126
showAdmin = allowAdmin && GitBlitWebSession .get ().canAdmin ();
117
127
} else {
118
128
showAdmin = GitBlit .getBoolean (Keys .web .allowAdministration , false );
119
129
}
120
-
121
- // Conditionally add edit link
122
130
if (showAdmin
123
131
|| GitBlitWebSession .get ().isLoggedIn ()
124
132
&& (model .owner != null && model .owner .equalsIgnoreCase (GitBlitWebSession .get ()
125
133
.getUser ().username ))) {
126
- extraPageLinks . add ("edit" );
134
+ pages . put ("edit" , new PageRegistration ( "gb.edit" , EditRepositoryPage . class , params ) );
127
135
}
128
-
129
- final String pageName = getPageName ();
130
- final String pageWicketId = getLinkWicketId (pageName );
131
- ListDataProvider <String > extrasDp = new ListDataProvider <String >(extraPageLinks );
132
- DataView <String > extrasView = new DataView <String >("extra" , extrasDp ) {
133
- private static final long serialVersionUID = 1L ;
134
-
135
- public void populateItem (final Item <String > item ) {
136
- String extra = item .getModelObject ();
137
- PageRegistration pageReg = registeredPages .get (extra );
138
- item .add (new LinkPanel ("extraLink" , null , getString (pageReg .translationKey ),
139
- pageReg .pageClass , WicketUtils .newRepositoryParameter (repositoryName )));
140
- }
141
- };
142
- add (extrasView );
143
-
144
- add (new ExternalLink ("syndication" , SyndicationServlet .asLink (getRequest ()
145
- .getRelativePathPrefixToContextRoot (), repositoryName , null , 0 )));
146
-
147
- // disable current page
148
- disableRegisteredPageLink (pageName );
149
-
150
- // add floating search form
151
- SearchForm searchForm = new SearchForm ("searchForm" , repositoryName );
152
- add (searchForm );
153
- searchForm .setTranslatedAttributes ();
154
-
155
- // set stateless page preference
156
- setStatelessHint (true );
136
+ return pages ;
157
137
}
158
-
138
+
159
139
@ Override
160
140
protected void setupPage (String repositoryName , String pageName ) {
161
141
add (new LinkPanel ("repositoryName" , null , repositoryName , SummaryPage .class ,
@@ -165,38 +145,6 @@ protected void setupPage(String repositoryName, String pageName) {
165
145
super .setupPage (repositoryName , pageName );
166
146
}
167
147
168
- public String getLinkWicketId (String pageName ) {
169
- for (String wicketId : registeredPages .keySet ()) {
170
- String key = registeredPages .get (wicketId ).translationKey ;
171
- String linkName = getString (key );
172
- if (linkName .equals (pageName )) {
173
- return wicketId ;
174
- }
175
- }
176
- return null ;
177
- }
178
-
179
- public void disableRegisteredPageLink (String pageName ) {
180
- String wicketId = getLinkWicketId (pageName );
181
- if (!StringUtils .isEmpty (wicketId )) {
182
- Component c = get (wicketId );
183
- if (c != null ) {
184
- // c.setEnabled(false);
185
- // WicketUtils.setCssClass(c, "selected");
186
- }
187
- }
188
- }
189
-
190
- private void addRegisteredPageLink (String key ) {
191
- PageRegistration pageReg = registeredPages .get (key );
192
- if (pageReg .repositoryLink ) {
193
- add (new BookmarkablePageLink <Void >(key , pageReg .pageClass ,
194
- WicketUtils .newRepositoryParameter (repositoryName )));
195
- } else {
196
- add (new BookmarkablePageLink <Void >(key , pageReg .pageClass ));
197
- }
198
- }
199
-
200
148
protected void addSyndicationDiscoveryLink () {
201
149
add (WicketUtils .syndicationDiscoveryLink (SyndicationServlet .getTitle (repositoryName ,
202
150
objectId ), SyndicationServlet .asLink (getRequest ()
@@ -344,24 +292,6 @@ protected PageParameters newCommitParameter(String commitId) {
344
292
return WicketUtils .newObjectParameter (repositoryName , commitId );
345
293
}
346
294
347
- private static class PageRegistration implements Serializable {
348
- private static final long serialVersionUID = 1L ;
349
-
350
- final String translationKey ;
351
- final Class <? extends BasePage > pageClass ;
352
- final boolean repositoryLink ;
353
-
354
- PageRegistration (String translationKey , Class <? extends BasePage > pageClass ) {
355
- this (translationKey , pageClass , true );
356
- }
357
-
358
- PageRegistration (String translationKey , Class <? extends BasePage > pageClass , boolean repositoryLink ) {
359
- this .translationKey = translationKey ;
360
- this .pageClass = pageClass ;
361
- this .repositoryLink = repositoryLink ;
362
- }
363
- }
364
-
365
295
private static class SearchForm extends StatelessForm <Void > implements Serializable {
366
296
private static final long serialVersionUID = 1L ;
367
297
@@ -384,7 +314,8 @@ public SearchForm(String id, String repositoryName) {
384
314
385
315
void setTranslatedAttributes () {
386
316
WicketUtils .setHtmlTooltip (get ("searchType" ), getString ("gb.searchTypeTooltip" ));
387
- WicketUtils .setHtmlTooltip (get ("searchBox" ), MessageFormat .format (getString ("gb.searchTooltip" ), repositoryName ));
317
+ WicketUtils .setHtmlTooltip (get ("searchBox" ),
318
+ MessageFormat .format (getString ("gb.searchTooltip" ), repositoryName ));
388
319
WicketUtils .setInputPlaceholder (get ("searchBox" ), getString ("gb.search" ));
389
320
}
390
321
0 commit comments