KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > uihandler > EnabledModulesCollector


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.uihandler;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.logging.Level JavaDoc;
26 import java.util.logging.LogRecord JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28 import org.netbeans.modules.uihandler.api.Deactivated;
29 import org.openide.modules.ModuleInfo;
30 import org.openide.util.Lookup;
31 import org.openide.util.NbBundle;
32
33 /** Implementation of deactivator with sends one log with a list
34  * of enabled modules.
35  *
36  */

37 public class EnabledModulesCollector implements Deactivated {
38     private List JavaDoc<ModuleInfo> previouslyEnabled = Collections.emptyList();
39     private List JavaDoc<ModuleInfo> previouslyDisabled = Collections.emptyList();
40     
41     
42     /** Creates a new instance of EnabledModulesCollector */
43     public EnabledModulesCollector() {
44     }
45
46     public void deactivated(Logger JavaDoc uiLogger) {
47         List JavaDoc<ModuleInfo> enabled = new ArrayList JavaDoc<ModuleInfo>();
48         List JavaDoc<ModuleInfo> disabled = new ArrayList JavaDoc<ModuleInfo>();
49         for (ModuleInfo m : Lookup.getDefault().lookupAll(ModuleInfo.class)) {
50             if (m.isEnabled()) {
51                 enabled.add(m);
52             } else {
53                 disabled.add(m);
54             }
55         }
56
57         List JavaDoc<ModuleInfo> newEnabled = new ArrayList JavaDoc<ModuleInfo>(enabled);
58         newEnabled.removeAll(previouslyEnabled);
59         List JavaDoc<ModuleInfo> newDisabled = new ArrayList JavaDoc<ModuleInfo>(disabled);
60         newDisabled.removeAll(previouslyDisabled);
61         
62         if (!newEnabled.isEmpty()) {
63             LogRecord JavaDoc rec = new LogRecord JavaDoc(Level.CONFIG, "UI_ENABLED_MODULES");
64             String JavaDoc[] enabledNames = new String JavaDoc[newEnabled.size()];
65             int i = 0;
66             for (ModuleInfo m : newEnabled) {
67                 enabledNames[i++] = m.getCodeName();
68             }
69             rec.setParameters(enabledNames);
70             rec.setLoggerName(uiLogger.getName());
71             rec.setResourceBundle(NbBundle.getBundle(EnabledModulesCollector.class));
72             rec.setResourceBundleName(EnabledModulesCollector.class.getPackage().getName()+".Bundle");
73             uiLogger.log(rec);
74         }
75         if (!newDisabled.isEmpty()) {
76             LogRecord JavaDoc rec = new LogRecord JavaDoc(Level.CONFIG, "UI_DISABLED_MODULES");
77             String JavaDoc[] disabledNames = new String JavaDoc[newDisabled.size()];
78             int i = 0;
79             for (ModuleInfo m : newDisabled) {
80                 disabledNames[i++] = m.getCodeName();
81             }
82             rec.setParameters(disabledNames);
83             rec.setLoggerName(uiLogger.getName());
84             rec.setResourceBundle(NbBundle.getBundle(EnabledModulesCollector.class));
85             rec.setResourceBundleName(EnabledModulesCollector.class.getPackage().getName()+".Bundle");
86             uiLogger.log(rec);
87         }
88         
89         previouslyEnabled = enabled;
90         previouslyDisabled = disabled;
91     }
92     
93 }
94
Popular Tags