PageRenderTime 32ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src/mpv5/handler/TrashHandler.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 89 lines | 45 code | 9 blank | 35 comment | 1 complexity | e51183cd232f753b77e72f47a361b8eb 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.handler;
  18. import javax.swing.SwingUtilities;
  19. import mpv5.db.common.Context;
  20. import mpv5.db.common.DatabaseObject;
  21. import mpv5.db.common.NodataFoundException;
  22. import mpv5.db.common.QueryCriteria;
  23. import mpv5.db.common.QueryData;
  24. import mpv5.db.common.QueryHandler;
  25. import mpv5.globals.Messages;
  26. import mpv5.logging.Log;
  27. import mpv5.ui.frames.MPView;
  28. /**
  29. *
  30. */
  31. public class TrashHandler {
  32. /**
  33. * Finally delete an item
  34. * @param type
  35. * @param id
  36. * @param message
  37. */
  38. public static void delete(final String type, final int id, final String message) {
  39. QueryHandler.instanceOf().clone(type).delete(new String[][]{{"ids", String.valueOf(id), ""}}, message);
  40. Runnable runnable = new Runnable() {
  41. public void run() {
  42. QueryHandler.instanceOf().clone(Context.getHistory()).insertHistoryItem(message, mpv5.db.objects.User.getCurrentUser().__getCname(), type, id, mpv5.db.objects.User.getCurrentUser().__getGroupsids());
  43. }
  44. };
  45. SwingUtilities.invokeLater(runnable);
  46. }
  47. /**
  48. * Fetches the trashbin data
  49. * @return
  50. */
  51. public static Object[][] getData() {
  52. Object[][] data = QueryHandler.instanceOf().clone("trashbin").select("cname, rowid, description", new String[]{"deleteme", "1", ""});
  53. for (int i = 0; i < data.length; i++) {
  54. data[i][0] = data[i][0].toString().toUpperCase();
  55. }
  56. return data;
  57. }
  58. /**
  59. * Restores the given item
  60. * @param type
  61. * @param id
  62. * @param message
  63. */
  64. public static void restore(final String type, final int id, final String message) {
  65. Context context = Context.getMatchingContext(type);
  66. try {
  67. DatabaseObject dbo = DatabaseObject.getObject(context, id, true);
  68. Log.Debug(TrashHandler.class, "Restoring: " + dbo);
  69. dbo.undelete();
  70. } catch (NodataFoundException ex) {
  71. Log.Debug(ex);
  72. }
  73. Runnable runnable = new Runnable() {
  74. public void run() {
  75. QueryHandler.instanceOf().clone(Context.getHistory()).insertHistoryItem(message, mpv5.db.objects.User.getCurrentUser().__getCname(), type, id, mpv5.db.objects.User.getCurrentUser().__getGroupsids());
  76. }
  77. };
  78. SwingUtilities.invokeLater(runnable);
  79. }
  80. }