1 11 package org.eclipse.ui.texteditor.rulers; 12 13 import java.util.Set ; 14 15 import org.eclipse.core.runtime.Assert; 16 17 import org.eclipse.jface.preference.IPreferenceStore; 18 import org.eclipse.ui.internal.texteditor.rulers.StringSetSerializer; 19 20 25 public final class RulerColumnPreferenceAdapter { 26 private final IPreferenceStore fStore; 27 private final String fKey; 28 29 36 public RulerColumnPreferenceAdapter(IPreferenceStore store, String key) { 37 Assert.isLegal(store != null); 38 Assert.isLegal(key != null); 39 fStore= store; 40 fKey= key; 41 } 42 43 49 public boolean isEnabled(RulerColumnDescriptor descriptor) { 50 Assert.isLegal(descriptor != null); 51 String preference= fStore.getString(fKey); 52 return StringSetSerializer.deserialize(preference).contains(descriptor.getId()) ^ descriptor.getDefaultEnablement(); 53 } 54 55 62 public void setEnabled(RulerColumnDescriptor descriptor, boolean enabled) { 63 Assert.isLegal(descriptor != null); 64 String id= descriptor.getId(); 65 String preference= fStore.getString(fKey); 66 Set marked= StringSetSerializer.deserialize(preference); 67 boolean shouldMark= enabled ^ descriptor.getDefaultEnablement(); 68 boolean isMarked= marked.contains(id); 69 if (isMarked != shouldMark) { 70 if (shouldMark) 71 marked.add(id); 72 else 73 marked.remove(id); 74 fStore.setValue(fKey, StringSetSerializer.serialize(marked)); 75 } 76 } 77 78 83 public void toggle(RulerColumnDescriptor descriptor) { 84 Assert.isLegal(descriptor != null); 85 setEnabled(descriptor, !isEnabled(descriptor)); 86 } 87 } 88 | Popular Tags |