001: /*
002: * Copyright 2005 JBoss Inc
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.drools.brms.client;
018:
019: import org.drools.brms.client.JBRMSFeature.ComponentInfo;
020: import org.drools.brms.client.common.GenericCallback;
021: import org.drools.brms.client.rpc.RepositoryServiceFactory;
022:
023: import com.google.gwt.core.client.EntryPoint;
024: import com.google.gwt.user.client.Command;
025: import com.google.gwt.user.client.History;
026: import com.google.gwt.user.client.HistoryListener;
027: import com.google.gwt.user.client.Window;
028: import com.google.gwt.user.client.ui.DialogBox;
029: import com.google.gwt.user.client.ui.DockPanel;
030: import com.google.gwt.user.client.ui.HTML;
031: import com.google.gwt.user.client.ui.HasAlignment;
032: import com.google.gwt.user.client.ui.PopupPanel;
033: import com.google.gwt.user.client.ui.RootPanel;
034: import com.google.gwt.user.client.ui.VerticalPanel;
035:
036: /**
037: * This is the main launching/entry point for the JBRMS web console.
038: * It essentially sets the initial layout.
039: *
040: * If you hadn't noticed, this is using GWT from google. Refer to GWT docs
041: * if GWT is new to you (it is quite a different way of building web apps).
042: */
043: public class JBRMSEntryPoint implements EntryPoint, HistoryListener {
044:
045: private ComponentInfo curInfo;
046: private JBRMSFeature curSink;
047: private HTML description = new HTML();
048: private JBRMSFeatureList list = new JBRMSFeatureList();
049: private DockPanel panel = new DockPanel();
050: private DockPanel sinkContainer;
051: private LoginWidget loginWidget;
052: private LoggedInUserInfo loggedInUserInfo;
053:
054: public void onHistoryChanged(String token) {
055: // Find the SinkInfo associated with the history context. If one is
056: // found, show it (It may not be found, for example, when the user mis-
057: // types a URL, or on startup, when the first context will be "").
058: ComponentInfo info = list.find(token);
059: if (info == null) {
060: showInfo();
061: return;
062: }
063: show(info, false);
064: }
065:
066: public void onModuleLoad() {
067:
068: // Load all the sinks.
069: JBRMSFeatureConfigurator.configure(list);
070:
071: // Put the sink list on the left, and add the outer dock panel to the
072: // root.
073: sinkContainer = new DockPanel();
074: sinkContainer.setStyleName("ks-Sink");
075:
076: VerticalPanel vp = new VerticalPanel();
077: vp.setWidth("100%");
078: vp.add(description);
079: vp.add(sinkContainer);
080:
081: description.setStyleName("ks-Info");
082:
083: panel.add(list, DockPanel.WEST);
084: panel.add(vp, DockPanel.CENTER);
085:
086: panel.setCellVerticalAlignment(list, HasAlignment.ALIGN_TOP);
087: panel.setCellWidth(vp, "100%");
088:
089: History.addHistoryListener(this );
090:
091: loggedInUserInfo = new LoggedInUserInfo();
092: loginWidget = new LoginWidget();
093:
094: RootPanel.get().add(loggedInUserInfo);
095: RootPanel.get().add(panel);
096: RootPanel.get().add(loginWidget);
097: loginWidget.setWidth("100%");
098:
099: loggedInUserInfo.setVisible(false);
100: panel.setVisible(false);
101: loginWidget.setVisible(false);
102:
103: checkLoggedIn();
104:
105: // Show the initial screen.
106: String initToken = History.getToken();
107: if (initToken.length() > 0)
108: onHistoryChanged(initToken);
109: else
110: showInfo();
111: }
112:
113: /**
114: * Check if user is logged in, if not, then show prompt.
115: * If it is, then we show the app, in all its glory !
116: */
117: private void checkLoggedIn() {
118:
119: RepositoryServiceFactory.getSecurityService().getCurrentUser(
120: new GenericCallback() {
121:
122: public void onSuccess(Object data) {
123: String userName = (String) data;
124: if (userName != null) {
125: loggedInUserInfo.setUserName(userName);
126: loggedInUserInfo.setVisible(true);
127: panel.setVisible(true);
128: loginWidget.setVisible(false);
129: } else {
130:
131: loginWidget.setVisible(true);
132: loginWidget.setLoggedInEvent(new Command() {
133: public void execute() {
134: loggedInUserInfo
135: .setUserName(loginWidget
136: .getUserName());
137: loggedInUserInfo.setVisible(true);
138: loginWidget.setVisible(false);
139: panel.setVisible(true);
140: }
141: });
142:
143: }
144: }
145:
146: });
147:
148: }
149:
150: public void show(ComponentInfo info, boolean affectHistory) {
151: // Don't bother re-displaying the existing sink. This can be an issue
152: // in practice, because when the history context is set, our
153: // onHistoryChanged() handler will attempt to show the currently-visible
154: // sink.
155: if (info == curInfo)
156: return;
157: curInfo = info;
158:
159: // Remove the old sink from the display area.
160: if (curSink != null) {
161: curSink.onHide();
162: sinkContainer.remove(curSink);
163: }
164:
165: // Get the new sink instance, and display its description in the
166: // sink list.
167: curSink = info.getInstance();
168: list.setSinkSelection(info.getName());
169: description.setHTML(info.getDescription());
170:
171: // If affectHistory is set, create a new item on the history stack. This
172: // will ultimately result in onHistoryChanged() being called. It will call
173: // show() again, but nothing will happen because it will request the exact
174: // same sink we're already showing.
175: if (affectHistory)
176: History.newItem(info.getName());
177:
178: // Display the new sink.
179: sinkContainer.add(curSink, DockPanel.CENTER);
180: sinkContainer.setCellWidth(curSink, "100%");
181: //sinkContainer.setCellHeight(curSink, "100%");
182: sinkContainer.setCellVerticalAlignment(curSink,
183: DockPanel.ALIGN_TOP);
184: curSink.onShow();
185:
186: }
187:
188: private void showInfo() {
189: show(list.find("Info"), false);
190: }
191: }
|