You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EscalatorBasicClientFeaturesWidget.java 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. package com.vaadin.tests.widgetset.client.grid;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import com.google.gwt.core.client.Duration;
  5. import com.google.gwt.core.client.Scheduler.ScheduledCommand;
  6. import com.google.gwt.dom.client.TableCellElement;
  7. import com.google.gwt.user.client.DOM;
  8. import com.google.gwt.user.client.ui.Composite;
  9. import com.google.gwt.user.client.ui.HTML;
  10. import com.vaadin.v7.client.widget.escalator.EscalatorUpdater;
  11. import com.vaadin.v7.client.widget.escalator.FlyweightCell;
  12. import com.vaadin.v7.client.widget.escalator.Row;
  13. import com.vaadin.v7.client.widget.escalator.RowContainer;
  14. import com.vaadin.v7.client.widget.escalator.Spacer;
  15. import com.vaadin.v7.client.widget.escalator.SpacerUpdater;
  16. import com.vaadin.v7.client.widget.escalator.RowContainer.BodyRowContainer;
  17. import com.vaadin.v7.client.widgets.Escalator;
  18. import com.vaadin.v7.shared.ui.grid.ScrollDestination;
  19. public class EscalatorBasicClientFeaturesWidget
  20. extends PureGWTTestApplication<Escalator> {
  21. public static class LogWidget extends Composite {
  22. private static final int MAX_LOG = 9;
  23. private final HTML html = new HTML();
  24. private final List<String> logs = new ArrayList<String>();
  25. private Escalator escalator;
  26. public LogWidget() {
  27. initWidget(html);
  28. getElement().setId("log");
  29. }
  30. public void setEscalator(Escalator escalator) {
  31. this.escalator = escalator;
  32. }
  33. public void updateDebugLabel() {
  34. int headers = escalator.getHeader().getRowCount();
  35. int bodys = escalator.getBody().getRowCount();
  36. int footers = escalator.getFooter().getRowCount();
  37. int columns = escalator.getColumnConfiguration().getColumnCount();
  38. while (logs.size() > MAX_LOG) {
  39. logs.remove(0);
  40. }
  41. String logString = "<hr>";
  42. for (String log : logs) {
  43. logString += log + "<br>";
  44. }
  45. html.setHTML("Columns: " + columns + "<br>" + //
  46. "Header rows: " + headers + "<br>" + //
  47. "Body rows: " + bodys + "<br>" + //
  48. "Footer rows: " + footers + "<br>" + //
  49. logString);
  50. }
  51. public void log(String string) {
  52. logs.add((Duration.currentTimeMillis() % 10000) + ": " + string);
  53. }
  54. }
  55. public static class UpdaterLifetimeWidget
  56. extends EscalatorBasicClientFeaturesWidget {
  57. private final EscalatorUpdater debugUpdater = new EscalatorUpdater() {
  58. @Override
  59. public void preAttach(Row row,
  60. Iterable<FlyweightCell> cellsToAttach) {
  61. log("preAttach", cellsToAttach);
  62. }
  63. @Override
  64. public void postAttach(Row row,
  65. Iterable<FlyweightCell> attachedCells) {
  66. log("postAttach", attachedCells);
  67. }
  68. @Override
  69. public void update(Row row, Iterable<FlyweightCell> cellsToUpdate) {
  70. log("update", cellsToUpdate);
  71. }
  72. @Override
  73. public void preDetach(Row row,
  74. Iterable<FlyweightCell> cellsToDetach) {
  75. log("preDetach", cellsToDetach);
  76. }
  77. @Override
  78. public void postDetach(Row row,
  79. Iterable<FlyweightCell> detachedCells) {
  80. log("postDetach", detachedCells);
  81. }
  82. private void log(String methodName, Iterable<FlyweightCell> cells) {
  83. if (!cells.iterator().hasNext()) {
  84. return;
  85. }
  86. TableCellElement cellElement = cells.iterator().next()
  87. .getElement();
  88. boolean isAttached = cellElement.getParentElement() != null
  89. && cellElement.getParentElement()
  90. .getParentElement() != null;
  91. logWidget.log(
  92. methodName + ": elementIsAttached == " + isAttached);
  93. }
  94. };
  95. public UpdaterLifetimeWidget() {
  96. super();
  97. escalator.getHeader().setEscalatorUpdater(debugUpdater);
  98. escalator.getBody().setEscalatorUpdater(debugUpdater);
  99. escalator.getFooter().setEscalatorUpdater(debugUpdater);
  100. }
  101. }
  102. private static final String COLUMNS_AND_ROWS_MENU = "Columns and Rows";
  103. private static final String GENERAL_MENU = "General";
  104. private static final String FEATURES_MENU = "Features";
  105. private static abstract class TestEscalatorUpdater
  106. implements EscalatorUpdater {
  107. @Override
  108. public void preAttach(Row row, Iterable<FlyweightCell> cellsToAttach) {
  109. // noop
  110. }
  111. @Override
  112. public void postAttach(Row row, Iterable<FlyweightCell> attachedCells) {
  113. // noop
  114. }
  115. @Override
  116. public void preDetach(Row row, Iterable<FlyweightCell> cellsToDetach) {
  117. // noop
  118. }
  119. @Override
  120. public void postDetach(Row row, Iterable<FlyweightCell> detachedCells) {
  121. // noop
  122. }
  123. }
  124. private class Data {
  125. private int columnCounter = 0;
  126. private int rowCounter = 0;
  127. private final List<Integer> columns = new ArrayList<Integer>();
  128. private final List<Integer> rows = new ArrayList<Integer>();
  129. @SuppressWarnings("boxing")
  130. public void insertRows(final int offset, final int amount) {
  131. final List<Integer> newRows = new ArrayList<Integer>();
  132. for (int i = 0; i < amount; i++) {
  133. newRows.add(rowCounter++);
  134. }
  135. rows.addAll(offset, newRows);
  136. }
  137. @SuppressWarnings("boxing")
  138. public void insertColumns(final int offset, final int amount) {
  139. final List<Integer> newColumns = new ArrayList<Integer>();
  140. for (int i = 0; i < amount; i++) {
  141. newColumns.add(columnCounter++);
  142. }
  143. columns.addAll(offset, newColumns);
  144. }
  145. public EscalatorUpdater createHeaderUpdater() {
  146. return new TestEscalatorUpdater() {
  147. @Override
  148. public void update(final Row row,
  149. final Iterable<FlyweightCell> cellsToUpdate) {
  150. for (final FlyweightCell cell : cellsToUpdate) {
  151. final Integer columnName = columns
  152. .get(cell.getColumn());
  153. cell.getElement().setInnerText("Header " + columnName);
  154. if (colspan == Colspan.NORMAL) {
  155. if (cell.getColumn() % 2 == 0) {
  156. cell.setColSpan(2);
  157. }
  158. } else if (colspan == Colspan.CRAZY) {
  159. if (cell.getColumn() % 3 == 0) {
  160. cell.setColSpan(2);
  161. }
  162. }
  163. }
  164. }
  165. };
  166. }
  167. public EscalatorUpdater createFooterUpdater() {
  168. return new TestEscalatorUpdater() {
  169. @Override
  170. public void update(final Row row,
  171. final Iterable<FlyweightCell> cellsToUpdate) {
  172. for (final FlyweightCell cell : cellsToUpdate) {
  173. final Integer columnName = columns
  174. .get(cell.getColumn());
  175. cell.getElement().setInnerText("Footer " + columnName);
  176. if (colspan == Colspan.NORMAL) {
  177. if (cell.getColumn() % 2 == 0) {
  178. cell.setColSpan(2);
  179. }
  180. } else if (colspan == Colspan.CRAZY) {
  181. if (cell.getColumn() % 3 == 1) {
  182. cell.setColSpan(2);
  183. }
  184. }
  185. }
  186. }
  187. };
  188. }
  189. public EscalatorUpdater createBodyUpdater() {
  190. return new TestEscalatorUpdater() {
  191. public void renderCell(final FlyweightCell cell) {
  192. final Integer columnName = columns.get(cell.getColumn());
  193. final Integer rowName = rows.get(cell.getRow());
  194. String cellInfo = columnName + "," + rowName;
  195. if (cell.getColumn() > 0) {
  196. cell.getElement().setInnerText("Cell: " + cellInfo);
  197. } else {
  198. cell.getElement().setInnerText(
  199. "Row " + cell.getRow() + ": " + cellInfo);
  200. }
  201. if (colspan == Colspan.NORMAL) {
  202. if (cell.getColumn() % 2 == 0) {
  203. cell.setColSpan(2);
  204. }
  205. } else if (colspan == Colspan.CRAZY) {
  206. if (cell.getColumn() % 3 == cell.getRow() % 3) {
  207. cell.setColSpan(2);
  208. }
  209. }
  210. }
  211. @Override
  212. public void update(final Row row,
  213. final Iterable<FlyweightCell> cellsToUpdate) {
  214. for (final FlyweightCell cell : cellsToUpdate) {
  215. renderCell(cell);
  216. }
  217. }
  218. };
  219. }
  220. public void removeRows(final int offset, final int amount) {
  221. for (int i = 0; i < amount; i++) {
  222. rows.remove(offset);
  223. }
  224. }
  225. public void removeColumns(final int offset, final int amount) {
  226. for (int i = 0; i < amount; i++) {
  227. columns.remove(offset);
  228. }
  229. }
  230. }
  231. protected final Escalator escalator;
  232. private final Data data = new Data();
  233. private enum Colspan {
  234. NONE, NORMAL, CRAZY;
  235. }
  236. private Colspan colspan = Colspan.NONE;
  237. protected final LogWidget logWidget = new LogWidget();
  238. public EscalatorBasicClientFeaturesWidget() {
  239. super(new EscalatorProxy());
  240. escalator = getTestedWidget();
  241. logWidget.setEscalator(escalator);
  242. ((EscalatorProxy) escalator).setLogWidget(logWidget);
  243. addNorth(logWidget, 200);
  244. final RowContainer header = escalator.getHeader();
  245. header.setEscalatorUpdater(data.createHeaderUpdater());
  246. final RowContainer footer = escalator.getFooter();
  247. footer.setEscalatorUpdater(data.createFooterUpdater());
  248. escalator.getBody().setEscalatorUpdater(data.createBodyUpdater());
  249. setWidth("500px");
  250. setHeight("500px");
  251. escalator.getElement().getStyle().setZIndex(0);
  252. addNorth(escalator, 500);
  253. createGeneralMenu();
  254. createColumnMenu();
  255. createHeaderRowsMenu();
  256. createBodyRowsMenu();
  257. createFooterRowsMenu();
  258. createColumnsAndRowsMenu();
  259. createFrozenMenu();
  260. createColspanMenu();
  261. createSpacerMenu();
  262. }
  263. private void createFrozenMenu() {
  264. String[] menupath = { FEATURES_MENU, "Frozen columns" };
  265. addMenuCommand("Freeze 1 column", new ScheduledCommand() {
  266. @Override
  267. public void execute() {
  268. escalator.getColumnConfiguration().setFrozenColumnCount(1);
  269. }
  270. }, menupath);
  271. addMenuCommand("Freeze 0 columns", new ScheduledCommand() {
  272. @Override
  273. public void execute() {
  274. escalator.getColumnConfiguration().setFrozenColumnCount(0);
  275. }
  276. }, menupath);
  277. }
  278. private void createColspanMenu() {
  279. String[] menupath = { FEATURES_MENU, "Column spanning" };
  280. addMenuCommand("Apply normal colspan", new ScheduledCommand() {
  281. @Override
  282. public void execute() {
  283. colspan = Colspan.NORMAL;
  284. refreshEscalator();
  285. }
  286. }, menupath);
  287. addMenuCommand("Apply crazy colspan", new ScheduledCommand() {
  288. @Override
  289. public void execute() {
  290. colspan = Colspan.CRAZY;
  291. refreshEscalator();
  292. }
  293. }, menupath);
  294. addMenuCommand("Apply no colspan", new ScheduledCommand() {
  295. @Override
  296. public void execute() {
  297. colspan = Colspan.NONE;
  298. refreshEscalator();
  299. }
  300. }, menupath);
  301. }
  302. private void createColumnsAndRowsMenu() {
  303. String[] menupath = { COLUMNS_AND_ROWS_MENU };
  304. addMenuCommand("Add one of each row", new ScheduledCommand() {
  305. @Override
  306. public void execute() {
  307. insertRows(escalator.getHeader(), 0, 1);
  308. insertRows(escalator.getBody(), 0, 1);
  309. insertRows(escalator.getFooter(), 0, 1);
  310. }
  311. }, menupath);
  312. addMenuCommand("Remove one of each row", new ScheduledCommand() {
  313. @Override
  314. public void execute() {
  315. removeRows(escalator.getHeader(), 0, 1);
  316. removeRows(escalator.getBody(), 0, 1);
  317. removeRows(escalator.getFooter(), 0, 1);
  318. }
  319. }, menupath);
  320. }
  321. private void createGeneralMenu() {
  322. String[] menupath = { GENERAL_MENU };
  323. addMenuCommand("Detach Escalator", new ScheduledCommand() {
  324. @Override
  325. public void execute() {
  326. escalator.removeFromParent();
  327. }
  328. }, menupath);
  329. addMenuCommand("Attach Escalator", new ScheduledCommand() {
  330. @Override
  331. public void execute() {
  332. if (!escalator.isAttached()) {
  333. addNorth(escalator, 500);
  334. }
  335. }
  336. }, menupath);
  337. addMenuCommand("Clear (columns, then rows)", new ScheduledCommand() {
  338. @Override
  339. public void execute() {
  340. resetColRow();
  341. }
  342. }, menupath);
  343. addMenuCommand("Clear (rows, then columns)", new ScheduledCommand() {
  344. @Override
  345. public void execute() {
  346. resetRowCol();
  347. }
  348. }, menupath);
  349. addMenuCommand("Populate Escalator (columns, then rows)",
  350. new ScheduledCommand() {
  351. @Override
  352. public void execute() {
  353. resetColRow();
  354. insertColumns(0, 10);
  355. insertRows(escalator.getHeader(), 0, 1);
  356. insertRows(escalator.getBody(), 0, 100);
  357. insertRows(escalator.getFooter(), 0, 1);
  358. }
  359. }, menupath);
  360. addMenuCommand("Populate Escalator (rows, then columns)",
  361. new ScheduledCommand() {
  362. @Override
  363. public void execute() {
  364. resetColRow();
  365. insertRows(escalator.getHeader(), 0, 1);
  366. insertRows(escalator.getBody(), 0, 100);
  367. insertRows(escalator.getFooter(), 0, 1);
  368. insertColumns(0, 10);
  369. }
  370. }, menupath);
  371. createSizeMenu();
  372. }
  373. private void createSizeMenu() {
  374. String[] menupath = new String[] { "General", "Size" };
  375. addSizeMenuItem(null, "height", menupath);
  376. addSizeMenuItem("200px", "height", menupath);
  377. addSizeMenuItem("400px", "height", menupath);
  378. addSizeMenuItem(null, "width", menupath);
  379. addSizeMenuItem("200px", "width", menupath);
  380. addSizeMenuItem("400px", "width", menupath);
  381. }
  382. private void addSizeMenuItem(final String size, final String direction,
  383. String[] menupath) {
  384. final String title = (size != null ? size : "undefined");
  385. addMenuCommand(title + " " + direction, new ScheduledCommand() {
  386. @Override
  387. public void execute() {
  388. if (direction.equals("height")) {
  389. escalator.setHeight(size);
  390. } else {
  391. escalator.setWidth(size);
  392. }
  393. }
  394. }, menupath);
  395. }
  396. private void createColumnMenu() {
  397. String[] menupath = { COLUMNS_AND_ROWS_MENU, "Columns" };
  398. addMenuCommand("Add one column to beginning", new ScheduledCommand() {
  399. @Override
  400. public void execute() {
  401. insertColumns(0, 1);
  402. }
  403. }, menupath);
  404. addMenuCommand("Add one column to end", new ScheduledCommand() {
  405. @Override
  406. public void execute() {
  407. insertColumns(
  408. escalator.getColumnConfiguration().getColumnCount(), 1);
  409. }
  410. }, menupath);
  411. addMenuCommand("Add ten columns", new ScheduledCommand() {
  412. @Override
  413. public void execute() {
  414. insertColumns(0, 10);
  415. }
  416. }, menupath);
  417. addMenuCommand("Remove one column from beginning",
  418. new ScheduledCommand() {
  419. @Override
  420. public void execute() {
  421. removeColumns(0, 1);
  422. }
  423. }, menupath);
  424. addMenuCommand("Remove one column from end", new ScheduledCommand() {
  425. @Override
  426. public void execute() {
  427. removeColumns(
  428. escalator.getColumnConfiguration().getColumnCount() - 1,
  429. 1);
  430. }
  431. }, menupath);
  432. addMenuCommand("Refresh first column", new ScheduledCommand() {
  433. @Override
  434. public void execute() {
  435. escalator.getColumnConfiguration().refreshColumns(0, 1);
  436. }
  437. }, menupath);
  438. addMenuCommand("Resize first column to max width",
  439. new ScheduledCommand() {
  440. @Override
  441. public void execute() {
  442. escalator.getColumnConfiguration().setColumnWidth(0,
  443. -1);
  444. }
  445. }, menupath);
  446. addMenuCommand("Resize first column to 100 px", new ScheduledCommand() {
  447. @Override
  448. public void execute() {
  449. escalator.getColumnConfiguration().setColumnWidth(0, 100);
  450. }
  451. }, menupath);
  452. }
  453. private void createHeaderRowsMenu() {
  454. String[] menupath = { COLUMNS_AND_ROWS_MENU, "Header Rows" };
  455. createRowsMenu(escalator.getHeader(), menupath);
  456. }
  457. private void createFooterRowsMenu() {
  458. String[] menupath = { COLUMNS_AND_ROWS_MENU, "Footer Rows" };
  459. createRowsMenu(escalator.getFooter(), menupath);
  460. }
  461. private void createBodyRowsMenu() {
  462. String[] menupath = { COLUMNS_AND_ROWS_MENU, "Body Rows" };
  463. createRowsMenu(escalator.getBody(), menupath);
  464. addMenuCommand("Add 5 rows to top", new ScheduledCommand() {
  465. @Override
  466. public void execute() {
  467. insertRows(escalator.getBody(), 0, 5);
  468. }
  469. }, menupath);
  470. addMenuCommand("Add 50 rows to top", new ScheduledCommand() {
  471. @Override
  472. public void execute() {
  473. insertRows(escalator.getBody(), 0, 50);
  474. }
  475. }, menupath);
  476. addMenuCommand("Remove 5 rows from bottom", new ScheduledCommand() {
  477. @Override
  478. public void execute() {
  479. removeRows(escalator.getBody(),
  480. escalator.getBody().getRowCount() - 5, 5);
  481. }
  482. }, menupath);
  483. addMenuCommand("Remove 50 rows from bottom", new ScheduledCommand() {
  484. @Override
  485. public void execute() {
  486. removeRows(escalator.getBody(),
  487. escalator.getBody().getRowCount() - 50, 50);
  488. }
  489. }, menupath);
  490. addMenuCommand("Remove 50 rows from almost bottom",
  491. new ScheduledCommand() {
  492. @Override
  493. public void execute() {
  494. removeRows(escalator.getBody(),
  495. escalator.getBody().getRowCount() - 60, 50);
  496. }
  497. }, menupath);
  498. addMenuCommand("Remove all, insert 30 and scroll 40px",
  499. new ScheduledCommand() {
  500. @Override
  501. public void execute() {
  502. removeRows(escalator.getBody(), 0,
  503. escalator.getBody().getRowCount());
  504. insertRows(escalator.getBody(), 0, 30);
  505. escalator.setScrollTop(40);
  506. }
  507. }, menupath);
  508. String[] scrollToRowMenuPath = new String[menupath.length + 1];
  509. System.arraycopy(menupath, 0, scrollToRowMenuPath, 0, menupath.length);
  510. scrollToRowMenuPath[scrollToRowMenuPath.length - 1] = "Scroll to...";
  511. for (int i = 0; i < 100; i += 25) {
  512. final int rowIndex = i;
  513. addMenuCommand("Row " + i, new ScheduledCommand() {
  514. @Override
  515. public void execute() {
  516. escalator.scrollToRow(rowIndex, ScrollDestination.ANY, 0);
  517. }
  518. }, scrollToRowMenuPath);
  519. }
  520. addMenuCommand("Set 20px default height", new ScheduledCommand() {
  521. @Override
  522. public void execute() {
  523. escalator.getBody().setDefaultRowHeight(20);
  524. }
  525. }, menupath);
  526. }
  527. private void createRowsMenu(final RowContainer container,
  528. String[] menupath) {
  529. addMenuCommand("Add one row to beginning", new ScheduledCommand() {
  530. @Override
  531. public void execute() {
  532. int offset = 0;
  533. int number = 1;
  534. insertRows(container, offset, number);
  535. }
  536. }, menupath);
  537. addMenuCommand("Add one row to end", new ScheduledCommand() {
  538. @Override
  539. public void execute() {
  540. int offset = container.getRowCount();
  541. int number = 1;
  542. insertRows(container, offset, number);
  543. }
  544. }, menupath);
  545. addMenuCommand("Remove one row from beginning", new ScheduledCommand() {
  546. @Override
  547. public void execute() {
  548. int offset = 0;
  549. int number = 1;
  550. removeRows(container, offset, number);
  551. }
  552. }, menupath);
  553. addMenuCommand("Remove one row from end", new ScheduledCommand() {
  554. @Override
  555. public void execute() {
  556. int offset = container.getRowCount() - 1;
  557. int number = 1;
  558. removeRows(container, offset, number);
  559. }
  560. }, menupath);
  561. addMenuCommand("Remove all rows", new ScheduledCommand() {
  562. @Override
  563. public void execute() {
  564. if (container.getRowCount() > 0) {
  565. removeRows(container, 0, container.getRowCount());
  566. }
  567. }
  568. }, menupath);
  569. }
  570. private void createSpacerMenu() {
  571. String[] menupath = { "Features", "Spacers" };
  572. addMenuCommand("Swap Spacer Updater", new ScheduledCommand() {
  573. private final SpacerUpdater CUSTOM = new SpacerUpdater() {
  574. @Override
  575. public void destroy(Spacer spacer) {
  576. spacer.getElement().setInnerText("");
  577. }
  578. @Override
  579. public void init(Spacer spacer) {
  580. spacer.getElement()
  581. .setInnerText("Spacer for row " + spacer.getRow());
  582. }
  583. };
  584. @Override
  585. public void execute() {
  586. BodyRowContainer body = escalator.getBody();
  587. if (SpacerUpdater.NULL.equals(body.getSpacerUpdater())) {
  588. body.setSpacerUpdater(CUSTOM);
  589. } else {
  590. body.setSpacerUpdater(SpacerUpdater.NULL);
  591. }
  592. }
  593. }, menupath);
  594. addMenuCommand("Focusable Updater", new ScheduledCommand() {
  595. @Override
  596. public void execute() {
  597. escalator.getBody().setSpacerUpdater(new SpacerUpdater() {
  598. @Override
  599. public void init(Spacer spacer) {
  600. spacer.getElement().appendChild(DOM.createInputText());
  601. }
  602. @Override
  603. public void destroy(Spacer spacer) {
  604. spacer.getElement().removeAllChildren();
  605. }
  606. });
  607. }
  608. }, menupath);
  609. createSpacersMenuForRow(-1, menupath);
  610. createSpacersMenuForRow(1, menupath);
  611. createSpacersMenuForRow(50, menupath);
  612. createSpacersMenuForRow(99, menupath);
  613. }
  614. private void createSpacersMenuForRow(final int rowIndex,
  615. String[] menupath) {
  616. menupath = new String[] { menupath[0], menupath[1], "Row " + rowIndex };
  617. addMenuCommand("Set 100px", new ScheduledCommand() {
  618. @Override
  619. public void execute() {
  620. escalator.getBody().setSpacer(rowIndex, 100);
  621. }
  622. }, menupath);
  623. addMenuCommand("Set 50px", new ScheduledCommand() {
  624. @Override
  625. public void execute() {
  626. escalator.getBody().setSpacer(rowIndex, 50);
  627. }
  628. }, menupath);
  629. addMenuCommand("Remove", new ScheduledCommand() {
  630. @Override
  631. public void execute() {
  632. escalator.getBody().setSpacer(rowIndex, -1);
  633. }
  634. }, menupath);
  635. addMenuCommand("Scroll here (ANY, 0)", new ScheduledCommand() {
  636. @Override
  637. public void execute() {
  638. escalator.scrollToSpacer(rowIndex, ScrollDestination.ANY, 0);
  639. }
  640. }, menupath);
  641. addMenuCommand("Scroll here row+spacer below (ANY, 0)",
  642. new ScheduledCommand() {
  643. @Override
  644. public void execute() {
  645. escalator.scrollToRowAndSpacer(rowIndex,
  646. ScrollDestination.ANY, 0);
  647. }
  648. }, menupath);
  649. }
  650. private void insertRows(final RowContainer container, int offset,
  651. int number) {
  652. if (container == escalator.getBody()) {
  653. data.insertRows(offset, number);
  654. escalator.getBody().insertRows(offset, number);
  655. } else {
  656. container.insertRows(offset, number);
  657. }
  658. }
  659. private void removeRows(final RowContainer container, int offset,
  660. int number) {
  661. if (container == escalator.getBody()) {
  662. data.removeRows(offset, number);
  663. escalator.getBody().removeRows(offset, number);
  664. } else {
  665. container.removeRows(offset, number);
  666. }
  667. }
  668. private void insertColumns(final int offset, final int number) {
  669. data.insertColumns(offset, number);
  670. escalator.getColumnConfiguration().insertColumns(offset, number);
  671. }
  672. private void removeColumns(final int offset, final int number) {
  673. data.removeColumns(offset, number);
  674. escalator.getColumnConfiguration().removeColumns(offset, number);
  675. }
  676. private void resetColRow() {
  677. if (escalator.getColumnConfiguration().getColumnCount() > 0) {
  678. removeColumns(0,
  679. escalator.getColumnConfiguration().getColumnCount());
  680. }
  681. if (escalator.getFooter().getRowCount() > 0) {
  682. removeRows(escalator.getFooter(), 0,
  683. escalator.getFooter().getRowCount());
  684. }
  685. if (escalator.getBody().getRowCount() > 0) {
  686. removeRows(escalator.getBody(), 0,
  687. escalator.getBody().getRowCount());
  688. }
  689. if (escalator.getHeader().getRowCount() > 0) {
  690. removeRows(escalator.getHeader(), 0,
  691. escalator.getHeader().getRowCount());
  692. }
  693. }
  694. private void resetRowCol() {
  695. if (escalator.getFooter().getRowCount() > 0) {
  696. removeRows(escalator.getFooter(), 0,
  697. escalator.getFooter().getRowCount());
  698. }
  699. if (escalator.getBody().getRowCount() > 0) {
  700. removeRows(escalator.getBody(), 0,
  701. escalator.getBody().getRowCount());
  702. }
  703. if (escalator.getHeader().getRowCount() > 0) {
  704. removeRows(escalator.getHeader(), 0,
  705. escalator.getHeader().getRowCount());
  706. }
  707. if (escalator.getColumnConfiguration().getColumnCount() > 0) {
  708. removeColumns(0,
  709. escalator.getColumnConfiguration().getColumnCount());
  710. }
  711. }
  712. private void refreshEscalator() {
  713. if (escalator.getHeader().getRowCount() > 0) {
  714. escalator.getHeader().refreshRows(0,
  715. escalator.getHeader().getRowCount());
  716. }
  717. if (escalator.getBody().getRowCount() > 0) {
  718. escalator.getBody().refreshRows(0,
  719. escalator.getBody().getRowCount());
  720. }
  721. if (escalator.getFooter().getRowCount() > 0) {
  722. escalator.getFooter().refreshRows(0,
  723. escalator.getFooter().getRowCount());
  724. }
  725. }
  726. }