public PersonTableView(final IViewContext context, final IBeanTableModel<IPerson> model) { final IContainer container = context.getContainer(); container.setLayout(MigLayoutFactory.growingInnerCellLayout()); final ICapApiBluePrintFactory cbpf = CapUiToolkit.bluePrintFactory(); final IBeanTable<IPerson> table = container.add(cbpf.beanTable(model), MigLayoutFactory.GROWING_CELL_CONSTRAINTS); table.getCellPopMenu().addAction(PersonLongLastingActionFactory.create(model)); }
private String getSelectedUserName() { final IBeanProxy<IUser> selectedUser = table.getModel().getFirstSelectedBean(); if (selectedUser != null) { final IUser user = selectedUser.getBean(); return user.getName() + " " + user.getLastName(); } else { return "Nothing"; } }
public UserTableView( final IViewContext context, final IBeanTableModel<IUser> tableModel, final ValueHolder<Integer> parameter) { this.beanTableModel = tableModel; this.parameter = parameter; final IContainer container = context.getContainer(); container.setLayout(MigLayoutFactory.growingInnerCellLayout()); this.table = container.add( CapUiToolkit.bluePrintFactory().beanTable(beanTableModel), MigLayoutFactory.GROWING_CELL_CONSTRAINTS); final IToolBarModel toolBar = context.getToolBar(); toolBar.addContainer(createDelayFieldCreator()); toolBar.addAction(createClearAction()); toolBar.addAction(createPackAction()); table.getCellPopMenu().addAction(new ChangeGenderAction(tableModel)); table.getCellPopMenu().addAction(new ChangeBirthdayAction(tableModel)); table.getCellPopMenu().addAction(new LongLastingAction(tableModel)); table.getCellPopMenu().addAction(new CreateTransientUserAction(table)); table.getCellPopMenu().addSeparator(); // example for dynamic menu final Random random = new Random(); final IMenuModel dynamicMenuModel = createDynamicMenuModelStub(); table.getCellPopMenu().addItem(dynamicMenuModel); table.addCellMenuListener( new IPopupMenuListener<ITableCellPopupEvent>() { @Override public void beforeMenuShow(final ITableCellPopupEvent event) { fillDynamicMenuModel(dynamicMenuModel, random, event); } }); beanTableModel.load(); }
private void fillDynamicMenuModel( final IMenuModel menuModel, final Random random, final ITableCellPopupEvent event) { menuModel.removeAllItems(); menuModel.addActionItem( "Clicked row '" + event.getRowIndex() + "' and column '" + event.getColumnIndex() + "'"); menuModel.addActionItem( "Clicked value '" + table.getModel().getValue(event.getRowIndex(), event.getColumnIndex()) + "'"); menuModel.addActionItem("Its " + (new Date())); menuModel.addActionItem(getSelectedUserName() + " is selected"); final int count = random.nextInt(5) + 1; for (int i = 0; i < count; i++) { menuModel.addActionItem("Random item " + i); } }