PageRenderTime 234ms CodeModel.GetById 41ms app.highlight 156ms RepoModel.GetById 24ms app.codeStats 1ms

/src/mpv5/ui/dialogs/subcomponents/ControlPanel_Templates.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 981 lines | 832 code | 121 blank | 28 comment | 75 complexity | 55d4d33d9bfd1e55c5876d777aa37c44 MD5 | raw file
  1package mpv5.ui.dialogs.subcomponents;
  2
  3import enoa.handler.TableHandler;
  4import enoa.handler.TemplateHandler;
  5import java.awt.Color;
  6import java.awt.Component;
  7import java.awt.Desktop;
  8import java.io.File;
  9import java.io.IOException;
 10import java.net.URI;
 11import java.util.ArrayList;
 12import java.util.Arrays;
 13import java.util.Date;
 14import java.util.HashMap;
 15import java.util.List;
 16import java.util.logging.Level;
 17import java.util.logging.Logger;
 18import javax.print.PrintService;
 19import javax.print.PrintServiceLookup;
 20import javax.swing.DefaultComboBoxModel;
 21import javax.swing.DefaultListModel;
 22import mpv5.YabsViewProxy;
 23import mpv5.data.PropertyStore;
 24import mpv5.db.common.Context;
 25import mpv5.db.common.DatabaseObject;
 26import mpv5.db.common.DatabaseSearch;
 27import mpv5.db.common.NodataFoundException;
 28import mpv5.db.common.QueryCriteria;
 29import mpv5.db.common.QueryData;
 30import mpv5.db.common.QueryHandler;
 31import mpv5.db.common.SaveString;
 32
 33import mpv5.db.objects.*;
 34import mpv5.db.objects.SubItem;
 35import mpv5.db.objects.Template;
 36import mpv5.globals.Headers;
 37import mpv5.globals.Messages;
 38import mpv5.logging.Log;
 39import mpv5.ui.dialogs.ControlApplet;
 40import mpv5.ui.dialogs.Popup;
 41import mpv5.ui.panels.DataPanel;
 42import mpv5.usermanagement.MPSecurityManager;
 43import mpv5.db.objects.User;
 44
 45import mpv5.globals.Constants;
 46import mpv5.globals.LocalSettings;
 47import mpv5.handler.FormFieldsHandler;
 48import mpv5.handler.VariablesHandler;
 49import mpv5.ui.dialogs.BigPopup;
 50import mpv5.ui.dialogs.DialogForFile;
 51import mpv5.ui.dialogs.Search2;
 52import mpv5.ui.panels.LOAPanel;
 53import mpv5.ui.panels.PreviewPanel;
 54import mpv5.utils.export.Export;
 55import mpv5.utils.export.ODTFile;
 56import mpv5.utils.export.PDFFile;
 57import mpv5.utils.files.FileDirectoryHandler;
 58import mpv5.utils.files.FileExecutor;
 59import mpv5.utils.files.FileMonitor;
 60import mpv5.utils.jobs.Job;
 61import mpv5.utils.models.MPComboBoxModelItem;
 62import mpv5.utils.models.MPComboboxModel;
 63import mpv5.utils.models.MPTableModel;
 64import mpv5.utils.ui.TextFieldUtils;
 65
 66/**
 67 *
 68 *
 69 */
 70public final class ControlPanel_Templates extends javax.swing.JPanel implements ControlApplet, DataPanel {
 71
 72    private static final long serialVersionUID = 1L;
 73    /**
 74     * This unique name identifies this control applet
 75     */
 76    public final String UNAME = "templates";
 77    private Template dataOwner;
 78    private File lastImportedFile;
 79    private long lastmodified;
 80
 81    public ControlPanel_Templates() {
 82        if (MPSecurityManager.checkAdminAccess()) {
 83            initComponents();
 84            type.getComboBox().setModel(new MPComboboxModel(MPComboBoxModelItem.toItems(TemplateHandler.getTypes())));
 85            refresh();
 86            groupname.setModel(new DefaultComboBoxModel(
 87                    MPComboBoxModelItem.toItems(new DatabaseSearch(Context.getGroup()).getValuesFor(Context.getGroup().getSubID()))));
 88            java.util.ResourceBundle bundle1 = mpv5.i18n.LanguageManager.getBundle();
 89            format.setText(Template.DEFAULT_FORMAT);
 90            format.getTextField().setEditable(true);
 91            format.getTextField().setToolTipText(bundle1.getString("ControlPanel_Templates.format.toolTipText_1")); // NOI18N
 92            setVisible(true);
 93        }
 94    }
 95
 96    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 97    private void initComponents() {
 98
 99        jPanel6 = new javax.swing.JPanel();
100        jButton6 = new javax.swing.JButton();
101        jButton5 = new javax.swing.JButton();
102        jButton10 = new javax.swing.JButton();
103        jButton1 = new javax.swing.JButton();
104        jSeparator1 = new javax.swing.JSeparator();
105        jSeparator2 = new javax.swing.JSeparator();
106        jButton4 = new javax.swing.JButton();
107        jButton7 = new javax.swing.JButton();
108        jButton9 = new javax.swing.JButton();
109        jButton3 = new javax.swing.JButton();
110        jButton2 = new javax.swing.JButton();
111        jPanel1 = new javax.swing.JPanel();
112        jPanel2 = new javax.swing.JPanel();
113        jPanel4 = new javax.swing.JPanel();
114        fullname = new mpv5.ui.beans.LabeledTextField();
115        jLabel3 = new javax.swing.JLabel();
116        groupname = new javax.swing.JComboBox();
117        jLabel6 = new javax.swing.JLabel();
118        jLabel1 = new javax.swing.JLabel();
119        jScrollPane2 = new javax.swing.JScrollPane();
120        descr = new javax.swing.JTextArea();
121        jScrollPane3 = new javax.swing.JScrollPane();
122        jList1 = new javax.swing.JList();
123        type = new mpv5.ui.beans.LabeledCombobox();
124        format = new mpv5.ui.beans.LabeledTextField();
125        jButton8 = new javax.swing.JButton();
126        printern = new mpv5.ui.beans.LabeledTextField();
127        jButton11 = new javax.swing.JButton();
128        updateService = new javax.swing.JCheckBox();
129        pathtofile = new mpv5.ui.beans.LabeledTextField();
130        jScrollPane4 = new javax.swing.JScrollPane();
131        templates = new javax.swing.JTable();
132
133        setBackground(new java.awt.Color(255, 255, 255));
134        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
135        setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_Templates.border.title"))); // NOI18N
136        setName("Form"); // NOI18N
137        setPreferredSize(new java.awt.Dimension(495, 183));
138        setLayout(new java.awt.BorderLayout());
139
140        jPanel6.setBackground(new java.awt.Color(255, 255, 255));
141        jPanel6.setName("jPanel6"); // NOI18N
142        jPanel6.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
143
144        jButton6.setText(bundle.getString("ControlPanel_Templates.jButton6.text")); // NOI18N
145        jButton6.setName("jButton6"); // NOI18N
146        jButton6.addActionListener(new java.awt.event.ActionListener() {
147            public void actionPerformed(java.awt.event.ActionEvent evt) {
148                jButton6ActionPerformed(evt);
149            }
150        });
151        jPanel6.add(jButton6);
152
153        jButton5.setText(bundle.getString("ControlPanel_Templates.jButton5.text")); // NOI18N
154        jButton5.setName("jButton5"); // NOI18N
155        jButton5.addActionListener(new java.awt.event.ActionListener() {
156            public void actionPerformed(java.awt.event.ActionEvent evt) {
157                jButton5ActionPerformed(evt);
158            }
159        });
160        jPanel6.add(jButton5);
161
162        jButton10.setText(bundle.getString("ControlPanel_Templates.jButton10.text")); // NOI18N
163        jButton10.setName("jButton10"); // NOI18N
164        jButton10.addActionListener(new java.awt.event.ActionListener() {
165            public void actionPerformed(java.awt.event.ActionEvent evt) {
166                jButton10ActionPerformed(evt);
167            }
168        });
169        jPanel6.add(jButton10);
170
171        jButton1.setText(bundle.getString("ControlPanel_Templates.jButton1.text")); // NOI18N
172        jButton1.setName("jButton1"); // NOI18N
173        jButton1.addActionListener(new java.awt.event.ActionListener() {
174            public void actionPerformed(java.awt.event.ActionEvent evt) {
175                jButton1ActionPerformed(evt);
176            }
177        });
178        jPanel6.add(jButton1);
179
180        jSeparator1.setName("jSeparator1"); // NOI18N
181        jPanel6.add(jSeparator1);
182
183        jSeparator2.setName("jSeparator2"); // NOI18N
184        jPanel6.add(jSeparator2);
185
186        jButton4.setText(bundle.getString("ControlPanel_Templates.jButton4.text")); // NOI18N
187        jButton4.setName("jButton4"); // NOI18N
188        jButton4.addActionListener(new java.awt.event.ActionListener() {
189            public void actionPerformed(java.awt.event.ActionEvent evt) {
190                jButton4ActionPerformed(evt);
191            }
192        });
193        jPanel6.add(jButton4);
194
195        jButton7.setText(bundle.getString("ControlPanel_Templates.jButton7.text")); // NOI18N
196        jButton7.setName(bundle.getString("ControlPanel_Templates.jButton7.name")); // NOI18N
197        jButton7.addActionListener(new java.awt.event.ActionListener() {
198            public void actionPerformed(java.awt.event.ActionEvent evt) {
199                jButton7ActionPerformed(evt);
200            }
201        });
202        jPanel6.add(jButton7);
203
204        jButton9.setText(bundle.getString("ControlPanel_Templates.jButton9.text")); // NOI18N
205        jButton9.setName("jButton9"); // NOI18N
206        jButton9.addActionListener(new java.awt.event.ActionListener() {
207            public void actionPerformed(java.awt.event.ActionEvent evt) {
208                jButton9ActionPerformed(evt);
209            }
210        });
211        jPanel6.add(jButton9);
212
213        jButton3.setText(bundle.getString("ControlPanel_Templates.jButton3.text")); // NOI18N
214        jButton3.setName("jButton3"); // NOI18N
215        jButton3.addActionListener(new java.awt.event.ActionListener() {
216            public void actionPerformed(java.awt.event.ActionEvent evt) {
217                jButton3ActionPerformed(evt);
218            }
219        });
220        jPanel6.add(jButton3);
221
222        jButton2.setText(bundle.getString("ControlPanel_Templates.jButton2.text")); // NOI18N
223        jButton2.setName("jButton2"); // NOI18N
224        jButton2.addActionListener(new java.awt.event.ActionListener() {
225            public void actionPerformed(java.awt.event.ActionEvent evt) {
226                jButton2ActionPerformed(evt);
227            }
228        });
229        jPanel6.add(jButton2);
230
231        add(jPanel6, java.awt.BorderLayout.PAGE_END);
232
233        jPanel1.setName("jPanel1"); // NOI18N
234
235        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_Templates.jPanel2.border.title"))); // NOI18N
236        jPanel2.setName("jPanel2"); // NOI18N
237        jPanel2.setPreferredSize(new java.awt.Dimension(425, 100));
238
239        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
240        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_Templates.jPanel4.border.title"))); // NOI18N
241        jPanel4.setName("jPanel4"); // NOI18N
242
243        fullname.set_Label(bundle.getString("ControlPanel_Templates.fullname._Label")); // NOI18N
244        fullname.setFont(fullname.getFont());
245        fullname.setName("fullname"); // NOI18N
246
247        jLabel3.setFont(jLabel3.getFont());
248        jLabel3.setText(bundle.getString("ControlPanel_Templates.jLabel3.text")); // NOI18N
249        jLabel3.setName("jLabel3"); // NOI18N
250
251        groupname.setName("groupname"); // NOI18N
252
253        jLabel6.setFont(jLabel6.getFont());
254        jLabel6.setText(bundle.getString("ControlPanel_Templates.jLabel6.text")); // NOI18N
255        jLabel6.setName("jLabel6"); // NOI18N
256
257        jLabel1.setFont(jLabel1.getFont());
258        jLabel1.setText(bundle.getString("ControlPanel_Templates.jLabel1.text")); // NOI18N
259        jLabel1.setName("jLabel1"); // NOI18N
260
261        jScrollPane2.setName("jScrollPane2"); // NOI18N
262
263        descr.setColumns(20);
264        descr.setRows(5);
265        descr.setName("descr"); // NOI18N
266        jScrollPane2.setViewportView(descr);
267
268        jScrollPane3.setName("jScrollPane3"); // NOI18N
269
270        jList1.setForeground(new java.awt.Color(0, 153, 0));
271        jList1.setName("jList1"); // NOI18N
272        jScrollPane3.setViewportView(jList1);
273
274        type.set_Label(bundle.getString("ControlPanel_Templates.type._Label")); // NOI18N
275        type.setName("type"); // NOI18N
276
277        format.set_Label(bundle.getString("ControlPanel_Templates.format._Label")); // NOI18N
278        format.set_Text("1,2,3,4,5,6,7,8,9"); // NOI18N
279        format.setName("format"); // NOI18N
280
281        jButton8.setText(bundle.getString("ControlPanel_Templates.jButton8.text")); // NOI18N
282        jButton8.setName("jButton8"); // NOI18N
283        jButton8.addActionListener(new java.awt.event.ActionListener() {
284            public void actionPerformed(java.awt.event.ActionEvent evt) {
285                jButton8ActionPerformed(evt);
286            }
287        });
288
289        printern.set_Label(bundle.getString("ControlPanel_Templates.printern._Label")); // NOI18N
290        printern.setFont(printern.getFont());
291        printern.setName("printern"); // NOI18N
292
293        jButton11.setText(bundle.getString("ControlPanel_Templates.jButton11.text")); // NOI18N
294        jButton11.setName(bundle.getString("ControlPanel_Templates.jButton11.name")); // NOI18N
295        jButton11.addActionListener(new java.awt.event.ActionListener() {
296            public void actionPerformed(java.awt.event.ActionEvent evt) {
297                jButton11ActionPerformed(evt);
298            }
299        });
300
301        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
302        jPanel4.setLayout(jPanel4Layout);
303        jPanel4Layout.setHorizontalGroup(
304            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
305            .addGroup(jPanel4Layout.createSequentialGroup()
306                .addContainerGap()
307                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
308                    .addComponent(type, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
309                    .addGroup(jPanel4Layout.createSequentialGroup()
310                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
311                            .addComponent(printern, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
312                            .addComponent(format, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
313                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
314                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
315                            .addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
316                            .addComponent(jButton11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
317                    .addComponent(fullname, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
318                    .addGroup(jPanel4Layout.createSequentialGroup()
319                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
320                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
321                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
322                            .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
323                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
324                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
325                            .addComponent(groupname, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
326                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
327                            .addComponent(jScrollPane2)))))
328        );
329        jPanel4Layout.setVerticalGroup(
330            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
331            .addGroup(jPanel4Layout.createSequentialGroup()
332                .addComponent(fullname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
333                .addGap(7, 7, 7)
334                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
335                    .addComponent(printern, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
336                    .addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
337                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
338                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
339                    .addComponent(jButton8)
340                    .addComponent(format, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
341                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
342                .addComponent(type, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
343                .addGap(3, 3, 3)
344                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
345                    .addComponent(jLabel6)
346                    .addComponent(groupname, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
347                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
348                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
349                    .addGroup(jPanel4Layout.createSequentialGroup()
350                        .addComponent(jLabel3)
351                        .addGap(0, 0, Short.MAX_VALUE))
352                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
353                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
354                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
355                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
356                    .addComponent(jLabel1))
357                .addContainerGap())
358        );
359
360        updateService.setText(bundle.getString("ControlPanel_Templates.updateService.text")); // NOI18N
361        updateService.setEnabled(false);
362        updateService.setName("updateService"); // NOI18N
363        updateService.addItemListener(new java.awt.event.ItemListener() {
364            public void itemStateChanged(java.awt.event.ItemEvent evt) {
365                updateServiceItemStateChanged(evt);
366            }
367        });
368
369        pathtofile.set_Label(bundle.getString("ControlPanel_Templates.pathtofile._Label")); // NOI18N
370        pathtofile.setEnabled(false);
371        pathtofile.setFont(pathtofile.getFont());
372        pathtofile.setName("pathtofile"); // NOI18N
373
374        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
375        jPanel2.setLayout(jPanel2Layout);
376        jPanel2Layout.setHorizontalGroup(
377            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
378            .addGroup(jPanel2Layout.createSequentialGroup()
379                .addGap(6, 6, 6)
380                .addComponent(updateService, javax.swing.GroupLayout.PREFERRED_SIZE, 337, javax.swing.GroupLayout.PREFERRED_SIZE)
381                .addContainerGap())
382            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
383            .addGroup(jPanel2Layout.createSequentialGroup()
384                .addContainerGap()
385                .addComponent(pathtofile, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
386        );
387        jPanel2Layout.setVerticalGroup(
388            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
389            .addGroup(jPanel2Layout.createSequentialGroup()
390                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
391                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
392                .addComponent(updateService)
393                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
394                .addComponent(pathtofile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
395                .addGap(12, 12, 12))
396        );
397
398        jScrollPane4.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_Templates.jScrollPane4.border.title"))); // NOI18N
399        jScrollPane4.setName("jScrollPane4"); // NOI18N
400
401        templates.setAutoCreateRowSorter(true);
402        templates.setModel(new javax.swing.table.DefaultTableModel(
403            new Object [][] {
404                {},
405                {},
406                {},
407                {}
408            },
409            new String [] {
410
411            }
412        ));
413        templates.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
414        templates.setDragEnabled(true);
415        templates.setFillsViewportHeight(true);
416        templates.setName("templates"); // NOI18N
417        templates.addMouseListener(new java.awt.event.MouseAdapter() {
418            public void mouseClicked(java.awt.event.MouseEvent evt) {
419                templatesMouseClicked(evt);
420            }
421        });
422        jScrollPane4.setViewportView(templates);
423
424        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
425        jPanel1.setLayout(jPanel1Layout);
426        jPanel1Layout.setHorizontalGroup(
427            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
428            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
429                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
430                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
431                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 417, javax.swing.GroupLayout.PREFERRED_SIZE))
432        );
433        jPanel1Layout.setVerticalGroup(
434            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
435            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 473, Short.MAX_VALUE)
436            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 473, Short.MAX_VALUE)
437        );
438
439        add(jPanel1, java.awt.BorderLayout.CENTER);
440    }// </editor-fold>//GEN-END:initComponents
441
442    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
443        reset();
444}//GEN-LAST:event_jButton3ActionPerformed
445
446    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
447
448        if (dataOwner != null) {
449            DatabaseObject dato = dataOwner;
450            dato.getPanelData(this);
451            if (dato.save()) {
452                actionAfterSave();
453                refresh();
454//                TemplateHandler.cacheTemplates();
455            } else {
456                showRequiredFields();
457            }
458        }
459}//GEN-LAST:event_jButton2ActionPerformed
460
461    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
462        if (dataOwner != null && dataOwner.isExisting()) {
463            if (Popup.Y_N_dialog(Messages.REALLY_DELETE)) {
464
465                TemplateHandler.clearCache();
466                DatabaseObject dato = dataOwner;
467                dato.getPanelData(this);
468                dato.delete();
469
470                try {
471                    Thread.sleep(333);
472                } catch (InterruptedException ex) {
473                }
474                refresh();
475            }
476        }
477    }//GEN-LAST:event_jButton4ActionPerformed
478
479    private void templatesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_templatesMouseClicked
480        try {
481            setDataOwner((DatabaseObject) templates.getValueAt(templates.convertRowIndexToModel(templates.getSelectedRow()), 0), true);
482            if (!pathtofile_.equals("")) {
483                updateService.setEnabled(true);
484            }
485        } catch (Exception e) {
486            Log.Debug(this, e.getMessage());
487        }
488    }//GEN-LAST:event_templatesMouseClicked
489
490    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
491
492        try {
493            DatabaseObject t = Search2.showSearchFor(Context.getItem());
494            if (t != null) {
495                List<String[]> vars = VariablesHandler.resolveVarsFor(t);
496                List<List<String>> varsl = new ArrayList<List<String>>();
497                for (int i = 0; i < vars.size(); i++) {
498                    String[] strings = vars.get(i);
499                    varsl.add(Arrays.asList(strings));
500                }
501                Popup.notice(varsl, Messages.VARIABLES + "\n\n" + t.toString());
502            }
503        } catch (Exception ex) {
504            Log.Debug(ex);
505        }
506}//GEN-LAST:event_jButton6ActionPerformed
507
508    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
509        test();
510}//GEN-LAST:event_jButton5ActionPerformed
511
512    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
513        DialogForFile di = new DialogForFile(DialogForFile.FILES_ONLY);
514        di.setFileFilter(DialogForFile.TEMPLATE_FILES);
515
516        if (di.chooseFile()) {
517            Template t = new Template();
518            File fi = di.getFile();
519            if (QueryHandler.instanceOf().clone(Context.getFiles(), this).insertFile(fi, t, new SaveString(fi.getName(), true))) {
520                Popup.notice(Messages.ASSIGN_TEMPLATE);
521                configureUpdateService(fi);
522            }
523        }
524}//GEN-LAST:event_jButton1ActionPerformed
525
526    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
527        BigPopup.showPopup(this, TemplateFormatEditor.instanceOf(format.getTextField()), "", true);
528    }//GEN-LAST:event_jButton8ActionPerformed
529
530    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
531
532        if (dataOwner != null && dataOwner.isExisting()) {
533            try {
534                mpv5.YabsViewProxy.instance().showFilesaveDialogFor(dataOwner.getFile());
535
536                DialogForFile d = mpv5.YabsViewProxy.instance().getFiledialog();
537                File nFile = d.saveFile(dataOwner.getFile());
538                if (nFile != null) {
539                    configureUpdateService(nFile);
540                    updateService.setSelected(true);
541                }
542            } catch (Exception e) {
543                Log.Debug(e);
544            }
545        }
546    }//GEN-LAST:event_jButton9ActionPerformed
547
548    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
549        if (dataOwner != null && dataOwner.isExisting()) {
550            Template tpl = (Template) templates.getValueAt(templates.convertRowIndexToModel(templates.getSelectedRow()), 0);
551            if (Popup.Y_N_dialog(Messages.REALLY_CHANGE.toString(), tpl.__getCname())) {
552                DialogForFile di = new DialogForFile(DialogForFile.FILES_ONLY);
553                di.setFileFilter(DialogForFile.TEMPLATE_FILES);
554                if (di.chooseFile()) {
555                    File fi = di.getFile();
556                    QueryHandler.instanceOf().clone(Context.getFiles(), this).updateFile(fi, tpl.__getFilename());
557                    tpl.setDescription(tpl.__getDescription() + "\n - Updated: " + new Date());
558                    tpl.save(true);
559                    TemplateHandler.clearCache();
560
561                    try {
562                        Thread.sleep(333);
563                    } catch (InterruptedException ex) {
564                    }
565                    refresh();
566                    lastImportedFile = fi;
567                    updateService.setEnabled(true);
568                    try {
569                        pathtofile.setText(fi.getCanonicalPath().toString());
570                    } catch (IOException ex) {
571                        Log.Debug(this, ex);
572                    }
573                    lastmodified = fi.lastModified();
574                }
575            }
576        }
577    }//GEN-LAST:event_jButton10ActionPerformed
578
579    private void updateServiceItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_updateServiceItemStateChanged
580
581        final DataPanel x = this;
582        final Template tpl = dataOwner;
583        FileMonitor.FileChangeListener filecl = new FileMonitor.FileChangeListener() {
584            public void fileChanged(String fileName) {
585                QueryHandler.instanceOf().clone(Context.getFiles(), x).updateFile(new File(fileName), tpl.__getFilename());
586                tpl.setDescription(tpl.__getDescription() + "\n - Updated: " + new Date());
587                tpl.save(true);
588                TemplateHandler.clearCache();
589
590                try {
591                    Thread.sleep(333);
592                } catch (InterruptedException ex) {
593                }
594                refresh();
595            }
596        };
597
598        String file = null;
599        if (lastImportedFile != null) {
600            try {
601                file = lastImportedFile.getCanonicalPath();
602            } catch (IOException ex) {
603                Log.Debug(ex);
604            }
605        } else if (!pathtofile.getText().equals("") && new File(pathtofile.getText()).canRead()) {
606            file = pathtofile.getText();
607        }
608        if (updateService.isSelected() && file != null) {
609            FileMonitor.getInstance().addFileChangeListener(filecl, file, 1000l);
610        } else {
611            FileMonitor.getInstance().removeFileChangeListener(filecl, file);
612        }
613        lastImportedFile = null;
614    }//GEN-LAST:event_updateServiceItemStateChanged
615
616    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
617
618        if (dataOwner != null && dataOwner.isExisting()) {
619            try {
620//                LOAPanel lp = new LOAPanel();
621//                File f = dataOwner.getFile();
622//                YabsViewProxy.instance().addOrShowTab(lp, dataOwner.__getCname());
623//                lp.loadODT(f);
624                updateService.setSelected(false);
625                updateService.setSelected(true);
626                if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
627                    Desktop.getDesktop().open(dataOwner.getFile());
628                } else if (LocalSettings.getBooleanProperty(LocalSettings.OFFICE_USE)) {
629                    FileExecutor.run(LocalSettings.getProperty(LocalSettings.OFFICE_HOME) + File.separator + dataOwner.getFile().getPath());
630                }
631            } catch (Exception e) {
632                Log.Debug(e);
633            }
634        }
635    }//GEN-LAST:event_jButton7ActionPerformed
636
637    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
638        PrintService[] services3 = PrintServiceLookup.lookupPrintServices(null, null);
639        List<String> l = new ArrayList<String>();
640        for (int i = 0; i < services3.length; i++) {
641            PrintService printService = services3[i];
642            l.add(printService.getName());
643        }
644        Popup.notice(l, Messages.PRINTER_NAMES);
645    }//GEN-LAST:event_jButton11ActionPerformed
646
647    public void setValues(PropertyStore values) {
648    }
649
650    public String getUname() {
651        return UNAME;
652    }
653
654    public void reset() {
655        if (dataOwner != null) {
656            DatabaseObject dato = dataOwner;
657
658            dato.getPanelData(this);
659            dato.reset();
660            setDataOwner(dato, true);
661        }
662    }
663    // Variables declaration - do not modify//GEN-BEGIN:variables
664    private javax.swing.JTextArea descr;
665    private mpv5.ui.beans.LabeledTextField format;
666    private mpv5.ui.beans.LabeledTextField fullname;
667    private javax.swing.JComboBox groupname;
668    private javax.swing.JButton jButton1;
669    private javax.swing.JButton jButton10;
670    private javax.swing.JButton jButton11;
671    private javax.swing.JButton jButton2;
672    private javax.swing.JButton jButton3;
673    private javax.swing.JButton jButton4;
674    private javax.swing.JButton jButton5;
675    private javax.swing.JButton jButton6;
676    private javax.swing.JButton jButton7;
677    private javax.swing.JButton jButton8;
678    private javax.swing.JButton jButton9;
679    private javax.swing.JLabel jLabel1;
680    private javax.swing.JLabel jLabel3;
681    private javax.swing.JLabel jLabel6;
682    private javax.swing.JList jList1;
683    private javax.swing.JPanel jPanel1;
684    private javax.swing.JPanel jPanel2;
685    private javax.swing.JPanel jPanel4;
686    private javax.swing.JPanel jPanel6;
687    private javax.swing.JScrollPane jScrollPane2;
688    private javax.swing.JScrollPane jScrollPane3;
689    private javax.swing.JScrollPane jScrollPane4;
690    private javax.swing.JSeparator jSeparator1;
691    private javax.swing.JSeparator jSeparator2;
692    private mpv5.ui.beans.LabeledTextField pathtofile;
693    private mpv5.ui.beans.LabeledTextField printern;
694    private javax.swing.JTable templates;
695    private mpv5.ui.beans.LabeledCombobox type;
696    private javax.swing.JCheckBox updateService;
697    // End of variables declaration//GEN-END:variables
698    public String description_ = "";
699    public String filename_ = "";
700    public String cname_;
701    public String format_;
702    public int intsize_;
703    public String mimetype_;
704    public int intaddedby_ = 4343;
705    public int ids_;
706    public int groupsids_;
707    public int compsids_;
708    public String printer_;
709    public java.util.Date dateadded_ = new java.util.Date();
710    public boolean isupdateenabled_ = false;
711    public String pathtofile_ = "";
712    public long lastmodified_;
713
714    public boolean collectData() {
715        if (groupname.getSelectedItem() != null) {
716            groupsids_ = Integer.valueOf(((MPComboBoxModelItem) groupname.getSelectedItem()).getId());
717        } else {
718            groupsids_ = 1;
719        }
720
721        description_ = descr.getText();
722        cname_ = fullname.getText();
723        mimetype_ = String.valueOf(type.getSelectedItem().getId());
724        format_ = format.getText();
725        printer_ = printern.getText();
726        pathtofile_ = pathtofile.getText();
727        lastmodified_ = lastmodified;
728        isupdateenabled_ = updateService.isSelected();
729
730        return true;
731    }
732
733    public void exposeData() {
734
735        try {
736            groupname.setSelectedIndex(MPComboBoxModelItem.getItemID(String.valueOf(groupsids_), groupname.getModel()));
737            fullname.setText(cname_);
738            descr.setText(description_);
739            try {
740                type.setSelectedItem(Integer.valueOf(mimetype_));
741            } catch (NumberFormatException numberFormatException) {
742            }
743            format.setText(format_);
744            printern.setText(printer_);
745
746            DefaultListModel m = new DefaultListModel();
747            ArrayList<DatabaseObject> li = DatabaseObject.getObjects(Context.getUser());
748
749            QueryCriteria c = new QueryCriteria("templatesids", dataOwner.__getIDS());
750            Object[][] data = QueryHandler.instanceOf().clone(Context.getTemplatesToUsers()).select("usersids", c);
751
752            List<Integer> l = new ArrayList<Integer>();
753            for (int i = 0; i < li.size(); i++) {
754                User databaseObject = (User) li.get(i);
755
756                for (int j = 0; j < data.length; j++) {
757                    int id = Integer.valueOf(data[j][0].toString());
758                    if (id == databaseObject.__getIDS().intValue()) {
759                        l.add(Integer.valueOf(i));
760                    }
761                }
762                m.addElement(databaseObject);
763            }
764
765            jList1.setModel(m);
766
767            int[] ix = new int[l.size()];
768            for (int i = 0; i < l.size(); i++) {
769                Integer integer = l.get(i);
770                ix[i] = integer.intValue();
771            }
772
773            jList1.setSelectedIndices(ix);
774            pathtofile.setText(dataOwner.getFile().getPath());
775            lastImportedFile = null;
776            lastmodified = lastmodified_;
777            updateService.setSelected(isupdateenabled_);
778
779        } catch (Exception e) {
780            Log.Debug(this, e);
781            if (Popup.Y_N_dialog("There was a problem loading the template, delete?")) {
782                dataOwner.delete();
783            }
784        }
785    }
786
787    public DatabaseObject getDataOwner() {
788        return dataOwner;
789    }
790
791    public void setDataOwner(DatabaseObject object, boolean p) {
792        dataOwner = (Template) object;
793        if (p) {
794            dataOwner.setPanelData(this);
795            this.exposeData();
796        }
797    }
798
799    public void refresh() {
800
801        ArrayList<DatabaseObject> temps;
802        try {
803            temps = DatabaseObject.getObjects(Context.getTemplate());
804            Object[][] data = new Object[temps.size()][3];
805
806            for (int i = 0; i < temps.size(); i++) {
807                Template t = (Template) temps.get(i);
808                data[i][0] = t;
809                data[i][1] = t.__getMimetype();
810                data[i][2] = Group.getObject(Context.getGroup(), t.__getGroupsids());
811            }
812
813            templates.setModel(new MPTableModel(data, Headers.TEMPLATES.getValue()));
814        } catch (NodataFoundException ex) {
815            Log.Debug(this, ex.getMessage());
816        }
817//        Context c1 = Context.getTemplatesToUsers();
818//        c1.addReference(Context.getGroup());
819//        c1.addReference(Context.getTemplate());
820//        jTable1.setModel(new MPTableModel(new Class[]{Integer.class, String.class, String.class, String.class, String.class, String.class, String.class},
821//                QueryHandler.instanceOf().clone(c1).
822//                select(Context.DETAILS_TEMPLATES, (String[]) null),
823//                Headers.TEMPLATES.getValue()));
824//
825//        TableFormat.stripFirstColumn(jTable1);
826//        TableFormat.format(jTable1, 1, 120);
827//        TableFormat.format(jTable1, 5, 80);
828//        TableFormat.format(jTable1, 6, 150);
829
830    }
831
832    public void paste(DatabaseObject... dbos) {
833        for (DatabaseObject dbo : dbos) {
834            if (dbo.getContext().equals(Context.getTemplate())) {
835                setDataOwner(dbo, true);
836            } else {
837                mpv5.YabsViewProxy.instance().addMessage(Messages.NOT_POSSIBLE.toString() + Messages.ACTION_PASTE, Color.RED);
838            }
839        }
840    }
841
842    public void showRequiredFields() {
843        TextFieldUtils.blinkerRed(fullname);
844    }
845
846    public void showSearchBar(boolean show) {
847        throw new UnsupportedOperationException("Not supported yet.");
848    }
849
850    public Component getAndRemoveActionPanel() {
851        this.remove(jPanel6);
852        validate();
853        return jPanel6;
854    }
855
856    @Override
857    public void actionAfterSave() {
858        Object[] selectedValues = jList1.getSelectedValues();
859        Integer groups;
860        if (groupname.getSelectedItem() != null) {
861            groups = Integer.valueOf(((MPComboBoxModelItem) groupname.getSelectedItem()).getId());
862        } else {
863            groups = 1;
864        }
865
866        Object[][] UtT = new Object[0][0];
867        QueryCriteria d = new QueryCriteria("templatesids", dataOwner.__getIDS());
868        try {
869            UtT = QueryHandler.instanceOf().clone(Context.getTemplatesToUsers()).select(d).getData();
870        } catch (NodataFoundException ex) {
871            Log.Debug(this, ex.getMessage());
872        }
873        for (int i = 0; i < selectedValues.length; i++) {
874            User object = (User) selectedValues[i];
875            boolean found = false;
876
877            for (int j = 0; j < UtT.length; j++) {
878                if (Integer.parseInt(UtT[j][2].toString()) == object.__getIDS()) {
879                    found = true;
880                    UtT[j][1] = "found";
881                    break;
882                }
883            }
884
885            if (!found) {
886                QueryData c = new QueryData();
887                c.add("usersids", object.__getIDS());
888                c.add("templatesids", dataOwner.__getIDS());
889                c.add("groupsids", groups.intValue());
890                c.add("cname", dataOwner.__getIDS() + "@" + object.__getIDS() + "@" + groups);
891                QueryHandler.instanceOf().clone(Context.getTemplatesToUsers()).insert(c, null);
892            }
893        }
894
895        for (int j = 0; j < UtT.length; j++) {
896            if (!UtT[j][1].equals("found")) {
897                QueryCriteria d2 = new QueryCriteria("cname", UtT[j][1].toString());
898                QueryHandler.instanceOf().clone(Context.getTemplatesToUsers()).delete(d2);
899            }
900        }
901
902        TemplateHandler.clearCache();
903    }
904
905    @Override
906    public void actionAfterCreate() {
907    }
908
909    private void test() {
910        DatabaseObject t;
911        if (dataOwner != null) {
912            t = Search2.showSearchFor(Context.getItem());
913            if (t == null) {
914                try {
915                    t = DatabaseObject.getObject(Context.getItem(), 1);
916                } catch (NodataFoundException ex) {
917                    t = new Item();
918                    Contact k = new Contact();
919                    k.avoidNulls();
920                    k.fillSampleData();
921                    t.avoidNulls();
922                    t.fillSampleData();
923                    ((Item) t).setContactsids(k.__getIDS());
924                }
925            }
926
927            try {
928                HashMap<String, Object> hm1 = new FormFieldsHandler(t).getFormattedFormFields(null);
929//                Log.Print(hm1.entrySet().toArray());
930                File f = dataOwner.getFile();
931                File f2 = FileDirectoryHandler.getTempFile("pdf");
932                Export ex = new Export(dataOwner);
933                ex.putAll(hm1);
934
935                ArrayList<String[]> l = new ArrayList<String[]>();
936
937                for (int i = 0; i < 20; i++) {
938                    l.add(SubItem.getRandomItem().toStringArray());
939                }
940
941                ex.put(TableHandler.KEY_TABLE + "1", l);
942
943                if (f.getName().endsWith("odt")) {
944                    ex.setTemplate(new ODTFile(f.getPath()));
945                } else {
946                    ex.setTemplate(new PDFFile(f.getPath()));
947                }
948
949                ex.setTargetFile(f2);
950
951                new Job(ex, new PreviewPanel()).execute();
952            } catch (Exception ex1) {
953                Log.Debug(ex1);
954                Popup.error(ex1);
955            }
956        }
957    }
958
959    public void actionBeforeCreate() {
960    }
961
962    public void actionBeforeSave() {
963    }
964
965    public void mail() {
966    }
967
968    public void print() {
969    }
970
971    private void configureUpdateService(File fi) {
972        lastImportedFile = fi;
973        updateService.setEnabled(true);
974        try {
975            pathtofile.setText(fi.getCanonicalPath().toString());
976        } catch (IOException ex) {
977            Log.Debug(this, ex);
978        }
979        lastmodified = fi.lastModified();
980    }
981}