You are on page 1of 24

Search

vogella.com Tutorials Training

Books

Contact us

213

Free tutorial, donate to support

Extending the Eclipse IDE - Plug-in Development Tutorial


Lars Vogel
Version 2.5 Copyright 2007, 2008, 2009, 2010, 2011, 2012, 2013 Lars Vogel 10.06.2013
Revision History

by Lars Vogel

Revision 0.1

01.04.2008

Lars Vogel Lars Vogel

Created

Revision 0.2 - 2.5

14.04.2009 - 10.06.2013

bugfixes and enhancements

Eclipse Plug-ins Tutorial This article describes the creation and deployment of Eclipse plug-ins. The article is based on Eclipse 4.2 (Eclipse Juno) and Java 1.6.

Table of Contents
1. Developing Eclipse plug-ins 2. Prerequisites 3. Installation 3.1. Downloading or upgrading 3.2. Download the Eclipse plug-in distribution 3.3. Update an Eclipse Java IDE 4. Exercise: Developing a simple plug-in 4.1. Create project 4.2. Start an Eclipse IDE with your plug-in 5. Local deployment of your plug-in 5.1. Options for installation 5.2. Installing your plug-in from your Eclipse IDE 5.3. Export plug-in and put into dropins folder 6. Create update site for your plug-in 6.1. Creating update sites 6.2. Create feature project 6.3. Create category definition 6.4. Create an update site 6.5. Install feature via the Eclipse update manager 7. Exercise: Deploy and install your plug-in via update site 8. Contribute a menu to existing Part 8.1. Overview 8.2. Contribute to package explorer 8.3. Restrict the extension - Visible When 9. Resources and Marker 10. Tutorial: Create Markers for resources 11. Adapters 11.1. Overview 11.2. Example 12. Eclipse Resources 13. Tools 13.1. Eclipse Yari

13.2. VisualVM 13.3. JVM Monitor 14. Thank you 15. Questions and Discussion 16. Links and Literature 16.1. Source Code 16.2. Eclipse Resources 16.3. vogella Resources

1. Developing Eclipse plug-ins


A software component in Eclipse is called a plug-in. The Eclipse IDE allows the developer to extend the IDE functionality via plug-ins. For example you can create new menu entries and associated actions via plug-ins.

2. Prerequisites
This tutorial assumes that you are already familiar with standard Java development with the Eclipse IDE .

3. Installation
3.1. Downloading or upgrading
To get the required Eclipse tooling for plug-in development you can download a special version of Eclipse to develop plug-ins or your can upgrade an existing Eclipse Java IDE. Both approaches require that you have Java already installed.

3.2. Download the Eclipse plug-in distribution


Browse to the Eclipse download site and download the Eclipse Classic package.

Extract the zip file in a folder of your selection.

Warning
Avoid having special characters or spaces in the path to your extract Eclipse.

3.3. Update an Eclipse Java IDE


In case you have installed the Eclipse Java IDE (or any other non RCP flavor) distribution you can use the Eclipse update manager to install the plug-ins required for RCP development. To open the update manager select Help Install new Software... from the Eclipse menu.

Install General Purpose Tools Eclipse Plug-in Development Environment Eclipse RCP Plug-in Developer Resources from the Eclipse update site for your release. This would be for example http://download.eclipse.org/releases/kepler for the Eclipse 4.3. release. You may have to remove the Group items by category flag to see all available features.

4. Exercise: Developing a simple plug-in


4.1. Create project
In this exercise you create a plug-in which contributes a menu entry to the standard Eclipse menu. Create a new plug-in project called c o m . v o g e l l a . p l u g i n . f i r s tvia File New Project Plug-in Development Plug-in Project. Enter the data as depicted in the following screenshots.

Select the Hello, World Command! template and press the Next button.

The last page of the wizard allows you to customize the values of the wizard. You can leave the default values and press the Finish button.

Eclipse may ask you if you want to switch to the plug-in development perspective. Answer Yes if you are prompted.

As result the following project is created.

4.2. Start an Eclipse IDE with your plug-in


Eclipse allows you to start a new Eclipse IDE with your plug-in included. For this, select either your project folder or your M A N I F E S T . M Ffile, right-click on it and select Run-As Eclipse Application.

A new Eclipse workbench starts. This runtime Eclipse has your new menu entry included. If you select this menu entry a message box will be displayed.

Database Management
www.synametrics.com

WinSQL - A Homogeneous Solution for Heterogeneous Environment.

5. Local deployment of your plug-in


5.1. Options for installation
You have several options to make your plug-in available in your Eclipse IDE. You can: Install your plug-in directly into your Eclipse installation from your Eclipse IDE. This option is useful for a quick installation test during development. Export your plug-in and copy it into your Eclipse installation into the d r o p i n sfolder. This option is

useful for a simple distribution scenario, you only have to provide the exported plug-in to your users. On the other hand it is not very convenient for the end user as it requires manual file copying and provides no simple way to update the plug-in. Create a update site and use the Eclipse update manager to install it from this site. This is a bit more complex to setup but is the most simple for the end user and provides the developer with a simple way to provide updates to all users.

5.2. Installing your plug-in from your Eclipse IDE


You can install your plug-in directly into your running Eclipse IDE. The Eclipse plug-in export wizard has an option for this. Open the export wizard via File Export Plug-in Development Deployable plug-ins and fragments.

In the export wizard dialog select in this case Install into host. Repository. This is depicted in the following screenshot.

5.3. Export plug-in and put into dropins folder


If you export your plug-in locally you can put it into the Eclipse d r o p i n sfolder of your Eclipse installation. After a restart of your Eclipse your plug-in should be available and ready for use. Open again the export wizard via File Export Plug-in Development Deployable plug-ins and fragments. Select the plug-in you want to export and the folder to which this plug-in should get exporTheTheted.

Press the Finish button. This creates a J A Rfile with the exported plug-in in the selected directory. Copy this J A Rfile to the d r o p i n sdirectory in your Eclipse installation directory and restart your runnig Eclipse. After this restart your new plug-in is available in your Eclipse installation and ready to be used.

6. Create update site for your plug-in


6.1. Creating update sites
You can also create an update site for your plug-in. An update site consists of static files which can be placed on a fileserver or a web server. Other users can install Eclipse plug-in from this update site. This requires that you create a feature project for the plug-in. You can export this feature project and use the Eclipse update manager to install the feature (with the plug-in). By default the Eclipse update manager shows only features with a category. Therefore you should always include a category for your exported feature to make it easy for the user to install your feature.

6.2. Create feature project


Create a feature project for your plug-in and add your plug-in to this feature. You create a feature project via File New Other... Plug-in Development Feature Project. Create the feature project similar to the following screenshots.

6.3. Create category definition


In your feature project create via the menu entry File New Other... Plug-in development Category Definition a new category definition.

Press the New Category button and create a category with a name which describes your functionality. Add your feature to this category.

6.4. Create an update site


You can create an update site for your feature in a local directory on your machine. For this, select File Export Deployable features.

To use your category, switch to the Options tab and select the path to your c a t e g o r y . x m lfile in the Categorize repository option.

6.5. Install feature via the Eclipse update manager


Use the Eclipse update manager via Help Install new software to install this new feature into your Eclipse IDE. Use the update manager and point to your local directory and select and install your feature. In case you don't see your feature, try deselecting the Group items by category flag. In this case you have forgotten to use your category during the export.

Restart the Eclipse IDE after the installation. Afterwards plug-in is available in your Eclipse installation and can be used.

7. Exercise: Deploy and install your plug-in via update site


Create a feature project for your c o m . v o g e l l a . p l u g i n . f i r s tplug-in and export it as Eclipse update site. Use the Eclipse update manager to install the new feature into your Eclipse IDE.

8. Contribute a menu to existing Part


8.1. Overview
In this example we will add a new context menu entry to the Package Explorer part. The context menu is displayed if the user select a file in the package explorer via a right mouse click. We will offer the

option to create a HTML page from a Java source file. To contribute to an existing menu or toolbar you need to know the corresponding ID. This ID can be found via the Menu Spy. See Eclipse Source Code Guide for details.

8.2. Contribute to package explorer


This tutorial uses Eclipse Commands. See Eclipse Commands Tutorial to learn how to work with commands. Create a new plug-in project called de.vogella.plugin.htmlconverter. Do not use a template. Select the Dependencies tab of the file p l u g i n . x m land add the following dependencies to your plugin. org.eclipse.jdt.core org.eclipse.core.resources org.eclipse.core.runtime org.eclipse.core.resources org.eclipse.core.expressions Add a command with the ID d e . v o g e l l a . p l u g i n . h t m l c o n v e r t e r . c o n v e r tand the default handler d e . v o g e l l a . p l u g i n . h t m l c o n v e r t e r . h a n d l e r . C o n v e r t H a n d l e rto your plug-in. Add this command to the menu via the extension point o r g . e c l i p s e . u i . m e n u sand use as the "locationURI" p o p u p : o r g . e c l i p s e . j d t . u i . P a c k a g e E x p l o r e r . Set the label to "Create HTML" for this contribution. The resulting file p l u g i n . x m lshould look like the following.
< ? x m lv e r s i o n = " 1 . 0 "e n c o d i n g = " U T F 8 " ? > < ? e c l i p s ev e r s i o n = " 3 . 4 " ? > < p l u g i n > < e x t e n s i o np o i n t = " o r g . e c l i p s e . u i . m e n u s " > < m e n u C o n t r i b u t i o nl o c a t i o n U R I = " p o p u p : o r g . e c l i p s e . j d t . u i . P a c k a g e E x p l o r e r " > < c o m m a n dc o m m a n d I d = " d e . v o g e l l a . p l u g i n . h t m l c o n v e r t e r . c o n v e r t " l a b e l = " C r e a t eH T M L "s t y l e = " p u s h " > < / c o m m a n d > < / m e n u C o n t r i b u t i o n > < / e x t e n s i o n > < e x t e n s i o np o i n t = " o r g . e c l i p s e . u i . c o m m a n d s " > < c o m m a n dd e f a u l t H a n d l e r = " d e . v o g e l l a . p l u g i n . h t m l c o n v e r t e r . h a n d l e r . C o n v e r t H a n d l e r " i d = " d e . v o g e l l a . p l u g i n . h t m l c o n v e r t e r . c o n v e r t "n a m e = " C o n v e r t " > < / c o m m a n d > < / e x t e n s i o n > < / p l u g i n >

Eclipse allows to save additional information for each file. You can use the I R e s o u r c einterface and the s e t P e r s i s t e n t P r o p e r t y ( )and g e t P e r s i s t e n t P r o p e r t y ( )methods. With these functions you can save Strings on files. We use these functions to save a directory for Java source files which already were exported via HTML. Create the following C o n v e r t H a n d l e rclass.
p a c k a g ed e . v o g e l l a . p l u g i n . h t m l c o n v e r t e r . h a n d l e r ; i m p o r tj a v a . i o . B u f f e r e d W r i t e r ; i m p o r tj a v a . i o . F i l e W r i t e r ; i m p o r tj a v a . i o . I O E x c e p t i o n ; i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t o r g . e c l i p s e . c o r e . c o m m a n d s . A b s t r a c t H a n d l e r ; o r g . e c l i p s e . c o r e . c o m m a n d s . E x e c u t i o n E v e n t ; o r g . e c l i p s e . c o r e . c o m m a n d s . E x e c u t i o n E x c e p t i o n ; o r g . e c l i p s e . c o r e . r e s o u r c e s . I R e s o u r c e ; o r g . e c l i p s e . c o r e . r u n t i m e . C o r e E x c e p t i o n ; o r g . e c l i p s e . c o r e . r u n t i m e . Q u a l i f i e d N a m e ; o r g . e c l i p s e . j d t . c o r e . I C o m p i l a t i o n U n i t ; o r g . e c l i p s e . j d t . c o r e . J a v a M o d e l E x c e p t i o n ; o r g . e c l i p s e . j f a c e . d i a l o g s . M e s s a g e D i a l o g ; o r g . e c l i p s e . j f a c e . v i e w e r s . I S e l e c t i o n ; o r g . e c l i p s e . j f a c e . v i e w e r s . I S t r u c t u r e d S e l e c t i o n ; o r g . e c l i p s e . s w t . w i d g e t s . D i r e c t o r y D i a l o g ; o r g . e c l i p s e . s w t . w i d g e t s . S h e l l ; o r g . e c l i p s e . u i . h a n d l e r s . H a n d l e r U t i l ;

p u b l i cc l a s sC o n v e r t H a n d l e re x t e n d sA b s t r a c t H a n d l e r{

p r i v a t eQ u a l i f i e d N a m ep a t h=n e wQ u a l i f i e d N a m e ( " h t m l " ," p a t h " ) ; @ O v e r r i d e p u b l i cO b j e c te x e c u t e ( E x e c u t i o n E v e n te v e n t )t h r o w sE x e c u t i o n E x c e p t i o n{ S h e l ls h e l l=H a n d l e r U t i l . g e t A c t i v e S h e l l ( e v e n t ) ; I S e l e c t i o ns e l=H a n d l e r U t i l . g e t A c t i v e M e n u S e l e c t i o n ( e v e n t ) ; I S t r u c t u r e d S e l e c t i o ns e l e c t i o n=( I S t r u c t u r e d S e l e c t i o n )s e l ; O b j e c tf i r s t E l e m e n t=s e l e c t i o n . g e t F i r s t E l e m e n t ( ) ; i f( f i r s t E l e m e n ti n s t a n c e o fI C o m p i l a t i o n U n i t ){ c r e a t e O u t p u t ( s h e l l ,f i r s t E l e m e n t ) ; }e l s e{ M e s s a g e D i a l o g . o p e n I n f o r m a t i o n ( s h e l l ," I n f o " , " P l e a s es e l e c taJ a v as o u r c ef i l e " ) ; } r e t u r nn u l l ; } p r i v a t ev o i dc r e a t e O u t p u t ( S h e l ls h e l l ,O b j e c tf i r s t E l e m e n t ){ S t r i n gd i r e c t o r y ; I C o m p i l a t i o n U n i tc u=( I C o m p i l a t i o n U n i t )f i r s t E l e m e n t ; I R e s o u r c er e s=c u . g e t R e s o u r c e ( ) ; b o o l e a nn e w D i r e c t o r y=t r u e ; d i r e c t o r y=g e t P e r s i s t e n t P r o p e r t y ( r e s ,p a t h ) ; i f( d i r e c t o r y! =n u l l& &d i r e c t o r y . l e n g t h ( )>0 ){ n e w D i r e c t o r y=! ( M e s s a g e D i a l o g . o p e n Q u e s t i o n ( s h e l l ," Q u e s t i o n " , " U s et h ep r e v i o u so u t p u td i r e c t o r y ? " ) ) ; } i f( n e w D i r e c t o r y ){ D i r e c t o r y D i a l o gf i l e D i a l o g=n e wD i r e c t o r y D i a l o g ( s h e l l ) ; d i r e c t o r y=f i l e D i a l o g . o p e n ( ) ; } i f( d i r e c t o r y! =n u l l& &d i r e c t o r y . l e n g t h ( )>0 ){ s e t P e r s i s t e n t P r o p e r t y ( r e s ,p a t h ,d i r e c t o r y ) ; w r i t e ( d i r e c t o r y ,c u ) ; } } p r o t e c t e dS t r i n gg e t P e r s i s t e n t P r o p e r t y ( I R e s o u r c er e s ,Q u a l i f i e d N a m eq n ){ t r y{ r e t u r nr e s . g e t P e r s i s t e n t P r o p e r t y ( q n ) ; }c a t c h( C o r e E x c e p t i o ne ){ r e t u r n" " ; } } p r o t e c t e dv o i ds e t P e r s i s t e n t P r o p e r t y ( I R e s o u r c er e s ,Q u a l i f i e d N a m eq n , S t r i n gv a l u e ){ t r y{ r e s . s e t P e r s i s t e n t P r o p e r t y ( q n ,v a l u e ) ; }c a t c h( C o r e E x c e p t i o ne ){ e . p r i n t S t a c k T r a c e ( ) ; } } p r i v a t ev o i dw r i t e ( S t r i n gd i r ,I C o m p i l a t i o n U n i tc u ){ t r y{ c u . g e t C o r r e s p o n d i n g R e s o u r c e ( ) . g e t N a m e ( ) ; S t r i n gt e s t=c u . g e t C o r r e s p o n d i n g R e s o u r c e ( ) . g e t N a m e ( ) ; / /N e e d S t r i n g [ ]n a m e=t e s t . s p l i t ( " \ \ . " ) ; S t r i n gh t m l F i l e=d i r+" \ \ "+n a m e [ 0 ]+" . h t m l " ; F i l e W r i t e ro u t p u t=n e wF i l e W r i t e r ( h t m l F i l e ) ; B u f f e r e d W r i t e rw r i t e r=n e wB u f f e r e d W r i t e r ( o u t p u t ) ; w r i t e r . w r i t e ( " < h t m l > " ) ; w r i t e r . w r i t e ( " < h e a d > " ) ; w r i t e r . w r i t e ( " < / h e a d > " ) ; w r i t e r . w r i t e ( " < b o d y > " ) ; w r i t e r . w r i t e ( " < p r e > " ) ; w r i t e r . w r i t e ( c u . g e t S o u r c e ( ) ) ; w r i t e r . w r i t e ( " < / p r e > " ) ; w r i t e r . w r i t e ( " < / b o d y > " ) ; w r i t e r . w r i t e ( " < / h t m l > " ) ; w r i t e r . f l u s h ( ) ; }c a t c h( J a v a M o d e l E x c e p t i o ne ){ }c a t c h( I O E x c e p t i o ne ){ e . p r i n t S t a c k T r a c e ( ) ; } } }

If you start this plug-in you should be able to create HTML output from a Java source file.

8.3. Restrict the extension - Visible When


Currently our context menu is always displayed. We would like to show it only if a source file is selected. For this we will use a "visible-when" definition. Add the o r g . e c l i p s e . c o r e . e x p r e s s i o n splug-in as dependency to your plug-in. Select your menu contribution. Using the right mouse add the condition to the command that it should only be visible if a file is selected which represents a I C o m p i l a t i o n U n i tfrom the o r g . e c l i p s e . j d t . c o r epackage. For this exercise you use the predefined variable a c t i v e M e n u S e l e c t i o nwhich contains the selection in the menu and iterate over it. If the selection can get adapted to I C o m p i l a t i o n U n i tthen the contribution will be visible. This will result in the following p l u g i n . x m l .
< ? x m lv e r s i o n = " 1 . 0 "e n c o d i n g = " U T F 8 " ? > < ? e c l i p s ev e r s i o n = " 3 . 4 " ? > < p l u g i n > < e x t e n s i o n p o i n t = " o r g . e c l i p s e . u i . m e n u s " > < m e n u C o n t r i b u t i o n l o c a t i o n U R I = " p o p u p : o r g . e c l i p s e . j d t . u i . P a c k a g e E x p l o r e r " > < c o m m a n d c o m m a n d I d = " d e . v o g e l l a . p l u g i n . h t m l c o n v e r t e r . c o n v e r t " l a b e l = " C r e a t eH T M L " s t y l e = " p u s h " > < v i s i b l e W h e n c h e c k E n a b l e d = " f a l s e " > < w i t h v a r i a b l e = " a c t i v e M e n u S e l e c t i o n " > < i t e r a t e i f E m p t y = " f a l s e " o p e r a t o r = " o r " > < a d a p t t y p e = " o r g . e c l i p s e . j d t . c o r e . I C o m p i l a t i o n U n i t " > < / a d a p t > < / i t e r a t e > < / w i t h > < / v i s i b l e W h e n > < / c o m m a n d > < / m e n u C o n t r i b u t i o n > < / e x t e n s i o n > < e x t e n s i o n p o i n t = " o r g . e c l i p s e . u i . c o m m a n d s " > < c o m m a n d d e f a u l t H a n d l e r = " d e . v o g e l l a . p l u g i n . h t m l c o n v e r t e r . h a n d l e r . C o n v e r t " i d = " d e . v o g e l l a . p l u g i n . h t m l c o n v e r t e r . c o n v e r t "

n a m e = " C o n v e r t " > < / c o m m a n d > < / e x t e n s i o n > < / p l u g i n >

If you now start your plug-in, the menu entry should only be visible if at least one compilation unit has been selected.

9. Resources and Marker


Eclipse represents Resources like Projects, Files, Folders, Packages as I R e s o u r c e . Marker represent additional informations for resources, e.g. an error marker. Every marker can have attributes (key / value combination). Markers can be displayed in the standard view, e.g. the Task, Bookmark or the problems view. To be displayed in these views you have to use predefined attributes. The following will demonstrate how to create marker for a selected resource.

10. Tutorial: Create Markers for resources


Create a plug-in project "de.vogella.plugin.markers". Add the dependency to org.eclipse.core.resources", "org.eclipse.jdt.core" and "org.eclipse.jdt.ui". Create the command "de.vogella.plugin.markers.AddMarker" with the default handler A d d M a r k e r H a n d l e rin the d e . v o g e l l a . p l u g i n . m a r k e r s . h a n d l e rclass and add this command to the menu. Create the following code.
p a c k a g ed e . v o g e l l a . p l u g i n . m a r k e r s . h a n d l e r ; i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t o r g . e c l i p s e . c o r e . c o m m a n d s . A b s t r a c t H a n d l e r ; o r g . e c l i p s e . c o r e . c o m m a n d s . E x e c u t i o n E v e n t ; o r g . e c l i p s e . c o r e . c o m m a n d s . E x e c u t i o n E x c e p t i o n ; o r g . e c l i p s e . c o r e . r e s o u r c e s . I M a r k e r ; o r g . e c l i p s e . c o r e . r e s o u r c e s . I R e s o u r c e ; o r g . e c l i p s e . j d t . c o r e . I J a v a P r o j e c t ; o r g . e c l i p s e . j f a c e . v i e w e r s . I S t r u c t u r e d S e l e c t i o n ; o r g . e c l i p s e . u i . h a n d l e r s . H a n d l e r U t i l ;

p u b l i cc l a s sA d d M a r k e re x t e n d sA b s t r a c t H a n d l e r{ @ O v e r r i d e p u b l i cO b j e c te x e c u t e ( E x e c u t i o n E v e n te v e n t )t h r o w sE x e c u t i o n E x c e p t i o n{ I S t r u c t u r e d S e l e c t i o ns e l e c t i o n=( I S t r u c t u r e d S e l e c t i o n )H a n d l e r U t i l . g e t A c t i v e S i t e ( e v e n t ) . g e t S e l e c t i o n P r o v i d e r ( ) . g e t S e l e c t i o n ( ) ; i f( s e l e c t i o n= =n u l l ){ r e t u r nn u l l ; } O b j e c tf i r s t E l e m e n t=s e l e c t i o n . g e t F i r s t E l e m e n t ( ) ; i f( f i r s t E l e m e n ti n s t a n c e o fI J a v a P r o j e c t ){ I J a v a P r o j e c tt y p e=( I J a v a P r o j e c t )f i r s t E l e m e n t ; w r i t e M a r k e r s ( t y p e ) ; } r e t u r nn u l l ; } p r i v a t ev o i dw r i t e M a r k e r s ( I J a v a P r o j e c tt y p e ){ t r y{ I R e s o u r c er e s o u r c e=t y p e . g e t U n d e r l y i n g R e s o u r c e ( ) ; I M a r k e rm a r k e r=r e s o u r c e . c r e a t e M a r k e r ( I M a r k e r . T A S K ) ; m a r k e r . s e t A t t r i b u t e ( I M a r k e r . M E S S A G E ," T h i saat a s k " ) ; m a r k e r . s e t A t t r i b u t e ( I M a r k e r . P R I O R I T Y ,I M a r k e r . P R I O R I T Y _ H I G H ) ; }c a t c h( E x c e p t i o ne ){ e . p r i n t S t a c k T r a c e ( ) ; } } }

If you run you can create a marker in the TODO list if you select a Java project and click your menu entry.

11. Adapters
11.1. Overview
Adapters help to display information about objects in view without having to adjust the existing views. In this example we will create a small view which allows to select objects and use the properties view to display them. Adapters are used on several places for example you can use an adapter to display your data in the outline view. See Outline View Example for an example how to do this.

11.2. Example
We will simple use an adapter to show our data in the property view. Create a new plug-in project "de.vogella.plugin.adapter". Use the "Plug-in with a view" template with the following settings.

Add the dependency "org.eclipse.ui.views" in tab dependencies of plugin.xml. Create the following data model.
p a c k a g ed e . v o g e l l a . p l u g i n . a d a p t e r . m o d e l ;

p u b l i cc l a s sT o d o{ p r i v a t eS t r i n gs u m m a r y ; p r i v a t eS t r i n gd e s c r i p t i o n ; p u b l i cS t r i n gg e t S u m m a r y ( ){ r e t u r ns u m m a r y ; } p u b l i cv o i ds e t S u m m a r y ( S t r i n gs u m m a r y ){ t h i s . s u m m a r y=s u m m a r y ; } p u b l i cS t r i n gg e t D e s c r i p t i o n ( ){ r e t u r nd e s c r i p t i o n ; } p u b l i cv o i ds e t D e s c r i p t i o n ( S t r i n gd e s c r i p t i o n ){ t h i s . d e s c r i p t i o n=d e s c r i p t i o n ; } }

Change the code of SampleView.java to the following. After this change you should be able to run your project, open your view and see your todo items.
p a c k a g ed e . v o g e l l a . p l u g i n . a d a p t e r . v i e w s ; i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t i m p o r t o r g . e c l i p s e . j f a c e . v i e w e r s . A r r a y C o n t e n t P r o v i d e r ; o r g . e c l i p s e . j f a c e . v i e w e r s . I T a b l e L a b e l P r o v i d e r ; o r g . e c l i p s e . j f a c e . v i e w e r s . L a b e l P r o v i d e r ; o r g . e c l i p s e . j f a c e . v i e w e r s . T a b l e V i e w e r ; o r g . e c l i p s e . s w t . S W T ; o r g . e c l i p s e . s w t . g r a p h i c s . I m a g e ; o r g . e c l i p s e . s w t . w i d g e t s . C o m p o s i t e ; o r g . e c l i p s e . u i . I S h a r e d I m a g e s ; o r g . e c l i p s e . u i . P l a t f o r m U I ; o r g . e c l i p s e . u i . p a r t . V i e w P a r t ;

i m p o r td e . v o g e l l a . p l u g i n . a d a p t e r . m o d e l . T o d o ; p u b l i cc l a s sS a m p l e V i e we x t e n d sV i e w P a r t{ p u b l i cs t a t i cf i n a lS t r i n gI D=" d e . v o g e l l a . p l u g i n . a d a p t e r . v i e w s . S a m p l e V i e w " ; p r i v a t eT a b l e V i e w e rv i e w e r ; c l a s sV i e w L a b e l P r o v i d e re x t e n d sL a b e l P r o v i d e ri m p l e m e n t s I T a b l e L a b e l P r o v i d e r{ p u b l i cS t r i n gg e t C o l u m n T e x t ( O b j e c to b j ,i n ti n d e x ){ T o d ot o d o=( T o d o )o b j ; r e t u r nt o d o . g e t S u m m a r y ( ) ; } p u b l i cI m a g eg e t C o l u m n I m a g e ( O b j e c to b j ,i n ti n d e x ){ r e t u r ng e t I m a g e ( o b j ) ; } p u b l i cI m a g eg e t I m a g e ( O b j e c to b j ){ r e t u r nP l a t f o r m U I . g e t W o r k b e n c h ( ) . g e t S h a r e d I m a g e s ( ) . g e t I m a g e ( I S h a r e d I m a g e s . I M G _ O B J _ E L E M E N T ) ; } }

/ * * *T h i si sac a l l b a c kt h a tw i l la l l o wu st oc r e a t et h ev i e w e ra n di n i t i a l i z e *i t . * / p u b l i cv o i dc r e a t e P a r t C o n t r o l ( C o m p o s i t ep a r e n t ){ v i e w e r=n e wT a b l e V i e w e r ( p a r e n t ,S W T . M U L T I|S W T . H _ S C R O L L |S W T . V _ S C R O L L ) ; v i e w e r . s e t C o n t e n t P r o v i d e r ( n e wA r r a y C o n t e n t P r o v i d e r ( ) ) ; v i e w e r . s e t L a b e l P r o v i d e r ( n e wV i e w L a b e l P r o v i d e r ( ) ) ; g e t S i t e ( ) . s e t S e l e c t i o n P r o v i d e r ( v i e w e r ) ; v i e w e r . s e t I n p u t ( g e t E l e m e n t s ( ) ) ; }

/ * * *P a s s i n gt h ef o c u sr e q u e s tt ot h ev i e w e r ' sc o n t r o l . * / p u b l i cv o i ds e t F o c u s ( ){ v i e w e r . g e t C o n t r o l ( ) . s e t F o c u s ( ) ; } / /B u i l du pas i m p l ed a t am o d e l p r i v a t eT o d o [ ]g e t E l e m e n t s ( ){ T o d o [ ]t o d o s=n e wT o d o [ 2 ] ; T o d ot o d o=n e wT o d o ( ) ; t o d o . s e t S u m m a r y ( " F i r s tT o d o " ) ; t o d o . s e t D e s c r i p t i o n ( " Av e r yg o o dd e s c r i p t i o n " ) ; t o d o s [ 0 ]=t o d o ; t o d o=n e wT o d o ( ) ; t o d o . s e t S u m m a r y ( " S e c o n dT o d o " ) ; t o d o . s e t D e s c r i p t i o n ( " S e c o n ds u p e rd e s c r i p t i o n " ) ; t o d o s [ 1 ]=t o d o ; r e t u r nt o d o s ;

} }

To displays its values in the property view, add the extension point "org.eclipse.core.runtime.adapters" to your project. The data of the extension point should be like the following.
< e x t e n s i o n p o i n t = " o r g . e c l i p s e . c o r e . r u n t i m e . a d a p t e r s " > < f a c t o r y a d a p t a b l e T y p e = " d e . v o g e l l a . p l u g i n . a d a p t e r . m o d e l . T o d o " c l a s s = " d e . v o g e l l a . p l u g i n . a d a p t e r . T o d o A d a p t e r F a c t o r y " > < a d a p t e r t y p e = " o r g . e c l i p s e . u i . v i e w s . p r o p e r t i e s . I P r o p e r t y S o u r c e " > < / a d a p t e r > < / f a c t o r y > < / e x t e n s i o n >

Implement the factory and the new class "TodoPropertySource" which implements "IPropertySource".
p a c k a g ed e . v o g e l l a . p l u g i n . a d a p t e r ; i m p o r to r g . e c l i p s e . c o r e . r u n t i m e . I A d a p t e r F a c t o r y ; i m p o r to r g . e c l i p s e . u i . v i e w s . p r o p e r t i e s . I P r o p e r t y S o u r c e ; i m p o r td e . v o g e l l a . p l u g i n . a d a p t e r . m o d e l . T o d o ; p u b l i cc l a s sT o d o A d a p t e r F a c t o r yi m p l e m e n t sI A d a p t e r F a c t o r y{ @ O v e r r i d e p u b l i cO b j e c tg e t A d a p t e r ( O b j e c ta d a p t a b l e O b j e c t ,C l a s sa d a p t e r T y p e ){ i f( a d a p t e r T y p e = =I P r o p e r t y S o u r c e . c l a s s& &a d a p t a b l e O b j e c ti n s t a n c e o fT o d o ) { r e t u r nn e wT o d o P r o p e r t y S o u r c e ( ( T o d o )a d a p t a b l e O b j e c t ) ; } r e t u r nn u l l ; } @ O v e r r i d e p u b l i cC l a s s [ ]g e t A d a p t e r L i s t ( ){ r e t u r nn e wC l a s s [ ]{I P r o p e r t y S o u r c e . c l a s s} ; } }

p a c k a g ed e . v o g e l l a . p l u g i n . a d a p t e r ; i m p o r to r g . e c l i p s e . u i . v i e w s . p r o p e r t i e s . I P r o p e r t y D e s c r i p t o r ; i m p o r to r g . e c l i p s e . u i . v i e w s . p r o p e r t i e s . I P r o p e r t y S o u r c e ; i m p o r to r g . e c l i p s e . u i . v i e w s . p r o p e r t i e s . T e x t P r o p e r t y D e s c r i p t o r ; i m p o r td e . v o g e l l a . p l u g i n . a d a p t e r . m o d e l . T o d o ; p u b l i cc l a s sT o d o P r o p e r t y S o u r c ei m p l e m e n t sI P r o p e r t y S o u r c e{ p r i v a t ef i n a lT o d ot o d o ; p u b l i cT o d o P r o p e r t y S o u r c e ( T o d ot o d o ){ t h i s . t o d o=t o d o ; }

@ O v e r r i d e p u b l i cb o o l e a ni s P r o p e r t y S e t ( O b j e c ti d ){ r e t u r nf a l s e ; } @ O v e r r i d e p u b l i cO b j e c tg e t E d i t a b l e V a l u e ( ){ r e t u r nt h i s ; } @ O v e r r i d e p u b l i cI P r o p e r t y D e s c r i p t o r [ ]g e t P r o p e r t y D e s c r i p t o r s ( ){ r e t u r nn e wI P r o p e r t y D e s c r i p t o r [ ]{ n e wT e x t P r o p e r t y D e s c r i p t o r ( " s u m m a r y " ," S u m m a r y " ) , n e wT e x t P r o p e r t y D e s c r i p t o r ( " d e s c r i p t i o n " ," D e s c r i p t i o n " )} ; } @ O v e r r i d e p u b l i cO b j e c tg e t P r o p e r t y V a l u e ( O b j e c ti d ){ i f( i d . e q u a l s ( " s u m m a r y " ) ){ r e t u r nt o d o . g e t S u m m a r y ( ) ; } i f( i d . e q u a l s ( " d e s c r i p t i o n " ) ){ r e t u r nt o d o . g e t D e s c r i p t i o n ( ) ; } r e t u r nn u l l ; } @ O v e r r i d e p u b l i cv o i dr e s e t P r o p e r t y V a l u e ( O b j e c ti d ){

} @ O v e r r i d e p u b l i cv o i ds e t P r o p e r t y V a l u e ( O b j e c ti d ,O b j e c tv a l u e ){ S t r i n gs=( S t r i n g )v a l u e ; i f( i d . e q u a l s ( " s u m m a r y " ) ){ t o d o . s e t S u m m a r y ( s ) ; } i f( i d . e q u a l s ( " d e s c r i p t i o n " ) ){ t o d o . s e t D e s c r i p t i o n ( s ) ; } } }

If you run your workbench and open your View via Windows -> Show View -> Others -> Sample Category -> Sample View and the property view you should be able to view your data.

12. Eclipse Resources


You can register I R e s o u r c e C h a n g e L i s t e n e ron resources in Eclipse. For example if you have a project you can add or remove a resource listener to or from it.
/ /a d dl i s t e n e r p r o j e c t . g e t W o r k s p a c e ( ) . a d d R e s o u r c e C h a n g e L i s t e n e r ( l i s t e n e r ) ; / /R e m o v el i s t e n e r p r o j e c t . g e t W o r k s p a c e ( ) . r e m o v e R e s o u r c e C h a n g e L i s t e n e r ( l i s t e n e r ) ; / /E x a m p l er e s o u r c el i s t e n e r p r i v a t eI R e s o u r c e C h a n g e L i s t e n e rl i s t e n e r=n e wI R e s o u r c e C h a n g e L i s t e n e r ( ){ p u b l i cv o i dr e s o u r c e C h a n g e d ( I R e s o u r c e C h a n g e E v e n te v e n t ){ i f( e v e n t . g e t T y p e ( )= =I R e s o u r c e C h a n g e E v e n t . P R E _ C L O S E| |e v e n t . g e t T y p e ( )= =I R e s o u r c e C h a n g e E v e n t . P R E _ D E L E T E ){ i f( e v e n t . g e t R e s o u r c e ( ) . e q u a l s ( p r o j e c t ) ){ / /P r o j e c td e l e t e do rc l o s e d / /d os o m e t h i n g } r e t u r n ; } i f( r e s o u r c e= =n u l l ) r e t u r n ; I R e s o u r c e D e l t ad e l t a=e v e n t . g e t D e l t a ( ) . f i n d M e m b e r ( n e wP a t h ( r e s o u r c e . g e t U R I ( ) . t o P l a t f o r m S t r i n g ( f a l s e ) ) ) ; i f( d e l t a= =n u l l ){ r e t u r n ; } i f( d e l t a . g e t K i n d ( )= =I R e s o u r c e D e l t a . R E M O V E D ){ / /R e s o u r c ed e l e t e / /d os o m e t h i n g } } } ;

13. Tools
13.1. Eclipse Yari
It's a comprehensive tool suite to debug, spy, spider, inspect and navigate Eclipse based application GUIs (Workbench or RCP). http://sourceforge.net/projects/yari/

13.2. VisualVM

VisualVM is a debugging tool which can be integrated into Eclipse. http://visualvm.java.net/eclipselauncher.html

13.3. JVM Monitor


JVM Monitor is a Java profiler integrated with Eclipse to monitor CPU, threads and memory usage of Java applications. http://www.jvmmonitor.org/index.html

14. Thank you


Please help me to support this article:

15. Questions and Discussion


If you find errors in this tutorial, please notify me (see the top of the page). Please note that due to the high volume of feedback I receive, I cannot answer questions to your implementation. Ensure you have read the vogella FAQ as I don't respond to questions already answered there.

16. Links and Literature


16.1. Source Code
Source Code of Examples

16.2. Eclipse Resources


http://wiki.eclipse.org/Eclipse_Plug-in_Development_FAQ Eclipse Plug-in Development FAQ http://www.eclipse.org/articles/article.php?file=Article-Adapters/index.html Adapters in Eclipse http://www.eclipse.org/articles/Article-Resource-deltas/resource-deltas.html How to react to Eclipse resource deltas Using markers, annotations, and decorators in Eclipse (IBM) .

16.3. vogella Resources


vogella Training Android and Eclipse Training from the vogella team Android Tutorial Introduction to Android Programming GWT Tutorial Program in Java, compile to JavaScript and HTML Eclipse RCP Tutorial Create native applications in Java JUnit Tutorial Test your application Git Tutorial Put all your files in a distributed version control system

You might also like