0bbb26c86be35b572f23349ad475fdb99a73e49a
1 /**********************************************************************
2 * Copyright (c) 2005, 2008 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
.Iterator
;
17 import java
.util
.List
;
19 import org
.eclipse
.jface
.dialogs
.DialogSettings
;
22 * A filter criteria is a criteria that can be activated or not, positive or not.
28 public class FilterCriteria
{
30 // ------------------------------------------------------------------------
32 // ------------------------------------------------------------------------
34 * The filter state value for 'active'.
36 protected static final String ACTIVE
= "active"; //$NON-NLS-1$
38 * The property value for positive filter.
40 protected static final String POSITIVE
= "positive"; //$NON-NLS-1$
42 * The filter loader class name property.
44 protected static final String LOADERCLASSNAME
= "loaderClassName"; //$NON-NLS-1$
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
50 * The criteria reference.
52 protected Criteria fCriteria
;
54 * Flag whether this criteria is active or not
56 protected boolean fIsActive
;
58 * Flag whether this criteria is for positive filter or not
60 protected boolean fIsPositive
;
62 * The loader class name.
64 protected String fLoaderClassName
;
66 // ------------------------------------------------------------------------
68 // ------------------------------------------------------------------------
70 * Standard constructor
72 * @param criteria A criteria reference
73 * @param isActive <code>true</code> if filter criteria is active else <code>false</code>
74 * @param isPositive <code>true</code> for positive filter else <code>false</code>
76 public FilterCriteria(Criteria criteria
, boolean isActive
, boolean isPositive
) {
77 this(criteria
, isActive
, isPositive
, null);
83 * @param criteria A criteria reference
84 * @param isActive <code>true</code> if filter criteria is active else <code>false</code>
85 * @param isPositive <code>true</code> for positive filter else <code>false</code>
86 * @param loaderClassName A loader class name
88 public FilterCriteria(Criteria criteria
, boolean isActive
, boolean isPositive
, String loaderClassName
) {
91 fIsPositive
= isPositive
;
92 fLoaderClassName
= loaderClassName
;
97 * @param other FilterCriteria
99 public FilterCriteria (FilterCriteria other
) {
100 fCriteria
= new Criteria(other
.fCriteria
);
101 fIsActive
= other
.fIsActive
;
102 fIsPositive
= other
.fIsPositive
;
103 fLoaderClassName
= other
.fLoaderClassName
;
107 * Default constructor
109 protected FilterCriteria() {
112 // ------------------------------------------------------------------------
114 // ------------------------------------------------------------------------
117 * @see java.lang.Object#toString()
120 public String
toString() {
121 StringBuffer sb
= new StringBuffer(super.toString());
123 if (fCriteria
!= null) {
124 sb
.append(" expression=");sb
.append(fCriteria
.getExpression()); //$NON-NLS-1$
125 sb
.append(" active=");sb
.append(fIsActive
); //$NON-NLS-1$
126 sb
.append(" positive=");sb
.append(fIsPositive
); //$NON-NLS-1$
128 sb
.append("empty criteria"); //$NON-NLS-1$
130 return sb
.toString();
134 * Sets a criteria reference.
135 * @param criteria A criteria reference
137 public void setCriteria(Criteria criteria
) {
138 fCriteria
= criteria
;
142 * Returns the criteria reference.
144 * @return the criteria reference
146 public Criteria
getCriteria() {
151 * Sets the active flag.
153 * @param isActive A active value.
155 public void setActive(boolean isActive
) {
156 fIsActive
= isActive
;
160 * Returns whether filter criteria is active or not.
162 * @return whether filter criteria is active or not.
164 public boolean isActive() {
169 * Sets filter is for positive filtering or not.
171 * @param isPositive The value to set.
173 public void setPositive(boolean isPositive
) {
174 fIsPositive
= isPositive
;
178 * Returns whether the filter si for positive filtering or not.
180 * @return Returns the positive.
182 public boolean isPositive() {
187 * Sets the loader class name for this filter.
189 * @param loaderClassName The loader class name to set
191 public void setLoaderClassName(String loaderClassName
) {
192 fLoaderClassName
= loaderClassName
;
196 * Returns the class loader name.
198 * @return the class loader name.
200 public String
getLoaderClassName() {
201 return fLoaderClassName
;
205 * Finds a filter criteria within a list of criteria.
207 * @param what The filter to find
208 * @param list A list of filter criteria
209 * @return The found filter criteria or null
211 public static FilterCriteria
find(FilterCriteria what
, List
<FilterCriteria
> list
) {
212 if (what
!= null && list
!= null) {
214 for (Iterator
<FilterCriteria
> i
= list
.iterator(); i
.hasNext();) {
215 FilterCriteria fc
= i
.next();
216 if (what
.compareTo(fc
)) {
220 } catch (Exception e
) {
228 * Compares this filter criteria with a given criteria.
230 * @param to The filter criteria to compare.
231 * @return usual comparison result (< 0, 0, > 0)
233 public boolean compareTo(FilterCriteria to
) {
234 if (isPositive() == to
.isPositive() && getCriteria().compareTo(to
.getCriteria())) {
235 if (getLoaderClassName() == null && to
.getLoaderClassName() == null) {
238 if ((getLoaderClassName() != null && to
.getLoaderClassName() != null) && getLoaderClassName().equals(to
.getLoaderClassName())) {
246 * Saves current criteria attributes in the dialog settings.
248 * @param settings The dialog settings
250 public void save(DialogSettings settings
) {
251 settings
.put(ACTIVE
, isActive());
252 settings
.put(POSITIVE
, isPositive());
253 if (getLoaderClassName() != null) {
254 settings
.put(LOADERCLASSNAME
, getLoaderClassName());
256 settings
.put(LOADERCLASSNAME
, ""); //$NON-NLS-1$
258 if (fCriteria
!= null) {
259 fCriteria
.save(settings
);
264 * Loads the criteria with values of the dialog settings.
266 * @param settings The dialog settings
268 public void load(DialogSettings settings
) {
269 setActive(settings
.getBoolean(ACTIVE
));
270 setPositive(settings
.getBoolean(POSITIVE
));
271 String loaderClassName
= settings
.get(LOADERCLASSNAME
);
272 setLoaderClassName(loaderClassName
!= null && loaderClassName
.length() > 0 ? loaderClassName
: null);
273 if (fCriteria
!= null) {
274 fCriteria
.load(settings
);
This page took 0.035784 seconds and 5 git commands to generate.