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

TableSelection.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package com.rthoni.intellij.codefromds.dbo.options;
  2. import com.intellij.database.model.DasTable;
  3. import com.intellij.database.util.DasUtil;
  4. import com.rthoni.intellij.codefromds.business.Helper;
  5. import org.json.JSONArray;
  6. import org.json.JSONObject;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Vector;
  10. import java.util.stream.Collectors;
  11. /**
  12. * Created by robin on 11/15/16.
  13. */
  14. public class TableSelection {
  15. private DasTable _table;
  16. private List<ColumnSelection> _columns;
  17. public TableSelection(DasTable table)
  18. {
  19. _table = table;
  20. _columns = DasUtil.getColumns(table).toList().stream().map(ColumnSelection::new).collect(Collectors.toList());
  21. }
  22. public HashMap<String, Object> toMap()
  23. {
  24. HashMap<String, Object> map = new HashMap<>();
  25. map.put("table", _table == null ? null : _table.getName());
  26. List<Object> tables = new Vector<>();
  27. for (ColumnSelection col : _columns) {
  28. tables.add(col.toMap());
  29. }
  30. map.put("columns", tables);
  31. return map;
  32. }
  33. public void fromJson(JSONObject json)
  34. {
  35. JSONArray array = json.getJSONArray("columns");
  36. for (ColumnSelection column : _columns) {
  37. JSONObject obj = Helper.findColumnInJson(array, column.getColumn().getName());
  38. if (obj != null) {
  39. column.fromJson(obj);
  40. } else {
  41. column.setSelected(false);
  42. }
  43. }
  44. }
  45. public DasTable getTable() {
  46. return _table;
  47. }
  48. public void setTable(DasTable table) {
  49. _table = table;
  50. }
  51. public List<ColumnSelection> getColumns() {
  52. return _columns;
  53. }
  54. public void setColumns(List<ColumnSelection> columns) {
  55. _columns = columns;
  56. }
  57. public boolean hasNone()
  58. {
  59. return _columns != null && _columns.stream().filter(ColumnSelection::isSelected).count() == 0;
  60. }
  61. public boolean hasAll()
  62. {
  63. return _columns != null && _columns.stream().filter(ColumnSelection::isSelected).count() == _columns.size();
  64. }
  65. }