Exemple #1
0
  private void setupSessionDataGrid() {
    sessionsDataGrid = new DataGrid<SessionDataDto>();
    sessionsDataGrid.setPageSize(15);
    sessionsDataGrid.setEmptyTableWidget(new Label("No Sessions"));

    // Add a selection model so we can select cells.
    final SelectionModel<SessionDataDto> selectionModel =
        new MultiSelectionModel<SessionDataDto>(
            new ProvidesKey<SessionDataDto>() {
              @Override
              public Object getKey(SessionDataDto item) {
                return item.getSessionId();
              }
            });
    sessionsDataGrid.setSelectionModel(
        selectionModel, DefaultSelectionEventManager.<SessionDataDto>createCheckboxManager());

    // Checkbox column. This table will uses a checkbox column for selection.
    // Alternatively, you can call dataGrid.setSelectionEnabled(true) to enable mouse selection.
    Column<SessionDataDto, Boolean> checkColumn =
        new Column<SessionDataDto, Boolean>(new CheckboxCell(true, false)) {
          @Override
          public Boolean getValue(SessionDataDto object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
          }
        };
    sessionsDataGrid.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
    sessionsDataGrid.setColumnWidth(checkColumn, 40, Style.Unit.PX);

    sessionsDataGrid.addColumn(
        new TextColumn<SessionDataDto>() {
          @Override
          public String getValue(SessionDataDto object) {
            return object.getName();
          }
        },
        "Name");

    sessionsDataGrid.addColumn(
        new TextColumn<SessionDataDto>() {
          @Override
          public String getValue(SessionDataDto object) {
            return object.getStartDate();
          }
        },
        "Start Date");

    sessionsDataGrid.addColumn(
        new TextColumn<SessionDataDto>() {
          @Override
          public String getValue(SessionDataDto object) {
            return object.getEndDate();
          }
        },
        "End Date");

    sessionDataProvider.addDataDisplay(sessionsDataGrid);
  }
Exemple #2
0
  private void createDataGrid() {
    dataGrid = new DataGrid<InputItem>(1024 * 1024, ZicoDataGridResources.INSTANCE, KEY_PROVIDER);
    selectionModel = new SingleSelectionModel<InputItem>(KEY_PROVIDER);
    dataGrid.setSelectionModel(selectionModel);

    recordStore = new ListDataProvider<InputItem>(KEY_PROVIDER);
    recordStore.addDataDisplay(dataGrid);

    sortHandler = new ColumnSortEvent.ListHandler<InputItem>(recordStore.getList());

    Column<InputItem, InputItem> colId = new IdentityColumn<InputItem>(ID_CELL);
    dataGrid.addColumn(colId, new ResizableHeader<InputItem>("#", dataGrid, colId));
    dataGrid.setColumnWidth(colId, 35, Style.Unit.PX);

    final EditTextCell cellName = new EditTextCell();
    Column<InputItem, String> colName =
        new Column<InputItem, String>(cellName) {
          @Override
          public String getValue(InputItem rec) {
            return rec.getName();
          }
        };
    colName.setFieldUpdater(
        new FieldUpdater<InputItem, String>() {
          @Override
          public void update(int index, InputItem rec, String value) {
            if (!value.equals(rec.getName())) {
              markChange(rec);
              rec.setName(value);
              cellName.clearViewData(rec.getId());
            }
          }
        });
    dataGrid.addColumn(colName, new ResizableHeader<InputItem>("Name", dataGrid, colName));
    dataGrid.setColumnWidth(colName, 128, Style.Unit.PX);

    colName.setSortable(true);
    sortHandler.setComparator(
        colName,
        new Comparator<InputItem>() {
          @Override
          public int compare(InputItem o1, InputItem o2) {
            return o1.getName().compareTo(o2.getName());
          }
        });

    //        final SelectCell<String,Integer> cellActive = new SelectCell<String,Integer>(
    //                ZicoWidgets.<String,Integer>map("NO",0,"YES",1));
    //        Column<InputItem,Integer> colActive = new Column<InputItem, Integer>(cellActive) {
    //            @Override
    //            public Integer getValue(InputItem rec) {
    //                return rec.getActive();
    //            }
    //        };
    //        colActive.setFieldUpdater(new FieldUpdater<InputItem, Integer>() {
    //            @Override
    //            public void update(int index, InputItem rec, Integer value) {
    //                if (rec.getActive() != value) {
    //                    markChange(rec);
    //                    rec.setActive(value);
    //                    cellActive.clearViewData(rec.getId());
    //                }
    //            }
    //        });
    //        dataGrid.addColumn(colActive, new ResizableHeader<InputItem>("Active", dataGrid,
    // colActive));
    //        dataGrid.setColumnWidth(colActive, 128, Style.Unit.PX);

    //        final DatePickerCell cellTstart = new DatePickerCell(ClientUtil.TSTAMP_FORMAT0);
    //        Column<InputItem,Date> colTstart = new Column<InputItem, Date>(cellTstart) {
    //            @Override
    //            public Date getValue(InputItem rec) {
    //                return ClientUtil.unix2date(rec.getTstart());
    //            }
    //        };
    //        colTstart.setFieldUpdater(new FieldUpdater<InputItem, Date>() {
    //            @Override
    //            public void update(int index, InputItem rec, Date value) {
    //                long t = ClientUtil.date2unix(value);
    //                if (t != rec.getTstart()) {
    //                    markChange(rec);
    //                    rec.setTstart(t);
    //                    cellTstart.clearViewData(rec.getId());
    //                }
    //            }
    //        });
    //        colTstart.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    //        dataGrid.addColumn(colTstart, new ResizableHeader<InputItem>("TStart", dataGrid,
    // colTstart));
    //        dataGrid.setColumnWidth(colTstart, 100, Style.Unit.PX);

    //        final DatePickerCell cellTstop = new DatePickerCell(ClientUtil.TSTAMP_FORMAT0);
    //        Column<InputItem,Date> colTstop = new Column<InputItem, Date>(cellTstop) {
    //            @Override
    //            public Date getValue(InputItem rec) {
    //                return ClientUtil.unix2date(rec.getTstop());
    //            }
    //        };
    //        colTstop.setFieldUpdater(new FieldUpdater<InputItem, Date>() {
    //            @Override
    //            public void update(int index, InputItem rec, Date value) {
    //                long t = ClientUtil.date2unix(value);
    //                if (t != rec.getTstop()) {
    //                    markChange(rec);
    //                    rec.setTstop(t);
    //                    cellTstop.clearViewData(rec.getId());
    //                }
    //            }
    //        });
    //        colTstop.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    //        dataGrid.addColumn(colTstop, new ResizableHeader<InputItem>("TStop", dataGrid,
    // colTstop));
    //        dataGrid.setColumnWidth(colTstop, 100, Style.Unit.PX);

    Column<InputItem, Integer> colInput =
        new Column<InputItem, Integer>(cellInput) {
          @Override
          public Integer getValue(InputItem iitem) {
            return iitem.getInputId();
          }
        };
    colInput.setFieldUpdater(
        new FieldUpdater<InputItem, Integer>() {
          @Override
          public void update(int index, InputItem rec, Integer value) {
            if (rec.getInputId() != value) {
              markChange(rec);
              rec.setInputId(value);
              cellInput.clearViewData(rec.getId());
            }
          }
        });
    dataGrid.addColumn(colInput, new ResizableHeader<InputItem>("Input", dataGrid, colInput));
    dataGrid.setColumnWidth(colInput, 128, Style.Unit.PX);

    Column<InputItem, Integer> colTxForm =
        new Column<InputItem, Integer>(cellTxForm) {
          @Override
          public Integer getValue(InputItem rec) {
            return rec.getTxFormid();
          }
        };
    colTxForm.setFieldUpdater(
        new FieldUpdater<InputItem, Integer>() {
          @Override
          public void update(int index, InputItem iitem, Integer value) {
            if (iitem.getTxFormid() != value) {
              markChange(iitem);
              iitem.setTxFormid(value);
              cellTxForm.clearViewData(iitem.getId());
            }
          }
        });
    dataGrid.addColumn(colTxForm, new ResizableHeader<InputItem>("TxForm", dataGrid, colTxForm));
    dataGrid.setColumnWidth(colTxForm, 128, Style.Unit.PX);

    final EditTextCell cellComment = new EditTextCell();
    Column<InputItem, String> colComment =
        new Column<InputItem, String>(cellComment) {
          @Override
          public String getValue(InputItem rec) {
            return rec.getComment();
          }
        };
    colComment.setFieldUpdater(
        new FieldUpdater<InputItem, String>() {
          @Override
          public void update(int index, InputItem rec, String value) {
            if (!value.equals(rec.getComment())) {
              markChange(rec);
              rec.setComment(value);
              cellComment.clearViewData(rec.getId());
            }
          }
        });
    dataGrid.addColumn(colComment, new ResizableHeader<InputItem>("Comment", dataGrid, colComment));

    colComment.setSortable(true);
    sortHandler.setComparator(
        colComment,
        new Comparator<InputItem>() {
          @Override
          public int compare(InputItem o1, InputItem o2) {
            return o1.getComment().compareTo(o2.getComment());
          }
        });

    dataGrid.addCellPreviewHandler(
        new CellPreviewEvent.Handler<InputItem>() {
          @Override
          public void onCellPreview(CellPreviewEvent<InputItem> event) {
            NativeEvent nev = event.getNativeEvent();
            String eventType = nev.getType();
            if (BrowserEvents.CONTEXTMENU.equals(eventType)) {
              selectionModel.setSelected(event.getValue(), true);
              if (event.getValue() != null) {
                contextMenu.setPopupPosition(
                    event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
                contextMenu.show();
              }
            }
          }
        });

    dataGrid.setKeyboardSelectionPolicy(
        HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);
    dataGrid.addDomHandler(
        new DoubleClickHandler() {
          @Override
          public void onDoubleClick(DoubleClickEvent event) {
            event.preventDefault();
          }
        },
        DoubleClickEvent.getType());
    dataGrid.addDomHandler(
        new ContextMenuHandler() {
          @Override
          public void onContextMenu(ContextMenuEvent event) {
            event.preventDefault();
          }
        },
        ContextMenuEvent.getType());
  }