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