cd8bfacfef262ca4c789f18226a9cf5f1f0113bb
1 /**********************************************************************
2 * Copyright (c) 2005, 2012 IBM Corporation, Ericsson
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
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
;
15 import java
.util
.Iterator
;
16 import java
.util
.List
;
18 import org
.eclipse
.jface
.dialogs
.DialogSettings
;
21 * A filter criteria is a criteria that can be activated or not, positive or not.
27 public class FilterCriteria
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 * The filter state value for 'active'.
35 protected static final String ACTIVE
= "active"; //$NON-NLS-1$
37 * The property value for positive filter.
39 protected static final String POSITIVE
= "positive"; //$NON-NLS-1$
41 * The filter loader class name property.
43 protected static final String LOADERCLASSNAME
= "loaderClassName"; //$NON-NLS-1$
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
49 * The criteria reference.
51 protected Criteria fCriteria
;
53 * Flag whether this criteria is active or not
55 protected boolean fIsActive
;
57 * Flag whether this criteria is for positive filter or not
59 protected boolean fIsPositive
;
61 * The loader class name.
63 protected String fLoaderClassName
;
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
69 * Standard constructor
71 * @param criteria A criteria reference
72 * @param isActive <code>true</code> if filter criteria is active else <code>false</code>
73 * @param isPositive <code>true</code> for positive filter else <code>false</code>
75 public FilterCriteria(Criteria criteria
, boolean isActive
, boolean isPositive
) {
76 this(criteria
, isActive
, isPositive
, null);
82 * @param criteria A criteria reference
83 * @param isActive <code>true</code> if filter criteria is active else <code>false</code>
84 * @param isPositive <code>true</code> for positive filter else <code>false</code>
85 * @param loaderClassName A loader class name
87 public FilterCriteria(Criteria criteria
, boolean isActive
, boolean isPositive
, String loaderClassName
) {
90 fIsPositive
= isPositive
;
91 fLoaderClassName
= loaderClassName
;
96 * @param other FilterCriteria
98 public FilterCriteria (FilterCriteria other
) {
99 fCriteria
= new Criteria(other
.fCriteria
);
100 fIsActive
= other
.fIsActive
;
101 fIsPositive
= other
.fIsPositive
;
102 fLoaderClassName
= other
.fLoaderClassName
;
106 * Default constructor
108 protected FilterCriteria() {
111 // ------------------------------------------------------------------------
113 // ------------------------------------------------------------------------
116 * @see java.lang.Object#toString()
119 public String
toString() {
120 StringBuffer sb
= new StringBuffer(super.toString());
122 if (fCriteria
!= null) {
123 sb
.append(" expression=");sb
.append(fCriteria
.getExpression()); //$NON-NLS-1$
124 sb
.append(" active=");sb
.append(fIsActive
); //$NON-NLS-1$
125 sb
.append(" positive=");sb
.append(fIsPositive
); //$NON-NLS-1$
127 sb
.append("empty criteria"); //$NON-NLS-1$
129 return sb
.toString();
133 * Sets a criteria reference.
134 * @param criteria A criteria reference
136 public void setCriteria(Criteria criteria
) {
137 fCriteria
= criteria
;
141 * Returns the criteria reference.
143 * @return the criteria reference
145 public Criteria
getCriteria() {
150 * Sets the active flag.
152 * @param isActive A active value.
154 public void setActive(boolean isActive
) {
155 fIsActive
= isActive
;
159 * Returns whether filter criteria is active or not.
161 * @return whether filter criteria is active or not.
163 public boolean isActive() {
168 * Sets filter is for positive filtering or not.
170 * @param isPositive The value to set.
172 public void setPositive(boolean isPositive
) {
173 fIsPositive
= isPositive
;
177 * Returns whether the filter si for positive filtering or not.
179 * @return Returns the positive.
181 public boolean isPositive() {
186 * Sets the loader class name for this filter.
188 * @param loaderClassName The loader class name to set
190 public void setLoaderClassName(String loaderClassName
) {
191 fLoaderClassName
= loaderClassName
;
195 * Returns the class loader name.
197 * @return the class loader name.
199 public String
getLoaderClassName() {
200 return fLoaderClassName
;
204 * Finds a filter criteria within a list of criteria.
206 * @param what The filter to find
207 * @param list A list of filter criteria
208 * @return The found filter criteria or null
210 public static FilterCriteria
find(FilterCriteria what
, List
<FilterCriteria
> list
) {
211 if (what
!= null && list
!= null) {
213 for (Iterator
<FilterCriteria
> i
= list
.iterator(); i
.hasNext();) {
214 FilterCriteria fc
= i
.next();
215 if (what
.compareTo(fc
)) {
219 } catch (Exception e
) {
227 * Compares this filter criteria with a given criteria.
229 * @param to The filter criteria to compare.
230 * @return usual comparison result (< 0, 0, > 0)
232 public boolean compareTo(FilterCriteria to
) {
233 if (isPositive() == to
.isPositive() && getCriteria().compareTo(to
.getCriteria())) {
234 if (getLoaderClassName() == null && to
.getLoaderClassName() == null) {
237 if ((getLoaderClassName() != null && to
.getLoaderClassName() != null) && getLoaderClassName().equals(to
.getLoaderClassName())) {
245 * Saves current criteria attributes in the dialog settings.
247 * @param settings The dialog settings
249 public void save(DialogSettings settings
) {
250 settings
.put(ACTIVE
, isActive());
251 settings
.put(POSITIVE
, isPositive());
252 if (getLoaderClassName() != null) {
253 settings
.put(LOADERCLASSNAME
, getLoaderClassName());
255 settings
.put(LOADERCLASSNAME
, ""); //$NON-NLS-1$
257 if (fCriteria
!= null) {
258 fCriteria
.save(settings
);
263 * Loads the criteria with values of the dialog settings.
265 * @param settings The dialog settings
267 public void load(DialogSettings settings
) {
268 setActive(settings
.getBoolean(ACTIVE
));
269 setPositive(settings
.getBoolean(POSITIVE
));
270 String loaderClassName
= settings
.get(LOADERCLASSNAME
);
271 setLoaderClassName(loaderClassName
!= null && loaderClassName
.length() > 0 ? loaderClassName
: null);
272 if (fCriteria
!= null) {
273 fCriteria
.load(settings
);
This page took 0.035668 seconds and 5 git commands to generate.