Package org.gwtlib.client.table.ui

Examples of org.gwtlib.client.table.ui.PagingTable


    root.add(createGrid());
  }

  private Grid createGrid() {
    final Grid grid = new Grid(3, 1);
    final PagingTable table = createTable();
    table.setSize("100%", "100%");
    grid.setWidget(0, 0, table);
    grid.getRowFormatter().setVerticalAlign(0, HasVerticalAlignment.ALIGN_TOP);
    grid.getCellFormatter().setWidth(0, 0, "100%");
    grid.getCellFormatter().setHeight(0, 0, "100%");
    HorizontalPanel hpanel = new HorizontalPanel();
    hpanel.add(new Label("Show Column:"));
    for(int i = 0; i < table.getColumnLayout().getTotalColumnCount(); ++i) {
      final CheckBox checkbox = new CheckBox(String.valueOf(i));
      checkbox.setValue(true);
      hpanel.add(checkbox);
      final int ii = i;
      checkbox.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
          table.show(ii, checkbox.getValue());
          table.update();
        }
      });
    }
    grid.setWidget(1, 0, hpanel);
    hpanel = new HorizontalPanel();
    hpanel.add(new Button("Clear", new ClickHandler() {
      public void onClick(ClickEvent event) {
        table.clear();
      }     
    }));
    hpanel.add(new Button("Reset", new ClickHandler() {
      public void onClick(ClickEvent event) {
        table.reset();
      }     
    }));
    hpanel.add(new Button("Simulate Failure", new ClickHandler() {
      public void onClick(ClickEvent event) {
        table.onFailure(null);
      }     
    }));
    grid.setWidget(2, 0, hpanel);
    grid.setSize("100%", "100%");
    return grid;
View Full Code Here


          number.toString(), "Hyperlink", "img/down.gif"
      });
    }
    // Now configure the table
    ColumnLayout layout = new ColumnLayout(columns);
    final PagingTable table = new PagingTable(layout, new PagingBar(0, TOTAL_SIZE, 10, new int[] { 5, 10, 20, 50, 100 }));
    ContentProvider provider = new ContentProvider() {
      // Simulate retrieval of sample data, in requested sort order
      public void load(int begin, int end, final int sortId, boolean ascending) {
        final int sign = ascending ? 1 : -1;
        Row[] tmp = new Row[rows.length];
        for(int i = 0; i < rows.length; ++i) tmp[i] = rows[i];
        switch(sortId) {
          case 1:
            Arrays.sort(tmp, new Comparator<Row>() {
              public int compare(Row o1, Row o2) {
                String v1 = (String)o1.getValue(sortId);
                String v2 = (String)o2.getValue(sortId);
                return sign * (v1.compareTo(v2));
              }
            });
            break;
          case 4:
            Arrays.sort(tmp, new Comparator<Row>() {
              public int compare(Row o1, Row o2) {
                Date v1 = (Date)o1.getValue(sortId);
                Date v2 = (Date)o2.getValue(sortId);
                return sign * (v1.compareTo(v2));
              }
            });
            break;
          case 5:
            Arrays.sort(tmp, new Comparator<Row>() {
              public int compare(Row o1, Row o2) {
                int v1 = ((Integer)o1.getValue(sortId)).intValue();
                int v2 = ((Integer)o2.getValue(sortId)).intValue();
                return sign * (v1 < v2 ? -1 : (v1 == v2 ? 0 : 1));
              }
            });
            break;
          default:
            break;
        }
        Row[] srows = new Row[Math.min(end - begin, tmp.length - begin)];
        for(int i = 0; i < srows.length; ++i) srows[i] = tmp[begin + i];
        table.onSuccess(new Rows(srows, begin, sortId, ascending));
      }
    };
    table.setContentProvider(provider);
    table.addTableListener(new TableListenerAdapter() {
      public void onCellClicked(SourcesTableEvents sender, Row row, Column column) {
        for(int i = 0; i < columns.length; ++i) columns[i].setState(Column.State.NONE);
        column.setState(Column.State.SELECT);
      }

      public void onRowClicked(SourcesTableEvents sender, Row row) {
        GWT.log("Row clicked (id " + row.getId() + ")", null);
        for(int i = 0; i < rows.length; ++i) rows[i].setState(Row.State.NONE);
        row.setState(Row.State.SELECT);
        table.refreshRowState();
      }

      public void onClick(SourcesTableEvents sender, Row row, Column column, Widget widget) {
        GWT.log("Renderer widget clicked", null);
        if(widget instanceof CheckBox) {
          row.setValue(0, new Boolean(((CheckBox)widget).getValue()));
        } else if (widget instanceof Button) {
          Window.alert(((Button)widget).getHTML());
        } else if (widget instanceof Hyperlink) {
          Window.alert(((Hyperlink)widget).getHTML());
        } else if (widget instanceof Image) {
          Window.alert(((Image)widget).getUrl());
        }
      }

      public void onChange(SourcesTableEvents sender, Row row, Column column, Widget widget) {
        GWT.log("Renderer widget changed", null);
        if(widget instanceof ListBox) {
          ListBox listBox = (ListBox)widget;
          row.setValue(6, listBox.getValue(listBox.getSelectedIndex()));
        } else if(widget instanceof TextBox) {
          row.setValue(8, ((TextBox)widget).getText());
        }
      }
    });
    checkAll.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {
        for(int i = 0; i < rows.length; ++i) rows[i].setValue(0, new Boolean(checkAll.getValue()));
        table.update();
      }
    });
    table.update();
    return table;
  }
View Full Code Here

TOP

Related Classes of org.gwtlib.client.table.ui.PagingTable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.