PageRenderTime 72ms CodeModel.GetById 20ms RepoModel.GetById 7ms app.codeStats 0ms

/src/mpv5/db/objects/FileToContact.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 178 lines | 105 code | 18 blank | 55 comment | 5 complexity | 6b45edcaf6a0ed8a5a141fd88268cf98 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.db.objects;
  18. import java.io.File;
  19. import javax.swing.Icon;
  20. import javax.swing.JComponent;
  21. import javax.swing.JFileChooser;
  22. import mpv5.db.common.Context;
  23. import mpv5.db.common.DatabaseObject;
  24. import mpv5.db.common.QueryHandler;
  25. import mpv5.logging.Log;
  26. import mpv5.utils.files.FileDirectoryHandler;
  27. import mpv5.utils.images.MPIcon;
  28. /**
  29. *
  30. *
  31. */
  32. public class FileToContact extends DatabaseObject {
  33. private String description = "";
  34. private int contactsids;
  35. private String filename = "";
  36. private File file;
  37. private int intsize;
  38. private String mimetype;
  39. public FileToContact() {
  40. setContext(Context.getFilesToContacts());
  41. }
  42. @Override
  43. public JComponent getView() {
  44. try {
  45. FileDirectoryHandler.open(getFile());
  46. } catch (Exception e) {
  47. Log.Debug(e);
  48. }
  49. return null;
  50. }
  51. /**
  52. * @return the description
  53. */
  54. public String __getDescription() {
  55. return description;
  56. }
  57. /**
  58. * @param description the description to set
  59. */
  60. public void setDescription(String description) {
  61. this.description = description;
  62. }
  63. /**
  64. * @return the contactsids
  65. */
  66. public int __getContactsids() {
  67. return contactsids;
  68. }
  69. /**
  70. * @param contactsids the contactsids to set
  71. */
  72. public void setContactsids(int contactsids) {
  73. this.contactsids = contactsids;
  74. }
  75. /**
  76. * @return the filename
  77. */
  78. public String __getFilename() {
  79. return filename;
  80. }
  81. /**
  82. * @param filename the filename to set
  83. */
  84. public void setFilename(String filename) {
  85. this.filename = filename;
  86. }
  87. MPIcon icon;
  88. @Override
  89. public mpv5.utils.images.MPIcon getIcon() {
  90. if (icon == null) {
  91. try {
  92. Log.Debug(this, "Determining Icon for " + __getCname());
  93. icon = new MPIcon(MPIcon.DIRECTORY_DEFAULT_ICONS + __getCname().substring(__getCname().lastIndexOf(".") + 1, __getCname().length()) + ".png");
  94. return icon;
  95. } catch (Exception e) {
  96. Log.Debug(this, "Icon file not existing in " + MPIcon.DIRECTORY_DEFAULT_ICONS);
  97. try {
  98. JFileChooser chooser = new JFileChooser();
  99. icon = new MPIcon(chooser.getIcon(new File(filename)));
  100. return icon;
  101. } catch (Exception ez) {
  102. Log.Debug(this, ez);
  103. icon = new MPIcon(MPIcon.DIRECTORY_DEFAULT_ICONS + "folder_tar.png");
  104. return icon;
  105. }
  106. }
  107. } else {
  108. return icon;
  109. }
  110. }
  111. /**
  112. * Fetches the physical file from db
  113. *
  114. * @return
  115. */
  116. public synchronized File getFile() {
  117. if (file == null) {
  118. try {
  119. file = QueryHandler.instanceOf().clone(Context.getFiles()).retrieveFile(filename,
  120. new File(FileDirectoryHandler.getTempDir() + getCname()));
  121. } catch (Exception e) {
  122. Log.Debug(e);
  123. }
  124. }
  125. return file;
  126. }
  127. /**
  128. * @return the mimetype
  129. */
  130. public String __getMimetype() {
  131. return mimetype;
  132. }
  133. /**
  134. * @param mimetype the mimetype to set
  135. */
  136. public void setMimetype(String mimetype) {
  137. this.mimetype = mimetype;
  138. }
  139. /**
  140. * @return the intsize
  141. */
  142. public int __getIntsize() {
  143. return intsize;
  144. }
  145. /**
  146. * @param intsize the intsize to set
  147. */
  148. public void setIntsize(int intsize) {
  149. this.intsize = intsize;
  150. }
  151. @Override
  152. public boolean delete() {
  153. try {
  154. QueryHandler.instanceOf().clone(Context.getFiles()).removeFile(filename);
  155. } catch (Exception ex) {
  156. Log.Debug(ex);
  157. }
  158. return super.delete();
  159. }
  160. }