aboutsummaryrefslogtreecommitdiffstats
path: root/netx/net/sourceforge/jnlp/controlpanel/UnsignedAppletsTrustingListPanel.java
blob: 2059d38a3ff4b5af548b2d05c152f9b724644c2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
/*   Copyright (C) 2013 Red Hat, Inc.

 This file is part of IcedTea.

 IcedTea is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation, version 2.

 IcedTea is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with IcedTea; see the file COPYING.  If not, write to
 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 02110-1301 USA.

 Linking this library statically or dynamically with other modules is
 making a combined work based on this library.  Thus, the terms and
 conditions of the GNU General Public License cover the whole
 combination.

 As a special exception, the copyright holders of this library give you
 permission to link this library with independent modules to produce an
 executable, regardless of the license terms of these independent
 modules, and to copy and distribute the resulting executable under
 terms of your choice, provided that you also meet, for each linked
 independent module, the terms and conditions of the license of that
 module.  An independent module is a module which is not derived from
 or based on this library.  If you modify this library, you may extend
 this exception to your version of the library, but you are not
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version.
 */
package net.sourceforge.jnlp.controlpanel;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.RowFilter;
import javax.swing.RowFilter.Entry;
import javax.swing.RowSorter.SortKey;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import net.sourceforge.jnlp.config.DeploymentConfiguration;
import net.sourceforge.jnlp.runtime.Translator;
import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityLevel;
import net.sourceforge.jnlp.security.appletextendedsecurity.ExecuteUnsignedApplet;
import net.sourceforge.jnlp.security.appletextendedsecurity.ExtendedAppletSecurityHelp;
import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletActionEntry;
import net.sourceforge.jnlp.security.appletextendedsecurity.UrlRegEx;
import net.sourceforge.jnlp.security.appletextendedsecurity.impl.UnsignedAppletActionStorageExtendedImpl;
import net.sourceforge.jnlp.util.logging.OutputController;
import net.sourceforge.jnlp.util.ScreenFinder;

public class UnsignedAppletsTrustingListPanel extends javax.swing.JPanel {

    private javax.swing.JButton helpButton;
    private javax.swing.JButton deleteButton;
    private javax.swing.JButton addRowButton;
    private javax.swing.JButton validateTableButton;
    private javax.swing.JButton testUrlButton;
    private javax.swing.JButton invertSelectionButton;
    private javax.swing.JButton moveRowUpButton;
    private javax.swing.JButton moveRowDownButton;
    private javax.swing.JCheckBox askBeforeActionCheckBox;
    private javax.swing.JCheckBox filterRegexesCheckBox;
    private javax.swing.JComboBox mainPolicyComboBox;
    private javax.swing.JComboBox deleteTypeComboBox;
    private javax.swing.JComboBox viewFilter;
    private javax.swing.JLabel globalBehaviourLabel;
    private javax.swing.JLabel securityLevelLabel;
    private javax.swing.JScrollPane userTableScrollPane;
    private javax.swing.JTabbedPane mainTabPanel;
    private javax.swing.JTable userTable;
    private javax.swing.JScrollPane globalTableScrollPane;
    private javax.swing.JTable globalTable;
    private final UnsignedAppletActionStorageExtendedImpl customBackEnd;
    private final UnsignedAppletActionStorageExtendedImpl globalBackEnd;
    private final UnsignedAppletActionTableModel customModel;
    private final UnsignedAppletActionTableModel globalModel;
    private final ByPermanencyFilter customFilter;
    private final ByPermanencyFilter globalFilter;
    private final DeploymentConfiguration conf;
    private javax.swing.JTable currentTable;
    private UnsignedAppletActionTableModel currentModel;
    private String lastDoc;
    private String lastCode;


    /*
     * for testing and playing
     */
    public static void main(String args[]) {
        final String defaultDir = System.getProperty("user.home") + "/Desktop/";
        final String defaultFileName1 = "terrorList1";
        final String defaultFileName2 = "terrorList2";
        final String defaultFile1 = defaultDir + defaultFileName1;
        final String defaultFile2 = defaultDir + defaultFileName2;
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    JFrame f = new JFrame();
                    f.setSize(700, 300);
                    f.setLayout(new BorderLayout());
                    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    DeploymentConfiguration cc = new DeploymentConfiguration();
                    cc.load();
                    File ff1 = new File(defaultFile1);
                    File ff2 = new File(defaultFile2);
                    f.add(new UnsignedAppletsTrustingListPanel(ff2, ff1, cc));
                    f.setVisible(true);
                } catch (Exception ex) {
                    OutputController.getLogger().log(OutputController.Level.ERROR_ALL, ex);
                }
            }
        });
    }

    public UnsignedAppletsTrustingListPanel(File globalSettings, File customSettings, DeploymentConfiguration conf) {
        customBackEnd = new UnsignedAppletActionStorageExtendedImpl(customSettings);
        globalBackEnd = new UnsignedAppletActionStorageExtendedImpl(globalSettings);
        customModel = new UnsignedAppletActionTableModel(customBackEnd);
        globalModel = new UnsignedAppletActionTableModel(globalBackEnd);
        customFilter = new ByPermanencyFilter(customModel);
        globalFilter = new ByPermanencyFilter(globalModel);
        initComponents();
        userTable.setRowSorter(customFilter);
        globalTable.setRowSorter(globalFilter);
        this.conf = conf;
        AppletSecurityLevel gs = AppletSecurityLevel.getDefault();
        String s = conf.getProperty(DeploymentConfiguration.KEY_SECURITY_LEVEL);
        if (s != null) {
            gs = AppletSecurityLevel.fromString(s);
        }
        mainPolicyComboBox.setSelectedItem(gs);
        userTable.getSelectionModel().addListSelectionListener(new SingleSelectionListenerImpl(userTable));
        globalTable.getSelectionModel().addListSelectionListener(new SingleSelectionListenerImpl(globalTable));

        userTable.addKeyListener(new DeleteAdapter(userTable));
        globalTable.addKeyListener(new DeleteAdapter(globalTable));
        currentTable = userTable;
        currentModel = customModel;
        setButtons((!currentModel.back.isReadOnly()));
    }

    public String appletItemsToCaption(List<UnsignedAppletActionEntry> ii, String caption) {
        StringBuilder sb = new StringBuilder();
        for (UnsignedAppletActionEntry i : ii) {
            sb.append(appletItemToCaption(i, caption)).append("\n");
        }
        return sb.toString();
    }

    public static String appletItemToCaption(UnsignedAppletActionEntry i, String caption) {
        return Translator.R("APPEXTSECguiPanelAppletInfoHederPart1", caption, i.getDocumentBase().getFilteredRegEx())
                + "\n  (" + Translator.R("APPEXTSECguiPanelAppletInfoHederPart2", i.getUnsignedAppletAction(), DateFormat.getInstance().format(i.getTimeStamp()))
                + "\n    " + Translator.R("APPEXTSECguiTableModelTableColumnDocumentBase") + ": " + i.getDocumentBase().getFilteredRegEx()
                + "\n    " + Translator.R("APPEXTSECguiTableModelTableColumnCodeBase") + ": " + i.getCodeBase().getFilteredRegEx()
                + "\n    " + Translator.R("APPEXTSECguiTableModelTableColumnArchives") + ": " + UnsignedAppletActionEntry.createArchivesString(i.getArchives());
    }

    public void removeSelectedFromTable(JTable table) {
        removeSelectedFromTable(table, askBeforeActionCheckBox.isSelected(), currentModel, this);
    }

    public static void removeSelectedFromTable(JTable table, boolean ask, UnsignedAppletActionTableModel data, Component forDialog) {
        int[] originalIndexes = table.getSelectedRows();
        List<Integer> newIndexes = new ArrayList<Integer>(originalIndexes.length);
        for (int i = 0; i < originalIndexes.length; i++) {
            //we need to remap values first
            int modelRow = table.convertRowIndexToModel(originalIndexes[i]);
            newIndexes.add(modelRow);
        }
        //now to sort so we can incrementaly dec safely
        Collections.sort(newIndexes);
        if (ask) {
            String s = Translator.R("APPEXTSECguiPanelConfirmDeletionOf", newIndexes.size()) + ": \n";
            UnsignedAppletActionEntry[] items = data.back.toArray();
            for (int i = 0; i < newIndexes.size(); i++) {
                Integer integer = newIndexes.get(i);
                s += appletItemToCaption(items[integer], "  ") + "\n";
            }
            int a = JOptionPane.showConfirmDialog(forDialog, s);
            if (a != JOptionPane.OK_OPTION) {
                return;
            }
        }
        int sub = 0;
        for (int i = 0; i < newIndexes.size(); i++) {
            Integer integer = newIndexes.get(i);
            data.removeRow(integer.intValue() + sub);
            sub--;
        }
    }

    public void removeAllItemsFromTable(JTable table, UnsignedAppletActionTableModel model) {
        table.clearSelection();

        if (askBeforeActionCheckBox.isSelected()) {
            UnsignedAppletActionEntry[] items = model.back.toArray();
            String s = Translator.R("APPEXTSECguiPanelConfirmDeletionOf", items.length) + ": \n";
            for (int i = 0; i < items.length; i++) {
                s += appletItemToCaption(items[i], "  ") + "\n";
            }
            int a = JOptionPane.showConfirmDialog(this, s);
            if (a != JOptionPane.OK_OPTION) {
                return;
            }
        }
        model.clear();
    }

    private void initComponents() {

        userTableScrollPane = new javax.swing.JScrollPane();
        globalTableScrollPane = new javax.swing.JScrollPane();
        userTable = createTbale(customModel);
        globalTable = createTbale(globalModel);
        helpButton = new javax.swing.JButton();
        mainPolicyComboBox = new JComboBox(new AppletSecurityLevel[]{
                    AppletSecurityLevel.DENY_ALL,
                    AppletSecurityLevel.DENY_UNSIGNED,
                    AppletSecurityLevel.ASK_UNSIGNED,
                    AppletSecurityLevel.ALLOW_UNSIGNED
                });
        mainPolicyComboBox.setSelectedItem(AppletSecurityLevel.getDefault());
        securityLevelLabel = new javax.swing.JLabel();
        globalBehaviourLabel = new javax.swing.JLabel();
        deleteTypeComboBox = new javax.swing.JComboBox();
        viewFilter = new javax.swing.JComboBox();
        deleteButton = new javax.swing.JButton();
        testUrlButton = new javax.swing.JButton();
        addRowButton = new javax.swing.JButton();
        validateTableButton = new javax.swing.JButton();
        askBeforeActionCheckBox = new javax.swing.JCheckBox();
        filterRegexesCheckBox = new javax.swing.JCheckBox();
        invertSelectionButton = new javax.swing.JButton();
        moveRowUpButton = new javax.swing.JButton();
        moveRowDownButton = new javax.swing.JButton();
        mainTabPanel = new javax.swing.JTabbedPane();

        userTableScrollPane.setViewportView(userTable);

        globalTableScrollPane.setViewportView(globalTable);

        helpButton.setText(Translator.R("APPEXTSECguiPanelHelpButton"));
        helpButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpButtonActionPerformed(evt);
            }
        });

        mainPolicyComboBox.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mainPolicyComboBoxActionPerformed(evt);
            }
        });

        viewFilter.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                userTable.getRowSorter().setSortKeys(null);
                userTable.getRowSorter().setSortKeys(null);
                int i = viewFilter.getSelectedIndex();
                switch (i) {
                    case 0:
                        customFilter.setRowFilter(ByPermanencyFilter.showPermanents);
                        globalFilter.setRowFilter(ByPermanencyFilter.showPermanents);
                        break;
                    case 1:
                        customFilter.setRowFilter(ByPermanencyFilter.showTemporarilyDecisions);
                        globalFilter.setRowFilter(ByPermanencyFilter.showTemporarilyDecisions);
                        break;
                    case 2:
                        customFilter.setRowFilter(ByPermanencyFilter.showAll);
                        globalFilter.setRowFilter(ByPermanencyFilter.showAll);
                        break;
                    case 3:
                        customFilter.setRowFilter(ByPermanencyFilter.showPermanentA);
                        globalFilter.setRowFilter(ByPermanencyFilter.showPermanentA);
                        break;
                    case 4:
                        customFilter.setRowFilter(ByPermanencyFilter.showPermanentN);
                        globalFilter.setRowFilter(ByPermanencyFilter.showPermanentN);
                        break;
                    case 5:
                        customFilter.setRowFilter(ByPermanencyFilter.showHasChosenYes);
                        globalFilter.setRowFilter(ByPermanencyFilter.showHasChosenYes);
                        break;
                    case 6:
                        customFilter.setRowFilter(ByPermanencyFilter.showHasChosenNo);
                        globalFilter.setRowFilter(ByPermanencyFilter.showHasChosenNo);
                        break;
                }

            }
        });


        securityLevelLabel.setText(Translator.R("APPEXTSECguiPanelSecurityLevel"));

        globalBehaviourLabel.setText(Translator.R("APPEXTSECguiPanelGlobalBehaviourCaption"));

        deleteTypeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[]{
                    Translator.R("APPEXTSECguiPanelDeleteMenuSelected"),
                    Translator.R("APPEXTSECguiPanelDeleteMenuAllA"),
                    Translator.R("APPEXTSECguiPanelDeleteMenuAllN"),
                    Translator.R("APPEXTSECguiPanelDeleteMenuAlly"),
                    Translator.R("APPEXTSECguiPanelDeleteMenuAlln"),
                    Translator.R("APPEXTSECguiPanelDeleteMenuAllAll")}));

        viewFilter.setModel(new javax.swing.DefaultComboBoxModel(new String[]{
                    Translator.R("APPEXTSECguiPanelShowOnlyPermanent"),
                    Translator.R("APPEXTSECguiPanelShowOnlyTemporal"),
                    Translator.R("APPEXTSECguiPanelShowAll"),
                    Translator.R("APPEXTSECguiPanelShowOnlyPermanentA"),
                    Translator.R("APPEXTSECguiPanelShowOnlyPermanentN"),
                    Translator.R("APPEXTSECguiPanelShowOnlyTemporalY"),
                    Translator.R("APPEXTSECguiPanelShowOnlyTemporalN")}));

        deleteButton.setText(Translator.R("APPEXTSECguiPanelDeleteButton"));
        deleteButton.setToolTipText(Translator.R("APPEXTSECguiPanelDeleteButtonToolTip"));
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });

        testUrlButton.setText(Translator.R("APPEXTSECguiPanelTestUrlButton"));
        testUrlButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                testUrlButtonActionPerformed(evt);
            }
        });

        addRowButton.setText(Translator.R("APPEXTSECguiPanelAddRowButton"));
        addRowButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addRowButtonActionPerformed(evt);
            }
        });

        validateTableButton.setText(Translator.R("APPEXTSECguiPanelValidateTableButton"));
        validateTableButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                validateTableButtonActionPerformed(evt);
            }
        });

        askBeforeActionCheckBox.setSelected(true);
        askBeforeActionCheckBox.setText(Translator.R("APPEXTSECguiPanelAskeforeActionBox"));

        filterRegexesCheckBox.setText(Translator.R("APPEXTSECguiPanelShowRegExesBox"));
        filterRegexesCheckBox.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                filterRegexesCheckBoxActionPerformed(evt);
            }
        });

        invertSelectionButton.setText(Translator.R("APPEXTSECguiPanelInverSelection"));
        invertSelectionButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                invertSelectionButtonActionPerformed(evt);
            }
        });

        moveRowUpButton.setText(Translator.R("APPEXTSECguiPanelMoveRowUp"));
        moveRowUpButton.setEnabled(false);
        moveRowUpButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                moveRowUpButtonActionPerformed(evt);
            }
        });

        moveRowDownButton.setText(Translator.R("APPEXTSECguiPanelMoveRowDown"));
        moveRowDownButton.setEnabled(false);
        moveRowDownButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                moveRowDownButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(mainTabPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 583, Short.MAX_VALUE)
                .addComponent(globalBehaviourLabel, javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                .addComponent(securityLevelLabel).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(mainPolicyComboBox, 0, 474, Short.MAX_VALUE))
                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                .addComponent(addRowButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(validateTableButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(testUrlButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 94, Short.MAX_VALUE)
                .addComponent(moveRowDownButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(moveRowUpButton))
                .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                .addComponent(deleteButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(deleteTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(invertSelectionButton))
                .addGroup(layout.createSequentialGroup()
                .addComponent(askBeforeActionCheckBox).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(filterRegexesCheckBox).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 93, Short.MAX_VALUE)
                .addComponent(viewFilter))).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(helpButton, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))).addContainerGap()));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                .addComponent(globalBehaviourLabel).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(securityLevelLabel)
                .addComponent(mainPolicyComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(deleteButton)
                .addComponent(deleteTypeComboBox)
                .addComponent(invertSelectionButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(askBeforeActionCheckBox)
                .addComponent(filterRegexesCheckBox)
                .addComponent(viewFilter)))
                .addComponent(helpButton, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(mainTabPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(addRowButton)
                .addComponent(validateTableButton)
                .addComponent(testUrlButton)
                .addComponent(moveRowUpButton)
                .addComponent(moveRowDownButton)).addContainerGap()));

        JPanel userPanel = new JPanel(new BorderLayout());
        JPanel globalPanel = new JPanel(new BorderLayout());
        userPanel.add(userTableScrollPane);
        globalPanel.add(globalTableScrollPane);
        mainTabPanel.add(userPanel);
        mainTabPanel.add(globalPanel);
        mainTabPanel.setTitleAt(0, Translator.R("APPEXTSECguiPanelCustomDefs"));
        mainTabPanel.setTitleAt(1, Translator.R("APPEXTSECguiPanelGlobalDefs"));
        mainTabPanel.setToolTipTextAt(0, DeploymentConfiguration.getAppletTrustUserSettingsPath().getAbsolutePath());
        mainTabPanel.setToolTipTextAt(1, DeploymentConfiguration.getAppletTrustGlobalSettingsPath().getAbsolutePath());
        mainTabPanel.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                switch (mainTabPanel.getSelectedIndex()) {
                    case 0:
                        currentModel = customModel;
                        currentTable = userTable;
                        break;
                    case 1:
                        currentModel = globalModel;
                        currentTable = globalTable;
                        break;
                }
                setButtons((!currentModel.back.isReadOnly()));
            }
        });
    }

    private void mainPolicyComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
        try {
            conf.setProperty(DeploymentConfiguration.KEY_SECURITY_LEVEL, ((AppletSecurityLevel) mainPolicyComboBox.getSelectedItem()).toChars());
            conf.save();
        } catch (Exception ex) {
            OutputController.getLogger().log(OutputController.Level.ERROR_ALL, ex);
            JOptionPane.showMessageDialog(this, ex);
        }
    }

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {

        if (deleteTypeComboBox.getSelectedIndex() == 0) {
            removeSelectedFromTable(currentTable);
        }
        if (deleteTypeComboBox.getSelectedIndex() == 1) {
            removeByBehaviour(ExecuteUnsignedApplet.ALWAYS);
        }
        if (deleteTypeComboBox.getSelectedIndex() == 2) {
            removeByBehaviour(ExecuteUnsignedApplet.NEVER);
        }
        if (deleteTypeComboBox.getSelectedIndex() == 3) {
            removeByBehaviour(ExecuteUnsignedApplet.YES);
        }
        if (deleteTypeComboBox.getSelectedIndex() == 4) {
            removeByBehaviour(ExecuteUnsignedApplet.NO);
        }
        if (deleteTypeComboBox.getSelectedIndex() == 5) {
            removeAllItemsFromTable(currentTable, customModel);
        }
    }

    private void testUrlButtonActionPerformed(java.awt.event.ActionEvent evt) {

        String s1 = JOptionPane.showInputDialog(Translator.R("APPEXTSECguiPanelDocTest"), lastDoc);
        String s2 = JOptionPane.showInputDialog(Translator.R("APPEXTSECguiPanelCodeTest"), lastCode);
        lastDoc = s1;
        lastCode = s2;
        try {
            List<UnsignedAppletActionEntry> i = currentModel.back.getMatchingItems(s1, s2, null);
            if (i == null || i.isEmpty()) {
                JOptionPane.showMessageDialog(this, Translator.R("APPEXTSECguiPanelNoMatch"));
            } else {
                JOptionPane.showMessageDialog(this, Translator.R("APPEXTSECguiPanelMatchingNote") + "\n" + appletItemsToCaption(i, Translator.R("APPEXTSECguiPanelMatched") + ": "));
            }
        } catch (Exception ex) {
            OutputController.getLogger().log(OutputController.Level.ERROR_ALL, ex);
            JOptionPane.showMessageDialog(this, Translator.R("APPEXTSECguiPanelMatchingError", ex));
        }

    }

    private void addRowButtonActionPerformed(java.awt.event.ActionEvent evt) {

        currentModel.addRow();
    }

    private void validateTableButtonActionPerformed(java.awt.event.ActionEvent evt) {

        File f = null;
        try {
            f = File.createTempFile("appletTable", "validation");
        } catch (Exception ex) {
            OutputController.getLogger().log(OutputController.Level.ERROR_ALL, ex);
            JOptionPane.showMessageDialog(this, Translator.R("APPEXTSECguiPanelCanNOtValidate", ex.toString()));
            return;
        }
        try {
            currentModel.back.writeContentsLocked();
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "UTF-8"));
            currentModel.back.writeContent(bw);
            bw.flush();
            bw.close();
            UnsignedAppletActionStorageExtendedImpl copy = new UnsignedAppletActionStorageExtendedImpl(f);
            UnsignedAppletActionEntry[] items = copy.toArray();
            for (int i = 0; i < items.length; i++) {
                UnsignedAppletActionEntry unsignedAppletActionEntry = items[i];
                if (unsignedAppletActionEntry.getDocumentBase() != null && !unsignedAppletActionEntry.getDocumentBase().getRegEx().trim().isEmpty()) {
                    Pattern p = Pattern.compile(unsignedAppletActionEntry.getDocumentBase().getRegEx());
                    p.matcher("someInput").find();
                } else {
                    throw new RuntimeException(Translator.R("APPEXTSECguiPanelEmptyDoc"));
                }
                if (unsignedAppletActionEntry.getCodeBase() != null && !unsignedAppletActionEntry.getCodeBase().getRegEx().trim().isEmpty()) {
                    Pattern p = Pattern.compile(unsignedAppletActionEntry.getCodeBase().getRegEx());
                    p.matcher("someInput").find();
                } else {
                    throw new RuntimeException(Translator.R("APPEXTSECguiPanelEmptyCode"));
                }
                UnsignedAppletActionEntry.createArchivesString(UnsignedAppletActionEntry.createArchivesList(UnsignedAppletActionEntry.createArchivesString(unsignedAppletActionEntry.getArchives())));

            }
            JOptionPane.showMessageDialog(this, Translator.R("APPEXTSECguiPanelTableValid"));
        } catch (Exception ex) {
            OutputController.getLogger().log(OutputController.Level.ERROR_ALL, ex);
            JOptionPane.showMessageDialog(this, Translator.R("APPEXTSECguiPanelTableInvalid ", ex.toString()));
        } finally {
            f.delete();
        }

    }

    private void filterRegexesCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {

        reloadTable();
    }

    private void invertSelectionButtonActionPerformed(java.awt.event.ActionEvent evt) {
        int[] selectedIndexs = currentTable.getSelectedRows();
        currentTable.selectAll();

        for (int i = 0; i < currentTable.getRowCount(); i++) {
            for (int selectedIndex : selectedIndexs) {
                if (selectedIndex == i) {
                    currentTable.removeRowSelectionInterval(i, i);
                    break;
                }
            }
        }
    }

    private void moveRowUpButtonActionPerformed(java.awt.event.ActionEvent evt) {
        int orig = currentTable.getSelectedRow();
        if (orig < 0 || orig >= currentTable.getRowCount()) {
            return;
        }
        int nw = 0;
        while (true) {
            int i = currentTable.convertRowIndexToModel(orig);
            int nwx = currentModel.moveUp(i);
            reloadTable();
            nw = currentTable.convertRowIndexToView(nwx);
            if (i == nwx) {
                break;
            }
            if (nw != orig) {
                break;
            }
        }
        //ItwLogger.getLogger().log(OutputController.Level.ERROR_ALL, orig+" "+i+" "+nwx+" "+nw+" ");
        if (nw != orig) {
            if (orig >= 1) {
                currentTable.getSelectionModel().setSelectionInterval(orig - 1, orig - 1);
            }
        } else {
            currentTable.getSelectionModel().setSelectionInterval(orig, orig);
        }
    }

    private void moveRowDownButtonActionPerformed(java.awt.event.ActionEvent evt) {
        int orig = currentTable.getSelectedRow();
        if (orig < 0 || orig >= currentTable.getRowCount()) {
            return;
        }
        int nw = 0;
        while (true) {
            int i = currentTable.convertRowIndexToModel(orig);
            int nwx = currentModel.moveDown(i);
            reloadTable();
            nw = currentTable.convertRowIndexToView(nwx);
            if (i == nwx) {
                break;
            }
            if (nw != orig) {
                break;
            }
        }
        // OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, orig+" "+i+" "+nwx+" "+nw+" ");
        if (nw != orig) {
            if (orig < currentModel.getRowCount()) {
                currentTable.getSelectionModel().setSelectionInterval(orig + 1, orig + 1);
            }
        } else {
            currentTable.getSelectionModel().setSelectionInterval(orig, orig);
        }
    }

    private void helpButtonActionPerformed(java.awt.event.ActionEvent evt) {
        JDialog d = new ExtendedAppletSecurityHelp(null, false);
        ScreenFinder.centerWindowsToCurrentScreen(d);
        d.setVisible(true);
    }

    private void setButtons(boolean b) {
        deleteButton.setEnabled(b);
        addRowButton.setEnabled(b);
        invertSelectionButton.setEnabled(b);
        moveRowUpButton.setEnabled(b);
        moveRowDownButton.setEnabled(b);
    }

    private JTable createTbale(final TableModel model) {
        JTable jt = new JTable() {
            @Override
            public TableCellEditor getCellEditor(int row, int column) {
                int columnx = convertColumnIndexToModel(column);
                if (columnx == 0) {
                    return new DefaultCellEditor(new JComboBox(new ExecuteUnsignedApplet[]{ExecuteUnsignedApplet.ALWAYS, ExecuteUnsignedApplet.NEVER, ExecuteUnsignedApplet.YES, ExecuteUnsignedApplet.NO}));
                }
                if (columnx == 2) {
                    column = convertColumnIndexToModel(column);
                    row = convertRowIndexToModel(row);
                    return new DefaultCellEditor(new MyTextField((UrlRegEx) (model.getValueAt(row, column))));
                }
                if (columnx == 3) {
                    column = convertColumnIndexToModel(column);
                    row = convertRowIndexToModel(row);
                    return new DefaultCellEditor(new MyTextField((UrlRegEx) (model.getValueAt(row, column))));
                }
                return super.getCellEditor(row, column);
            }

            @Override
            public TableCellRenderer getCellRenderer(int row, int column) {
                int columnx = convertColumnIndexToModel(column);
                if (columnx == 1) {
                    column = convertColumnIndexToModel(column);
                    row = convertRowIndexToModel(row);
                    return new UrlRegexCellRenderer.MyDateCellRenderer((Date) (model.getValueAt(row, column)));
                }
                if (columnx == 2) {
                    if (!filterRegexesCheckBox.isSelected()) {
                        column = convertColumnIndexToModel(column);
                        row = convertRowIndexToModel(row);
                        return new UrlRegexCellRenderer((UrlRegEx) (model.getValueAt(row, column)));
                    }
                }
                if (columnx == 3) {
                    if (!filterRegexesCheckBox.isSelected()) {
                        column = convertColumnIndexToModel(column);
                        row = convertRowIndexToModel(row);
                        return new UrlRegexCellRenderer((UrlRegEx) (model.getValueAt(row, column)));
                    }
                }
                return super.getCellRenderer(row, column);
            }
        };
        jt.setRowHeight(jt.getRowHeight() + jt.getRowHeight() / 2);
        jt.setModel(model);
        return jt;

    }

    private void reloadTable() {
        List<? extends SortKey> l = currentTable.getRowSorter().getSortKeys();
        currentTable.setModel(new DefaultTableModel());
        currentTable.setModel(currentModel);
        {
            currentTable.getRowSorter().setSortKeys(l);
            
        }

    }

    private void removeByBehaviour(ExecuteUnsignedApplet unsignedAppletAction) {
        UnsignedAppletActionEntry[] items = currentModel.back.toArray();
        if (askBeforeActionCheckBox.isSelected()) {
            List<UnsignedAppletActionEntry> toBeDeleted = new ArrayList<UnsignedAppletActionEntry>();
            for (int i = 0; i < items.length; i++) {
                UnsignedAppletActionEntry unsignedAppletActionEntry = items[i];
                if (unsignedAppletActionEntry.getUnsignedAppletAction() == unsignedAppletAction) {
                    toBeDeleted.add(unsignedAppletActionEntry);
                }

            }
            String s = Translator.R("APPEXTSECguiPanelConfirmDeletionOf", toBeDeleted.size()) + ": \n";
            for (int i = 0; i < toBeDeleted.size(); i++) {
                s += appletItemToCaption(toBeDeleted.get(i), "  ") + "\n";
            }
            int a = JOptionPane.showConfirmDialog(this, s);
            if (a != JOptionPane.OK_OPTION) {
                return;
            }
        }
        currentModel.removeByBehaviour(unsignedAppletAction);
    }

    public static final class MyTextField extends JTextField {

        private final UrlRegEx keeper;

        private MyTextField(UrlRegEx urlRegEx) {
            if (urlRegEx == null) {
                keeper = new UrlRegEx("");
            } else {
                this.keeper = urlRegEx;
            }
            setText(keeper.getFilteredRegEx());
        }

        @Override
        public void setText(String t) {
            super.setText(keeper.getRegEx());
        }
    }

    public static final class UrlRegexCellRenderer extends DefaultTableCellRenderer {

        private final UrlRegEx keeper;

        private UrlRegexCellRenderer(UrlRegEx urlRegEx) {
            if (urlRegEx == null) {
                keeper = new UrlRegEx("");
            } else {
                this.keeper = urlRegEx;
            }
            setText(keeper.getFilteredRegEx());
        }

        @Override
        public void setText(String t) {
            if (keeper == null) {
                super.setText("");
            } else {
                super.setText(keeper.getFilteredRegEx());
            }
        }

        public static final class MyDateCellRenderer extends DefaultTableCellRenderer {

            private final Date keeper;

            private MyDateCellRenderer(Date d) {
                this.keeper = d;
                setText(DateFormat.getInstance().format(d));
            }

            @Override
            public void setText(String t) {
                if (keeper == null) {
                    super.setText("");
                } else {
                    super.setText(DateFormat.getInstance().format(keeper));
                }
            }
        }
    }

    private final class SingleSelectionListenerImpl implements ListSelectionListener {

        private final JTable table;

        public SingleSelectionListenerImpl(JTable table) {
            this.table = table;
        }

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (table.getSelectedRows().length == 1 && !currentModel.back.isReadOnly()) {
                moveRowUpButton.setEnabled(true);
                moveRowDownButton.setEnabled(true);
            } else {
                moveRowUpButton.setEnabled(false);
                moveRowDownButton.setEnabled(false);
            }
        }
    }

    private final class DeleteAdapter implements KeyListener {

        private final JTable table;

        public DeleteAdapter(JTable table) {
            this.table = table;
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DELETE && !currentModel.back.isReadOnly()) {
                removeSelectedFromTable(table, askBeforeActionCheckBox.isSelected(), (UnsignedAppletActionTableModel) table.getModel(), UnsignedAppletsTrustingListPanel.this);
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }
    }

    private abstract static  class MyCommonSorter extends RowFilter<UnsignedAppletActionTableModel, Integer>  {
        
        
    }
    private static final class ByPermanencyFilter extends TableRowSorter<UnsignedAppletActionTableModel> {

        private static final class ShowAll extends MyCommonSorter {

            @Override
            public boolean include(Entry<? extends UnsignedAppletActionTableModel, ? extends Integer> entry) {
                return true;
            }
        }

        private static final class ShowPermanents extends MyCommonSorter {

            @Override
            public boolean include(Entry<? extends UnsignedAppletActionTableModel, ? extends Integer> entry) {
                ExecuteUnsignedApplet o = (ExecuteUnsignedApplet) entry.getModel().getValueAt(entry.getIdentifier(), 0);
                return (o.equals(ExecuteUnsignedApplet.ALWAYS) || o.equals(ExecuteUnsignedApplet.NEVER));
            }
        }

        private static final class ShowPermanentA extends MyCommonSorter {
            @Override
            public boolean include(Entry<? extends UnsignedAppletActionTableModel, ? extends Integer> entry) {
                ExecuteUnsignedApplet o = (ExecuteUnsignedApplet) entry.getModel().getValueAt(entry.getIdentifier(), 0);
                return (o.equals(ExecuteUnsignedApplet.ALWAYS));
            }
        }

        private static final class ShowPermanentN  extends MyCommonSorter {

            @Override
            public boolean include(Entry<? extends UnsignedAppletActionTableModel, ? extends Integer> entry) {
                ExecuteUnsignedApplet o = (ExecuteUnsignedApplet) entry.getModel().getValueAt(entry.getIdentifier(), 0);
                return (o.equals(ExecuteUnsignedApplet.NEVER));
            }
        }

        private static final class ShowTemporarilyDecisions  extends MyCommonSorter {

            @Override
            public boolean include(Entry<? extends UnsignedAppletActionTableModel, ? extends Integer> entry) {
                ExecuteUnsignedApplet o = (ExecuteUnsignedApplet) entry.getModel().getValueAt(entry.getIdentifier(), 0);
                return (o.equals(ExecuteUnsignedApplet.YES) || o.equals(ExecuteUnsignedApplet.NO));
            }
        }

        private static final class ShowHasChosenYes  extends MyCommonSorter {

            @Override
            public boolean include(Entry<? extends UnsignedAppletActionTableModel, ? extends Integer> entry) {
                ExecuteUnsignedApplet o = (ExecuteUnsignedApplet) entry.getModel().getValueAt(entry.getIdentifier(), 0);
                return (o.equals(ExecuteUnsignedApplet.YES));
            }
           
            
        }

        private static final class ShowHasChosenNo  extends MyCommonSorter {

            @Override
            public boolean include(Entry<? extends UnsignedAppletActionTableModel, ? extends Integer> entry) {
                ExecuteUnsignedApplet o = (ExecuteUnsignedApplet) entry.getModel().getValueAt(entry.getIdentifier(), 0);
                return (o.equals(ExecuteUnsignedApplet.NO));
            }
            
        }
        public static final ShowAll showAll = new ShowAll();
        public static final ShowPermanents showPermanents = new ShowPermanents();
        public static final ShowPermanentA showPermanentA = new ShowPermanentA();
        public static final ShowPermanentN showPermanentN = new ShowPermanentN();
        public static final ShowTemporarilyDecisions showTemporarilyDecisions = new ShowTemporarilyDecisions();
        public static final ShowHasChosenYes showHasChosenYes = new ShowHasChosenYes();
        public static final ShowHasChosenNo showHasChosenNo = new ShowHasChosenNo();

        public ByPermanencyFilter(UnsignedAppletActionTableModel model) {
            super(model);
            setRowFilter(showPermanents);
        }
    }
}