下面列出了org.eclipse.ui.console.MessageConsole#newMessageStream ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public OutputStream getOutputStream(final OutputStreamType type, OutputRedirection redirect) {
if (!PlatformUI.isWorkbenchRunning()) {
return DEFAULT.getOutputStream(type, redirect);
}
final MessageConsole console = consoleSupplier.get();
boolean silent = redirect == OutputRedirection.SUPPRESS;
if (!silent) {
console.activate();
}
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console });
final MessageConsoleStream stream = console.newMessageStream();
getDisplay().asyncExec(() -> {
stream.setColor(toColor(type));
showConsoleView(silent);
});
return stream;
}
public ConsoleContext ( final MessageConsole messageConsole )
{
this.writerStream = messageConsole.newMessageStream ();
final MessageConsoleStream errorStream = messageConsole.newMessageStream ();
errorStream.setColor ( Display.getDefault ().getSystemColor ( SWT.COLOR_RED ) );
this.errorPrintWriter = new PrintWriter ( new OutputStreamWriter ( errorStream ) );
this.logStream = messageConsole.newMessageStream ();
this.logStream.setColor ( Display.getDefault ().getSystemColor ( SWT.COLOR_GRAY ) );
}
@Override
public CommandConsole get(String name, String title) throws IOException {
MessageConsole console = findConsole(name);
MessageConsoleStream stream = console.newMessageStream();
stream.setActivateOnWrite(true);
stream.write("*** " + title + " ***\n");
return new CommandConsoleImpl(console);
}
@VisibleForTesting
MessageConsoleStream createNewMessageConsole() {
MessageConsole console = MessageConsoleUtilities.getMessageConsole(
Messages.getString("configuring.cloud.sdk"), // $NON-NLS-1$
null /* imageDescriptor */);
setProperty(IProgressConstants.ACTION_PROPERTY, new ShowConsoleViewAction(console));
return console.newMessageStream();
}
private PrintStream getConsolePrintStream() {
final MessageConsole console = EclipseUtils.getOrCreateConsole("Resource Loading Statistics", true, true);
final PrintStream out = new PrintStream(console.newMessageStream());
return out;
}
public DockerClientMessageConsole(String name) {
ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager conMan = plugin.getConsoleManager();
IConsole[] existing = conMan.getConsoles();
for (int i = 0; i < existing.length; i++) {
if (name.equals(existing[i].getName())) {
dockerMessageConsole = (MessageConsole) existing[i];
dockerConsoleOut = dockerMessageConsole.newMessageStream();
return;
}
}
// no console found, so create a new one
Bundle bundle = Platform.getBundle("com.zenika.doclipser.api");
ImageDescriptor imageDcr = ImageDescriptor.createFromURL(
FileLocator.find(bundle,
new Path("icons/docker-solo.gif"),
null));
MessageConsole dockerConsole = new MessageConsole(name, imageDcr);
conMan.addConsoles(new IConsole[] { dockerConsole });
dockerMessageConsole = dockerConsole;
dockerConsoleOut = dockerMessageConsole.newMessageStream();
// Currently does not work: win is always null
// (I guess because we are not in the main UI Thread)
//
// // get current active page
// IWorkbench wb = PlatformUI.getWorkbench();
// IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
//
// // on new versions it may need to be changed to:
// IWorkbenchPage page = win.getActivePage();
//
// // Reveal the console view
// String id = IConsoleConstants.ID_CONSOLE_VIEW;
// IConsoleView view;
// try {
// view = (IConsoleView) page.showView(id);
// view.display(dockerConsole);
// } catch (PartInitException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
/**
* Returns the path to the gwt-dev-xxx.jar in the event that the launch configuration depends on a
* GWT Contributor Runtime. Otherwise, returns the empty string.
*/
private static String maybeGetDevJarPath(IJavaProject project) {
/*
* In order to figure out whether or not to add the -Dgwt.devjar argument to the list of VM
* args, we have to figure out the runtime that this launch configuration depends on. If the
* project is one of the GWT Runtime projects, then we'll definitely have to add the
* -Dgwt.devjar argument to the launch configuration.
*/
try {
if (GWTProjectsRuntime.isGWTRuntimeProject(project)) {
// Synthesize a temporary contributor SDK so that we can use it
// to compute the devjar path
GwtSdk tempContribSDK = GWTProjectsRuntime.syntheziseContributorRuntime();
if (tempContribSDK.validate().isOK()) {
return tempContribSDK.getDevJar().getAbsolutePath();
} else {
return "";
}
}
GwtSdk sdk = GwtSdk.findSdkFor(project);
if (sdk == null) {
MessageConsole messageConsole =
MessageConsoleUtilities.getMessageConsole(project.getProject().getName() + "-GWT", null);
messageConsole.activate();
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] {messageConsole});
final ConsoleColorProvider consoleColorProvider = new ConsoleColorProvider();
final MessageConsoleStream console = messageConsole.newMessageStream();
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
console.setColor(consoleColorProvider.getColor(IDebugUIConstants.ID_STANDARD_ERROR_STREAM));
}
});
console.println("GWT SDK not installed.");
try {
console.close();
} catch (IOException e) {
GWTPluginLog.logError(e, "Unable to close output stream to console");
}
return "";
} else if (sdk.usesGwtDevProject()) {
File gwtDevJarFile = sdk.getDevJar();
return gwtDevJarFile.getAbsolutePath();
}
} catch (SdkException sdke) {
GWTPluginLog.logError(sdke, "Unable to extract gwt dev jar argument from GWTProjectsRuntime");
} catch (JavaModelException jme) {
GWTPluginLog.logError(jme, "Unable to extract gwt dev jar argument from GWTProjectsRuntime");
}
return "";
}
/**
* Returns {@link MessageConsoleStream} to the plugin console
*
* @return message console stream
*/
public static MessageConsoleStream getConsoleStream() {
final MessageConsole pluginConsole = findConsole(PLUGIN);
return pluginConsole.newMessageStream();
}