Fix javadoc warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / handlers / widgets / Criteria.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2006, 2011 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 * $Id: Criteria.java,v 1.2 2006/09/20 20:56:27 ewchan Exp $
8 *
9 * Contributors:
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
13 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.widgets;
14
15 import java.util.ArrayList;
16 import java.util.Iterator;
17 import java.util.regex.Pattern;
18 import java.util.regex.PatternSyntaxException;
19
20 import org.eclipse.jface.dialogs.DialogSettings;
21 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider;
22 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter;
23 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDMessages;
24
25 /**
26 * This class describe the Find or Filter criteria selected by the user in the Find or Filter dialog box
27 *
28 * @author sveyrier
29 */
30 public class Criteria {
31
32 protected boolean lifeLineSelected = false;
33 protected boolean syncMessageSelected = false;
34 protected boolean syncMessageReturnSelected = false;
35 protected boolean asyncMessageSelected = false;
36 protected boolean asyncMessageReturnSelected = false;
37 private boolean caseSenstiveSelected = false;
38 protected boolean stopSelected = false;
39 private String expression = null;
40 private Pattern pattern = null;
41
42 /**
43 * Default constructor
44 */
45 public Criteria () {
46 }
47
48 /**
49 * Copy constructor
50 * @param other Criteria to create new criteria
51 */
52 public Criteria (Criteria other) {
53 this.lifeLineSelected = other.lifeLineSelected;
54 this.syncMessageSelected = other.syncMessageSelected;
55 this.syncMessageReturnSelected = other.syncMessageReturnSelected;
56 this.asyncMessageSelected = other.asyncMessageSelected;
57 this.asyncMessageReturnSelected = other.asyncMessageReturnSelected;
58 this.caseSenstiveSelected = other.caseSenstiveSelected;
59 this.stopSelected = other.stopSelected;
60 setExpression(other.expression);
61 }
62
63 /**
64 * Returns true if the AsyncMessageReturn is selected, false otherwise
65 *
66 * @return true if the AsyncMessageReturn is selected, false otherwise
67 */
68 public boolean isAsyncMessageReturnSelected() {
69 return asyncMessageReturnSelected;
70 }
71
72 /**
73 * Returns true if the AsyncMessage is selected, false otherwise
74 *
75 * @return true if the AsyncMessage is selected, false otherwise
76 */
77 public boolean isAsyncMessageSelected() {
78 return asyncMessageSelected;
79 }
80
81 /**
82 * Returns the text enter by the user
83 *
84 * @return the text
85 */
86 public String getExpression() {
87 return expression;
88 }
89
90 /**
91 * @return pattern
92 */
93 public Pattern getPattern() {
94 return pattern;
95 }
96
97 /**
98 * @param pattern
99 */
100 public void setPattern(Pattern pattern) {
101 this.pattern = pattern;
102 }
103
104 /**
105 * Returns true if the LifeLine is selected, false otherwise
106 *
107 * @return true if the LifeLine is selected, false otherwise
108 */
109 public boolean isLifeLineSelected() {
110 return lifeLineSelected;
111 }
112
113 /**
114 * Returns true if the Stop is selected, false otherwise
115 *
116 * @return true if the Stop is selected, false otherwise
117 */
118 public boolean isStopSelected() {
119 return stopSelected;
120 }
121
122 /**
123 * Returns true if the SyncMessageReturn is selected, false otherwise
124 *
125 * @return true if the SyncMessageReturn is selected, false otherwise
126 */
127 public boolean isSyncMessageReturnSelected() {
128 return syncMessageReturnSelected;
129 }
130
131 /**
132 * Returns true if the SyncMessage is selected, false otherwise
133 *
134 * @return true if the SyncMessage is selected, false otherwise
135 */
136 public boolean isSyncMessageSelected() {
137 return syncMessageSelected;
138 }
139
140 /**
141 * Set AsyncMessageReturn selection state
142 *
143 * @param b true if selected, false otherwise
144 */
145 public void setAsyncMessageReturnSelected(boolean b) {
146 asyncMessageReturnSelected = b;
147 }
148
149 /**
150 * Set AsyncMessage selection state
151 *
152 * @param b true if selected, false otherwise
153 */
154 public void setAsyncMessageSelected(boolean b) {
155 asyncMessageSelected = b;
156 }
157
158 /**
159 * Set the text enter by the user
160 *
161 * @param string the text
162 */
163 public void setExpression(String string) {
164 expression = string;
165 if (expression != null) {
166
167 try {
168 if (caseSenstiveSelected) {
169 pattern = Pattern.compile(string);
170 }
171 else {
172 pattern = Pattern.compile(string, Pattern.CASE_INSENSITIVE);
173 }
174
175 } catch (PatternSyntaxException e) {
176 pattern = null;
177 }
178 }
179 else {
180 pattern = null;
181 }
182 }
183
184 /**
185 * Set Stop selection state
186 *
187 * @param b true if selected, false otherwise
188 */
189 public void setLifeLineSelected(boolean b) {
190 lifeLineSelected = b;
191 }
192
193 /**
194 * Set Stop selection state
195 *
196 * @param b true if selected, false otherwise
197 */
198 public void setStopSelected(boolean b) {
199 stopSelected = b;
200 }
201
202 /**
203 * Set SyncMessageReturn selection state
204 *
205 * @param b true if selected, false otherwise
206 */
207 public void setSyncMessageReturnSelected(boolean b) {
208 syncMessageReturnSelected = b;
209 }
210
211 /**
212 * Set SyncMessage selection state
213 *
214 * @param b true if selected, false otherwise
215 */
216 public void setSyncMessageSelected(boolean b) {
217 syncMessageSelected = b;
218 }
219
220 /**
221 * Returns true if the case sensitive is selected, false otherwise
222 *
223 * @return true if the case sensitive is selected, false otherwise
224 */
225 public boolean isCaseSenstiveSelected() {
226 return caseSenstiveSelected;
227 }
228
229 /**
230 * Set case sensitive selection state
231 *
232 * @param b true if selected, false otherwise
233 */
234 public void setCaseSenstiveSelected(boolean b) {
235 caseSenstiveSelected = b;
236 // Make sure that pattern is set
237 setExpression(expression);
238 }
239
240 /**
241 * @param to
242 * @return usual comparison result (< 0, 0, > 0)
243 */
244 public boolean compareTo(Criteria to) {
245 boolean retVal = true;
246 if (getExpression() != null) {
247 retVal = getExpression().equals(to.getExpression());
248 } else if (to.getExpression() != null) {
249 retVal = to.getExpression().equals(getExpression());
250 }
251 return retVal && isCaseSenstiveSelected() == to.isCaseSenstiveSelected() && isAsyncMessageReturnSelected() == to.isAsyncMessageReturnSelected() && isAsyncMessageSelected() == to.isAsyncMessageSelected()
252 && isLifeLineSelected() == to.isLifeLineSelected() && isStopSelected() == to.isStopSelected() && isSyncMessageReturnSelected() == to.isSyncMessageReturnSelected() && isSyncMessageSelected() == to.isSyncMessageSelected();
253 }
254
255 /**
256 * @param settings
257 */
258 public void save(DialogSettings settings) {
259 settings.put("expression", getExpression()); //$NON-NLS-1$
260 settings.put("isCaseSenstiveSelected", isCaseSenstiveSelected()); //$NON-NLS-1$
261 settings.put("isAsyncMessageReturnSelected", isAsyncMessageReturnSelected()); //$NON-NLS-1$
262 settings.put("isAsyncMessageSelected", isAsyncMessageSelected()); //$NON-NLS-1$
263 settings.put("isLifeLineSelected", isLifeLineSelected()); //$NON-NLS-1$
264 settings.put("isStopSelected", isStopSelected()); //$NON-NLS-1$
265 settings.put("isSyncMessageReturnSelected", isSyncMessageReturnSelected()); //$NON-NLS-1$
266 settings.put("isSyncMessageSelected", isSyncMessageSelected()); //$NON-NLS-1$
267 }
268
269 /**
270 * @param settings
271 */
272 public void load(DialogSettings settings) {
273 setExpression(settings.get("expression")); //$NON-NLS-1$
274 setCaseSenstiveSelected(settings.getBoolean("isCaseSenstiveSelected")); //$NON-NLS-1$
275 setAsyncMessageReturnSelected(settings.getBoolean("isAsyncMessageReturnSelected")); //$NON-NLS-1$
276 setAsyncMessageSelected(settings.getBoolean("isAsyncMessageSelected")); //$NON-NLS-1$
277 setLifeLineSelected(settings.getBoolean("isLifeLineSelected")); //$NON-NLS-1$
278 setStopSelected(settings.getBoolean("isStopSelected")); //$NON-NLS-1$
279 setSyncMessageReturnSelected(settings.getBoolean("isSyncMessageReturnSelected")); //$NON-NLS-1$
280 setSyncMessageSelected(settings.getBoolean("isSyncMessageSelected")); //$NON-NLS-1$
281 }
282
283 public String getGraphNodeSummary(ISDFilterProvider provider, String loaderClassName) {
284 ArrayList<String> list = new ArrayList<String>();
285
286 if (provider != null) {
287 if (isLifeLineSelected()) {
288 list.add(provider.getNodeName(ISDGraphNodeSupporter.LIFELINE, loaderClassName));
289 }
290 if (isSyncMessageSelected()) {
291 list.add(provider.getNodeName(ISDGraphNodeSupporter.SYNCMESSAGE, loaderClassName));
292 }
293 if (isSyncMessageReturnSelected()) {
294 list.add(provider.getNodeName(ISDGraphNodeSupporter.SYNCMESSAGERETURN, loaderClassName));
295 }
296 if (isAsyncMessageSelected()) {
297 list.add(provider.getNodeName(ISDGraphNodeSupporter.ASYNCMESSAGE, loaderClassName));
298 }
299 if (isAsyncMessageReturnSelected()) {
300 list.add(provider.getNodeName(ISDGraphNodeSupporter.ASYNCMESSAGERETURN, loaderClassName));
301 }
302 if (isStopSelected()) {
303 list.add(provider.getNodeName(ISDGraphNodeSupporter.STOP, loaderClassName));
304 }
305 } else {
306 if (isLifeLineSelected()) {
307 list.add(SDMessages._28);
308 }
309 if (isSyncMessageSelected()) {
310 list.add(SDMessages._30);
311 }
312 if (isSyncMessageReturnSelected()) {
313 list.add(SDMessages._31);
314 }
315 if (isAsyncMessageSelected()) {
316 list.add(SDMessages._32);
317 }
318 if (isAsyncMessageReturnSelected()) {
319 list.add(SDMessages._33);
320 }
321 if (isStopSelected()) {
322 list.add(SDMessages._29);
323 }
324 }
325
326 String ret = "", prefix = "["; //$NON-NLS-1$ //$NON-NLS-2$
327 for (Iterator<String> i = list.iterator(); i.hasNext();) {
328 String s = (String) i.next();
329 ret += prefix + s;
330 prefix = " " + SDMessages._34 + " "; //$NON-NLS-1$ //$NON-NLS-2$
331 }
332 ret += "]"; //$NON-NLS-1$
333 return ret;
334 }
335
336 /**
337 * @param stringToMatch
338 * @return true if string matches expression
339 */
340 public boolean matches(String stringToMatch) {
341 if (pattern == null) {
342 return false;
343 }
344 return pattern.matcher(stringToMatch).matches();
345 }
346 }
This page took 0.03995 seconds and 5 git commands to generate.