/src/mpv5/ui/panels/MassPrintPanel.java
Java | 747 lines | 655 code | 66 blank | 26 comment | 58 complexity | 04af50f04f65f1c2114abbb29c5dd8f0 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
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /*
- * MassPrintUI.java
- *
- * Created on 09.05.2011, 22:07:37
- */
- package mpv5.ui.panels;
- import enoa.handler.TemplateHandler;
- import java.awt.Font;
- import java.awt.GraphicsEnvironment;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseEvent;
- import java.io.ByteArrayOutputStream;
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.DefaultListModel;
- import javax.swing.JComboBox;
- import javax.swing.JTextPane;
- import javax.swing.JToggleButton;
- import javax.swing.text.AttributeSet;
- import javax.swing.text.BadLocationException;
- import javax.swing.text.MutableAttributeSet;
- import javax.swing.text.SimpleAttributeSet;
- import javax.swing.text.StyleConstants;
- import javax.swing.text.StyledDocument;
- import javax.swing.text.StyledEditorKit;
- import javax.swing.text.rtf.RTFEditorKit;
- import mpv5.db.common.Context;
- import mpv5.db.common.DatabaseObject;
- import mpv5.db.common.DatabaseSearch;
- import mpv5.db.common.NodataFoundException;
- import mpv5.db.common.QueryHandler;
- import mpv5.db.common.ReturnValue;
- import mpv5.db.objects.Contact;
- import mpv5.db.objects.MailMessage;
- import mpv5.db.objects.MassprintRules;
- import mpv5.db.objects.Template;
- import mpv5.db.objects.User;
- import mpv5.globals.Constants;
- import mpv5.globals.LocalSettings;
- import mpv5.globals.Messages;
- import mpv5.logging.Log;
- import mpv5.ui.dialogs.DialogForFile;
- import mpv5.ui.dialogs.Popup;
- import mpv5.ui.menus.ListMenuItem;
- import mpv5.ui.popups.ListPopUp;
- import mpv5.usermanagement.MPSecurityManager;
- import mpv5.utils.export.Export;
- import mpv5.utils.jobs.Job;
- import mpv5.utils.jobs.Waitable;
- /**
- *
- * @author Samsung SA11
- */
- public class MassPrintPanel
- extends javax.swing.JPanel
- implements ActionListener {
- private static MassPrintPanel me;
- private final DefaultListModel model;
- private static final long serialVersionUID = -4425127949239926332L;
- /**
- * Singleton
- * @return
- */
- public static MassPrintPanel instanceOf() {
- if (me == null) {
- me = new MassPrintPanel();
- }
- me.setContacts();
- me.setTemplateList();
- me.setMessageTemplateList();
- return me;
- }
- private int cursorPosition;
- /** Creates new form MassPrintUI */
- public MassPrintPanel() {
- model = new DefaultListModel();
- initComponents();
- setName("MassPrintPanel");
- }
- /** This method is called from within the constructor to
- * initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is
- * always regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
- private void initComponents() {
- jPanel3 = new javax.swing.JPanel();
- jComboBox2 = new javax.swing.JComboBox();
- String fontSizes[] = {"8", "10", "11", "12", "14", "16", "18",
- "20", "24", "30", "36", "40", "48", "60", "72"};
- for (int index = 0; index < fontSizes.length; index++) {
- jComboBox2.addItem(fontSizes[index]);
- }
- jComboBox1 = new javax.swing.JComboBox();
- try {
- String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
- Log.Debug(this, "Ermittelte Fonts: " + fonts.length);
- for (int index = 0; index < fonts.length; index++) {
- jComboBox1.addItem(fonts[index]);
- }
- } catch (Exception e) {
- Log.Debug(MassPrintPanel.class, e);
- }
- jToggleButton3 = new javax.swing.JToggleButton();
- jToggleButton1 = new javax.swing.JToggleButton();
- jToggleButton2 = new javax.swing.JToggleButton();
- jLabel3 = new javax.swing.JLabel();
- jScrollPane1 = new javax.swing.JScrollPane();
- RTF_Text = new javax.swing.JTextPane();
- dateTo = new mpv5.ui.beans.DateChooser();
- templates = new javax.swing.JComboBox();
- jButton1 = new javax.swing.JButton();
- jLabel5 = new javax.swing.JLabel();
- jButton2 = new javax.swing.JButton();
- messageTpl = new javax.swing.JComboBox();
- jLabel6 = new javax.swing.JLabel();
- jLabel7 = new javax.swing.JLabel();
- jPanel1 = new javax.swing.JPanel();
- jScrollPane2 = new javax.swing.JScrollPane();
- contactlist = new javax.swing.JList();
- setName("Form"); // NOI18N
- setPreferredSize(new java.awt.Dimension(1004, 333));
- setLayout(new java.awt.BorderLayout());
- java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
- jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ConversationPanel.jPanel3.border.title"))); // NOI18N
- jPanel3.setPreferredSize(new java.awt.Dimension(818, 333));
- jComboBox2.setName("jComboBox2"); // NOI18N
- jComboBox2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jComboBox2ActionPerformed(evt);
- }
- });
- jComboBox1.setName("jComboBox1"); // NOI18N
- jComboBox1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jComboBox1ActionPerformed(evt);
- }
- });
- jToggleButton3.setFont(jToggleButton3.getFont());
- jToggleButton3.setText(bundle.getString("ConversationPanel.jToggleButton3.text")); // NOI18N
- jToggleButton3.setName("jToggleButton3"); // NOI18N
- jToggleButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jToggleButton3ActionPerformed(evt);
- }
- });
- jToggleButton1.setFont(new java.awt.Font("Tahoma", 1, 11));
- jToggleButton1.setText(bundle.getString("ConversationPanel.jToggleButton1.text")); // NOI18N
- jToggleButton1.setName("jToggleButton1"); // NOI18N
- jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jToggleButton1ActionPerformed(evt);
- }
- });
- jToggleButton2.setFont(new java.awt.Font("Tahoma", 2, 11));
- jToggleButton2.setText(bundle.getString("ConversationPanel.jToggleButton2.text")); // NOI18N
- jToggleButton2.setName("jToggleButton2"); // NOI18N
- jToggleButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jToggleButton2ActionPerformed(evt);
- }
- });
- jLabel3.setText(bundle.getString("ConversationPanel.jLabel3.text")); // NOI18N
- jLabel3.setName("jLabel3"); // NOI18N
- jScrollPane1.setName("jScrollPane1"); // NOI18N
- RTF_Text.setDocument(new javax.swing.text.rtf.RTFEditorKit().createDefaultDocument());
- RTF_Text.setEditorKit(new javax.swing.text.rtf.RTFEditorKit());
- RTF_Text.setFont(Font.decode(LocalSettings.getProperty(LocalSettings.DEFAULT_FONT)).deriveFont(Font.PLAIN, 11));
- RTF_Text.setName("RTF_Text"); // NOI18N
- RTF_Text.addCaretListener(new javax.swing.event.CaretListener() {
- public void caretUpdate(javax.swing.event.CaretEvent evt) {
- RTF_TextCaretUpdate(evt);
- }
- });
- jScrollPane1.setViewportView(RTF_Text);
- dateTo.setMaximumSize(new java.awt.Dimension(32767, 20));
- dateTo.setMinimumSize(new java.awt.Dimension(120, 20));
- dateTo.setName("dateTo"); // NOI18N
- dateTo.setPreferredSize(new java.awt.Dimension(150, 20));
- templates.setModel(new DefaultComboBoxModel());
- templates.setName("templates"); // NOI18N
- jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/32/bright_printer.png"))); // NOI18N
- jButton1.setText(bundle.getString("MassPrintPanel.jButton1.text")); // NOI18N
- jButton1.setName("jButton1"); // NOI18N
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jLabel5.setText(bundle.getString("ConversationPanel.jLabel3.text")); // NOI18N
- jLabel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());
- jLabel5.setName("jLabel5"); // NOI18N
- jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/32/acroread.png"))); // NOI18N
- jButton2.setText(bundle.getString("MassPrintPanel.jButton2.text_1")); // NOI18N
- jButton2.setName("jButton2"); // NOI18N
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- messageTpl.setModel(new DefaultComboBoxModel());
- messageTpl.setName("messageTpl"); // NOI18N
- messageTpl.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- messageTplActionPerformed(evt);
- }
- });
- jLabel6.setText(bundle.getString("MassPrintPanel.jLabel6.text")); // NOI18N
- jLabel6.setName("jLabel6"); // NOI18N
- jLabel7.setText(bundle.getString("MassPrintPanel.jLabel7.text")); // NOI18N
- jLabel7.setName("jLabel7"); // NOI18N
- javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
- jPanel3.setLayout(jPanel3Layout);
- jPanel3Layout.setHorizontalGroup(
- jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel3Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 820, Short.MAX_VALUE)
- .addGroup(jPanel3Layout.createSequentialGroup()
- .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel3Layout.createSequentialGroup()
- .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(templates, javax.swing.GroupLayout.Alignment.LEADING, 0, 183, Short.MAX_VALUE))
- .addGap(18, 18, 18)
- .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(messageTpl, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
- .addGroup(jPanel3Layout.createSequentialGroup()
- .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(7, 7, 7)
- .addComponent(jToggleButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(2, 2, 2)
- .addComponent(jToggleButton2)
- .addGap(5, 5, 5)
- .addComponent(jToggleButton3)
- .addGap(22, 22, 22)
- .addComponent(jLabel3)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(dateTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addGap(10, 10, 10))
- .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 820, Short.MAX_VALUE)))
- );
- jPanel3Layout.setVerticalGroup(
- jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel3Layout.createSequentialGroup()
- .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addGroup(jPanel3Layout.createSequentialGroup()
- .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
- .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
- .addComponent(templates, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(messageTpl, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addComponent(jButton2, javax.swing.GroupLayout.Alignment.CENTER, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE)
- .addComponent(jButton1, javax.swing.GroupLayout.Alignment.CENTER, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
- .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jToggleButton1)
- .addComponent(jToggleButton2)
- .addComponent(jToggleButton3)
- .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(dateTo, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE))
- );
- add(jPanel3, java.awt.BorderLayout.CENTER);
- jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("MassPrintPanel.jPanel1.border.title_1"))); // NOI18N
- jPanel1.setPreferredSize(new java.awt.Dimension(170, 333));
- jScrollPane2.setName("jScrollPane2"); // NOI18N
- contactlist.setModel(model);
- contactlist.setToolTipText(bundle.getString("MassPrintPanel.contactlist.toolTipText_1")); // NOI18N
- contactlist.setName("contactlist"); // NOI18N
- contactlist.setSelectionBackground(java.awt.Color.green);
- contactlist.setSelectionForeground(java.awt.Color.black);
- contactlist.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseReleased(java.awt.event.MouseEvent evt) {
- contactlistMouseReleased(evt);
- }
- });
- jScrollPane2.setViewportView(contactlist);
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 349, Short.MAX_VALUE)
- );
- add(jPanel1, java.awt.BorderLayout.WEST);
- }// </editor-fold>//GEN-END:initComponents
- private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed
- JToggleButton btn = (JToggleButton) evt.getSource();
- RTFEditorKit kit = (RTFEditorKit) RTF_Text.getEditorKit();
- MutableAttributeSet attr = kit.getInputAttributes();
- boolean bold = (StyleConstants.isBold(attr)) ? false : true;
- btn.setSelected(bold);
- SimpleAttributeSet sas = new SimpleAttributeSet();
- StyleConstants.setBold(sas, bold);
- RTF_Text.setCharacterAttributes(sas, false);
- }//GEN-LAST:event_jToggleButton1ActionPerformed
- private void jToggleButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton2ActionPerformed
- JToggleButton btn = (JToggleButton) evt.getSource();
- RTFEditorKit kit = (RTFEditorKit) RTF_Text.getEditorKit();
- MutableAttributeSet attr = kit.getInputAttributes();
- boolean italic = (StyleConstants.isItalic(attr)) ? false : true;
- btn.setSelected(italic);
- SimpleAttributeSet sas = new SimpleAttributeSet();
- StyleConstants.setItalic(sas, italic);
- RTF_Text.setCharacterAttributes(sas, false);
- }//GEN-LAST:event_jToggleButton2ActionPerformed
- private void jToggleButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton3ActionPerformed
- JToggleButton btn = (JToggleButton) evt.getSource();
- RTFEditorKit kit = (RTFEditorKit) RTF_Text.getEditorKit();
- MutableAttributeSet attr = kit.getInputAttributes();
- boolean under = (StyleConstants.isUnderline(attr)) ? false : true;
- btn.setSelected(under);
- SimpleAttributeSet sas = new SimpleAttributeSet();
- StyleConstants.setUnderline(sas, under);
- RTF_Text.setCharacterAttributes(sas, false);
- }//GEN-LAST:event_jToggleButton3ActionPerformed
- private void RTF_TextCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_RTF_TextCaretUpdate
- JTextPane text = (JTextPane) evt.getSource();
- StyledDocument doc = text.getStyledDocument();
- if (doc.getLength() > 0) {
- Boolean isBold = null;
- Boolean isItalic = null;
- Boolean isUnderline = null;
- Boolean tmp = null;
- String fontFamily = null;
- int fontSize = 8;
- cursorPosition = evt.getDot();
- for (int i = evt.getMark(); i < cursorPosition; i++) {
- AttributeSet atts = doc.getCharacterElement(i).getAttributes();
- tmp = StyleConstants.isBold(atts);
- if (isBold == null) {
- isBold = tmp;
- } else if (tmp.equals(isBold) == false) {
- isBold = false;
- }
- tmp = StyleConstants.isItalic(atts);
- if (isItalic == null) {
- isItalic = tmp;
- } else if (tmp.equals(isItalic) == false) {
- isItalic = false;
- }
- tmp = StyleConstants.isUnderline(atts);
- if (isUnderline == null) {
- isUnderline = tmp;
- } else if (tmp.equals(isUnderline) == false) {
- isUnderline = false;
- }
- fontFamily = StyleConstants.getFontFamily(atts);
- fontSize = StyleConstants.getFontSize(atts);
- }
- if (isBold == null && isItalic == null && isUnderline == null) {
- AttributeSet atts = doc.getCharacterElement(evt.getDot() - 1).getAttributes();
- isBold = StyleConstants.isBold(atts);
- isItalic = StyleConstants.isItalic(atts);
- isUnderline = StyleConstants.isUnderline(atts);
- }
- if (fontFamily == null || fontSize == 8) {
- AttributeSet atts = doc.getCharacterElement(evt.getDot() - 1).getAttributes();
- fontFamily = StyleConstants.getFontFamily(atts);
- fontSize = StyleConstants.getFontSize(atts);
- }
- jToggleButton1.setSelected(isBold);
- jToggleButton2.setSelected(isItalic);
- jToggleButton3.setSelected(isUnderline);
- jComboBox1.setSelectedItem(fontFamily);
- jComboBox2.setSelectedItem(String.valueOf(fontSize));
- }
- }//GEN-LAST:event_RTF_TextCaretUpdate
- private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
- JComboBox comboBox = (JComboBox) evt.getSource();
- javax.swing.text.StyledEditorKit.FontFamilyAction action = new StyledEditorKit.FontFamilyAction("yyy", comboBox.getSelectedItem().toString());
- action.actionPerformed(new ActionEvent(comboBox, ActionEvent.ACTION_PERFORMED, "yyy"));
- }//GEN-LAST:event_jComboBox1ActionPerformed
- private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed
- JComboBox comboBox = (JComboBox) evt.getSource();
- javax.swing.text.StyledEditorKit.FontSizeAction action = new StyledEditorKit.FontSizeAction("xxx", Integer.parseInt(comboBox.getSelectedItem().toString()));
- action.actionPerformed(new ActionEvent(comboBox, ActionEvent.ACTION_PERFORMED, "xxx"));
- }//GEN-LAST:event_jComboBox2ActionPerformed
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- Object[] sel = contactlist.getSelectedValues();
- Template tpl = (Template) templates.getSelectedItem();
- HashMap<String, Object> hm1;
- List<File> files = new ArrayList<File>();
- File f;
- if (tpl != null) {
- for (int o = 0; o < sel.length; o++) {
- try {
- Contact cont = (Contact) (Contact.getObject(Context.getContact(), ((IdItem) sel[o]).getId()));
- hm1 = new HashMap<String, Object>();
- hm1 = me.ReplaceVariablesInContent(hm1, cont);
- f = Export.print2(TemplateHandler.loadTemplate(tpl),
- cont, hm1);
- files.add(f);
- mpv5.YabsViewProxy.instance().getProgressbar().setValue((100 / sel.length) * (o + 1));
- mpv5.YabsViewProxy.instance().getProgressbar().setString(cont.__getCname());
- mpv5.YabsViewProxy.instance().getProgressbar().setStringPainted(true);
- } catch (NodataFoundException e) {
- Log.Debug(this, e);
- }
- }
- } else {
- Popup.error(MassPrintPanel.instanceOf(), Messages.NO_TEMPLATE_DEFINDED.toString());
- }
- if (!files.isEmpty()) {
- try {
- Export.print3(files, tpl.__getPrinter());
- } catch (Exception ex1) {
- Log.Debug(ex1);
- }
- }
- }
- };
- new Thread(runnable).start();
- }//GEN-LAST:event_jButton1ActionPerformed
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
- Object[] sel = contactlist.getSelectedValues();
- Template tpl = (Template) templates.getSelectedItem();
- HashMap<String, Object> hm1;
- List<Waitable> files = new ArrayList<Waitable>();
- if (tpl != null) {
- for (int o = 0; o < sel.length; o++) {
- try {
- Contact cont = (Contact) (Contact.getObject(Context.getContact(), ((IdItem) sel[o]).getId()));
- hm1 = new HashMap<String, Object>();
- hm1 = this.ReplaceVariablesInContent(hm1, cont);
- files.add(Export.createFile(cont.__getCname(),
- TemplateHandler.loadTemplate(tpl),
- cont,
- hm1));
- mpv5.YabsViewProxy.instance().getProgressbar().setValue((100 / sel.length) * (o + 1));
- mpv5.YabsViewProxy.instance().getProgressbar().setString(cont.__getCname());
- mpv5.YabsViewProxy.instance().getProgressbar().setStringPainted(true);
- } catch (NodataFoundException ex) {
- Log.Debug(this, ex);
- }
- }
- } else {
- Popup.error(this, Messages.NO_TEMPLATE_DEFINDED.toString());
- }
- if (!files.isEmpty()) {
- DialogForFile.CURRENT_DIR = new File(LocalSettings.getProperty(LocalSettings.BASE_DIR) + File.separator + "test");
- DialogForFile d = new DialogForFile();
- Job job = new Job(files, d, files.size() + " PDF " + Messages.SAVED);
- job.execute();
- mpv5.YabsViewProxy.instance().getProgressbar().setValue(100);
- mpv5.YabsViewProxy.instance().getProgressbar().setString(Messages.DONE.toString());
- }
- }//GEN-LAST:event_jButton2ActionPerformed
- private void messageTplActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_messageTplActionPerformed
- if (evt.getModifiers() == 16) {
- try {
- String cn = (String) messageTpl.getSelectedItem();
- MailMessage msg = (MailMessage) (MailMessage.getObject(Context.getMessage(), cn));
- StyledDocument doc = RTF_Text.getStyledDocument();
- doc.insertString(cursorPosition, msg.__getDescription(), null);
- } catch (BadLocationException ex) {
- Log.Debug(this, ex);
- } catch (NodataFoundException ex) {
- Log.Debug(this, ex);
- }
- }
- }//GEN-LAST:event_messageTplActionPerformed
- private void contactlistMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_contactlistMouseReleased
- if (evt.isPopupTrigger()) {
- showMenu(evt);
- }
- }//GEN-LAST:event_contactlistMouseReleased
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JTextPane RTF_Text;
- private javax.swing.JList contactlist;
- private mpv5.ui.beans.DateChooser dateTo;
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JComboBox jComboBox1;
- private javax.swing.JComboBox jComboBox2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel5;
- private javax.swing.JLabel jLabel6;
- private javax.swing.JLabel jLabel7;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JPanel jPanel3;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JScrollPane jScrollPane2;
- private javax.swing.JToggleButton jToggleButton1;
- private javax.swing.JToggleButton jToggleButton2;
- private javax.swing.JToggleButton jToggleButton3;
- private javax.swing.JComboBox messageTpl;
- private javax.swing.JComboBox templates;
- // End of variables declaration//GEN-END:variables
- private void setContacts() {
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- Object[][] data1 = null;
- data1 = new DatabaseSearch(Context.getContact(), 200).getValuesFor("ids, cname", "cname", "", true);
- model.clear();
- for (int i = 0; i < data1.length; i++) {
- model.addElement(new IdItem(Integer.parseInt(data1[i][0].toString()), data1[i][1].toString()));
- }
- }
- };
- new Thread(runnable).start();
- }
- private void showMenu(MouseEvent evt) {
- try {
- Object[][] d = QueryHandler.instanceOf().clone(Context.getMassprint()).select(Context.DETAILS_MASSPRINT, false);
- String[][] rules = new String[d.length + 1][2];
- ActionListener[] act = new ActionListener[d.length + 1];
- rules[0][0] = Messages.MASSPRINT_FILTER_ALL.toString();
- rules[0][1] = "999999";
- act[0] = this;
- for (int i = 0; i < d.length; i++) {
- rules[i + 1][0] = d[i][1].toString();
- rules[i + 1][1] = d[i][0].toString();
- act[i + 1] = this;
- }
- new ListPopUp(contactlist, rules, act);
- } catch (NodataFoundException ex) {
- Log.Debug(this, ex);
- }
- }
- private void setTemplateList() {
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- DefaultComboBoxModel mdl = (DefaultComboBoxModel) templates.getModel();
- Template[] tpl = TemplateHandler.getTemplatesForType(User.getCurrentUser().__getGroupsids(), Constants.TYPE_MASSPRINT);
- mdl.removeAllElements();
- for (int i = 0; i < tpl.length; i++) {
- mdl.addElement(tpl[i]);
- TemplateHandler.loadTemplate(tpl[i]);
- }
- }
- };
- new Thread(runnable).start();
- }
- private HashMap<String, Object> ReplaceVariablesInContent(HashMap<String, Object> hm1, Contact cont) {
- String rtf = serialize();
- hm1.put("massprint.cname", "");
- hm1.put("massprint.addedby", User.getCurrentUser().getName());
- hm1.put("massprint.dateadded", dateTo.getDate());
- if (cont.__getisMale()) {
- hm1.put("massprint.gender",
- Messages.CONTACT_TYPE_MALE.toString());
- hm1.put("massprint.intro",
- Messages.CONTACT_INTRO_MALE.toString());
- } else {
- hm1.put("massprint.gender",
- Messages.CONTACT_TYPE_FEMALE.toString());
- hm1.put("massprint.intro",
- Messages.CONTACT_INTRO_FEMALE.toString());
- }
- hm1.put("massprint.content", rtf);
- return hm1;
- }
- private String serialize() {
- ByteArrayOutputStream out;
- RTFEditorKit kit = (RTFEditorKit) RTF_Text.getEditorKit();
- StyledDocument doc = RTF_Text.getStyledDocument();
- out = new ByteArrayOutputStream();
- try {
- kit.write(out,
- doc,
- 0,
- doc.getLength());
- } catch (BadLocationException ex) {
- Log.Debug(this,
- ex.toString());
- } catch (IOException ex) {
- Log.Debug(this,
- ex.toString());
- }
- String str = null;
- str = out.toString();
- str = str.replaceAll("[\r\n]+",
- " ");
- str = str.replaceAll(" ",
- " ");
- return str;
- }
- private void setMessageTemplateList() {
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- DefaultComboBoxModel mdl = (DefaultComboBoxModel) messageTpl.getModel();
- Object[][] data1 = null;
- data1 = new DatabaseSearch(Context.getMessage(), 200).getValuesFor("cname", "cname", "", true);
- mdl.removeAllElements();
- for (int i = 0; i < data1.length; i++) {
- mdl.addElement((String) data1[i][0]);
- }
- }
- };
- new Thread(runnable).start();
- }
- public void actionPerformed(ActionEvent e) {
- int cname = 0;
- ListMenuItem mi = (ListMenuItem) e.getSource();
- Log.Debug(this, " Executing Rule: " + mi.getID());
- Object[][] data = null;
- int ids = 0;
- try {
- if (mi.getID() == 999999) {
- model.clear();
- data = new DatabaseSearch(Context.getContact(), 200).getValuesFor("ids, cname", "cname", "", true);
- for (int i = 0; i < data.length; i++) {
- model.addElement(new IdItem(Integer.parseInt(data[i][0].toString()), data[i][1].toString()));
- }
- } else {
- MassprintRules mpr = (MassprintRules) (DatabaseObject.getObject(Context.getMassprint(), mi.getID()));
- model.clear();
- ReturnValue ret = QueryHandler.instanceOf().freeSelectQuery(mpr.__getContent(), MPSecurityManager.VIEW, null);
- String[] cols = ret.getFullColumnNames();
- for (int j = 0; j < cols.length; j++) {
- if (cols[j].equalsIgnoreCase("contacts.cname")) {
- cname = j;
- }
- if (cols[j].equalsIgnoreCase("contacts.ids")) {
- ids = j;
- }
- }
- data = ret.getData();
- for (int i = 0; i < data.length; i++) {
- model.addElement(new IdItem(Integer.parseInt(data[i][ids].toString()), data[i][cname].toString()));
- }
- }
- } catch (NodataFoundException ex) {
- Log.Debug(this, ex);
- }
- }
- class IdItem {
- int id;
- String description;
- IdItem(int id, String description) {
- this.id = id;
- this.description = description;
- }
- public int getId() {
- return id;
- }
- @Override
- public String toString() {
- return description;
- }
- }
- }