1 19 20 package org.netbeans.modules.uihandler; 21 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.List ; 25 import java.util.logging.Level ; 26 import java.util.logging.LogRecord ; 27 import java.util.logging.Logger ; 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 37 public class EnabledModulesCollector implements Deactivated { 38 private List <ModuleInfo> previouslyEnabled = Collections.emptyList(); 39 private List <ModuleInfo> previouslyDisabled = Collections.emptyList(); 40 41 42 43 public EnabledModulesCollector() { 44 } 45 46 public void deactivated(Logger uiLogger) { 47 List <ModuleInfo> enabled = new ArrayList <ModuleInfo>(); 48 List <ModuleInfo> disabled = new ArrayList <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 <ModuleInfo> newEnabled = new ArrayList <ModuleInfo>(enabled); 58 newEnabled.removeAll(previouslyEnabled); 59 List <ModuleInfo> newDisabled = new ArrayList <ModuleInfo>(disabled); 60 newDisabled.removeAll(previouslyDisabled); 61 62 if (!newEnabled.isEmpty()) { 63 LogRecord rec = new LogRecord (Level.CONFIG, "UI_ENABLED_MODULES"); 64 String [] enabledNames = new String [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 rec = new LogRecord (Level.CONFIG, "UI_DISABLED_MODULES"); 77 String [] disabledNames = new String [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 |