KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > autoupdate > catalog > ModuleUninstallPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.autoupdate.catalog;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Set JavaDoc;
28 import java.util.SortedSet JavaDoc;
29 import java.util.TreeSet JavaDoc;
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 /** XXX
38  * @author Jiri Rechtacek
39  * @see "#20323"
40  */

41 class ModuleUninstallPanel extends JPanel {
42     Set JavaDoc/*<Module>*/ modules;
43     String JavaDoc category;
44     
45     public ModuleUninstallPanel (Set JavaDoc/*<Module>*/ m, String JavaDoc category) {
46         this.modules = m;
47         this.category = category;
48         initComponents ();
49         postInitComponents ();
50     }
51     
52     private void initComponents() {//GEN-BEGIN:initComponents
53
jPanel1 = new javax.swing.JPanel JavaDoc();
54         uninstallConfirmation = new javax.swing.JLabel JavaDoc();
55
56         setLayout(new java.awt.BorderLayout JavaDoc(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 JavaDoc[] {}));
61         add(uninstallConfirmation, java.awt.BorderLayout.SOUTH);
62
63     }//GEN-END:initComponents
64

65     
66     // Variables declaration - do not modify//GEN-BEGIN:variables
67
private javax.swing.JPanel JavaDoc jPanel1;
68     private javax.swing.JLabel JavaDoc uninstallConfirmation;
69     // End of variables declaration//GEN-END:variables
70

71     private String JavaDoc 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"); // NOI18N
77
}
78     
79     private void postInitComponents () {
80         
81         Set JavaDoc disableCandidates = new HashSet JavaDoc ();
82         Iterator JavaDoc/*<Module>*/ 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 JavaDoc toDisable = manager.simulateDisable (disableCandidates);
99
100             Iterator JavaDoc/*<Module>*/ it2 = toDisable.iterator();
101             SortedSet JavaDoc others = new TreeSet JavaDoc (ModuleBean.AllModulesBean.getDefault ()); // SortedSet<Module>
102
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 JavaDoc c = new ModulesAndDescription ((Module []) others.toArray (new Module [others.size ()]),
111                 NbBundle.getMessage(ModuleUninstallPanel.class, "LBL_ModuleUninstallPanel_UninstallLabel_depend", // NOI18N
112
new Object JavaDoc[] {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", // NOI18N
122
category,
123                                             NbBundle.getMessage (ModuleUninstallPanel.class, "CTL_ModuleNodeActions_EnableDisableAction_category") // NOI18N
124
));
125             } else {
126                 uninstallLabel.setText (NbBundle.getMessage(ModuleUninstallPanel.class, "LBL_ModuleUninstallPanel_UninstallLabel_noDepend", // NOI18N
127
modules.size () == 1 ? ((Module)modules.iterator ().next ()).getDisplayName () : String.valueOf (modules.size ()),
128                                             modules.size () == 1 ? NbBundle.getMessage (ModuleUninstallPanel.class, "CTL_ModuleNodeActions_EnableDisableAction_single") : // NOI18N
129
NbBundle.getMessage (ModuleUninstallPanel.class, "CTL_ModuleNodeActions_EnableDisableAction_many") // NOI18N
130
));
131             }
132             uninstallConfirmation.setVisible (false);
133             add (uninstallLabel, BorderLayout.CENTER);
134         }
135     }
136 }
137
Popular Tags