Eclipse plugin and RCP development notes
This page contains my Eclipse plugin and RCP development notes. I am not developing Eclipse plugin often enough to stay current so this should help me to get re-started with Eclipse plugin development.
I use Diigo to store my links about Eclipse here.
Eclipse Plugins
Following steps can help you with Eclipse Plugin development:
- For Eclipse plugin development I strongly recommend the book Eclipse Plug-ins (third edition), get the book or at least install the examples and use them for development! You can download/install the examples from the update site and Open the QualityEclipse Book Samples View and load the appropriate chapter project. Additional code examples can be found here.
- Learn from mistakes here is Top 10.
- Check the official Plugins Development documentation, FAQ and the API Reference.
- Use Plug-In Spy by selecting en Eclipse window (view, editor,…) ore resource (file, project) and pressing Alt-Shift F1. The popup window will display information about the contributing plug-in and much more; click on the links to learn more! Since Eclipse 3.5 Plug-In Spy can be used to explore menus by pressing Alt-Shift-F2, see second part of this excellent blog.
- Install and use PDE Core/Spy Tools, you can download them from here.
- Read FAQ: Eclipse Plug-in Development
- Check Plugin Development Environment (PDE) Forum, PDE – Plugin Development Environment or Eclipse Platform Forum
Check following tutorials:
- Eclipse Plugin Development – Tutorial for Eclipse 3.5 (Galileo)
- Plug-in Development 101: The Fundamentals
- Eclipse Plug-in Developer Guide
- Eclipse Plugin Development Tutorial website
- Understanding how Eclipse plug-ins work with OSGi
- Introduction to Eclipse Plugin Architecture
- Recommended Eclipse reading list
- Creating an Eclipse View (old, but still useful)
- Contributing a Little Help (old, but still useful)
- Eclipse Extension Points and Extensions – Tutorial
- Getting Started with Equinox and OSGi
- Eclipse Articles
- Eclipse RCP – Converting Dependencies to OSGi Bundles
- What every Eclipse Developer should know about EMF – Part 1
- What every Eclipse Developer should know about EMF – Part 2
- A short tutorial on Intro/Welcome
- Lars Vogel’s excellent tutorials, this is must read for all plugin developers
- Eclipse Source Code Access
- Eclipse slideshows and excellent introductory slideshow to Eclipse SDK/RCP
- Thoughts on Eclipse UI
- The experience of creating an Eclipse refactoring, part 1, part 2, part 3, part 4
- Eclipse common navigator framework
- Tips on developing Eclipse plugins
- Single sourcing with declarative services
You will need some Eclipse compliant icons for plugin development, here are some:
To leverage Eclipse SDK and use plugins/tools already available in Eclipse, you need to know extension point, here is the documentation.
To learn how to use JFace Views you can use Eclipse JFace TableViewer – Tutorial . To learn how to use wizards, check Creating JFace Wizards.
To learn how to use Eclipse Preferences and Preference Pages you can use Eclipse Preference or Simplifying Preference Pages with Field Editors or check Eclipse preferences customization video.
Pay attention to plugin activation. Eclipse plugins are by default lazily initialized (only when needed), see check "Activate this plugin when one of its classes is loaded" on plugin editor Overview page. You plugin activator, usually subclass of AbstractUIPlugin start() method is only called when the plugin is activated, so if you store static reference to plugin like:
public void start(BundleContext context) throws Exception {
super.start(context); plugin = this;
}
public static PluginActivator getDefault() { return plugin; }
getDefault() method can return null if referenced before the plugin is activated (for example from your perspective that is restored form workspace instead of created from the perspective factory).
SWT, JFace
SWT is the core UI/presentation framework for Eclipse, JFace is higher level UI/presentation framework for Eclipse:
- SWT
- SWT Documentation
- Understanding SWT layouts
- SWT Examples
- PDE Developer Examples Guide
- SWT snippets
- SWT graphics
- SWT Writing Your Own Widget
- SWT tutorial
- JFace
- JFace FAQ
- JFace Framework
- JFace Code Snippets
- JFace Wizards
- Eclipse JFace
- Eclipse JFace Table and advanced tutorial
- Eclipse JFace Tree
- Tree Viewer Sample
- JFace – Demonstrates ListViewer
- Working with JFace Viewers
- JFace – Demonstrates CheckboxTreeViewer
- JFace – Create CheckBoxTreeView and react to CheckStateListener
- JFace – CheckboxTreeViewer updating checkboxes problem
- JFace – TreeViewer Article
- JFace – Add checked state provider to CheckBox*Viewer
- JFace Combobox Viewer
- SWT Combo selection listener
- Eclipse Data Binding
- SWT and JFace part1, part2, part3, part4
- The JFace of Eclipse
- Eclipse Forms: Rich UI for the Rich Client
- Eclipse Forms
- JFace Forms example with Hyperlinks
- Viewing HTML pages with SWT Browser widget
- SWT JFace SWTBrowser
- How to display Browser widget link in internal browser
- SWT browser widget
- SWT Browser Sample Code or here
- SWT Scrolled Composite
- How to use the JFace Tree Viewer
- Building tables made easy
- How to use SWT Link
- FAQ: JFace Data Binding
- Using SWT and JFace in standalone mode part1, part2, part3
- Find and Replace Bar and other plugins
- Tabs – TabFolder Example
- TableViewer – Sorting with ViewerComparator example
- Catalog of SWT and JFace Eclipse code examples
- JFace-Viewer and Eclipse Databinding with > 10.000 Objects
- Eclipse RCP – AutoCompleteCombo/Text control
- How do I set the title of a custom dialog?
- SWT Subclassing
- How to put combo-boxes into toolbars in Eclipse RCP/Plugin?
- JFace ErrorDialog: how do I show something in the details portion?
Menus, Actions, Commands
Eclipse plugins menus are implemented using Actions (older) or Commands, check following links:
Four good articles by Prakash G.R.:
- Commands Part 1: Actions Vs Commands
- Commands Part 2: Selection and Enablement of IHandlers
- Commands Part 3: Parameters for Commands
- Commands Part 4: Misc items …
- Commands Part 5: Authentication in RCP applications
- Commands Part 6: Toggle & Radio menu contributions.
Other menu references:
- Eclipse Commands – Tutorial
- Writing an Eclipse Plug-in (Part 18 – Take 2): Common Navigator: Adding submenus (Presentation/Behavior)
- Showing menu contributions depending on active perspective
- Eclipse Commands
- Eclipse Commands Advanced
- Using adapters to handle menus and handlers in large scale applications presentation and blog
- Workbench Core Expressions
- Configuring and adding menu items in Eclipse
- FAQ How do I associate an action with a command?
- Configuring and adding menu items in Eclipse V3.3
- Contributing Actions to the Eclipse Workbench
- Disable or Enable ActionSets on Perspective Change in an Eclipse RCP Application
- Menu Contributions – Debug, Tracing options
The standard set of references:
- Platform Command Framework
- Command Core Expressions
- Menu Contribution
- Menus Extension Mapping
- Action into Submenu Context Menu Java JFace SWT Eclipse
- Difference between handler activeWhen and enabledWhen?
- FAQ How do I provide a keyboard shortcut for my action?
Credit for links to How to Eclipse Commands blog.
The Platform Command Framework uses core expressions for enabledWhen and activeWhen for handlers, programmatic activation of contexts, and for visibleWhen for menu contributions. The command framework provides the IEvaluationContext that command core expressions are evaluate against.
- Command Core Expressions
- ISources.java
- Eclipse RCP Commands Part 3: visibleWhen and Core Expressions
- visibleWhen for command to appear in context menu, note the use of org.eclipse.core.expressions.definitions
- PropertyTester
- Show/hide menu and toolbar entries depending on the selected perspective
- org.eclipse.ui.menus vs. actionSets in Perspectives
Eclipse Menu Contributions are documented here. If you use Commands you will probably have to use custom property testers to set command visibility visibleWhen and/or handler active state activeWhen and enabled state enabledWhen.
If no activeWhen is specified or if it evaluates to true the handler will be active and associated with the command. Note that command can be associated with more than one active handler, in this case specific rule apply, see Commands Part 2: Selection and Enablement of IHandlers. If command has no active handler, the command is disabled. Still the command will be enabled only if handler is enabled. Handler can be enabled with enabledWhen expression, or by implementing handler.isEnabled(). activeWhen and enabledWhen are similar – with respective to the expression language and lazy loading of the plugin until the command is executed. But there is small difference – your handler might be loaded if the enabledWhen expression returns true and your plugin is already loaded. The enablement also works this way:
- No enabledWhen specified, plugin is not loaded – command is enabled
- No enabledWhen specified, but plugin is loaded – consult handler.isEnabled() and set command accordingly
- enabledWhen specified, returns false, command is disabled (no matter plugin is loaded or not)
- enabledWhen specified, returns true, plugin is not loaded – command is enabled
- enabledWhen specified, returns true, plugin is loaded – consult handler.isEnabled() and set command accordingly
To learn more check great screencast from Robert Konigsberg. You will need to declare command handlers, the class org.eclipse.ui.handlers.HandlerUtil provides several convenience methods useful from within the handler execute() method. To get an active shell in handle, use HandlerUtil.getActiveShell(event). To get a window use IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
See Showing menu contributions depending on active perspective for how to make menus visible only for a given perspective.
Note. Property tester receiver can be Collection that contains selected objects. Check for Collection instance and loop through all element to test receiver.
Note. Handler class generated by eclipse from plugin manifest implement IHandler and sets isEnabled to false by default. Unless you have overriding reason to use IHandler, it is better to subclass AbstractHandler instead, which takes care of listeners and sets isEnabled to true by default. Just override AbstractHandler.executed() method.
Note. Eclipse Search menu (org.eclipse.search.menu) doesn’t support Command contributions, so you cannot use org.eclipse.ui.menus extension point to make Search menu contribution. You have to use action sets and org.eclipse.ui.actionSets extension point and use menubarPath org.eclipse.search.menu/dialogGroup (for example) for your action.
If you wish to contribute to already existing Eclipse menus, you will have to make menu contributions. Check Eclipse Plugins Exposed page 1, page 2.
If you need to take a look at Eclipse source, here is Eclipse CVS Howto. I highly recommend to put the repository :pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse into Eclipse CVS perspective, and use the repository (directly without downloading the source code projects) to explore Eclipse source code.
Implementing toolbar menu and dynamic menu
Toolbar (like view toolbar) cannot contain menu or another toolbar. To implement menu in toolbar:
- Create command with pulldown style
- create org.eclipse.ui.menus menuContribution and define locationURI as menu:<id of the command above>
If you want to define dynamic menu (in toolbar menu or otherwise):
- define dynamic in the menuContribution and define class that extends CompoundContributionItem, implement method getContributionItems(), set the command parameter for each dynamic item created
- associate dynamic with command with parameter and with handler, in execute() method retrieve the parameter value and act on it
- handler should implement IElementUpdater and updateElement() method to set selection for RADIO or CHECK items
Following is a set of links for toolbar and dynamic menus:
- http://wiki.eclipse.org/Menu_Contributions
- http://wiki.eclipse.org/Menu_Contributions/Dropdown_Command
- http://wiki.eclipse.org/Menu_Contributions/Populating_a_dynamic_submenu
- http://wiki.eclipse.org/Menu_Contributions/Problems_View_Example
- http://wiki.eclipse.org/Menu_Contributions/Radio_Button_Command
- http://www.eclipsezone.com/eclipse/forums/t114139.html
- http://stackoverflow.com/questions/6943620/dynamic-menu-contribution-in-plugin-xml
- http://www.ibm.com/developerworks/library/os-eclipse-3.3menu/
- http://stackoverflow.com/questions/6881581/eclipse-rcp-how-to-get-show-view-menu-instead-of-a-dialog
- http://groups.google.com/group/vogella/browse_thread/thread/198b902bd62f2388?pli=1
- http://www.sigasi.com/Dynamic_menu_items_in_Eclipse
- http://stackoverflow.com/questions/6943620/dynamic-menu-contribution-in-plugin-xml
- http://wiki.eclipse.org/FAQ_How_do_I_build_menus_and_toolbars_programmatically%3F
- http://wiki.eclipse.org/FAQ_How_do_I_make_menus_with_dynamic_contents%3F
- http://wiki.eclipse.org/Menu_Contributions/Populating_a_dynamic_submenu
Extension points and Extensions
Adding an extension point (publish extension) and load (consume) the extensions defined by the extension is a fairly involved and not very well documented procedure. But you can always rely on excellent Lars Vogel tutorial Eclipse Extension Points and Extensions – Tutorial.
Old way to load extensions was static and usually happened only while your plugin was being loaded. New approach uses IExtensionChangeHandler to load or remove the extension during the lifetime of your plugin. See the article OSGi, Dynamics and Eclipse « EclipseSource Blog for excellent explanation how to dynamically add/load or remove extensions based on your extension point.
Tutorials
Writing an Eclipse plugin (by cvalcarcel):
- Writing an Eclipse Plug-in (Part 1)- What I’m going to do
- Writing an Eclipse Plug-in (Part 2): Creating a custom project in Eclipse – Adding to the New Project Wizard
- Writing an Eclipse Plug-in (Part 3): Create a custom project in Eclipse – New Project Wizard: Time to Refactor
- Writing an Eclipse Plug-in (Part 4): Create a Custom Project in Eclipse – New Project Wizard: the Behavior
- Writing an Eclipse Plug-in (Part 5): Adding Icons and A New Project Structure
- Writing an Eclipse Plug-in (Part 6): Adding an Icon To New Project Types
- Writing an Eclipse Plug-in (Part 7): Creating a Custom Navigator
- Writing an Eclipse Plug-in (Part 8): Common Navigator: Adding a New Sorter Under navigatorContent
- Writing an Eclipse Plug-in (Part 9): Custom Project: Defining a Custom File Type
- Writing an Eclipse Plug-in (Part 10): Custom Project: Creating a Custom File Type
- Writing an Eclipse Plug-in (Part 11): Common Navigator: Displaying Custom Resources or Refresh Or Die or The Magic of navigatorContent
- Writing an Eclipse Plug-in (Part 12): Common Navigator: Keeping the Tree Open When a New Resource is Added
- Writing an Eclipse Plug-in (Part 13): Common Navigator: Adding Tests
- Writing an Eclipse Plug-in (Part 14): Common Navigator: Refactoring the Children
- Writing an Eclipse Plug-in (Part 15): Custom Project: Customizing the Perspective Menus (Main menu)
- Writing an Eclipse Plug-in (Part 16): Custom Project: Customizing the Perspective Menus (Toolbar)
- Writing an Eclipse Plug-in (Part 17): Custom Project: Customizing the Perspective Menus Using Customize Perspective
- Writing an Eclipse Plug-in (Part 18): Common Navigator: Adding Submenus (Presentation)
- Writing an Eclipse Plug-in (Part 18 – Take 2): Common Navigator: Adding submenus (Presentation/Behavior)
- Writing an Eclipse Plug-in (Part 19): A Quick Display Fix
- Writing an Eclipse Plug-in (Part 20): Return of the Popup Menu (For an Empty Navigator)
- Writing an Eclipse Plug-in (Part 21): Return of the Popup Menu (Displaying Resources)
- Writing an Eclipse Plug-in (Part 22): Common Navigator: Adding submenus (Presentation)
- Writing an Eclipse Plug-in (Part 23): Common Navigator: Rewriting History
- Writing an Eclipse Plug-in (Part 24): Common Navigator: Configuring the submenus (Presentation…again)
- Writing an Eclipse Plug-in: The Missing Zip Files
- Help! I Programmatically Created a Resource in my Project, but My Code Doesn’t Find It!
Dialogs
- Discover Eclipse’s JFace Dialogs
- JFace Dialogs : which one is right for you?
- Eclipse SDK: Dialog
- Eclipse SDK: Package org.eclipse.jface.dialogs
- Eclipse Dialogs
- Eclipse Wizards
- Positioning dialogs
- FAQ How do I save settings for a dialog or wizard?
- Invoking an Eclipse Wizard programmatically
- SourceActionDialog.java – An advanced version of CheckedTreeSelectionDialog with right-side button layout
Search Pages and Dialogs
- FAQ How do I write a Search dialog?
- FAQ How do I implement a search operation?
- FAQ How do I display search results?
- Custom Search Page
- Contributing a search result page
- Search Result View Pages
- JavaSearchPage.java source code
- JavaSearchQuery.java source code
- SearchDialog.java source code
- NLSSearchPage.java source code
- BeansSearchPage.java source code
- Example SearchDialog.java source code
- PluginSearchPage.java source code
- NLSSearchResultPage.java source code
- OccurrencesSearchResultPage.java source code
- How do you find all subclasses of a given class in Java?
- How to find whether a member variable is used in a method using code in eclipse jdt?
- How could I search references to a field on a AST or a CompilationUnit in eclipse?
- Implemention Class proposal mechanism in SWT field.
- How to find an anonymous class or a local type using the JDT Java Search Engine?
Using Eclipse Search
Following section describes how to leverage Eclipse build-in text search to search in Eclipse resources.
- Main search engine class: org.eclipse.search.core.text.TextSearchEngine
- Examples of use:
- org.eclipse.search.internal.core.text.TextSearchVisitor
- org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertyKeyHyperlink
- org.eclipse.search.internal.ui.text.FileSearchQuery
- org.eclipse.jdt.internal.corext.refactoring.util.QualifiedNameFinder
- org.eclipse.search.core.text.TextSearchRequestor
- org.eclipse.search.internal.ui.text.FileSearchResult
- org.eclipse.search.ui.text.AbstractTextSearchResult
- org.eclipse.search.ui.NewSearchUI
- Example source code:
// get allEntries and sourceFiles somehow final List<myentry> foundEntries = new ArrayList<myentry>(); TextSearchEngine engine = TextSearchEngine.create(); for (MyEntry entry : allEntries) { Pattern searchPattern = Pattern.compile(getPatternFromEntry(entry)); ResultCollector collector = new ResultCollector(foundEntries, entry); IStatus status = engine.search(sourceFiles, collector, searchPattern, monitor); } private static class ResultCollector extends TextSearchRequestor { private List<myentry> results; private MyEntry entry; public ResultCollector(List<giresourceentry> results, GIResourceEntry entry) { this.results = results; this.entry = entry; } @Override public boolean acceptPatternMatch(TextSearchMatchAccess matchAccess) throws CoreException { // You might do sdome logic and extend matching data from TextSearchMatchAccess results.add(entry); return true; } }
Progress Monitors, Jobs, Concurrency
For progress monitors start with this excellent overview.
- FAQ: How do I use progress monitors
- How to Correctly and Uniformly Use Progress Monitors
- Using progress bars …
- How to get ProgressMonitor
- How to report operation progress?
- Adding work to a Job’s progress monitor in Eclipse
- ProgressMonitor with jface in RCP
- Shared progress monitor?
- cancel in ProgressMonitor?
- FAQ: How do I use a SubProgressMonitor
- FAQ: How do I switch from using a Progress dialog to the Progress view
- FAQ: Does the platform have support for concurrency
- FAQ: How do I show progress for things happening in the background
- FAQ: Actions, commands, operations, jobs: What does it all mean
- FAQ: What are IWorkspaceRunnable, IRunnableWithProgress and WorkspaceModifyOperation
- FAQ How do I prevent builds between multiple changes to the workspace?
- FAQ How do I prevent two jobs from running at the same time?
- Concurrency – jobs API
- IJobManager
- Eclipse Jobs
- FAQ: Why should I use the new progress service
- FAQ: Why do I get an invalid thread access exception
- Using progress bars
- Progress Reporting Patterns
- Progress Reporting Patterns
- ProgressMonitorDialog Sample
- JobsView.java source code
- Sequential Jobs
- How do you report progress in your software ??
Workbench Views
- FAQ How does a view persist its state between sessions?
- Make your Eclipse applications richer with view linking
- FAQ How do I make my view appear in the Show In menu?
- PDESourceViewer.java
Properties
- Working with Properties
- Tabbed-Properties (might be obsolete)
- Contributing a property page
- Eclipse Secure storage of preferences
Files, Editors
- FAQ: How do I open an editor programmatically
- FAQ: How do I open an editor on a file in the workspace
- How do I open an editor on a file outside the workspace
- How do I open external file in an editor programmatically
- How do I open an editor on something that is not a file
- How do I set the selection of an editor or view
- How do I get the selection of an editor or view
- How can I get the IDocument from an editor
- How to get the cursor position in the CEditor?
- Opening an Editor programmatically
- Editors
- Editors API
- Eclipse Editors Tutorial
- Custom markers and annotations
- Enumerating open editors
- Eclipse File System
- Class MultiPageEditor
- Working with Editors
- Example – Multi-page Editor
- How to write a Multi Page Editor
- Multipage Tiled Editor source code example
- Eclipse Cookbook Editors
- Embedding the StructuredTextEditor in a MultiPageEditor
- Multi-page form editors
- FAQ How do I add Content Assist to my language editor?
- FAQ How do I create an Outline view for my own language editor?
- FAQ How do I write an editor for my own language?
- FAQ How do I add hover support to my text editor?
- Eclipse Drag and Drop – Tutorial
- Drag and Drop in the Eclipse UI
- Drag and Drop in SWT
- See org.eclipse.ui.internal.ide.EditorAreaDropAdapter for examples of editor drop adapter and how to open non-external editor
- Drag and drop Eclipse Workbench tabs
- Drag and Drop Improvements in Eclipse
- Drag and Drop in Eclipse RCP
- Drag and Drop with Editors
- Programmatically split an editor area to show two editors side by side
- See org.eclipse.ui.ide.IDE for use and examples to open editor
- FAQ: Close All Editors On Shutdown
- How to programmatically close an editor
- How to properly hide editors, when switching between perspectives in eclipse rcp application
- Folding in Eclipse Text Editors
- Can’t get Code Folding Hover text to work
- Eclipse editors tutorial
Closing editor programatically:
- From inside the editor do: this.getEditorSite().getPage().closeEditor(this, false);
- From the "outside" do: editor.getEditorSite().getPage().closeEditor(editor, false); Check apidocs of IWorkbenchPage to find out about the second parameter
and other convenience methods for closing all editors and the like.
Articles an tutorials for creating new Eclipse editors:
- Building an Eclipse Text Editor with JFace Text
- FAQ How do I get started with creating a custom text editor?
- FAQ What support is there for creating custom text editors?
- FAQ I’m still confused! How do all the editor pieces fit together?
- FAQ How do I use the text document model?
- FAQ How do I insert text in the active text editor?
- FAQ What is a document partition?
- Word Wrap for Text Viewer and Editor
- How to implement your own Editor
- JavaSourcecodeViewer.java
- ScriptMultiTextEdit.java
- SWTCompletionEditor.java
- Text Editing – Eclipse Rich Client Platform: Designing, Coding, and Packaging Java Applications
Drag and drop classes to explore:
- org.eclipse.ui.internal.ide.EditorAreaDropAdapter
- org.eclipse.ui.internal.ide.application.IDEWorkbenchAdvisor
- org.eclipse.ui.internal.ide.application.IDEWorkbenchWindowAdvisor
Resource handling, Common Navigator Framework
- Eclipse Common Navigator Framework, and part 2
- Common Navigator Framework
- CNF tutorials
- What does the Common Navigator Framework (CNF) help me do?, and Where do we go from here?
- Building a Common Navigator based viewer, Part I: Defining the Viewer, Part 2, Part 3, Part 4
- Eclipse CNF
- Link to Editor
- FAQ How are resources created?
- FAQ What is the difference between a path and a location?
- FAQ How can I be notified of changes to the workspace?
- FAQ How do I store extra properties on a resource?
- FAQ When should I use refreshLocal?
- FAQ How and when do I save the workspace?
- RefreshAction class
- Auto-refresh providers
Natures, Builders, Markers
- To learn about Project Builders and Natures, read article Project Builders and Natures, Resource Changes and Deltas, Build Configuration, and check Eclipse Builder , or here, or here, and Nature Documentation
- If you need to listen to resource changes check the article Responding to resource changes in the Eclipse workspace.
- Batching resource changes
- How to create a new project nature in Eclipse
- Eclipse(c) Building Commercial-Quality Plug-ins – 14.3. Natures
- Using markers to tell users about problems and tasks
- Custom markers and annotations
- Resource markers
- Markers and annotations in Eclipse for error feedback
- Eclipse(c) Building Commercial-Quality Plug-ins – 14.2. Markers
- Creating a custom Marker View or here
- Extending Eclipse: grouping filters for custom problem markers
- Support for displaying markers
- Marker help and resolution
- Marker Support
- How to group custom markers in a custom view ?
- Eclipse marker is Invisible
- FAQ How do I implement Quick Fixes for my own language?
- FAQ How do I support refactoring for my own language?
- FAQ How do I create problem markers for my compiler?
- Debugging Eclipse builders
- How to implement Quick Fix / Quick Assist for custom editor?
Markers are not quite as lightweight as Eclipse documentation states, it takes quite some time to add thousands or ten thousands of markers. If you have so many markers, install Part listener using PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().addPartListener(new YourPluginPartListener2());.
Decorators
- Understanding Decorators in Eclipse
- FAQ What is a label decorator?
- FAQ How do I create a label decorator declaratively?
- FAQ How do I add label decorations to my viewer?
- Decorators Reference
- Tips on developing Eclipse plugins – III. – Project Decorators
- Label decorator in Eclipse RCP
- How to set the color of an Eclipse/RCP decorator?
- Label Decorators
- Adding Control Decoration to SWT Controls
- Adding an overlay to an ImageDescriptor
- Using Images in Eclipse
Help System
Help should be implemented in separate plugin like your.plugin.help, the help plugin should have following dependencies:
- org.eclipse.help,
- org.eclipse.ui.ide,
- org.eclipse.ui.cheatsheet
Your plugin should contain following Help System related dependencies:
- org.eclipse.help
- org.eclipse.help.ui
- org.eclipse.help.webapp
Useful links:
- Contributing a little help
- Adding Help to Eclipse RCP Applications – Tutorial
- Documenting your project using the Eclipse help system
- Eclipse Help System
- Class HelpSystem
- Adding Help to Dialogs
- Describing and packaging context-sensitive help content
- Adding Help Support to a Rich Client Platform (RCP) Application
- Writing Context Help
- Context Sensitive Help in Eclipse
- Context Help in Eclipse revisited
- How to add context help to the Eclipse plugin
- Context Help Editor
- Dynamic Context Help
- Cheat sheets
- Building Cheat Sheets in Eclipse
- Building cheat sheets in Eclipse – Tutorial
- Building cheat sheets in Eclipse
- Working with cheat sheets
- Recommended Work Flow for Cheat Sheet Development
- Eclipse Plug-in Developer Guide Cheat Sheets, starts here
- Get to know Eclipse User Assistance
- Simple cheat sheets
- Cheat Sheet Content File XML Format
- Cheat sheet authoring guidelines
- ParameterizedCommand class
To register help with dialogs use PlatformUI.getWorkbench().getHelpSystem().setHelp(container, helpContextId), for wizard pages override DialogPage.performHelp() and call help directly using PlatformUI.getWorkbench().getHelpSystem().displayHelp(helpContextId).
Implementing Intro, Welcome page
The new intro system is quite badly documented and it is not clear to me how to set it up so the Welcome page uses Intro instead of old 2.0 welcome.xml. I can make Intro contribute for initial (first time start) Intro, but then in RCP application the action ActionFactory.INTRO.create(window) calls the old welcome.xml from Help/Welcome instead of new Intro like Eclipse IDE does. I got advise on newsgroup about “bind the command "org.eclipse.ui.help.quickStartAction" to the Welcome menu item”, but I am not sure how to do that.
- Customizing a product
- A short tutorial on Intro/Welcome
- Contributing to universal intro
- Welcome and Universal Intro
- Universal Welcome
- Extending the content of an intro config
- Defining intro content, and Intro Content File XML Format
- Defining a minimal intro configuration and Defining an intro config and Extending the content of an intro config
- Contributing a HelloWorld intro Part
- Eclipse Tip: Making a Good First Impression
- Creating product branding – Eclipse 2.0 old, old welcome.xml sample
- Customizing the Eclipse About Dialog
- How Can I Give My Eclipse Blob An Icon In The Flippin’ About Dialog?
- Custom about dialogs in Eclipse applications
- Creating About dialog for your Eclipse RCP
Internationalization
Good background information on internationalizing plug-ins can be found in the Eclipse Foundation’s articles:
- How to Internationalize your Eclipse Plug-In
- How to Test Your Internationalized Eclipse Plug-In
- How to Internationalize your Eclipse Plug-In
- Getting Started with Internationalization
- Eclipse RCP: How to Localize
- Eclipse Babel Project
- Babel FAQ
- Teach Your Eclipse to Speak the Local Lingo
- FileLocator.java
- Java Internationalization Tutorial
- ICU User’s Guide
- How to edit UTF-8 resource properties in Eclipse
- Problem with Java properties utf8 encoding in Eclipse
- How to use UTF-8 in resource properties with ResourceBundle
- Unicode Code Converter
P2 provisioning and software installs/updates
- Adding Self-Update to an RCP Application
- P2 Publisher
- EclipseSource Equinox p2
- Eclipse p2
- PDE/Build project
- My RCP-Self-Update is not working
- Using Equinox P2 – Getting information about installed features and plugins
- Tutorial: p2 updates for Eclipse RCP applications (Eclipse 3.5/Galileo)
- Eclipse RCP Update with p2 – Tutorial
- Building p2 RCP products in Eclipse 3.5M6
- Eclipse PDE Build – Tutorial
- RCP FAQ: How can I deploy my RCP app
- RCP Self Provisioning with P2: It Works!!!
- Getting started with PDE Build
- Headless Eclipse RCP builds with Buckminster and Hudson
- Equinox/p2/Customizing Metadata
- Eclipse RCP build updatesite for multiple features
- Eclipse RCP p2 update not working
Tips, Tricks and How to
Following notes contain small code howto snippets useful for Eclipse plugin development :
- To get all projects in workbench:
IProject[] projects = ResourcePlugin.getWorkspace().getRoot().getProjects();
- To get Eclipse installation configuration location:
Location loc = Platform.getConfigurationLocation();
- FAQ How do I find out the install location of a plug-in?
public static String getFilenameInPlugin(String pluginId, String fileLocation) { Bundle bundle = Platform.getBundle(pluginId); Path path = new Path(fileLocation); URL fileURL = FileLocator.find(bundle, path, null); if (fileURL == null) return null; try { fileURL = FileLocator.toFileURL(fileURL); return new File(fileURL.getFile()).getAbsolutePath(); } catch (Exception e) { logError(&quot;Unable to get file: &quot; + fileLocation + &quot; from plugin: &quot; + pluginId, e); } return null; }
- If you need to create and write into console view, check "How do I write to the console from a plug-in"? Here is some code:
public static MessageConsole findConsole(String name) {
ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager conMan = plugin.getConsoleManager();
IConsole[] existing = conMan.getConsoles();
for (int i = 0; i &amp;lt; 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;
}
public static void writeToConsole(String message) {
MessageConsole myConsole = findConsole(CONSOLE_NAME);
MessageConsoleStream out = myConsole.newMessageStream();
out.println(message);
// Make console visible
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
IConsoleView view = (IConsoleView) page.showView(IConsoleConstants.ID_CONSOLE_VIEW);
view.display(myConsole);
} catch (Exception e) {
Log.logError(&quot;Unable to display Console View&quot;, e);
}
}
- To create links in your console you have to, define extension point org.eclipse.ui.console.consolePatternMatchListeners and define regex attribute like regex="\(.*:(\d+|(\d+-\d+))\, and class attribute like class=”my.plugin.PatternMatchListenerDelegate". Then you have to create delegate class PatternMatchListenerDelegate that implements IPatternMatchListenerDelegate, and in matchFound() method get console, offset and length (of the console content), and text console.getDocument().get(offset, length). Then parse the text and create your own link that implements IHyperlink, and add that link to console.addHyperlink(link, offset, length).
- Application specific Console
- How to write a hyperlink to an eclipse console from a plugin
- How link Eclipse Console text to source code? – note this will not work with your own console
- Console Pattern Match Listeners
- Create internal web browser editor
try { IWebBrowser browser = YourPluginActivator.getDefault().getWorkbench().getBrowserSupport().createBrowser(YOUR_BROWSER_ID); URL url = new URL(urlStr); browser.openURL(url); } catch (Exception e) { YourPluginLog.logError(&quot;Failed to open browser at: &quot; + urlStr, e); } - Set/reset wait cursor:
Cursor cursor = Display.getDefault().getActiveShell().getCursor(); Cursor waitCursor = Display.getDefault().getSystemCursor(SWT.CURSOR_WAIT); Display.getDefault().getActiveShell().setCursor(waitCursor); .... Display.getDefault().getActiveShell().setCursor(cursor);
- Open type dialog for classes in current project with nature JavaCore.NATURE_ID (requires org.eclipse.jdt.core):
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[]{JavaCore.create(project)}, IJavaSearchScope.SOURCES); SelectionDialog dlg = JavaUI.createTypeDialog(e.display.getActiveShell(), new ProgressMonitorDialog(e.display.getActiveShell()), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false); int status = dlg.open(); - Intercepting hyperlinks in SWT browser is not straightforward, following code is an example how I managed to intercept hyperlink click and display the link in internal browser:
private Browser dummyBrowser; .... dummyBrowser = new Browser(parent, SWT.EMBEDDED); setupBrowser(dummyBrowser); .... Browser browser = new Browser(folder, SWT.EMBEDDED); setupBrowser(browser); .... private void setupBrowser(Browser browser) { browser.addOpenWindowListener(new OpenWindowListener() { public void open(WindowEvent event) { event.browser = dummyBrowser; event.required = true; } }); browser.addLocationListener(new LocationListener() { @Override public void changing(LocationEvent event) { } @Override public void changed(LocationEvent event) { String urlStr = event.location; if (urlStr == null || !urlStr.startsWith(&quot;http:&quot;)) return; try { IWebBrowser browser = MyPluginActivator.getDefault().getWorkbench().getBrowserSupport().createBrowser(MyPluginActivator.BROWSER_ID); URL url = new URL(urlStr); browser.openURL(url); } catch (Exception e) { MyPluginLog.logError(&quot;Failed to open browser at: &quot; + urlStr, e); } } }); } - Calculate widget/control width based on text size (can be used in int computeWidth(Control control)):
GC gc = new GC(control); gc.setFont(Display.getCurrent().getSystemFont()); int width = gc.textExtent(&quot;123456&quot;).x; gc.dispose(); ((Text) control).computeTrim(0, 0, width, 0).width;
- Execute UI code in any thread (UI or non UI)
// If this is the UI thread, then make the change. if (Display.getCurrent() != null) { // Do the work return; } // otherwise, redirect to execute on the UI thread. Display.getDefault().asyncExec(new Runnable() { public void run() { // Do the work } }); - Execute command programmatically:
IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(IHandlerService.class); handlerService.executeCommand(&quot;id.of.the.command&quot;, null); - Display Java String Externalization wizard:
IEditorPart editor = null; try { editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); } catch (Exception e) { } if (editor == null || !(editor instanceof CompilationUnitEditor)) return; ExternalizeStringsAction action = new ExternalizeStringsAction((CompilationUnitEditor)editor); ISelection selection = YourPluginActivator.getDefault().getSelection(); if (selection instanceof ITextSelection) { action.run((ITextSelection)selection); } else if (selection instanceof IStructuredSelection) { action.run((IStructuredSelection)selection); } - How to open two editors in splitscreen?
// get the current workbench page IWorkbenchPage activeWorkbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); WorkbenchPage page = (WorkbenchPage) activeWorkbenchPage; // get the editor area and set the default workbook active EditorSashContainer editorArea = (EditorSashContainer) page.getEditorPresentation().getLayoutPart(); editorArea.setActiveWorkbookFromID(&quot;DefaultEditorWorkbook&quot;); // open the editor for the first part IDE.openEditor(page, getIEditorInput1(), getEditorId1()); // get the second workbook or create a new one EditorStack newWorkbook; if (editorArea.getEditorWorkbooks().size() &gt; 1) { newWorkbook = (EditorStack) editorArea.getEditorWorkbooks().get(1); } else { newWorkbook = EditorStack.newEditorWorkbook(editorArea, page); editorArea.add(newWorkbook); } // activate the second workbook editorArea.setActiveWorkbook(newWorkbook, true); // open the second editor IDE.openEditor(page, getIEditorInput2(), getEditorId2()); - Running application launch programmatically (JUnit):
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); ILaunchConfigurationType launchConfig = launchManager.getLaunchConfigurationType(&quot;org.eclipse.jdt.junit.launchconfig&quot;); ILaunchConfigurationWorkingCopy workingCopy = launchConfig.newInstance(null, &quot;name&quot;); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, &quot;javaprojectname&quot;); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, &quot;testclassname&quot;); workingCopy.setAttribute(&quot;org.eclipse.jdt.junit.TEST_KIND&quot;, &quot;org.eclipse.jdt.junit.loader.junit4&quot;); ILaunchConfiguration config = workingCopy.doSave(); config.launch(ILaunchManager.RUN_MODE, null); - Fairly common requirement is to programmatically refresh resources especially the ones open in editor. But there in no easy way to do it programmatically. Following are the two ways I found how to trigger refresh:
// trigger a refresh IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class); if (handlerService != null) { try { handlerService.executeCommand(&quot;org.eclipse.ui.file.refresh&quot;, null); } catch (Exception e) { } } If you have a resource available you can call refreshLocal() on it: IFile resource = <get resource somehow> if (resource != null) resource.refreshLocal(IResource.DEPTH_INFINITE, monitor); - FAQ How do I find out what view or editor is selected?
- FAQ: Eclipse Plug-in Development
- FAQ: Plugin Development Environment
- FAQ: When does a plug-in get started
- Lazy Start Bundles Bundle-ActivationPolicy
- If you need to handle selection, check Use the Selection Service
- SourceFolderClassFileContainer
- How to get the project name in Eclipse
- Eclipse runtime options
- To retrieve application command line options: String [] args = Platform.getApplicationArgs();
- To run background (long running jobs) see Lars Vogel’s excellent tutorial (one of many) Eclipse Jobs
- Can I make a job run in the UI thread
- To write to workbench status line see FAQ: How do I write a message to the workbench status line
- FAQ: Diagnose Bundle Start
- FAQ: PDE/Build
- FAQ: PDE/API Tools
- FAQ: How do I find the active workbench page
- FAQ How do I load and save plug-in preferences?
- Plugin Spy
- SWT Spy
- Using IAdaptable and Adaptors
- How do I find the active workbench page
- When developing an Eclipse plugin, how to get access to the project’s Java Model and AST root node?
- EclipseUtils.java
- EclipseSearchUtils.java
- Creating Java Projects Programmatically in Eclipse
- How to subscribe to an OpenProject event in Eclipse?
- Patch a plugin with a single class?
- Eclipse plug-in on project loaded.
- Eclipse-plugin how to get current text editor cursor position
- How to get cursor position in an eclipse TextEditor
- How to get the cursor position in the CEditor?
- How do you disable/hide menu items contributed by other plugins: Is it possible to hide/remove arbitrary context menu items in Eclipse, FAQ How do I add activities to my plug-in?, and Activities definition
- Filtering large user interfaces – Activities
- JFace ErrorDialog: how do I show something in the details portion?
- JDT UI source code
If you have problem with some packages not being exported from your plugin check the following:
- Make sure they are in the Build Configuration -> Order and Export area, and they are check for export.
- Make sure you have the packages exported in the manifest (PDE Tools -> Open Manifest -> Runtime tab)
- In the same place as above, make sure the JAR files are in the manifest classpath.
- (as Al says below), make sure the build properties has your jars marked for exclusion (though this is not likely your issue as you are getting errors compiling).
If all of this is done (and it’s still not working), do a clean build an restart eclipse. Sometimes the Eclipse gets a little confused about this and a restart helps.
If you get ClassNotFoundException when referencing different plugin (e.g. you have core and ui plugins), make sure that classes and libraries are on classpath, usually classes are in bin directory, include explicitly all your external libraries from lib/… . You might also include . as top directory if you are loading resources like config files from root.
If you need to access configuration files included in plugin, make sure you configure them in feature.xml Plug-ins tab as “Unpack the plugin archive after installation”.
If your plugin exports libraries, they have to be individually listed in PDE Tools -> Open Manifest -> Runtime tab in Classpath and packages to be exported from the libraries has to be listed in Runtime tab Exported packages. See also this FAQ item.
Eclipse RCP
To get started with Eclipse RCP development you should install Eclipse RCP delta pack to support multiple platforms, here are some useful links:
- Eclipse Rich Client Platform
- Using deltapack in Eclipse 3.5
- Installing deltapack for Eclipse
- Creating an Eclipse RCP 3.5 target platform
- Improved Target Platform Management, Eclipse Galileo
- DZone Refcard – Programming Eclipse RCP
- FAQ: Rich Client Platform
- Eclipse 3.7 DeltaPack Download
- Sharing Target Platforms and Launch Configurations in Version Control
- Running Eclipse – cmd. line options
- Setting workspace programmatically in RCP application
Note, do not unzip deltapack directly into Eclipse install, use Eclipse/Preferences/PDE Development as described in Using deltapack in Eclipse 3.5.
Review the older but still very useful Eclipse RCP tutorial from Ed Brunette:
Another useful RCP tutorials:
- Eclipse RCP – Tutorial with Eclipse 3.5 (Galileo)
- Eclipse RCP Tutorial
- Plug-in development 101, Part 2: Introducing Rich-Client Applications
- Building RCP application
- Rich clients with the SWT and JFace
- SWT and JFace part1, part2, part3, part4
- Spring OSGi + Eclipse RCP
- Eclipse RCP — The book forum
- Using OSGi services to single-source an RCP and RAP Application
- Eclipse Rich Client Platform – Text Infrastructure
- Eclipse Rich Client Platform: Designing, Coding, and Packaging Java Applications
- Eclipse RCP Demo “MP3 Manager”
- How to fix "workspace exited with unsaved changes" issue?
- Eclipse RCP Splash Screens and Java WebStart
And check the official Eclipse RCP web site RCP FAQ.
If you need to create a intro/welcome, cheatsheet or help page for your RCP application or plugin read "Get to know Eclipse User Assistance."
Custom branding and splash screen
- Brand your Eclipse RCP applications
- Branding Your Application
- Customizing a product
- Eclipse RCP application – custom splash screen
- [SWT/RCP] To create a login screen that looks similar to the splash
- Create a login screen that looks similar to the splash
- How to change Eclipse splash welcome screen image
- FAQ Who shows the Eclipse splash screen?
- Equinox Launcher
- Eclipse Custom Branding
- Eclipse Hack :- Change the Splash Screen
Debugging and testing Plugin or RCP
You can run or debug the plugin or RCP application from the Overview tab of the plugin or RCP. It will create a launch configuration if it doesn’t exist. If you need to start from scratch, you can reset the workspace before the launch. To do that, check Clear workspace (on Main tab). Optionally, you can check "Clear the configuration area before launching" in Configuration tab.
Make sure you have -consoleLog as a Program Argument in your launch configuration. You may also want to take a look at these runtime tools.
Testing tools:
- SWTBot
- SWTBot User’s Guide
- Window Tester Pro
- WindowTester Pro User Guide
- GUIdancer
- Jubula
- Automatic testing with Jubula
- UI Testing with Eclipse Jubula: Preparing the Test Object (1)
- UI Testing with Eclipse Jubula: Specifying the Tests (2)
- UI Testing with Eclipse Jubula: Executing the Tests (3)
- Automating Eclipse Jubula Tests with Jenkins
- Using Jubula to test multiple applications
- The good, the bad and the Ugly – Summary after 1 month of jubula
- Jubula forum
I did not have much luck with Window Tester, and I did not try to use SWTBot because I had feeling from documentation and blogs that it requires. Too many changes to tested object. I installed and started using Jubula and I am quite impressed. It is still not trivial to get going and I recommend following steps:
- Install standalone version of Jubula from http://eclipse.org/jubula/
- Read or at least skim the documentation in the installation and read the blogs above
- Export your RCP product and install <jubula installation>/rcp-support.zip plugin org.eclipse.jubula.rc.rcp_… in your product plugins directory
- Edit you product’s configuration/config.ini and add “,org.eclipse.jubula.rc.rcp” to the end of the property osgi.bundles=
- Start the AUT agent (on Windows from Start/All Programs/Jubula)
- Follow the documentation to create AUT, create and execute tests
Remote debugging of RCP application
- Add following to –vmargs of yourapplication.ini:
-Xdebug
-Xnoagent
-Djava.compiler=NONE
-Xrunjdwp:transport=dt_socket,suspend=y,server=y,address=8000
- Create Debug launch configuration, select appropriate project with your RCP application and Connection Standard (Socket Attach), with Host (localhost) and Port (8000)
- Start your RCP application
- Start your remote launch configuration in debug mode
Building plugins, features
Automated build of plugins and features without Eclipse IDE is challenge task. Check bottom of this blog and P2 Publisher (new in Eclipse 3.5). See also Eclipse PDE Build – Tutorial.
Versioning is described in MANIFEST.MF and feature.xml versioning rules.
To prevent custom build.xml being overwritten, see FAQ How do I prevent my build.xml file from being overwritten (puts custom = true into build.properties).
There are two tools that makes building Eclipse plugins and RCP, they are Buckminster and Tycho. If you use Maven, you should hav strong look at Tycho, if you prefer And as your build tool, consider:
- Buckminster
- Introduction to Buckminster
- Headless Eclipse RCP builds with Buckminster and Hudson
- Automating An Eclipse RCP Build
- Tycho
- The next generation of build tools for Eclipse plugins and RCP applications
- Building with Tycho – part 1 (OSGi bundles)
- Building with Tycho – part 2 (RCP applications)
- Stamping Version Number and Build Time in a Properties File with Maven
- Building Eclipse based Products
- Eclipse fragment tutorial
- FAQ: Can fragments be used to patch a plug-in?
- Eclipse Plugin Fragment
- Developing Eclipse plug-ins
- How to become an Eclipse committer and fork the Eclipse IDE in 20 minutes
Adding Update Support
There is a great tutorial Adding Self-Update to an RCP Application at Eclipse Wiki. You can also check EclipseSource Equinox p2 website and Eclipse p2 website, and this note.
Here is some code how to handle updates programatically Using Equinox P2 – Getting information about installed features and plugins.
the free poker room said
Howdy I am so happy I found your website, I really found you by accident, while I was researching on Google for something else, Regardless I am
here now and would just like to say kudos for a incredible post and a all round interesting
blog (I also love the theme/design), I don’t have time to look
over it all at the moment but I have saved it and also added in your RSS feeds, so when
I have time I will be back to read a great deal more, Please do keep up the great b.
wiki word wp plugin said
I am genuinely delighted to glance at this weblog posts which contains tons of valuable
data, thanks for providing these information.
Online Discount Codes said
Hello There. I found your blog using msn. This is
a very well written article. I’ll make sure to bookmark it and return to read more of your useful information. Thanks for the post. I’ll certainly comeback.
Alpesh Rathod said
Very nice articles….liked a lot
Keep it updated.
chepa653 said
I like this post! A lot of structured information in one bundle! Thanks very much, Appreciate this!
Eclipse RCP (Useful Links) | Devel(oper)s Blog said
[...] Eclipse plugin and RCP development notes [...]
www.waagg.com said
Your post offers verified helpful to me. It’s really informative and you are naturally quite educated of this type.
You get opened my own face in order to various opinion of this specific subject together with intriquing, notable and reliable written content.
natural breast growth said
Many thanks for such a great blog. Where else could anybody
get that kind of info written in such a great way?
I have a presentation that i’m presently writing on, and I have been on the look out for such fantastic information. Pleased to find your site.
Ativan said
I just couldn’t go away your site before suggesting that I actually enjoyed the usual info a person provide for your guests? Is gonna be again ceaselessly to investigate cross-check new posts