KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > omg > lifl > eclipse > plugin > utils > OutputToConsole


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2003 USTL - LIFL - GOAL
5 Contact: openccm-team@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Offroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 /*
27  * Created on 27 juin 2003
28  *
29  */

30 package org.omg.lifl.eclipse.plugin.utils;
31
32 import java.util.Vector JavaDoc;
33
34 import org.eclipse.swt.graphics.Point;
35 import org.eclipse.ui.IWorkbench;
36 import org.eclipse.ui.IWorkbenchPage;
37 import org.eclipse.ui.IWorkbenchWindow;
38 import org.eclipse.ui.PartInitException;
39 import org.eclipse.ui.PlatformUI;
40 import org.omg.lifl.eclipse.plugin.shell.views.OpenCCMConsole;
41
42 /**
43  * @author offroy
44  *
45  */

46 public class OutputToConsole {
47     private static String JavaDoc err;
48     private static String JavaDoc out;
49     private static OpenCCMConsole console;
50     private static StringBuffer JavaDoc textBuffer = new StringBuffer JavaDoc();
51     private static Vector JavaDoc errorHighlight = new Vector JavaDoc();
52
53     public static boolean init()
54     {
55         IWorkbenchWindow window;
56         IWorkbench workbench = PlatformUI.getWorkbench();
57         window = workbench.getActiveWorkbenchWindow();
58         if(window == null)
59             return false;
60         IWorkbenchPage page = window.getActivePage();
61         if(page == null)
62             return false;
63         try
64         {
65             console = (OpenCCMConsole)page.findView(OpenCCMConsole.CONSOLE_ID);
66             if(console == null)
67             {
68                 page.showView(OpenCCMConsole.CONSOLE_ID);
69                 console = (OpenCCMConsole)page.findView("org.omg.lifl.eclipse.plugin.shell.views.OpenCCMConsole");
70             }
71             if (console == null) System.out.println("console null");
72         }
73         catch(PartInitException e)
74         {
75             e.printStackTrace();
76         }
77         if(err == null)
78             err = "";
79         if(out == null)
80             out = "";
81         if(err == null)
82             if(out != null);
83         return true;
84     }
85
86     public static void addError(String JavaDoc errorString)
87     {
88         errorHighlight.addElement(new Point(textBuffer.length(), errorString.length() - 1));
89         textBuffer.append(errorString);
90     }
91
92     public static void addOutString(String JavaDoc outString)
93     {
94         textBuffer.append(outString);
95     }
96
97     public static void clear()
98     {
99         textBuffer = new StringBuffer JavaDoc();
100         errorHighlight = new Vector JavaDoc();
101         start();
102     }
103
104     public static void start()
105     {
106         console.refresh(textBuffer.toString(), errorHighlight);
107     }
108
109
110     /**
111      * @return
112      */

113     public static OpenCCMConsole getConsole() {
114         return console;
115     }
116
117     /**
118      * @param console
119      */

120     public static void setConsole(OpenCCMConsole console) {
121         OutputToConsole.console = console;
122     }
123
124 }
125
Popular Tags