001: /**
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * LogPanel
022: * LPS
023: * Nov 5, 2007
024: */package com.bostechcorp.cbesb.console.client.log;
025:
026: import com.bostechcorp.cbesb.console.client.AdminWithTimer;
027: import com.bostechcorp.cbesb.console.client.ConsoleCallback;
028: import com.bostechcorp.cbesb.console.client.ICallbackHandler;
029: import com.bostechcorp.cbesb.console.client.PollingTimerCallback;
030: import com.bostechcorp.cbesb.console.common.Constants;
031: import com.bostechcorp.cbesb.console.common.LogData;
032: import com.bostechcorp.cbesb.console.common.LogViewProperties;
033: import com.bostechcorp.cbesb.console.i18n.ConsoleMessages;
034: import com.bostechcorp.cbesb.console.rpc.ViewLog;
035: import com.bostechcorp.cbesb.console.rpc.ViewLogAsync;
036: import com.google.gwt.core.client.GWT;
037: import com.google.gwt.user.client.rpc.ServiceDefTarget;
038: import com.google.gwt.user.client.ui.ClickListener;
039: import com.google.gwt.user.client.ui.DockPanel;
040: import com.google.gwt.user.client.ui.FlexTable;
041: import com.google.gwt.user.client.ui.Image;
042: import com.google.gwt.user.client.ui.PushButton;
043: import com.google.gwt.user.client.ui.TextArea;
044: import com.google.gwt.user.client.ui.VerticalPanel;
045: import com.google.gwt.user.client.ui.Widget;
046:
047: /**
048: * @author LPS
049: *
050: */
051: public abstract class LogPanel extends AdminWithTimer {
052:
053: private VerticalPanel displayPanel = new VerticalPanel();
054:
055: private TextArea logOnetextArea = new TextArea();
056:
057: protected String currentFileName = "cbesb_server.log";
058:
059: LogViewProperties properties = new LogViewProperties();
060:
061: private PushButton pauseButton = new PushButton();
062:
063: private FlexTable flexTable = new FlexTable();
064:
065: public int NUMOFCHARPERLINE = 100;
066:
067: public String lastData = "";
068:
069: private Image image = new Image();
070:
071: final DockPanel dockPanel = new DockPanel();
072:
073: private ReadLogCallback readLogListener = new ReadLogCallback(this );
074:
075: /**
076: *
077: */
078: public LogPanel() {
079: super ();
080: setCurrentFile();
081: createWidget();
082: //initalLog(currentFileName);
083: initTimer();
084: }
085:
086: protected abstract void setCurrentFile();
087:
088: /*
089: * (non-Javadoc)
090: *
091: * @see com.bostechcorp.cbesb.console.client.AdminWithTimer#updateContent()
092: */
093: public void updateContent(boolean isPolling) {
094: if (isPolling) {
095: pollingReadLogFile(currentFileName);
096: } else {
097:
098: readLogFile(currentFileName);
099: }
100: }
101:
102: public void readLogFile(String currentLog) {
103: if (currentLog.equals(""))
104: return;
105: read(currentLog);
106: }
107:
108: public void pollingReadLogFile(String currentLog) {
109: if (currentLog.equals(""))
110: return;
111: pollingRead(currentLog);
112: }
113:
114: public void read(String currentLog) {
115: ViewLogAsync logAsync;
116: logAsync = (ViewLogAsync) GWT.create(ViewLog.class);
117: ServiceDefTarget databaseConnectTarget = (ServiceDefTarget) logAsync;
118: String relativeUrl = GWT.getModuleBaseURL()
119: + Constants.VIEW_LOG_SERVLET;
120: databaseConnectTarget.setServiceEntryPoint(relativeUrl);
121: this .showWaitingDialog();
122: logAsync.update(properties.getBufferSize(), currentLog,
123: readLogListener);
124: }
125:
126: public void pollingRead(String currentLog) {
127: ViewLogAsync logAsync;
128: logAsync = (ViewLogAsync) GWT.create(ViewLog.class);
129: ServiceDefTarget databaseConnectTarget = (ServiceDefTarget) logAsync;
130: String relativeUrl = GWT.getModuleBaseURL()
131: + Constants.VIEW_LOG_SERVLET;
132: databaseConnectTarget.setServiceEntryPoint(relativeUrl);
133:
134: logAsync.pollingUpdate(properties.getBufferSize(), currentLog,
135: readLogListener);
136:
137: }
138:
139: protected void createWidget() {
140: displayPanel.setWidth("100%");
141: displayPanel.setHeight("100%");
142:
143: dockPanel.setWidth("100%");
144: dockPanel.setHeight("100%");
145:
146: dockPanel.add(createHorizontalPanel(currentFileName),
147: DockPanel.NORTH);
148:
149: logOnetextArea.setWidth("100%");
150: logOnetextArea.setCharacterWidth(NUMOFCHARPERLINE);
151:
152: logOnetextArea.setVisibleLines(properties.getNumOfLines());
153: logOnetextArea.setReadOnly(true);
154:
155: dockPanel.add(logOnetextArea, DockPanel.CENTER);
156: dockPanel.setCellWidth(logOnetextArea, "100%");
157: dockPanel.setCellHeight(logOnetextArea, "100%");
158: displayPanel.add(dockPanel);
159:
160: initWidget(displayPanel);
161:
162: }
163:
164: /* public void initalLog(String log) {
165: ViewLogAsync logAsync;
166: logAsync = (ViewLogAsync) GWT.create(ViewLog.class);
167: ServiceDefTarget databaseConnectTarget = (ServiceDefTarget) logAsync;
168: String relativeUrl = GWT.getModuleBaseURL()
169: + Constants.VIEW_LOG_SERVLET;
170: databaseConnectTarget.setServiceEntryPoint(relativeUrl);
171: logAsync.inital(properties.getBufferSize(), log,
172: new InitialLogCallback(this));
173: }*/
174:
175: private FlexTable createHorizontalPanel(final String name) {
176: flexTable.setWidget(0, 0, pauseButton);
177: pauseButton.setText(((ConsoleMessages) GWT
178: .create(ConsoleMessages.class)).Pause());
179: pauseButton.addClickListener(new PauseButtonClickListener() {
180: });
181: flexTable.setWidget(0, 1, image);
182: image.setUrl("images/download.gif");
183: flexTable.setHTML(0, 2, "<a href=\""
184: + GWT.getModuleBaseURL()
185: + "savelog?name="
186: + name
187: + "\">"
188: + ((ConsoleMessages) GWT.create(ConsoleMessages.class))
189: .Save() + "</a>");
190: flexTable.getFlexCellFormatter()
191: .setStyleName(0, 2, "gwt-Label");
192: flexTable.getFlexCellFormatter().setColSpan(0, 1, 2);
193:
194: return flexTable;
195: }
196:
197: class ReadLogCallback extends PollingTimerCallback {
198:
199: public ReadLogCallback(AdminWithTimer handler) {
200: super (handler);
201:
202: }
203:
204: public void handleSuccess(Object result) {
205: if (result instanceof LogData) {
206: LogData logData = (LogData) result;
207: if (logData.getProperties() != null) {
208:
209: properties = logData.getProperties();
210: // change the refreshing rate
211: setINTERVAL(properties.getInterval() * 1000);
212: logOnetextArea.setVisibleLines(properties
213: .getNumOfLines());
214:
215: }
216:
217: if (logData.getData() == null
218: || logData.getData().equals("")) {
219: logOnetextArea.setCursorPos(logOnetextArea
220: .getText().length());
221: return;
222: }
223:
224: StringBuffer newData = new StringBuffer(logData
225: .getData());
226: StringBuffer oldData = new StringBuffer(lastData);
227: if ((newData == null) || (newData.equals(""))) {
228: newData = oldData;
229: } else {
230: newData = newData.insert(0, oldData);
231: if (newData.toString().endsWith("\r")) {
232:
233: newData.append("\n");
234: }
235:
236: String[] data = newData.toString().split("\n");
237:
238: int lines = data.length;
239: if (lines > properties.getBufferSize()) {
240: int numRemove = lines
241: - properties.getBufferSize() - 1;
242: newData.delete(0, newData
243: .indexOf(data[numRemove])
244: + data[numRemove].length() + 1);
245: }
246: }
247: String dt = newData.toString();
248: logOnetextArea.setText(dt);
249: lastData = dt;
250: logOnetextArea.setCursorPos(logOnetextArea.getText()
251: .length());
252:
253: }
254:
255: }
256: }
257:
258: class PauseButtonClickListener implements ClickListener {
259: public void onClick(Widget sender) {
260:
261: if (pauseButton.getUpFace().getText().equals(
262: ((ConsoleMessages) GWT
263: .create(ConsoleMessages.class)).Pause())) {
264: currentTimer.cancel();
265:
266: pauseButton.getUpFace().setText(
267: ((ConsoleMessages) GWT
268: .create(ConsoleMessages.class))
269: .Resume());
270: } else if (pauseButton.getUpFace().getText().equals(
271: ((ConsoleMessages) GWT
272: .create(ConsoleMessages.class)).Resume())) {
273: reset();
274: currentTimer.scheduleRepeating(getINTERVAL());
275:
276: pauseButton.getUpFace()
277: .setText(
278: ((ConsoleMessages) GWT
279: .create(ConsoleMessages.class))
280: .Pause());
281: }
282: }
283:
284: }
285:
286: public void reset() {
287:
288: ViewLogAsync logAsync;
289: logAsync = (ViewLogAsync) GWT.create(ViewLog.class);
290: ServiceDefTarget databaseConnectTarget = (ServiceDefTarget) logAsync;
291: String relativeUrl = GWT.getModuleBaseURL()
292: + Constants.VIEW_LOG_SERVLET;
293: databaseConnectTarget.setServiceEntryPoint(relativeUrl);
294: logAsync.read(new ReadLogCallback(this ));
295: }
296:
297: /* class InitialLogCallback extends ConsoleCallback {
298: public InitialLogCallback(ICallbackHandler handler) {
299: super(handler);
300:
301: }
302:
303: public void handleSuccess(Object result) {
304: if (result instanceof LogData) {
305: LogData logData = (LogData) result;
306: if (logData.getProperties() != null) {
307: properties = logData.getProperties();
308: // change the refreshing rate
309: setINTERVAL(properties.getInterval() * 1000);
310: logOnetextArea.setVisibleLines(properties.getNumOfLines());
311:
312: }
313:
314: String data = logData.getData();
315:
316: logOnetextArea.setText(data);
317: }
318:
319: }
320: }*/
321:
322: /**
323: * sets the properties loaded from the session
324: *
325: * @author LPS
326: */
327: class LoadConfigCallback extends ConsoleCallback {
328:
329: public LoadConfigCallback(ICallbackHandler handler) {
330: super (handler);
331:
332: }
333:
334: public void handleSuccess(Object result) {
335: if (result instanceof LogViewProperties) {
336: properties = (LogViewProperties) result;
337: // change the refreshing rate
338: setINTERVAL(properties.getInterval());
339:
340: logOnetextArea.setVisibleLines(properties
341: .getNumOfLines());
342:
343: }
344:
345: }
346: }
347: }
|