PageRenderTime 35ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mpv5/utils/models/ImportTableModel.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 91 lines | 47 code | 13 blank | 31 comment | 7 complexity | da8b31a98f08a3d9ba5238411862ce9c MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
  1. /*
  2. * This file is part of YaBS.
  3. *
  4. * YaBS is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * YaBS is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with YaBS. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package mpv5.utils.models;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import javax.swing.table.TableModel;
  21. import mpv5.db.common.DatabaseObject;
  22. import mpv5.globals.Headers;
  23. /**
  24. *
  25. *
  26. */
  27. public class ImportTableModel extends MPTableModel {
  28. private static final long serialVersionUID = 1L;
  29. /**
  30. *
  31. * @param objs
  32. * @param selectOnlyNonExisting
  33. * @return
  34. */
  35. public static ImportTableModel getModel(ArrayList<ArrayList<DatabaseObject>> objs, boolean selectOnlyNonExisting) {
  36. ArrayList<DatabaseObject> l = new ArrayList<DatabaseObject>();
  37. for (int i = 0; i < objs.size(); i++) {
  38. ArrayList<DatabaseObject> arrayList = objs.get(i);
  39. for (int j = 0; j < arrayList.size(); j++) {
  40. DatabaseObject databaseObject = arrayList.get(j);
  41. l.add(databaseObject);
  42. }
  43. }
  44. return new ImportTableModel(l, selectOnlyNonExisting);
  45. }
  46. /**
  47. *
  48. * @param list
  49. * @param selectOnlyNonExisting
  50. */
  51. public ImportTableModel(ArrayList<DatabaseObject> list, boolean selectOnlyNonExisting) {
  52. super();
  53. Object[][] data = new Object[list.size()][5];
  54. for (int i = 0; i < list.size(); i++) {
  55. DatabaseObject databaseObject = list.get(i);
  56. List<String[]> t = databaseObject.getValues();
  57. String sdata = "";
  58. for (int j = 0; j < t.size(); j++) {
  59. String[] strings = t.get(j);
  60. sdata += strings[0] + ": " + strings[1] + " ";
  61. }
  62. data[i][0] = databaseObject;
  63. if (selectOnlyNonExisting) {
  64. if (DatabaseObject.exists(databaseObject.getContext(), databaseObject.__getIDS())) {
  65. data[i][1] = false;
  66. } else {
  67. data[i][1] = true;
  68. }
  69. }
  70. data[i][2] = databaseObject.getDbIdentity();
  71. data[i][3] = databaseObject.__getCname();
  72. data[i][4] = sdata;
  73. }
  74. setCanEdits(new boolean[]{false, true, false, false, false, false});
  75. setTypes(new Class[]{Object.class, Boolean.class, Object.class, Object.class, Object.class, Object.class});
  76. setDataVector(data, Headers.IMPORT.getValue());
  77. }
  78. }