1 19 20 package org.netbeans.modules.autoupdate.catalog; 21 22 import java.awt.BorderLayout ; 23 import java.awt.Component ; 24 import java.util.HashSet ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Set ; 28 import java.util.SortedSet ; 29 import java.util.TreeSet ; 30 import javax.swing.*; 31 32 import org.netbeans.Module; 33 import org.netbeans.ModuleManager; 34 import org.openide.awt.Mnemonics; 35 import org.openide.util.NbBundle; 36 37 41 class ModuleUninstallPanel extends JPanel { 42 Set modules; 43 String category; 44 45 public ModuleUninstallPanel (Set m, String category) { 46 this.modules = m; 47 this.category = category; 48 initComponents (); 49 postInitComponents (); 50 } 51 52 private void initComponents() { jPanel1 = new javax.swing.JPanel (); 54 uninstallConfirmation = new javax.swing.JLabel (); 55 56 setLayout(new java.awt.BorderLayout (0, 2)); 57 58 add(jPanel1, java.awt.BorderLayout.CENTER); 59 60 uninstallConfirmation.setText(org.openide.util.NbBundle.getMessage(ModuleUninstallPanel.class, "LBL_ModuleUninstallPanel_UninstallConfirmation", new Object [] {})); 61 add(uninstallConfirmation, java.awt.BorderLayout.SOUTH); 62 63 } 65 66 private javax.swing.JPanel jPanel1; 68 private javax.swing.JLabel uninstallConfirmation; 69 71 private String getModuleNames () { 72 if (category != null) { 73 return category; 74 } 75 return modules.size () == 1 ? ((Module) modules.iterator ().next ()).getDisplayName () : 76 NbBundle.getMessage (ModuleUninstallPanel.class, "CTL_ModuleNodeActions_UninstallAction_many"); } 78 79 private void postInitComponents () { 80 81 Set disableCandidates = new HashSet (); 82 Iterator it = modules.iterator (); 83 ModuleManager manager = null; 84 while (it.hasNext ()) { 85 Module module = (Module) it.next (); 86 if (manager == null) { 87 manager = module.getManager (); 88 } 89 if (module.isEnabled () && ! module.isAutoload () && ! module.isEager ()) { 90 disableCandidates.add (module); 91 } 92 } 93 94 boolean simple = true; 95 96 if (! disableCandidates.isEmpty ()) { 97 98 List toDisable = manager.simulateDisable (disableCandidates); 99 100 Iterator it2 = toDisable.iterator(); 101 SortedSet others = new TreeSet (ModuleBean.AllModulesBean.getDefault ()); while (it2.hasNext ()) { 103 Module m = (Module) it2.next (); 104 if (!m.isAutoload () && !m.isEager () && ! modules.contains (m)) { 105 others.add (m); 106 } 107 } 108 109 if (! others.isEmpty ()) { 110 Component c = new ModulesAndDescription ((Module []) others.toArray (new Module [others.size ()]), 111 NbBundle.getMessage(ModuleUninstallPanel.class, "LBL_ModuleUninstallPanel_UninstallLabel_depend", new Object [] {getModuleNames ()})); 113 add (c, BorderLayout.CENTER); 114 simple = false; 115 } 116 } 117 118 if (simple) { 119 JLabel uninstallLabel = new JLabel (); 120 if (category != null) { 121 uninstallLabel.setText (NbBundle.getMessage(ModuleUninstallPanel.class, "LBL_ModuleUninstallPanel_UninstallLabel_noDepend", category, 123 NbBundle.getMessage (ModuleUninstallPanel.class, "CTL_ModuleNodeActions_EnableDisableAction_category") )); 125 } else { 126 uninstallLabel.setText (NbBundle.getMessage(ModuleUninstallPanel.class, "LBL_ModuleUninstallPanel_UninstallLabel_noDepend", modules.size () == 1 ? ((Module)modules.iterator ().next ()).getDisplayName () : String.valueOf (modules.size ()), 128 modules.size () == 1 ? NbBundle.getMessage (ModuleUninstallPanel.class, "CTL_ModuleNodeActions_EnableDisableAction_single") : NbBundle.getMessage (ModuleUninstallPanel.class, "CTL_ModuleNodeActions_EnableDisableAction_many") )); 131 } 132 uninstallConfirmation.setVisible (false); 133 add (uninstallLabel, BorderLayout.CENTER); 134 } 135 } 136 } 137 | Popular Tags |