Guest User

Untitled

a guest
Sep 25th, 2023
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.88 KB | Source Code | 0 0
  1. import com.advance.common.entity.TestEntity;
  2. import io.jmix.core.DataManager;
  3. import io.jmix.core.LoadContext;
  4. import io.jmix.ui.Notifications;
  5. import io.jmix.ui.UiComponents;
  6. import io.jmix.ui.component.Button;
  7. import io.jmix.ui.component.Component;
  8. import io.jmix.ui.component.DataGrid.ColumnGeneratorEvent;
  9. import io.jmix.ui.component.HBoxLayout;
  10. import io.jmix.ui.component.LinkButton;
  11. import io.jmix.ui.model.CollectionLoader;
  12. import io.jmix.ui.screen.*;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14.  
  15. import java.util.List;
  16.  
  17. import static io.jmix.ui.icon.JmixIcon.TOGGLE_ON;
  18.  
  19. @UiController("Test.browse")
  20. @UiDescriptor("test-browse.xml")
  21. public class TestBrowse extends StandardLookup<TestEntity> {
  22.  
  23.     @Autowired private DataManager dataManager;
  24.     @Autowired private UiComponents uiComponents;
  25.     @Autowired private Notifications notifications;
  26.     @Autowired private CollectionLoader<TestEntity> testDl;
  27.  
  28.     @Subscribe
  29.     public void onBeforeShow(final BeforeShowEvent event) {
  30.        testDl.load();
  31.     }
  32.  
  33.     @Subscribe("refreshBtn")
  34.     public void onRefreshBtnClick(Button.ClickEvent event) {
  35.         testDl.load();
  36.     }
  37.  
  38.     @Install(to = "testDl", target = Target.DATA_LOADER)
  39.     private List<TestEntity> testDlLoadDelegate(final LoadContext<TestEntity> loadContext) {
  40.         return dataManager.load(TestEntity.class).all().list();
  41.     }
  42.  
  43.     @Install(to = "testTable.id", subject = "columnGenerator")
  44.     private String testTableIdCoulmnGeneratr(ColumnGeneratorEvent<TestEntity> event) {
  45.         return event.getItem()
  46.                     .getId()
  47.                     .toString();
  48.     }
  49.  
  50.     @Install(to = "testTable.name", subject = "columnGenerator")
  51.     private String testTableNameCoulmnGeneratr(ColumnGeneratorEvent<TestEntity> event) {
  52.         return event.getItem()
  53.                     .getName();
  54.     }
  55.  
  56.     @Install(to = "testTable.description", subject = "columnGenerator")
  57.     private String testTableDescriptionCoulmnGeneratr(ColumnGeneratorEvent<TestEntity> event) {
  58.         return event.getItem()
  59.                     .getDescription();
  60.     }
  61.  
  62.     @Install(to = "testTable.actions", subject = "columnGenerator")
  63.     private Component testTableActionsCoulmnGeneratr(ColumnGeneratorEvent<TestEntity> event) {
  64.         var hbox = uiComponents.create(HBoxLayout.class);
  65.         var firstButton = createButton("first");
  66.         var secondButton = createButton("second");
  67.         hbox.add(firstButton);
  68.         hbox.add(secondButton);
  69.         return hbox;
  70.     }
  71.  
  72.     private Button createButton(String id) {
  73.         var button = uiComponents.create(LinkButton.class);
  74.         button.setIcon(TOGGLE_ON.source());
  75.         button.addClickListener(e ->
  76.                 notifications.create()
  77.                              .withCaption(id + " was clicked")
  78.                              .show());
  79.         return button;
  80.     }
  81.  
  82. }
  83.  
Add Comment
Please, Sign In to add comment