Eclipse plug-in development: Implement console output information

Source: Internet
Author: User

During Eclipse plug-in development, you sometimes need to develop your own console for the plug-in, so that you can output the prompt information as necessary. This article describes how to implement your own console during Eclipse plug-in development.

1. Expand the console extension point.

Expand the org. Eclipse. UI. Console. consolefactories extension point and fill in necessary information, such as label and class. For example.

2. Implement the lelefactory class. Add org. Eclipse. UI. lele_3.4.0.v20090513.jar to the project. The version can be different.

Package project; import Org. eclipse. UI. console. leleplugin; import Org. eclipse. UI. console. iconsole; import Org. eclipse. UI. console. iconsolefactory; import Org. eclipse. UI. console. iconsolemanager; import Org. eclipse. UI. console. messageconsole; public class consolefactory implements iconsolefactory {Private Static messageconsole console = new messageconsole ("", null); static Boolean exists = false;/*** description: Open console **/Public void openconsole () {showconsole ();}/***** // *** Description: Display Console **/Private Static void showconsole () {If (console! = NULL) {// obtain the default console manager iconsolemanager manager = consoleplugin. getdefault (). getconsolemanager (); // get all console instances iconsole [] existing = manager. getreceivles (); exists = false; // if the newly created messageconsole instance does not exist, add it to the console manager and display it for (INT I = 0; I <existing. length; I ++) {If (console = existing [I]) exists = true;} If (! Exists) {manager. addconsoles (New iconsole [] {console});} // console. activate () ;}/ ***** // ***** Description: Disable the console **/public static void closeconsole () {iconsolemanager manager = consoleplugin. getdefault (). getconsolemanager (); If (console! = NULL) {manager. removeconsoles (New iconsole [] {console}) ;}/ *** obtain the console ** @ return */public static messageconsole getconsole () {showconsole (); return console ;}}

3. Outputs Information to the console.

/*** Print a message to the console and activate the console. ** @ Param message * @ Param activate * Whether to activate the console */public static void printtoconsole (string message, Boolean activate) {messageconsolestream printer = consolefactory. getconsole (). newmessagestream (); printer. setactivateonwrite (activate); printer. println ("prompt:" + message );}

To output information to the console, you only need to call the printtoconsole () function.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.