Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 2.79 KB | None | 0 0
  1. public class ContainerTagPage extends WebPage {
  2.    
  3.     @SpringBean(name="containerTagService")
  4.     private ContainerTagService containerTagService;
  5.    
  6.     public ContainerTagPage() {
  7.  
  8.         add(new FeedbackPanel("feedback"));
  9.  
  10.        
  11.         // DataProvider speaks to the database
  12.         final IDataProvider dataProvider = new IDataProvider<ContainerTag>() {
  13.  
  14.             public Iterator iterator(int first, int count) {
  15.                 return containerTagService.findAll().iterator();
  16.             }
  17.  
  18.             public int size() {
  19.                 return containerTagService.countAll().intValue();
  20.             }
  21.  
  22.             public IModel<ContainerTag> model(final ContainerTag tag) {
  23.                 return new LoadableDetachableModel<ContainerTag>() {
  24.  
  25.                     @Override
  26.                     protected ContainerTag load() {
  27.                         return tag;
  28.                     }
  29.                 };
  30.             }
  31.  
  32.  
  33.             public void detach() {
  34.             }
  35.         };
  36.  
  37.  
  38.         // The data view
  39.         final DataView dataView = new DataView<ContainerTag>("list", dataProvider) {
  40.  
  41.             @Override
  42.             protected void populateItem(Item<ContainerTag> item) {
  43.                 ContainerTag containerTag = item.getModelObject();
  44.                 item.add(new Label("id", containerTag.getId().toString()));
  45.                 item.add(new Label("name", containerTag.getName()));
  46.                 item.add(new Label("description", containerTag.getDescription()));
  47.                 item.add(new Label("active", containerTag.getActive().toString()));
  48.             }
  49.  
  50.             @Override
  51.             protected Item newItem(final String id, int index, final IModel model) {
  52.                 return new OddEvenItem(id, index, model);
  53.             }
  54.  
  55.         };
  56.  
  57.  
  58.         // Markup container that will be replaced with ajax
  59.         final WebMarkupContainer wmc = new WebMarkupContainer("containerTags");
  60.         wmc.setOutputMarkupId(true);
  61.         wmc.add(dataView);
  62.         add(wmc);
  63.  
  64.  
  65.         // Modal window to edit the container tag
  66.         final ModalWindow modalWindow = new ModalWindow("modalWindow");
  67.         add(modalWindow);
  68.  
  69.         modalWindow.setPageCreator(new ModalWindow.PageCreator() {
  70.             public Page createPage() {
  71.                 return new ManageContainerTagPage(ContainerTagPage.this, modalWindow);
  72.             }
  73.         });
  74.         modalWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
  75.  
  76.             public void onClose(AjaxRequestTarget target) {
  77.                 // Refresh the list of tags with ajax
  78.                 target.addComponent(wmc);
  79.             }
  80.         });
  81.  
  82.         add(new AjaxLink("showModal") {
  83.             public void onClick(AjaxRequestTarget target) {
  84.                 modalWindow.show(target);
  85.             }
  86.         });
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement