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: *
022: * $Id:$
023: */
024: package com.bostechcorp.cbesb.ui.util.log;
025:
026: import java.io.IOException;
027: import java.io.OutputStream;
028: import java.io.PrintStream;
029:
030: import org.eclipse.swt.SWT;
031: import org.eclipse.swt.dnd.Clipboard;
032: import org.eclipse.swt.events.DisposeEvent;
033: import org.eclipse.swt.events.DisposeListener;
034: import org.eclipse.swt.events.ModifyEvent;
035: import org.eclipse.swt.events.ModifyListener;
036: import org.eclipse.swt.layout.FillLayout;
037: import org.eclipse.swt.widgets.Composite;
038: import org.eclipse.swt.widgets.Text;
039: import org.eclipse.ui.IMemento;
040: import org.eclipse.ui.IViewSite;
041: import org.eclipse.ui.PartInitException;
042: import org.eclipse.ui.part.ViewPart;
043:
044: /**
045: * This is the primary class behind the error view. It creates the view
046: * controls, associates those controls with a model, defines how the model
047: * content should be displayed, etc.
048: */
049: public class ESBLog extends ViewPart {
050:
051: public static final String ID = "com.bostechcorp.cbesb.ui.util.view.ErrorlogView";
052:
053: String old = null;
054:
055: private Clipboard clipboard;
056:
057: Text text = null;
058:
059: IMemento memento;
060:
061: /**
062: * The constructor.
063: */
064:
065: public ESBLog() {
066: ErrorLogStringBuffer.setView(this );
067:
068: }
069:
070: public void createPartControl(Composite parent) {
071: parent.setLayout(new FillLayout());
072:
073: text = new Text(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
074:
075: if (ErrorLogStringBuffer.getBuf() != null)
076: text.append(ErrorLogStringBuffer.getBuf().toString());
077:
078: OutputStream out = new OutputStream() {
079:
080: public void write(int b) throws IOException {
081:
082: ErrorLogStringBuffer.getPendingFlushBuf().write(b);
083: if (text.isDisposed())
084: return;
085:
086: }
087:
088: public void flush() {
089: text.append(ErrorLogStringBuffer
090: .getPendingFlushString());
091:
092: ErrorLogStringBuffer.flush();
093:
094: if (text.getLineCount() >= text.getLineHeight())
095: text.setTopIndex(text.getLineCount()
096: - text.getLineHeight());
097: }
098:
099: };
100:
101: OutputStream out1 = new OutputStream() {
102:
103: public void write(int b) throws IOException {
104: ErrorLogStringBuffer.getPendingFlushBuf().write(b);
105:
106: if (text.isDisposed())
107: return;
108:
109: }
110:
111: public void flush() {
112:
113: text.append(ErrorLogStringBuffer
114: .getPendingFlushString());
115:
116: ErrorLogStringBuffer.flush();
117: if (text.getLineCount() >= text.getLineHeight())
118: text.setTopIndex(text.getLineCount()
119: - text.getLineHeight());
120: }
121:
122: };
123: final PrintStream oldOut = System.out;
124: PrintStream newOut = null;
125:
126: newOut = new PrintStream(out);
127:
128: System.setOut(newOut);
129: final PrintStream oldOut1 = System.err;
130: PrintStream newOut1 = null;
131:
132: newOut1 = new PrintStream(out1);
133:
134: System.setErr(newOut1);
135:
136: text.addDisposeListener(new DisposeListener() {
137: public void widgetDisposed(DisposeEvent e) {
138: System.setOut(oldOut);
139: System.setErr(oldOut1);
140: // ErrorView.setOld("");
141: }
142:
143: });
144: text.addModifyListener(new ModifyListener() {
145: public void modifyText(ModifyEvent event) {
146:
147: ErrorLogStringBuffer.resetString(text.getText());
148:
149: }
150: });
151: /*
152: * Menu menu = new Menu(text); menu = text.getMenu(); MenuItem editItem =
153: * new MenuItem(menu, SWT.CASCADE); editItem.setText("clear");
154: * editItem.addSelectionListener(new SelectionAdapter() { public void
155: * widgetSelected(final SelectionEvent e) { text.setText(""); } });
156: * menu.addMenuListener(new MenuAdapter() { public void
157: * menuShown(MenuEvent e) {
158: * } });
159: */
160:
161: }
162:
163: public void setFocus() {
164: text.setFocus();
165:
166: }
167:
168: /**
169: * For testing purposes only.
170: *
171: * @return the table viewer in the favorites view
172: */
173: public Text getErrorlog() {
174: return text;
175: }
176:
177: public void setText(String content) {
178: text.setText(content + "\n");
179: }
180:
181: public String getText() {
182: return text.getText();
183: }
184:
185: public void appendText(String content) {
186: text.append(content);
187: }
188:
189: /**
190: * Lazily initialize and answer the clipboard
191: *
192: * @return the clipboard (not <code>null</code>)
193: */
194: public Clipboard getClipboard() {
195: if (clipboard == null)
196: clipboard = new Clipboard(getSite().getShell().getDisplay());
197: return clipboard;
198: }
199:
200: /**
201: * Disposes of this view. Clients should not call this method; it is called
202: * by the Eclipse infrastructure.
203: * <p>
204: * This is the last method called on the view. At this point the part
205: * controls (if they were ever created) have been disposed as part of an SWT
206: * composite. There is no guarantee that createPartControl() has been
207: * called, so the part controls may never have been created.
208: * <p>
209: * Within this method a part may release any resources, fonts, images,
210: * etc. held by this part. It is also very important to deregister all
211: * listeners from the workbench.
212: */
213: public void dispose() {
214: // ErrorView.setOld(oldOut.toString());
215: }
216:
217: public void init(IViewSite site, IMemento memento)
218: throws PartInitException {
219:
220: super.init(site, memento);
221: this.memento = memento;
222: }
223: }
|