View Javadoc

1   /***
2    * Copyright (C) 2008 Jeremy Thomerson (jthomerson@users.sourceforge.net)
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package net.sf.vcaperture.web.panels;
18  
19  import java.util.Arrays;
20  
21  import net.sf.vcaperture.web.models.AppendingStringModel;
22  import net.sf.vcaperture.web.urls.ViewDirectoryLink;
23  
24  import org.apache.wicket.markup.html.basic.Label;
25  import org.apache.wicket.markup.html.list.ListItem;
26  import org.apache.wicket.markup.html.list.ListView;
27  import org.apache.wicket.markup.html.panel.Panel;
28  import org.apache.wicket.model.IModel;
29  import org.apache.wicket.model.LoadableDetachableModel;
30  
31  public class BreadCrumbsPanel extends Panel {
32  
33  	private static final long serialVersionUID = 1L;
34  
35  	private final IModel/*<String>*/ mRelativePathModel;
36  	
37      public BreadCrumbsPanel(String id, IModel/*<String>*/ projectNameModel, IModel/*<String>*/ relativePathModel) {
38  	    super(id, projectNameModel);
39  	    setRenderBodyOnly(true);
40  	    mRelativePathModel = relativePathModel;
41  	    add(new ListView("list", new PathAsListModel(mRelativePathModel)) {
42  
43              private static final long serialVersionUID = 1L;
44              private final AppendingStringModel mAllPathModel = new AppendingStringModel("/");
45  
46  			@Override
47              protected void populateItem(ListItem item) {
48  				item.setRenderBodyOnly(true);
49  				mAllPathModel.addModel(item.getModel());
50  				ViewDirectoryLink vdl = new ViewDirectoryLink("view", BreadCrumbsPanel.this.getModel(), mAllPathModel.copy());
51  				vdl.add(new Label("path", item.getModel()).setRenderBodyOnly(true));
52  				item.add(vdl);
53              }
54  	    	
55  	    });
56      }
57  
58      @Override
59      public boolean isVisible() {
60          return getModelObject() != null;
61      }
62      
63      static class PathAsListModel extends LoadableDetachableModel {
64  
65          private static final long serialVersionUID = 1L;
66  
67          private final IModel/*<String>*/ mRelativePathModel;
68  		public PathAsListModel(IModel relativePathModel) {
69  			mRelativePathModel = relativePathModel;
70          }
71  
72  		@Override
73      	protected Object load() {
74  			String path = (String) mRelativePathModel.getObject();
75      		return Arrays.asList(path.split("/"));
76      	}
77  
78      }
79  
80  }