Advertisement
Guest User

Untitled

a guest
Sep 29th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 70.16 KB | None | 0 0
  1. package pt.isep.nsheets.client.application.workbook;
  2.  
  3. import com.google.gwt.core.client.GWT;
  4. import com.google.gwt.event.logical.shared.ValueChangeEvent;
  5. import com.google.gwt.uibinder.client.UiBinder;
  6. import com.google.gwt.uibinder.client.UiField;
  7. import com.google.gwt.uibinder.client.UiHandler;
  8. import com.google.gwt.user.client.Window;
  9. import com.google.gwt.user.client.rpc.AsyncCallback;
  10. import com.google.gwt.user.client.ui.HTMLPanel;
  11. import com.google.gwt.user.client.ui.Panel;
  12. import com.google.gwt.user.client.ui.Widget;
  13. import com.gwtplatform.mvp.client.ViewWithUiHandlers;
  14. import com.google.gwt.dom.client.Style;
  15. import gwt.material.design.addins.client.combobox.MaterialComboBox;
  16. import gwt.material.design.addins.client.popupmenu.MaterialPopupMenu;
  17. import gwt.material.design.addins.client.window.MaterialWindow;
  18. import gwt.material.design.client.constants.Color;
  19. import gwt.material.design.client.data.component.RowComponent;
  20. import gwt.material.design.client.ui.*;
  21. import gwt.material.design.client.ui.table.MaterialDataTable;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. import javax.inject.Inject;
  25.  
  26. import java.util.HashSet;
  27. import pt.isep.nsheets.client.application.lapr4.blue.s2.core.n1150344.filter.FilterController;
  28. import pt.isep.nsheets.client.application.Lapr.Red.n1161018.Search.OptionService;
  29. import pt.isep.nsheets.client.application.Lapr.Red.n1161018.Search.OptionType;
  30. import pt.isep.nsheets.client.application.Lapr.Red.n1161018.ext.UIController;
  31. import pt.isep.nsheets.client.application.chartWizzard.SpreadSheetSingleton;
  32. import pt.isep.nsheets.client.application.s1.n1160701.conditionalFormat.ConditionalFormatView;
  33. import pt.isep.nsheets.shared.core.*;
  34. import pt.isep.nsheets.shared.core.formula.BinaryOperator;
  35. import pt.isep.nsheets.shared.core.formula.Expression;
  36. import pt.isep.nsheets.shared.core.formula.Function;
  37. import pt.isep.nsheets.shared.core.formula.compiler.ExpressionCompiler;
  38. import pt.isep.nsheets.shared.core.formula.compiler.FormulaCompilationException;
  39. import pt.isep.nsheets.shared.core.formula.lang.Language;
  40. import pt.isep.nsheets.shared.core.formula.lang.LanguageManager;
  41. import pt.isep.nsheets.shared.lapr4.blue.s1.lang.n1090657.macrolanguage.application.MacroLanguageController;
  42. import pt.isep.nsheets.shared.lapr4.blue.s1.lang.n1090657.macrolanguage.compiler.MacroCompilerManager;
  43. import pt.isep.nsheets.shared.lapr4.blue.s1.lang.n1090657.shared.lang.MacroLanguage;
  44. import pt.isep.nsheets.shared.lapr4.blue.s1.lang.n1131485.macro.domain.Macro;
  45. import pt.isep.nsheets.shared.services.SearchService;
  46. import pt.isep.nsheets.shared.services.SearchServiceAsync;
  47.  
  48. import static gwt.material.design.jquery.client.api.JQuery.$;
  49. import pt.isep.nsheets.client.application.blue.s2.n1090657.WorkbookManager;
  50. import pt.isep.nsheets.shared.core.formula.FunctionParameter;
  51. import pt.isep.nsheets.shared.core.formula.Operator;
  52. import pt.isep.nsheets.shared.core.formula.UnaryOperator;
  53. import pt.isep.nsheets.shared.ext.Extension;
  54. import pt.isep.nsheets.shared.lapr4.blue.s1.lang.n1161386.formula2.NaryOperator;
  55. import pt.isep.nsheets.shared.lapr4.blue.s2.core.n1090657.core.SpreadsheetDTO;
  56. import pt.isep.nsheets.shared.lapr4.blue.s2.core.n1090657.core.WorkbookDTO;
  57. import pt.isep.nsheets.shared.services.ExportToPDFService;
  58. import pt.isep.nsheets.shared.services.ExportToPDFServiceAsync;
  59. import pt.isep.nsheets.shared.services.WorkbookDescriptionDTO;
  60. import pt.isep.nsheets.shared.services.WorkbooksService;
  61. import pt.isep.nsheets.shared.services.WorkbooksServiceAsync;
  62.  
  63. // public class HomeView extends ViewImpl implements HomePresenter.MyView {
  64. // public class WorkbookView extends NavigatedView implements WorkbookPresenter.MyView {
  65. public class WorkbookView extends ViewWithUiHandlers<WorkbookUIHandlers> implements WorkbookPresenter.MyView {
  66.  
  67. private UIController uiController = new UIController();
  68.  
  69. private FilterController filterController = new FilterController();
  70.  
  71. public MaterialTextBox getFirstBox() {
  72. return firstBox;
  73. }
  74.  
  75. public MaterialIcon getFirstButton() {
  76. return firstButton;
  77. }
  78.  
  79. public MaterialIcon getSecondButton() {
  80. return secondtButton;
  81. }
  82.  
  83. @UiField
  84. HTMLPanel htmlPanel;
  85.  
  86. @UiField
  87. MaterialTextBox firstBox;
  88.  
  89. @UiField
  90. MaterialIcon firstButton;
  91.  
  92. @UiField
  93. MaterialIcon secondtButton;
  94.  
  95. @UiField
  96. MaterialIcon searchNReplace_btn;
  97.  
  98. @UiField
  99. MaterialIcon sortButton;
  100.  
  101. @UiField
  102. MaterialDataTable<SheetCell> customTable;
  103.  
  104. @UiField
  105. MaterialPopupMenu popupMenu;
  106.  
  107. @UiField
  108. MaterialWindow window;
  109.  
  110. @UiField
  111. MaterialWindow searchNReplace_window;
  112.  
  113. @UiField
  114. MaterialWindow replace_window;
  115.  
  116. @UiField
  117. MaterialRadioButton radioValue;
  118.  
  119. @UiField
  120. MaterialRadioButton radioValue1;
  121.  
  122. @UiField
  123. MaterialRadioButton radioValue2;
  124.  
  125. @UiField
  126. MaterialRadioButton radioValue3;
  127.  
  128. @UiField
  129. MaterialWindow janela;
  130.  
  131. @UiField
  132. MaterialButton ExportToPDF;
  133.  
  134. //bea
  135. @UiField
  136. MaterialLink conditionalFormat;
  137.  
  138. @UiField
  139. MaterialWindow windowFormat;
  140.  
  141. //bea
  142. @UiField
  143. MaterialComboBox<BinaryOperator> conditional;
  144.  
  145. //bea
  146. @UiField
  147. MaterialComboBox<BinaryOperator> conditional2;
  148.  
  149. //bea
  150. @UiField
  151. MaterialComboBox<BinaryOperator> conditional3;
  152.  
  153. //bea
  154. @UiField
  155. MaterialTextBox numberConditional;
  156.  
  157. //bea
  158. @UiField
  159. MaterialTextBox numberConditional2;
  160.  
  161. //bea
  162. @UiField
  163. MaterialTextBox numberConditional3;
  164.  
  165. //bea
  166. @UiField
  167. MaterialComboBox<Color> listColors;
  168.  
  169. //bea
  170. @UiField
  171. MaterialComboBox<Color> listColors2;
  172.  
  173. //bea
  174. @UiField
  175. MaterialComboBox<Color> listColors3;
  176.  
  177. //bea
  178. @UiField
  179. MaterialComboBox<Color> listColors4;
  180.  
  181. //bea
  182. @UiField
  183. MaterialComboBox<Style.BorderStyle> listBorder;
  184.  
  185. //bea
  186. @UiField
  187. MaterialComboBox<Style.BorderStyle> listBorder2;
  188.  
  189. //bea
  190. @UiField
  191. MaterialButton confirmConditional;
  192.  
  193. //bea
  194. @UiField
  195. MaterialButton confirmConditional2;
  196.  
  197. //bea
  198. @UiField
  199. MaterialButton confirmConditional3;
  200.  
  201. //joana
  202. @UiField
  203. MaterialLink removeConditionalFormat;
  204.  
  205. @UiField
  206. MaterialWindow windowPDF;
  207.  
  208. @UiField
  209. MaterialTextBox fileName;
  210.  
  211. @UiField
  212. MaterialButton startExportWorkbookPDF;
  213.  
  214. @UiField
  215. MaterialButton startExportSpreadsheetPDF;
  216.  
  217. @UiField
  218. MaterialButton startExportPartialSpreadsheetPDF;
  219.  
  220. @UiField
  221. MaterialWindow windowSpreadsheetPDF;
  222.  
  223. @UiField
  224. MaterialWindow windowPartialSpreadsheetPDF;
  225.  
  226. @UiField
  227. MaterialButton ExportSpreadsheetPDF, ExportPartialSpreadsheetPDF;
  228.  
  229. @UiField
  230. MaterialTextBox SpreadsheetNumber1, SpreadsheetNumber2, posicao1, posicao2;
  231.  
  232. @UiField
  233. MaterialButton ExportToXML;
  234.  
  235. @UiField
  236. MaterialWindow windowXML;
  237.  
  238. @UiField
  239. MaterialTextBox fileName1;
  240.  
  241. @UiField
  242. MaterialButton startExportWorkbookXML;
  243.  
  244. @UiField
  245. MaterialButton startExportSpreadsheetXML;
  246.  
  247. @UiField
  248. MaterialButton startExportPartOfSpreadsheetXML;
  249.  
  250. @UiField
  251. MaterialWindow windowWorkbook1;
  252.  
  253. @UiField
  254. MaterialTextBox changetagOne;
  255.  
  256. @UiField
  257. MaterialTextBox changetagTwo;
  258.  
  259. @UiField
  260. MaterialTextBox changetagThree;
  261.  
  262. @UiField
  263. MaterialTextBox changetagFour;
  264.  
  265. @UiField
  266. MaterialTextBox changetagFive;
  267.  
  268. @UiField
  269. MaterialTextBox changetagSix;
  270.  
  271. @UiField
  272. MaterialButton Exportx;
  273.  
  274. @UiField
  275. MaterialWindow windowSpreadsheet1;
  276.  
  277. @UiField
  278. MaterialTextBox changeTag1;
  279.  
  280. @UiField
  281. MaterialTextBox changeTag2;
  282.  
  283. @UiField
  284. MaterialTextBox changeTag3;
  285.  
  286. @UiField
  287. MaterialTextBox changeTag4;
  288.  
  289. @UiField
  290. MaterialTextBox changeTag5;
  291.  
  292. @UiField
  293. MaterialTextBox changeTag6;
  294.  
  295. @UiField
  296. MaterialTextBox changeSpread2;
  297.  
  298. @UiField
  299. MaterialButton Exportm;
  300.  
  301. @UiField
  302. MaterialWindow windowPart1;
  303.  
  304. @UiField
  305. MaterialTextBox change1tag;
  306.  
  307. @UiField
  308. MaterialTextBox change2tag;
  309.  
  310. @UiField
  311. MaterialTextBox change3tag;
  312.  
  313. @UiField
  314. MaterialTextBox change4tag;
  315.  
  316. @UiField
  317. MaterialTextBox change5tag;
  318.  
  319. @UiField
  320. MaterialTextBox change6tag;
  321.  
  322. @UiField
  323. MaterialTextBox minL;
  324.  
  325. @UiField
  326. MaterialTextBox maxL;
  327.  
  328. @UiField
  329. MaterialTextBox minC;
  330.  
  331. @UiField
  332. MaterialTextBox maxC;
  333.  
  334. @UiField
  335. MaterialButton ExportL;
  336.  
  337. //AQUI
  338. @UiField
  339. MaterialButton ExportToCSV;
  340.  
  341. @UiField
  342. MaterialWindow windowCSV;
  343.  
  344. @UiField
  345. MaterialTextBox fileName2;
  346.  
  347. @UiField
  348. MaterialButton startExportWorkbookCSV;
  349.  
  350. @UiField
  351. MaterialButton startExportSpreadsheetCSV;
  352.  
  353. @UiField
  354. MaterialButton startExportPartOfSpreadsheetCSV;
  355.  
  356. @UiField
  357. MaterialWindow windowWorkbook;
  358.  
  359. @UiField
  360. MaterialTextBox changeFieldSeparator;
  361. @UiField
  362. MaterialTextBox changeFieldSeparator1;
  363. @UiField
  364. MaterialTextBox changeFieldSeparator2;
  365. @UiField
  366. MaterialButton Export;
  367.  
  368. @UiField
  369. MaterialWindow windowSpreadsheet;
  370.  
  371. @UiField
  372. MaterialTextBox changeSpreadsheet;
  373.  
  374. @UiField
  375. MaterialButton Export1;
  376.  
  377. @UiField
  378. MaterialWindow windowPart;
  379.  
  380. //joana
  381. MaterialLabel widget;
  382.  
  383. @UiField
  384. MaterialTextBox changeSpreadsheet1;
  385. @UiField
  386. MaterialTextBox minLinhas;
  387. @UiField
  388. MaterialTextBox maxLinhas;
  389. @UiField
  390. MaterialTextBox minColunas;
  391. @UiField
  392. MaterialTextBox maxColunas;
  393.  
  394. @UiField
  395. MaterialButton Export2;
  396. /* Search window content (@author David Camelo <1161294@isep.ipp.pt>) */
  397. @UiField
  398. MaterialIcon searchButton;
  399.  
  400. @UiField
  401. MaterialWindow popUpView;
  402.  
  403. @UiField
  404. MaterialTextBox regExpressionTextBox;
  405.  
  406. @UiField
  407. MaterialButton sendRegExpression;
  408.  
  409. @UiField
  410. MaterialTextArea outputOfSearch;
  411.  
  412.  
  413. /* -- Search window content -- */
  414. @UiField
  415. MaterialLink macroButton; // open macro window
  416.  
  417. /* Macro usage window´s content */
  418. @UiField
  419. MaterialWindow macroWindow;
  420.  
  421. @UiField
  422. MaterialTextArea macroCommands;
  423.  
  424. @UiField
  425. MaterialListValueBox<Macro> macroList;
  426.  
  427. @UiField
  428. MaterialButton executeMacro;
  429.  
  430. @UiField
  431. MaterialWindow macroWindow2;
  432. @UiField
  433. MaterialListValueBox<Language> langList;
  434.  
  435. @UiField
  436. MaterialButton langButton;
  437.  
  438. @UiField
  439. MaterialButton resetMacro;
  440.  
  441. /**
  442. * -- MACRO USAGE WINDOW CONTENT *
  443. *
  444. * By Pedro Emanuel 1131485
  445. */
  446. @UiField
  447. MaterialRadioButton ascendingButton;
  448.  
  449. @UiField
  450. MaterialRadioButton descendingButton;
  451.  
  452. @UiField
  453. MaterialTextBox firstAddress;
  454.  
  455. @UiField
  456. MaterialTextBox secondAddress;
  457.  
  458. @UiField
  459. MaterialIcon functionButton;
  460.  
  461. @UiField
  462. MaterialWindow windowFunctions;
  463.  
  464. // @UiField
  465. // MaterialButton applyFunction;
  466. @UiField
  467. MaterialButton selFunction;
  468.  
  469. @UiField
  470. MaterialButton selLang;
  471.  
  472. @UiField
  473. MaterialButton selButton;
  474. // @UiField
  475. // MaterialButton selPara;
  476. @UiField
  477. MaterialListValueBox<Language> languageListBox;
  478.  
  479. @UiField
  480. MaterialListValueBox<Function> functionListBox;
  481.  
  482. @UiField
  483. MaterialListValueBox<Operator> operatorListBox;
  484. // @UiField
  485. // MaterialTextBox functionParameters;
  486. @UiField
  487. MaterialButton CreateMacro;
  488.  
  489. @UiField
  490. MaterialButton EditMacro;
  491.  
  492. // @UiField
  493. // MaterialTextBox enterPara;
  494. // @UiField
  495. // MaterialLabel result;
  496. /**
  497. * Rui Almeida <1160818> Lang 07.2 - Visual Basic Macro Call
  498. * =========================================================
  499. */
  500. @UiField
  501. MaterialTextBox saveMacroName;
  502.  
  503. @UiField
  504. MaterialButton saveMacro;
  505.  
  506. @UiField
  507. MaterialButton viewMacros;
  508.  
  509. @UiField
  510. MaterialButton removeMacro;
  511.  
  512. /**
  513. * =========================================================
  514. */
  515.  
  516. private String parameters;
  517. private String stringT;
  518. private int nParameters;
  519. private ArrayList<MaterialTextBox> texts = new ArrayList<>();
  520. private MaterialButton buttonApply = new MaterialButton("Apply");
  521. private MaterialButton buttonCheck = new MaterialButton("Check");
  522. private MaterialLabel finalResult = new MaterialLabel();
  523. private MaterialSection ms = new MaterialSection();
  524. private MaterialSection ms2 = new MaterialSection();
  525. private MaterialSection ms3 = new MaterialSection();
  526. private MaterialTextBox parameter1 = new MaterialTextBox();
  527. private MaterialTextBox parameter2 = new MaterialTextBox();
  528. private Function finalFunction = null;
  529. private Operator finalOperator = null;
  530.  
  531. /**
  532. * Rui Ribeiro [1150344] Core03.2 Filter Range of Cells
  533. */
  534. @UiField
  535. MaterialTextBox filterFormula, filterStartCell, filterEndCell, filterColumn;
  536.  
  537. @UiField
  538. MaterialButton filterApply, filterClear;
  539.  
  540. HashSet<Integer> rowsSelectedIndex = new HashSet<>();
  541.  
  542. /**
  543. * ENDOF Rui Ribeiro [1150344] Core03.2 Filter Range of Cells
  544. */
  545. /**
  546. * SEARCH N REPLACE
  547. */
  548. /**
  549. * SEARCH N REPLACE
  550. */
  551. @UiField
  552. MaterialListBox lstOptions, lstOptions2;
  553.  
  554. @UiField
  555. MaterialButton startSearchNReplace;
  556.  
  557. @UiField
  558. MaterialTextBox regExpressionTextBox2, regExpressionTextBox3;
  559.  
  560. @UiField
  561. MaterialLabel reg1, reg2, reg3;
  562.  
  563. @UiField
  564. MaterialCheckBox cbYes, cbApply, cbDontApply;
  565.  
  566.  
  567. //======================================================================
  568. // Mario Dias 1151708
  569. /**
  570. * Extension combobox
  571. */
  572. @UiField
  573. MaterialComboBox<String> material_list_extension;
  574. //==============================
  575.  
  576. @UiHandler("cbYes")
  577. void onCheckValue(ValueChangeEvent<Boolean> e) {
  578.  
  579. OptionService.getInstance().setYesToAll(e.getValue());
  580.  
  581. }
  582.  
  583. @UiHandler("cbApply")
  584. void onCheckValueApply(ValueChangeEvent<Boolean> e) {
  585.  
  586. replace(OptionType.CHANGE);
  587. }
  588.  
  589. @UiHandler("cbDontApply")
  590. void onCheckValueDontApply(ValueChangeEvent<Boolean> e) {
  591.  
  592. replace(OptionType.DONT_CHANGE);
  593. }
  594.  
  595. @UiHandler({"lstOptions"})
  596. void onChangeListBox(ValueChangeEvent<String> e) {
  597.  
  598. // 0 - UNDEFINED
  599. // 1 - NUMERIC
  600. // 2 - TEXT
  601. // 3 - BOOLEAN
  602. // 4 - DATE
  603. // 5 - MATRIX
  604. Value.Type selectedType = Value.Type.UNDEFINED;
  605.  
  606. switch (lstOptions.getSelectedIndex()) {
  607. case 0:
  608. selectedType = Value.Type.UNDEFINED;
  609. break;
  610. case 1:
  611. selectedType = Value.Type.NUMERIC;
  612. break;
  613. case 2:
  614. selectedType = Value.Type.TEXT;
  615. break;
  616. case 3:
  617. selectedType = Value.Type.BOOLEAN;
  618. break;
  619. case 4:
  620. selectedType = Value.Type.DATE;
  621. break;
  622. case 5:
  623. selectedType = Value.Type.MATRIX;
  624. break;
  625. default:
  626. selectedType = Value.Type.UNDEFINED;
  627. break;
  628. }
  629.  
  630. OptionService.getInstance().changeMyFilter(selectedType);
  631.  
  632. // DEBUG MaterialToast.fireToast("Selected Index: " + lstOptions2.getSelectedIndex());
  633. }
  634.  
  635. @UiHandler({"lstOptions2"})
  636. void onChangeListBox2(ValueChangeEvent<String> e) {
  637.  
  638. // 0 - UNDEFINED
  639. // 1 - NUMERIC
  640. // 2 - TEXT
  641. // 3 - BOOLEAN
  642. // 4 - DATE
  643. // 5 - MATRIX
  644. Value.Type selectedType = Value.Type.UNDEFINED;
  645.  
  646. switch (lstOptions2.getSelectedIndex()) {
  647. case 0:
  648. selectedType = Value.Type.UNDEFINED;
  649. break;
  650. case 1:
  651. selectedType = Value.Type.NUMERIC;
  652. break;
  653. case 2:
  654. selectedType = Value.Type.TEXT;
  655. break;
  656. case 3:
  657. selectedType = Value.Type.BOOLEAN;
  658. break;
  659. case 4:
  660. selectedType = Value.Type.DATE;
  661. break;
  662. case 5:
  663. selectedType = Value.Type.MATRIX;
  664. break;
  665. default:
  666. selectedType = Value.Type.UNDEFINED;
  667. break;
  668. }
  669.  
  670. OptionService.getInstance().changeMyFilter(selectedType);
  671.  
  672. // DEBUG MaterialToast.fireToast("Selected Index: " + lstOptions2.getSelectedIndex());
  673. }
  674.  
  675. /**
  676. * /SEARCH N REPLACE
  677. */
  678. //======================================================================
  679. // Ra�l Correia - 1090657
  680. /**
  681. * Refresh button
  682. */
  683. @UiField
  684. MaterialIcon refreshButton;
  685.  
  686. @UiField
  687. MaterialIcon saveButton;
  688. //==============================
  689.  
  690.  
  691. /* -- Macro window content -- */
  692. @UiHandler("radioValue")
  693. void onRadioValue(ValueChangeEvent<Boolean> e) {
  694.  
  695. MaterialToast.fireToast("Color defined : " + "Red");
  696.  
  697. uiController.changeYellowExtensionColor("RED");
  698. }
  699.  
  700. @UiHandler("radioValue1")
  701. void onRadioValue1(ValueChangeEvent<Boolean> w) {
  702.  
  703. MaterialToast.fireToast("Color defined : " + "Yellow");
  704. uiController.changeYellowExtensionColor("YELLOW");
  705.  
  706. }
  707.  
  708. @UiHandler("radioValue2")
  709. void onRadioValue2(ValueChangeEvent<Boolean> w) {
  710.  
  711. MaterialToast.fireToast("Color defined : " + "Green");
  712. uiController.changeYellowExtensionColor("GREEN");
  713.  
  714. }
  715.  
  716. @UiHandler("radioValue3")
  717. void onRadioValue3(ValueChangeEvent<Boolean> w) {
  718.  
  719. MaterialToast.fireToast("Color defined : " + "Brown");
  720. uiController.changeYellowExtensionColor("BROWN");
  721.  
  722. }
  723.  
  724. @Override
  725. public MaterialButton getExportButton() {
  726. return Export;
  727. }
  728.  
  729. @Override
  730. public MaterialButton getExportXmlButton() {
  731. return Exportx;
  732. }
  733.  
  734. @Override
  735. public MaterialButton getExport1Button() {
  736. return Export1;
  737. }
  738.  
  739. @Override
  740. public MaterialButton getExportXml1Button() {
  741. return Exportm;
  742. }
  743.  
  744. @Override
  745. public MaterialButton getExport2Button() {
  746. return Export2;
  747. }
  748.  
  749. @Override
  750. public MaterialButton getExportXml2Button() {
  751. return ExportL;
  752. }
  753.  
  754. @Override
  755. public MaterialTextBox getFileName2() {
  756. return fileName2;
  757. }
  758.  
  759. @Override
  760. public MaterialTextBox getFileName1() {
  761. return fileName1;
  762. }
  763.  
  764. @Override
  765. public MaterialTextBox gettag1() {
  766. return changetagOne;
  767. }
  768.  
  769. @Override
  770. public MaterialTextBox gettag2() {
  771. return changetagTwo;
  772. }
  773.  
  774. /**
  775. *
  776. * @return
  777. */
  778. @Override
  779. public MaterialTextBox gettag3() {
  780. return changetagThree;
  781. }
  782.  
  783. @Override
  784. public MaterialTextBox gettag4() {
  785. return changetagFour;
  786. }
  787.  
  788. @Override
  789. public MaterialTextBox gettag5() {
  790. return changetagFive;
  791. }
  792.  
  793. @Override
  794. public MaterialTextBox gettag6() {
  795. return changetagSix;
  796. }
  797.  
  798. @Override
  799. public MaterialTextBox getTag1() {
  800. return changeTag1;
  801. }
  802.  
  803. @Override
  804. public MaterialTextBox getTag2() {
  805. return changeTag2;
  806. }
  807.  
  808. @Override
  809. public MaterialTextBox getTag3() {
  810. return changeTag3;
  811. }
  812.  
  813. @Override
  814. public MaterialTextBox getTag4() {
  815. return changeTag4;
  816. }
  817.  
  818. @Override
  819. public MaterialTextBox getTag5() {
  820. return changeTag5;
  821. }
  822.  
  823. @Override
  824. public MaterialTextBox getTag6() {
  825. return changeTag6;
  826. }
  827.  
  828. @Override
  829. public MaterialTextBox get1Tag() {
  830. return change1tag;
  831. }
  832.  
  833. @Override
  834. public MaterialTextBox get2Tag() {
  835. return change2tag;
  836. }
  837.  
  838. @Override
  839. public MaterialTextBox get3Tag() {
  840. return change3tag;
  841. }
  842.  
  843. @Override
  844. public MaterialTextBox get4Tag() {
  845. return change4tag;
  846. }
  847.  
  848. @Override
  849. public MaterialTextBox get5Tag() {
  850. return change5tag;
  851. }
  852.  
  853. @Override
  854. public MaterialTextBox get6Tag() {
  855. return change6tag;
  856. }
  857.  
  858. @Override
  859. public MaterialTextBox getMinL() {
  860. return minL;
  861. }
  862.  
  863. @Override
  864. public MaterialTextBox getMinC() {
  865. return minC;
  866. }
  867.  
  868. @Override
  869. public MaterialTextBox getMaxL() {
  870. return maxL;
  871. }
  872.  
  873. @Override
  874. public MaterialTextBox getMaxC() {
  875. return maxC;
  876. }
  877.  
  878. @Override
  879. public MaterialTextBox getFieldSeparator1() {
  880. return changeFieldSeparator1;
  881. }
  882.  
  883. @Override
  884. public MaterialTextBox getFieldSeparator() {
  885. return changeFieldSeparator;
  886. }
  887.  
  888. @Override
  889. public MaterialTextBox getFieldSeparator2() {
  890. return changeFieldSeparator2;
  891. }
  892.  
  893. @Override
  894. public MaterialTextBox getMinLinhas() {
  895. return minLinhas;
  896. }
  897.  
  898. @Override
  899. public MaterialTextBox getMaxLinhas() {
  900. return maxLinhas;
  901. }
  902.  
  903. @Override
  904. public MaterialTextBox getMaxColunas() {
  905. return maxColunas;
  906. }
  907.  
  908. @Override
  909. public MaterialTextBox getMinColunas() {
  910. return minColunas;
  911. }
  912.  
  913. @Override
  914. public MaterialTextBox getFilterFormula() {
  915. return filterFormula;
  916. }
  917.  
  918. @Override
  919. public MaterialTextBox getFilterStartCell() {
  920. return null;
  921. }
  922.  
  923. @Override
  924. public MaterialTextBox getFilterEndCell() {
  925. return null;
  926. }
  927.  
  928. @Override
  929. public MaterialTextBox getFilterColumn() {
  930. return null;
  931. }
  932.  
  933. @Override
  934. public MaterialButton getFilterApply() {
  935. return filterApply;
  936. }
  937.  
  938. @Override
  939. public MaterialButton getFilterClear() {
  940. return filterClear;
  941. }
  942.  
  943. interface Binder extends UiBinder<Widget, WorkbookView> {
  944. }
  945.  
  946. private pt.isep.nsheets.shared.core.Cell activeCell = null;
  947.  
  948. @Inject
  949. WorkbookView(Binder uiBinder) {
  950.  
  951. initWidget(uiBinder.createAndBindUi(this));
  952.  
  953. Extension[] extension_vec = uiController.getAllExtensions();
  954. for (int i = 0; i < extension_vec.length; i++) {
  955. material_list_extension.addItem(extension_vec[i].getExtensionType());
  956. }
  957. material_list_extension.addSelectionHandler(selectionEvent -> {
  958. String extension = material_list_extension.getSingleValue();
  959. if (extension.equals("Cell Background")) {
  960. window.open();
  961. }
  962. if (extension.equals("Conditional Formating")) {
  963. windowFormat.open();
  964. }
  965. if (extension.equals("Border Extension")) {
  966. windowFormat.open();
  967. }
  968. if (extension.equals("Text Extension")) {
  969. windowFormat.open();
  970. }
  971. });
  972.  
  973. ExportToPDF.addClickHandler(event -> {
  974. windowPDF.open();
  975. });
  976.  
  977. startExportSpreadsheetPDF.addClickHandler(
  978. clickEvent -> {
  979. windowPDF.close();
  980. windowSpreadsheetPDF.open();
  981. }
  982. );
  983.  
  984. startExportPartialSpreadsheetPDF.addClickHandler(
  985. clickEvent -> {
  986. windowPDF.close();
  987. windowPartialSpreadsheetPDF.open();
  988. }
  989. );
  990.  
  991. functionButton.addClickHandler(event -> {
  992. languageListBox.clear();
  993. functionListBox.clear();
  994. //functionParameters.clear();
  995. List<Language> ll = new ArrayList<Language>();
  996. ll = LanguageManager.getInstance().getLanguages();
  997. for (Language lang : ll) {
  998. languageListBox.addItem(lang, lang.getName());
  999. }
  1000. windowFunctions.open();
  1001. });
  1002.  
  1003. filterApply.addClickHandler(event -> {
  1004. if (filterFormula.getText().isEmpty() || filterColumn.getText().isEmpty() || filterStartCell.getText().isEmpty() || filterEndCell.getText().isEmpty()) {
  1005. for (RowComponent<SheetCell> row : customTable.getRows()) {
  1006. MaterialToast.fireToast("Filter Cleared.");
  1007. row.setEnabled(true);
  1008. }
  1009. } else {
  1010. HashSet<Integer> rowsToHide = new HashSet<>();
  1011. if (filterController.isValidColumn(filterStartCell.getText(), filterEndCell.getText(), filterColumn.getText())) {
  1012. filterColumn.clearErrorOrSuccess();
  1013. try {
  1014. filterController.filter(filterStartCell.getText(), filterEndCell.getText(), filterColumn.getText(), WorkbookManager.getInstance().getCurrentActiveWorkbook().getSpreadsheet(0), filterFormula.getText(), rowsToHide);
  1015. filterFormula.setSuccess("Filtered the column: " + filterColumn.getText());
  1016. filterColumn.clearErrorOrSuccess();
  1017. } catch (FormulaCompilationException ex) {
  1018. filterFormula.setError("Invalid Formula.");
  1019. } catch (IllegalValueTypeException ex) {
  1020. filterFormula.setError("Could not apply a boolean formula to a Cell.");
  1021. }
  1022. } else {
  1023. filterColumn.setError("This column does not belong in the specified range.");
  1024. }
  1025. rowsToHide.forEach((i) -> {
  1026. MaterialToast.fireToast("Disable the row: " + i);
  1027. customTable.getRow(i).setEnabled(false);
  1028. });
  1029. }
  1030. });
  1031.  
  1032. filterClear.addClickHandler(event -> {
  1033. filterFormula.clear();
  1034. for (RowComponent<SheetCell> row : customTable.getRows()) {
  1035. row.setEnabled(true);
  1036. }
  1037. });
  1038.  
  1039. selLang.addClickHandler(event -> {
  1040. finalFunction = null;
  1041. finalOperator = null;
  1042. windowFunctions.remove(parameter1);
  1043. windowFunctions.remove(parameter2);
  1044. for (MaterialTextBox text : texts) {
  1045. windowFunctions.remove(text);
  1046. }
  1047. texts.clear();
  1048. windowFunctions.remove(buttonApply);
  1049. windowFunctions.remove(buttonCheck);
  1050. windowFunctions.remove(finalResult);
  1051. functionListBox.clear();
  1052. //functionParameters.clear();
  1053. //operatorListBox.clear();
  1054. Language l = languageListBox.getSelectedValue();
  1055. List<Function> lf = new ArrayList<Function>();
  1056. List<Operator> lo = new ArrayList<Operator>();
  1057. UnaryOperator[] uo = l.getUnaryOperators();
  1058. BinaryOperator[] bo = l.getBinaryOperators();
  1059. NaryOperator[] no = l.getNaryOperators();
  1060. Function[] f = l.getFunctions();
  1061. for (int i = 0; i < uo.length; i++) {
  1062. lo.add(uo[i]);
  1063. }
  1064. for (int i = 0; i < bo.length; i++) {
  1065. lo.add(bo[i]);
  1066. }
  1067. for (int i = 0; i < no.length; i++) {
  1068. lo.add(no[i]);
  1069. }
  1070. for (int i = 0; i < f.length; i++) {
  1071. lf.add(f[i]);
  1072. }
  1073. for (Function func : lf) {
  1074. functionListBox.addItem(func, func.getIdentifier());
  1075. }
  1076. for (Operator operator : lo) {
  1077. operatorListBox.addItem(operator, operator.getIdentifier());
  1078. }
  1079. //result.setText("Este é o resultado");
  1080. // Function func = functionListBox.getSelectedValue();
  1081. // String parameters = l.getStarter() + func.getIdentifier() + "(";
  1082. // FunctionParameter[] fp = func.getParameters();
  1083. // for (int i = 0; i < fp.length; i++) {
  1084. // if (i < fp.length - 1) {
  1085. // parameters += fp[i].getValueType() + ";";
  1086. // } else {
  1087. // parameters += fp[i].getValueType();
  1088. // }
  1089. // }
  1090. // parameters += ")";
  1091. // functionParameters.setValue(parameters);
  1092.  
  1093. });
  1094.  
  1095. selFunction.addClickHandler(event -> {
  1096. finalOperator = null;
  1097. windowFunctions.remove(ms);
  1098. windowFunctions.remove(ms2);
  1099. windowFunctions.remove(ms3);
  1100. windowFunctions.remove(parameter1);
  1101. windowFunctions.remove(parameter2);
  1102. for (MaterialTextBox text : texts) {
  1103. windowFunctions.remove(text);
  1104. }
  1105. texts.clear();
  1106. parameters = "";
  1107. nParameters = 0;
  1108. finalFunction = functionListBox.getSelectedValue();
  1109. // Language l = languageListBox.getSelectedValue();
  1110. // stringT = l.getStarter() + func.getIdentifier() + "(" + parameters + ")";
  1111. //functionParameters.setValue(stringT);
  1112. // String parameters = l.getStarter() + func.getIdentifier() + "(";
  1113. FunctionParameter[] fp = finalFunction.getParameters();
  1114. for (int i = 0; i < fp.length; i++) {
  1115. MaterialTextBox mtb = new MaterialTextBox();
  1116. mtb.setLabel("parameter" + (i + 1));
  1117. texts.add(mtb);
  1118. }
  1119. windowFunctions.add(ms);
  1120. windowFunctions.add(ms2);
  1121. windowFunctions.add(ms3);
  1122. for (MaterialTextBox b : texts) {
  1123. windowFunctions.add(b);
  1124. }
  1125.  
  1126. windowFunctions.add(buttonApply);
  1127. windowFunctions.add(buttonCheck);
  1128. finalResult.setText("This is result");
  1129. windowFunctions.add(finalResult);
  1130. // parameters += ")";
  1131. // functionParameters.setValue(parameters);
  1132.  
  1133. });
  1134.  
  1135. selButton.addClickHandler(event -> {
  1136. finalFunction = null;
  1137. windowFunctions.remove(ms);
  1138. windowFunctions.remove(ms2);
  1139. windowFunctions.remove(ms3);
  1140. windowFunctions.remove(parameter1);
  1141. windowFunctions.remove(parameter2);
  1142. for (MaterialTextBox text : texts) {
  1143. windowFunctions.remove(text);
  1144. }
  1145. texts.clear();
  1146. parameters = "";
  1147. nParameters = 0;
  1148. parameter1.setLabel("parameter1");
  1149. parameter2.setLabel("parameter2");
  1150. finalOperator = operatorListBox.getSelectedValue();
  1151. windowFunctions.add(ms);
  1152. windowFunctions.add(ms2);
  1153. windowFunctions.add(ms3);
  1154. windowFunctions.add(parameter1);
  1155. windowFunctions.add(parameter2);
  1156. windowFunctions.add(buttonApply);
  1157. windowFunctions.add(buttonCheck);
  1158. finalResult.setText("This is result");
  1159. windowFunctions.add(finalResult);
  1160. });
  1161.  
  1162. // selPara.addClickHandler(event -> {
  1163. // String para = enterPara.getText();
  1164. // Function func = functionListBox.getSelectedValue();
  1165. // Language l = languageListBox.getSelectedValue();
  1166. // if (nParameters == 0) {
  1167. // parameters = para;
  1168. // nParameters++;
  1169. // } else {
  1170. // parameters = parameters + ";" + para;
  1171. // nParameters++;
  1172. // }
  1173. // stringT = l.getStarter() + func.getIdentifier() + "(" + parameters + ")";
  1174. // functionParameters.setValue(stringT);
  1175. // });
  1176. buttonCheck.addClickHandler(event -> {
  1177. if(finalFunction != null){
  1178. String text = "";
  1179. //Function f = functionListBox.getSelectedValue();
  1180. Language l = languageListBox.getSelectedValue();
  1181. int i = 0;
  1182. for (MaterialTextBox texttttt : texts) {
  1183. if (i == 0) {
  1184. parameters = texttttt.getText();
  1185. i++;
  1186. } else {
  1187. parameters = parameters + ";" + texttttt.getText();
  1188. }
  1189. }
  1190. stringT = l.getStarter() + finalFunction.getIdentifier() + "(" + parameters + ")";
  1191. Spreadsheet s = new SpreadsheetImpl();
  1192. try {
  1193. CellImpl cell = new CellImpl(s, new Address(), stringT);
  1194. finalResult.setTextColor(Color.GREEN);
  1195. text = cell.getValue().toString();
  1196.  
  1197. } catch (FormulaCompilationException ex) {
  1198. finalResult.setTextColor(Color.RED);
  1199. text = ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage();
  1200. }
  1201. finalResult.setText(text);
  1202. } else if(finalOperator != null){
  1203. String text = "";
  1204. Language l = languageListBox.getSelectedValue();
  1205. stringT = l.getStarter()+parameter1.getText()+finalOperator+parameter2.getText();
  1206. Spreadsheet s = new SpreadsheetImpl();
  1207. try {
  1208. CellImpl cell = new CellImpl(s, new Address(), stringT);
  1209. finalResult.setTextColor(Color.GREEN);
  1210. text = cell.getValue().toString();
  1211.  
  1212. } catch (FormulaCompilationException ex) {
  1213. finalResult.setTextColor(Color.RED);
  1214. text = ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage();
  1215. }
  1216. finalResult.setText(text);
  1217. }
  1218. });
  1219. buttonApply.addClickHandler(event -> {
  1220. if(finalFunction != null){
  1221. String text = "";
  1222. //Function f = functionListBox.getSelectedValue();
  1223. Language l = languageListBox.getSelectedValue();
  1224. int i = 0;
  1225. for (MaterialTextBox texttttt : texts) {
  1226. if (i == 0) {
  1227. parameters = texttttt.getText();
  1228. i++;
  1229. } else {
  1230. parameters = parameters + ";" + texttttt.getText();
  1231. }
  1232. }
  1233. stringT = l.getStarter() + finalFunction.getIdentifier() + "(" + parameters + ")";
  1234. }else if(finalOperator != null){
  1235. String text = "";
  1236. Language l = languageListBox.getSelectedValue();
  1237. stringT = l.getStarter()+parameter1.getText()+finalOperator+parameter2.getText();
  1238. }
  1239. firstBox.setText(stringT);
  1240. windowFunctions.close();
  1241. });
  1242.  
  1243. ExportToXML.addClickHandler(event -> {
  1244. windowXML.open();
  1245. });
  1246.  
  1247. ExportToCSV.addClickHandler(event -> {
  1248. windowCSV.open();
  1249. });
  1250.  
  1251. // Opens pop-up
  1252. secondtButton.addClickHandler(event -> {
  1253.  
  1254. window.open();
  1255.  
  1256. });
  1257.  
  1258. searchNReplace_btn.addClickHandler(event -> {
  1259.  
  1260. searchNReplace_window.open();
  1261.  
  1262. });
  1263.  
  1264. sortButton.addClickHandler(
  1265. clickEvent -> {
  1266. janela.open();
  1267. }
  1268. );
  1269. startExportWorkbookCSV.addClickHandler(
  1270. clickEvent -> {
  1271. windowCSV.close();
  1272. windowWorkbook.open();
  1273. }
  1274. );
  1275.  
  1276. startExportSpreadsheetCSV.addClickHandler(
  1277. clickEvent -> {
  1278. windowCSV.close();
  1279. windowSpreadsheet.open();
  1280. }
  1281. );
  1282.  
  1283. startExportPartOfSpreadsheetCSV.addClickHandler(
  1284. clickEvent -> {
  1285. windowCSV.close();
  1286. windowPart.open();
  1287. }
  1288. );
  1289. startExportWorkbookXML.addClickHandler(
  1290. clickEvent -> {
  1291. windowXML.close();
  1292. windowWorkbook1.open();
  1293. }
  1294. );
  1295. startExportSpreadsheetXML.addClickHandler(
  1296. clickEvent -> {
  1297. windowXML.close();
  1298. windowSpreadsheet1.open();
  1299. }
  1300. );
  1301. startExportPartOfSpreadsheetXML.addClickHandler(
  1302. clickEvent -> {
  1303. windowXML.close();
  1304. windowPart1.open();
  1305. }
  1306. );
  1307.  
  1308. firstButton.addClickHandler(event -> {
  1309. if (activeCell != null) {
  1310. String result = "";
  1311. try {
  1312. activeCell.setContent(firstBox.getText());
  1313. } catch (FormulaCompilationException e) {
  1314. // TODO Auto-generated catch block
  1315. // YellowExtension.printStackTrace();
  1316. result = e.getMessage();
  1317. } finally {
  1318. // resultLabel.setText(result);
  1319.  
  1320. // refresh the table...
  1321. customTable.getView().setRedraw(true);
  1322. customTable.getView().refresh();
  1323.  
  1324. // refresh the active cell
  1325. //
  1326. //this.setActiveCell(activeCell, widget);
  1327. SpreadSheetSingleton.getInstance().wb = activeCell.getSpreadsheet().getWorkbook();
  1328. }
  1329. }
  1330. // Window.alert("Hello");
  1331. });
  1332.  
  1333. /*
  1334. * Macro window button click handlers (@author Pedro Emanuel Coelho
  1335. * 1131485@isep.ipp.pt )
  1336. */
  1337. //Event when user changes the index on listbox
  1338. macroList.addValueChangeHandler(selectEvent -> {
  1339.  
  1340. MaterialToast.fireToast("Selected Macro : " + macroList.getSelectedValue().name());
  1341.  
  1342. });
  1343.  
  1344. macroButton.addClickHandler(clickEvent -> {
  1345. MacroLanguageController ctrl = new MacroLanguageController();
  1346.  
  1347. macroWindow.setTitle("Macro Window - NSHEETS");
  1348.  
  1349. macroList.clear();
  1350.  
  1351. Macro macro = new Macro("MACRO321");
  1352.  
  1353. macro.addCommand("3+3\n2*2\n;one comment\nsum(E1:E3)\n{3+3;2*2;6*4}");
  1354.  
  1355. macroList.addItem(macro, macro.toString());
  1356.  
  1357. langList.clear();
  1358.  
  1359. for (MacroLanguage l : ctrl.getAllMacroLanguages()) {
  1360.  
  1361. langList.addItem(l, l.getName());
  1362.  
  1363. }
  1364.  
  1365. MaterialToast.fireToast("TOTAL OF MACROS LOADED : " + macroList.getItemCount());
  1366.  
  1367. if (!macro.commands().isEmpty()) {
  1368. macroCommands.setText(macro.commands());
  1369. }
  1370.  
  1371. macroWindow.open();
  1372. macroWindow2.close();
  1373. });
  1374.  
  1375. //button that changes the macro language
  1376. langButton.addClickHandler(event -> {
  1377.  
  1378. Macro m = macroList.getSelectedValue();
  1379.  
  1380. int i = macroList.getSelectedIndex();
  1381.  
  1382. m.resetMacro();
  1383.  
  1384. macroCommands.setText("");
  1385.  
  1386. Language l = langList.getSelectedValue();
  1387.  
  1388. m.changeLanguage(l);
  1389.  
  1390. MaterialToast.fireToast("Macro language changed to " + m.language().getName());
  1391.  
  1392. macroList.removeItem(i);
  1393.  
  1394. macroList.addItem(m, m.toString());
  1395.  
  1396. macroList.reload();
  1397. });
  1398.  
  1399. /**
  1400. * Rui Almeida <1160818> Lang 07.2 - Visual Basic Macro Call
  1401. * START
  1402. * =========================================================
  1403. */
  1404.  
  1405. /**
  1406. * Saves a macro to wb event
  1407. */
  1408. saveMacro.addClickHandler(event -> {
  1409.  
  1410. if (saveMacroName.getText().isEmpty()) {
  1411. MaterialToast.fireToast("Macro name is empty!");
  1412. } else {
  1413. if (macroCommands.getText().isEmpty()) {
  1414. MaterialToast.fireToast("There are no commands to add to the macro!");
  1415. } else {
  1416. Macro macro = new Macro(saveMacroName.getText());
  1417. macro.addCommand(macroCommands.getText());
  1418.  
  1419. boolean flag = false;
  1420.  
  1421. for (Macro m : wb.macros()) {
  1422. if (m.name().equalsIgnoreCase(saveMacroName.getText())) {
  1423. flag = true;
  1424. }
  1425. }
  1426.  
  1427. if (!flag) {
  1428. if (wb.addMacro(macro)) {
  1429. MaterialToast.fireToast("Macro " + macro.name() + " added to the workbook.");
  1430. saveMacroName.clear();
  1431. macroCommands.clear();
  1432. }
  1433. } else {
  1434. if (flag) {
  1435. MaterialToast.fireToast("Could not add macro: name already exists!");
  1436. } else {
  1437. MaterialToast.fireToast("Could not add macro!");
  1438. }
  1439. }
  1440. }
  1441. }
  1442. });
  1443.  
  1444. /**
  1445. * View all saved macros event
  1446. */
  1447. viewMacros.addClickHandler(event -> {
  1448. StringBuilder s = new StringBuilder();
  1449. s.append("LIST OF MACROS\n================\n");
  1450. for (Macro m : wb.macros()) {
  1451. s.append("Macro name: " + m.name() + "\n" + "Macro commands: " + m.commands() + "\n----\n");
  1452. }
  1453. Window.alert(s.toString());
  1454. });
  1455.  
  1456. /**
  1457. * Removes a macro from wb
  1458. */
  1459. removeMacro.addClickHandler(event -> {
  1460. String macroName = saveMacroName.getText();
  1461.  
  1462. if (wb.removeMacro(macroName)) {
  1463. MaterialToast.fireToast("Macro " + macroName + " was removed with success.");
  1464. } else {
  1465. MaterialToast.fireToast("Could not find/delete macro " + macroName + "!");
  1466. }
  1467. });
  1468.  
  1469. /**
  1470. * Lang 07.2 MACRO CALL
  1471. * END
  1472. * =========================================================
  1473. */
  1474.  
  1475.  
  1476. executeMacro.addClickHandler(event -> {
  1477.  
  1478. Macro macro = macroList.getSelectedValue();
  1479.  
  1480. macro.addCommand(macroCommands.getText());
  1481.  
  1482. ExpressionCompiler compiler = MacroCompilerManager.getInstance().getCompiler(macro.language().getName());
  1483.  
  1484. try {
  1485. Expression expression = compiler.compile(activeCell, macro.commands());
  1486.  
  1487. Value value = expression.evaluate();
  1488.  
  1489. activeCell.setContent(value.toString());
  1490. customTable.getView().setRedraw(true);
  1491. customTable.getView().refresh();
  1492.  
  1493. MaterialToast.fireToast("Result of Macro : " + value.toString()); //to show on Window, as requirement
  1494.  
  1495. } catch (FormulaCompilationException | IllegalValueTypeException ex) {
  1496. MaterialToast.fireToast(ex.getMessage());
  1497. }
  1498. });
  1499.  
  1500. resetMacro.addClickHandler(event -> {
  1501.  
  1502. macroList.reload();
  1503.  
  1504. Macro m = macroList.getSelectedValue();
  1505.  
  1506. m.resetMacro();
  1507.  
  1508. macroCommands.setText("");
  1509.  
  1510. MaterialToast.fireToast("Reset on macro done with sucess!");
  1511.  
  1512. //persist workbook
  1513. });
  1514.  
  1515. /* -- MACRO WINDOW HANDLERS -- */
  1516.  
  1517. /*
  1518. * Search window button click handlers (@author David Camelo
  1519. * <1161294@isep.ipp.pt>)
  1520. */
  1521. searchButton.addClickHandler(clickEvent -> {
  1522. final String EMPTY = "";
  1523.  
  1524. outputOfSearch.setText(EMPTY);
  1525. regExpressionTextBox.setText(EMPTY);
  1526.  
  1527. popUpView.open();
  1528. });
  1529.  
  1530.  
  1531. /*.addClickHandler(clickEvent -> {
  1532. final String EMPTY = "";
  1533.  
  1534. outputOfSearch.setText(EMPTY);
  1535. regExpressionTextBox.setText(EMPTY);
  1536.  
  1537. popUpView.open();
  1538. });
  1539. */
  1540. startExportWorkbookPDF.addClickHandler(clickEvent -> {
  1541. // Window.alert("Not Suported Yet!");
  1542. WorkbookDTO wbDTO = wb.toDTO();
  1543. List<Spreadsheet> list = wb.getSpreadSheets();
  1544. List<SpreadsheetDTO> listDTO = new ArrayList<>();
  1545.  
  1546. for (Spreadsheet s : list) {
  1547. SpreadsheetDTO sDTO = s.toDTO();
  1548. String[][] lul = new String[s.getRowCount()][s.getColumnCount()];
  1549.  
  1550. for (int i = 0; i < s.getRowCount(); i++) {
  1551. for (int j = 0; j < s.getColumnCount(); j++) {
  1552. String ze = s.getCell(j, i).getContent();
  1553. lul[i][j] = ze;
  1554. }
  1555. }
  1556.  
  1557. sDTO.setContent(lul);
  1558. wbDTO.getSpreadsheets().add(sDTO);
  1559. }
  1560.  
  1561. MaterialToast.fireToast("Numero sheets "+wbDTO.getCreatedSpreadsheets());
  1562.  
  1563.  
  1564. // ExportToPDFServiceAsync exportPDF = GWT.create(ExportToPDFService.class);
  1565. // AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {
  1566. // @Override
  1567. // public void onFailure(Throwable caught) {
  1568. // MaterialToast.fireToast("An internal error has occurred while exporting to pdf! " + caught.getMessage());
  1569. // }
  1570. //
  1571. // @Override
  1572. // public void onSuccess(Boolean result) {
  1573. // if(result == true){
  1574. // MaterialToast.fireToast("Export to PDF successful!");
  1575. // }else if(result == false){
  1576. // MaterialToast.fireToast("Export to PDF failed");
  1577. // }
  1578. // }
  1579. //
  1580. // };
  1581. // exportPDF.exportWorkbookToPDF(wb, fileName.getText(), callback);
  1582. });
  1583.  
  1584. ExportSpreadsheetPDF.addClickHandler(clickEvent -> {
  1585. //Window.alert("Not Suported Yet!");
  1586.  
  1587. Spreadsheet s = activeCell.getSpreadsheet();
  1588. SpreadsheetDTO sDTO = s.toDTO();
  1589. String[][] lul = new String[s.getRowCount()][s.getColumnCount()];
  1590.  
  1591. for (int i = 0; i < s.getRowCount(); i++) {
  1592. for (int j = 0; j < s.getColumnCount(); j++) {
  1593. String ze = s.getCell(j, i).getContent().toString();
  1594. lul[i][j] = ze;
  1595. }
  1596. }
  1597.  
  1598. sDTO.setContent(lul);
  1599. MaterialToast.fireToast("Titulo 2");
  1600.  
  1601. MaterialToast.fireToast("Titulo "+sDTO.getTitle());
  1602.  
  1603. // MaterialToast.fireToast("lel1");
  1604. // SpreadsheetDTO s2 = s.toDTO();
  1605. // MaterialToast.fireToast("lel1"+s.getRowCount());
  1606. // MaterialToast.fireToast("lel2"+s2.getRows());
  1607. // ExportToPDFServiceAsync exportPDF = GWT.create(ExportToPDFService.class);
  1608. // AsyncCallback<String> callback = new AsyncCallback<String>() {
  1609. // @Override
  1610. // public void onFailure(Throwable caught) {
  1611. // MaterialToast.fireToast("An internal error has occurred while exporting to pdf! " + caught.getMessage());
  1612. // }
  1613. //
  1614. // @Override
  1615. // public void onSuccess(String result) {
  1616. // if(result == true){
  1617. // MaterialToast.fireToast("Export to PDF successful!");
  1618. // }else if(result == false){
  1619. // MaterialToast.fireToast("Export to PDF failed");
  1620. // }
  1621. // HTML downloadLink = new HTML("<a href=\""+result+"\">Download</a>");
  1622. // MaterialToast.fireToast(result);
  1623.  
  1624. // }
  1625. //
  1626. // };
  1627. // exportPDF.exportSpreadsheetToPDF(sDTO, fileName.getText(), callback);
  1628. });
  1629.  
  1630. ExportPartialSpreadsheetPDF.addClickHandler(clickEvent -> {
  1631. // Window.alert("Not Suported Yet!");
  1632. MaterialToast.fireToast(posicao1.getText().charAt(0)-64+"");
  1633. MaterialToast.fireToast(posicao1.getText().charAt(1) +"");
  1634. MaterialToast.fireToast(posicao2.getText().charAt(0)-64+"");
  1635. MaterialToast.fireToast(posicao2.getText().charAt(1)+"");
  1636.  
  1637. Spreadsheet s = activeCell.getSpreadsheet();
  1638. SpreadsheetDTO sDTO = s.toDTO();
  1639. String[][] lul = new String[s.getRowCount()][s.getColumnCount()];
  1640.  
  1641. for (int i = 0; i < s.getRowCount(); i++) {
  1642. for (int j = 0; j < s.getColumnCount(); j++) {
  1643. String ze = s.getCell(j, i).getContent().toString();
  1644. lul[i][j] = ze;
  1645. }
  1646. }
  1647.  
  1648. sDTO.setContent(lul);
  1649. MaterialToast.fireToast("Titulo Partial");
  1650.  
  1651.  
  1652. MaterialToast.fireToast("Titulo "+sDTO.getTitle());
  1653. // Spreadsheet s = activeCell.getSpreadsheet().getWorkbook().getSpreadsheet(SpreadsheetNumber1.getText());
  1654. // ExportToPDFServiceAsync exportPDF = GWT.create(ExportToPDFService.class);
  1655. // AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {
  1656. // @Override
  1657. // public void onFailure(Throwable caught) {
  1658. // MaterialToast.fireToast("An internal error has occurred while exporting to pdf! " + caught.getMessage());
  1659. // }
  1660. //
  1661. // @Override
  1662. // public void onSuccess(Boolean result) {
  1663. // if(result.booleanValue() == true){
  1664. // MaterialToast.fireToast("Export to PDF successful!");
  1665. // }else if(result.booleanValue() == false){
  1666. // MaterialToast.fireToast("Export to PDF failed");
  1667. // }
  1668. // }
  1669. //
  1670. // };
  1671. // exportPDF.exportPartOfSpreadSheet(s, fileName.getText(), posicao1.getText().charAt(0)-64, posicao1.getText().charAt(1), posicao2.getText().charAt(0)-64, posicao2.getText().charAt(1));
  1672. });
  1673.  
  1674. sendRegExpression.addClickHandler(clickEvent -> {
  1675.  
  1676. Spreadsheet sh_test = activeCell.getSpreadsheet();
  1677.  
  1678. // ------------------------ TEMP. SOLUTION ------------------------------------
  1679. Window.alert("Number os spreadSheets before:" + sh_test.getWorkbook().getSpreadsheetCount());
  1680.  
  1681. String contents[][] = { // second spreadsheet
  1682. /* A B C D E F G */
  1683. {"1", "-1", "1", "1", "2", "2", "3"}, //1
  1684. {"5", "3", "1", "-1", "-4", "3", "2"}, // 2
  1685. {"1", "-2", "3", "-2", "5", "-1", "-2"}}; // 3
  1686.  
  1687. try {
  1688. sh_test.getWorkbook().addSpreadsheet(contents);
  1689. } catch (Exception e) {
  1690. e.printStackTrace();
  1691. }
  1692.  
  1693. Window.alert("Number os spreadSheets after:" + sh_test.getWorkbook().getSpreadsheetCount());
  1694.  
  1695. // ------------------------ TEMP. SOLUTION ------------------------------------
  1696. if (regExpressionTextBox.getText().equals("")) {
  1697. MaterialToast.fireToast("Textbox empty");
  1698. } else {
  1699. final String NEW_LINE = "\n";
  1700. final String EMPTY = "";
  1701.  
  1702. outputOfSearch.setText(EMPTY);
  1703.  
  1704. OptionService.getInstance().setMyWb(sh_test.getWorkbook());
  1705. OptionService.getInstance().setMySS(sh_test);
  1706.  
  1707. startSearch(sh_test, 0, 0);
  1708.  
  1709. }
  1710.  
  1711. if (outputOfSearch.equals("")) {
  1712. MaterialToast.fireToast("Nothing Found with regex:" + regExpressionTextBox.getText());
  1713. outputOfSearch.setText("Nothing found...");
  1714. }
  1715. });
  1716. /* -- Search window button click handlers -- */
  1717.  
  1718. /* SEARCH N REPLACE - DAVID BLANQUETT<1161018@isep.ipp.pt> */
  1719. startSearchNReplace.addClickHandler(clickEvent -> {
  1720.  
  1721.  
  1722. /* Checks if the textboxes are empty. */
  1723. if (checkUIDetails(regExpressionTextBox2, regExpressionTextBox3)) {
  1724.  
  1725.  
  1726. /* UI DETAILS : RESETS CBOX TO DEFAULT VALUE */
  1727. cbYes.setValue(true);
  1728.  
  1729. searchNReplace(activeCell.getSpreadsheet());
  1730.  
  1731. }
  1732.  
  1733. });
  1734. /* /SEARCH N REPLACE - DAVID BLANQUETT<1161018@isep.ipp.pt> */
  1735.  
  1736. /* -- Search window button click handlers -- */
  1737. // It is possible to create your own custom renderer per table
  1738. // When you use the BaseRenderer you can override certain draw
  1739. // methods to create elements the way you would like.
  1740. customTable.getView().setRenderer(new SheetRenderer<SheetCell>());
  1741.  
  1742. /* conditional format window (@author Beatriz Ferreira <1160701@isep.ipp.pt>)*/
  1743. ConditionalFormatView cf = new ConditionalFormatView();
  1744. List<BinaryOperator> operators = cf.listBinaryOperations();
  1745. List<Color> colors = cf.listColor();
  1746. List<Style.BorderStyle> borders = cf.listBorders();
  1747. for (Color c : colors) {
  1748. listColors.addItem(c);
  1749. listColors2.addItem(c);
  1750. listColors3.addItem(c);
  1751. listColors4.addItem(c);
  1752.  
  1753. }
  1754.  
  1755. for (BinaryOperator b : operators) {
  1756. conditional.addItem(b);
  1757. conditional2.addItem(b);
  1758. conditional3.addItem(b);
  1759. }
  1760.  
  1761. for (Style.BorderStyle border : borders) {
  1762. listBorder.addItem(border);
  1763. listBorder2.addItem(border);
  1764. }
  1765.  
  1766. /* conditional format window (@author Beatriz Ferreira <1160701@isep.ipp.pt>)*/
  1767. conditionalFormat.addClickHandler(event -> {
  1768. if (activeCell != null) {
  1769. windowFormat.open();
  1770. String cellInfo = "Atual Cell: " + activeCell.toString() + " Content:" + activeCell.getContent();
  1771. MaterialToast.fireToast(cellInfo);
  1772. }
  1773.  
  1774. });
  1775.  
  1776. /* conditional format window (@author Beatriz Ferreira <1160701@isep.ipp.pt>)*/
  1777. confirmConditional.addClickHandler(event -> {
  1778. if (activeCell != null) {
  1779. BinaryOperator operator = conditional.getSingleValue();
  1780. String n = numberConditional.getValue();
  1781.  
  1782. Color cT = listColors.getSingleValue();
  1783. Color cF = listColors2.getSingleValue();
  1784.  
  1785. cf.setBackgroundColor(activeCell, operator, n, cT, cF, widget);
  1786.  
  1787. windowFormat.close();
  1788.  
  1789. }
  1790. });
  1791.  
  1792. /* conditional format window (@author Beatriz Ferreira <1160701@isep.ipp.pt>)*/
  1793. confirmConditional2.addClickHandler(event -> {
  1794. if (activeCell != null) {
  1795. BinaryOperator operator = conditional2.getSingleValue();
  1796. String n = numberConditional2.getValue();
  1797.  
  1798. Style.BorderStyle bT = listBorder.getSingleValue();
  1799. Style.BorderStyle bF = listBorder2.getSingleValue();
  1800.  
  1801. cf.setBorderStyle(activeCell, operator, n, bT, bF, widget);
  1802. windowFormat.close();
  1803. }
  1804. });
  1805.  
  1806. /* conditional format window (@author Beatriz Ferreira <1160701@isep.ipp.pt>)*/
  1807. confirmConditional3.addClickHandler(event -> {
  1808. if (activeCell != null) {
  1809. BinaryOperator operator = conditional3.getSingleValue();
  1810. String n = numberConditional3.getValue();
  1811.  
  1812. Color cT = listColors3.getSingleValue();
  1813. Color cF = listColors4.getSingleValue();
  1814.  
  1815. cf.setTextColor(activeCell, operator, n, cT, cF, widget);
  1816. windowFormat.close();
  1817.  
  1818. }
  1819. });
  1820.  
  1821. removeConditionalFormat.addClickHandler(event -> {
  1822. if (activeCell != null) {
  1823.  
  1824. widget.setBackgroundColor(Color.TRANSPARENT);
  1825. widget.setTextColor(Color.BLACK);
  1826. widget.setBorder(Style.BorderStyle.NONE.getCssName());
  1827. setActiveCell(activeCell, widget);
  1828.  
  1829. MaterialToast.fireToast("Delete Sucess!");
  1830.  
  1831. }
  1832.  
  1833. }
  1834. );
  1835.  
  1836. /**
  1837. * 1090657 possible way to get currentActiveCell
  1838. *
  1839. */
  1840. initWorkbook();
  1841.  
  1842. // Set the visible range of the table for pager (later)
  1843. customTable.setVisibleRange(0, 2001);
  1844.  
  1845. // Configure the tables long press duration configuration.
  1846. // The short press is when a click is held less than this duration.
  1847. customTable.setLongPressDuration(400);
  1848.  
  1849. customTable.addRowContextMenuHandler(event -> {
  1850. // Firing Row Context will automatically select the row where it was right
  1851. // clicked
  1852. customTable.selectRow($(event.getRow()).asElement(), true);
  1853. popupMenu.setSelected(event.getModel());
  1854. // Get the PageX and getPageY
  1855. popupMenu.setPopupPosition(event.getMouseEvent().getPageX(), event.getMouseEvent().getPageY());
  1856. popupMenu.open();
  1857. });
  1858.  
  1859. // Added access to ToolPanel to add icon widget
  1860. Panel panel = customTable.getScaffolding().getToolPanel();
  1861. panel.clear();
  1862. panel.setVisible(false);
  1863.  
  1864. customTable.getTableTitle().setText("The Future Worksheet!");
  1865. /**
  1866. * 1090657 Ra�l Correia Adding a refresh button to see current workbook
  1867. */
  1868. refreshButton.addClickHandler(event
  1869. -> {
  1870.  
  1871. int size = customTable.getColumns().size();
  1872. for (int i = 0; i < size; i++) {
  1873. customTable.removeColumn(0);
  1874. }
  1875. Workbook wb = WorkbookManager.getInstance().getCurrentActiveWorkbook();
  1876. if (wb != null) {
  1877.  
  1878. Spreadsheet sh = wb.getSpreadsheet(0);
  1879.  
  1880. int columnNumber = 0;
  1881.  
  1882. // Add the columns...
  1883. customTable.addColumn(new SheetWidgetColumn(-1, this));
  1884. for (int i = 0; i < sh.getColumnCount(); ++i) {
  1885.  
  1886. // Add a column for the column :-)
  1887. customTable.addColumn(new SheetWidgetColumn(columnNumber, this));
  1888.  
  1889. ++columnNumber;
  1890. }
  1891.  
  1892. // int rowIndex = 0;
  1893. List<SheetCell> rows = new ArrayList<>();
  1894. for (int k = 0; k < sh.getRowCount(); k++) {
  1895. rows.add(new SheetCell(sh, k));
  1896. }
  1897. customTable.setRowData(0, rows);
  1898. customTable.getView().setRedraw(true);
  1899. customTable.getView().refresh();
  1900. }
  1901. }
  1902. );
  1903. saveButton.addClickHandler(event -> {
  1904. Workbook wb = WorkbookManager.getInstance().getCurrentActiveWorkbook();
  1905. if (wb != null) {
  1906. WorkbookDescriptionDTO currentdto = WorkbookManager.getInstance().getCurrentDescription();
  1907. WorkbookDescriptionDTO novoDTO = new WorkbookDescriptionDTO(currentdto.getName(), currentdto.getDescription(), wb);
  1908.  
  1909. WorkbooksServiceAsync wbservice = GWT.create(WorkbooksService.class);
  1910. AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {
  1911. @Override
  1912. public void onFailure(Throwable caught) {
  1913. MaterialToast.fireToast("There were problems....");
  1914. }
  1915.  
  1916. @Override
  1917. public void onSuccess(Boolean result) {
  1918. if (result) {
  1919. MaterialToast.fireToast("Saved the workbook successfully!");
  1920. } else {
  1921. MaterialToast.fireToast("Failed saving workbook.");
  1922. }
  1923. }
  1924. };
  1925.  
  1926. wbservice.saveWorkbook(novoDTO, callback);
  1927. }
  1928. });
  1929. }
  1930.  
  1931. private void startSearch(Spreadsheet sh_test, int row, int col) {
  1932.  
  1933. if (col == -1) {
  1934. Window.alert("Search Ended.");
  1935.  
  1936. return;
  1937.  
  1938. }
  1939.  
  1940. SearchServiceAsync searchService = GWT.create(SearchService.class);
  1941. AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {
  1942.  
  1943. @Override
  1944. public void onFailure(Throwable throwable) {
  1945. MaterialToast.fireToast("Impossible to search: " + throwable.getMessage());
  1946. }
  1947.  
  1948. @Override
  1949. public void onSuccess(Boolean aBoolean) {
  1950. if (aBoolean) {
  1951.  
  1952. MaterialToast.fireToast("FOUND @" + activeCell.getSpreadsheet().getCell(OptionService.getInstance().getRealCol(), OptionService.getInstance().getnRow()).toString());
  1953.  
  1954. outputOfSearch.setText(outputOfSearch.getText() + sh_test.getCell(col, row).getAddress().toString() + " @SPREADSHEET: " + OptionService.getInstance().getSheetIndex() + "\n");
  1955.  
  1956. startSearch(OptionService.getInstance().getMySS(), OptionService.getInstance().getnRow(), OptionService.getInstance().getnCol());
  1957.  
  1958. } else {
  1959.  
  1960. // DEBUG: MaterialToast.fireToast("Not found" );
  1961. startSearch(OptionService.getInstance().getMySS(), OptionService.getInstance().getnRow(), OptionService.getInstance().getnCol());
  1962.  
  1963. }
  1964.  
  1965. }
  1966. };
  1967.  
  1968. if (cellFilter(sh_test.getCell(col, row).getValue().getType())) {
  1969.  
  1970. String formula = "";
  1971. if (sh_test.getCell(col, row).getFormula() != null) {
  1972. formula = sh_test.getCell(col, row).getFormula().toString();
  1973. }
  1974.  
  1975. searchService.matchByPattern(regExpressionTextBox.getText(),
  1976. sh_test.getCell(col, row).getContent(), formula, callback);
  1977.  
  1978. } else {
  1979.  
  1980. startSearch(OptionService.getInstance().getMySS(), OptionService.getInstance().getnRow(), OptionService.getInstance().getnCol());
  1981.  
  1982. }
  1983.  
  1984. }
  1985.  
  1986. /**
  1987. * Checks if the textboxes are empty.
  1988. *
  1989. * @author: David Blanquett<1161018@isep.ipp.pt>
  1990. *
  1991. * @param regExpressionTextBox2: REGEX
  1992. * @param regExpressionTextBox3: REPLACE BY
  1993. * @return: their state of emptiness
  1994. */
  1995. private boolean checkUIDetails(MaterialTextBox regExpressionTextBox2, MaterialTextBox regExpressionTextBox3) {
  1996.  
  1997. if (regExpressionTextBox3.getText().isEmpty()) {
  1998.  
  1999. MaterialToast.fireToast("WORD BOX IS EMPTY: INSERT A TOKEN");
  2000. return false;
  2001.  
  2002. } else if (regExpressionTextBox2.getText().isEmpty()) {
  2003.  
  2004. MaterialToast.fireToast("REGEX BOX IS EMPTY: INSERT A REGULAR EXPRESSION");
  2005. return false;
  2006. }
  2007.  
  2008. return true;
  2009.  
  2010. }
  2011.  
  2012. /**
  2013. * Starts the search N Replace feature.
  2014. *
  2015. * @author: David Blanquett<1161018@isep.ipp.pt>
  2016. *
  2017. * @param sh_test: the active spreadsheet.
  2018. */
  2019. private void searchNReplace(Spreadsheet sh_test) {
  2020.  
  2021. // ------------------------ TEMP. SOLUTION ------------------------------------
  2022. Window.alert("Number os spreadSheets before:" + sh_test.getWorkbook().getSpreadsheetCount());
  2023.  
  2024. String contents[][] = { // second spreadsheet
  2025. /* A B C D E F G */
  2026. {"1", "-1", "1", "1", "2", "2", "3"}, //1
  2027. {"5", "3", "1", "-1", "-4", "3", "2"}, // 2
  2028. {"1", "-2", "3", "-2", "5", "-1", "-2"}}; // 3
  2029.  
  2030. try {
  2031. sh_test.getWorkbook().addSpreadsheet(contents);
  2032. } catch (Exception e) {
  2033. e.printStackTrace();
  2034. }
  2035.  
  2036. Window.alert("Number os spreadSheets after:" + sh_test.getWorkbook().getSpreadsheetCount());
  2037.  
  2038. // ------------------------ TEMP. SOLUTION ------------------------------------
  2039. OptionService.getInstance().setMySS(sh_test);
  2040. OptionService.getInstance().setMyWb(sh_test.getWorkbook());
  2041.  
  2042. /* starts recursive method */
  2043. next(0, 0, sh_test);
  2044.  
  2045. }
  2046.  
  2047. /**
  2048. * Recursive method: Processes if a content of a cell( spreadsheet(col,row)
  2049. * ) is described by a regex.
  2050. *
  2051. * @author: David Blanquett<1161018@isep.ipp.pt>
  2052. *
  2053. * @param col: the column
  2054. * @param row: the row
  2055. * @param sh_test: the spreadsheet
  2056. */
  2057. public void next(int col, int row, Spreadsheet sh_test) {
  2058.  
  2059. Window.alert("COL,ROW: " + sh_test.getCell(col, row).toString()); //-- DEBUG
  2060.  
  2061. /* SINCE THE METHOD IS RECURSIVE IT NEEDS A STOPPING CONDITION */
  2062. if (col == -1) {
  2063.  
  2064. Window.alert("Search N' Replaced finished.");
  2065. return;
  2066. }
  2067.  
  2068.  
  2069. /* UI DETAILS */
  2070. reg3.setText("SpreadSheet" + OptionService.getInstance().getSheetIndex() + " @ " + sh_test.getCell(new Address(col, row)).toString());
  2071. reg1.setText(sh_test.getCell(new Address(col, row)).getContent());
  2072. /* /UI DETAILS */
  2073.  
  2074.  
  2075. /* CREATES THE SEARCH SERVICE */
  2076. SearchServiceAsync searchService = GWT.create(SearchService.class
  2077. );
  2078. AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {
  2079.  
  2080. @Override
  2081. public void onFailure(Throwable throwable) {
  2082. MaterialToast.fireToast("Impossible to search: " + throwable.getMessage());
  2083.  
  2084. }
  2085.  
  2086. @Override
  2087. public void onSuccess(Boolean aBoolean) {
  2088. if (aBoolean) {
  2089.  
  2090. // Window.alert("ENCONTROU"); // -- DEBUG
  2091.  
  2092. /* UI DETAILS */
  2093. reg2.setText(regExpressionTextBox3.getText());
  2094. /* /UI DETAILS */
  2095.  
  2096. /* Checks if the yesToAll checkbox is enabled */
  2097. if (OptionService.getInstance().isYesToAll()) {
  2098.  
  2099. replace(OptionType.CHANGE);
  2100.  
  2101. } else {
  2102.  
  2103. /* asks the user if he wants to replace or not. */
  2104. replace_window.open();
  2105. }
  2106.  
  2107. } else {
  2108.  
  2109. MaterialToast.fireToast("Not Found"); // --- DEBUG
  2110.  
  2111. /* SEARCHS NEXT CELL */
  2112. next(OptionService.getInstance().getnCol(), OptionService.getInstance().getnRow(), OptionService.getInstance().getMySS());
  2113.  
  2114. }
  2115.  
  2116. }
  2117. };
  2118.  
  2119. /* IF THE CELL IS FROM THE REQUIRED TYPE IT PROCESSES THE SEARCH */
  2120. if (cellFilter(sh_test.getCell(col, row).getValue().getType())) {
  2121. searchService.matchByPattern(regExpressionTextBox2.getText(),
  2122. sh_test.getCell(col, row).getContent(), "", callback);
  2123. } else {
  2124.  
  2125. // Window.alert("Nao é do tipo"); // -- DEBUG
  2126.  
  2127. /* CHECKS NEXT CELL*/
  2128. next(OptionService.getInstance().getnCol(), OptionService.getInstance().getnRow(), OptionService.getInstance().getMySS());
  2129.  
  2130. }
  2131.  
  2132. }
  2133.  
  2134. /**
  2135. * Method used to filter a Cell according to its Type.
  2136. *
  2137. *
  2138. * @author: David Blanquett<1161018@isep.ipp.pt>
  2139. * @param type: the type of the cell
  2140. * @return: true if its the select type, otherwise it returns false.
  2141. */
  2142. private boolean cellFilter(Value.Type type) {
  2143.  
  2144. if (OptionService.getInstance().currentSelectedType() == Value.Type.UNDEFINED) {
  2145.  
  2146. return true;
  2147. }
  2148.  
  2149. return (type == OptionService.getInstance().currentSelectedType());
  2150.  
  2151. }
  2152.  
  2153. /**
  2154. * Replaces the content of the cell.
  2155. *
  2156. * @author: David Blanquett <1161018@isep.ipp.pt>
  2157. * @param change: if it should ne be changed or not.
  2158. */
  2159. private void replace(OptionType change) {
  2160.  
  2161.  
  2162. /* UI DETAILS: RESET ELEMENTS STATE */
  2163. cbApply.setValue(false);
  2164. cbDontApply.setValue(false);
  2165. replace_window.close();
  2166. /* /UI DETAILS */
  2167.  
  2168. if (change == OptionType.CHANGE) {
  2169.  
  2170. updateCurrent();
  2171.  
  2172. }
  2173.  
  2174. /* CALLS NEXT CELL */
  2175. next(OptionService.getInstance().getnCol(), OptionService.getInstance().getnRow(), OptionService.getInstance().getMySS());
  2176.  
  2177. }
  2178.  
  2179. /**
  2180. * Updates the content of the cell.
  2181. *
  2182. * @author: David Blanquett <1161018@isep.ipp.pt>
  2183. */
  2184. private void updateCurrent() {
  2185.  
  2186. try {
  2187. getActiveCell().getSpreadsheet().getCell(new Address(OptionService.getInstance().getRealCol(), OptionService.getInstance().getnRow())).setContent(reg2.getText());
  2188. } catch (FormulaCompilationException e) {
  2189. e.printStackTrace();
  2190. }
  2191.  
  2192. customTable.getView().setRedraw(true);
  2193. customTable.getView().refresh();
  2194.  
  2195. }
  2196.  
  2197. public pt.isep.nsheets.shared.core.Cell getActiveCell() {
  2198. return this.activeCell;
  2199. }
  2200.  
  2201. public MaterialDataTable<SheetCell> getTable() {
  2202. return customTable;
  2203.  
  2204. }
  2205.  
  2206. public class SheetCell {
  2207.  
  2208. private Spreadsheet sheet;
  2209. private int row = -1;
  2210.  
  2211. public SheetCell(Spreadsheet sheet, int row) {
  2212. this.row = row;
  2213. this.sheet = sheet;
  2214. }
  2215.  
  2216. public pt.isep.nsheets.shared.core.Cell getCell(int column) {
  2217. return this.sheet.getCell(column, this.row);
  2218. }
  2219. }
  2220.  
  2221. Workbook wb;
  2222.  
  2223. void initWorkbook() {
  2224.  
  2225. // Test the initialization of an Workbook
  2226. String contents[][][] = {{ // first spreadsheet
  2227. {"10", "-9", "8", "7", "1", "2", "3"}, {"8", "7", "6", "5", "4", "3", "2"},
  2228. {"1", "2", "3", "4", "5", "6", "7"},}};
  2229.  
  2230. wb = new Workbook(contents);
  2231. SpreadSheetSingleton.getInstance().wb = wb;
  2232. Spreadsheet sh = wb.getSpreadsheet(0);
  2233.  
  2234. int columnNumber = 0;
  2235.  
  2236. // Add the columns...
  2237. customTable.addColumn(new SheetWidgetColumn(-1, this));
  2238. for (int i = 0; i < sh.getColumnCount(); ++i) {
  2239.  
  2240. // Add a column for the column :-)
  2241. customTable.addColumn(new SheetWidgetColumn(columnNumber, this));
  2242.  
  2243. ++columnNumber;
  2244. }
  2245.  
  2246. // int rowIndex = 0;
  2247. List<SheetCell> rows = new ArrayList<>();
  2248. for (int k = 0; k < sh.getRowCount(); k++) {
  2249. rows.add(new SheetCell(sh, k));
  2250. }
  2251. customTable.setRowData(0, rows);
  2252.  
  2253. }
  2254.  
  2255. public void setActiveCell(Cell cell, MaterialLabel widget) {
  2256.  
  2257. this.widget = widget;
  2258. this.activeCell = cell;
  2259. this.customTable.getTableTitle().setText(cell.toString() + ": " + cell.getContent());
  2260. this.firstBox.setText(cell.getContent());
  2261. }
  2262.  
  2263. @Override
  2264. protected void onAttach() {
  2265. super.onAttach();
  2266.  
  2267. // table.getTableTitle().setText("The Future Worksheet!");
  2268. }
  2269.  
  2270. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement