@Override
 public void initializeTableModel() {
   TableHeader[] headers = TableHeader.values();
   for (TableHeader header : headers) {
     columnNames.put(header.getHeader(), header.getToolTip());
   }
 }
Example #2
0
  private void update(boolean isRadioButton, int startIndex, int selectedIndexlocal) {
    selectedRowId = null;
    flexTable.removeAllRows();
    navBarTable.removeAllRows();
    createTableHeader(isRadioButton);
    int count = totalCount;
    int max = startIndex + visibleRecodrCount;
    if (max > count) {
      max = count;
    }
    navBar.update(startIndex, count, max);
    setNavigationBar();
    TableHeader header = tableData.getHeader();
    HeaderColumn[] columns = header.getHeaderColumns();
    String width = null;
    int rowCounter = 0;
    String radioName = String.valueOf(new Date().getTime());
    final List<Record> recordList = tableData.getRecordList();
    if (recordList != null) {
      if (!recordList.isEmpty()) {
        for (final Record record : recordList) {
          int colCounter = 0;
          for (; colCounter < columns.length; colCounter++) {
            width = columns[colCounter].getWidth() + "%";
            flexTable.getCellFormatter().setWidth(rowCounter, colCounter, width);
            flexTable.setWidget(rowCounter, colCounter, record.getWidget(columns[colCounter]));
            flexTable
                .getCellFormatter()
                .setHorizontalAlignment(rowCounter, colCounter, HasHorizontalAlignment.ALIGN_LEFT);
            flexTable.getCellFormatter().setWordWrap(rowCounter, colCounter, true);
            flexTable.getCellFormatter().addStyleName(rowCounter, colCounter, "wordWrap");
          }
          if (isRadioButton) {
            final RadioButton radioButton = new RadioButton(radioName);
            if (rowCounter == selectedIndexlocal) {
              radioButton.setValue(true);
              selectedRowId = record.getIdentifier();
              selectedIndex = rowCounter;
              if (null != listner && fireEventForFirstRow) {
                listner.onRowSelected(selectedRowId);
              }

              scrollIntoView(
                  flexTable.getWidget(selectedIndexlocal, FIRST_COLUMN_INDEX).getElement());
            }
            radioButton.addClickHandler(
                new ClickHandler() {

                  @Override
                  public void onClick(ClickEvent arg0) {
                    clearRadioButtons();
                    radioButton.setValue(true);
                    selectedRowId = record.getIdentifier();
                    selectedIndex = recordList.indexOf(record);
                  }
                });
            flexTable.setWidget(rowCounter, 0, radioButton);
            RadioButtonContainer radioButtonContainer =
                new RadioButtonContainer(radioButton, record.getIdentifier());
            radioButtons.put(rowCounter, radioButtonContainer);
            flexTable
                .getCellFormatter()
                .setHorizontalAlignment(rowCounter, 0, HasHorizontalAlignment.ALIGN_CENTER);

            radioButton.addFocusHandler(
                new FocusHandler() {

                  @Override
                  public void onFocus(FocusEvent arg0) {
                    removeSelectedRowStyleFromTable();
                    for (Integer rowId : radioButtons.keySet()) {
                      if (radioButtons.get(rowId).getRadioButton().equals(radioButton)) {
                        selectedIndex = recordList.indexOf(record);
                        flexTable
                            .getRowFormatter()
                            .addStyleName(rowId, selectionStyle.rowHighlighted());
                      }
                    }
                  }
                });
          } else {
            RadioButtonContainer radioButtonContainer =
                new RadioButtonContainer(null, record.getIdentifier());
            radioButtons.put(rowCounter, radioButtonContainer);
          }
          if (rowCounter % 2 == 0) {
            flexTable.getRowFormatter().setStyleName(rowCounter, selectionStyle.oddRow());
          } else {
            flexTable.getRowFormatter().setStyleName(rowCounter, selectionStyle.evenRow());
          }
          rowCounter++;
          flexTable
              .getRowFormatter()
              .addStyleName(selectedIndexlocal, selectionStyle.rowHighlighted());
        }
      } else {
        Label label = new Label();
        label.setWidth("100%");
        label.setText("No record found.");
        flexTable.getCellFormatter().setWidth(1, 0, "100%");
        flexTable.getFlexCellFormatter().setColSpan(1, 0, 3);
        // Record record = new Record("1");
        // tableData.getRecordList().add(record);
        flexTable.setWidget(1, 0, label);
      }
    }
  }
Example #3
0
  private void createTableHeader(boolean isRadioButton) {
    Images images = GWT.create(Images.class);
    final TableHeader header = tableData.getHeader();
    final List<HeaderColumn> columns = header.getHeaderColumns(isRadioButton);
    String width = null;
    int counter = 0;
    for (final HeaderColumn column : columns) {
      width = column.getWidth() + "%";
      headerTable.getCellFormatter().setWidth(0, counter, width);
      headerTable.getCellFormatter().addStyleName(0, counter, "wordWrap");
      HorizontalPanel headerPanel = new HorizontalPanel();
      Label name = new Label(column.getName());
      headerPanel.add(name);
      final Label sortImage = new Label();
      sortImage.setWidth("5px");
      sortImage.setStyleName("alignMiddle");
      if (order != null
          && column.getDomainProperty() != null
          && order
              .getSortProperty()
              .getProperty()
              .equals(column.getDomainProperty().getProperty())) {
        if (column.isPrimaryAsc()) {
          DOM.setInnerHTML(
              sortImage.getElement(), AbstractImagePrototype.create(images.sortUp()).getHTML());
        } else {
          DOM.setInnerHTML(
              sortImage.getElement(), AbstractImagePrototype.create(images.sortDown()).getHTML());
        }
      }
      headerPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
      headerPanel.add(sortImage);

      if (counter == 0 && isRadioButton) {
        name.setText("");
      }
      headerTable.setWidget(0, counter, headerPanel);
      if (column.isSortable()) {
        name.addStyleName("cursorHand");
        name.addClickHandler(
            new ClickHandler() {

              @Override
              public void onClick(ClickEvent arg0) {
                order = new Order(column.getDomainProperty(), !column.isPrimaryAsc());
                navBar.setOrder(order);
                column.setPrimaryAsc(!column.isPrimaryAsc());
                navBar.getListner().onPagination(navBar.getStartIndex(), visibleRecodrCount, order);
              }
            });
      }
      headerTable
          .getFlexCellFormatter()
          .setVerticalAlignment(0, counter, HasVerticalAlignment.ALIGN_TOP);
      headerTable
          .getCellFormatter()
          .setHorizontalAlignment(0, counter, HasHorizontalAlignment.ALIGN_LEFT);
      counter++;
    }
    headerTable.getRowFormatter().setStyleName(0, selectionStyle.header());
  }