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

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