`
Dollyn
  • 浏览: 168715 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

FAQ How do I write to the console from a plug-in?

 
阅读更多

Many of the people asking this question are confused by the fact that two Eclipse instances are in use when you are developing plug-ins. One is the development platform you are using as your IDE, and the other is the target platform—also known as the runtime workbench—consisting of the plug-ins in the development workbench you are testing against. When a plug-in in the target platform writes a message to System.out or System.err , the message appears in the Console view of the development platform. This view emulates the Java console that appears when Eclipse runs under Windows with java.exe . You should be writing to the console only in this manner when in debug mode (see FAQ_How_do_I_use_the_platform_debug_tracing_facility? ).


In some situations however, a plug-in in the development platform has a legitimate reason to write to the development platform Console view. Some tools originally designed for the command line, such as Ant and CVS, traditionally use console output as a way of communicating results to the tool user. When these tools are ported for use with an IDE, this console output is typically replaced with richer forms of feedback, such as views, markers, and decorations. However, users accustomed to the old command-line output may still want to see this raw output as an alternative to other visual forms of feedback. Tools in this category can use the Console view to write this output.


Prior to Eclipse 3.0, each plug-in that wanted console-like output created its own Console view. Eclipse 3.0 provides a single generic Console view that all plug-ins can write to. The view can host several console documents at once and allows the user to switch between different console pages. Each page in the console is represented by an org.eclipse.ui.console.IConsole object. To write to the console, you need to create your own IConsole instance and connect it to the Console view. For a console containing a simple text document, you can instantiate a MessageConsole instance. Here is a method that locates a console with a given name and creates a new one if it cannot be found:

   private MessageConsole findConsole(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()))
return (MessageConsole) existing[i];
//no console found, so create a new one
MessageConsole myConsole = new MessageConsole(name, null);
conMan.addConsoles(new IConsole[]{myConsole});
return myConsole;
}


Once a console is created, you can write to it either by directly modifying its IDocument or by opening an output stream on the console. This snippet opens a stream and writes some text to a console:

   MessageConsole myConsole = findConsole(CONSOLE_NAME);
MessageConsoleStream out = myConsole.newMessageStream();
out.println("Hello from Generic console sample action");


Creating a console and writing to it do not create or reveal the Console view. If you want to make that sure the Console view is visible, you need to reveal it using the usual workbench API. Even once the Console view is revealed, keep in mind that it may contain several pages, each representing a different IConsole provided by a plug-in. Additional API asks the Console view to display your console. This snippet reveals the Console view and asks it to display a particular console instance:

   IConsole myConsole = ...;//your console instance
IWorkbenchPage page = ...;//obtain the active page
String id = IConsoleConstants.ID_CONSOLE_VIEW;
IConsoleView view = (IConsoleView) page.showView(id);
view.display(myConsole);

转自http://wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in%3F

分享到:
评论

相关推荐

    linux howto中文合集

    这个是合集~一般是这里最全的了 另外加的 PDF是英文的 .为 GCC4.1的HOWTO &lt;br&gt;目录 &lt;br&gt;ADSM-Backup-html&lt;br&gt;Advocacy&lt;br&gt;Automount-html&lt;br&gt;Battery-Powered-html&lt;br&gt;BootPrompt-HOWTO&lt;br&gt;Bridge-......

    word自动转化为chm

    A: Connection to Microsoft Word may be blocked by the anti-virus plug-in for Microsoft Office or other security software. Please see “Working with Security Software” for solution. Q: Error while ...

    LePutty SSH Connection 串口联机serial

    in the manuals, read the Feedback page to find out how to report bugs to us. PLEASE read the Feedback page carefully: it is there to save you time as well as us. Do not send us one-line bug reports ...

    eSDK Storage V100R005C10 快速指引 01(SCOM, Plug-in)

    《eSDK Storage V100R005C10 快速指引 01 (SCOM, Plug-in)》是一份针对System Center Operations Manager (SCOM)与华为存储设备集成使用的详细指南。SCOM是一款由微软开发的企业级监控工具,能够对IT基础设施进行全...

    Sakemail

    Serge Wagener put me to work &gt;:|1.8.4- Dmitry Bondarenko (again) has found a bug in wich I do not respect the RFC, wich say that replys from the SMTP server could be multi-line, and the previous ...

    Java邮件开发Fundamentals of the JavaMail API

    Instructions on how to download and install the JavaMail API are contained in the course. In addition, you will need a development environment such as the JDK 1.1.6+ or the Java 2 Platform, Standard...

    纯英文版 C-FAQ chm

    Q: How should I decide which integer type to use? -------------------------------------------------------------------------------- A: If you might need large values (above 32,767 or below -32,767...

    Linux Howto 中文文档

    META-FAQ (7KB) 一份有用资讯来源的列表 Networking-HOWTO (20KB) 针对 Linux 作业系统的网路能力提出一个概观的说明 News-HOWTO (20KB) 如何设定、维护在 Linux 系统下的 USENET News 伺服器 ...

    NetBackup1011_vSphereClient_HTML5_Plug-in_Guide.pdf

    VERITAS Technologies LLC 提供了多种文档和资源,包括用户手册、指南、FAQ 等,来帮助用户快速了解和使用 NetBackup™ 插件。用户可以访问 VERITAS Technologies LLC 的网站,获取最新的文档和资源。

    python-3.6-book

    howto-argparse.pdf howto-clinic.pdf howto-cporting.pdf howto-curses.pdf howto-descriptor.pdf howto-functional.pdf howto-instrumentation.pdf howto-ipaddress.pdf howto-logging.pdf howto-logging-cookbook...

    LuaUnicode icu-lua

    It may be that your operating system has a locale that implements the sorting algorithm that you want, in which case you can just use that, otherwise you will have to write a function to sort Unicode ...

    CanFestival3. Version 3.0 The CANOpen stack manual

    3. **Testing and Validation**: Test the node in a controlled environment to ensure compliance with the CANopen standard and proper functionality. #### 5. FAQ The FAQ section addresses common ...

    RealThinClientSDK_v610_BETA

    When you start working on your project, the FAQ will come in handy when you have to do something specific (use Sessions, accept form post data, write and call remote functions, etc). The FAQ is ...

    Chinese-Linux-HOWTO

    《Chinese-Linux-HOWTO》是一份详细的指南,专注于在中文环境下配置和使用Linux操作系统。这份文档深入到源码级别,旨在帮助用户理解和解决在安装、配置和使用中文Linux时遇到的各种问题。它不仅适用于初学者,也对...

    apktool documentation

    compressionType - Used to determine the compression that resources.arsc had on the original apk in order to replicate during [b]uild unknownFiles - Used to record name/location of non-standard files...

    rubyinstaller-devkit-2.5.3-1-x64.exe

    The MSYS2 development environment can be activated in the running cmd or powershell console by ridk enable. This adds commands like make, gcc, pacman or sh to the search path. See more in the Wiki. ...

    ethminer-0.16.0.dev3

    from a Windows command prompt or Linux console, or create shortcuts to predefined command lines using a Linux Bash script or Windows batch/cmd file. For a full list of available command, please run: ...

    王小平版遗传算法的光盘源代码

    Here is how the properties of a function are assigned in make_function_table(pop_struct *pop): pop[0].function_table[0].arity = 2; pop[0].function_table[0].macro = FALSE; pop[0].function_...

    WPTools.v6.29.1.Pro

    specify the fieldname in the format string, i.e. "f:name=RTF" to save or load the contents of the field "name". + There is an overloaded LoadFromString which expects a WideString as parameter (Delphi...

Global site tag (gtag.js) - Google Analytics