jdk/src/share/classes/sun/security/tools/policytool/PolicyTool.java
changeset 22059 3ad91a1b7495
parent 21365 2a7be11ae905
child 23333 b0af2c7c8c91
equal deleted inserted replaced
22058:db159b144c98 22059:3ad91a1b7495
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
  1054     public static final int MW_EDIT_BUTTON              = 1;
  1054     public static final int MW_EDIT_BUTTON              = 1;
  1055     public static final int MW_REMOVE_BUTTON            = 2;
  1055     public static final int MW_REMOVE_BUTTON            = 2;
  1056     public static final int MW_POLICY_LIST              = 3; // follows MW_PANEL
  1056     public static final int MW_POLICY_LIST              = 3; // follows MW_PANEL
  1057 
  1057 
  1058     /* The preferred height of JTextField should match JComboBox. */
  1058     /* The preferred height of JTextField should match JComboBox. */
  1059     static final int TEXTFIELD_HEIGHT = new JComboBox().getPreferredSize().height;
  1059     static final int TEXTFIELD_HEIGHT = new JComboBox<>().getPreferredSize().height;
  1060 
  1060 
  1061     private PolicyTool tool;
  1061     private PolicyTool tool;
  1062 
  1062 
  1063     /**
  1063     /**
  1064      * Constructor
  1064      * Constructor
  1167         try {
  1167         try {
  1168             // open the policy file
  1168             // open the policy file
  1169             tool.openPolicy(policyFile);
  1169             tool.openPolicy(policyFile);
  1170 
  1170 
  1171             // display the policy entries via the policy list textarea
  1171             // display the policy entries via the policy list textarea
  1172             DefaultListModel listModel = new DefaultListModel();
  1172             DefaultListModel<String> listModel = new DefaultListModel<>();
  1173             JList list = new JList(listModel);
  1173             JList<String> list = new JList<>(listModel);
  1174             list.setVisibleRowCount(15);
  1174             list.setVisibleRowCount(15);
  1175             list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  1175             list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  1176             list.addMouseListener(new PolicyListListener(tool, this));
  1176             list.addMouseListener(new PolicyListListener(tool, this));
  1177             PolicyEntry entries[] = tool.getEntry();
  1177             PolicyEntry entries[] = tool.getEntry();
  1178             if (entries != null) {
  1178             if (entries != null) {
  1185             newFilename.setText(policyFile);
  1185             newFilename.setText(policyFile);
  1186             initPolicyList(list);
  1186             initPolicyList(list);
  1187 
  1187 
  1188         } catch (FileNotFoundException fnfe) {
  1188         } catch (FileNotFoundException fnfe) {
  1189             // add blank policy listing
  1189             // add blank policy listing
  1190             JList list = new JList(new DefaultListModel());
  1190             JList<String> list = new JList<>(new DefaultListModel<>());
  1191             list.setVisibleRowCount(15);
  1191             list.setVisibleRowCount(15);
  1192             list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  1192             list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  1193             list.addMouseListener(new PolicyListListener(tool, this));
  1193             list.addMouseListener(new PolicyListListener(tool, this));
  1194             initPolicyList(list);
  1194             initPolicyList(list);
  1195             tool.setPolicyFileName(null);
  1195             tool.setPolicyFileName(null);
  1198             // just add warning
  1198             // just add warning
  1199             tool.warnings.addElement(fnfe.toString());
  1199             tool.warnings.addElement(fnfe.toString());
  1200 
  1200 
  1201         } catch (Exception e) {
  1201         } catch (Exception e) {
  1202             // add blank policy listing
  1202             // add blank policy listing
  1203             JList list = new JList(new DefaultListModel());
  1203             JList<String> list = new JList<>(new DefaultListModel<>());
  1204             list.setVisibleRowCount(15);
  1204             list.setVisibleRowCount(15);
  1205             list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  1205             list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  1206             list.addMouseListener(new PolicyListListener(tool, this));
  1206             list.addMouseListener(new PolicyListListener(tool, this));
  1207             initPolicyList(list);
  1207             initPolicyList(list);
  1208             tool.setPolicyFileName(null);
  1208             tool.setPolicyFileName(null);
  1314 
  1314 
  1315     /**
  1315     /**
  1316      * Init the policy_entry_list TEXTAREA component in the
  1316      * Init the policy_entry_list TEXTAREA component in the
  1317      * PolicyTool window
  1317      * PolicyTool window
  1318      */
  1318      */
  1319     void initPolicyList(JList policyList) {
  1319     void initPolicyList(JList<String> policyList) {
  1320 
  1320 
  1321         // add the policy list to the window
  1321         // add the policy list to the window
  1322         //policyList.setPreferredSize(new Dimension(500, 350));
  1322         //policyList.setPreferredSize(new Dimension(500, 350));
  1323         JScrollPane scrollPane = new JScrollPane(policyList);
  1323         JScrollPane scrollPane = new JScrollPane(policyList);
  1324         addNewComponent(this, scrollPane, MW_POLICY_LIST,
  1324         addNewComponent(this, scrollPane, MW_POLICY_LIST,
  1327 
  1327 
  1328     /**
  1328     /**
  1329      * Replace the policy_entry_list TEXTAREA component in the
  1329      * Replace the policy_entry_list TEXTAREA component in the
  1330      * PolicyTool window with an updated one.
  1330      * PolicyTool window with an updated one.
  1331      */
  1331      */
  1332     void replacePolicyList(JList policyList) {
  1332     void replacePolicyList(JList<String> policyList) {
  1333 
  1333 
  1334         // remove the original list of Policy Entries
  1334         // remove the original list of Policy Entries
  1335         // and add the new list of entries
  1335         // and add the new list of entries
  1336         JList list = (JList)getComponent(MW_POLICY_LIST);
  1336         @SuppressWarnings("unchecked")
       
  1337         JList<String> list = (JList<String>)getComponent(MW_POLICY_LIST);
  1337         list.setModel(policyList.getModel());
  1338         list.setModel(policyList.getModel());
  1338     }
  1339     }
  1339 
  1340 
  1340     /**
  1341     /**
  1341      * display the main PolicyTool window
  1342      * display the main PolicyTool window
  1666     private static final int PERMISSION_SIGNEDBY        = 3;
  1667     private static final int PERMISSION_SIGNEDBY        = 3;
  1667     private static final int PRINCIPAL_TYPE             = 4;
  1668     private static final int PRINCIPAL_TYPE             = 4;
  1668     private static final int PRINCIPAL_NAME             = 5;
  1669     private static final int PRINCIPAL_NAME             = 5;
  1669 
  1670 
  1670     /* The preferred height of JTextField should match JComboBox. */
  1671     /* The preferred height of JTextField should match JComboBox. */
  1671     static final int TEXTFIELD_HEIGHT = new JComboBox().getPreferredSize().height;
  1672     static final int TEXTFIELD_HEIGHT = new JComboBox<>().getPreferredSize().height;
  1672 
  1673 
  1673     public static java.util.ArrayList<Perm> PERM_ARRAY;
  1674     public static java.util.ArrayList<Perm> PERM_ARRAY;
  1674     public static java.util.ArrayList<Prin> PRIN_ARRAY;
  1675     public static java.util.ArrayList<Prin> PRIN_ARRAY;
  1675     PolicyTool tool;
  1676     PolicyTool tool;
  1676     ToolWindow tw;
  1677     ToolWindow tw;
  1809         setResizable(true);
  1810         setResizable(true);
  1810 
  1811 
  1811         if (edit) {
  1812         if (edit) {
  1812             // get the selected item
  1813             // get the selected item
  1813             entries = tool.getEntry();
  1814             entries = tool.getEntry();
  1814             JList policyList = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  1815             @SuppressWarnings("unchecked")
       
  1816             JList<String> policyList = (JList<String>)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  1815             listIndex = policyList.getSelectedIndex();
  1817             listIndex = policyList.getSelectedIndex();
  1816 
  1818 
  1817             // get principal list
  1819             // get principal list
  1818             LinkedList<PolicyParser.PrincipalEntry> principals =
  1820             LinkedList<PolicyParser.PrincipalEntry> principals =
  1819                 entries[listIndex].getGrantEntry().principals;
  1821                 entries[listIndex].getGrantEntry().principals;
  2153         tw.addNewComponent(newTD, label, PRD_DESC_LABEL,
  2155         tw.addNewComponent(newTD, label, PRD_DESC_LABEL,
  2154                            0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2156                            0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2155                            ToolWindow.TOP_BOTTOM_PADDING);
  2157                            ToolWindow.TOP_BOTTOM_PADDING);
  2156 
  2158 
  2157         // principal choice
  2159         // principal choice
  2158         JComboBox choice = new JComboBox();
  2160         JComboBox<String> choice = new JComboBox<>();
  2159         choice.addItem(PRIN_TYPE);
  2161         choice.addItem(PRIN_TYPE);
  2160         choice.getAccessibleContext().setAccessibleName(PRIN_TYPE);
  2162         choice.getAccessibleContext().setAccessibleName(PRIN_TYPE);
  2161         for (int i = 0; i < PRIN_ARRAY.size(); i++) {
  2163         for (int i = 0; i < PRIN_ARRAY.size(); i++) {
  2162             Prin next = PRIN_ARRAY.get(i);
  2164             Prin next = PRIN_ARRAY.get(i);
  2163             choice.addItem(next.CLASS);
  2165             choice.addItem(next.CLASS);
  2269         tw.addNewComponent(newTD, label, PD_DESC_LABEL,
  2271         tw.addNewComponent(newTD, label, PD_DESC_LABEL,
  2270                            0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2272                            0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2271                            ToolWindow.TOP_BOTTOM_PADDING);
  2273                            ToolWindow.TOP_BOTTOM_PADDING);
  2272 
  2274 
  2273         // permission choice (added in alphabetical order)
  2275         // permission choice (added in alphabetical order)
  2274         JComboBox choice = new JComboBox();
  2276         JComboBox<String> choice = new JComboBox<>();
  2275         choice.addItem(PERM);
  2277         choice.addItem(PERM);
  2276         choice.getAccessibleContext().setAccessibleName(PERM);
  2278         choice.getAccessibleContext().setAccessibleName(PERM);
  2277         for (int i = 0; i < PERM_ARRAY.size(); i++) {
  2279         for (int i = 0; i < PERM_ARRAY.size(); i++) {
  2278             Perm next = PERM_ARRAY.get(i);
  2280             Perm next = PERM_ARRAY.get(i);
  2279             choice.addItem(next.CLASS);
  2281             choice.addItem(next.CLASS);
  2297                            1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
  2299                            1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
  2298                            ToolWindow.LR_BOTTOM_PADDING);
  2300                            ToolWindow.LR_BOTTOM_PADDING);
  2299         choice.addItemListener(new PermissionMenuListener(newTD));
  2301         choice.addItemListener(new PermissionMenuListener(newTD));
  2300 
  2302 
  2301         // name label and textfield
  2303         // name label and textfield
  2302         choice = new JComboBox();
  2304         choice = new JComboBox<>();
  2303         choice.addItem(PERM_NAME);
  2305         choice.addItem(PERM_NAME);
  2304         choice.getAccessibleContext().setAccessibleName(PERM_NAME);
  2306         choice.getAccessibleContext().setAccessibleName(PERM_NAME);
  2305         tf = (edit ? new JTextField(editMe.name, 40) : new JTextField(40));
  2307         tf = (edit ? new JTextField(editMe.name, 40) : new JTextField(40));
  2306         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
  2308         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
  2307         tf.getAccessibleContext().setAccessibleName(PERM_NAME);
  2309         tf.getAccessibleContext().setAccessibleName(PERM_NAME);
  2315                            1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
  2317                            1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
  2316                            ToolWindow.LR_BOTTOM_PADDING);
  2318                            ToolWindow.LR_BOTTOM_PADDING);
  2317         choice.addItemListener(new PermissionNameMenuListener(newTD));
  2319         choice.addItemListener(new PermissionNameMenuListener(newTD));
  2318 
  2320 
  2319         // actions label and textfield
  2321         // actions label and textfield
  2320         choice = new JComboBox();
  2322         choice = new JComboBox<>();
  2321         choice.addItem(PERM_ACTIONS);
  2323         choice.addItem(PERM_ACTIONS);
  2322         choice.getAccessibleContext().setAccessibleName(PERM_ACTIONS);
  2324         choice.getAccessibleContext().setAccessibleName(PERM_ACTIONS);
  2323         tf = (edit ? new JTextField(editMe.action, 40) : new JTextField(40));
  2325         tf = (edit ? new JTextField(editMe.action, 40) : new JTextField(40));
  2324         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
  2326         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
  2325         tf.getAccessibleContext().setAccessibleName(PERM_ACTIONS);
  2327         tf.getAccessibleContext().setAccessibleName(PERM_ACTIONS);
  2512      * confirm that the user REALLY wants to remove the Policy Entry
  2514      * confirm that the user REALLY wants to remove the Policy Entry
  2513      */
  2515      */
  2514     void displayConfirmRemovePolicyEntry() {
  2516     void displayConfirmRemovePolicyEntry() {
  2515 
  2517 
  2516         // find the entry to be removed
  2518         // find the entry to be removed
  2517         JList list = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  2519         @SuppressWarnings("unchecked")
       
  2520         JList<String> list = (JList<String>)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  2518         int index = list.getSelectedIndex();
  2521         int index = list.getSelectedIndex();
  2519         PolicyEntry entries[] = tool.getEntry();
  2522         PolicyEntry entries[] = tool.getEntry();
  2520 
  2523 
  2521         // find where the PolicyTool gui is
  2524         // find where the PolicyTool gui is
  2522         Point location = tw.getLocationOnScreen();
  2525         Point location = tw.getLocationOnScreen();
  2732                 tool.modified = false;
  2735                 tool.modified = false;
  2733                 tw.displayErrorDialog(null, ee);
  2736                 tw.displayErrorDialog(null, ee);
  2734             }
  2737             }
  2735 
  2738 
  2736             // display the policy entries via the policy list textarea
  2739             // display the policy entries via the policy list textarea
  2737             JList list = new JList(new DefaultListModel());
  2740             JList<String> list = new JList<>(new DefaultListModel<>());
  2738             list.setVisibleRowCount(15);
  2741             list.setVisibleRowCount(15);
  2739             list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  2742             list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  2740             list.addMouseListener(new PolicyListListener(tool, tw));
  2743             list.addMouseListener(new PolicyListListener(tool, tw));
  2741             tw.replacePolicyList(list);
  2744             tw.replacePolicyList(list);
  2742 
  2745 
  2770             try {
  2773             try {
  2771                 // open the policy file
  2774                 // open the policy file
  2772                 tool.openPolicy(policyFile);
  2775                 tool.openPolicy(policyFile);
  2773 
  2776 
  2774                 // display the policy entries via the policy list textarea
  2777                 // display the policy entries via the policy list textarea
  2775                 DefaultListModel listModel = new DefaultListModel();
  2778                 DefaultListModel<String> listModel = new DefaultListModel<>();
  2776                 list = new JList(listModel);
  2779                 list = new JList<>(listModel);
  2777                 list.setVisibleRowCount(15);
  2780                 list.setVisibleRowCount(15);
  2778                 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  2781                 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  2779                 list.addMouseListener(new PolicyListListener(tool, tw));
  2782                 list.addMouseListener(new PolicyListListener(tool, tw));
  2780                 PolicyEntry entries[] = tool.getEntry();
  2783                 PolicyEntry entries[] = tool.getEntry();
  2781                 if (entries != null) {
  2784                 if (entries != null) {
  2798                         ("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information."));
  2801                         ("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information."));
  2799                 }
  2802                 }
  2800 
  2803 
  2801             } catch (Exception e) {
  2804             } catch (Exception e) {
  2802                 // add blank policy listing
  2805                 // add blank policy listing
  2803                 list = new JList(new DefaultListModel());
  2806                 list = new JList<>(new DefaultListModel<>());
  2804                 list.setVisibleRowCount(15);
  2807                 list.setVisibleRowCount(15);
  2805                 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  2808                 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  2806                 list.addMouseListener(new PolicyListListener(tool, tw));
  2809                 list.addMouseListener(new PolicyListListener(tool, tw));
  2807                 tw.replacePolicyList(list);
  2810                 tw.replacePolicyList(list);
  2808                 tool.setPolicyFileName(null);
  2811                 tool.setPolicyFileName(null);
  2833      *
  2836      *
  2834      * If TARGETS are valid but there are no standard ones
  2837      * If TARGETS are valid but there are no standard ones
  2835      * (user must enter them by hand) then the TARGETS array may be empty
  2838      * (user must enter them by hand) then the TARGETS array may be empty
  2836      * (and of course non-null).
  2839      * (and of course non-null).
  2837      */
  2840      */
  2838     void setPermissionNames(Perm inputPerm, JComboBox names, JTextField field) {
  2841     void setPermissionNames(Perm inputPerm, JComboBox<String> names, JTextField field) {
  2839         names.removeAllItems();
  2842         names.removeAllItems();
  2840         names.addItem(PERM_NAME);
  2843         names.addItem(PERM_NAME);
  2841 
  2844 
  2842         if (inputPerm == null) {
  2845         if (inputPerm == null) {
  2843             // custom permission
  2846             // custom permission
  2863      *
  2866      *
  2864      * If ACTIONS are valid but there are no standard ones
  2867      * If ACTIONS are valid but there are no standard ones
  2865      * (user must enter them by hand) then the ACTIONS array may be empty
  2868      * (user must enter them by hand) then the ACTIONS array may be empty
  2866      * (and of course non-null).
  2869      * (and of course non-null).
  2867      */
  2870      */
  2868     void setPermissionActions(Perm inputPerm, JComboBox actions, JTextField field) {
  2871     void setPermissionActions(Perm inputPerm, JComboBox<String> actions, JTextField field) {
  2869         actions.removeAllItems();
  2872         actions.removeAllItems();
  2870         actions.addItem(PERM_ACTIONS);
  2873         actions.addItem(PERM_ACTIONS);
  2871 
  2874 
  2872         if (inputPerm == null) {
  2875         if (inputPerm == null) {
  2873             // custom permission
  2876             // custom permission
  3102 
  3105 
  3103         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  3106         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  3104                                ToolWindow.REMOVE_POLICY_ENTRY) == 0) {
  3107                                ToolWindow.REMOVE_POLICY_ENTRY) == 0) {
  3105 
  3108 
  3106             // get the selected entry
  3109             // get the selected entry
  3107             JList list = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  3110             @SuppressWarnings("unchecked")
       
  3111             JList<String> list = (JList<String>)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  3108             int index = list.getSelectedIndex();
  3112             int index = list.getSelectedIndex();
  3109             if (index < 0) {
  3113             if (index < 0) {
  3110                 tw.displayErrorDialog(null, new Exception
  3114                 tw.displayErrorDialog(null, new Exception
  3111                         (PolicyTool.getMessage("No.Policy.Entry.selected")));
  3115                         (PolicyTool.getMessage("No.Policy.Entry.selected")));
  3112                 return;
  3116                 return;
  3119 
  3123 
  3120         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  3124         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  3121                                  ToolWindow.EDIT_POLICY_ENTRY) == 0) {
  3125                                  ToolWindow.EDIT_POLICY_ENTRY) == 0) {
  3122 
  3126 
  3123             // get the selected entry
  3127             // get the selected entry
  3124             JList list = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  3128             @SuppressWarnings("unchecked")
       
  3129             JList<String> list = (JList<String>)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  3125             int index = list.getSelectedIndex();
  3130             int index = list.getSelectedIndex();
  3126             if (index < 0) {
  3131             if (index < 0) {
  3127                 tw.displayErrorDialog(null, new Exception
  3132                 tw.displayErrorDialog(null, new Exception
  3128                         (PolicyTool.getMessage("No.Policy.Entry.selected")));
  3133                         (PolicyTool.getMessage("No.Policy.Entry.selected")));
  3129                 return;
  3134                 return;
  3190                     }
  3195                     }
  3191                 }
  3196                 }
  3192             }
  3197             }
  3193 
  3198 
  3194             // add the entry
  3199             // add the entry
  3195             JList policyList = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  3200             @SuppressWarnings("unchecked")
       
  3201             JList<String> policyList = (JList<String>)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  3196             if (edit) {
  3202             if (edit) {
  3197                 int listIndex = policyList.getSelectedIndex();
  3203                 int listIndex = policyList.getSelectedIndex();
  3198                 tool.addEntry(newEntry, listIndex);
  3204                 tool.addEntry(newEntry, listIndex);
  3199                 String newCodeBaseStr = newEntry.headerToString();
  3205                 String newCodeBaseStr = newEntry.headerToString();
  3200                 if (PolicyTool.collator.compare
  3206                 if (PolicyTool.collator.compare
  3201                         (newCodeBaseStr, policyList.getModel().getElementAt(listIndex)) != 0)
  3207                         (newCodeBaseStr, policyList.getModel().getElementAt(listIndex)) != 0)
  3202                     tool.modified = true;
  3208                     tool.modified = true;
  3203                 ((DefaultListModel)policyList.getModel()).set(listIndex, newCodeBaseStr);
  3209                 ((DefaultListModel<String>)policyList.getModel()).set(listIndex, newCodeBaseStr);
  3204             } else {
  3210             } else {
  3205                 tool.addEntry(newEntry, -1);
  3211                 tool.addEntry(newEntry, -1);
  3206                 ((DefaultListModel)policyList.getModel()).addElement(newEntry.headerToString());
  3212                 ((DefaultListModel<String>)policyList.getModel()).addElement(newEntry.headerToString());
  3207                 tool.modified = true;
  3213                 tool.modified = true;
  3208             }
  3214             }
  3209             td.setVisible(false);
  3215             td.setVisible(false);
  3210             td.dispose();
  3216             td.dispose();
  3211 
  3217 
  3579     }
  3585     }
  3580 
  3586 
  3581     public void actionPerformed(ActionEvent e) {
  3587     public void actionPerformed(ActionEvent e) {
  3582 
  3588 
  3583         // get the Permission selected from the Permission List
  3589         // get the Permission selected from the Permission List
  3584         JList list = (JList)td.getComponent(ToolDialog.PE_PERM_LIST);
  3590         @SuppressWarnings("unchecked")
       
  3591         JList<String> list = (JList<String>)td.getComponent(ToolDialog.PE_PERM_LIST);
  3585         int permIndex = list.getSelectedIndex();
  3592         int permIndex = list.getSelectedIndex();
  3586 
  3593 
  3587         if (permIndex < 0) {
  3594         if (permIndex < 0) {
  3588             tw.displayErrorDialog(td, new Exception
  3595             tw.displayErrorDialog(td, new Exception
  3589                 (PolicyTool.getMessage("No.permission.selected")));
  3596                 (PolicyTool.getMessage("No.permission.selected")));
  3614         if (e.getStateChange() == ItemEvent.DESELECTED) {
  3621         if (e.getStateChange() == ItemEvent.DESELECTED) {
  3615             // We're only interested in SELECTED events
  3622             // We're only interested in SELECTED events
  3616             return;
  3623             return;
  3617         }
  3624         }
  3618 
  3625 
  3619         JComboBox prin = (JComboBox)td.getComponent(ToolDialog.PRD_PRIN_CHOICE);
  3626         @SuppressWarnings("unchecked")
       
  3627         JComboBox<String> prin = (JComboBox<String>)td.getComponent(ToolDialog.PRD_PRIN_CHOICE);
  3620         JTextField prinField = (JTextField)td.getComponent(
  3628         JTextField prinField = (JTextField)td.getComponent(
  3621                 ToolDialog.PRD_PRIN_TEXTFIELD);
  3629                 ToolDialog.PRD_PRIN_TEXTFIELD);
  3622         JTextField nameField = (JTextField)td.getComponent(
  3630         JTextField nameField = (JTextField)td.getComponent(
  3623                 ToolDialog.PRD_NAME_TEXTFIELD);
  3631                 ToolDialog.PRD_NAME_TEXTFIELD);
  3624 
  3632 
  3664         if (e.getStateChange() == ItemEvent.DESELECTED) {
  3672         if (e.getStateChange() == ItemEvent.DESELECTED) {
  3665             // We're only interested in SELECTED events
  3673             // We're only interested in SELECTED events
  3666             return;
  3674             return;
  3667         }
  3675         }
  3668 
  3676 
  3669         JComboBox perms = (JComboBox)td.getComponent(
  3677         @SuppressWarnings("unchecked")
       
  3678         JComboBox<String> perms = (JComboBox<String>)td.getComponent(
  3670                 ToolDialog.PD_PERM_CHOICE);
  3679                 ToolDialog.PD_PERM_CHOICE);
  3671         JComboBox names = (JComboBox)td.getComponent(
  3680         @SuppressWarnings("unchecked")
       
  3681         JComboBox<String> names = (JComboBox<String>)td.getComponent(
  3672                 ToolDialog.PD_NAME_CHOICE);
  3682                 ToolDialog.PD_NAME_CHOICE);
  3673         JComboBox actions = (JComboBox)td.getComponent(
  3683         @SuppressWarnings("unchecked")
       
  3684         JComboBox<String> actions = (JComboBox<String>)td.getComponent(
  3674                 ToolDialog.PD_ACTIONS_CHOICE);
  3685                 ToolDialog.PD_ACTIONS_CHOICE);
  3675         JTextField nameField = (JTextField)td.getComponent(
  3686         JTextField nameField = (JTextField)td.getComponent(
  3676                 ToolDialog.PD_NAME_TEXTFIELD);
  3687                 ToolDialog.PD_NAME_TEXTFIELD);
  3677         JTextField actionsField = (JTextField)td.getComponent(
  3688         JTextField actionsField = (JTextField)td.getComponent(
  3678                 ToolDialog.PD_ACTIONS_TEXTFIELD);
  3689                 ToolDialog.PD_ACTIONS_TEXTFIELD);
  3735         if (e.getStateChange() == ItemEvent.DESELECTED) {
  3746         if (e.getStateChange() == ItemEvent.DESELECTED) {
  3736             // We're only interested in SELECTED events
  3747             // We're only interested in SELECTED events
  3737             return;
  3748             return;
  3738         }
  3749         }
  3739 
  3750 
  3740         JComboBox names = (JComboBox)td.getComponent(ToolDialog.PD_NAME_CHOICE);
  3751         @SuppressWarnings("unchecked")
       
  3752         JComboBox<String> names = (JComboBox<String>)td.getComponent(ToolDialog.PD_NAME_CHOICE);
  3741         names.getAccessibleContext().setAccessibleName(
  3753         names.getAccessibleContext().setAccessibleName(
  3742             PolicyTool.splitToWords((String)e.getItem()));
  3754             PolicyTool.splitToWords((String)e.getItem()));
  3743 
  3755 
  3744         if (((String)e.getItem()).indexOf(ToolDialog.PERM_NAME) != -1)
  3756         if (((String)e.getItem()).indexOf(ToolDialog.PERM_NAME) != -1)
  3745             return;
  3757             return;
  3764         if (e.getStateChange() == ItemEvent.DESELECTED) {
  3776         if (e.getStateChange() == ItemEvent.DESELECTED) {
  3765             // We're only interested in SELECTED events
  3777             // We're only interested in SELECTED events
  3766             return;
  3778             return;
  3767         }
  3779         }
  3768 
  3780 
  3769         JComboBox actions = (JComboBox)td.getComponent(
  3781         @SuppressWarnings("unchecked")
       
  3782         JComboBox<String> actions = (JComboBox<String>)td.getComponent(
  3770                 ToolDialog.PD_ACTIONS_CHOICE);
  3783                 ToolDialog.PD_ACTIONS_CHOICE);
  3771         actions.getAccessibleContext().setAccessibleName((String)e.getItem());
  3784         actions.getAccessibleContext().setAccessibleName((String)e.getItem());
  3772 
  3785 
  3773         if (((String)e.getItem()).indexOf(ToolDialog.PERM_ACTIONS) != -1)
  3786         if (((String)e.getItem()).indexOf(ToolDialog.PERM_ACTIONS) != -1)
  3774             return;
  3787             return;
  3989         this.us = us;
  4002         this.us = us;
  3990     }
  4003     }
  3991 
  4004 
  3992     public void actionPerformed(ActionEvent e) {
  4005     public void actionPerformed(ActionEvent e) {
  3993         // remove the entry
  4006         // remove the entry
  3994         JList list = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  4007         @SuppressWarnings("unchecked")
       
  4008         JList<String> list = (JList<String>)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  3995         int index = list.getSelectedIndex();
  4009         int index = list.getSelectedIndex();
  3996         PolicyEntry entries[] = tool.getEntry();
  4010         PolicyEntry entries[] = tool.getEntry();
  3997         tool.removeEntry(entries[index]);
  4011         tool.removeEntry(entries[index]);
  3998 
  4012 
  3999         // redraw the window listing
  4013         // redraw the window listing
  4000         DefaultListModel listModel = new DefaultListModel();
  4014         DefaultListModel<String> listModel = new DefaultListModel<>();
  4001         list = new JList(listModel);
  4015         list = new JList<>(listModel);
  4002         list.setVisibleRowCount(15);
  4016         list.setVisibleRowCount(15);
  4003         list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  4017         list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  4004         list.addMouseListener(new PolicyListListener(tool, tw));
  4018         list.addMouseListener(new PolicyListListener(tool, tw));
  4005         entries = tool.getEntry();
  4019         entries = tool.getEntry();
  4006         if (entries != null) {
  4020         if (entries != null) {
  4023 }
  4037 }
  4024 
  4038 
  4025 /**
  4039 /**
  4026  * This is a java.awt.List that bind an Object to each String it holds.
  4040  * This is a java.awt.List that bind an Object to each String it holds.
  4027  */
  4041  */
  4028 class TaggedList extends JList {
  4042 class TaggedList extends JList<String> {
  4029     private static final long serialVersionUID = -5676238110427785853L;
  4043     private static final long serialVersionUID = -5676238110427785853L;
  4030 
  4044 
  4031     private java.util.List<Object> data = new LinkedList<>();
  4045     private java.util.List<Object> data = new LinkedList<>();
  4032     public TaggedList(int i, boolean b) {
  4046     public TaggedList(int i, boolean b) {
  4033         super(new DefaultListModel());
  4047         super(new DefaultListModel<>());
  4034         setVisibleRowCount(i);
  4048         setVisibleRowCount(i);
  4035         setSelectionMode(b ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : ListSelectionModel.SINGLE_SELECTION);
  4049         setSelectionMode(b ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : ListSelectionModel.SINGLE_SELECTION);
  4036     }
  4050     }
  4037 
  4051 
  4038     public Object getObject(int index) {
  4052     public Object getObject(int index) {
  4039         return data.get(index);
  4053         return data.get(index);
  4040     }
  4054     }
  4041 
  4055 
  4042     public void addTaggedItem(String string, Object object) {
  4056     public void addTaggedItem(String string, Object object) {
  4043         ((DefaultListModel)getModel()).addElement(string);
  4057         ((DefaultListModel<String>)getModel()).addElement(string);
  4044         data.add(object);
  4058         data.add(object);
  4045     }
  4059     }
  4046 
  4060 
  4047     public void replaceTaggedItem(String string, Object object, int index) {
  4061     public void replaceTaggedItem(String string, Object object, int index) {
  4048         ((DefaultListModel)getModel()).set(index, string);
  4062         ((DefaultListModel<String>)getModel()).set(index, string);
  4049         data.set(index, object);
  4063         data.set(index, object);
  4050     }
  4064     }
  4051 
  4065 
  4052     public void removeTaggedItem(int index) {
  4066     public void removeTaggedItem(int index) {
  4053         ((DefaultListModel)getModel()).remove(index);
  4067         ((DefaultListModel<String>)getModel()).remove(index);
  4054         data.remove(index);
  4068         data.remove(index);
  4055     }
  4069     }
  4056 }
  4070 }
  4057 
  4071 
  4058 /**
  4072 /**