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 / Criteria.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2006 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.ArrayList;
17 import java.util.Iterator;
18 import java.util.regex.Pattern;
19 import java.util.regex.PatternSyntaxException;
20
21 import org.eclipse.jface.dialogs.DialogSettings;
22 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider;
23 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter;
24 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDMessages;
25
26 /**
27 * This class describes the find or filter criteria selected by the user in the find or filter dialog box
28 *
29 * @version 1.0
30 * @author sveyrier
31 * @author Bernd Hufmann
32 */
33 public class Criteria {
34
35 // ------------------------------------------------------------------------
36 // Attributes
37 // ------------------------------------------------------------------------
38 /**
39 * Flag whether lifeline is selected or not.
40 */
41 protected boolean lifeLineSelected = false;
42 /**
43 * Flag whether synchronous message is selected or not.
44 */
45 protected boolean syncMessageSelected = false;
46 /**
47 * Flag whether synchronous message return is selected or not.
48 */
49 protected boolean syncMessageReturnSelected = false;
50 /**
51 * Flag whether asynchronous message is selected or not.
52 */
53 protected boolean asyncMessageSelected = false;
54 /**
55 * Flag whether asynchronous message return is selected or not.
56 */
57 protected boolean asyncMessageReturnSelected = false;
58 /**
59 * Flag whether case sensitive find is required or not.
60 */
61 protected boolean caseSenstiveSelected = false;
62 /**
63 * Flag whether stop graph node is selected or not.
64 */
65 protected boolean stopSelected = false;
66 /**
67 * The find expression.
68 */
69 protected String expression = null;
70 /**
71 * The find pattern as regular expression.
72 */
73 protected Pattern pattern = null;
74
75 // ------------------------------------------------------------------------
76 // Constructors
77 // ------------------------------------------------------------------------
78
79 /**
80 * Default constructor
81 */
82 public Criteria () {
83 }
84
85 /**
86 * Copy constructor
87 *
88 * @param other Criteria to create new criteria
89 */
90 public Criteria (Criteria other) {
91 this.lifeLineSelected = other.lifeLineSelected;
92 this.syncMessageSelected = other.syncMessageSelected;
93 this.syncMessageReturnSelected = other.syncMessageReturnSelected;
94 this.asyncMessageSelected = other.asyncMessageSelected;
95 this.asyncMessageReturnSelected = other.asyncMessageReturnSelected;
96 this.caseSenstiveSelected = other.caseSenstiveSelected;
97 this.stopSelected = other.stopSelected;
98 setExpression(other.expression);
99 }
100
101 // ------------------------------------------------------------------------
102 // Methods
103 // ------------------------------------------------------------------------
104
105 /**
106 * Returns true if the AsyncMessageReturn is selected, false otherwise.
107 *
108 * @return true if the AsyncMessageReturn is selected, false otherwise
109 */
110 public boolean isAsyncMessageReturnSelected() {
111 return asyncMessageReturnSelected;
112 }
113
114 /**
115 * Returns true if the AsyncMessage is selected, false otherwise.
116 *
117 * @return true if the AsyncMessage is selected, false otherwise
118 */
119 public boolean isAsyncMessageSelected() {
120 return asyncMessageSelected;
121 }
122
123 /**
124 * Returns the text enter by the user.
125 *
126 * @return the expression text
127 */
128 public String getExpression() {
129 return expression;
130 }
131
132 /**
133 * Returns the regular expression pattern.
134 *
135 * @return the regular expression pattern
136 */
137 public Pattern getPattern() {
138 return pattern;
139 }
140
141 /**
142 * Sets the regular expression pattern.
143 *
144 * @param the pattern to set
145 */
146 public void setPattern(Pattern pattern) {
147 this.pattern = pattern;
148 }
149
150 /**
151 * Returns true if the LifeLine is selected, false otherwise.
152 *
153 * @return true if the LifeLine is selected, false otherwise
154 */
155 public boolean isLifeLineSelected() {
156 return lifeLineSelected;
157 }
158
159 /**
160 * Returns true if the Stop is selected, false otherwise.
161 *
162 * @return true if the Stop is selected, false otherwise
163 */
164 public boolean isStopSelected() {
165 return stopSelected;
166 }
167
168 /**
169 * Returns true if the SyncMessageReturn is selected, false otherwise.
170 *
171 * @return true if the SyncMessageReturn is selected, false otherwise
172 */
173 public boolean isSyncMessageReturnSelected() {
174 return syncMessageReturnSelected;
175 }
176
177 /**
178 * Returns true if the SyncMessage is selected, false otherwise.
179 *
180 * @return true if the SyncMessage is selected, false otherwise
181 */
182 public boolean isSyncMessageSelected() {
183 return syncMessageSelected;
184 }
185
186 /**
187 * Sets the AsyncMessageReturn selection state.
188 *
189 * @param b true if selected, false otherwise
190 */
191 public void setAsyncMessageReturnSelected(boolean b) {
192 asyncMessageReturnSelected = b;
193 }
194
195 /**
196 * Sets the AsyncMessage selection state.
197 *
198 * @param b true if selected, false otherwise
199 */
200 public void setAsyncMessageSelected(boolean b) {
201 asyncMessageSelected = b;
202 }
203
204 /**
205 * Sets the text entered by the user and compiles the regular expression.
206 *
207 * @param string the text
208 */
209 public void setExpression(String string) {
210 expression = string;
211 if (expression != null) {
212 try {
213 if (caseSenstiveSelected) {
214 pattern = Pattern.compile(string);
215 }
216 else {
217 pattern = Pattern.compile(string, Pattern.CASE_INSENSITIVE);
218 }
219 } catch (PatternSyntaxException e) {
220 pattern = null;
221 }
222 }
223 else {
224 pattern = null;
225 }
226 }
227
228 /**
229 * Sets the Stop selection state.
230 *
231 * @param b true if selected, false otherwise
232 */
233 public void setLifeLineSelected(boolean b) {
234 lifeLineSelected = b;
235 }
236
237 /**
238 * Set Stop selection state.
239 *
240 * @param b true if selected, false otherwise
241 */
242 public void setStopSelected(boolean b) {
243 stopSelected = b;
244 }
245
246 /**
247 * Sets the SyncMessageReturn selection state.
248 *
249 * @param b true if selected, false otherwise
250 */
251 public void setSyncMessageReturnSelected(boolean b) {
252 syncMessageReturnSelected = b;
253 }
254
255 /**
256 * Sets the SyncMessage selection state.
257 *
258 * @param b true if selected, false otherwise
259 */
260 public void setSyncMessageSelected(boolean b) {
261 syncMessageSelected = b;
262 }
263
264 /**
265 * Returns true if the case sensitive is selected, false otherwise.
266 *
267 * @return true if the case sensitive is selected, false otherwise
268 */
269 public boolean isCaseSenstiveSelected() {
270 return caseSenstiveSelected;
271 }
272
273 /**
274 * Set case sensitive selection state.
275 *
276 * @param b true if selected, false otherwise
277 */
278 public void setCaseSenstiveSelected(boolean b) {
279 caseSenstiveSelected = b;
280 // Make sure that pattern is set
281 setExpression(expression);
282 }
283
284 /**
285 * Compares this criteria with a given criteria.
286 *
287 * @param to The criteria to compare
288 * @return usual comparison result (< 0, 0, > 0)
289 */
290 public boolean compareTo(Criteria to) {
291 boolean retVal = true;
292 if (getExpression() != null) {
293 retVal = getExpression().equals(to.getExpression());
294 } else if (to.getExpression() != null) {
295 retVal = to.getExpression().equals(getExpression());
296 }
297 return retVal && isCaseSenstiveSelected() == to.isCaseSenstiveSelected() && isAsyncMessageReturnSelected() == to.isAsyncMessageReturnSelected() && isAsyncMessageSelected() == to.isAsyncMessageSelected()
298 && isLifeLineSelected() == to.isLifeLineSelected() && isStopSelected() == to.isStopSelected() && isSyncMessageReturnSelected() == to.isSyncMessageReturnSelected() && isSyncMessageSelected() == to.isSyncMessageSelected();
299 }
300
301 /**
302 * Saves current criteria attributes in the dialog settings.
303 *
304 * @param settings The dialog settings
305 */
306 public void save(DialogSettings settings) {
307 settings.put("expression", getExpression()); //$NON-NLS-1$
308 settings.put("isCaseSenstiveSelected", isCaseSenstiveSelected()); //$NON-NLS-1$
309 settings.put("isAsyncMessageReturnSelected", isAsyncMessageReturnSelected()); //$NON-NLS-1$
310 settings.put("isAsyncMessageSelected", isAsyncMessageSelected()); //$NON-NLS-1$
311 settings.put("isLifeLineSelected", isLifeLineSelected()); //$NON-NLS-1$
312 settings.put("isStopSelected", isStopSelected()); //$NON-NLS-1$
313 settings.put("isSyncMessageReturnSelected", isSyncMessageReturnSelected()); //$NON-NLS-1$
314 settings.put("isSyncMessageSelected", isSyncMessageSelected()); //$NON-NLS-1$
315 }
316
317 /**
318 * Loads the criteria with values of the dialog settings.
319 *
320 * @param settings The dialog settings
321 */
322 public void load(DialogSettings settings) {
323 setExpression(settings.get("expression")); //$NON-NLS-1$
324 setCaseSenstiveSelected(settings.getBoolean("isCaseSenstiveSelected")); //$NON-NLS-1$
325 setAsyncMessageReturnSelected(settings.getBoolean("isAsyncMessageReturnSelected")); //$NON-NLS-1$
326 setAsyncMessageSelected(settings.getBoolean("isAsyncMessageSelected")); //$NON-NLS-1$
327 setLifeLineSelected(settings.getBoolean("isLifeLineSelected")); //$NON-NLS-1$
328 setStopSelected(settings.getBoolean("isStopSelected")); //$NON-NLS-1$
329 setSyncMessageReturnSelected(settings.getBoolean("isSyncMessageReturnSelected")); //$NON-NLS-1$
330 setSyncMessageSelected(settings.getBoolean("isSyncMessageSelected")); //$NON-NLS-1$
331 }
332
333 /**
334 * Gets the summary of supported graph nodes.
335 *
336 * @param provider A filter provider
337 * @param loaderClassName A class loader
338 * @return graph node summary
339 */
340 public String getGraphNodeSummary(ISDFilterProvider provider, String loaderClassName) {
341 ArrayList<String> list = new ArrayList<String>();
342
343 if (provider != null) {
344 if (isLifeLineSelected()) {
345 list.add(provider.getNodeName(ISDGraphNodeSupporter.LIFELINE, loaderClassName));
346 }
347 if (isSyncMessageSelected()) {
348 list.add(provider.getNodeName(ISDGraphNodeSupporter.SYNCMESSAGE, loaderClassName));
349 }
350 if (isSyncMessageReturnSelected()) {
351 list.add(provider.getNodeName(ISDGraphNodeSupporter.SYNCMESSAGERETURN, loaderClassName));
352 }
353 if (isAsyncMessageSelected()) {
354 list.add(provider.getNodeName(ISDGraphNodeSupporter.ASYNCMESSAGE, loaderClassName));
355 }
356 if (isAsyncMessageReturnSelected()) {
357 list.add(provider.getNodeName(ISDGraphNodeSupporter.ASYNCMESSAGERETURN, loaderClassName));
358 }
359 if (isStopSelected()) {
360 list.add(provider.getNodeName(ISDGraphNodeSupporter.STOP, loaderClassName));
361 }
362 } else {
363 if (isLifeLineSelected()) {
364 list.add(SDMessages._28);
365 }
366 if (isSyncMessageSelected()) {
367 list.add(SDMessages._30);
368 }
369 if (isSyncMessageReturnSelected()) {
370 list.add(SDMessages._31);
371 }
372 if (isAsyncMessageSelected()) {
373 list.add(SDMessages._32);
374 }
375 if (isAsyncMessageReturnSelected()) {
376 list.add(SDMessages._33);
377 }
378 if (isStopSelected()) {
379 list.add(SDMessages._29);
380 }
381 }
382
383 String ret = "", prefix = "["; //$NON-NLS-1$ //$NON-NLS-2$
384 for (Iterator<String> i = list.iterator(); i.hasNext();) {
385 String s = (String) i.next();
386 ret += prefix + s;
387 prefix = " " + SDMessages._34 + " "; //$NON-NLS-1$ //$NON-NLS-2$
388 }
389 ret += "]"; //$NON-NLS-1$
390 return ret;
391 }
392
393 /**
394 * Matches given string using compiled pattern based on user expression.
395 *
396 * @param stringToMatch A string to match
397 * @return true if string matches expression
398 */
399 public boolean matches(String stringToMatch) {
400 if (pattern == null) {
401 return false;
402 }
403 return pattern.matcher(stringToMatch).matches();
404 }
405 }
This page took 0.040055 seconds and 6 git commands to generate.