KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > markers > internal > BookmarkFilter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 JavaDoc TAG_CONTAINS = "contains"; //$NON-NLS-1$
21

22     private final static String JavaDoc TAG_DESCRIPTION = "description"; //$NON-NLS-1$
23

24     final static boolean DEFAULT_CONTAINS = true;
25
26     final static String JavaDoc DEFAULT_DESCRIPTION = ""; //$NON-NLS-1$
27

28     private boolean contains;
29
30     private String JavaDoc description;
31
32     /**
33      * Create a new instance of the recevier with the default name.
34      *
35      */

36     public BookmarkFilter() {
37         this(MarkerMessages.MarkerFilter_defaultFilterName);
38     }
39
40     /**
41      * Create a new instance of the recevier with the filterName
42      *
43      * @param filterName
44      */

45     public BookmarkFilter(String JavaDoc filterName) {
46         super(filterName, new String JavaDoc[] { IMarker.BOOKMARK });
47     }
48
49     /**
50      * Returns true iff the given marker is accepted by this filter
51      */

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("")) { //$NON-NLS-1$
59
return true;
60         }
61
62         String JavaDoc 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 JavaDoc getDescription() {
72         return description;
73     }
74
75     void setContains(boolean contains) {
76         this.contains = contains;
77     }
78
79     void setDescription(String JavaDoc description) {
80         this.description = description;
81     }
82
83     /*
84      * (non-Javadoc)
85      *
86      * @see org.eclipse.ui.views.markers.internal.MarkerFilter#resetState()
87      */

88     void resetState() {
89         super.resetState();
90         contains = DEFAULT_CONTAINS;
91         description = DEFAULT_DESCRIPTION;
92     }
93
94     /*
95      * (non-Javadoc)
96      *
97      * @see org.eclipse.ui.views.markers.internal.MarkerFilter#restoreFilterSettings(org.eclipse.jface.dialogs.IDialogSettings)
98      */

99     public void restoreFilterSettings(IDialogSettings settings) {
100
101         super.restoreFilterSettings(settings);
102
103         String JavaDoc 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 JavaDoc(setting);
113         }
114
115     }
116
117     /* (non-Javadoc)
118      * @see org.eclipse.ui.views.markers.internal.MarkerFilter#restoreFilterSettings(org.eclipse.ui.IMemento)
119      */

120     protected void restoreFilterSettings(IMemento memento) {
121         super.restoreFilterSettings(memento);
122
123         String JavaDoc 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 JavaDoc(setting);
133         }
134
135     }
136
137     /*
138      * (non-Javadoc)
139      *
140      * @see org.eclipse.ui.views.markers.internal.MarkerFilter#saveFilterSettings(org.eclipse.ui.IMemento)
141      */

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