PageRenderTime 55ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mpv5/ui/panels/ConversationPanel.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 1227 lines | 1023 code | 108 blank | 96 comment | 104 complexity | 1b5eacaa90c82913ee2e48e342d518d4 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. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. /*
  6. * ConversationUI.java
  7. *
  8. * Created on 06.04.2011, 20:17:07
  9. */
  10. package mpv5.ui.panels;
  11. import enoa.handler.TemplateHandler;
  12. import java.awt.BorderLayout;
  13. import java.awt.Color;
  14. import java.awt.GraphicsEnvironment;
  15. import java.awt.event.ActionEvent;
  16. import java.awt.event.ActionListener;
  17. import java.io.ByteArrayInputStream;
  18. import java.io.ByteArrayOutputStream;
  19. import java.io.IOException;
  20. import java.util.Date;
  21. import java.util.HashMap;
  22. import java.util.Iterator;
  23. import java.util.List;
  24. import javax.swing.JComboBox;
  25. import javax.swing.JFrame;
  26. import javax.swing.JTabbedPane;
  27. import javax.swing.JTextPane;
  28. import javax.swing.JToggleButton;
  29. import javax.swing.JViewport;
  30. import javax.swing.SwingUtilities;
  31. import javax.swing.text.AttributeSet;
  32. import javax.swing.text.BadLocationException;
  33. import javax.swing.text.DefaultStyledDocument;
  34. import javax.swing.text.MutableAttributeSet;
  35. import javax.swing.text.SimpleAttributeSet;
  36. import javax.swing.text.StyleConstants;
  37. import javax.swing.text.StyledDocument;
  38. import javax.swing.text.StyledEditorKit;
  39. import javax.swing.text.rtf.RTFEditorKit;
  40. import mpv5.db.common.Context;
  41. import mpv5.db.common.DatabaseObject;
  42. import mpv5.db.common.DatabaseSearch;
  43. import mpv5.db.common.NodataFoundException;
  44. import mpv5.db.objects.Address;
  45. import mpv5.db.objects.Contact;
  46. import mpv5.db.objects.Favourite;
  47. import mpv5.db.objects.User;
  48. import mpv5.globals.Messages;
  49. import mpv5.logging.Log;
  50. import mpv5.ui.dialogs.DialogForFile;
  51. import mpv5.ui.dialogs.Popup;
  52. import mpv5.ui.panels.ChangeNotApprovedException;
  53. import mpv5.ui.panels.DataPanel;
  54. import mpv5.ui.panels.ExportablePanel;
  55. import mpv5.ui.toolbars.DataPanelTB;
  56. import mpv5.utils.export.Export;
  57. import mpv5.utils.jobs.Job;
  58. import mpv5.db.objects.Conversation;
  59. import mpv5.globals.Constants;
  60. import mpv5.ui.dialogs.Search2;
  61. import mpv5.utils.models.MPComboBoxModelItem;
  62. import mpv5.utils.ui.TextFieldUtils;
  63. /**
  64. *
  65. * @author Jan Hahnisch
  66. */
  67. public class ConversationPanel
  68. extends javax.swing.JPanel
  69. implements DataPanel,
  70. ExportablePanel {
  71. private static final long serialVersionUID = -7873021087487613697L;
  72. private static ConversationPanel me;
  73. /**
  74. * Singleton
  75. * @return
  76. */
  77. public static ConversationPanel instanceOf() {
  78. if (me == null) {
  79. me = new ConversationPanel();
  80. } else {
  81. me.refresh_internal();
  82. }
  83. return me;
  84. }
  85. private int Type = Constants.TYPE_CONVERSATION;
  86. private DataPanelTB tb;
  87. private SearchPanel sp;
  88. private Conversation dataOwner;
  89. public Integer groupsids_ = 1;
  90. public String cnumber_ = "";
  91. public String content_ = "";
  92. public String cname_ = "";
  93. public String adress_ = "";
  94. public Date date_ = null;
  95. public Date dateadded_;
  96. Contact contact = null;
  97. List data = null;
  98. Thread t = null;
  99. public Integer intaddedby_;
  100. public int contactsids_;
  101. /** Creates new form ConversationUI */
  102. public ConversationPanel() {
  103. initComponents();
  104. Log.Debug(ConversationPanel.class,
  105. "Erstellung gestartet ...");
  106. sp = new SearchPanel(Context.getConversation(), this);
  107. sp.setVisible(true);
  108. tb = new DataPanelTB(this);
  109. tb.getMailButton().setEnabled(false);
  110. SearchBarPane.add(sp,
  111. BorderLayout.CENTER);
  112. Log.Debug(ConversationPanel.class,
  113. "Suchbar eingebaut ...");
  114. ToolBarPane.add(tb,
  115. BorderLayout.CENTER);
  116. Log.Debug(ConversationPanel.class,
  117. "Toolbar eingebaut ...");
  118. dataOwner = new Conversation();
  119. RTFEditorKit kit = (RTFEditorKit) RTF_Text.getEditorKitForContentType(
  120. "text/rtf");
  121. DefaultStyledDocument doc = (DefaultStyledDocument) kit.createDefaultDocument();
  122. RTF_Text.setEditorKit(kit);
  123. RTF_Text.setDocument(doc);
  124. addedby.setText(mpv5.db.objects.User.getCurrentUser().getName());
  125. contactname.setSearchEnabled(true);
  126. contactname.setContext(Context.getCustomer());
  127. contactname.getComboBox().addActionListener(new ActionListener() {
  128. @Override
  129. public void actionPerformed(ActionEvent e) {
  130. Log.Debug(this, e.getActionCommand());
  131. final MPComboBoxModelItem item = contactname.getSelectedItem();
  132. if (item != null && item.isValid()) {
  133. t = new Thread() {
  134. @Override
  135. public void run() {
  136. Address adr;
  137. try {
  138. contact = (Contact) DatabaseObject.getObject(Context.getContact(), Integer.valueOf(item.getId()));
  139. data = DatabaseObject.getReferencedObjects(contact,
  140. Context.getAddress());
  141. if (data.isEmpty()) {
  142. contactcity.setText(contact.__getCity());
  143. contactcompany.setText(contact.__getCompany());
  144. contactzip.setText(contact.__getZip());
  145. contactstreet.setText(contact.__getStreet());
  146. } else {
  147. contactcity.setText("");
  148. contactcompany.setText("");
  149. contactzip.setText("");
  150. contactstreet.setText("");
  151. }
  152. contactid.setText(contact.__getCNumber());
  153. Object[][] data1 = new Object[data.size() + 1][2];
  154. data1[0][0] = 0;
  155. data1[0][1] = Messages.Conversation_MainAddress.toString();
  156. for (int o = 0; o < data.size(); o++) {
  157. adr = (Address) data.get(o);
  158. data1[o + 1][0] = adr.__getIDS();
  159. data1[o + 1][1] = adr.__getCname();
  160. }
  161. adressList.setModel(data1);
  162. } catch (NodataFoundException ex) {
  163. Log.Debug(this, ex);
  164. }
  165. }
  166. };
  167. t.start();
  168. }
  169. }
  170. });
  171. adressList.getComboBox().addActionListener(new ActionListener() {
  172. @Override
  173. public void actionPerformed(ActionEvent e) {
  174. final MPComboBoxModelItem item = adressList.getSelectedItem();
  175. if (item != null) {
  176. Runnable runnable = new Runnable() {
  177. @Override
  178. public void run() {
  179. Log.Debug(this, "AdressListe");
  180. if (item.getId().equals("0")) {
  181. contactcity.setText(contact.__getCity());
  182. contactcompany.setText(contact.__getCompany());
  183. contactzip.setText(contact.__getZip());
  184. contactstreet.setText(contact.__getStreet());
  185. contactid.setText(contact.__getCNumber());
  186. } else {
  187. for (int i = 0; i < data.size(); i++) {
  188. Address adr = (Address) data.get(i);
  189. if (item.getId() == null ? adr.__getIDS().toString() == null : item.getId().equals(adr.__getIDS().toString())) {
  190. contactcity.setText(adr.__getCity());
  191. contactcompany.setText(adr.__getCompany());
  192. contactzip.setText(adr.__getZip());
  193. contactstreet.setText(adr.__getStreet());
  194. }
  195. }
  196. }
  197. }
  198. };
  199. SwingUtilities.invokeLater(runnable);
  200. }
  201. }
  202. });
  203. }
  204. private HashMap<String, Object> getAddData() {
  205. HashMap<String, Object> hm1 = null;
  206. HashMap<String, Object> hm2 = new HashMap<String, Object>();
  207. if (contact != null) {
  208. String AdressName = adressList.getSelectedItem().getId();
  209. int adressID = Integer.parseInt(AdressName);
  210. Log.Debug(this,
  211. "Kontakt zum drucken geladen ...");
  212. if (adressID == 0) {
  213. hm1 = contact.getValues4();
  214. Log.Debug(this,
  215. "Hauptkontakt ausgegeben ...");
  216. } else {
  217. for (int i = 0; i < data.size(); i++) {
  218. Address adr = (Address) data.get(i);
  219. if (adressID == adr.__getIDS()) {
  220. hm1 = adr.getValues4();
  221. }
  222. }
  223. Log.Debug(this,
  224. "gezielte Addresse geladen ...");
  225. }
  226. Iterator<String> iterator = hm1.keySet().iterator();
  227. Object e;
  228. while (iterator.hasNext()) {
  229. e = iterator.next();
  230. hm2.put(dataOwner.getType() + "." + contact.getType() + "." + e.toString(),
  231. hm1.get(e));
  232. if (e.equals("ismale")) {
  233. if (hm1.get(e).
  234. equals(true)) {
  235. hm2.put(dataOwner.getType() + "." + contact.getType() + ".gender",
  236. Messages.CONTACT_TYPE_MALE.toString());
  237. hm2.put(dataOwner.getType() + ".intro",
  238. Messages.CONTACT_INTRO_MALE.toString());
  239. } else {
  240. hm2.put(dataOwner.getType() + "." + contact.getType() + ".gender",
  241. Messages.CONTACT_TYPE_FEMALE.toString());
  242. hm2.put(dataOwner.getType() + ".intro",
  243. Messages.CONTACT_INTRO_FEMALE.toString());
  244. }
  245. }
  246. }
  247. }
  248. return hm2;
  249. }
  250. /** This method is called from within the constructor to
  251. * initialize the form.
  252. * WARNING: Do NOT modify this code. The content of this method is
  253. * always regenerated by the Form Editor.
  254. */
  255. @SuppressWarnings("unchecked")
  256. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  257. private void initComponents() {
  258. ToolBarPane = new javax.swing.JPanel();
  259. jPanel1 = new javax.swing.JPanel();
  260. street = new javax.swing.JPanel();
  261. contactname = new mpv5.ui.beans.LabeledCombobox();
  262. contactcity = new javax.swing.JTextField();
  263. contactcompany = new javax.swing.JTextField();
  264. contactid = new javax.swing.JTextField();
  265. jButton3 = new javax.swing.JButton();
  266. jButton4 = new javax.swing.JButton();
  267. adressList = new mpv5.ui.beans.LabeledCombobox();
  268. contactzip = new javax.swing.JTextField();
  269. contactstreet = new javax.swing.JTextField();
  270. jPanel3 = new javax.swing.JPanel();
  271. jComboBox2 = new javax.swing.JComboBox();
  272. String fontSizes[] = {"8", "10", "11", "12", "14", "16", "18",
  273. "20", "24", "30", "36", "40", "48", "60", "72"};
  274. for (int index = 0; index < fontSizes.length; index++) {
  275. jComboBox2.addItem(fontSizes[index]);
  276. }
  277. jComboBox1 = new javax.swing.JComboBox();
  278. try {
  279. String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
  280. Log.Debug(this, "Ermittelte Fonts: " + fonts.length);
  281. for (int index = 0; index < fonts.length; index++) {
  282. jComboBox1.addItem(fonts[index]);
  283. }
  284. } catch (Exception e) {
  285. Log.Debug(ConversationPanel.class, e);
  286. }
  287. jToggleButton3 = new javax.swing.JToggleButton();
  288. jToggleButton1 = new javax.swing.JToggleButton();
  289. jToggleButton2 = new javax.swing.JToggleButton();
  290. jLabel3 = new javax.swing.JLabel();
  291. jSeparator1 = new javax.swing.JSeparator();
  292. jScrollPane1 = new javax.swing.JScrollPane();
  293. RTF_Text = new javax.swing.JTextPane();
  294. jLabel7 = new javax.swing.JLabel();
  295. dateTo = new mpv5.ui.beans.DateChooser();
  296. cname = new javax.swing.JTextField();
  297. jPanel4 = new javax.swing.JPanel();
  298. jLabel6 = new javax.swing.JLabel();
  299. ids = new javax.swing.JTextField();
  300. jLabel4 = new javax.swing.JLabel();
  301. addedby = new javax.swing.JTextField();
  302. jLabel5 = new javax.swing.JLabel();
  303. dateadded = new mpv5.ui.beans.DateChooser();
  304. dateadded.setEnabled(false);
  305. SearchBarPane = new javax.swing.JPanel();
  306. setName("Form"); // NOI18N
  307. setLayout(new java.awt.BorderLayout());
  308. ToolBarPane.setName("ToolBarPane"); // NOI18N
  309. ToolBarPane.setLayout(new java.awt.BorderLayout());
  310. add(ToolBarPane, java.awt.BorderLayout.NORTH);
  311. jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
  312. jPanel1.setName("jPanel1"); // NOI18N
  313. street.setBackground(new java.awt.Color(255, 255, 255));
  314. java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
  315. street.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ConversationPanel.street.border.title"))); // NOI18N
  316. street.setName("street"); // NOI18N
  317. street.setOpaque(false);
  318. contactname.set_Label(bundle.getString("ConversationPanel.contactname._Label")); // NOI18N
  319. contactname.setName("contactname"); // NOI18N
  320. contactcity.setEditable(false);
  321. contactcity.setText(bundle.getString("ConversationPanel.contactcity.text")); // NOI18N
  322. contactcity.setName("contactcity"); // NOI18N
  323. contactcompany.setEditable(false);
  324. contactcompany.setText(bundle.getString("ConversationPanel.contactcompany.text")); // NOI18N
  325. contactcompany.setName("contactcompany"); // NOI18N
  326. contactid.setEditable(false);
  327. contactid.setText(bundle.getString("ConversationPanel.contactid.text")); // NOI18N
  328. contactid.setName("contactid"); // NOI18N
  329. jButton3.setText(bundle.getString("ConversationPanel.jButton3.text")); // NOI18N
  330. jButton3.setName("jButton3"); // NOI18N
  331. jButton3.addActionListener(new java.awt.event.ActionListener() {
  332. public void actionPerformed(java.awt.event.ActionEvent evt) {
  333. actionShowContact(evt);
  334. }
  335. });
  336. jButton4.setText(bundle.getString("ConversationPanel.jButton4.text")); // NOI18N
  337. jButton4.setName("jButton4"); // NOI18N
  338. jButton4.addActionListener(new java.awt.event.ActionListener() {
  339. public void actionPerformed(java.awt.event.ActionEvent evt) {
  340. actionLookupContact(evt);
  341. }
  342. });
  343. adressList.set_Label(bundle.getString("ConversationPanel.adressList._Label")); // NOI18N
  344. adressList.setName("adressList"); // NOI18N
  345. contactzip.setEditable(false);
  346. contactzip.setText(bundle.getString("ConversationPanel.contactzip.text")); // NOI18N
  347. contactzip.setName("contactzip"); // NOI18N
  348. contactstreet.setEditable(false);
  349. contactstreet.setText(bundle.getString("ConversationPanel.contactstreet.text")); // NOI18N
  350. contactstreet.setName("contactstreet"); // NOI18N
  351. javax.swing.GroupLayout streetLayout = new javax.swing.GroupLayout(street);
  352. street.setLayout(streetLayout);
  353. streetLayout.setHorizontalGroup(
  354. streetLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  355. .addGroup(streetLayout.createSequentialGroup()
  356. .addGroup(streetLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  357. .addGroup(streetLayout.createSequentialGroup()
  358. .addComponent(contactcompany, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
  359. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  360. .addComponent(contactcity, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE))
  361. .addComponent(contactname, javax.swing.GroupLayout.PREFERRED_SIZE, 338, javax.swing.GroupLayout.PREFERRED_SIZE))
  362. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  363. .addGroup(streetLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  364. .addGroup(streetLayout.createSequentialGroup()
  365. .addComponent(adressList, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)
  366. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  367. .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
  368. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  369. .addComponent(jButton4))
  370. .addGroup(streetLayout.createSequentialGroup()
  371. .addComponent(contactzip, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
  372. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  373. .addComponent(contactstreet, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
  374. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  375. .addComponent(contactid)))
  376. .addGap(28, 28, 28))
  377. );
  378. streetLayout.setVerticalGroup(
  379. streetLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  380. .addGroup(streetLayout.createSequentialGroup()
  381. .addGroup(streetLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
  382. .addComponent(adressList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  383. .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
  384. .addComponent(jButton4)
  385. .addComponent(contactname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  386. .addGap(6, 6, 6)
  387. .addGroup(streetLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
  388. .addComponent(contactcompany, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  389. .addComponent(contactcity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  390. .addComponent(contactzip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  391. .addComponent(contactstreet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  392. .addComponent(contactid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
  393. );
  394. jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ConversationPanel.jPanel3.border.title"))); // NOI18N
  395. jPanel3.setName("jPanel3"); // NOI18N
  396. jComboBox2.setName("jComboBox2"); // NOI18N
  397. jComboBox2.addActionListener(new java.awt.event.ActionListener() {
  398. public void actionPerformed(java.awt.event.ActionEvent evt) {
  399. jComboBox2ActionPerformed(evt);
  400. }
  401. });
  402. jComboBox1.setName("jComboBox1"); // NOI18N
  403. jComboBox1.addActionListener(new java.awt.event.ActionListener() {
  404. public void actionPerformed(java.awt.event.ActionEvent evt) {
  405. jComboBox1ActionPerformed(evt);
  406. }
  407. });
  408. jToggleButton3.setFont(jToggleButton3.getFont());
  409. jToggleButton3.setText(bundle.getString("ConversationPanel.jToggleButton3.text")); // NOI18N
  410. jToggleButton3.setName("jToggleButton3"); // NOI18N
  411. jToggleButton3.addActionListener(new java.awt.event.ActionListener() {
  412. public void actionPerformed(java.awt.event.ActionEvent evt) {
  413. jToggleButton3ActionPerformed(evt);
  414. }
  415. });
  416. jToggleButton1.setFont(new java.awt.Font("Tahoma", 1, 11));
  417. jToggleButton1.setText(bundle.getString("ConversationPanel.jToggleButton1.text")); // NOI18N
  418. jToggleButton1.setName("jToggleButton1"); // NOI18N
  419. jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
  420. public void actionPerformed(java.awt.event.ActionEvent evt) {
  421. jToggleButton1ActionPerformed(evt);
  422. }
  423. });
  424. jToggleButton2.setFont(new java.awt.Font("Tahoma", 2, 11));
  425. jToggleButton2.setText(bundle.getString("ConversationPanel.jToggleButton2.text")); // NOI18N
  426. jToggleButton2.setName("jToggleButton2"); // NOI18N
  427. jToggleButton2.addActionListener(new java.awt.event.ActionListener() {
  428. public void actionPerformed(java.awt.event.ActionEvent evt) {
  429. jToggleButton2ActionPerformed(evt);
  430. }
  431. });
  432. jLabel3.setLabelFor(dateTo);
  433. jLabel3.setText(bundle.getString("ConversationPanel.jLabel3.text")); // NOI18N
  434. jLabel3.setName("jLabel3"); // NOI18N
  435. jSeparator1.setName("jSeparator1"); // NOI18N
  436. jScrollPane1.setName("jScrollPane1"); // NOI18N
  437. RTF_Text.setEditorKit(new javax.swing.text.rtf.RTFEditorKit());
  438. RTF_Text.setName("RTF_Text"); // NOI18N
  439. RTF_Text.addCaretListener(new javax.swing.event.CaretListener() {
  440. public void caretUpdate(javax.swing.event.CaretEvent evt) {
  441. RTF_TextCaretUpdate(evt);
  442. }
  443. });
  444. jScrollPane1.setViewportView(RTF_Text);
  445. jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
  446. jLabel7.setLabelFor(cname);
  447. jLabel7.setText(bundle.getString("ConversationPanel.jLabel7.text")); // NOI18N
  448. jLabel7.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
  449. jLabel7.setMaximumSize(new java.awt.Dimension(65, 20));
  450. jLabel7.setMinimumSize(new java.awt.Dimension(65, 20));
  451. jLabel7.setName("jLabel7"); // NOI18N
  452. jLabel7.setPreferredSize(new java.awt.Dimension(65, 20));
  453. dateTo.setMaximumSize(new java.awt.Dimension(32767, 20));
  454. dateTo.setMinimumSize(new java.awt.Dimension(120, 20));
  455. dateTo.setName("dateTo"); // NOI18N
  456. dateTo.setPreferredSize(new java.awt.Dimension(150, 20));
  457. cname.setText(bundle.getString("ConversationPanel.cname.text")); // NOI18N
  458. cname.setName("cname"); // NOI18N
  459. javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
  460. jPanel3.setLayout(jPanel3Layout);
  461. jPanel3Layout.setHorizontalGroup(
  462. jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  463. .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 910, Short.MAX_VALUE)
  464. .addGroup(jPanel3Layout.createSequentialGroup()
  465. .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  466. .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 900, Short.MAX_VALUE)
  467. .addGroup(jPanel3Layout.createSequentialGroup()
  468. .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)
  469. .addGap(15, 15, 15)
  470. .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
  471. .addGap(7, 7, 7)
  472. .addComponent(jToggleButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
  473. .addGap(2, 2, 2)
  474. .addComponent(jToggleButton2)
  475. .addGap(5, 5, 5)
  476. .addComponent(jToggleButton3)
  477. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  478. .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
  479. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  480. .addComponent(dateTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  481. .addGroup(jPanel3Layout.createSequentialGroup()
  482. .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  483. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  484. .addComponent(cname, javax.swing.GroupLayout.DEFAULT_SIZE, 831, Short.MAX_VALUE)))
  485. .addContainerGap())
  486. );
  487. jPanel3Layout.setVerticalGroup(
  488. jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  489. .addGroup(jPanel3Layout.createSequentialGroup()
  490. .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  491. .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  492. .addComponent(cname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  493. .addGap(10, 10, 10)
  494. .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
  495. .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  496. .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  497. .addComponent(jToggleButton1)
  498. .addComponent(jToggleButton2)
  499. .addComponent(jToggleButton3)
  500. .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
  501. .addComponent(dateTo, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
  502. .addGap(5, 5, 5)
  503. .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  504. .addGap(10, 10, 10)
  505. .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE))
  506. );
  507. jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ConversationPanel.jPanel4.border.title"))); // NOI18N
  508. jPanel4.setName("jPanel4"); // NOI18N
  509. jPanel4.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
  510. jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
  511. jLabel6.setLabelFor(ids);
  512. jLabel6.setText(bundle.getString("ConversationPanel.jLabel6.text")); // NOI18N
  513. jLabel6.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
  514. jLabel6.setMaximumSize(new java.awt.Dimension(333, 20));
  515. jLabel6.setMinimumSize(new java.awt.Dimension(65, 20));
  516. jLabel6.setName("jLabel6"); // NOI18N
  517. jLabel6.setOpaque(true);
  518. jLabel6.setPreferredSize(new java.awt.Dimension(120, 20));
  519. jPanel4.add(jLabel6);
  520. ids.setMaximumSize(new java.awt.Dimension(333, 20));
  521. ids.setMinimumSize(new java.awt.Dimension(65, 20));
  522. ids.setName("ids"); // NOI18N
  523. ids.setPreferredSize(new java.awt.Dimension(120, 20));
  524. jPanel4.add(ids);
  525. jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  526. jLabel4.setLabelFor(addedby);
  527. jLabel4.setText(bundle.getString("ConversationPanel.jLabel4.text")); // NOI18N
  528. jLabel4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
  529. jLabel4.setMaximumSize(new java.awt.Dimension(333, 20));
  530. jLabel4.setMinimumSize(new java.awt.Dimension(65, 20));
  531. jLabel4.setName("jLabel4"); // NOI18N
  532. jLabel4.setOpaque(true);
  533. jLabel4.setPreferredSize(new java.awt.Dimension(120, 20));
  534. jPanel4.add(jLabel4);
  535. addedby.setEditable(false);
  536. addedby.setMaximumSize(new java.awt.Dimension(333, 20));
  537. addedby.setMinimumSize(new java.awt.Dimension(65, 20));
  538. addedby.setName("addedby"); // NOI18N
  539. addedby.setPreferredSize(new java.awt.Dimension(120, 20));
  540. jPanel4.add(addedby);
  541. jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  542. jLabel5.setLabelFor(ids);
  543. jLabel5.setText(bundle.getString("ConversationPanel.jLabel5.text")); // NOI18N
  544. jLabel5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
  545. jLabel5.setMaximumSize(new java.awt.Dimension(333, 20));
  546. jLabel5.setMinimumSize(new java.awt.Dimension(65, 20));
  547. jLabel5.setName("jLabel5"); // NOI18N
  548. jLabel5.setOpaque(true);
  549. jLabel5.setPreferredSize(new java.awt.Dimension(120, 20));
  550. jPanel4.add(jLabel5);
  551. dateadded.setMaximumSize(new java.awt.Dimension(333, 20));
  552. dateadded.setMinimumSize(new java.awt.Dimension(65, 20));
  553. dateadded.setName("dateadded"); // NOI18N
  554. dateadded.setOpaque(true);
  555. dateadded.setPreferredSize(new java.awt.Dimension(120, 20));
  556. jPanel4.add(dateadded);
  557. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  558. jPanel1.setLayout(jPanel1Layout);
  559. jPanel1Layout.setHorizontalGroup(
  560. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  561. .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  562. .addGroup(jPanel1Layout.createSequentialGroup()
  563. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  564. .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  565. .addComponent(street, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  566. .addContainerGap())
  567. );
  568. jPanel1Layout.setVerticalGroup(
  569. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  570. .addGroup(jPanel1Layout.createSequentialGroup()
  571. .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
  572. .addGap(0, 0, 0)
  573. .addComponent(street, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  574. .addGap(0, 0, 0)
  575. .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  576. );
  577. add(jPanel1, java.awt.BorderLayout.CENTER);
  578. SearchBarPane.setName("SearchBarPane"); // NOI18N
  579. SearchBarPane.setLayout(new java.awt.BorderLayout());
  580. add(SearchBarPane, java.awt.BorderLayout.WEST);
  581. }// </editor-fold>//GEN-END:initComponents
  582. private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
  583. JComboBox comboBox = (JComboBox) evt.getSource();
  584. javax.swing.text.StyledEditorKit.FontFamilyAction action =
  585. new StyledEditorKit.FontFamilyAction("xxx",
  586. comboBox.getSelectedItem().
  587. toString());
  588. action.actionPerformed(new ActionEvent(comboBox,
  589. ActionEvent.ACTION_PERFORMED,
  590. "xxx"));
  591. }//GEN-LAST:event_jComboBox1ActionPerformed
  592. private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed
  593. JToggleButton btn = (JToggleButton) evt.getSource();
  594. RTFEditorKit kit = (RTFEditorKit) RTF_Text.getEditorKit();
  595. MutableAttributeSet attr = kit.getInputAttributes();
  596. boolean bold =
  597. (StyleConstants.isBold(attr)) ? false : true;
  598. btn.setSelected(bold);
  599. SimpleAttributeSet sas = new SimpleAttributeSet();
  600. StyleConstants.setBold(sas,
  601. bold);
  602. RTF_Text.setCharacterAttributes(sas,
  603. false);
  604. }//GEN-LAST:event_jToggleButton1ActionPerformed
  605. private void jToggleButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton2ActionPerformed
  606. JToggleButton btn = (JToggleButton) evt.getSource();
  607. RTFEditorKit kit = (RTFEditorKit) RTF_Text.getEditorKit();
  608. MutableAttributeSet attr = kit.getInputAttributes();
  609. boolean italic =
  610. (StyleConstants.isItalic(attr)) ? false : true;
  611. btn.setSelected(italic);
  612. SimpleAttributeSet sas = new SimpleAttributeSet();
  613. StyleConstants.setItalic(sas,
  614. italic);
  615. RTF_Text.setCharacterAttributes(sas,
  616. false);
  617. }//GEN-LAST:event_jToggleButton2ActionPerformed
  618. private void jToggleButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton3ActionPerformed
  619. JToggleButton btn = (JToggleButton) evt.getSource();
  620. RTFEditorKit kit = (RTFEditorKit) RTF_Text.getEditorKit();
  621. MutableAttributeSet attr = kit.getInputAttributes();
  622. boolean under =
  623. (StyleConstants.isUnderline(attr)) ? false : true;
  624. btn.setSelected(under);
  625. SimpleAttributeSet sas = new SimpleAttributeSet();
  626. StyleConstants.setUnderline(sas,
  627. under);
  628. RTF_Text.setCharacterAttributes(sas,
  629. false);
  630. }//GEN-LAST:event_jToggleButton3ActionPerformed
  631. private void RTF_TextCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_RTF_TextCaretUpdate
  632. JTextPane text = (JTextPane) evt.getSource();
  633. StyledDocument doc = text.getStyledDocument();
  634. if (doc.getLength() > 0) {
  635. Boolean isBold = null;
  636. Boolean isItalic = null;
  637. Boolean isUnderline = null;
  638. Boolean tmp = null;
  639. String fontFamily = null;
  640. int fontSize = 8;
  641. for (int i = evt.getMark(); i < evt.getDot(); i++) {
  642. AttributeSet atts = doc.getCharacterElement(i).
  643. getAttributes();
  644. tmp = StyleConstants.isBold(atts);
  645. if (isBold == null) {
  646. isBold = tmp;
  647. } else if (tmp.equals(isBold) == false) {
  648. isBold = false;
  649. }
  650. tmp = StyleConstants.isItalic(atts);
  651. if (isItalic == null) {
  652. isItalic = tmp;
  653. } else if (tmp.equals(isItalic) == false) {
  654. isItalic = false;
  655. }
  656. tmp = StyleConstants.isUnderline(atts);
  657. if (isUnderline == null) {
  658. isUnderline = tmp;
  659. } else if (tmp.equals(isUnderline) == false) {
  660. isUnderline = false;
  661. }
  662. fontFamily = StyleConstants.getFontFamily(atts);
  663. fontSize = StyleConstants.getFontSize(atts);
  664. }
  665. if (isBold == null && isItalic == null && isUnderline == null) {
  666. AttributeSet atts = doc.getCharacterElement(evt.getDot() - 1).
  667. getAttributes();
  668. isBold = StyleConstants.isBold(atts);
  669. isItalic = StyleConstants.isItalic(atts);
  670. isUnderline = StyleConstants.isUnderline(atts);
  671. }
  672. if (fontFamily == null || fontSize == 8) {
  673. AttributeSet atts = doc.getCharacterElement(evt.getDot() - 1).
  674. getAttributes();
  675. fontFamily = StyleConstants.getFontFamily(atts);
  676. fontSize = StyleConstants.getFontSize(atts);
  677. }
  678. jToggleButton1.setSelected(isBold);
  679. jToggleButton2.setSelected(isItalic);
  680. jToggleButton3.setSelected(isUnderline);
  681. jComboBox1.setSelectedItem(fontFamily);
  682. jComboBox2.setSelectedItem(String.valueOf(fontSize));
  683. }
  684. }//GEN-LAST:event_RTF_TextCaretUpdate
  685. private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed
  686. JComboBox comboBox = (JComboBox) evt.getSource();
  687. javax.swing.text.StyledEditorKit.FontSizeAction action =
  688. new StyledEditorKit.FontSizeAction("xxx",
  689. Integer.parseInt(comboBox.getSelectedItem().
  690. toString()));
  691. action.actionPerformed(new ActionEvent(comboBox,
  692. ActionEvent.ACTION_PERFORMED,
  693. "xxx"));
  694. }//GEN-LAST:event_jComboBox2ActionPerformed
  695. private void actionShowContact(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actionShowContact
  696. try {
  697. int cid = Integer.valueOf(contactname.getSelectedItem().getId());
  698. Contact c = (Contact) DatabaseObject.getObject(Context.getContact(), cid);
  699. ContactPanel cp = new ContactPanel(Context.getContact());
  700. mpv5.YabsViewProxy.instance().getIdentifierView().addOrShowTab(cp, Messages.TYPE_CONTACT.toString());
  701. cp.setDataOwner(c, true);
  702. } catch (Exception e) {
  703. Log.Debug(this, e);
  704. }
  705. }//GEN-LAST:event_actionShowContact
  706. private void actionLookupContact(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actionLookupContact
  707. Contact dbo = (Contact) Search2.showSearchFor(Context.getContact());
  708. if (dbo != null) {
  709. contact = dbo;
  710. contactname.setModel(dbo);
  711. contactcity.setText(dbo.__getCity());
  712. contactzip.setText(dbo.__getZip());
  713. contactstreet.setText(dbo.__getStreet());
  714. contactcompany.setText(dbo.__getCompany());
  715. contactid.setText(dbo.__getCNumber());
  716. }
  717. }//GEN-LAST:event_actionLookupContact
  718. // Variables declaration - do not modify//GEN-BEGIN:variables
  719. private javax.swing.JTextPane RTF_Text;
  720. private javax.swing.JPanel SearchBarPane;
  721. private javax.swing.JPanel ToolBarPane;
  722. private javax.swing.JTextField addedby;
  723. private mpv5.ui.beans.LabeledCombobox adressList;
  724. private javax.swing.JTextField cname;
  725. private javax.swing.JTextField contactcity;
  726. private javax.swing.JTextField contactcompany;
  727. private javax.swing.JTextField contactid;
  728. private mpv5.ui.beans.LabeledCombobox contactname;
  729. private javax.swing.JTextField contactstreet;
  730. private javax.swing.JTextField contactzip;
  731. private mpv5.ui.beans.DateChooser dateTo;
  732. private mpv5.ui.beans.DateChooser dateadded;
  733. private javax.swing.JTextField ids;
  734. private javax.swing.JButton jButton3;
  735. private javax.swing.JButton jButton4;
  736. private javax.swing.JComboBox jComboBox1;
  737. private javax.swing.JComboBox jComboBox2;
  738. private javax.swing.JLabel jLabel3;
  739. private javax.swing.JLabel jLabel4;
  740. private javax.swing.JLabel jLabel5;
  741. private javax.swing.JLabel jLabel6;
  742. private javax.swing.JLabel jLabel7;
  743. private javax.swing.JPanel jPanel1;
  744. private javax.swing.JPanel jPanel3;
  745. private javax.swing.JPanel jPanel4;
  746. private javax.swing.JScrollPane jScrollPane1;
  747. private javax.swing.JSeparator jSeparator1;
  748. private javax.swing.JToggleButton jToggleButton1;
  749. private javax.swing.JToggleButton jToggleButton2;
  750. private javax.swing.JToggleButton jToggleButton3;
  751. private javax.swing.JPanel street;
  752. // End of variables declaration//GEN-END:variables
  753. /**
  754. * Give the DatabaseObject back
  755. * @return The DatabaseObject
  756. */
  757. public DatabaseObject getDataOwner() {
  758. return dataOwner;
  759. }
  760. /**
  761. * Sets the DatabaseObject
  762. * @param DatabaseObject
  763. * @param populate
  764. */
  765. public void setDataOwner(DatabaseObject object,
  766. boolean populate) {
  767. dataOwner = (Conversation) object;
  768. if (populate) {
  769. dataOwner.setPanelData(this);
  770. Runnable runnable = new Runnable() {
  771. @Override
  772. public void run() {
  773. try {
  774. me.exposeData();
  775. } catch (Exception e) {
  776. Log.Debug(this,
  777. e);
  778. }
  779. }
  780. };
  781. SwingUtilities.invokeLater(runnable);
  782. if (dataOwner.isExisting() && populate) {
  783. setTitle(dataOwner.__getCname());
  784. }
  785. tb.setFavourite(Favourite.isFavourite(object));
  786. tb.setEditable(!object.isReadOnly());
  787. if (object.isReadOnly()) {
  788. Popup.notice(Messages.LOCKED_BY);
  789. }
  790. validate();
  791. }
  792. }
  793. private void refresh_internal() {
  794. contact = null;
  795. sp.refresh();
  796. cname.setText("");
  797. contactcity.setText("");
  798. contactcompany.setText("");
  799. contactzip.setText("");
  800. contactstreet.setText("");
  801. contactid.setText("");
  802. dateTo.setDate(new Date());
  803. dateadded.setDate(new Date());
  804. addedby.setText(String.valueOf(User.getUserId(User.getCurrentUser().
  805. toString())));
  806. ids.setText("");
  807. try {
  808. RTF_Text.getStyledDocument().
  809. remove(0,
  810. RTF_Text.getStyledDocument().
  811. getLength());
  812. } catch (BadLocationException ex) {
  813. Log.Debug(this,
  814. "Fehler löschen Textfeld!!");
  815. }
  816. Log.Debug(this,
  817. "UI zurückgesetzt!!");
  818. }
  819. /**
  820. * Pastestub of the Copy&Paste-function
  821. * @param arg0
  822. */
  823. public void paste(DatabaseObject... arg0) {
  824. mpv5.YabsViewProxy.instance().
  825. addMessage(Messages.NOT_POSSIBLE.toString() + Messages.ACTION_PASTE.toString(), Color.RED);
  826. }
  827. /**
  828. * Checks the fullfillment of all requierements
  829. */
  830. public void showRequiredFields() {
  831. TextFieldUtils.blink(contactid,
  832. Color.RED);
  833. TextFieldUtils.blink(adressList,
  834. Color.RED);
  835. TextFieldUtils.blink(contactname,
  836. Color.RED);
  837. TextFieldUtils.blinkerRed(cname);
  838. cname.requestFocus();
  839. }
  840. /**
  841. * enables / disables the Searchbar
  842. * @param show
  843. */
  844. public void showSearchBar(boolean show) {
  845. SearchBarPane.removeAll();
  846. if (show) {
  847. SearchBarPane.add(sp,
  848. BorderLayout.CENTER);
  849. Log.Debug(ConversationPanel.class,
  850. "Suchfenster eingeblendet");
  851. sp.search();
  852. } else {
  853. Log.Debug(ConversationPanel.class,
  854. "Suchfenster ausgeblendet");
  855. }
  856. validate();
  857. }
  858. /**
  859. * empty Function
  860. */
  861. public void actionAfterSave() {
  862. }
  863. /**
  864. * empty Function
  865. */
  866. public void actionAfterCreate() {
  867. sp.refresh();
  868. }
  869. /**
  870. * empty Function
  871. */
  872. public void actionBeforeCreate() {
  873. }
  874. /**
  875. * Do an action bevor the System saves
  876. * @throws ChangeNotApprovedException
  877. */
  878. public void actionBeforeSave() throws ChangeNotApprovedException {
  879. if (dataOwner.isExisting()) {
  880. if (!mpv5.db.objects.User.getCurrentUser().
  881. getProperties().
  882. getProperty("org.openyabs.uiproperty",
  883. "nowarnings")) {
  884. if (!Popup.Y_N_dialog(Messages.REALLY_CHANGE)) {
  885. throw new ChangeNotApprovedException(dataOwner);
  886. }
  887. }
  888. }
  889. }
  890. /**
  891. * Sends the DataObject as Mail
  892. */
  893. public void mail() {
  894. // if (dataOwner != null && dataOwner.isExisting()) {
  895. // if (TemplateHandler.isLoaded(dataOwner.templateGroupIds(), dataOwner.__getInttype())) {
  896. //
  897. // try {
  898. // Contact cont = (Contact) (Contact.getObject(Context.getContact(), dataOwner.__getContactsids()));
  899. // Export.mail(TemplateHandler.loadTemplate(dataOwner.templateGroupIds(), dataOwner.__getInttype()), dataOwner, cont);
  900. // } catch (NodataFoundException ex) {
  901. // Log.Debug(ex);
  902. // }
  903. // } else {
  904. // Popup.notice(Messages.NO_TEMPLATE_LOADED + " (" + mpv5.db.objects.User.getCurrentUser() + ")");
  905. // }
  906. // } else {
  907. // Popup.notice(Messages.NOT_POSSIBLE + "\n" + Messages.NOT_SAVED_YET);
  908. // }
  909. }
  910. /**
  911. * prints the DataObject
  912. */
  913. public void print() {
  914. if (dataOwner != null && dataOwner.isExisting()) {
  915. if (TemplateHandler.isLoaded(Long.valueOf(dataOwner.templateGroupIds()),
  916. Type)) {
  917. Export.print(TemplateHandler.loadTemplate(dataOwner.templateGroupIds(),
  918. Type),
  919. dataOwner);
  920. } else {
  921. Popup.notice(Messages.NO_TEMPLATE_LOADED + " (" + mpv5.db.objects.User.getCurrentUser() + ")");
  922. Export.print(this);
  923. }
  924. } else {
  925. Popup.notice(Messages.FILE_NOT_SAVED);
  926. }
  927. }
  928. /**
  929. * Sends the DataObject as PDF
  930. */
  931. public void pdf() {
  932. if (dataOwner != null && dataOwner.isExisting()) {
  933. if (TemplateHandler.isLoaded(Long.valueOf(dataOwner.templateGroupIds()),
  934. Type)) {
  935. new Job(Export.createFile(cname_,
  936. TemplateHandler.loadTemplate(dataOwner.templateGroupIds(),
  937. Type),
  938. dataOwner,
  939. getAddData()),
  940. new DialogForFile(User.getSaveDir(dataOwner))).execute();
  941. } else {
  942. Popup.notice(Messages.NO_TEMPLATE_LOADED + " (" + mpv5.db.objects.User.getCurrentUser() + ")");
  943. }
  944. } else {
  945. Popup.notice(Messages.FILE_NOT_SAVED);
  946. }
  947. }
  948. /**
  949. * Sends the DataObject as odt
  950. */
  951. public void odt() {
  952. if (dataOwner != null && dataOwner.isExisting()) {
  953. if (TemplateHandler.isLoaded(Long.valueOf(dataOwner.templateGroupIds()),
  954. Type)) {
  955. new Job(Export.sourceFile(cname_,
  956. TemplateHandler.loadTemplate(dataOwner.templateGroupIds(),
  957. Type),
  958. dataOwner),
  959. new DialogForFile(User.getSaveDir(dataOwner))).execute();
  960. } else {
  961. Popup.notice(Messages.NO_TEMPLATE_LOADED + " (" + mpv5.db.objects.User.getCurrentUser() + ")");
  962. }
  963. } else {
  964. Popup.notice(Messages.FILE_NOT_SAVED);
  965. }
  966. }
  967. /**
  968. * Collects the Data from the Userscreen
  969. */
  970. public boolean collectData() {
  971. if (contactname.getSelectedItem() == null) {
  972. showRequiredFields();
  973. return false;
  974. } else {
  975. groupsids_ = 1;
  976. cname_ = cname.getText();
  977. cnumber_ = contactid.getText();
  978. contactsids_ = Integer.parseInt(contactname.getSelectedItem().getId());
  979. adress_ = adressList.getSelectedItem().getId();
  980. date_ = dateTo.getDate();
  981. dateadded_ = dateadded.getDate();
  982. intaddedby_ = User.getUserId(addedby.getText());
  983. content_ = serialize();
  984. if (cname_.length() == 0
  985. || cnumber_.length() == 0
  986. || adress_.equals("choose")) {
  987. Popup.notice(Messages.CONTACT_COMPLETE.toString());
  988. return false;
  989. }
  990. Object[][] liste = new DatabaseSearch(dataOwner).getValuesFor(
  991. Context.IDENTITY_CONVERSATION + "." + "CNAME",
  992. "cname",
  993. cname_);
  994. if (liste.length > 0 && !dataOwner.isExisting()) {
  995. Popup.notice(
  996. Messages.CNAME_EXISTS.toString());
  997. return false;
  998. }
  999. }
  1000. return true;
  1001. }
  1002. /**
  1003. * Puts the Data to the Userscreen
  1004. */
  1005. public void exposeData() {
  1006. cname.setText(cname_);
  1007. fillContactFields();
  1008. dateTo.setDate(date_);
  1009. dateadded.setDate(dateadded_);
  1010. addedby.setText(User.getUsername(intaddedby_));
  1011. ids.setText(dataOwner.__getIDS().
  1012. toString());
  1013. deserialize(content_);
  1014. }
  1015. private String serialize() {
  1016. ByteArrayOutputStream out;
  1017. RTFEditorKit kit = (RTFEditorKit) RTF_Text.getEditorKit();
  1018. StyledDocument doc = RTF_Text.getStyledDocument();
  1019. out = new ByteArrayOutputStream();
  1020. try {
  1021. kit.write(out,
  1022. doc,
  1023. 0,
  1024. doc.getLength());
  1025. } catch (BadLocationException ex) {
  1026. Log.Debug(this,
  1027. ex.toString());
  1028. } catch (IOException ex) {
  1029. Log.Debug(this,
  1030. ex.toString());
  1031. }
  1032. String str = null;
  1033. str = out.toString();
  1034. str = str.replaceAll("[\r\n]+",
  1035. " ");
  1036. str = str.replaceAll(" ",
  1037. " ");
  1038. return str;
  1039. }
  1040. private void deserialize(String in) {
  1041. ByteArrayInputStream stream = null;
  1042. in = in.replaceAll("`",
  1043. "'");
  1044. RTFEditorKit kit = (RTFEditorKit) RTF_Text.getEditorKit();
  1045. StyledDocument doc = RTF_Text.getStyledDocument();
  1046. stream = new ByteArrayInputStream(in.getBytes());
  1047. Log.Debug(this,
  1048. in);
  1049. try {
  1050. doc.remove(0,
  1051. doc.getLength());
  1052. kit.read(stream,
  1053. doc,
  1054. 0);
  1055. } catch (BadLocationException ex) {
  1056. Log.Debug(this,
  1057. ex.toString());
  1058. } catch (IOException ex) {
  1059. Log.Debug(this,
  1060. ex.toString());
  1061. }
  1062. }
  1063. private void setTitle(String title) {
  1064. if (this.getParent() instanceof JViewport
  1065. || this.getParent() instanceof JTabbedPane) {
  1066. JTabbedPane jTabbedPane = null;
  1067. String title1 = title;
  1068. if (this.getParent().
  1069. getParent().
  1070. getParent() instanceof JTabbedPane) {
  1071. jTabbedPane = (JTabbedPane) this.getParent().
  1072. getParent().
  1073. getParent();
  1074. } else {
  1075. try {
  1076. jTabbedPane = (JTabbedPane) this.getParent();
  1077. } catch (Exception e) {
  1078. //Free floating window
  1079. ((JFrame) this.getRootPane().
  1080. getParent()).setTitle(title1);
  1081. }
  1082. }
  1083. if (jTabbedPane != null) {
  1084. jTabbedPane.setTitleAt(jTabbedPane.getSelectedIndex(),
  1085. title1);
  1086. }
  1087. }
  1088. }
  1089. /**
  1090. * empty
  1091. */
  1092. public void refresh() {
  1093. }
  1094. private void fillContactFields() {
  1095. Log.Debug(this,
  1096. "Felder füllen ...");
  1097. try {
  1098. Log.Debug(this,
  1099. "... mit ID: " + contactsids_);
  1100. if (contactsids_ > 0) {
  1101. contact = (Contact) DatabaseObject.getObject(Context.getContact(),
  1102. contactsids_,
  1103. false);
  1104. contactid.setText(cnumber_);
  1105. contactname.setModel(contact);
  1106. try {
  1107. t.join();
  1108. adressList.setSelectedItem(Integer.parseInt(adress_));
  1109. } catch (InterruptedException ex) {
  1110. Log.Debug(this, ex);
  1111. }
  1112. Log.Debug(this, "test..2");
  1113. }
  1114. } catch (NodataFoundException ex) {
  1115. Log.Debug(this,
  1116. ex);
  1117. }
  1118. }
  1119. }