Advertisement
Guest User

Untitled

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