KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > suggestions > TrackingProvider


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.suggestions;
21
22 import org.netbeans.modules.tasklist.providers.SuggestionProvider;
23 import org.openide.util.Lookup;
24 import org.openide.util.lookup.AbstractLookup;
25 import org.openide.util.lookup.InstanceContent;
26 import junit.framework.Assert;
27
28 /**
29  * Looks like real Suggestion provider but has
30  * side channels that monitor events from framework.
31  *
32  * @author Petr Kuzel
33  */

34 public final class TrackingProvider extends SuggestionProvider {
35
36     public static void installSuggestionProviders() {
37         InstanceContent content = new InstanceContent();
38         content.add(new TrackingProvider());
39         content.add(new Lookup.Provider() {
40             public Lookup getLookup() {
41                 return Lookup.getDefault();
42             }
43         });
44         AbstractLookup testLookup = new AbstractLookup(content);
45         SuggestionProviders.lookup = testLookup;
46     }
47
48     public String JavaDoc getType() {
49         return "test";
50     }
51
52     static final int PREPARED = 1;
53     static final int RUN = 10;
54     static final int STOPPED = 30;
55     static final int FINISHED = 50;
56
57     private int state = FINISHED;
58
59     public void notifyFinish() {
60         if (state != STOPPED && state != PREPARED) Assert.fail("Unexpected state: " + state);
61         state = FINISHED;
62     }
63
64     public void notifyPrepare() {
65         if (state != FINISHED) Assert.fail("Unexpected state: " + state);
66         state = PREPARED;
67     }
68
69     public void notifyRun() {
70         if (state != PREPARED && state != STOPPED) Assert.fail("Unexpected state: " + state);
71         state = RUN;
72     }
73
74     public void notifyStop() {
75         if (state != RUN) Assert.fail("Unexpected state: " + state);
76         state = STOPPED;
77     }
78 }
79
Popular Tags