GoogleGit

blob: deac8f8030c7e3854251314a0e91737f212ac258 [file] [log] [blame]
  1. /*******************************************************************************
  2. * Copyright (c) 2010 BSI Business Systems Integration AG.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * BSI Business Systems Integration AG - initial API and implementation
  10. ******************************************************************************/
  11. package org.eclipse.scout.rt.ui.rap.mobile.form.fields.tablefield;
  12. import java.util.List;
  13. import org.eclipse.scout.rt.client.mobile.ui.basic.table.IMobileTable;
  14. import org.eclipse.scout.rt.client.ui.basic.table.ITableRow;
  15. /**
  16. * @since 3.9.0
  17. */
  18. public class RwtScoutMobileListModel extends RwtScoutListModel {
  19. private static final long serialVersionUID = 1L;
  20. private RwtPagingSupport m_pagingSupport;
  21. public RwtScoutMobileListModel(IMobileTable scoutTable, RwtScoutList uiTable) {
  22. super(scoutTable, uiTable);
  23. if (scoutTable.isPagingEnabled()) {
  24. m_pagingSupport = new RwtPagingSupport(uiTable, scoutTable);
  25. }
  26. }
  27. @Override
  28. public void dispose() {
  29. super.dispose();
  30. if (m_pagingSupport != null) {
  31. m_pagingSupport.dispose();
  32. m_pagingSupport = null;
  33. }
  34. }
  35. @Override
  36. public IMobileTable getScoutTable() {
  37. return (IMobileTable) super.getScoutTable();
  38. }
  39. @Override
  40. public Object[] getElements(Object inputElement) {
  41. if (m_pagingSupport == null) {
  42. return super.getElements(inputElement);
  43. }
  44. if (getScoutTable() != null) {
  45. List<ITableRow> filteredRows = getScoutTable().getFilteredRows();
  46. return m_pagingSupport.getElementsOfCurrentPage(filteredRows).toArray();
  47. }
  48. else {
  49. return new Object[0];
  50. }
  51. }
  52. public void setPagingEnabled(boolean enabled) {
  53. boolean refreshNecessary = false;
  54. if (enabled) {
  55. if (m_pagingSupport == null) {
  56. m_pagingSupport = new RwtPagingSupport(getUiList(), getScoutTable());
  57. refreshNecessary = true;
  58. }
  59. }
  60. else {
  61. if (m_pagingSupport != null) {
  62. m_pagingSupport.dispose();
  63. m_pagingSupport = null;
  64. refreshNecessary = true;
  65. }
  66. }
  67. if (refreshNecessary) {
  68. getUiList().getUiTableViewer().refresh();
  69. }
  70. }
  71. }