1 /* |
|
2 * CDDL HEADER START |
|
3 * |
|
4 * The contents of this file are subject to the terms of the |
|
5 * Common Development and Distribution License (the "License"). |
|
6 * You may not use this file except in compliance with the License. |
|
7 * |
|
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 * or http://www.opensolaris.org/os/licensing. |
|
10 * See the License for the specific language governing permissions |
|
11 * and limitations under the License. |
|
12 * |
|
13 * When distributing Covered Code, include this CDDL HEADER in each |
|
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 * If applicable, add the following below this CDDL HEADER, with the |
|
16 * fields enclosed by brackets "[]" replaced with your own identifying |
|
17 * information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 * |
|
19 * CDDL HEADER END |
|
20 */ |
|
21 |
|
22 /* |
|
23 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
|
24 */ |
|
25 |
|
26 package com.oracle.solaris.vp.panel.swing.view; |
|
27 |
|
28 import com.oracle.solaris.vp.panel.common.model.ManagedObject; |
|
29 import com.oracle.solaris.vp.util.misc.finder.Finder; |
|
30 import com.oracle.solaris.vp.util.misc.predicate.*; |
|
31 |
|
32 /** |
|
33 * The {@code ObjectsFilter} class encapsulates a predicate filter and a |
|
34 * displayable name. |
|
35 */ |
|
36 public class ObjectsFilter<C extends ManagedObject> { |
|
37 // |
|
38 // Static data |
|
39 // |
|
40 |
|
41 private static final String TEXT = Finder.getString( |
|
42 "objects.header.filter.all.label"); |
|
43 |
|
44 // |
|
45 // Instance data |
|
46 // |
|
47 |
|
48 private String text_; |
|
49 private Predicate<? super C> predicate_; |
|
50 |
|
51 // |
|
52 // Constructors |
|
53 // |
|
54 |
|
55 /** |
|
56 * Constructs an {@code ObjectsFilter} with the given text. |
|
57 */ |
|
58 public ObjectsFilter(String text, Predicate<? super C> predicate) { |
|
59 text_ = text; |
|
60 predicate_ = predicate; |
|
61 } |
|
62 |
|
63 /** |
|
64 * Constructs an {@code ObjectsFilter} with the given text. |
|
65 */ |
|
66 public ObjectsFilter(String text) { |
|
67 this(text, TruePredicate.getInstance()); |
|
68 } |
|
69 |
|
70 /** |
|
71 * Constructs an {@code ObjectsFilter} with default text indicating that all |
|
72 * items are accepted. |
|
73 */ |
|
74 public ObjectsFilter() { |
|
75 this(TEXT); |
|
76 } |
|
77 |
|
78 // |
|
79 // Object methods |
|
80 // |
|
81 |
|
82 /** |
|
83 * Forwards to {@link #getText}(). |
|
84 */ |
|
85 @Override |
|
86 public String toString() { |
|
87 return getText(); |
|
88 } |
|
89 |
|
90 // |
|
91 // ObjectsFilter methods |
|
92 // |
|
93 |
|
94 /** |
|
95 * Gets a {@link Predicate} to test whether any given {@code ManagedObject} |
|
96 * should be included in the result of the filter. |
|
97 * <p/> |
|
98 * This default implementation returns an instance of {@link TruePredicate}. |
|
99 */ |
|
100 public Predicate<? super C> getPredicate() { |
|
101 assert (predicate_ != null); |
|
102 return predicate_; |
|
103 } |
|
104 |
|
105 public String getText() { |
|
106 return text_; |
|
107 } |
|
108 |
|
109 protected void setText(String text) { |
|
110 text_ = text; |
|
111 } |
|
112 } |
|