Revision: 7964
Author: [email protected]
Date: Thu Apr 22 06:58:10 2010
Log: Reorganizes styles in bikeshed to use CssResource and ClientBundle.
Moves all styles in stock and cookbook samples to one place.
Removes the "hovering boxes" we stole from Wave for a slightly flatter look.
Review at http://gwt-code-reviews.appspot.com/388801
http://code.google.com/p/google-web-toolkit/source/detail?r=7964
Added:
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/style
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/style/Style.gwt.xml
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/style/client
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/style/client/Styles.java
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/style/client/common.css
Deleted:
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/common.css
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/common.css
/trunk/bikeshed/war/Cookbook.css
/trunk/bikeshed/war/Stocks.css
Modified:
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/PagingTableListView.java
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/Cookbook.gwt.xml
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/Cookbook.java
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/Cookbook.ui.xml
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/MailRecipe.java
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/Recipe.java
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/ValidationRecipe.java
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/StocksCommon.gwt.xml
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/FavoritesWidget.ui.xml
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/PlayerScoresWidget.ui.xml
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/StockQueryWidget.ui.xml
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/StocksDesktop.ui.xml
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/StocksMobile.ui.xml
/trunk/bikeshed/war/Cookbook.html
/trunk/bikeshed/war/Stocks.html
/trunk/bikeshed/war/StocksMobile.html
=======================================
--- /dev/null
+++ /trunk/bikeshed/src/com/google/gwt/sample/bikeshed/style/Style.gwt.xml
Thu Apr 22 06:58:10 2010
@@ -0,0 +1,4 @@
+<module>
+ <inherits name="com.google.gwt.resources.Resources"/>
+ <source path='client'/>
+</module>
=======================================
--- /dev/null
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/style/client/Styles.java
Thu Apr 22 06:58:10 2010
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.sample.bikeshed.style.client;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.resources.client.ClientBundle;
+import com.google.gwt.resources.client.CssResource;
+import com.google.gwt.resources.client.CssResource.NotStrict;
+
+public class Styles {
+
+ public interface Common extends CssResource {
+ String box();
+ String header();
+ String headerLeft();
+ String headerMain();
+ String padded();
+ String table();
+ }
+
+ public interface Resources extends ClientBundle {
+ @NotStrict
+ @Source("common.css")
+ Common common();
+ }
+
+ private static Resources resources;
+
+ static {
+ resources = GWT.create(Resources.class);
+ resources.common().ensureInjected();
+ }
+
+ public static Common common() {
+ return resources.common();
+ }
+}
=======================================
--- /dev/null
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/style/client/common.css
Thu Apr 22 06:58:10 2010
@@ -0,0 +1,197 @@
+/* global */
+body {
+ background-color: #eee;
+ color: black;
+ margin: 8px;
+ margin-top: 3px;
+}
+
+body, table {
+ font-family: Arial, sans-serif;
+ font-weight: light;
+ font-size: 12px;
+}
+
+/* odds and ends */
+.box {
+ border: 1px solid #ccc;
+ background-color: white;
+ margin: 0.25em;
+ padding: 0.5em;
+ -webkit-border-radius: 4px;
+ -moz-border-radius: 4px;
+}
+
+.padded {
+ padding: 5px;
+}
+
+.header {
+ font-weight: bold;
+ font-size: 12pt;
+ margin: 0.5em;
+}
+
+.headerLeft {
+ font-weight: light;
+ font-size: 12pt;
+ margin-bottom: 0.5em;
+}
+
+.headerMain {
+ font-weight: light;
+ font-size: 18pt;
+}
+
+/* tables */
+.table {
+ width: 100%;
+ font-size: 8pt;
+ border-spacing: 0px 0px;
+ border-collapse: collapse;
+}
+
+.table th {
+ border-bottom: 1px solid #ccc;
+}
+
+.table td {
+ border-bottom: 1px solid #ccc;
+}
+
+.table tfoot th {
+ border-width: 0px;
+}
+
+.table tr.hover {
+ background-color: lightblue;
+}
+
+.table tr.selected {
+ background-color: rgb(56, 117, 215);
+}
+
+/* ss tree */
+.gwt-sstree {
+}
+
+.gwt-sstree-column {
+ overflow-y: scroll;
+ overflow-x: auto;
+ position: relative;
+}
+
+.gwt-sstree-selectedItem {
+ background-color: rgb(56, 117, 215);
+}
+
+.gwt-sstree-evenRow {
+ background-color: rgb(255, 255, 255);
+}
+
+.gwt-sstree-oddRow {
+ background-color: rgb(220, 220, 220);
+}
+
+/* date picker */
+.gwt-DatePicker {
+ border: 1px solid #A2BBDD;
+ cursor: default;
+}
+.gwt-DatePicker td,
+.datePickerMonthSelector td:focus {
+ outline: none
+}
+.datePickerDays {
+ width: 100%;
+ background: white;
+}
+.datePickerDay,
+.datePickerWeekdayLabel,
+.datePickerWeekendLabel {
+ font-size: 75%;
+ text-align: center;
+ padding: 4px;
+ outline: none;
+}
+.datePickerWeekdayLabel,
+.datePickerWeekendLabel {
+ background: #C3D9FF;
+ padding: 0px 4px 2px;
+ cursor: default;
+}
+.datePickerDay {
+ padding: 4px;
+ cursor: hand;
+ cursor: pointer;
+}
+.datePickerDayIsToday {
+ border: 1px solid black;
+ padding: 3px;
+}
+.datePickerDayIsWeekend {
+ background: #EEEEEE;
+}
+.datePickerDayIsFiller {
+ color: #888888;
+}
+.datePickerDayIsValue {
+ background: #aaccee;
+}
+.datePickerDayIsDisabled {
+ color: #AAAAAA;
+ font-style: italic;
+}
+.datePickerDayIsHighlighted {
+ background: #F0E68C;
+}
+.datePickerDayIsValueAndHighlighted {
+ background: #bbddd9;
+}
+.datePickerMonthSelector {
+ background: #C3D9FF;
+ width: 100%;
+}
+td.datePickerMonth {
+ text-align: center;
+ vertical-align: center;
+ white-space: nowrap;
+ font-size: 70%;
+ font-weight: bold;
+ color: blue;
+}
+.datePickerPreviousButton,
+.datePickerNextButton {
+ font-size: 120%;
+ line-height: 1em;
+ color: blue;
+ cursor: hand;
+ cursor: pointer;
+ padding: 0px 4px;
+}
+
+/* dialog box */
+.gwt-DialogBox {
+ border: 8px solid white;
+ border-right: 11px solid white;
+ border-bottom: 11px solid white;
+ -webkit-border-image: url(blueborder.png) 8 11 11 8 round round;
+ -moz-border-image: url(blueborder.png) 8 11 11 8 round round;
+}
+
+.gwt-DialogBox .Caption {
+ font-weight: light;
+ font-size: 12pt;
+ text-align: center;
+ margin-bottom: 0.5em;
+ border-bottom: 1px solid #ccc;
+}
+
+/* splitters */
+.gwt-SplitLayoutPanel-HDragger {
+ background: transparent url(hsplitter-grip.png) center center no-repeat;
+}
+
+.gwt-SplitLayoutPanel-VDragger {
+ background: transparent url(vsplitter-grip.png) center center no-repeat;
+}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/common.css
Fri Apr 9 04:13:29 2010
+++ /dev/null
@@ -1,49 +0,0 @@
-.bg {
- border: 8px solid white;
- border-right: 12px solid white;
- border-bottom: 14px solid white;
- -webkit-border-image: url(border.png) 8 12 14 8 round round;
- -moz-border-image: url(border.png) 8 12 14 8 round round;
-}
-
-.header {
- font-weight: light;
- font-size: 12pt;
- text-align: center;
- margin-bottom: 0.5em;
-}
-
-.header-left {
- font-weight: light;
- font-size: 12pt;
- margin-bottom: 0.5em;
-}
-
-.header-main {
- font-weight: light;
- font-size: 18pt;
-}
-
-.table {
- width: 95%;
- font-size: 8pt;
- border-spacing: 0px 0px;
- border-collapse: collapse;
-}
-
-.table th {
- border-bottom: 1px solid #ccc;
-}
-
-.table td {
- border-left: 1px solid #ccc;
- border-right: 1px solid #ccc;
-}
-
-.table tfoot th {
- border-width: 0px;
-}
-
-.padded {
- padding: 5px;
-}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/common.css
Tue Mar 23 06:01:07 2010
+++ /dev/null
@@ -1,51 +0,0 @@
-/* text-overflow: ellipsis; */
-
-.bg {
- border: 8px solid white;
- border-right: 12px solid white;
- border-bottom: 14px solid white;
- -webkit-border-image: url(border.png) 8 12 14 8 round round;
- -moz-border-image: url(border.png) 8 12 14 8 round round;
-}
-
-.header {
- font-weight: light;
- font-size: 12pt;
- text-align: center;
- margin-bottom: 0.5em;
-}
-
-.header-left {
- font-weight: light;
- font-size: 12pt;
- margin-bottom: 0.5em;
-}
-
-.header-main {
- font-weight: light;
- font-size: 18pt;
-}
-
-.table {
- width: 95%;
- font-size: 8pt;
- border-spacing: 0px 0px;
- border-collapse: collapse;
-}
-
-.table th {
- border-bottom: 1px solid #ccc;
-}
-
-.table td {
- border-left: 1px solid #ccc;
- border-right: 1px solid #ccc;
-}
-
-.table tfoot th {
- border-width: 0px;
-}
-
-.padded {
- padding: 5px;
-}
=======================================
--- /trunk/bikeshed/war/Cookbook.css Mon Apr 19 04:48:30 2010
+++ /dev/null
@@ -1,191 +0,0 @@
-body {
- background: url(bg.png) repeat-x;
- background-color: rgb(216, 220, 224);
- color: black;
- margin: 8px;
- margin-top: 3px;
-}
-
-body, table {
- font-family: Helvetica Neue Light, Helvetica, Arial, sans-serif; */
- font-weight: light;
- font-size: small;
-}
-
-tr.selected {
- background-color: rgb(56, 117, 215);
-}
-
-tr.evenRow {
- background-color: rgb(255, 255, 255);
-}
-
-tr.oddRow {
- background-color: rgb(220, 220, 220);
-}
-
-tr.hover {
- background-color: rgb(255, 0, 0);
-}
-
-div.gwt-sstree-column {
- overflow-y: scroll;
- overflow-x: auto;
- position: relative;
-}
-
-div.gwt-sstree {
-}
-
-div.gwt-sstree-selectedItem {
- background-color: rgb(56, 117, 215);
-}
-
-div.gwt-sstree-evenRow {
- background-color: rgb(255, 255, 255);
-}
-
-div.gwt-sstree-oddRow {
- background-color: rgb(220, 220, 220);
-}
-
-/** Example rules used by the template application (remove for your app) */
-h1 {
- font-size: 2em;
- font-weight: bold;
- color: #777777;
- margin: 40px 0px 70px;
- text-align: center;
-}
-
-.sendButton {
- display: block;
- font-size: 16pt;
-}
-
-/** Most GWT widgets already have a style name defined */
-.gwt-DialogBox {
- width: 400px;
-}
-
-.dialogVPanel {
- margin: 5px;
-}
-
-.serverResponseLabelError {
- color: red;
-}
-
-.playerScoreBox {
- border: 1px solid #777;
- padding:3px;
- background: #eee;
- margin-bottom: 5px;
-}
-
-/** Set ids using widget.getElement().setId("idOfElement") */
-#closeButton {
- margin: 15px 6px 6px;
-}
-
-.gwt-DialogBox {
- border: 8px solid white;
- border-right: 11px solid white;
- border-bottom: 11px solid white;
- -webkit-border-image: url(blueborder.png) 8 11 11 8 round round;
- -moz-border-image: url(blueborder.png) 8 11 11 8 round round;
-}
-
-.gwt-DialogBox .Caption {
- font-weight: light;
- font-size: 12pt;
- text-align: center;
- margin-bottom: 0.5em;
- border-bottom: 1px solid #ccc;
-}
-
-.gwt-SplitLayoutPanel-HDragger {
- background: transparent url(hsplitter-grip.png) center center no-repeat;
-}
-
-.gwt-SplitLayoutPanel-VDragger {
- background: transparent url(vsplitter-grip.png) center center no-repeat;
-}
-
-/* Date picker */
-
-.gwt-DatePicker {
- border: 1px solid #A2BBDD;
- cursor: default;
-}
-.gwt-DatePicker td,
-.datePickerMonthSelector td:focus {
- outline: none
-}
-.datePickerDays {
- width: 100%;
- background: white;
-}
-.datePickerDay,
-.datePickerWeekdayLabel,
-.datePickerWeekendLabel {
- font-size: 75%;
- text-align: center;
- padding: 4px;
- outline: none;
-}
-.datePickerWeekdayLabel,
-.datePickerWeekendLabel {
- background: #C3D9FF;
- padding: 0px 4px 2px;
- cursor: default;
-}
-.datePickerDay {
- padding: 4px;
- cursor: hand;
- cursor: pointer;
-}
-.datePickerDayIsToday {
- border: 1px solid black;
- padding: 3px;
-}
-.datePickerDayIsWeekend {
- background: #EEEEEE;
-}
-.datePickerDayIsFiller {
- color: #888888;
-}
-.datePickerDayIsValue {
- background: #aaccee;
-}
-.datePickerDayIsDisabled {
- color: #AAAAAA;
- font-style: italic;
-}
-.datePickerDayIsHighlighted {
- background: #F0E68C;
-}
-.datePickerDayIsValueAndHighlighted {
- background: #bbddd9;
-}
-.datePickerMonthSelector {
- background: #C3D9FF;
- width: 100%;
-}
-td.datePickerMonth {
- text-align: center;
- vertical-align: center;
- white-space: nowrap;
- font-size: 70%;
- font-weight: bold;
- color: blue;
-}
-.datePickerPreviousButton,
-.datePickerNextButton {
- font-size: 120%;
- line-height: 1em;
- color: blue;
- cursor: hand;
- cursor: pointer;
- padding: 0px 4px;
-}
=======================================
--- /trunk/bikeshed/war/Stocks.css Fri Mar 12 07:16:19 2010
+++ /dev/null
@@ -1,97 +0,0 @@
-body {
- background: url(bg.png) repeat-x;
- background-color: rgb(216, 220, 224);
- color: black;
- margin: 8px;
- margin-top: 3px;
-}
-
-body, table {
- font-family: Helvetica Neue Light, Helvetica, Arial, sans-serif; */
- font-weight: light;
- font-size: small;
-}
-
-div.gwt-sstree-column {
- overflow-y: scroll;
- overflow-x: auto;
- position: relative;
-}
-
-div.gwt-sstree {
-}
-
-div.gwt-sstree-selectedItem {
- background-color: rgb(56, 117, 215);
-}
-
-div.gwt-sstree-evenRow {
- background-color: rgb(255, 255, 255);
-}
-
-div.gwt-sstree-oddRow {
- background-color: rgb(220, 220, 220);
-}
-
-/** Example rules used by the template application (remove for your app) */
-h1 {
- font-size: 2em;
- font-weight: bold;
- color: #777777;
- margin: 40px 0px 70px;
- text-align: center;
-}
-
-.sendButton {
- display: block;
- font-size: 16pt;
-}
-
-/** Most GWT widgets already have a style name defined */
-.gwt-DialogBox {
- width: 400px;
-}
-
-.dialogVPanel {
- margin: 5px;
-}
-
-.serverResponseLabelError {
- color: red;
-}
-
-.playerScoreBox {
- border: 1px solid #777;
- padding:3px;
- background: #eee;
- margin-bottom: 5px;
-}
-
-/** Set ids using widget.getElement().setId("idOfElement") */
-#closeButton {
- margin: 15px 6px 6px;
-}
-
-.gwt-DialogBox {
- border: 8px solid white;
- border-right: 11px solid white;
- border-bottom: 11px solid white;
- -webkit-border-image: url(blueborder.png) 8 11 11 8 round round;
- -moz-border-image: url(blueborder.png) 8 11 11 8 round round;
-}
-
-.gwt-DialogBox .Caption {
- font-weight: light;
- font-size: 12pt;
- text-align: center;
- margin-bottom: 0.5em;
- border-bottom: 1px solid #ccc;
-}
-
-.gwt-SplitLayoutPanel-HDragger {
- background: transparent url(hsplitter-grip.png) center center no-repeat;
-}
-
-.gwt-SplitLayoutPanel-VDragger {
- background: transparent url(vsplitter-grip.png) center center no-repeat;
-}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/PagingTableListView.java
Tue Apr 20 16:34:24 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/PagingTableListView.java
Thu Apr 22 06:58:10 2010
@@ -52,7 +52,8 @@
}
}
- protected int curPage;
+ private static final int DEFAULT_SIZE = 10;
+
private List<Column<T, ?, ?>> columns = new ArrayList<Column<T, ?, ?>>();
private ArrayList<Boolean> dataSelected = new ArrayList<Boolean>();
private ArrayList<T> dataValues = new ArrayList<T>();
@@ -60,8 +61,8 @@
private List<Header<?>> footers = new ArrayList<Header<?>>();
private List<Header<?>> headers = new ArrayList<Header<?>>();
private TableRowElement hoveringRow;
- private int numPages;
- private int pageSize;
+ private int pageSize = -1;
+ private int pageStart = 0;
/**
* If null, each T will be used as its own key.
@@ -74,20 +75,28 @@
private TableSectionElement tbody;
private TableSectionElement tfoot;
private TableSectionElement thead;
- private int totalSize;
+ private int size = 0;
/**
- * Constructs a table with the given page size.
-
+ * Constructs a table with a default page size of 10.
+ */
+ public PagingTableListView() {
+ this(DEFAULT_SIZE);
+ }
+
+ /**
+ * Constructs a table with the given page size.
+ *
* @param pageSize the page size
*/
public PagingTableListView(final int pageSize) {
- this.pageSize = pageSize;
setElement(table = Document.get().createTableElement());
+ table.setCellSpacing(0);
thead = table.createTHead();
table.appendChild(tbody = Document.get().createTBodyElement());
tfoot = table.createTFoot();
- createRows();
+
+ setPageSize(pageSize);
// TODO: Total hack. It would almost definitely be preferable to sink
only
// those events actually needed by cells.
@@ -118,7 +127,8 @@
createHeadersAndFooters(); // TODO: defer header recreation
columns.add(col);
createRows();
- setPage(curPage); // TODO: better way to refresh?
+
+ refresh();
}
/**
@@ -127,10 +137,25 @@
public void addColumn(Column<T, ?, ?> col, String headerString) {
addColumn(col, new TextHeader(headerString), null);
}
+
+ /**
+ * Returns true if it there is enough data to allow a given number of
+ * additional rows to be displayed.
+ */
+ public boolean canAddRows(int rows) {
+ return size - pageSize >= rows;
+ }
+
+ /**
+ * Returns true if the page size is sufficient to allow a given number
of rows
+ * to be removed.
+ */
+ public boolean canRemoveRows(int rows) {
+ return pageSize > rows;
+ }
// TODO: remove(Column)
- // TODO - bounds check
public T getDisplayedItem(int indexOnPage) {
if (indexOnPage < 0 || indexOnPage >= getNumDisplayedItems()) {
throw new IndexOutOfBoundsException("indexOnPage = " + indexOnPage);
@@ -143,32 +168,52 @@
}
public int getNumDisplayedItems() {
- return Math.min(getPageSize(), totalSize - curPage * pageSize);
- }
-
- /**
- * Get the current page.
- *
- * @return the current page
- */
- public int getPage() {
- return curPage;
+ return Math.min(getPageSize(), size - pageStart);
}
public int getPageSize() {
return pageSize;
}
+
+ public int getPageStart() {
+ return pageStart;
+ }
public ProvidesKey<T> getProvidesKey() {
return providesKey;
}
public Range getRange() {
- return new DefaultRange(curPage * pageSize, pageSize);
+ return new DefaultRange(pageStart, pageSize);
}
+ public int getSize() {
+ return size;
+ }
+
+ /**
+ * Returns true if there is enough data such that a call to
+ * {...@link #nextPage()} will succeed in moving the starting point of the
table
+ * forward.
+ */
+ public boolean hasNextPage() {
+ return pageStart + pageSize < size;
+ }
+
+ /**
+ * Returns true if there is enough data such that a call to
+ * {...@link #previousPage()} will succeed in moving the starting point of
the
+ * table backward.
+ */
+ public boolean hasPreviousPage() {
+ return pageStart > 0 && size > 0;
+ }
+
+ /**
+ * Advance the starting row by {...@link #getPageSize()} rows.
+ */
public void nextPage() {
- setPage(curPage + 1);
+ setPageStart(Math.min(getSize() - 1, getPageStart() + getPageSize()));
}
@Override
@@ -210,15 +255,20 @@
T value = dataValues.get(row);
Column<T, ?, ?> column = columns.get(col);
- column.onBrowserEvent(cell, curPage * pageSize + row, value, event,
- providesKey);
+ column.onBrowserEvent(cell, pageStart + row, value, event,
providesKey);
}
}
+ /**
+ * Move the starting row back by {...@link #getPageSize()} rows.
+ */
public void previousPage() {
- setPage(curPage - 1);
+ setPageStart(Math.max(0, getPageStart() - getPageSize()));
}
+ /**
+ * Redraw the table, requesting data from the delegate.
+ */
public void refresh() {
if (delegate != null) {
delegate.onRangeChanged(this);
@@ -226,6 +276,10 @@
updateRowVisibility();
}
+ /**
+ * Refresh those portions of the table that depend on the state of the
+ * {...@link SelectionModel}.
+ */
public void refreshSelection() {
// Refresh headers
Element th = thead.getFirstChild().getFirstChild().cast();
@@ -276,17 +330,39 @@
}
public void setData(int start, int length, List<T> values) {
- render(start, length, values);
+ int numCols = columns.size();
+
+ NodeList<TableRowElement> rows = tbody.getRows();
+ for (int r = start; r < start + length; ++r) {
+ int indexOnPage = r - pageStart;
+ TableRowElement row = rows.getItem(indexOnPage);
+ T q = values.get(r - start);
+ if (selectionModel != null && selectionModel.isSelected(q)) {
+ row.setClassName("pagingTableListView selected");
+ } else {
+ row.setClassName("pagingTableListView "
+ + ((indexOnPage & 0x1) == 0 ? "evenRow" : "oddRow"));
+ }
+
+ dataValues.set(indexOnPage, q);
+ for (int c = 0; c < numCols; ++c) {
+ TableCellElement cell = row.getCells().getItem(c);
+ StringBuilder sb = new StringBuilder();
+ columns.get(c).render(q, sb);
+ cell.setInnerHTML(sb.toString());
+
+ // TODO: Really total hack! There's gotta be a better way...
+ Element child = cell.getFirstChildElement();
+ if (child != null) {
+ Event.sinkEvents(child, Event.ONFOCUS | Event.ONBLUR);
+ }
+ }
+ }
}
public void setDataSize(int size, boolean isExact) {
- totalSize = size;
- if (totalSize <= 0) {
- numPages = 0;
- } else {
- numPages = 1 + (totalSize - 1) / pageSize;
- }
- setPage(curPage);
+ this.size = size;
+ refresh();
}
public void setDelegate(Delegate<T> delegate) {
@@ -294,40 +370,41 @@
}
/**
- * Set the current visible page.
+ * Set the number of rows per page and refresh the table.
*
- * @param page the page index
+ * @param pageSize the page size
+ *
+ * @throw {...@link IllegalArgumentException} if pageSize is negative or 0
*/
- public void setPage(int page) {
- int newPage = Math.min(page, numPages - 1);
- newPage = Math.max(0, newPage);
-
- // Update the text showing the page number.
- updatePageText(newPage);
-
- // Early exit if we are already on the right page.
- if (curPage != newPage) {
- curPage = newPage;
- if (delegate != null) {
- delegate.onRangeChanged(this);
- }
+ public void setPageSize(int pageSize) {
+ if (pageSize <= 0) {
+ throw new IllegalArgumentException("pageSize = " + pageSize);
+ }
+ if (this.pageSize == pageSize) {
+ return;
+ }
+ this.pageSize = pageSize;
+
+ // If on last page and page size increases, move the page start upwards
+ if (pageStart + pageSize > size) {
+ pageStart = Math.max(0, size - pageSize);
}
- updateRowVisibility();
+ // TODO - avoid requesting data if the page size has decreased
+ createRows();
+ refresh();
}
/**
- * Set the number of rows per page.
+ * Set the starting index of the current visible page. The actual page
+ * start will be clamped in the range [0, getSize() - 1].
*
- * @param pageSize the page size
+ * @param pageStart the index of the row that should appear at the start
of
+ * the page
*/
- public void setPageSize(int pageSize) {
- if (this.pageSize == pageSize) {
- return;
- }
- this.pageSize = pageSize;
- curPage = -1;
- setPage(curPage);
+ public void setPageStart(int pageStart) {
+ this.pageStart = Math.max(Math.min(pageStart, size - 1), 0);
+ refresh();
}
/**
@@ -337,10 +414,14 @@
* @param providesKey an instance of {...@link ProvidesKey<T>} used to
generate
* keys for record objects.
*/
+ // TODO - when is this valid? Do we rehash column view data if it
changes?
public void setProvidesKey(ProvidesKey<T> providesKey) {
this.providesKey = providesKey;
}
+ /**
+ * Sets the selection model.
+ */
public void setSelectionModel(SelectionModel<T> selectionModel) {
if (selectionHandler != null) {
selectionHandler.removeHandler();
@@ -350,6 +431,8 @@
if (selectionModel != null && isAttached()) {
selectionHandler = selectionModel.addSelectionChangeHandler(new
TableSelectionHandler());
}
+
+ refreshSelection();
}
@Override
@@ -368,38 +451,6 @@
selectionHandler = null;
}
}
-
- protected void render(int start, int length, List<T> values) {
- int numCols = columns.size();
- int pageStart = curPage * pageSize;
-
- NodeList<TableRowElement> rows = tbody.getRows();
- for (int r = start; r < start + length; ++r) {
- int indexOnPage = r - pageStart;
- TableRowElement row = rows.getItem(indexOnPage);
- T q = values.get(r - start);
- if (selectionModel != null && selectionModel.isSelected(q)) {
- row.setClassName("pagingTableListView selected");
- } else {
- row.setClassName("pagingTableListView "
- + ((indexOnPage & 0x1) == 0 ? "evenRow" : "oddRow"));
- }
-
- dataValues.set(indexOnPage, q);
- for (int c = 0; c < numCols; ++c) {
- TableCellElement cell = row.getCells().getItem(c);
- StringBuilder sb = new StringBuilder();
- columns.get(c).render(q, sb);
- cell.setInnerHTML(sb.toString());
-
- // TODO: Really total hack! There's gotta be a better way...
- Element child = cell.getFirstChildElement();
- if (child != null) {
- Event.sinkEvents(child, Event.ONFOCUS | Event.ONBLUR);
- }
- }
- }
- }
private void createHeaders(List<Header<?>> headers,
TableSectionElement section) {
@@ -467,18 +518,9 @@
}
return null;
}
-
- /**
- * Update the text that shows the current page.
- *
- * @param page the current page
- */
- private void updatePageText(int page) {
- // TODO: Update external paging widget.
- }
private void updateRowVisibility() {
- int visible = Math.min(pageSize, totalSize - curPage * pageSize);
+ int visible = Math.min(pageSize, size - pageStart);
for (int r = 0; r < pageSize; ++r) {
Style rowStyle = tbody.getRows().getItem(r).getStyle();
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/Cookbook.gwt.xml
Fri Apr 9 04:13:29 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/Cookbook.gwt.xml
Thu Apr 22 06:58:10 2010
@@ -1,5 +1,6 @@
<module rename-to='cookbook'>
<inherits name='com.google.gwt.user.User'/>
+ <inherits name='com.google.gwt.sample.bikeshed.style.Style'/>
<inherits name='com.google.gwt.bikeshed.list.List'/>
<inherits name='com.google.gwt.bikeshed.tree.Tree'/>
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/Cookbook.java
Wed Apr 14 09:41:18 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/Cookbook.java
Thu Apr 22 06:58:10 2010
@@ -28,6 +28,7 @@
import com.google.gwt.uibinder.client.UiFactory;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.DockLayoutPanel;
+import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.Widget;
@@ -86,6 +87,7 @@
@UiField DockLayoutPanel dock;
@UiField StandardTreeView recipeTree;
+ @UiField LayoutPanel container;
private RecipeTreeModel recipeTreeModel = new RecipeTreeModel();
private SingleSelectionModel<Object> treeSelection;
@@ -137,9 +139,9 @@
private void showRecipe(Recipe recipe) {
if (curRecipe != null) {
- dock.remove(curRecipe.getWidget());
- }
- dock.add(recipe.getWidget());
+ container.remove(curRecipe.getWidget());
+ }
+ container.add(recipe.getWidget());
curRecipe = recipe;
}
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/Cookbook.ui.xml
Fri Apr 9 04:13:29 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/Cookbook.ui.xml
Thu Apr 22 06:58:10 2010
@@ -3,14 +3,18 @@
xmlns:l='urn:import:com.google.gwt.bikeshed.list.client'
xmlns:t='urn:import:com.google.gwt.bikeshed.tree.client'>
- <ui:style field='common' src='common.css' />
+ <ui:with field='styles'
+ type='com.google.gwt.sample.bikeshed.style.client.Styles'/>
<g:DockLayoutPanel unit='EM' ui:field='dock'>
- <g:north size="2">
- <g:HTML>Table Sample</g:HTML>
+ <g:north size="3.5">
+ <g:HTML styleName='{styles.common.header}'>Google Web Toolkit
Cookbook</g:HTML>
</g:north>
<g:west size="16">
- <t:StandardTreeView ui:field='recipeTree'/>
+ <t:StandardTreeView styleName='{styles.common.box}'
ui:field='recipeTree'/>
</g:west>
+ <g:center>
+ <g:LayoutPanel styleName='{styles.common.box}'
ui:field='container'/>
+ </g:center>
</g:DockLayoutPanel>
</ui:UiBinder>
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/MailRecipe.java
Wed Apr 21 09:07:02 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/MailRecipe.java
Thu Apr 22 06:58:10 2010
@@ -34,6 +34,7 @@
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
+import com.google.gwt.sample.bikeshed.style.client.Styles;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlowPanel;
@@ -341,6 +342,7 @@
sortMessages(idComparator, true);
table = new PagingTableListView<Message>(10);
+ table.setStyleName(Styles.common().table());
table.setSelectionModel(selectionModel);
adapter.addView(table);
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/Recipe.java
Fri Apr 9 11:12:18 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/Recipe.java
Thu Apr 22 06:58:10 2010
@@ -15,6 +15,7 @@
*/
package com.google.gwt.sample.bikeshed.cookbook.client;
+import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.ui.Widget;
/**
@@ -35,7 +36,12 @@
public final Widget getWidget() {
if (widget == null) {
widget = createWidget();
- }
+
+ // Minor style hack: we need to give a little margin to all recipes,
+ // so we just do it here instead of on all the individual recipes.
+ widget.getElement().getStyle().setMargin(0.5, Unit.EM);
+ }
+
return widget;
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/ValidationRecipe.java
Tue Apr 20 16:34:24 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/ValidationRecipe.java
Thu Apr 22 06:58:10 2010
@@ -116,7 +116,12 @@
public void run() {
String pendingValue = viewData.getValue();
- int zip = Integer.parseInt(pendingValue);
+ int zip;
+ try {
+ zip = Integer.parseInt(pendingValue);
+ } catch (NumberFormatException e) {
+ zip = -1;
+ }
boolean zipInvalid = ValidationRecipe.zipInvalid(zip);
final Address newValue = new Address(object);
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/StocksCommon.gwt.xml
Fri Mar 26 06:15:07 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/StocksCommon.gwt.xml
Thu Apr 22 06:58:10 2010
@@ -2,6 +2,7 @@
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit
0.0.999//EN" "http://google-web-toolkit.googlecode.com/svn/tags/0.0.999/distro-source/core/src/gwt-module.dtd">
<module>
<inherits name='com.google.gwt.user.User'/>
+ <inherits name='com.google.gwt.sample.bikeshed.style.Style'/>
<inherits name='com.google.gwt.regexp.RegExp'/>
<inherits name='com.google.gwt.bikeshed.list.List'/>
<inherits name='com.google.gwt.bikeshed.tree.Tree'/>
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/FavoritesWidget.ui.xml
Tue Mar 23 06:01:07 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/FavoritesWidget.ui.xml
Thu Apr 22 06:58:10 2010
@@ -5,16 +5,17 @@
xmlns:t='urn:import:com.google.gwt.bikeshed.tree.client'
xmlns:s='urn:import:com.google.gwt.sample.bikeshed.stocks.client'>
- <ui:style field='common' src='common.css'/>
+ <ui:with field='styles'
+ type='com.google.gwt.sample.bikeshed.style.client.Styles'/>
<g:DockLayoutPanel unit='EM'>
<g:north size='2'>
- <g:Label styleName='{common.header-left}'>Portfolio /
Favorites</g:Label>
+ <g:Label styleName='{styles.common.headerLeft}'>Portfolio /
Favorites</g:Label>
</g:north>
<g:center>
<g:ScrollPanel>
- <l:PagingTableListView ui:field='listView'
styleName='{common.table}'/>
+ <l:PagingTableListView ui:field='listView'
styleName='{styles.common.table}'/>
</g:ScrollPanel>
</g:center>
</g:DockLayoutPanel>
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/PlayerScoresWidget.ui.xml
Tue Mar 23 06:01:07 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/PlayerScoresWidget.ui.xml
Thu Apr 22 06:58:10 2010
@@ -5,15 +5,16 @@
xmlns:t='urn:import:com.google.gwt.bikeshed.tree.client'
xmlns:s='urn:import:com.google.gwt.sample.bikeshed.stocks.client'>
- <ui:style field='common' src='common.css'/>
+ <ui:with field='styles'
+ type='com.google.gwt.sample.bikeshed.style.client.Styles'/>
<g:DockLayoutPanel unit='EM'>
<g:north size='2'>
- <g:Label styleName='{common.header}'>Player Status</g:Label>
+ <g:Label styleName='{styles.common.header}'>Player Status</g:Label>
</g:north>
<g:center>
- <g:ScrollPanel styleName="{common.padded}">
+ <g:ScrollPanel styleName="{styles.common.padded}">
<l:SimpleCellList ui:field='listView'/>
</g:ScrollPanel>
</g:center>
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/StockQueryWidget.ui.xml
Tue Mar 23 06:01:07 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/StockQueryWidget.ui.xml
Thu Apr 22 06:58:10 2010
@@ -5,19 +5,20 @@
xmlns:t='urn:import:com.google.gwt.bikeshed.tree.client'
xmlns:s='urn:import:com.google.gwt.sample.bikeshed.stocks.client'>
- <ui:style field='common' src='common.css'/>
+ <ui:with field='styles'
+ type='com.google.gwt.sample.bikeshed.style.client.Styles'/>
<g:DockLayoutPanel unit='EM'>
<g:north size='2'>
<g:HTMLPanel>
- <span class='{common.header-left}'>Enter query:</span>
+ <span class='{styles.common.headerLeft}'>Enter query:</span>
<g:TextBox ui:field='queryField'/>
</g:HTMLPanel>
</g:north>
<g:center>
<g:ScrollPanel>
- <l:PagingTableListView ui:field='listView'
styleName='{common.table}'/>
+ <l:PagingTableListView ui:field='listView'
styleName='{styles.common.table}'/>
</g:ScrollPanel>
</g:center>
</g:DockLayoutPanel>
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/StocksDesktop.ui.xml
Fri Apr 9 11:25:51 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/StocksDesktop.ui.xml
Thu Apr 22 06:58:10 2010
@@ -5,18 +5,19 @@
xmlns:t='urn:import:com.google.gwt.bikeshed.tree.client'
xmlns:s='urn:import:com.google.gwt.sample.bikeshed.stocks.client'>
- <ui:style field='common' src='common.css'/>
+ <ui:with field='styles'
+ type='com.google.gwt.sample.bikeshed.style.client.Styles'/>
<g:DockLayoutPanel unit='EM'>
<g:north size='4'>
- <g:HTML styleName='{common.bg} {common.header-main}'>Day
Trader</g:HTML>
+ <g:HTML styleName='{styles.common.headerMain}'>Day Trader</g:HTML>
</g:north>
<g:west size='16'>
<g:DockLayoutPanel unit='EM'>
<g:north size='12'>
- <g:HTMLPanel styleName='{common.bg}'>
- <div class='{common.header}'>Your Stats</div>
+ <g:HTMLPanel styleName='{styles.common.box}'>
+ <div class='{styles.common.header}'>Your Stats</div>
<table>
<tr><td>Available cash:</td><td><g:InlineLabel
ui:field='cashLabel'/></td></tr>
<tr><td>Net worth:</td><td><g:InlineLabel
ui:field='netWorthLabel'/></td></tr>
@@ -25,13 +26,13 @@
</g:north>
<g:center>
- <s:PlayerScoresWidget styleName='{common.bg}'
ui:field='playerScoresWidget'/>
+ <s:PlayerScoresWidget styleName='{styles.common.box}'
ui:field='playerScoresWidget'/>
</g:center>
</g:DockLayoutPanel>
</g:west>
<g:north size="18">
- <g:LayoutPanel styleName='{common.bg}'>
+ <g:LayoutPanel styleName='{styles.common.box}'>
<g:layer>
<t:SideBySideTreeView ui:field='transactionTree'/>
</g:layer>
@@ -41,11 +42,11 @@
<g:center>
<g:DockLayoutPanel unit='PCT'>
<g:west size="50">
- <s:StockQueryWidget styleName='{common.bg}'
ui:field='queryWidget'/>
+ <s:StockQueryWidget styleName='{styles.common.box}'
ui:field='queryWidget'/>
</g:west>
<g:center>
- <s:FavoritesWidget styleName='{common.bg}'
ui:field='favoritesWidget'/>
+ <s:FavoritesWidget styleName='{styles.common.box}'
ui:field='favoritesWidget'/>
</g:center>
</g:DockLayoutPanel>
</g:center>
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/StocksMobile.ui.xml
Fri Mar 26 06:15:07 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/StocksMobile.ui.xml
Thu Apr 22 06:58:10 2010
@@ -5,10 +5,11 @@
xmlns:t='urn:import:com.google.gwt.bikeshed.tree.client'
xmlns:s='urn:import:com.google.gwt.sample.bikeshed.stocks.client'>
- <ui:style field='common' src='common.css'/>
+ <ui:with field='styles'
+ type='com.google.gwt.sample.bikeshed.style.client.Styles'/>
<g:HTMLPanel>
- <div styleName='{common.header-left}'>Portfolio / Favorites</div>
- <l:PagingTableListView ui:field='listView' styleName='{common.table}'/>
+ <div styleName='{styles.common.headerLeft}'>Portfolio / Favorites</div>
+ <l:PagingTableListView ui:field='listView'
styleName='{styles.common.table}'/>
</g:HTMLPanel>
</ui:UiBinder>
=======================================
--- /trunk/bikeshed/war/Cookbook.html Fri Apr 9 04:13:29 2010
+++ /trunk/bikeshed/war/Cookbook.html Thu Apr 22 06:58:10 2010
@@ -2,7 +2,6 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <link type="text/css" rel="stylesheet" href="Cookbook.css">
<title>Cookbook</title>
<script type="text/javascript" language="javascript"
src="cookbook/cookbook.nocache.js"></script>
</head>
=======================================
--- /trunk/bikeshed/war/Stocks.html Fri Mar 26 06:15:07 2010
+++ /trunk/bikeshed/war/Stocks.html Thu Apr 22 06:58:10 2010
@@ -2,7 +2,6 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <link type="text/css" rel="stylesheet" href="Stocks.css">
<title>Stock Game Sample</title>
<script type="text/javascript" language="javascript"
src="stocksdesktop/stocksdesktop.nocache.js"></script>
</head>
=======================================
--- /trunk/bikeshed/war/StocksMobile.html Fri Mar 26 06:15:07 2010
+++ /trunk/bikeshed/war/StocksMobile.html Thu Apr 22 06:58:10 2010
@@ -2,7 +2,6 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <link type="text/css" rel="stylesheet" href="Stocks.css">
<title>Stock Game Sample</title>
<script type="text/javascript" language="javascript"
src="stocksmobile/stocksmobile.nocache.js"></script>
</head>
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors