01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.client.gui.directory;
19:
20: import java.util.HashMap;
21: import java.util.Map;
22:
23: import de.finix.contelligent.client.base.ContelligentComponent;
24: import de.finix.contelligent.client.base.Type;
25:
26: public class ComponentFilter {
27:
28: private boolean acceptByDefault;
29:
30: private Map componentRules = new HashMap();
31:
32: private Map typeRules = new HashMap();
33:
34: public ComponentFilter(boolean acceptByDefault) {
35: this .acceptByDefault = acceptByDefault;
36: }
37:
38: public void addRule(Type type, boolean accept) {
39: typeRules.put(type, Boolean.valueOf(accept));
40: }
41:
42: public void addRule(ContelligentComponent component, boolean accept) {
43: componentRules.put(component, Boolean.valueOf(accept));
44: }
45:
46: public boolean accept(Type type) {
47: if (type == null)
48: return false;
49: if (typeRules.containsKey(type)) {
50: return ((Boolean) typeRules.get(type)).booleanValue();
51: }
52: return acceptByDefault;
53: }
54:
55: public boolean accept(ContelligentComponent component) {
56: if (componentRules.containsKey(component)) {
57: return ((Boolean) componentRules.get(component))
58: .booleanValue();
59: }
60: return accept(component.getType());
61: }
62: }
|