7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
1/24
213
Free tutorial, donate
to support
by Lars Vogel
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
Revision 0.1 01.04.2008 Lars
Vogel
Created
Revision 0.2 - 2.5 14.04.2009 - 10.06.2013 Lars
Vogel
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 y our 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 definition6.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 t o 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
vogella.com Tutorials Training Books Contact usSearch
http://-/?-http://-/?-http://-/?-http://-/?-http://www.vogella.com/books.htmlhttp://www.vogella.com/contact.htmlhttp://www.vogella.com/books.htmlhttp://training.vogella.com/index.htmlhttp://training.vogella.com/index.htmlhttps://profiles.google.com/104044918586174763681http://www.twitter.com/vogellahttp://www.vogella.com/contact.htmlhttp://www.vogella.com/books.htmlhttp://training.vogella.com/index.htmlhttp://www.vogella.com/tutorials.htmlhttp://www.vogella.com/http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://www.vogella.com/people/larsvogel.html7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
2/24
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 a lready 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 HelpInstall new Software... from the Eclipse menu.
http://www.eclipse.org/downloadshttp://www.vogella.com/articles/Eclipse/article.htmlhttp://www.vogella.com/articles/JavaIntroduction/article.htmlhttp://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://ad-emea.doubleclick.net/click;h=v8/3e87/2/0/*/k;273390097;1-0;0;103779257;2321-160/600;56014517/55903825/1;;~sscs=?http://newrelic.com/lp/clue-mobile?utm_source=SMIT&utm_medium=banner_ad&utm_content=mobile&utm_campaign=mobilelaunch&url_term=mobile&mpc=BA-SMIT-MOB-en-100-developermedia-Clue7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
3/24
7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
4/24
Select the Hello, World Command! template and press the Next button.
7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
5/24
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.
7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
6/24
Eclipse may ask you if you want to switch to the plug-in development perspective. A nswer 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 MANIFEST.MF file, right-click on it and select Run-As
Eclipse Application.
7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
7/24
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.
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 dropins folder. This option is
Database Managementwww.synametrics.com
WinSQL - A Homogeneous Solution for Heterogeneous Environment.
http://googleads.g.doubleclick.net/aclk?sa=L&ai=C0T-N-RNrUu-2EdKgigbJ_oGIB93yrg6hpZWTAcCNtwEQASD00tgPUOiT88kCYJUGyAEBqAMByAPTBKoEhQFP0B1Q6SCD746CWZwhfJqIqO25D5Sg4dIGaW5Lnj8VwYx4K5TFlYi8Xn6uYv9iM7-g7FSfIPHMeIRUHqhSa_oFqwAt7YYdq_s5neR4VA8_LOs6ao5XvwuivhIoUWukcaU4cuKUMJG6rn3AOlVxEcx83nJ7GIG68_v-43Oqja5eV1lTHZG5gAeIyEA&num=1&sig=AOD64_0PL5Yu0jRqbY__jFUEiAQh-hNGqg&client=ca-pub-3851443674951530&adurl=http://www.synametrics.com/SynametricsWebApp/WinSQL.jsp%3Frefid%3Dgooglehttp://googleads.g.doubleclick.net/aclk?sa=L&ai=C0T-N-RNrUu-2EdKgigbJ_oGIB93yrg6hpZWTAcCNtwEQASD00tgPUOiT88kCYJUGyAEBqAMByAPTBKoEhQFP0B1Q6SCD746CWZwhfJqIqO25D5Sg4dIGaW5Lnj8VwYx4K5TFlYi8Xn6uYv9iM7-g7FSfIPHMeIRUHqhSa_oFqwAt7YYdq_s5neR4VA8_LOs6ao5XvwuivhIoUWukcaU4cuKUMJG6rn3AOlVxEcx83nJ7GIG68_v-43Oqja5eV1lTHZG5gAeIyEA&num=1&sig=AOD64_0PL5Yu0jRqbY__jFUEiAQh-hNGqg&client=ca-pub-3851443674951530&adurl=http://www.synametrics.com/SynametricsWebApp/WinSQL.jsp%3Frefid%3Dgooglehttp://googleads.g.doubleclick.net/aclk?sa=L&ai=C0T-N-RNrUu-2EdKgigbJ_oGIB93yrg6hpZWTAcCNtwEQASD00tgPUOiT88kCYJUGyAEBqAMByAPTBKoEhQFP0B1Q6SCD746CWZwhfJqIqO25D5Sg4dIGaW5Lnj8VwYx4K5TFlYi8Xn6uYv9iM7-g7FSfIPHMeIRUHqhSa_oFqwAt7YYdq_s5neR4VA8_LOs6ao5XvwuivhIoUWukcaU4cuKUMJG6rn3AOlVxEcx83nJ7GIG68_v-43Oqja5eV1lTHZG5gAeIyEA&num=1&sig=AOD64_0PL5Yu0jRqbY__jFUEiAQh-hNGqg&client=ca-pub-3851443674951530&adurl=http://www.synametrics.com/SynametricsWebApp/WinSQL.jsp%3Frefid%3Dgoogle7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
8/24
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 FileExport
Plug-in DevelopmentDeployable plug-ins and fragments.
In the export wizard dialog select in this case Install into host. Repository. This is depicted in the
following screenshot.
7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
9/24
5.3. Export plug-in and put into dropins folder
If you export your plug-in locally you can put it into the Eclipse dropins folder 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 FileExportPlug-in DevelopmentDeployable plug-ins and
fragments.
Select the plug-in you want to export and the folder to which this plug-in should get exporTheTheted.
7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
10/24
Press the Finish button. This creates a JAR file with the exported plug-in in the selected directory.
Copy this JAR file to the dropins directory 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 NewOther...Plug-in Development Feature Project.
Create the feature project similar to the following screenshots.
7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
11/24
6.3. Create category definition
In your feature project create via the menu entry FileNewOther...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.
7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
12/24
6.4. Create an update site
You can crea te an update site for your feature in a local directory on your machine. For this, select File
ExportDeployable features.
7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
13/24
To use your category, switch to the Options tab and select the path to your category.xml file in the
Categorize repository option.
7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
14/24
6.5. Install feature via the Eclipse update manager
Use the Eclipse update manager via HelpInstall 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 c ategory flag. In this case you have
forgotten to use your category during the export.
7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
15/24
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 yourcom.vogella.plugin.first plug-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 Part8.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
7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
16/24
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 plugin.xml and add the following dependencies to your plug-
in.
org.eclipse.jdt.core
org.eclipse.core.resources
org.eclipse.core.runtime
org.eclipse.core.resources
org.eclipse.core.expressions
Add a c ommand with the ID de.vogella.plugin.htmlconverter.convert and the default
handler de.vogella.plugin.htmlconverter.handler.ConvertHandler to your plug-in.
Add this command to the menu via the extension point org.eclipse.ui.menus and use as the
"locationURI" popup:org.eclipse.jdt.ui.PackageExplorer. Set the label to "Create HTML"
for this contribution.
The resulting file plugin.xml should look like the following.
Eclipse allows to save additional information for each file. You can use the IResource interface and
the setPersistentProperty() and getPersistentProperty() 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 ConvertHandler class.
package de.vogella.plugin.htmlconverter.handler;
import java.io.BufferedWriter;import java.io.FileWriter;import java.io.IOException;
import org.eclipse.core.commands.AbstractHandler;import org.eclipse.core.commands.ExecutionEvent;import org.eclipse.core.commands.ExecutionException;import org.eclipse.core.resources.IResource;import org.eclipse.core.runtime.CoreException;import org.eclipse.core.runtime.QualifiedName;import org.eclipse.jdt.core.ICompilationUnit;import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.dialogs.MessageDialog;import org.eclipse.jface.viewers.ISelection;import org.eclipse.jface.viewers.IStructuredSelection;import org.eclipse.swt.widgets.DirectoryDialog;import org.eclipse.swt.widgets.Shell;import org.eclipse.ui.handlers.HandlerUtil;
publicclass ConvertHandler extends AbstractHandler {
http://www.vogella.com/articles/EclipseCommands/article.htmlhttp://www.vogella.com/articles/EclipseCodeAccess/article.html7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
17/24
private QualifiedName path = ne w QualifiedName("html", "path");
@Override public Object execute(ExecutionEvent event) throws ExecutionException {
Shell shell = HandlerUtil.getActiveShell(event);ISelection sel = HandlerUtil.getActiveMenuSelection(event);IStructuredSelection selection = (IStructuredSelection) sel;
Object firstElement = selection.getFirstElement(); if (firstElement instanceof ICompilationUnit) {
createOutput(shell, firstElement);
} else {MessageDialog.openInformation(shell, "Info",
"Please select a Java source file");}
return null;}
privatevoid createOutput(Shell shell, Object firstElement) {String directory;ICompilationUnit cu = (ICompilationUnit) firstElement;IResource res = cu.getResource();
boolean newDirectory = true;directory = getPersistentProperty(res, path);
if (directory != null && directory.length() > 0) {newDirectory = !(MessageDialog.openQuestion(shell, "Question",
"Use the previous output directory?"));}
if (newDirectory) {DirectoryDialog fileDialog = new DirectoryDialog(shell);directory = fileDialog.open();
} if (directory != null && directory.length() > 0) {
setPersistentProperty(res, path, directory);write(directory, cu);
}}
protected String getPersistentProperty(IResource res, QualifiedName qn) { try { return res.getPersistentProperty(qn);
} catch (CoreException e) { return"";
}}
protectedvoid setPersistentProperty(IResource res, QualifiedName qn,String value) {
try {
res.setPersistentProperty(qn, value);} catch (CoreException e) {
e.printStackTrace();}
}
privatevoid write(String dir, ICompilationUnit cu) { try {
cu.getCorrespondingResource().getName();String test = cu.getCorrespondingResource().getName();
// NeedString[] name = test.split("\\.");String htmlFile = dir + "\\" + name[0] + ".html";FileWriter output = ne w FileWriter(htmlFile);BufferedWriter writer = new BufferedWriter(output);writer.write("");writer.write("");writer.write("");
writer.write("");writer.write("");writer.write(cu.getSource());writer.write("");writer.write("");writer.write("");writer.flush();
} catch (JavaModelException e) {} catch (IOException e) {
e.printStackTrace();}
}}
If you start this plug-in you should be able to create HTML output from a Java source file.
7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
18/24
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 org.eclipse.core.expressions plug-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 ICompilationUnit from the
org.eclipse.jdt.core package.
For this exercise you use the predefined variable activeMenuSelection which contains the selection in
the menu and iterate over it. If the selection can get adapted to ICompilationUnit then the
contribution will be visible.
This will result in the following plugin.xml.
7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
19/24
name="Convert">
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 IResource.
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 handlerAddMarkerHandler in the
de.vogella.plugin.markers.handler class and add this command to the menu.
Create the following code.
package de.vogella.plugin.markers.handler;
import org.eclipse.core.commands.AbstractHandler;import org.eclipse.core.commands.ExecutionEvent;import org.eclipse.core.commands.ExecutionException;import org.eclipse.core.resources.IMarker;import org.eclipse.core.resources.IResource;import org.eclipse.jdt.core.IJavaProject;import org.eclipse.jface.viewers.IStructuredSelection;import org.eclipse.ui.handlers.HandlerUtil;
publicclass AddMarker extends AbstractHandler {
@Override public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveSite(event).getSelectionProvider().getSelection();
if (selection == null) { return null;
}Object firstElement = selection.getFirstElement();
if (firstElement instanceof IJavaProject) {IJavaProject type = (IJavaProject) firstElement;writeMarkers(type);
} return null;
}
privatevoid writeMarkers(IJavaProject type) { try {
IResource resource = type.getUnderlyingResource();IMarker marker = resource.createMarker(IMarker.TASK);marker.setAttribute(IMarker.MESSAGE, "This a a task");marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
} catch (Exception e) {e.printStackTrace();
}}
}
If you run you can create a marker in the TODO list if you select a Java project and click your menu
entry.
7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
20/24
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.
package de.vogella.plugin.adapter.model;
http://www.eclipsezone.com/eclipse/forums/t101941.htmlhttp://www.rssbus.com/odbc/?lq03137/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
21/24
publicclass Todo { private String summary; private String description; public String getSummary() { return summary;
} publicvoid setSummary(String summary) { this.summary = summary;
} public String getDescription() { return description;
} publicvoid setDescription(String description) { this.description = description;
}
}
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.
package de.vogella.plugin.adapter.views;
import org.eclipse.jface.viewers.ArrayContentProvider;import org.eclipse.jface.viewers.ITableLabelProvider;import org.eclipse.jface.viewers.LabelProvider;import org.eclipse.jface.viewers.TableViewer;import org.eclipse.swt.SWT;import org.eclipse.swt.graphics.Image;import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.ISharedImages;import org.eclipse.ui.PlatformUI;import org.eclipse.ui.part.ViewPart;
import de.vogella.plugin.adapter.model.Todo;
publicclass SampleView extends ViewPart { publicstaticfinal String ID = "de.vogella.plugin.adapter.views.SampleView" ;
private TableViewer viewer;
class ViewLabelProvider extends LabelProvider implementsITableLabelProvider {
public String getColumnText(Object obj, int index) {Todo todo = (Todo) obj;
return todo.getSummary();}
public Image getColumnImage(Object obj, int index) {
return getImage(obj);}
public Image getImage(Object obj) { return PlatformUI.getWorkbench().getSharedImages()
.getImage(ISharedImages.IMG_OBJ_ELEMENT);}
}
/**
* This is a callback that will allow us to create the viewer and initialize* it.*/
publicvoid createPartControl(Composite parent) {viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL);viewer.setContentProvider( new ArrayContentProvider());viewer.setLabelProvider(new ViewLabelProvider());getSite().setSelectionProvider(viewer);viewer.setInput(getElements());
}
/**
* Passing the focus request to the viewer's control.*/
publicvoid setFocus() {viewer.getControl().setFocus();
}
// Build up a simple data model private Todo[] getElements() {
Todo[] todos = new Todo[2];
Todo todo = new Todo();todo.setSummary("First Todo");todo.setDescription("A very good description");todos[0] = todo;todo = ne w Todo();todo.setSummary("Second Todo");todo.setDescription("Second super description");todos[1] = todo;
return todos;
7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
22/24
}}
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.
Implement the factory and the new class "TodoPropertySource" which implements "IPropertySource".
package de.vogella.plugin.adapter;
import org.eclipse.core.runtime.IAdapterFactory;import org.eclipse.ui.views.properties.IPropertySource;
import de.vogella.plugin.adapter.model.Todo;
publicclass TodoAdapterFactory implements IAdapterFactory {
@Override public Object getAdapter(Object adaptableObject, Class adapterType) { if (adapterType== IPropertySource.class && adaptableObject instanceof Todo){ returnnew TodoPropertySource((Todo) adaptableObject);
} return null;
}
@Override public Class[] getAdapterList() { returnnew Class[] { IPropertySource.class };
}
}
package de.vogella.plugin.adapter;
import org.eclipse.ui.views.properties.IPropertyDescriptor;import org.eclipse.ui.views.properties.IPropertySource;import org.eclipse.ui.views.properties.TextPropertyDescriptor;
import de.vogella.plugin.adapter.model.Todo;
publicclass TodoPropertySource implements IPropertySource {
privatefinal Todo todo;
public TodoPropertySource(Todo todo) { this.todo = todo;
}
@Override publicboolean isPropertySet(Object id) { return false;
}
@Override public Object getEditableValue() { returnthis;
}
@Override public IPropertyDescriptor[] getPropertyDescriptors() {
returnnew IPropertyDescriptor[] { new TextPropertyDescriptor("summary", "Summary"), new TextPropertyDescriptor("description", "Description") };
}
@Override public Object getPropertyValue(Object id) { if (id.equals("summary")) { return todo.getSummary();
} if (id.equals("description")) { return todo.getDescription();
} return null;
}
@Override publicvoid resetPropertyValue(Object id) {
7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
23/24
}
@Override publicvoid setPropertyValue(Object id, Object value) {
String s = (String) value; if (id.equals("summary")) {
todo.setSummary(s);}
if (id.equals("description")) {todo.setDescription(s);
}}
}
If you run your workbench and open your View via Windows -> Show View -> Others -> Sample
Category -> Sample V iew and the property view you should be able to view your data.
12. Eclipse Resources
You can register IResourceChangeListener on resources in Eclipse. For example if you have a
project you can add or remove a resource listener to or from it.
// add listenerproject.getWorkspace().addResourceChangeListener(listener);
// Remove listenerproject.getWorkspace().removeResourceChangeListener(listener);
// Example resource listenerprivate IResourceChangeListener listener = ne w IResourceChangeListener() { publicvoid resourceChanged(IResourceChangeEvent event) {
if (event.getType() == IResourceChangeEvent.PRE_CLOSE || event.getType() == IResourceChangeEvent.PRE_DELETE) { if (event.getResource().equals(project)) { // Project deleted or closed // do something
} return;
}
if (resource == null) return;
IResourceDelta delta = event.getDelta().findMember(ne w Path(resource.getURI().toPlatformString(false))); if (delta == null) {
return;}
if (delta.getKind() == IResourceDelta.REMOVED) { // Resource delete // do something
}}
};
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
http://sourceforge.net/projects/yari/7/22/2019 Extending the Eclipse IDE - Plug-In Development Tutorial
24/24
VisualVM is a debugging tool which can be integrated into Eclipse. http://visualvm.java.net/eclipse-
launcher.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 inEclipse
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
http://www.vogella.com/articles/Git/article.htmlhttp://www.vogella.com/articles/JUnit/article.htmlhttp://www.vogella.com/articles/EclipseRCP/article.htmlhttp://www.vogella.com/articles/GWT/article.htmlhttp://www.vogella.com/articles/Android/article.htmlhttp://training.vogella.com/index.htmlhttp://www.ibm.com/developerworks/opensource/tutorials/os-eclipse-plugin-guide/http://www.eclipse.org/articles/Article-Resource-deltas/resource-deltas.htmlhttp://www.eclipse.org/articles/article.php?file=Article-Adapters/index.htmlhttp://wiki.eclipse.org/Eclipse_Plug-in_Development_FAQhttp://www.vogella.com/code/index.htmlhttp://www.vogella.com/faq.htmlhttp://flattr.com/thing/49772/Tutorials-for-Eclipse-Java-Android-and-Webprogramminghttp://www.jvmmonitor.org/index.htmlhttp://visualvm.java.net/eclipse-launcher.htmlTop Related