Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jboss.errai.demo.grocery.client.local;
  
  import java.util.List;
  
 
 
 
 @Templated("#root")
 public class StoresPage extends Composite {
 
   // XXX need a better way of getting at this instance from the StoreListener
   private static StoresPage INSTANCE;
 
   @Inject
   private IOCBeanManager beanManager;
 
   @Inject
   private EntityManager em;
 
   private TableElement table = Document.get().createTableElement();
 
   private Button addStoreButton;
 
   @SuppressWarnings("unused")
   private void initInstance() {
      = this;
     refreshFromDb();
   }
 
   @SuppressWarnings("unused")
   private void deInitInstance() {
      = null;
   }
 
   // TODO make a bridge from JPA lifecycle events to CDI events
   public static class StoreListener {
     public void onStoreListChange(Store s) {
       if ( != null) {
         .refreshFromDb();
       }
     }
   }
 
   public void refreshFromDb() {
     .setInnerHTML("");
     List<StoreallStores = .createNamedQuery("allStores"Store.class).getResultList();
     for (Store s : allStores) {
       addStore(s);
     }
   }
 
   private void addStore(Store store) {
     TableRowElement row = .insertRow(-1);
     row.insertCell(-1).setInnerText(store.getName());
   }

  
Shows the store form in a popup when the "+" button is pressed.

Parameters:
event the click event (ignored)
 
   @EventHandler("addStoreButton")
   public void onStoreAddButtonClick(ClickEvent event) {
     final StoreForm storeForm = .lookupBean(StoreForm.class).getInstance();
     final PopoverContainer popover = .lookupBean(PopoverContainer.class).getInstance();
     popover.setTitleHtml(new SafeHtmlBuilder().appendEscaped("New Store").toSafeHtml());
     popover.setBodyWidget(storeForm);
     popover.show();
     storeForm.grabKeyboardFocus();
 
     // hide store form when new store is saved
    storeForm.setAfterSaveAction(new Runnable() {
      @Override
      public void run() {
        popover.hide();
        .destroyBean(popover);
        .destroyBean(storeForm);
      }
    });
  }
New to GrepCode? Check out our FAQ X