1 11 12 package org.eclipse.ui.views.markers.internal; 13 14 import org.eclipse.core.resources.IMarker; 15 import org.eclipse.jface.dialogs.IDialogSettings; 16 import org.eclipse.ui.IMemento; 17 18 public class BookmarkFilter extends MarkerFilter { 19 20 private final static String TAG_CONTAINS = "contains"; 22 private final static String TAG_DESCRIPTION = "description"; 24 final static boolean DEFAULT_CONTAINS = true; 25 26 final static String DEFAULT_DESCRIPTION = ""; 28 private boolean contains; 29 30 private String description; 31 32 36 public BookmarkFilter() { 37 this(MarkerMessages.MarkerFilter_defaultFilterName); 38 } 39 40 45 public BookmarkFilter(String filterName) { 46 super(filterName, new String [] { IMarker.BOOKMARK }); 47 } 48 49 52 public boolean selectMarker(ConcreteMarker marker) { 53 return !isEnabled() 54 || (super.selectMarker(marker) && selectByDescription(marker)); 55 } 56 57 private boolean selectByDescription(ConcreteMarker marker) { 58 if (description == null || description.equals("")) { return true; 60 } 61 62 String markerDescription = marker.getDescription(); 63 int index = markerDescription.indexOf(description); 64 return contains ? (index >= 0) : (index < 0); 65 } 66 67 boolean getContains() { 68 return contains; 69 } 70 71 String getDescription() { 72 return description; 73 } 74 75 void setContains(boolean contains) { 76 this.contains = contains; 77 } 78 79 void setDescription(String description) { 80 this.description = description; 81 } 82 83 88 void resetState() { 89 super.resetState(); 90 contains = DEFAULT_CONTAINS; 91 description = DEFAULT_DESCRIPTION; 92 } 93 94 99 public void restoreFilterSettings(IDialogSettings settings) { 100 101 super.restoreFilterSettings(settings); 102 103 String setting = settings.get(TAG_CONTAINS); 104 105 if (setting != null) { 106 contains = Boolean.valueOf(setting).booleanValue(); 107 } 108 109 setting = settings.get(TAG_DESCRIPTION); 110 111 if (setting != null) { 112 description = new String (setting); 113 } 114 115 } 116 117 120 protected void restoreFilterSettings(IMemento memento) { 121 super.restoreFilterSettings(memento); 122 123 String setting = memento.getString(TAG_CONTAINS); 124 125 if (setting != null) { 126 contains = Boolean.valueOf(setting).booleanValue(); 127 } 128 129 setting = memento.getString(TAG_DESCRIPTION); 130 131 if (setting != null) { 132 description = new String (setting); 133 } 134 135 } 136 137 142 public void saveFilterSettings(IMemento memento) { 143 super.saveFilterSettings(memento); 144 memento.putString(TAG_CONTAINS, String.valueOf(contains)); 145 memento.putString(TAG_DESCRIPTION, description); 146 } 147 148 } 149 | Popular Tags |