List of usage examples for com.google.gwt.user.cellview.client LoadingStateChangeEvent getLoadingState
public LoadingState getLoadingState()
From source file:com.google.gwt.sample.showcase.client.content.cell.CustomKeyboardHandler.java
public CustomKeyboardHandler(CellList<ContactInfo> cellList, SelectableWidget widgetAboveList) { super(cellList); this.cellList = cellList; this.widgetAboveList = widgetAboveList; cellList.addLoadingStateChangeHandler(new LoadingStateChangeEvent.Handler() { @Override/*from www . ja v a 2 s . c om*/ public void onLoadingStateChanged(LoadingStateChangeEvent event) { onLoadingChange(event.getLoadingState()); } }); widgetAboveList.addKeyDownHandler(new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent event) { switch (event.getNativeKeyCode()) { case KeyCodes.KEY_DOWN: case KeyCodes.KEY_J: setCurrentRow(0); event.preventDefault(); break; } } }); }
From source file:org.glom.web.client.ui.list.ListTable.java
License:Open Source License
protected void createCellTable(final LayoutGroup layoutGroup, final String tableName, final int numVisibleRows, final String navigationButtonLabel, final NavigationButtonCell navigationButtonCell) { this.tableName = tableName; final List<LayoutItem> layoutItems = layoutGroup.getItems(); ProvidesKey<DataItem[]> keyProvider = null; final int primaryKeyIndex = layoutGroup.getPrimaryKeyIndex(); if ((primaryKeyIndex < 0) || (primaryKeyIndex >= layoutItems.size())) { GWT.log("createCellTable(): primaryKeyIndex is out of range: " + primaryKeyIndex); } else {//from ww w . j a v a 2 s. com final LayoutItem primaryKeyItem = layoutItems.get(primaryKeyIndex); if (!(primaryKeyItem instanceof LayoutItemField)) { GWT.log("createCellTable(): primaryKeyItem is not a LayoutItemField."); } else { final LayoutItemField primaryKeyLayoutItem = (LayoutItemField) primaryKeyItem; final GlomFieldType primaryKeyFieldType = primaryKeyLayoutItem.getGlomType(); keyProvider = new ProvidesKey<DataItem[]>() { @Override public Object getKey(final DataItem[] row) { if (row.length == 1 && row[0] == null) { // an empty row return null; } if ((primaryKeyIndex < 0) || (primaryKeyIndex >= row.length)) { GWT.log("createCellTable() keyProvider.getKey(): primaryKeyIndex is out of range: " + primaryKeyIndex + ", row.length=" + row.length); return null; } return Utils.getTypedDataItem(primaryKeyFieldType, row[primaryKeyIndex]); } }; } } // create the CellTable with the requested number of rows and the key provider cellTable = new CellTable<DataItem[]>(numVisibleRows, keyProvider); // set some style cellTable.setStyleName("data-list"); cellTable.getElement().getStyle().setProperty("whiteSpace", "nowrap"); // this prevents the header and row text // from wrapping // add columns to the CellTable and deal with the case of the hidden primary key final int numItems = layoutGroup.hasHiddenPrimaryKey() ? layoutItems.size() - 1 : layoutItems.size(); for (int i = 0; i < numItems; i++) { final LayoutItem layoutItem = layoutItems.get(i); // only add columns for LayoutItemField types if (layoutItem instanceof LayoutItemField) { addColumn((LayoutItemField) layoutItem); } else { GWT.log("createCellTable(): Ignoring non-LayoutItemField layout item."); } } // add the navigation buttons as the last column addNavigationButtonColumn(navigationButtonLabel, navigationButtonCell); // create and set the data provider final AbstractDataProvider<DataItem[]> dataProvider = getDataProvider(); dataProvider.addDataDisplay(cellTable); // add an AsyncHandler to activate sorting for the data provider cellTable.addColumnSortHandler(new AsyncHandler(cellTable)); // pack the widgets into the container pager.setDisplay(cellTable); mainPanel.add(cellTable); mainPanel.add(pager); /* * Update the height of the loading indicator widget to match the body of the CellTable so that the pager widget * doesn't bounce up and down while paging. This code also ensures that loading indicator GIF is in the centre * of the table. * * TODO: Make this work with related lists in Notebooks. These related list tables will have the original bouncy * behaviour because CellTable.getBodyHeight() of a related list table in an unselected notebook tab returns 0. * * TODO: Fix the bounce when paging to the first or last page that doesn't fall on a natural page boundary. This * happens in the first and last page when dataSize % pageSize != 0. */ cellTable.addLoadingStateChangeHandler(new LoadingStateChangeEvent.Handler() { @Override public void onLoadingStateChanged(final LoadingStateChangeEvent event) { // LoadingState.LOADED means the data has been received but not necessarily rendered. if (event.getLoadingState() == LoadingState.LOADED) { new Timer() { @Override public void run() { if (cellTable.isAttached()) { final int bodyHeight = cellTable.getBodyHeight(); /* * Modify the indicator widget only if body height is bigger than the body height that * has already been set. This is just a safety check for the case where the timer isn't * long enough and the body height is calculated to be smaller than its full size. In * practice this is not expected to happen. * * Since cellTableBodyHeight is initialised to 0, the indicator widget will not be * modified when the body height cannot be calculated (e.g. when a related list table is * in an unselected notebook tab). */ if (bodyHeight > cellTableBodyHeight) { final Widget loadingIndicator = cellTable.getLoadingIndicator(); // Set the margin of the parent div to zero. final Element parent = loadingIndicator.getElement().getParentElement(); parent.getStyle().setMargin(0, Unit.PX); // Set the height of the table cell that holds the loading indicator GIF. final Element cell = parent.getParentElement().getParentElement() .getParentElement(); cell.getStyle().setPadding(0, Unit.PX); cell.getStyle().setHeight(bodyHeight, Unit.PX); // save the new body height cellTableBodyHeight = bodyHeight; } } } }.schedule(200); // 200 ms should be enough } } }); // initialize composite widget initWidget(mainPanel); }