From a5e762ba4ab82f0c6ef71d853c5103f19bbf8e22 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Thu, 11 Oct 2012 08:10:20 -0400
Subject: [PATCH] Tweak canFork description

---
 src/com/gitblit/wicket/panels/BranchesPanel.java |   63 +++++++++++++++++++++++--------
 1 files changed, 47 insertions(+), 16 deletions(-)

diff --git a/src/com/gitblit/wicket/panels/BranchesPanel.java b/src/com/gitblit/wicket/panels/BranchesPanel.java
index d784354..3ca02cb 100644
--- a/src/com/gitblit/wicket/panels/BranchesPanel.java
+++ b/src/com/gitblit/wicket/panels/BranchesPanel.java
@@ -15,6 +15,7 @@
  */
 package com.gitblit.wicket.panels;
 
+import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -22,27 +23,27 @@
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.link.BookmarkablePageLink;
 import org.apache.wicket.markup.html.link.ExternalLink;
+import org.apache.wicket.markup.html.link.Link;
 import org.apache.wicket.markup.html.panel.Fragment;
 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.apache.wicket.model.StringResourceModel;
-import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.Repository;
 
+import com.gitblit.Constants;
+import com.gitblit.GitBlit;
 import com.gitblit.SyndicationServlet;
 import com.gitblit.models.RefModel;
 import com.gitblit.models.RepositoryModel;
 import com.gitblit.utils.JGitUtils;
-import com.gitblit.utils.JGitUtils.SearchType;
 import com.gitblit.utils.StringUtils;
 import com.gitblit.wicket.WicketUtils;
 import com.gitblit.wicket.pages.BranchesPage;
 import com.gitblit.wicket.pages.CommitPage;
+import com.gitblit.wicket.pages.GitSearchPage;
 import com.gitblit.wicket.pages.LogPage;
 import com.gitblit.wicket.pages.MetricsPage;
-import com.gitblit.wicket.pages.SearchPage;
-import com.gitblit.wicket.pages.SummaryPage;
 import com.gitblit.wicket.pages.TreePage;
 
 public class BranchesPanel extends BasePanel {
@@ -52,7 +53,7 @@
 	private final boolean hasBranches;
 
 	public BranchesPanel(String wicketId, final RepositoryModel model, Repository r,
-			final int maxCount) {
+			final int maxCount, final boolean showAdmin) {
 		super(wicketId);
 
 		// branches
@@ -74,11 +75,12 @@
 					null), BranchesPage.class, WicketUtils.newRepositoryParameter(model.name)));
 		} else {
 			// branches page
-			// show repository summary page link
-			add(new LinkPanel("branches", "title", model.name, SummaryPage.class,
-					WicketUtils.newRepositoryParameter(model.name)));
+			add(new Label("branches", new StringResourceModel("gb.branches", this, null)));
 		}
-
+		
+		// only allow delete if we have multiple branches
+		final boolean showDelete = showAdmin && branches.size() > 1;
+		
 		ListDataProvider<RefModel> branchesDp = new ListDataProvider<RefModel>(branches);
 		DataView<RefModel> branchesView = new DataView<RefModel>("branch", branchesDp) {
 			private static final long serialVersionUID = 1L;
@@ -87,7 +89,7 @@
 			public void populateItem(final Item<RefModel> item) {
 				final RefModel entry = item.getModelObject();
 
-				item.add(WicketUtils.createDateLabel("branchDate", entry.getDate(), getTimeZone()));
+				item.add(WicketUtils.createDateLabel("branchDate", entry.getDate(), getTimeZone(), getTimeUtils()));
 
 				item.add(new LinkPanel("branchName", "list name", StringUtils.trimString(
 						entry.displayName, 28), LogPage.class, WicketUtils.newObjectParameter(
@@ -95,14 +97,14 @@
 
 				String author = entry.getAuthorIdent().getName();
 				LinkPanel authorLink = new LinkPanel("branchAuthor", "list", author,
-						SearchPage.class, WicketUtils.newSearchParameter(model.name,
-								entry.getName(), author, SearchType.AUTHOR));
-				setPersonSearchTooltip(authorLink, author, SearchType.AUTHOR);
+						GitSearchPage.class, WicketUtils.newSearchParameter(model.name,
+								entry.getName(), author, Constants.SearchType.AUTHOR));
+				setPersonSearchTooltip(authorLink, author, Constants.SearchType.AUTHOR);
 				item.add(authorLink);
 
 				// short message
 				String shortMessage = entry.getShortMessage();
-				String trimmedMessage = StringUtils.trimShortLog(shortMessage);
+				String trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG);
 				LinkPanel shortlog = new LinkPanel("branchLog", "list subject", trimmedMessage,
 						CommitPage.class, WicketUtils.newObjectParameter(model.name,
 								entry.getName()));
@@ -110,9 +112,9 @@
 					WicketUtils.setHtmlTooltip(shortlog, shortMessage);
 				}
 				item.add(shortlog);
-
+				
 				if (maxCount <= 0) {
-					Fragment fragment = new Fragment("branchLinks", "branchPageLinks", this);
+					Fragment fragment = new Fragment("branchLinks", showDelete? "branchPageAdminLinks" : "branchPageLinks", this);
 					fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class, WicketUtils
 							.newObjectParameter(model.name, entry.getName())));
 					fragment.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils
@@ -122,6 +124,9 @@
 					fragment.add(new ExternalLink("syndication", SyndicationServlet.asLink(
 							getRequest().getRelativePathPrefixToContextRoot(), model.name,
 							entry.getName(), 0)));
+					if (showDelete) {
+						fragment.add(createDeleteBranchLink(model, entry));
+					}
 					item.add(fragment);
 				} else {
 					Fragment fragment = new Fragment("branchLinks", "branchPanelLinks", this);
@@ -152,4 +157,30 @@
 		setVisible(hasBranches);
 		return this;
 	}
+
+	private Link<Void> createDeleteBranchLink(final RepositoryModel repositoryModel, final RefModel entry)
+	{
+		Link<Void> deleteLink = new Link<Void>("deleteBranch") {
+			private static final long serialVersionUID = 1L;
+
+			@Override
+			public void onClick() {
+				Repository r = GitBlit.self().getRepository(repositoryModel.name);
+				boolean success = JGitUtils.deleteBranchRef(r, entry.getName());
+				r.close();
+				if (success) {
+					info(MessageFormat.format("Branch \"{0}\" deleted", entry.displayName));
+					// redirect to the owning page
+					setResponsePage(getPage().getClass(), WicketUtils.newRepositoryParameter(repositoryModel.name));
+				}
+				else {
+					error(MessageFormat.format("Failed to delete branch \"{0}\"", entry.displayName));
+				}
+			}
+		};
+		
+		deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(
+				"Delete branch \"{0}\"?", entry.displayName )));
+		return deleteLink;
+	}
 }

--
Gitblit v1.9.1