1 /**********************************************************************
2 * Copyright (c) 2005, 2006 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
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
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
;
16 import java
.util
.ArrayList
;
17 import java
.util
.Iterator
;
18 import java
.util
.regex
.Pattern
;
19 import java
.util
.regex
.PatternSyntaxException
;
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
;
27 * This class describes the find or filter criteria selected by the user in the find or filter dialog box
31 * @author Bernd Hufmann
33 public class Criteria
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
39 * Flag whether lifeline is selected or not.
41 protected boolean fLifeLineSelected
= false;
43 * Flag whether synchronous message is selected or not.
45 protected boolean fSyncMessageSelected
= false;
47 * Flag whether synchronous message return is selected or not.
49 protected boolean fSyncMessageReturnSelected
= false;
51 * Flag whether asynchronous message is selected or not.
53 protected boolean fAsyncMessageSelected
= false;
55 * Flag whether asynchronous message return is selected or not.
57 protected boolean fAsyncMessageReturnSelected
= false;
59 * Flag whether case sensitive find is required or not.
61 protected boolean fCaseSenstiveSelected
= false;
63 * Flag whether stop graph node is selected or not.
65 protected boolean fStopSelected
= false;
67 * The find expression.
69 protected String fExpression
= null;
71 * The find pattern as regular expression.
73 protected Pattern pattern
= null;
75 // ------------------------------------------------------------------------
77 // ------------------------------------------------------------------------
88 * @param other Criteria to create new criteria
90 public Criteria (Criteria other
) {
91 this.fLifeLineSelected
= other
.fLifeLineSelected
;
92 this.fSyncMessageSelected
= other
.fSyncMessageSelected
;
93 this.fSyncMessageReturnSelected
= other
.fSyncMessageReturnSelected
;
94 this.fAsyncMessageSelected
= other
.fAsyncMessageSelected
;
95 this.fAsyncMessageReturnSelected
= other
.fAsyncMessageReturnSelected
;
96 this.fCaseSenstiveSelected
= other
.fCaseSenstiveSelected
;
97 this.fStopSelected
= other
.fStopSelected
;
98 fExpression
= other
.fExpression
;
102 // ------------------------------------------------------------------------
104 // ------------------------------------------------------------------------
107 * Returns true if the AsyncMessageReturn is selected, false otherwise.
109 * @return true if the AsyncMessageReturn is selected, false otherwise
111 public boolean isAsyncMessageReturnSelected() {
112 return fAsyncMessageReturnSelected
;
116 * Returns true if the AsyncMessage is selected, false otherwise.
118 * @return true if the AsyncMessage is selected, false otherwise
120 public boolean isAsyncMessageSelected() {
121 return fAsyncMessageSelected
;
125 * Returns the text enter by the user.
127 * @return the expression text
129 public String
getExpression() {
134 * Returns the regular expression pattern.
136 * @return the regular expression pattern
138 public Pattern
getPattern() {
143 * Sets the regular expression pattern.
145 * @param the pattern to set
147 public void setPattern(Pattern pattern
) {
148 this.pattern
= pattern
;
152 * Returns true if the LifeLine is selected, false otherwise.
154 * @return true if the LifeLine is selected, false otherwise
156 public boolean isLifeLineSelected() {
157 return fLifeLineSelected
;
161 * Returns true if the Stop is selected, false otherwise.
163 * @return true if the Stop is selected, false otherwise
165 public boolean isStopSelected() {
166 return fStopSelected
;
170 * Returns true if the SyncMessageReturn is selected, false otherwise.
172 * @return true if the SyncMessageReturn is selected, false otherwise
174 public boolean isSyncMessageReturnSelected() {
175 return fSyncMessageReturnSelected
;
179 * Returns true if the SyncMessage is selected, false otherwise.
181 * @return true if the SyncMessage is selected, false otherwise
183 public boolean isSyncMessageSelected() {
184 return fSyncMessageSelected
;
188 * Sets the AsyncMessageReturn selection state.
190 * @param b true if selected, false otherwise
192 public void setAsyncMessageReturnSelected(boolean b
) {
193 fAsyncMessageReturnSelected
= b
;
197 * Sets the AsyncMessage selection state.
199 * @param b true if selected, false otherwise
201 public void setAsyncMessageSelected(boolean b
) {
202 fAsyncMessageSelected
= b
;
206 * Sets the text entered by the user and compiles the regular expression.
208 * @param string the text
210 public void setExpression(String string
) {
211 fExpression
= string
;
216 * Sets the Stop selection state.
218 * @param b true if selected, false otherwise
220 public void setLifeLineSelected(boolean b
) {
221 fLifeLineSelected
= b
;
225 * Set Stop selection state.
227 * @param b true if selected, false otherwise
229 public void setStopSelected(boolean b
) {
234 * Sets the SyncMessageReturn selection state.
236 * @param b true if selected, false otherwise
238 public void setSyncMessageReturnSelected(boolean b
) {
239 fSyncMessageReturnSelected
= b
;
243 * Sets the SyncMessage selection state.
245 * @param b true if selected, false otherwise
247 public void setSyncMessageSelected(boolean b
) {
248 fSyncMessageSelected
= b
;
252 * Returns true if the case sensitive is selected, false otherwise.
254 * @return true if the case sensitive is selected, false otherwise
256 public boolean isCaseSenstiveSelected() {
257 return fCaseSenstiveSelected
;
261 * Set case sensitive selection state.
263 * @param b true if selected, false otherwise
265 public void setCaseSenstiveSelected(boolean b
) {
266 fCaseSenstiveSelected
= b
;
267 // Make sure that pattern is set
268 setExpression(fExpression
);
272 * Compares this criteria with a given criteria.
274 * @param to The criteria to compare
275 * @return usual comparison result (< 0, 0, > 0)
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());
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();
289 * Saves current criteria attributes in the dialog settings.
291 * @param settings The dialog settings
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$
305 * Loads the criteria with values of the dialog settings.
307 * @param settings The dialog settings
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$
321 * Gets the summary of supported graph nodes.
323 * @param provider A filter provider
324 * @param loaderClassName A class loader
325 * @return graph node summary
327 public String
getGraphNodeSummary(ISDFilterProvider provider
, String loaderClassName
) {
328 ArrayList
<String
> list
= new ArrayList
<String
>();
330 if (provider
!= null) {
331 if (isLifeLineSelected()) {
332 list
.add(provider
.getNodeName(ISDGraphNodeSupporter
.LIFELINE
, loaderClassName
));
334 if (isSyncMessageSelected()) {
335 list
.add(provider
.getNodeName(ISDGraphNodeSupporter
.SYNCMESSAGE
, loaderClassName
));
337 if (isSyncMessageReturnSelected()) {
338 list
.add(provider
.getNodeName(ISDGraphNodeSupporter
.SYNCMESSAGERETURN
, loaderClassName
));
340 if (isAsyncMessageSelected()) {
341 list
.add(provider
.getNodeName(ISDGraphNodeSupporter
.ASYNCMESSAGE
, loaderClassName
));
343 if (isAsyncMessageReturnSelected()) {
344 list
.add(provider
.getNodeName(ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
, loaderClassName
));
346 if (isStopSelected()) {
347 list
.add(provider
.getNodeName(ISDGraphNodeSupporter
.STOP
, loaderClassName
));
350 if (isLifeLineSelected()) {
351 list
.add(SDMessages
._28
);
353 if (isSyncMessageSelected()) {
354 list
.add(SDMessages
._30
);
356 if (isSyncMessageReturnSelected()) {
357 list
.add(SDMessages
._31
);
359 if (isAsyncMessageSelected()) {
360 list
.add(SDMessages
._32
);
362 if (isAsyncMessageReturnSelected()) {
363 list
.add(SDMessages
._33
);
365 if (isStopSelected()) {
366 list
.add(SDMessages
._29
);
369 StringBuffer ret
= new StringBuffer();
370 String prefix
= "["; //$NON-NLS-1$
371 for (Iterator
<String
> i
= list
.iterator(); i
.hasNext();) {
372 String s
= (String
) i
.next();
375 prefix
= " " + SDMessages
._34
+ " "; //$NON-NLS-1$ //$NON-NLS-2$
377 ret
.append("]"); //$NON-NLS-1$
378 return ret
.toString();
382 * Matches given string using compiled pattern based on user expression.
384 * @param stringToMatch A string to match
385 * @return true if string matches expression
387 public boolean matches(String stringToMatch
) {
388 if (pattern
== null) {
391 return pattern
.matcher(stringToMatch
).matches();
395 * Updates the regular expression pattern based on the expression.
397 private void updatePattern() {
398 if (fExpression
!= null) {
400 if (fCaseSenstiveSelected
) {
401 pattern
= Pattern
.compile(fExpression
);
404 pattern
= Pattern
.compile(fExpression
, Pattern
.CASE_INSENSITIVE
);
406 } catch (PatternSyntaxException e
) {