Java Doc and API clean up of TMF UML Sequence diagram framework
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / dialogs / FilterCriteria.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2008 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
4 *
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
9 *
10 * Contributors:
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs;
15
16 import java.util.Iterator;
17 import java.util.List;
18
19 import org.eclipse.jface.dialogs.DialogSettings;
20
21 /**
22 * A filter criteria is a criteria that can be activated or not, positive or not.
23 *
24 * @version 1.0
25 * @author sveyrier
26 *
27 */
28 public class FilterCriteria {
29
30 // ------------------------------------------------------------------------
31 // Constants
32 // ------------------------------------------------------------------------
33 /**
34 * The filter state value for 'active'.
35 */
36 protected static final String ACTIVE = "active"; //$NON-NLS-1$
37 /**
38 * The property value for positive filter.
39 */
40 protected static final String POSITIVE = "positive"; //$NON-NLS-1$
41 /**
42 * The filter loader class name property.
43 */
44 protected static final String LOADERCLASSNAME = "loaderClassName"; //$NON-NLS-1$
45
46 // ------------------------------------------------------------------------
47 // Attributes
48 // ------------------------------------------------------------------------
49 /**
50 * The criteria reference.
51 */
52 protected Criteria criteria;
53 /**
54 * Flag whether this criteria is active or not
55 */
56 protected boolean active;
57 /**
58 * Flag whether this criteria is for positive filter or not
59 */
60 protected boolean positive;
61 /**
62 * The loader class name.
63 */
64 protected String loaderClassName;
65
66 // ------------------------------------------------------------------------
67 // Constructor
68 // ------------------------------------------------------------------------
69 /**
70 * Standard constructor
71 *
72 * @param criteria_ A criteria reference
73 * @param active_ <code>true</code> if filter criteria is active else <code>false</code>
74 * @param positive_ <code>true</code> for positive filter else <code>false</code>
75 */
76 public FilterCriteria(Criteria criteria_, boolean active_, boolean positive_) {
77 setCriteria(criteria_);
78 setActive(active_);
79 setPositive(positive_);
80 }
81
82 /**
83 * Constructor
84 *
85 * @param criteria_ A criteria reference
86 * @param active_ <code>true</code> if filter criteria is active else <code>false</code>
87 * @param positive_ <code>true</code> for positive filter else <code>false</code>
88 * @param loaderClassName_ A loader class name
89 */
90 public FilterCriteria(Criteria criteria_, boolean active_, boolean positive_, String loaderClassName_) {
91 setCriteria(criteria_);
92 setActive(active_);
93 setPositive(positive_);
94 setLoaderClassName(loaderClassName_);
95 }
96
97 /**
98 * Copy Constructor
99 * @param other FilterCriteria
100 */
101 public FilterCriteria (FilterCriteria other) {
102 criteria = new Criteria(other.criteria);
103 this.active = other.active;
104 this.positive = other.positive;
105 this.loaderClassName = other.loaderClassName;
106 }
107
108 /**
109 * Default constructor
110 */
111 protected FilterCriteria() {
112 }
113
114 // ------------------------------------------------------------------------
115 // Methods
116 // ------------------------------------------------------------------------
117 /*
118 * (non-Javadoc)
119 * @see java.lang.Object#toString()
120 */
121 @Override
122 public String toString() {
123 StringBuffer sb = new StringBuffer(super.toString());
124 sb.append(":"); //$NON-NLS-1$
125 if (criteria != null) {
126 sb.append(" expression=");sb.append(criteria.getExpression()); //$NON-NLS-1$
127 sb.append(" active=");sb.append(active); //$NON-NLS-1$
128 sb.append(" positive=");sb.append(positive); //$NON-NLS-1$
129 } else {
130 sb.append("empty criteria"); //$NON-NLS-1$
131 }
132 return sb.toString();
133 }
134
135 /**
136 * Sets a criteria reference.
137 * @param criteria_ A criteria reference
138 */
139 public void setCriteria(Criteria criteria_) {
140 criteria = criteria_;
141 }
142
143 /**
144 * Returns the criteria reference.
145 *
146 * @return the criteria reference
147 */
148 public Criteria getCriteria() {
149 return criteria;
150 }
151
152 /**
153 * Sets the active flag.
154 *
155 * @param active_ A active value.
156 */
157 public void setActive(boolean active_) {
158 active = active_;
159 }
160
161 /**
162 * Returns whether filter criteria is active or not.
163 *
164 * @return whether filter criteria is active or not.
165 */
166 public boolean isActive() {
167 return active;
168 }
169
170 /**
171 * Sets filter is for positive filtering or not.
172 *
173 * @param positive_ The value to set.
174 */
175 public void setPositive(boolean positive_) {
176 positive = positive_;
177 }
178
179 /**
180 * Returns whether the filter si for positive filtering or not.
181 *
182 * @return Returns the positive.
183 */
184 public boolean isPositive() {
185 return positive;
186 }
187
188 /**
189 * Sets the loader class name for this filter.
190 *
191 * @param loaderClassName_ The loader class name to set
192 */
193 public void setLoaderClassName(String loaderClassName_) {
194 loaderClassName = loaderClassName_;
195 }
196
197 /**
198 * Returns the class loader name.
199 *
200 * @return the class loader name.
201 */
202 public String getLoaderClassName() {
203 return loaderClassName;
204 }
205
206 /**
207 * Finds a filter criteria within a list of criteria.
208 *
209 * @param what The filter to find
210 * @param list A list of filter criteria
211 * @return The found filter criteria or null
212 */
213 public static FilterCriteria find(FilterCriteria what, List<FilterCriteria> list) {
214 if (what != null && list != null) {
215 try {
216 for (Iterator<FilterCriteria> i = list.iterator(); i.hasNext();) {
217 FilterCriteria fc = (FilterCriteria) i.next();
218 if (what.compareTo(fc)) {
219 return fc;
220 }
221 }
222 } catch (Exception e) {
223 // Silence
224 }
225 }
226 return null;
227 }
228
229 /**
230 * Compares this filter criteria with a given criteria.
231 *
232 * @param to The filter criteria to compare.
233 * @return usual comparison result (< 0, 0, > 0)
234 */
235 public boolean compareTo(FilterCriteria to) {
236 if (isPositive() == to.isPositive() && getCriteria().compareTo(to.getCriteria())) {
237 if (getLoaderClassName() == null && to.getLoaderClassName() == null) {
238 return true;
239 }
240 if ((getLoaderClassName() != null && to.getLoaderClassName() != null) && getLoaderClassName().equals(to.getLoaderClassName())) {
241 return true;
242 }
243 }
244 return false;
245 }
246
247 /**
248 * Saves current criteria attributes in the dialog settings.
249 *
250 * @param settings The dialog settings
251 */
252 public void save(DialogSettings settings) {
253 settings.put(ACTIVE, isActive());
254 settings.put(POSITIVE, isPositive());
255 if (getLoaderClassName() != null) {
256 settings.put(LOADERCLASSNAME, getLoaderClassName());
257 } else {
258 settings.put(LOADERCLASSNAME, ""); //$NON-NLS-1$
259 }
260 if (criteria != null) {
261 criteria.save(settings);
262 }
263 }
264
265 /**
266 * Loads the criteria with values of the dialog settings.
267 *
268 * @param settings The dialog settings
269 */
270 public void load(DialogSettings settings) {
271 setActive(settings.getBoolean(ACTIVE));
272 setPositive(settings.getBoolean(POSITIVE));
273 String loaderClassName_ = settings.get(LOADERCLASSNAME);
274 setLoaderClassName(loaderClassName_ != null && loaderClassName_.length() > 0 ? loaderClassName_ : null);
275 if (criteria != null) {
276 criteria.load(settings);
277 }
278 }
279 }
This page took 0.03707 seconds and 5 git commands to generate.