001: /* uDig - User Friendly Desktop Internet GIS client
002: * http://udig.refractions.net
003: * (C) 2004, Refractions Research Inc.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation;
008: * version 2.1 of the License.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: */
015: package net.refractions.udig.ui.operations;
016:
017: /**
018: * Represents the filter element in the operation extension point.
019: * @author jones
020: * @since 1.1.0
021: */
022: public interface OpFilter {
023:
024: OpFilter TRUE = new OpFilter() {
025:
026: public boolean accept(Object object) {
027: return true;
028: }
029:
030: public void addListener(IOpFilterListener listener) {
031: }
032:
033: public boolean canCacheResult() {
034: return true;
035: }
036:
037: public boolean isBlocking() {
038: return false;
039: }
040:
041: public void removeListener(IOpFilterListener listener) {
042: }
043:
044: };
045: OpFilter FALSE = new OpFilter() {
046:
047: public boolean accept(Object object) {
048: return false;
049: }
050:
051: public void addListener(IOpFilterListener listener) {
052: }
053:
054: public boolean canCacheResult() {
055: return true;
056: }
057:
058: public boolean isBlocking() {
059: return false;
060: }
061:
062: public void removeListener(IOpFilterListener listener) {
063: }
064:
065: };
066:
067: /**
068: * Returns true if the object is accepted by the filter
069: *
070: * @param object object to test
071: * @return true if the object is accepted by the filter
072: */
073: boolean accept(Object object);
074:
075: /**
076: * Returns true if the results can be cached.
077: *
078: * <p>A result can be cached if
079: * <ol>
080: * <li>The value will never change</li>
081: * <li>It is possible for the filter to listen for changes and update listeners
082: * added via the {@link #addListener(IOpFilterListener)} method</li>
083: * </ol>
084: * </p><p>
085: * Therefore this method only returns false if it must be calculated each time because there is
086: * no way to listen for state changes. If it is non-blocking that is fine, if it is blocking
087: * then try to do this rarely.
088: * </p>
089: * <p>WARNING: If this returns true then the listeners must be notified for the new value to be
090: * recognized</p>
091: * @return true if the results can be cached.
092: */
093: boolean canCacheResult();
094:
095: /**
096: * Returns true if processing this filter may block when {@link #accept(Object)} is called or takes a large amount
097: * of time to execute.
098: *
099: * @return true if processing this filter may block when {@link #accept(Object)} is called.
100: */
101: boolean isBlocking();
102:
103: /**
104: * Adds a listener to listen for events indicating the value has changed. Listeners should only be added
105: * if {@link #canCacheResult()} returns true.
106: *
107: * @param listener listener to add
108: */
109: void addListener(IOpFilterListener listener);
110:
111: /**
112: * Removes a listeners
113: *
114: * @param listener listener to remove
115: */
116: void removeListener(IOpFilterListener listener);
117:
118: }
|