1 19 package org.netbeans.modules.editor.hints.options; 20 21 import java.util.HashMap ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.Map ; 25 import java.util.Map.Entry; 26 import org.netbeans.spi.editor.hints.ProvidersList; 27 import org.netbeans.spi.editor.hints.Severity; 28 29 33 public class ModelImpl { 34 35 private AdvancedHintsPanel panel; 36 37 private Map <String , Boolean > key2Enabled; 38 private Map <String , Map <String , Severity>> key2Error2Severity; 39 40 private int eagerness; 41 42 43 public ModelImpl(AdvancedHintsPanel panel) { 44 this.panel = panel; 45 key2Enabled = new HashMap <String , Boolean >(); 46 key2Error2Severity = new HashMap <String , Map <String , Severity>>(); 47 eagerness = (-1); 48 } 49 50 public synchronized boolean isProviderEnabled(String providerKey) { 51 Boolean cache = (Boolean ) key2Enabled.get(providerKey); 52 53 if (cache == null) 54 return ProvidersList.isProviderEnabled(providerKey); 55 56 return cache.booleanValue(); 57 } 58 59 public synchronized Severity getErrorSeverity(String providerKey, String errorKey) { 60 Map <String , Severity> error2Severity = key2Error2Severity.get(providerKey); 61 62 if (error2Severity == null) 63 return ProvidersList.getErrorSeverity(providerKey, errorKey); 64 65 Severity cache = error2Severity.get(errorKey); 66 67 if (cache == null) 68 return ProvidersList.getErrorSeverity(providerKey, errorKey); 69 70 return cache; 71 } 72 73 public synchronized void setProviderEnabled(String providerKey, boolean enabled) { 74 key2Enabled.put(providerKey, Boolean.valueOf(enabled)); 75 76 panel.firePropertyChange(AdvancedHintsPanel.PROP_CHANGED, null, null); 77 } 78 79 public synchronized void setSeverity(String providerKey, String errorKey, Severity severity) { 80 Map <String , Severity> error2Severity = key2Error2Severity.get(providerKey); 81 82 if (error2Severity == null) { 83 key2Error2Severity.put(providerKey, error2Severity = new HashMap <String , Severity>()); 84 } 85 86 error2Severity.put(errorKey, severity); 87 88 panel.firePropertyChange(AdvancedHintsPanel.PROP_CHANGED, null, null); 89 } 90 91 public synchronized List getDescriptions() { 92 return ProvidersListAccessor.INSTANCE.getDescriptions(); 93 } 94 95 public void rollBack() { 96 key2Enabled = new HashMap <String , Boolean >(); 97 key2Error2Severity = new HashMap <String , Map <String , Severity>>(); 98 eagerness = (-1); 99 } 100 101 public void commit() { 102 for (Entry<String , Boolean > e : key2Enabled.entrySet()) { 103 String key = e.getKey(); 104 Boolean value = e.getValue(); 105 106 ProvidersListAccessor.INSTANCE.setProviderEnabled(key, value.booleanValue()); 107 } 108 109 for (Entry<String , Map <String , Severity>> eP : key2Error2Severity.entrySet()) { 110 String key = eP.getKey(); 111 Map <String , Severity> error2Severity = eP.getValue(); 112 113 for (Entry<String , Severity> e : error2Severity.entrySet()) { 114 String errorKey = e.getKey(); 115 Severity severity = e.getValue(); 116 117 ProvidersListAccessor.INSTANCE.setSeverity(key, errorKey, severity); 118 } 119 } 120 121 122 key2Enabled = new HashMap <String , Boolean >(); 123 key2Error2Severity = new HashMap <String , Map <String , Severity>>(); 124 eagerness = (-1); 125 } 126 127 public boolean isModified() { 128 return !key2Enabled.isEmpty() || !key2Error2Severity.isEmpty() || (eagerness != (-1)); 129 } 130 } 131 | Popular Tags |