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 criteria
;
54 * Flag whether this criteria is active or not
56 protected boolean active
;
58 * Flag whether this criteria is for positive filter or not
60 protected boolean positive
;
62 * The loader class name.
64 protected String loaderClassName
;
66 // ------------------------------------------------------------------------
68 // ------------------------------------------------------------------------
70 * Standard constructor
72 * @param criteria_ A criteria reference
73 * @param active_ <code>true</code> if filter criteria is active else <code>false</code>
74 * @param positive_ <code>true</code> for positive filter else <code>false</code>
76 public FilterCriteria(Criteria criteria_
, boolean active_
, boolean positive_
) {
77 setCriteria(criteria_
);
79 setPositive(positive_
);
85 * @param criteria_ A criteria reference
86 * @param active_ <code>true</code> if filter criteria is active else <code>false</code>
87 * @param positive_ <code>true</code> for positive filter else <code>false</code>
88 * @param loaderClassName_ A loader class name
90 public FilterCriteria(Criteria criteria_
, boolean active_
, boolean positive_
, String loaderClassName_
) {
91 setCriteria(criteria_
);
93 setPositive(positive_
);
94 setLoaderClassName(loaderClassName_
);
99 * @param other FilterCriteria
101 public FilterCriteria (FilterCriteria other
) {
102 criteria
= new Criteria(other
.criteria
);
103 this.active
= other
.active
;
104 this.positive
= other
.positive
;
105 this.loaderClassName
= other
.loaderClassName
;
109 * Default constructor
111 protected FilterCriteria() {
114 // ------------------------------------------------------------------------
116 // ------------------------------------------------------------------------
119 * @see java.lang.Object#toString()
122 public String
toString() {
123 StringBuffer sb
= new StringBuffer(super.toString());
124 sb
.append(":"); //$NON-NLS-1$
125 if (criteria
!= null) {
126 sb
.append(" expression=");sb
.append(criteria
.getExpression()); //$NON-NLS-1$
127 sb
.append(" active=");sb
.append(active
); //$NON-NLS-1$
128 sb
.append(" positive=");sb
.append(positive
); //$NON-NLS-1$
130 sb
.append("empty criteria"); //$NON-NLS-1$
132 return sb
.toString();
136 * Sets a criteria reference.
137 * @param criteria_ A criteria reference
139 public void setCriteria(Criteria criteria_
) {
140 criteria
= criteria_
;
144 * Returns the criteria reference.
146 * @return the criteria reference
148 public Criteria
getCriteria() {
153 * Sets the active flag.
155 * @param active_ A active value.
157 public void setActive(boolean active_
) {
162 * Returns whether filter criteria is active or not.
164 * @return whether filter criteria is active or not.
166 public boolean isActive() {
171 * Sets filter is for positive filtering or not.
173 * @param positive_ The value to set.
175 public void setPositive(boolean positive_
) {
176 positive
= positive_
;
180 * Returns whether the filter si for positive filtering or not.
182 * @return Returns the positive.
184 public boolean isPositive() {
189 * Sets the loader class name for this filter.
191 * @param loaderClassName_ The loader class name to set
193 public void setLoaderClassName(String loaderClassName_
) {
194 loaderClassName
= loaderClassName_
;
198 * Returns the class loader name.
200 * @return the class loader name.
202 public String
getLoaderClassName() {
203 return loaderClassName
;
207 * Finds a filter criteria within a list of criteria.
209 * @param what The filter to find
210 * @param list A list of filter criteria
211 * @return The found filter criteria or null
213 public static FilterCriteria
find(FilterCriteria what
, List
<FilterCriteria
> list
) {
214 if (what
!= null && list
!= null) {
216 for (Iterator
<FilterCriteria
> i
= list
.iterator(); i
.hasNext();) {
217 FilterCriteria fc
= (FilterCriteria
) i
.next();
218 if (what
.compareTo(fc
)) {
222 } catch (Exception e
) {
230 * Compares this filter criteria with a given criteria.
232 * @param to The filter criteria to compare.
233 * @return usual comparison result (< 0, 0, > 0)
235 public boolean compareTo(FilterCriteria to
) {
236 if (isPositive() == to
.isPositive() && getCriteria().compareTo(to
.getCriteria())) {
237 if (getLoaderClassName() == null && to
.getLoaderClassName() == null) {
240 if ((getLoaderClassName() != null && to
.getLoaderClassName() != null) && getLoaderClassName().equals(to
.getLoaderClassName())) {
248 * Saves current criteria attributes in the dialog settings.
250 * @param settings The dialog settings
252 public void save(DialogSettings settings
) {
253 settings
.put(ACTIVE
, isActive());
254 settings
.put(POSITIVE
, isPositive());
255 if (getLoaderClassName() != null) {
256 settings
.put(LOADERCLASSNAME
, getLoaderClassName());
258 settings
.put(LOADERCLASSNAME
, ""); //$NON-NLS-1$
260 if (criteria
!= null) {
261 criteria
.save(settings
);
266 * Loads the criteria with values of the dialog settings.
268 * @param settings The dialog settings
270 public void load(DialogSettings settings
) {
271 setActive(settings
.getBoolean(ACTIVE
));
272 setPositive(settings
.getBoolean(POSITIVE
));
273 String loaderClassName_
= settings
.get(LOADERCLASSNAME
);
274 setLoaderClassName(loaderClassName_
!= null && loaderClassName_
.length() > 0 ? loaderClassName_
: null);
275 if (criteria
!= null) {
276 criteria
.load(settings
);
This page took 0.03707 seconds and 5 git commands to generate.