You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommitLegendPanel.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright 2011 gitblit.com.
  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. package com.gitblit.wicket.panels;
  17. import java.text.MessageFormat;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import java.util.Map;
  21. import java.util.concurrent.atomic.AtomicInteger;
  22. import org.apache.wicket.markup.html.basic.Label;
  23. import org.apache.wicket.markup.html.panel.Panel;
  24. import org.apache.wicket.markup.repeater.Item;
  25. import org.apache.wicket.markup.repeater.data.DataView;
  26. import org.apache.wicket.markup.repeater.data.ListDataProvider;
  27. import org.eclipse.jgit.diff.DiffEntry.ChangeType;
  28. import com.gitblit.utils.JGitUtils;
  29. import com.gitblit.wicket.WicketUtils;
  30. import com.gitblit.wicket.models.PathModel.PathChangeModel;
  31. public class CommitLegendPanel extends Panel {
  32. private static final long serialVersionUID = 1L;
  33. public CommitLegendPanel(String id, List<PathChangeModel> paths) {
  34. super(id);
  35. final Map<ChangeType, AtomicInteger> stats = JGitUtils.getChangedPathsStats(paths);
  36. ListDataProvider<ChangeType> legendDp = new ListDataProvider<ChangeType>(new ArrayList<ChangeType>(stats.keySet()));
  37. DataView<ChangeType> legendsView = new DataView<ChangeType>("legend", legendDp) {
  38. private static final long serialVersionUID = 1L;
  39. public void populateItem(final Item<ChangeType> item) {
  40. ChangeType entry = item.getModelObject();
  41. Label changeType = new Label("changeType", "");
  42. WicketUtils.setChangeTypeCssClass(changeType, entry);
  43. item.add(changeType);
  44. int count = stats.get(entry).intValue();
  45. String description = "";
  46. switch(entry) {
  47. case ADD:
  48. description = MessageFormat.format(getString("gb.filesAdded"), count);
  49. break;
  50. case MODIFY:
  51. description = MessageFormat.format(getString("gb.filesModified"), count);
  52. break;
  53. case DELETE:
  54. description = MessageFormat.format(getString("gb.filesDeleted"), count);
  55. break;
  56. case COPY:
  57. description = MessageFormat.format(getString("gb.filesCopied"), count);
  58. break;
  59. case RENAME:
  60. description = MessageFormat.format(getString("gb.filesRenamed"), count);
  61. break;
  62. }
  63. item.add(new Label("description", description));
  64. }
  65. };
  66. add(legendsView);
  67. }
  68. }