Guest User

Untitled

a guest
Jul 18th, 2018
4,471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.55 KB | None | 0 0
  1. package TreeTableView;
  2. import java.net.URL;
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.text.DecimalFormat;
  7. import java.util.Date;
  8. import java.util.ResourceBundle;
  9. import com.jfoenix.controls.RecursiveTreeItem;
  10.  
  11. import com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject;
  12. import javafx.beans.property.SimpleIntegerProperty;
  13. import javafx.beans.property.SimpleStringProperty;
  14. import javafx.beans.value.ObservableValue;
  15. import javafx.collections.FXCollections;
  16. import javafx.collections.ObservableList;
  17. import javafx.fxml.FXML;
  18. import javafx.fxml.Initializable;
  19. import javafx.scene.control.TreeItem;
  20. import javafx.scene.control.TreeTableColumn;
  21. import javafx.scene.control.TreeTableView;
  22. import javafx.util.Callback;
  23. public class FXMLDocument implements Initializable{
  24.  
  25. Connection conn = null;
  26. ResultSet rs = null;
  27. PreparedStatement pst = null;
  28. Integer idjobs = 286; //temp
  29. Integer idjobs_by = 6; //temp
  30. Integer loginID = 4;
  31.  
  32. @FXML
  33. private TreeTableView<ER_Report> tableview;
  34. ObservableList<ER_Report> ER_report = FXCollections.observableArrayList();
  35.  
  36. @FXML
  37. private TreeTableColumn<ER_Report, Number> col1;
  38.  
  39. @FXML
  40. private TreeTableColumn<ER_Report, String> col2;
  41.  
  42. @FXML
  43. private TreeTableColumn<ER_Report, String> col3;
  44.  
  45. @FXML
  46. private TreeTableColumn<ER_Report, String> col4;
  47.  
  48. TreeItem<ER_Report> root;
  49.  
  50. public void dataset() {
  51. String sql = "SELECT * FROM expensereport_total_withlist where job = '" + idjobs + "' and jobby = '" + idjobs_by + "' and employee = '" + loginID + "' "
  52. + "order by newSort, root";
  53. try {
  54. pst = conn.prepareStatement(sql);
  55. rs = pst.executeQuery();
  56. while(rs.next()) {
  57. DecimalFormat df2 = new DecimalFormat("###0.00");
  58. DecimalFormat df3 = new DecimalFormat("###0.000");
  59.  
  60. Integer c_rootI = 0;
  61. Date c_Date;
  62. Integer c_WorkedDayI = 0;
  63. String c_MealsS = "";
  64. String c_AirfareS = "";
  65.  
  66. c_rootI = rs.getInt("root");
  67. String c_rootS = c_rootI.toString();
  68. c_Date = rs.getDate("newSort");
  69. String c_DateS = c_Date.toString();
  70. c_WorkedDayI = rs.getInt("workedDay");
  71. String c_WorkedDayS = c_WorkedDayI.toString();
  72. Double c_MealsD = rs.getDouble("Meals");
  73. if(c_MealsD > 0) {
  74. c_MealsS = "$ " + df2.format(c_MealsD) ;
  75. }
  76. Double c_airD = rs.getDouble("Meals");
  77. if(c_airD > 0) {
  78. c_AirfareS = "$ " + df2.format(c_airD) ;
  79. }
  80.  
  81. ER_report.add(new ER_Report(c_rootI, c_DateS,c_MealsS,c_AirfareS));
  82. }
  83. final TreeItem<ER_Report> root = new RecursiveTreeItem<ER_Report>(ER_report, RecursiveTreeObject::getChildren);
  84.  
  85.  
  86. col1.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<ER_Report, Number>, ObservableValue<Number>>() {
  87. @Override
  88. public ObservableValue<Number> call(TreeTableColumn.CellDataFeatures<ER_Report, Number> param) {
  89. return param.getValue().getValue().rootProperty;
  90. }
  91. });
  92. col2.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<ER_Report, String>, ObservableValue<String>>() {
  93. @Override
  94. public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<ER_Report, String> param) {
  95. return param.getValue().getValue().newDateProperty;
  96. }
  97. });
  98. col3.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<ER_Report, String>, ObservableValue<String>>() {
  99. @Override
  100. public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<ER_Report, String> param) {
  101. return param.getValue().getValue().mealsProperty;
  102. }
  103. });
  104. col4.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<ER_Report, String>, ObservableValue<String>>() {
  105. @Override
  106. public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<ER_Report, String> param) {
  107. return param.getValue().getValue().airProperty;
  108. }
  109. });
  110.  
  111.  
  112. root.getChildren().setAll(root);
  113. tableview.setRoot(root);
  114. }catch(Exception e) {
  115. e.printStackTrace();
  116. }
  117. root = new TreeItem<>(new ER_Report(0, "Name", "None", "None"));
  118. }
  119.  
  120. @Override
  121. public void initialize(URL arg0, ResourceBundle arg1) {
  122. conn = connector.ConnectDb();
  123.  
  124. idjobs = 286; //temp
  125. idjobs_by = 6; //temp
  126. dataset();
  127. }
  128.  
  129. class ER_Report extends RecursiveTreeObject<ER_Report>{
  130. SimpleIntegerProperty rootProperty;
  131. SimpleStringProperty newDateProperty;
  132. SimpleStringProperty mealsProperty;
  133. SimpleStringProperty airProperty;
  134.  
  135. public ER_Report(Integer root, String newDate, String meals, String air) {
  136. this.rootProperty = new SimpleIntegerProperty(root);
  137. this.newDateProperty = new SimpleStringProperty(newDate);
  138. this.mealsProperty = new SimpleStringProperty(meals);
  139. this.airProperty = new SimpleStringProperty(air);
  140. }
  141.  
  142. /**
  143. * @return the rootProperty
  144. */
  145. public SimpleIntegerProperty getRootProperty() {
  146. return rootProperty;
  147. }
  148.  
  149. /**
  150. * @param rootProperty the rootProperty to set
  151. */
  152. public void setRootProperty(SimpleIntegerProperty rootProperty) {
  153. this.rootProperty = rootProperty;
  154. }
  155.  
  156. /**
  157. * @return the newDateProperty
  158. */
  159. public SimpleStringProperty getNewDateProperty() {
  160. return newDateProperty;
  161. }
  162.  
  163. /**
  164. * @param newDateProperty the newDateProperty to set
  165. */
  166. public void setNewDateProperty(SimpleStringProperty newDateProperty) {
  167. this.newDateProperty = newDateProperty;
  168. }
  169.  
  170. /**
  171. * @return the mealsProperty
  172. */
  173. public SimpleStringProperty getMealsProperty() {
  174. return mealsProperty;
  175. }
  176.  
  177. /**
  178. * @param mealsProperty the mealsProperty to set
  179. */
  180. public void setMealsProperty(SimpleStringProperty mealsProperty) {
  181. this.mealsProperty = mealsProperty;
  182. }
  183.  
  184. /**
  185. * @return the airProperty
  186. */
  187. public SimpleStringProperty getAirProperty() {
  188. return airProperty;
  189. }
  190.  
  191. /**
  192. * @param airProperty the airProperty to set
  193. */
  194. public void setAirProperty(SimpleStringProperty airProperty) {
  195. this.airProperty = airProperty;
  196. }
  197.  
  198.  
  199. }
  200. }
  201.  
  202. newSort root Meals Airfare
  203. 6/22/2018 1 94.16 756.46
  204. 6/22/2018 2 NULL 756.46
  205. 6/22/2018 2 38.53 NULL
  206. 6/22/2018 2 55.63 NULL
  207. 6/27/2018 1 6.92 NULL
  208. 6/27/2018 2 3.63 NULL
  209. 6/27/2018 2 3.29 NULL
  210. 6/29/2018 1 NULL 698.9
  211. 6/29/2018 2 NULL 698.9
  212.  
  213. public void rowchecker() {
  214. Callback<TableColumn<ExpenseReportTable, Integer>, TableCell<ExpenseReportTable, Integer>> cellFactory
  215. = new Callback<TableColumn<ExpenseReportTable, Integer>, TableCell<ExpenseReportTable, Integer>>() {
  216. public TableCell call(TableColumn p) {
  217. TableCell cell = new TableCell<ExpenseReportTable, Integer>() {
  218. @Override
  219. public void updateItem(Integer item, boolean empty) {
  220. super.updateItem(item, empty);
  221. if (!empty) {
  222. TableRow ttr = getTableRow();
  223. if (item == null || empty){
  224. setText(null);
  225. ttr.setStyle("");
  226. setStyle("");
  227. } else {
  228. ttr.setStyle(item.doubleValue() > 0
  229. ? "-fx-background-color:lightgreen"
  230. : "-fx-background-color:#FFE793");
  231. setText(item.toString());
  232. setStyle(item.doubleValue() > 0
  233. ? "-fx-background-color:green"
  234. : "-fx-background-color:lightgreen");
  235. }
  236. } else {
  237. setText(null);
  238. }
  239. }
  240.  
  241. private String getString() {
  242. return getItem() == null ? "" : getItem().toString();
  243. }
  244. };
  245.  
  246. return cell;
  247. }
  248. };
  249. col_NonWorkedDate.setCellFactory(cellFactory);
  250.  
  251. }
Add Comment
Please, Sign In to add comment