forked from srizzo/code2code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsole.java
More file actions
70 lines (64 loc) · 1.79 KB
/
Copy pathConsole.java
File metadata and controls
70 lines (64 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package code2code.utils;
import java.io.IOException;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;
/**
* Utility to output test to the console
*/
public class Console
{
/** the constant name of the console used to write the result of the template instantation to */
private static final String CONSOLE_NAME = "code2code.console";
/**
* @return
* the console to use for output
*/
private static MessageConsole getConsole()
{
ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager manager = plugin.getConsoleManager();
IConsole[] existing = manager.getConsoles();
for (int i = 0; i < existing.length; i++)
{
if (CONSOLE_NAME.equals(existing[i].getName()))
{
return (MessageConsole) existing[i];
}
}
MessageConsole myConsole = new MessageConsole(CONSOLE_NAME, null);
manager.addConsoles(new IConsole[] {myConsole});
return myConsole;
}
/**
* Write the specified text to the console
* @param p_text
* @throws IOException
*/
public static void write(String p_text) throws IOException
{
MessageConsole console = getConsole();
ConsolePlugin.getDefault().getConsoleManager().showConsoleView(console);
MessageConsoleStream out = console.newMessageStream();
try
{
out.println(p_text);
}
finally
{
out.flush();
out.close();
}
}
/**
* Used by tests
* @return
* the text currently on the console
*/
public static String getText()
{
return getConsole().getDocument().get();
}
}