Revision: 8025
Author: [email protected]
Date: Fri Apr 30 14:56:39 2010
Log: Adds a new styled SimplePager to the expense app. Also rearranges the expense app so that the report list is now next to the browser, and the items list are on the bottom. This works better for smaller screens.

http://code.google.com/p/google-web-toolkit/source/detail?r=8025

Added:
/branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/AbstractPager.java /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/SimplePager.css /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/SimplePager.java /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/simplePagerFirstPage.png /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/simplePagerFirstPageDisabled.png /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/simplePagerLastPage.png /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/simplePagerLastPageDisabled.png /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/simplePagerNextPage.png /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/simplePagerNextPageDisabled.png /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/simplePagerPreviousPage.png /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/simplePagerPreviousPageDisabled.png
Modified:
/branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/CellTable.css /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/cellTableHeaderBackground.png /branches/2.1/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/SimplePager.java /branches/2.1/bikeshed/src/com/google/gwt/sample/bikeshed/style/client/Styles.java /branches/2.1/bikeshed/src/com/google/gwt/sample/bikeshed/style/client/common.css /branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpenseDetails.java /branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpenseDetails.ui.xml /branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpenseList.java /branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpenseList.ui.xml /branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpensesShell.ui.xml

=======================================
--- /dev/null
+++ /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/AbstractPager.java Fri Apr 30 14:56:39 2010
@@ -0,0 +1,188 @@
+/*
+ * 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.bikeshed.list.client;
+
+import com.google.gwt.bikeshed.list.client.PagingListView.Pager;
+import com.google.gwt.user.client.ui.Composite;
+
+/**
+ * An abstract pager that exposes many methods useful for paging.
+ *
+ * @param <T> the type of the PagingListView being controlled
+ */
+public abstract class AbstractPager<T> extends Composite implements Pager<T> {
+
+  /**
+   * If true, all operations should be limited to the data size.
+   */
+  private boolean isRangeLimited;
+
+  /**
+   * The {...@link PagingListView} being paged.
+   */
+  private final PagingListView<T> view;
+
+  public AbstractPager(PagingListView<T> view) {
+    this.view = view;
+    view.setPager(this);
+  }
+
+  /**
+   * Go to the first page.
+   */
+  public void firstPage() {
+    setPage(0);
+  }
+
+  /**
+   * Get the current page index.
+   *
+   * Since the page start index can be set to any value, its possible to be
+   * between pages. In this case, the return value is the number of times
+   * {...@link #previousPage()} can be called.
+   *
+   * @return the page index
+   */
+  public int getPage() {
+    int pageSize = view.getPageSize();
+    return (view.getPageStart() + pageSize - 1) / pageSize;
+  }
+
+  /**
+   * Get the number of pages based on the data size.
+   *
+   * @return the page count
+   */
+  public int getPageCount() {
+    int pageSize = view.getPageSize();
+    return (view.getDataSize() + pageSize - 1) / pageSize;
+  }
+
+  /**
+   * Get the {...@link PagingListView} being paged.
+   *
+   * @return the {...@link PagingListView}
+   */
+  public PagingListView<T> getPagingListView() {
+    return view;
+  }
+
+  /**
+   * 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 view.getPageStart() + view.getPageSize() < view.getDataSize();
+  }
+
+  /**
+ * Returns true if there is enough data such that the specified page is within
+   * range.
+   */
+  public boolean hasPage(int index) {
+    return view.getPageSize() * index < view.getDataSize();
+  }
+
+  /**
+   * 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 view.getPageStart() > 0 && view.getDataSize() > 0;
+  }
+
+  /**
+   * Check if the page should be limited to the actual data size.
+   *
+   * @return true if the range is limited to the data size
+   */
+  public boolean isRangeLimited() {
+    return isRangeLimited;
+  }
+
+  /**
+   * Go to the last page.
+   */
+  public void lastPage() {
+    setPage(getPageCount() - 1);
+  }
+
+  /**
+   * Set the page start to the last index that will still show a full page.
+   */
+  public void lastPageStart() {
+    setPageStart(view.getDataSize() - view.getPageSize());
+  }
+
+  /**
+   * Advance the starting row by 'pageSize' rows.
+   */
+  public void nextPage() {
+    setPageStart(view.getPageStart() + view.getPageSize());
+  }
+
+  public void onRangeOrSizeChanged(PagingListView<T> listView) {
+    if (isRangeLimited) {
+      setPageStart(view.getPageStart());
+    }
+  }
+
+  /**
+   * Move the starting row back by 'pageSize' rows.
+   */
+  public void previousPage() {
+    setPageStart(view.getPageStart() - view.getPageSize());
+  }
+
+  /**
+   * Go to a specific page.
+   *
+   * @param index the page index
+   */
+  public void setPage(int index) {
+    if (!isRangeLimited || hasPage(index)) {
+      // We don't use the local version of setPageStart because the user
+      // probably wants to use absolute page indexes.
+      view.setPageStart(view.getPageSize() * index);
+    }
+  }
+
+  /**
+   * Set the page start index.
+   *
+   * @param index the index
+   */
+  public void setPageStart(int index) {
+    if (isRangeLimited) {
+      index = Math.min(index, view.getDataSize() - view.getPageSize());
+    }
+    index = Math.max(0, index);
+    view.setPageStart(index);
+  }
+
+  /**
+   * Set whether or not the page range should be limited to the actual data
+   * size. If true, all operations will adjust so that there is always data
+   * visible on the page.
+   *
+   * @param isRangeLimited
+   */
+  public void setRangeLimited(boolean isRangeLimited) {
+    this.isRangeLimited = isRangeLimited;
+  }
+}
=======================================
--- /dev/null
+++ /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/SimplePager.css Fri Apr 30 14:56:39 2010
@@ -0,0 +1,11 @@
+.pageDetails {
+  padding: 4px 8px;
+}
+
+.button {
+  padding: 4px;
+}
+
+.disabledButton {
+
+}
=======================================
--- /dev/null
+++ /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/SimplePager.java Fri Apr 30 14:56:39 2010
@@ -0,0 +1,266 @@
+/*
+ * 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.bikeshed.list.client;
+
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.resources.client.ClientBundle;
+import com.google.gwt.resources.client.CssResource;
+import com.google.gwt.resources.client.ImageResource;
+import com.google.gwt.sample.bikeshed.style.client.Styles;
+import com.google.gwt.user.client.ui.HasVerticalAlignment;
+import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.Image;
+import com.google.gwt.user.client.ui.Label;
+
+/**
+ * A pager for controlling a {...@link PagingListView} that only supports simple
+ * page navigation.
+ *
+ * @param <T> the type of the PagingListView being controlled
+ */
+public class SimplePager<T> extends AbstractPager<T> {
+
+  /**
+   * Styles used by this widget.
+   */
+  public static interface Style extends CssResource {
+
+    /**
+     * Applied to buttons.
+     */
+    String button();
+
+    /**
+     * Applied to disabled buttons.
+     */
+    String disabledButton();
+
+    /**
+     * Applied to the details text.
+     */
+    String pageDetails();
+  }
+
+  /**
+   * A ClientBundle that provides images for this widget.
+   */
+  public static interface Resources extends ClientBundle {
+
+    /**
+     * The image used to go to the first page.
+     */
+    ImageResource simplePagerFirstPage();
+
+    /**
+     * The disabled first page image.
+     */
+    ImageResource simplePagerFirstPageDisabled();
+
+    /**
+     * The image used to go to the last page.
+     */
+    ImageResource simplePagerLastPage();
+
+    /**
+     * The disabled last page image.
+     */
+    ImageResource simplePagerLastPageDisabled();
+
+    /**
+     * The image used to go to the next page.
+     */
+    ImageResource simplePagerNextPage();
+
+    /**
+     * The disabled next page image.
+     */
+    ImageResource simplePagerNextPageDisabled();
+
+    /**
+     * The image used to go to the previous page.
+     */
+    ImageResource simplePagerPreviousPage();
+
+    /**
+     * The disabled previous page image.
+     */
+    ImageResource simplePagerPreviousPageDisabled();
+
+    /**
+     * The styles used in this widget.
+     */
+    @Source("SimplePager.css")
+    Style simplePagerStyle();
+  }
+
+  private final Image firstPage;
+  private final Label label = new Label();
+  private final Image lastPage;
+  /**
+   * Set to true when the next and last buttons are disabled.
+   */
+  private boolean nextDisabled;
+
+  private final Image nextPage;
+
+  /**
+   * Set to true when the prev and first buttons are disabled.
+   */
+  private boolean prevDisabled;
+
+  private final Image prevPage;
+
+  /**
+   * The {...@link Resources} used by this widget.
+   */
+  private final Resources resources;
+
+  /**
+   * The {...@link Style} used by this widget.
+   */
+  private final Style style;
+
+  /**
+   * Construct a {...@link SimplePager}.
+   *
+   * @param view the {...@link PagingListView} to page
+   */
+  public SimplePager(PagingListView<T> view) {
+    this(view, Styles.resources());
+  }
+
+  /**
+   * Construct a {...@link SimplePager} with the specified resources.
+   *
+   * @param view the {...@link PagingListView} to page
+   */
+  public SimplePager(PagingListView<T> view, Resources resources) {
+    super(view);
+    this.resources = resources;
+    this.style = resources.simplePagerStyle();
+    this.style.ensureInjected();
+
+    // Create the buttons.
+    firstPage = new Image(resources.simplePagerFirstPage());
+    lastPage = new Image(resources.simplePagerLastPage());
+    nextPage = new Image(resources.simplePagerNextPage());
+    prevPage = new Image(resources.simplePagerPreviousPage());
+
+    // Add handlers.
+    firstPage.addClickHandler(new ClickHandler() {
+      public void onClick(ClickEvent event) {
+        firstPage();
+      }
+    });
+    lastPage.addClickHandler(new ClickHandler() {
+      public void onClick(ClickEvent event) {
+        lastPage();
+      }
+    });
+    nextPage.addClickHandler(new ClickHandler() {
+      public void onClick(ClickEvent event) {
+        nextPage();
+      }
+    });
+    prevPage.addClickHandler(new ClickHandler() {
+      public void onClick(ClickEvent event) {
+        previousPage();
+      }
+    });
+
+    // Construct the widget.
+    HorizontalPanel layout = new HorizontalPanel();
+    layout.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
+    initWidget(layout);
+    layout.add(firstPage);
+    layout.add(prevPage);
+    layout.add(label);
+    layout.add(nextPage);
+    layout.add(lastPage);
+
+    // Add style names to the cells.
+    firstPage.getElement().getParentElement().addClassName(style.button());
+    prevPage.getElement().getParentElement().addClassName(style.button());
+ label.getElement().getParentElement().addClassName(style.pageDetails());
+    nextPage.getElement().getParentElement().addClassName(style.button());
+    lastPage.getElement().getParentElement().addClassName(style.button());
+  }
+
+  @Override
+  public void onRangeOrSizeChanged(PagingListView<T> listView) {
+    super.onRangeOrSizeChanged(listView);
+    label.setText(createText());
+
+    // Update the prev and first buttons.
+    boolean hasPrev = hasPreviousPage();
+    if (hasPrev && prevDisabled) {
+      prevDisabled = false;
+      firstPage.setResource(resources.simplePagerFirstPage());
+      prevPage.setResource(resources.simplePagerPreviousPage());
+      firstPage.getElement().getParentElement().removeClassName(
+          style.disabledButton());
+      prevPage.getElement().getParentElement().removeClassName(
+          style.disabledButton());
+    } else if (!hasPrev && !prevDisabled) {
+      prevDisabled = true;
+      firstPage.setResource(resources.simplePagerFirstPageDisabled());
+      prevPage.setResource(resources.simplePagerPreviousPageDisabled());
+      firstPage.getElement().getParentElement().addClassName(
+          style.disabledButton());
+      prevPage.getElement().getParentElement().addClassName(
+          style.disabledButton());
+    }
+
+    // Update the next and last buttons.
+    if (isRangeLimited()) {
+      boolean hasNext = hasNextPage();
+      if (hasNext && nextDisabled) {
+        nextDisabled = false;
+        nextPage.setResource(resources.simplePagerNextPage());
+        lastPage.setResource(resources.simplePagerLastPage());
+        nextPage.getElement().getParentElement().removeClassName(
+            style.disabledButton());
+        lastPage.getElement().getParentElement().removeClassName(
+            style.disabledButton());
+      } else if (!hasNext && !nextDisabled) {
+        nextDisabled = true;
+        nextPage.setResource(resources.simplePagerNextPageDisabled());
+        lastPage.setResource(resources.simplePagerLastPageDisabled());
+        nextPage.getElement().getParentElement().addClassName(
+            style.disabledButton());
+        lastPage.getElement().getParentElement().addClassName(
+            style.disabledButton());
+      }
+    }
+  }
+
+  /**
+ * Get the text to display in the pager that reflects the state of the pager.
+   *
+   * @return the text
+   */
+  protected String createText() {
+    // Default text is 1 based.
+    PagingListView<T> view = getPagingListView();
+    int pageStart = view.getPageStart() + 1;
+    int pageSize = view.getPageSize();
+    int dataSize = view.getDataSize();
+    int endIndex = Math.min(dataSize, pageStart + pageSize - 1);
+    endIndex = Math.max(pageStart, endIndex);
+    return pageStart + "-" + endIndex + " of " + dataSize;
+  }
+}
=======================================
--- /dev/null   
+++ /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/simplePagerFirstPage.png Fri Apr 30 14:56:39 2010
Binary file, no diff available.
=======================================
--- /dev/null
+++ /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/simplePagerFirstPageDisabled.png Fri Apr 30 14:56:39 2010
@@ -0,0 +1,13 @@
+‰PNG
+ + +IHDR ØYþG sRGB ®Î +é pHYs šœ tIME Ú + 5
+b>Y¶   UIDAT(ÏMÒMŠ A  à/²²¦»¦»U W‚koâÖ‹¸ ï!è æ  ‚·ð
+Š83àtWw×Oº¨ê #!‰|<2"^¼( Šb4 ŒŠ T’$ È i4èœtzEÈj+µJ ­ uŽZ öB Š ­ÆZ- ™Q§õ× ÆÎ ¡óËK µJ. ' î +¡¨Õþ i:£Þѽ-¾ùbê5Ü*vî
+õFi*YÍ  ÂÉgß *­Î( ½ƒ e.÷ÓW¿ç|í`§È“ «ù·â‡ ç9‡Þ`œt‹ lÝ8ù?&<M³\ ÆG¯–>1ï"
+¬Ñ-ðkŸ¼]^ kYHI­qœg$l}ðn¦µ Y’“¬±Ój–^Â{o„ƒg—u ep¶÷ µ™e˜î½Æ  W*9Tjו 
a­28*žÛjÔ*!J¡Ì6:9댒ڕÕl¥`¢]
+7è
+ ’U‹Û Ú“ƒË¼Ù'çÂ?£¡‡Z—¦‘     IEND®B`‚
=======================================
--- /dev/null
+++ /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/simplePagerLastPage.png Fri Apr 30 14:56:39 2010
@@ -0,0 +1,19 @@
+‰PNG
+ + +IHDR rP6Ì sBIT | dˆ öIDAT8 e”9 ]E +¿ÞîòÞ¼7¶f<–ÿ " @äN "!C ‡ $"$$–ØH$ �...@d–œ ""ˆ Ù <û»KwW ô}‹5'¹
+t {úT 2ªªLP UEDÈ"ä\Ϊ` XkqÎà¬ÅZ‹1 cØÀo‰  %åÌ 3à  c"¥ŒªbŒÁ{G <u
+¨‚Ã;‡µ 31úµ" eŒ‰¾ \w  W=g
+DSm” í¸ÕÂr¯aÞÖ4M 
+~" £ªš³0ÆÄª 9¿\ñçiÂÍnã}` ÆÀ #º:åÞmÏþbƬ­¨‚Ç9‹ Ur †!ryÕñûS¡Ý?Ú¡PÀl¾Á{Ìþ  œþ‹5
+Î   5X %¦Ìª 9>
+i–  <þö뉀 É ?ÿ Çß=  ^
+p|6²êGbʨ(VD‰1Ñu#1,°¶¨xòý#¾úì †¡£4|Û¶µ‡Ñ/J]Lˆ(VTˆ)s±J´ílS À¯¿üÈ ½ËÉ_¿q †¦™q±JÄ” •¢,gaHÛ¿ ؉ðéÉ1_~ü
+?ÿô  l§²`H ³ ek‹ sã¢] Œ=ß<ü”¡ïË ˜µ ZêÖ÷  g
+a]9uMvæáðÎ=Þyð UÓ À64¥ÎMsæ­±xïX´†§) ü&  ðÜó/òú[ï3ß[b0ë £
+1Ž
+´% ÖX¼µ†à
+ó¶âä䜰<,9 î¿ò /¿ú&ÖÚ’[ô™,æþ’ÙaE˜Rà­µ„ài›Š»‹ÈßÝ5M;ç · ðÂK÷wžNQ6 úîš»seÖV ïJðETsÎ 
câêºç¿³kNúšÙÞr àµEÆ”óêêœ;ÍÀÁ­9{ó†ºò8çJ6E•œ„aŒ¬º Ë«ž .2£m¨Û ÎzrN ÝŠJ;Ž–žÅ^ì­©«€ó kL! Xg4Në§ 
Fú1 £ " ;
+Måiꊺ „àp®  [2Øî´œ
+”31    ’¥  Á:Kð ï&’ ]vƒì RUTtÛE¦ eMyÒn['ü iT¡ÀŽ Š     IEND®B`‚
=======================================
--- /dev/null
+++ /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/simplePagerLastPageDisabled.png Fri Apr 30 14:56:39 2010
@@ -0,0 +1,15 @@
+‰PNG
+ + +IHDR ØYþG sRGB ®Î +é pHYs šœ tIME Ú + 5 ˜1dÕ RIDAT(ÏUÒKŽ 1 +áïº\Ý©P ‰=0f ÌØ b ì ‰9l€54b Ù D òª‡ TuÒ}<²|| üûD)P £Ñ`t„¤�...@žl£aç¨Ó+bv»v«$1ÙŠqç`ok‡"°Ôj,Ô’ uöþÚh´& +Î7 Ô*¹ +mý´vWÙÚFHÓ õ 6V¸™'ñÞG´~9è Ò ™%|òÎQ™ç ¡²× ¥¢·ÓÌG_¼ñõNôÂN¯H +ç ?¼õùξ3 ¥Û€‹N>8ˆ3ZHÓ[.
+O¼¶8_ þ"‡l©Ÿ¾ O½ÔΦ¢³”
+œd ïV Ͻ ”   kµ$'µ
+µ Æ+Ïî!Þ[idIŒepòÏo;­˜ãB±µôÈ W*9TjK¡öGX¨ öx¨Õ¨UB”B™kttš˜«]¹ž« L¶ÛÆ
+z ¨dÕ¹mgÛ¥Áe¦—îáý Ñ ‚Þ
+ÉAv    IEND®B`‚
=======================================
--- /dev/null   
+++ /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/simplePagerNextPage.png Fri Apr 30 14:56:39 2010
Binary file, no diff available.
=======================================
--- /dev/null
+++ /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/simplePagerNextPageDisabled.png Fri Apr 30 14:56:39 2010
@@ -0,0 +1,19 @@
+‰PNG
+ + +IHDR ØYþG sRGB ®Î +é pHYs šœ tIME Ú + 5 ŽyD RIDAT(ÏMÒKnÔP +á¯ìë¤Ýi ‚ˆ=0d Y ;AbÎ
+XC ì f¬! ¨ Êà øQ 츩;¹ƒ¿^§NdBJ“Éh’B¥V©„ e†&£ÞƒÞ
+¢qªQ«ÄŒ¥Iï së
+)°µÓÚhTBaÒëÜØk=“æ \y%Ѩ•4zpkï\J„Dqn/Tó›  ®í–:—KÓ v®
+ &Õ<W½lÄ7_
+–ÝC­Ó›Tipgã)ÒOŸ\!°qo ªY
+k5øí³ïË¿7šTÇ*±ÂéÑW¿þK.ó.GxŽ  ]   K(¶z \¤à  ΄4h ¡TŠÖ f
+Þy¿6뼞ï0fïεN ~x»Ì”:­—¶ 1åèÑ ?ºUâù ·¶^8s¢VB­± + Úè =·ÓjÔBd’‹ +<Κkœ8]¬ ÌØ“ãFƒ ÔŠzuÛŠ
+
+œËlGçÂ?`¸ Â
+• Œ    IEND®B`‚
=======================================
--- /dev/null   
+++ /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/simplePagerPreviousPage.png Fri Apr 30 14:56:39 2010
Binary file, no diff available.
=======================================
--- /dev/null   
+++ /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/simplePagerPreviousPageDisabled.png Fri Apr 30 14:56:39 2010
Binary file, no diff available.
=======================================
--- /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/CellTable.css Fri Apr 30 09:33:31 2010 +++ /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/CellTable.css Fri Apr 30 14:56:39 2010
@@ -8,7 +8,7 @@

 @sprite .footer {
   gwt-image: 'cellTableFooterBackground';
-  background-color: #b5d0f7;
+  background-color: #b4d0f8;
   border-top: 1px solid #5478af;
   border-left: 1px solid #5478af;
   padding: 5px 20px;
@@ -18,7 +18,7 @@

 @sprite .header {
   gwt-image: 'cellTableHeaderBackground';
-  background-color: #b5d0f7;
+  background-color: #b4d0f8;
   border-bottom: 1px solid #5478af;
   border-left: 1px solid #5478af;
   padding: 5px 20px;
=======================================
--- /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/cellTableHeaderBackground.png Fri Apr 30 09:33:31 2010 +++ /branches/2.1/bikeshed/src/com/google/gwt/bikeshed/list/client/cellTableHeaderBackground.png Fri Apr 30 14:56:39 2010
Binary file, no diff available.
=======================================
--- /branches/2.1/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/SimplePager.java Tue Apr 27 06:38:30 2010 +++ /branches/2.1/bikeshed/src/com/google/gwt/sample/bikeshed/cookbook/client/SimplePager.java Fri Apr 30 14:56:39 2010
@@ -15,11 +15,11 @@
  */
 package com.google.gwt.sample.bikeshed.cookbook.client;

+import com.google.gwt.bikeshed.list.client.AbstractPager;
 import com.google.gwt.bikeshed.list.client.PagingListView;
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.ClickHandler;
 import com.google.gwt.user.client.ui.Button;
-import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.FlowPanel;
 import com.google.gwt.user.client.ui.Label;

@@ -29,17 +29,17 @@
  *
  * @param <T> the type of the PagingListView being controlled
  */
-public class SimplePager<T> extends Composite implements
-    PagingListView.Pager<T>, ClickHandler {
+public class SimplePager<T> extends AbstractPager<T> implements ClickHandler {

   private Button nextPageButton;
   private Button prevPageButton;
   private Button remove1Button;
   private Button remove5Button;
-  private PagingListView<T> view;
   private Label infoLabel;
+  private PagingListView<T> view;

   public SimplePager(PagingListView<T> view) {
+    super(view);
     FlowPanel p = new FlowPanel();
     p.add(prevPageButton = makeButton("Previous Page", "PREV"));
     p.add(nextPageButton = makeButton("Next Page", "NEXT"));
@@ -51,7 +51,6 @@
     initWidget(p);

     this.view = view;
-    view.setPager(this);
   }

   /**
@@ -69,31 +68,6 @@
   public boolean canRemoveRows(int rows) {
     return view.getPageSize() > rows;
   }
-
-  /**
-   * 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 view.getPageStart() + view.getPageSize() < view.getDataSize();
-  }
-
-  /**
-   * 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 view.getPageStart() > 0 && view.getDataSize() > 0;
-  }
-
-  /**
-   * Advance the starting row by 'pageSize' rows.
-   */
-  public void nextPage() {
-    view.setPageStart(view.getPageStart() + view.getPageSize());
-  }

   public void onClick(ClickEvent event) {
     String id = ((Button) event.getSource()).getElement().getId();
@@ -110,16 +84,11 @@
     updateButtons();
   }

+  @Override
   public void onRangeOrSizeChanged(PagingListView<T> listView) {
+    super.onRangeOrSizeChanged(listView);
     updateButtons();
   }
-
-  /**
-   * Move the starting row back by 'pageSize' rows.
-   */
-  public void previousPage() {
-    view.setPageStart(view.getPageStart() - view.getPageSize());
-  }

   private void addRows(int rows) {
     view.setPageSize(view.getPageSize() + rows);
=======================================
--- /branches/2.1/bikeshed/src/com/google/gwt/sample/bikeshed/style/client/Styles.java Fri Apr 30 09:33:31 2010 +++ /branches/2.1/bikeshed/src/com/google/gwt/sample/bikeshed/style/client/Styles.java Fri Apr 30 14:56:39 2010
@@ -17,6 +17,7 @@

 import com.google.gwt.bikeshed.list.client.CellList;
 import com.google.gwt.bikeshed.list.client.CellTable;
+import com.google.gwt.bikeshed.list.client.SimplePager;
 import com.google.gwt.bikeshed.tree.client.CellBrowser;
 import com.google.gwt.bikeshed.tree.client.CellTree;
 import com.google.gwt.core.client.GWT;
@@ -51,7 +52,8 @@
    * Shared resources.
    */
   public interface Resources extends ClientBundle, CellBrowser.Resources,
-      CellList.Resources, CellTable.Resources, CellTree.Resources {
+      CellList.Resources, CellTable.Resources, CellTree.Resources,
+      SimplePager.Resources {

     @NotStrict
     @Source("common.css")
=======================================
--- /branches/2.1/bikeshed/src/com/google/gwt/sample/bikeshed/style/client/common.css Fri Apr 30 09:33:31 2010 +++ /branches/2.1/bikeshed/src/com/google/gwt/sample/bikeshed/style/client/common.css Fri Apr 30 14:56:39 2010
@@ -154,7 +154,7 @@

 /* splitters */
 .gwt-SplitLayoutPanel-HDragger {
-  background: #b6cef3 url(hsplitter-grip.png) center center no-repeat;
+  background: #ddd url(hsplitter-grip.png) center center no-repeat;
 }

 .gwt-SplitLayoutPanel-VDragger {
=======================================
--- /branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpenseDetails.java Fri Apr 30 10:15:06 2010 +++ /branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpenseDetails.java Fri Apr 30 14:56:39 2010
@@ -26,6 +26,7 @@
 import com.google.gwt.bikeshed.list.client.Column;
 import com.google.gwt.bikeshed.list.shared.ListViewAdapter;
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.Element;
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.ClickHandler;
 import com.google.gwt.event.logical.shared.CloseEvent;
@@ -43,7 +44,6 @@
 import com.google.gwt.user.client.ui.DialogBox;
 import com.google.gwt.user.client.ui.FlexTable;
 import com.google.gwt.user.client.ui.HorizontalPanel;
-import com.google.gwt.user.client.ui.Label;
 import com.google.gwt.user.client.ui.PopupPanel;
 import com.google.gwt.user.client.ui.TextBox;
 import com.google.gwt.user.client.ui.Widget;
@@ -128,20 +128,29 @@

private static ExpenseDetailsUiBinder uiBinder = GWT.create(ExpenseDetailsUiBinder.class);

+  @UiField
+  Element approvedLabel;
+
+  @UiField
+  Element costLabel;
+
+  @UiField
+  Element defaultText;
+
   ExpensesRequestFactory expensesRequestFactory;

+  @UiField
+  Element mainLayout;
+
   @UiField
   TextBox notesBox;

   @UiField
-  Label reportName;
+  Element reportName;

   @UiField
   CellTable<ExpenseRecord> table;

-  @UiField
-  Label totalLabel;
-
private List<SortableHeader> allHeaders = new ArrayList<SortableHeader>();

   private SortableColumn<ExpenseRecord, Date> dateColumn;
@@ -155,6 +164,7 @@

   public ExpenseDetails() {
     initWidget(uiBinder.createAndBindUi(this));
+    setReportRecord(null);

     // Add the view to the adapter.
     items.addView(table);
@@ -189,7 +199,17 @@
   }

   public void setReportRecord(ReportRecord report) {
-    reportName.setText(report.getPurpose());
+    if (report == null) {
+      setVisible(defaultText, true);
+      setVisible(mainLayout, false);
+      return;
+    }
+
+    // Show the main layout when a report becomes available.
+    setVisible(defaultText, false);
+    setVisible(mainLayout, true);
+
+    reportName.setInnerText(report.getPurpose());
     notesBox.setText(report.getNotes());

     // Reset sorting state of table
=======================================
--- /branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpenseDetails.ui.xml Wed Apr 28 13:19:55 2010 +++ /branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpenseDetails.ui.xml Fri Apr 30 14:56:39 2010
@@ -10,32 +10,92 @@
     }

     .padded {
-      padding: 0px 20px 0px 28px;
+      padding: 0px 20px;
+    }
+
+    .reportName {
+      font-size: 16pt;
+    }
+
+    .details {
+      background-color: #eef4fb;
+      border: 1px solid #5478af;
+    }
+
+    .table {
+      padding-top: 20px;
+      padding-left: 30px;
     }
   </ui:style>

   <g:HTMLPanel
     width='100%'
     height='100%'>
-    <div class='{style.padded}'>
-    <h1><g:Label ui:field='reportName'></g:Label></h1>
-    <table>
-      <td
-        class='{style.label}'>
-        Total Approved:
-      </td>
-      <td>
-        <g:Label
-          ui:field='totalLabel'></g:Label>
-        </td>
+
+    <div
+      ui:field='defaultText'>Select a report above</div>
+
+    <div
+      ui:field='mainLayout'
+      class='{style.padded}'>
+
+      <table
+        width='100%'>
+        <tr>
+          <td
+            valign='top'
+            align='center'
+            width='100'>
+
+            <h1
+              class='{style.reportName}'
+              ui:field='reportName'>
+            </h1>
+
+            <table
+              class='{style.details}'
+              cellpadding='8'>
+              <tr>
+                <td
+                  class='{style.label}'>
+                  Cost:
+                </td>
+                <td
+                  ui:field='costLabel'>
+                </td>
+              </tr>
+              <tr>
+                <td
+                  class='{style.label}'>
+                  Approved:
+                </td>
+                <td
+                  ui:field='approvedLabel'>
+                </td>
+              </tr>
+              <tr>
+                <td
+                  class='{style.label}'>
+                  Notes:
+                </td>
+                <td>
+                  <g:TextBox
+                    ui:field='notesBox'></g:TextBox>
+                </td>
+              </tr>
+            </table>
+          </td>
+
+          <td
+            valign='top'
+            align='center'
+            class='{style.table}'>
+            <l:CellTable
+              width='100%'
+              ui:field='table' />
+          </td>
+        </tr>
       </table>
-      <span
-        class='{style.label}'>Notes:</span>
-      <g:TextBox
-        ui:field='notesBox'></g:TextBox>
-      <l:CellTable
-        width='100%'
-        ui:field='table' />
     </div>
   </g:HTMLPanel>

=======================================
--- /branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpenseList.java Fri Apr 30 09:10:49 2010 +++ /branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpenseList.java Fri Apr 30 14:56:39 2010
@@ -20,6 +20,7 @@
 import com.google.gwt.bikeshed.cells.client.TextCell;
 import com.google.gwt.bikeshed.cells.client.ValueUpdater;
 import com.google.gwt.bikeshed.list.client.CellTable;
+import com.google.gwt.bikeshed.list.client.SimplePager;
 import com.google.gwt.bikeshed.list.shared.ListViewAdapter;
 import com.google.gwt.bikeshed.list.shared.SingleSelectionModel;
import com.google.gwt.bikeshed.list.shared.SelectionModel.SelectionChangeEvent;
@@ -83,8 +84,15 @@
private static ExpenseListUiBinder uiBinder = GWT.create(ExpenseListUiBinder.class);

   @UiField
-  TextBox searchBox;
+  SimplePager<ReportRecord> pager;
   @UiField
+  TextBox searchBox;
+
+  /**
+   * The main table. We provide this in the constructor before calling
+ * {...@link UiBinder#createAndBindUi(Object)} because the pager depends on it.
+   */
+  @UiField(provided = true)
   CellTable<ReportRecord> table;

private List<SortableHeader> allHeaders = new ArrayList<SortableHeader>();
@@ -109,6 +117,7 @@
   private SortableColumn<ReportRecord, String> purposeColumn;

   public ExpenseList() {
+    createTable();
     initWidget(uiBinder.createAndBindUi(this));

     // Add the view to the adapter.
@@ -174,45 +183,19 @@
     this.listener = listener;
     search();
   }
-
-  @UiFactory
-  CellTable<ReportRecord> createTable() {
-    CellTable<ReportRecord> view = new CellTable<ReportRecord>(25);
-
-    // Add a selection model.
- final SingleSelectionModel<ReportRecord> selectionModel = new SingleSelectionModel<ReportRecord>();
-    view.setSelectionModel(selectionModel);
-    view.setSelectionEnabled(true);
-    selectionModel.addSelectionChangeHandler(new SelectionChangeHandler() {
-      public void onSelectionChange(SelectionChangeEvent event) {
-        Object selected = selectionModel.getSelectedObject();
-        if (selected != null && listener != null) {
-          listener.onReportSelected((ReportRecord) selected);
-        }
-      }
-    });
-
-    // Purpose column.
- purposeColumn = addColumn(view, "Purpose", TextCell.getInstance(), new GetValue<ReportRecord, String>() {
-      public String getValue(ReportRecord object) {
-        return object.getPurpose();
-      }
-    });
-
-    // Created column.
- addColumn(view, "Created", new DateCell(), new GetValue<ReportRecord, Date>() {
-      public Date getValue(ReportRecord object) {
-        return object.getCreated();
-      }
-    });
-
-    return view;
-  }
-
+
+  @UiFactory
+  SimplePager<ReportRecord> createPager() {
+    SimplePager<ReportRecord> p = new SimplePager<ReportRecord>(table);
+    p.setRangeLimited(true);
+    return p;
+  }
+
private <C extends Comparable<C>> SortableColumn<ReportRecord, C> addColumn( - final CellTable<ReportRecord> table, final String text, final Cell<C> cell,
-      final GetValue<ReportRecord, C> getter) {
- final SortableColumn<ReportRecord, C> column = new SortableColumn<ReportRecord, C>(cell) {
+      final CellTable<ReportRecord> table, final String text,
+      final Cell<C> cell, final GetValue<ReportRecord, C> getter) {
+ final SortableColumn<ReportRecord, C> column = new SortableColumn<ReportRecord, C>(
+        cell) {
       @Override
       public C getValue(ReportRecord object) {
         return getter.getValue(object);
@@ -239,6 +222,42 @@
     table.addColumn(column, header);
     return column;
   }
+
+  /**
+   * Create the {...@link CellTable}.
+   */
+  private void createTable() {
+    table = new CellTable<ReportRecord>(8);
+
+    // Add a selection model.
+ final SingleSelectionModel<ReportRecord> selectionModel = new SingleSelectionModel<ReportRecord>();
+    table.setSelectionModel(selectionModel);
+    table.setSelectionEnabled(true);
+    selectionModel.addSelectionChangeHandler(new SelectionChangeHandler() {
+      public void onSelectionChange(SelectionChangeEvent event) {
+        Object selected = selectionModel.getSelectedObject();
+        if (selected != null && listener != null) {
+          listener.onReportSelected((ReportRecord) selected);
+        }
+      }
+    });
+
+    // Purpose column.
+    purposeColumn = addColumn(table, "Purpose", TextCell.getInstance(),
+        new GetValue<ReportRecord, String>() {
+          public String getValue(ReportRecord object) {
+            return object.getPurpose();
+          }
+        });
+
+    // Created column.
+    addColumn(table, "Created", new DateCell(),
+        new GetValue<ReportRecord, Date>() {
+          public Date getValue(ReportRecord object) {
+            return object.getCreated();
+          }
+        });
+  }

   /**
    * Search based on the text.
@@ -252,7 +271,7 @@
       listener.onSearch(startsWith);
     }
   }
-
+
   private void sortReports(final Comparator<ReportRecord> comparator) {
     Collections.sort(reports.getList(), comparator);
   }
=======================================
--- /branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpenseList.ui.xml Wed Apr 28 13:19:55 2010 +++ /branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpenseList.ui.xml Fri Apr 30 14:56:39 2010
@@ -8,12 +8,8 @@
     field='searchIcon' />

   <ui:style>
-    .paddedLeft {
-      padding-left: 20px;
-    }
-
-    .paddedRight {
-      padding-right: 20px;
+    .padded {
+      padding: 0px 20px;
     }

     .textBox {
@@ -30,9 +26,11 @@
     width='100%'
     height='100%'>
     <div
-      class='{style.paddedLeft}'>
+      class='{style.padded}'>
       <table
-        width='100%'>
+        width='100%'
+        cellspacing='0'
+        cellpadding='0'>
         <tr>
           <td>
             <h1>Reports</h1>
@@ -49,10 +47,23 @@
               class='{style.searchIcon}' />
           </td>
         </tr>
+        <tr>
+          <td
+            colspan='3'>
+            <l:CellTable
+              width='100%'
+              ui:field='table' />
+          </td>
+        </tr>
+        <tr>
+          <td
+            align='center'
+            colspan='3'>
+            <l:SimplePager
+              ui:field='pager' />
+          </td>
+        </tr>
       </table>
-      <l:CellTable
-        width='100%'
-        ui:field='table' />
     </div>
   </g:HTMLPanel>

=======================================
--- /branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpensesShell.ui.xml Wed Apr 28 13:19:55 2010 +++ /branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpensesShell.ui.xml Fri Apr 30 14:56:39 2010
@@ -30,55 +30,58 @@
     }
   </ui:style>

-  <g:SplitLayoutPanel
-    ui:field='splitLayout'>
+  <g:DockLayoutPanel
+    unit='PX'>
     <g:north
-      size='250'>
-      <g:DockLayoutPanel
-        unit='PX'
-        ui:field='northPanel'>
-        <g:north
-          size='50'>
-          <g:HTMLPanel
-            styleName='{style.title}'>
-            <table
-              height='100%'>
-              <tr>
-                <td>
-                  <img
-                    height='40'
- src='http://www.google.com/intl/en_ALL/images/logo.gif' />
+      size='50'>
+      <g:HTMLPanel
+        styleName='{style.title}'>
+        <table
+          height='100%'>
+          <tr>
+            <td>
+              <img
+                height='40'
+                src='http://www.google.com/intl/en_ALL/images/logo.gif' />
+            </td>
+            <td
+              class='{style.titleText}'
+              valign='middle'>
+              Expenses Sample
                 </td>
-                <td
-                  class='{style.titleText}'
-                  valign='middle'>
-                  Expenses Sample
-                </td>
-              </tr>
-            </table>
-          </g:HTMLPanel>
-        </g:north>
-        <g:center>
-          <c:ExpenseBrowser
-            ui:field='expenseBrowser'></c:ExpenseBrowser>
-        </g:center>
-      </g:DockLayoutPanel>
+          </tr>
+        </table>
+      </g:HTMLPanel>
     </g:north>
+
     <g:center>
-      <g:DockLayoutPanel
-        unit='PCT'>
-        <g:west
-          size='50'>
-          <c:ExpenseList
-            ui:field='expenseList'></c:ExpenseList>
-        </g:west>
+      <g:SplitLayoutPanel
+        ui:field='splitLayout'>
+        <g:north
+          size='300'>
+          <g:DockLayoutPanel
+            unit='PCT'
+            ui:field='northPanel'>
+            <g:west
+              size='40'>
+              <c:ExpenseBrowser
+                ui:field='expenseBrowser' />
+            </g:west>
+            <g:center
+              size='60'>
+              <c:ExpenseList
+                ui:field='expenseList'
+                styleName='{style.shadowLeft}' />
+            </g:center>
+          </g:DockLayoutPanel>
+        </g:north>
+
         <g:center>
           <c:ExpenseDetails
-            styleName='{style.shadowLeft}'
-            ui:field='expenseDetails'></c:ExpenseDetails>
+            ui:field='expenseDetails' />
         </g:center>
-      </g:DockLayoutPanel>
+      </g:SplitLayoutPanel>
     </g:center>
-  </g:SplitLayoutPanel>
+  </g:DockLayoutPanel>

 </ui:UiBinder>

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to