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.

LinkPanel.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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;
  17. import org.apache.wicket.PageParameters;
  18. import org.apache.wicket.behavior.SimpleAttributeModifier;
  19. import org.apache.wicket.markup.html.WebPage;
  20. import org.apache.wicket.markup.html.basic.Label;
  21. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  22. import org.apache.wicket.markup.html.link.Link;
  23. import org.apache.wicket.markup.html.panel.Panel;
  24. import org.apache.wicket.model.IModel;
  25. import org.apache.wicket.model.Model;
  26. public class LinkPanel extends Panel {
  27. private static final long serialVersionUID = 1L;
  28. private final IModel<String> labelModel;
  29. public LinkPanel(String wicketId, String linkCssClass, String label, Class<? extends WebPage> clazz) {
  30. this(wicketId, linkCssClass, new Model<String>(label), clazz, null);
  31. }
  32. public LinkPanel(String wicketId, String linkCssClass, String label, Class<? extends WebPage> clazz, PageParameters parameters) {
  33. this(wicketId, linkCssClass, new Model<String>(label), clazz, parameters);
  34. }
  35. public LinkPanel(String wicketId, String linkCssClass, IModel<String> model, Class<? extends WebPage> clazz, PageParameters parameters) {
  36. super(wicketId);
  37. this.labelModel = model;
  38. Link<Void> link = null;
  39. if (parameters == null) {
  40. link = new BookmarkablePageLink<Void>("link", clazz);
  41. } else {
  42. link = new BookmarkablePageLink<Void>("link", clazz, parameters);
  43. }
  44. if (linkCssClass != null) {
  45. link.add(new SimpleAttributeModifier("class", linkCssClass));
  46. }
  47. link.add(new Label("label", labelModel));
  48. add(link);
  49. }
  50. }