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 $
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.widgets
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Iterator
;
17 import java
.util
.regex
.Pattern
;
18 import java
.util
.regex
.PatternSyntaxException
;
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
;
26 * This class describe the Find or Filter criteria selected by the user in the Find or Filter dialog box
30 public class Criteria
{
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;
50 * @param other Criteria to create new criteria
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
);
64 * Returns true if the AsyncMessageReturn is selected, false otherwise
66 * @return true if the AsyncMessageReturn is selected, false otherwise
68 public boolean isAsyncMessageReturnSelected() {
69 return asyncMessageReturnSelected
;
73 * Returns true if the AsyncMessage is selected, false otherwise
75 * @return true if the AsyncMessage is selected, false otherwise
77 public boolean isAsyncMessageSelected() {
78 return asyncMessageSelected
;
82 * Returns the text enter by the user
86 public String
getExpression() {
93 public Pattern
getPattern() {
100 public void setPattern(Pattern pattern
) {
101 this.pattern
= pattern
;
105 * Returns true if the LifeLine is selected, false otherwise
107 * @return true if the LifeLine is selected, false otherwise
109 public boolean isLifeLineSelected() {
110 return lifeLineSelected
;
114 * Returns true if the Stop is selected, false otherwise
116 * @return true if the Stop is selected, false otherwise
118 public boolean isStopSelected() {
123 * Returns true if the SyncMessageReturn is selected, false otherwise
125 * @return true if the SyncMessageReturn is selected, false otherwise
127 public boolean isSyncMessageReturnSelected() {
128 return syncMessageReturnSelected
;
132 * Returns true if the SyncMessage is selected, false otherwise
134 * @return true if the SyncMessage is selected, false otherwise
136 public boolean isSyncMessageSelected() {
137 return syncMessageSelected
;
141 * Set AsyncMessageReturn selection state
143 * @param b true if selected, false otherwise
145 public void setAsyncMessageReturnSelected(boolean b
) {
146 asyncMessageReturnSelected
= b
;
150 * Set AsyncMessage selection state
152 * @param b true if selected, false otherwise
154 public void setAsyncMessageSelected(boolean b
) {
155 asyncMessageSelected
= b
;
159 * Set the text enter by the user
161 * @param string the text
163 public void setExpression(String string
) {
165 if (expression
!= null) {
168 if (caseSenstiveSelected
) {
169 pattern
= Pattern
.compile(string
);
172 pattern
= Pattern
.compile(string
, Pattern
.CASE_INSENSITIVE
);
175 } catch (PatternSyntaxException e
) {
185 * Set Stop selection state
187 * @param b true if selected, false otherwise
189 public void setLifeLineSelected(boolean b
) {
190 lifeLineSelected
= b
;
194 * Set Stop selection state
196 * @param b true if selected, false otherwise
198 public void setStopSelected(boolean b
) {
203 * Set SyncMessageReturn selection state
205 * @param b true if selected, false otherwise
207 public void setSyncMessageReturnSelected(boolean b
) {
208 syncMessageReturnSelected
= b
;
212 * Set SyncMessage selection state
214 * @param b true if selected, false otherwise
216 public void setSyncMessageSelected(boolean b
) {
217 syncMessageSelected
= b
;
221 * Returns true if the case sensitive is selected, false otherwise
223 * @return true if the case sensitive is selected, false otherwise
225 public boolean isCaseSenstiveSelected() {
226 return caseSenstiveSelected
;
230 * Set case sensitive selection state
232 * @param b true if selected, false otherwise
234 public void setCaseSenstiveSelected(boolean b
) {
235 caseSenstiveSelected
= b
;
236 // Make sure that pattern is set
237 setExpression(expression
);
242 * @return usual comparison result (< 0, 0, > 0)
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());
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();
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$
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$
283 public String
getGraphNodeSummary(ISDFilterProvider provider
, String loaderClassName
) {
284 ArrayList
<String
> list
= new ArrayList
<String
>();
286 if (provider
!= null) {
287 if (isLifeLineSelected()) {
288 list
.add(provider
.getNodeName(ISDGraphNodeSupporter
.LIFELINE
, loaderClassName
));
290 if (isSyncMessageSelected()) {
291 list
.add(provider
.getNodeName(ISDGraphNodeSupporter
.SYNCMESSAGE
, loaderClassName
));
293 if (isSyncMessageReturnSelected()) {
294 list
.add(provider
.getNodeName(ISDGraphNodeSupporter
.SYNCMESSAGERETURN
, loaderClassName
));
296 if (isAsyncMessageSelected()) {
297 list
.add(provider
.getNodeName(ISDGraphNodeSupporter
.ASYNCMESSAGE
, loaderClassName
));
299 if (isAsyncMessageReturnSelected()) {
300 list
.add(provider
.getNodeName(ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
, loaderClassName
));
302 if (isStopSelected()) {
303 list
.add(provider
.getNodeName(ISDGraphNodeSupporter
.STOP
, loaderClassName
));
306 if (isLifeLineSelected()) {
307 list
.add(SDMessages
._28
);
309 if (isSyncMessageSelected()) {
310 list
.add(SDMessages
._30
);
312 if (isSyncMessageReturnSelected()) {
313 list
.add(SDMessages
._31
);
315 if (isAsyncMessageSelected()) {
316 list
.add(SDMessages
._32
);
318 if (isAsyncMessageReturnSelected()) {
319 list
.add(SDMessages
._33
);
321 if (isStopSelected()) {
322 list
.add(SDMessages
._29
);
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();
330 prefix
= " " + SDMessages
._34
+ " "; //$NON-NLS-1$ //$NON-NLS-2$
332 ret
+= "]"; //$NON-NLS-1$
337 * @param stringToMatch
338 * @return true if string matches expression
340 public boolean matches(String stringToMatch
) {
341 if (pattern
== null) {
344 return pattern
.matcher(stringToMatch
).matches();