01: package org.drools.brms.client;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import org.drools.brms.client.common.ErrorPopup;
20: import org.drools.brms.client.rpc.RepositoryServiceFactory;
21:
22: import com.google.gwt.user.client.Timer;
23: import com.google.gwt.user.client.rpc.AsyncCallback;
24: import com.google.gwt.user.client.ui.Composite;
25: import com.google.gwt.user.client.ui.HTML;
26:
27: /**
28: * Simple widget to show who is logged in, and a link to logout.
29: * @author Fernando Meyer
30: */
31: public class LoggedInUserInfo extends Composite {
32: private HTML widgetcontent;
33:
34: public LoggedInUserInfo() {
35:
36: widgetcontent = new HTML();
37: initWidget(widgetcontent);
38: }
39:
40: public void setUserName(String userName) {
41: StringBuffer content = new StringBuffer();
42:
43: content.append("<div id='user_info'>");
44: content.append("Welcome: " + userName);
45: content
46: .append(" <a href='/drools-jbrms/logout.jsp'>[Sign Out]</a>");
47: content.append("</div>");
48: widgetcontent.setHTML(content.toString());
49:
50: //we have the timer to keep the session alive.
51: Timer timer = new Timer() {
52:
53: public void run() {
54: RepositoryServiceFactory.getSecurityService()
55: .getCurrentUser(new AsyncCallback() {
56:
57: public void onFailure(Throwable t) {
58: }
59:
60: public void onSuccess(Object o) {
61: if (o == null) {
62: ErrorPopup
63: .showMessage("Your session has expired. Please press the 'Sign out' link so you can re-login.");
64: }
65: }
66:
67: });
68: }
69:
70: };
71:
72: timer.scheduleRepeating(300000);
73:
74: }
75:
76: }
|