@Override
  public void onModuleLoad() {

    // Create the buttons
    testPerformance = new Button("Test Performance of both");
    testPerformance.addClickHandler(this);

    testListPerformance = new Button("Test Performance of List");
    testListPerformance.addClickHandler(this);

    testSetPerformance = new Button("Test Performance of Set");
    testSetPerformance.addClickHandler(this);

    // Create the Output table
    CellTable<PerformanceTestResults> table = new CellTable<PerformanceTestResults>();
    table.setPageSize(1000);
    initTableColumns(table);

    // Create the data provider and bind it to the table
    ListDataProvider<PerformanceTestResults> dataProvider =
        new ListDataProvider<PerformanceTestResults>();
    dataProvider.addDataDisplay(table);

    // Get the data providers collection to manipulate
    results = dataProvider.getList();

    // Create number of elements input
    Label inputLabel = new Label("Number of elements:");
    inputLabel.getElement().getStyle().setDisplay(Display.INLINE);
    inputTextBox = new TextBox();
    inputTextBox.setText("" + DEFAULT_NUMBER_OF_TEST_ITEMS);

    // Add Elements to the screen
    RootPanel.get().add(inputLabel);
    RootPanel.get().add(inputTextBox);
    RootPanel.get().add(testPerformance);
    RootPanel.get().add(testListPerformance);
    RootPanel.get().add(testSetPerformance);
    RootPanel.get().add(table);
  }
  /**
   * The table that holds the basic friends list.
   *
   * @param result
   */
  private void setTable(GetLogResult result) {
    if (cellTable.getColumnCount() == 4) {
      dataList.clear();
      dataList = dataProvider.getList();
      for (GetLogType friend : result.getResults()) dataList.add(friend);
    } else {
      TextColumn<GetLogType> victimColumn =
          new TextColumn<GetLogType>() {
            @Override
            public String getValue(GetLogType log) {
              if (log.getFbVictimName() != null) return log.getFbVictimName();
              else return "";
            }
          };
      victimColumn.setSortable(true);

      TextColumn<GetLogType> commentPermalink =
          new TextColumn<GetLogType>() {
            @Override
            public String getValue(GetLogType log) {
              if (log.getFbCommentPermalink() != null) return log.getFbCommentPermalink();
              else return "";
            }
          };
      commentPermalink.setSortable(true);

      TextColumn<GetLogType> comment =
          new TextColumn<GetLogType>() {
            @Override
            public String getValue(GetLogType log) {
              if (log.getFbComment() != null) return log.getFbComment();
              else return "";
            }
          };
      comment.setSortable(true);

      TextColumn<GetLogType> date =
          new TextColumn<GetLogType>() {
            @Override
            public String getValue(GetLogType log) {
              if (log.getDate() != null) return log.getDate().toString();
              else return "";
            }
          };
      date.setSortable(true);

      cellTable.addColumn(victimColumn, "Name");
      cellTable.addColumn(commentPermalink, "Comment Link");
      cellTable.addColumn(comment, "Comment Text");
      cellTable.addColumn(date, "Time");

      // Fix column sizes for stupid facebook
      cellTable.setWidth("675px", true);
      cellTable.setColumnWidth(victimColumn, 10.0, Unit.PCT);
      cellTable.setColumnWidth(commentPermalink, 40.0, Unit.PCT);
      cellTable.setColumnWidth(comment, 40.0, Unit.PCT);
      cellTable.setColumnWidth(date, 10.0, Unit.PCT);

      // Attach provider
      dataProvider.addDataDisplay(cellTable);
      dataList = dataProvider.getList();
      for (GetLogType friend : result.getResults()) dataList.add(friend);

      // Set row count
      cellTable.setRowCount(dataList.size());
      cellTable.setPageSize(20);

      ListHandler<GetLogType> columnSortHandler = new ListHandler<GetLogType>(dataList);
      columnSortHandler.setComparator(
          victimColumn,
          new Comparator<GetLogType>() {

            @Override
            public int compare(GetLogType o1, GetLogType o2) {
              if (o1 == o2) {
                return 0;
              }

              // Compare the name columns.
              if (o1 != null) {
                return (o2 != null) ? o1.getFbVictimName().compareTo(o2.getFbVictimName()) : 1;
              }
              return -1;
            }
          });

      columnSortHandler.setComparator(
          commentPermalink,
          new Comparator<GetLogType>() {

            @Override
            public int compare(GetLogType o1, GetLogType o2) {
              if (o1 == o2) {
                return 0;
              }

              // Compare the role columns.
              if (o1 != null) {
                return (o2 != null)
                    ? o1.getFbCommentPermalink().compareTo(o2.getFbCommentPermalink())
                    : 1;
              }
              return -1;
            }
          });

      columnSortHandler.setComparator(
          comment,
          new Comparator<GetLogType>() {
            @Override
            public int compare(GetLogType o1, GetLogType o2) {
              if (o1 == o2) {
                return 0;
              }

              // Compare the role columns.
              if (o1 != null) {
                return (o2 != null) ? o1.getFbComment().compareTo(o2.getFbComment()) : 1;
              }
              return -1;
            }
          });

      columnSortHandler.setComparator(
          date,
          new Comparator<GetLogType>() {

            @Override
            public int compare(GetLogType o1, GetLogType o2) {
              if (o1 == o2) {
                return 0;
              }

              // Compare the role columns.
              if (o1 != null) {
                return (o2 != null) ? o1.getDate().compareTo(o2.getDate()) : 1;
              }
              return -1;
            }
          });

      cellTable.addColumnSortHandler(columnSortHandler);
      cellTable.getColumnSortList().push(date);
      cellTable.setPageSize(5000);
    }
  }
  /** Method that places the components in the form. */
  @Override
  public void onLoad() {

    // Display 15 rows in one page
    propertiesTable.setPageSize(20);

    // Add a text column to show the name.
    TextColumn<OrganizationProperty> nameColumn =
        new TextColumn<OrganizationProperty>() {
          @Override
          public String getValue(OrganizationProperty property) {
            return property.getProperty().getName();
          }
        };

    propertiesTable.addColumn(nameColumn, "Name");

    // Add column with an input cell to edit the value of the property
    TextInputCell valueCell = new TextInputCell();
    Column<OrganizationProperty, String> valueColumn =
        new Column<OrganizationProperty, String>(valueCell) {
          @Override
          public String getValue(OrganizationProperty property) {
            return property.getValue();
          }
        };

    valueColumn.setFieldUpdater(
        new FieldUpdater() {
          @Override
          public void update(int index, Object object, Object value) {
            newPropertyValue = (String) value;
          }
        });

    propertiesTable.addColumn(valueColumn, "Value");
    propertiesTable.addColumnStyleName(2, "gridOrganizationPropertyValueColumn");

    // Add column with save button to save the value of the property
    Column<OrganizationProperty, String> saveButtonColumn = createSaveButtonColumn();
    propertiesTable.addColumn(saveButtonColumn);

    // Get properties
    final List<OrganizationProperty> properties =
        new ArrayList<OrganizationProperty>(organization.getOrganizationProperties());
    AsyncDataProvider<OrganizationProperty> provider =
        new AsyncDataProvider<OrganizationProperty>() {
          @Override
          protected void onRangeChanged(HasData<OrganizationProperty> display) {
            int start = display.getVisibleRange().getStart();
            int end = start + display.getVisibleRange().getLength();
            end = end >= properties.size() ? properties.size() : end;
            List<OrganizationProperty> sub = properties.subList(start, end);
            updateRowData(start, sub);
          }
        };

    provider.addDataDisplay(propertiesTable);
    provider.updateRowCount(properties.size(), true);

    SimplePager pager = new SimplePager();
    pager.setDisplay(propertiesTable);

    VerticalPanel vp = new VerticalPanel();
    vp.add(propertiesTable);
    vp.add(pager);
    mainPanel.add(vp);
  }
示例#4
0
 private void initializeTable() {
   dataProvider.addDataDisplay(table);
   table.setPageSize(PAGE_SIZE);
   table.setEmptyTableWidget(noValues);
   pager.setDisplay(table);
 }