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 27KB

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