Example usage for com.google.gwt.gen2.table.client ScrollTable ScrollTable

List of usage examples for com.google.gwt.gen2.table.client ScrollTable ScrollTable

Introduction

In this page you can find the example usage for com.google.gwt.gen2.table.client ScrollTable ScrollTable.

Prototype

public ScrollTable(FixedWidthGrid dataTable, FixedWidthFlexTable headerTable) 

Source Link

Document

Construct a new ScrollTable .

Usage

From source file:com.google.gwt.gen2.demo.scrolltable.client.ScrollTableDemo.java

License:Apache License

/**
 * Setup the scroll table./*www.  java 2  s .  c  o  m*/
 */
protected AbstractScrollTable createScrollTable() {
    // Create the three component tables
    FixedWidthFlexTable headerTable = createHeaderTable();
    FixedWidthFlexTable footerTable = createFooterTable();
    FixedWidthGrid dataTable = createDataTable();

    // Create the scroll table
    ScrollTable theScrollTable = new ScrollTable(dataTable, headerTable);
    theScrollTable.setFooterTable(footerTable);

    // Setup the formatting
    theScrollTable.setCellPadding(3);
    theScrollTable.setCellSpacing(0);
    theScrollTable.setResizePolicy(ScrollTable.ResizePolicy.FILL_WIDTH);

    // first name
    theScrollTable.setMinimumColumnWidth(0, 50);
    theScrollTable.setPreferredColumnWidth(0, 100);
    theScrollTable.setColumnTruncatable(0, false);

    // last name
    theScrollTable.setMinimumColumnWidth(1, 50);
    theScrollTable.setPreferredColumnWidth(1, 100);
    theScrollTable.setColumnTruncatable(1, false);

    // age
    theScrollTable.setMinimumColumnWidth(2, 35);
    theScrollTable.setPreferredColumnWidth(2, 35);
    theScrollTable.setMaximumColumnWidth(2, 35);

    // gender
    theScrollTable.setMinimumColumnWidth(3, 45);
    theScrollTable.setPreferredColumnWidth(3, 45);
    theScrollTable.setMaximumColumnWidth(3, 45);

    // race
    theScrollTable.setMinimumColumnWidth(4, 45);
    theScrollTable.setPreferredColumnWidth(4, 45);
    theScrollTable.setMaximumColumnWidth(4, 45);

    // color
    theScrollTable.setPreferredColumnWidth(5, 80);

    // sport
    theScrollTable.setMinimumColumnWidth(6, 40);
    theScrollTable.setPreferredColumnWidth(6, 110);

    // college
    theScrollTable.setMinimumColumnWidth(7, 50);
    theScrollTable.setPreferredColumnWidth(7, 180);
    theScrollTable.setMaximumColumnWidth(7, 250);

    // year
    theScrollTable.setPreferredColumnWidth(8, 25);
    theScrollTable.setColumnTruncatable(8, false);

    // gpa
    theScrollTable.setPreferredColumnWidth(9, 35);
    theScrollTable.setColumnTruncatable(9, false);

    // id
    theScrollTable.setPreferredColumnWidth(10, 55);
    theScrollTable.setColumnTruncatable(10, false);

    // pin
    theScrollTable.setPreferredColumnWidth(11, 45);
    theScrollTable.setColumnTruncatable(11, false);

    return theScrollTable;
}

From source file:com.qualogy.qafe.gwt.client.ui.renderer.TableRenderer.java

License:Apache License

public UIObject render(ComponentGVO component, String uuid, String parent, String context) {
    ScrollTable uiObject = null;// w w  w  .j  ava2s . c o m
    if (component != null) {
        if (component instanceof TableGVO) {
            TableGVO gvo = (TableGVO) component;
            // setup the table
            FixedWidthFlexTable headerTable = new FixedWidthFlexTable();
            FixedWidthGrid dataTable = new FixedWidthGrid();
            //dataTable.setHoveringPolicy(SelectionGrid.HOVERING_POLICY_ROW);
            if (gvo.getMenu() != null) {
                final ComponentGVO finalComponentGVO = component;
                final String finalUuid = uuid;
                final String finalParent = parent;
                uiObject = new ScrollTable(dataTable, headerTable) {
                    @Override
                    public void onBrowserEvent(Event event) {
                        if (event.getTypeInt() == Event.ONCONTEXTMENU) {
                            DOM.eventPreventDefault(event);
                            applyContextMenu(event, finalComponentGVO, finalUuid, finalParent);
                        }
                        super.onBrowserEvent(event);
                    }

                    @Override
                    protected void setElement(Element elem) {
                        super.setElement(elem);
                        sinkEvents(Event.ONCONTEXTMENU);
                    }
                };
            } else {
                uiObject = new ScrollTable(dataTable, headerTable);
            }

            uiObject.setCellPadding(3);
            uiObject.setCellSpacing(1);
            uiObject.setResizePolicy(ScrollTable.ResizePolicy.FILL_WIDTH);

            // Header processing

            TableRowGVO header = gvo.getHeader();
            if (header != null) {
                TableCellGVO[] cells = header.getCells();
                if (cells != null) {

                    for (int i = 0; i < cells.length; i++) {
                        UIObject componentUIObject = renderChildComponent(cells[i].getComponent(), uuid, parent,
                                context);
                        if (componentUIObject != null && componentUIObject instanceof Widget) {
                            Widget w = (Widget) componentUIObject;
                            headerTable.setWidget(0, i, w);
                        }

                    }
                }
            }
            // Row processing
            TableRowGVO[] rows = gvo.getRows();
            if (rows != null) {
                for (int i = 0; i < rows.length; i++) {
                    int beforeRow = dataTable.insertRow(i);
                    TableCellGVO[] cells = rows[i].getCells();
                    if (cells != null) {
                        dataTable.resizeColumns(cells.length);
                        for (int j = 0; j < cells.length; j++) {
                            UIObject componentUIObject = renderChildComponent(cells[j].getComponent(), uuid,
                                    parent, context);
                            if (componentUIObject != null && componentUIObject instanceof Widget) {
                                Widget w = (Widget) componentUIObject;

                                dataTable.setWidget(beforeRow, j, w);
                            }

                        }
                    }
                }
            }
            // Redraw the scroll table
            RendererHelper.fillIn(gvo, uiObject, uuid, parent, context);

            uiObject.redraw();

        }

    }

    return uiObject;
}

From source file:edu.ycp.cs.netcoder.client.CourseAndProblemView.java

License:Open Source License

/**
 * Constructor./*ww w.j  a va2  s.c  o m*/
 * 
 * @param session the Session
 */
public CourseAndProblemView(Session session) {
    super(session);

    // Subscribe to session ADDED_OBJECT events (to find out when course list is loaded)
    getSession().subscribe(Session.Event.ADDED_OBJECT, this, getSubscriptionRegistrar());

    LayoutPanel layoutPanel = getLayoutPanel();

    // Add grid to display problems
    headerTable = new FixedWidthFlexTable();
    FlexCellFormatter formatter = headerTable.getFlexCellFormatter();
    headerTable.setHTML(0, 0, "Problem name");
    headerTable.setHTML(0, 1, "Description");
    formatter.setColSpan(0, 0, 1);
    formatter.setColSpan(0, 1, 1);

    grid = new FixedWidthGrid();
    grid.setSelectionPolicy(SelectionPolicy.ONE_ROW);
    grid.setSelectionEnabled(true);
    grid.addRowSelectionHandler(new RowSelectionHandler() {
        @Override
        public void onRowSelection(RowSelectionEvent event) {
            //Window.alert("Row selection event!");
            CourseSelection courseSelection = getSession().get(CourseSelection.class);
            Problem[] problemList = courseSelection.getProblemList();
            Set<Row> selectedRows = event.getSelectedRows();
            //Window.alert(selectedRows.size() + " rows selected");
            if (selectedRows.size() == 1) {
                // A problem has been selected
                Row row = selectedRows.iterator().next();
                int index = row.getRowIndex();
                Problem problem = problemList[index];
                //Window.alert("Setting problem " + problem.getBriefDescription() + " in session");
                getSession().add(problem);
            }
        }
    });

    setColumnWidth(0, 100);
    setColumnWidth(1, 300);

    table = new ScrollTable(grid, headerTable);

    layoutPanel.add(table);

    // Status and button bar widget
    this.statusAndButtonBar = new StatusAndButtonBarWidget(getSession(), getSubscriptionRegistrar());
    statusAndButtonBar.addToLeftPanel(new StatusMessageWidget(getSession(), getSubscriptionRegistrar()));
    Button selectProblemButton = new Button("Select problem");
    selectProblemButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            Problem problem = getSession().get(Problem.class);
            if (problem != null) {
                // Woot!!!
                //Window.alert("firing PROBLEM_CHOSEN for " + problem.getBriefDescription());
                getSession().notifySubscribers(Session.Event.PROBLEM_CHOSEN, problem);
            }
        }
    });
    statusAndButtonBar.addToRightPanel(selectProblemButton);
    layoutPanel.add(statusAndButtonBar);

    // Problem description
    this.problemDescriptionWidget = new ProblemDescriptionWidget(getSession(), getSubscriptionRegistrar());
    layoutPanel.add(problemDescriptionWidget);

    initWidget(layoutPanel);

    // Subscribe to window resize events
    getSession().get(WindowResizeNotifier.class).subscribe(WindowResizeNotifier.WINDOW_RESIZED, this,
            getSubscriptionRegistrar());

    // Subscribe to changes in selected course
    CourseSelection courseSelection = new CourseSelection();
    addSessionObject(courseSelection);
    courseSelection.subscribe(CourseSelection.Event.COURSE_SELECTED, this, getSubscriptionRegistrar());
    courseSelection.subscribe(CourseSelection.Event.COURSE_LOADED, this, getSubscriptionRegistrar());
}

From source file:edu.ycp.cs.netcoder.client.status.ResultWidget.java

License:Open Source License

/**
 * Constructor.// ww  w  .j a v  a2  s .  com
 * The ResultWidget will listen for TestResult[] objects being
 * added to the session, and update its contents appropriately.
 * 
 * @param session    the Session
 * @param registrar  the SubscriptionRegistrar
 */
public ResultWidget(Session session, SubscriptionRegistrar registrar) {
    this.session = session;
    session.subscribe(Session.Event.ADDED_OBJECT, this, registrar);

    headerTable = new FixedWidthFlexTable();
    FlexCellFormatter formatter = headerTable.getFlexCellFormatter();
    headerTable.setHTML(0, 0, "Outcome");
    headerTable.setHTML(0, 1, "Message");
    headerTable.setHTML(0, 2, "Output");
    headerTable.setHTML(0, 3, "Error output");
    formatter.setColSpan(0, 0, 1);
    formatter.setColSpan(0, 1, 1);
    formatter.setColSpan(0, 2, 1);
    formatter.setColSpan(0, 3, 1);

    grid = new FixedWidthGrid();
    grid.setSelectionPolicy(SelectionPolicy.ONE_ROW);

    setColumnWidth(0, 100);
    setColumnWidth(1, 400);
    setColumnWidth(2, 100);
    setColumnWidth(3, 100);

    table = new ScrollTable(grid, headerTable);

    initWidget(table);
}

From source file:org.gwtaf.widgets.expanding.gin.ScrollTableGinModule.java

License:Apache License

/**
 * Small hack to bypass Gin complaining about no default constructors of
 * ScrollTable.//  w  w w  . java  2 s . co  m
 * 
 * @return dummy {@link ScrollTable}
 */
@Provides
public ScrollTable scrollTableProvider() {
    FixedWidthFlexTable headingsTable = new FixedWidthFlexTable();
    FixedWidthGrid grid = new FixedWidthGrid(1, 1);
    ScrollTable table = new ScrollTable(grid, headingsTable);
    return table;
}

From source file:org.gwtaf.widgets.search.SearchResultScrollTable.java

License:Apache License

/**
 * Constructs a new {@Code SearchResultsTable}
 * //from  w  ww.j a v  a  2s. c  om
 * @param scrolltable
 *            the injected {@link ScrollTable}
 * @param dataGrid
 *            the injected {@link SearchDataGrid}
 * @param headerTable
 *            the injected {@link FixedWidthFlexTable}
 * @param headings
 *            the injected {@link SearchResultHeadings}
 */
@Inject
public SearchResultScrollTable(FlexTable flexTable, ScrollTable scrolltable, SearchDataGrid dataGrid,
        FixedWidthFlexTable headerTable) {

    assert scrolltable != null && dataGrid != null && headerTable != null;

    this.mainPanel = flexTable;

    // the dataGrid and headerTable are passed in but mainTable will already
    // be constructed using them in the Provider. We need these references
    // because ScrollTable does not offer setter methods
    // if nothing is provided, go with a blank setup.
    if (headerTable.equals(new FixedWidthFlexTable())) {
        SearchDataGrid grid = new SearchDataGrid(1, 0);
        grid.setSelectionEnabled(true);
        scrolltable = new ScrollTable(grid, headerTable);
    }

    this.dataGrid = dataGrid;
    this.headerTable = headerTable;
    this.scrollTable = scrolltable;

    initWidget(this.mainPanel);
}

From source file:org.gwtaf.widgets.search.SearchResultScrollTable.java

License:Apache License

private void setValue(List<SearchResult> results, boolean saveFullResult) {

    // store the full results if necessary.
    if (saveFullResult) {
        fullResults = new DynamicSearchResults();
        fullResults.setResults(results);
    }//from  w  ww  .  j av  a2 s.  co  m

    // nothing to do if there are no results.
    if (results == null) {
        return;
    }

    // figure out how many columns we'll need
    int neededColumns = results.size() == 0 ? 0 : results.get(0).getDataValues().length;

    // make a new data grid
    this.dataGrid = createDataGrid(results.size(), neededColumns);
    dataGrid.setCellSpacing(0);

    // pass on the cell selection handler
    dataGrid.addCellClickHandler(clickHandler);

    // pass on the handler
    dataGrid.addRowSelectionHandler(rowSelectionHandler);

    // add handler for sorting
    dataGrid.addColumnSortHandler(new ColumnSortHandler() {

        public void onColumnSorted(ColumnSortEvent event) {
            lastSortedColumn = event.getColumnSortList().getPrimaryColumn();
            lastSortDirection = event.getColumnSortList().isPrimaryAscending();
            markOdd();
        }
    });

    int dataGridIndex = 0;

    // set the values into the list
    for (int i = 0; i < results.size(); i++) {

        // if not null
        if (results.get(i) != null) {
            setSingleResult(results.get(i), dataGridIndex);
            dataGridIndex++;
        }
    }

    /**
     * Creating a new header table. Cannot re-use the old one due to
     * scrolltable not supporting remove. (one parent widget constraint)
     */
    FixedWidthFlexTable newHeaderTable = new FixedWidthFlexTable();
    for (int i = 0; i < headerTable.getColumnCount(); i++) {
        newHeaderTable.setHTML(0, i, headerTable.getHTML(0, i));
    }

    // replace the scrolltable
    ScrollTable newTable = new ScrollTable(dataGrid, newHeaderTable);
    newTable.setSortPolicy(SortPolicy.SINGLE_CELL);
    newTable.setResizePolicy(ScrollTable.ResizePolicy.FILL_WIDTH);
    this.scrollTable = newTable;
    mainPanel.clear();
    mainPanel.setWidget(0, 0, newTable);
}