KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > xam > ui > search > SearchEvent


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.xam.ui.search;
21
22 import java.util.EventObject JavaDoc;
23 import java.util.List JavaDoc;
24
25 /**
26  * An event which indicates that a search operation has commenced,
27  * completed, was dismissed, or failed due to an exception.
28  *
29  * @author Nathan Fiedler
30  */

31 public class SearchEvent extends EventObject JavaDoc {
32     /** silence compiler warnings */
33     private static final long serialVersionUID = 1L;
34     /** Search results, if any. */
35     private List JavaDoc<Object JavaDoc> results;
36     /** Event type. */
37     private Type type;
38     /** The exception for this event, if any (e.g. for searchFailed()). */
39     private SearchException exception;
40
41     /**
42      * Type of the search event.
43      */

44     public static enum Type {
45         COMMENCED {
46             public void fireEvent(SearchEvent e, SearchListener l) {
47                 l.searchCommenced(e);
48             }
49         },
50         DISMISSED {
51             public void fireEvent(SearchEvent e, SearchListener l) {
52                 l.searchDismissed(e);
53             }
54         },
55         FAILED {
56             public void fireEvent(SearchEvent e, SearchListener l) {
57                 l.searchFailed(e);
58             }
59         },
60         FINISHED {
61             public void fireEvent(SearchEvent e, SearchListener l) {
62                 l.searchFinished(e);
63             }
64         };
65
66         /**
67          * Dispatches the event to the listener.
68          *
69          * @param e event to dispatch.
70          * @param l listener to receive event.
71          */

72         public abstract void fireEvent(SearchEvent e, SearchListener l);
73     }
74
75     /**
76      * Creates a new instance of SearchEvent.
77      *
78      * @param src event source.
79      * @param type event type.
80      */

81     public SearchEvent(Object JavaDoc src, Type type) {
82         super(src);
83         this.type = type;
84     }
85
86     /**
87      * Creates a new instance of SearchEvent.
88      *
89      * @param src event source.
90      * @param type event type.
91      * @param results set of search results.
92      */

93     public SearchEvent(Object JavaDoc src, Type type, List JavaDoc<Object JavaDoc> results) {
94         this(src, type);
95         this.results = results;
96     }
97
98     /**
99      * Creates a new instance of SearchEvent.
100      *
101      * @param src event source.
102      * @param type event type.
103      * @param error the search exception for this event.
104      */

105     public SearchEvent(Object JavaDoc src, Type type, SearchException error) {
106         this(src, type);
107         this.exception = error;
108     }
109
110     /**
111      * Return the search exception, if any, for this event.
112      *
113      * @return search exception, or null if none.
114      */

115     public SearchException getException() {
116         return exception;
117     }
118
119     /**
120      * Retrieve the results of the search.
121      *
122      * @return search results, or null if none available.
123      */

124     public List JavaDoc<Object JavaDoc> getResults() {
125         return results;
126     }
127
128     /**
129      * Get the search event type.
130      *
131      * @return search event type.
132      */

133     public Type getType() {
134         return type;
135     }
136 }
137
Popular Tags