James Moger
2012-09-10 fabe060d3a435f116128851f828e35c2af5fde67
src/com/gitblit/wicket/pages/BranchesPage.java
@@ -1,75 +1,34 @@
/*
 * Copyright 2011 gitblit.com.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.gitblit.wicket.pages;
import java.util.ArrayList;
import java.util.List;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.Utils;
import com.gitblit.wicket.LinkPanel;
import com.gitblit.wicket.RepositoryPage;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.models.RefModel;
import com.gitblit.wicket.panels.BranchLinksPanel;
import com.gitblit.wicket.panels.BranchesPanel;
public class BranchesPage extends RepositoryPage {
   public BranchesPage(PageParameters params) {
      super(params);
      Repository r = getRepository();
      List<RefModel> branches = new ArrayList<RefModel>();
      branches.addAll(JGitUtils.getLocalBranches(r, -1));
      branches.addAll(JGitUtils.getRemoteBranches(r, -1));
      // shortlog
      add(new LinkPanel("summary", "title", repositoryName, SummaryPage.class, newRepositoryParameter()));
      ListDataProvider<RefModel> branchesDp = new ListDataProvider<RefModel>(branches);
      DataView<RefModel> branchView = new DataView<RefModel>("branch", branchesDp) {
         private static final long serialVersionUID = 1L;
         int counter = 0;
         public void populateItem(final Item<RefModel> item) {
            final RefModel entry = item.getModelObject();
            String date;
            if (entry.getDate() != null) {
               date = Utils.timeAgo(entry.getDate());
            } else {
               date = "";
            }
            Label branchDateLabel = new Label("branchDate", date);
            item.add(branchDateLabel);
            WicketUtils.setCssClass(branchDateLabel, Utils.timeAgoCss(entry.getDate()));
            item.add(new LinkPanel("branchName", "list name", entry.getDisplayName(), ShortLogPage.class, newCommitParameter(entry.getName())));
            boolean remote = entry.getName().startsWith(Constants.R_REMOTES);
            item.add(new Label("branchType", remote ? "remote":"local"));
            item.add(new BranchLinksPanel("branchLinks", repositoryName, entry));
            String clazz = counter % 2 == 0 ? "dark" : "light";
            WicketUtils.setCssClass(item, clazz);
            counter++;
         }
      };
      add(branchView);
      // footer
      addFooter();
      add(new BranchesPanel("branchesPanel", getRepositoryModel(), getRepository(), -1));
   }
   @Override
   protected String getPageName() {
      return "branches";
      return getString("gb.branches");
   }
}