KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > getahead > dwrdemo > livehelp > LiveHelp


1 /*
2  * Copyright 2005 Joe Walker
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.getahead.dwrdemo.livehelp;
17
18 import java.util.Collection JavaDoc;
19
20 import org.directwebremoting.Security;
21 import org.directwebremoting.WebContext;
22 import org.directwebremoting.WebContextFactory;
23 import org.directwebremoting.proxy.dwr.Util;
24 import org.directwebremoting.util.Logger;
25
26 /**
27  * A simple shared input form that several users can share
28  * @author Joe Walker [joe at getahead dot ltd dot uk]
29  */

30 public class LiveHelp
31 {
32     /**
33      * Something has changed
34      * @param id The id of the field that changed
35      * @param value The new value
36      */

37     public void notifyTyping(String JavaDoc id, String JavaDoc value)
38     {
39         Util utilAll = new Util(getUsersToAffect());
40
41         utilAll.setValue(id, Security.replaceXmlCharacters(value));
42     }
43
44     /**
45      * The user has tabbed in
46      * @param id The id of the field that changed
47      */

48     public void notifyFocus(String JavaDoc id)
49     {
50         Util utilAll = new Util(getUsersToAffect());
51
52         utilAll.addClassName(id, "disabled");
53         String JavaDoc addr = WebContextFactory.get().getHttpServletRequest().getRemoteAddr();
54         utilAll.setValue(id + "Tip", addr);
55
56         //utilAll.addScript("$('" + id + "').disabled = true;");
57
}
58
59     /**
60      * The user has tabbed out
61      * @param id The id of the field that changed
62      */

63     public void notifyBlur(String JavaDoc id)
64     {
65         Util utilAll = new Util(getUsersToAffect());
66
67         utilAll.removeClassName(id, "disabled");
68         utilAll.setValue(id + "Tip", "");
69
70         //utilAll.addScript("$('" + id + "').disabled = false;");
71
}
72
73     /**
74      * @return The collection of people to affect
75      */

76     private Collection JavaDoc getUsersToAffect()
77     {
78         WebContext wctx = WebContextFactory.get();
79         String JavaDoc currentPage = wctx.getCurrentPage();
80
81         // For all the browsers on the current page:
82
Collection JavaDoc sessions = wctx.getScriptSessionsByPage(currentPage);
83
84         // But not the current user!
85
sessions.remove(wctx.getScriptSession());
86
87         log.debug("Affecting " + sessions.size() + " users");
88
89         return sessions;
90     }
91
92     /**
93      * The log stream
94      */

95     private static final Logger log = Logger.getLogger(LiveHelp.class);
96 }
97
Popular Tags