What's New in Mars (SWT and Plug-in Developers)

Here are descriptions of some of the changes of interest to plug-in developers made to the Eclipse Platform, Equinox and SWT for the Mars (4.5) release of Eclipse.

New features oriented towards end-users of the platform can be viewed in the What's New section of the Workbench User Guide.

Platform Changes

Job groups API A JobGroup API (org.eclipse.core.runtime.jobs.JobGroup) has been added that makes it easier to implement parallel algorithms in Eclipse.

Job groups provide a simple way to manage a set of Eclipse Jobs that are responsible for pieces of the same large task. The API supports throttling, joining, cancellation, combined progress and error reporting for all of the jobs in the group. The job grouping functionality can be used to implement performance critical algorithms using cooperating jobs. More information can be found in bug 432049.

Direct access to structured selection of a JFace Viewer The JFace StructuredViewer class now has an API to access the IStructuredSelection directly. Examples:
	IStructuredSelection sel = viewer.getStructuredSelection();
	ITreeSelection treeSel = treeViewer.getStructuredSelection();
Bye bye (IStructuredSelection) viewer.getSelection(), we won't miss you!
New API: AbstractSelectionDialog org.eclipse.jface.dialogs.AbstractSelectionDialog is an enhanced version of the existing org.eclipse.ui.dialogs.SelectionDialog. It has been added to the org.eclipse.jface bundle, where it is also available for Eclipse 4 RCP applications.

The AbstractSelectionDialog API supports generics and varargs.

Ant 1.9.4 Eclipse has adopted Ant version 1.9.4.
New stepFilters extension point The new stepFilters extension point allows clients to provide new step filters for existing debug models without having to extend those models.

To use the new extension point, clients will require a dependency on org.eclipse.debug.core. Clients can then access any contributed step filters using the new API: org.eclipse.debug.core.DebugPlugin.getStepFilters(String).

An example of the new extension point:

<extension point="org.eclipse.debug.core.stepFilters">
  <stepFilter
   class="com.example.ExampleStepFilter"
   modelIdentifier="com.example.debug.model">
  </stepFilter>
</extension>
New debug option for resource change notifications In order to help troubleshooting problems with resource change listeners, a new debug option was added to print information about which event triggers which listener. This option gives a better picture of the flow of all workspace change events and how other plugins react to those changes. To enable the new option, add
      org.eclipse.core.resources/debug=true
      org.eclipse.core.resources/notifications=true
in your .options file or use the General > Tracing preference page to enable it.
I18n support for CSS bridge Internationalization and localization support for the CSS bridge has been added. More information can be found in bug 437902

Example:

1. Modified files needed to enable the i18n support in the CSS bridge for the Polish locale:

Modified files for the i18n support

2. Launch the Eclipse instance with the '-nl pl' command line arguments. Running CSS bridge with Polish locale:

CSS bridge with polish locale
Changed type of TranslationService.LOCALE The type of the LOCALE value in the application context was changed from String to Locale (for performance reasons).

If you are injecting org.eclipse.e4.core.services.translation.TranslationService.LOCALE in your code, you need to change the type from String to Locale.

CSS support for new COLOR-TRANSPARENT constant The CSS engine now supports the COLOR-TRANSPARENT property. The implementation uses SWT's new SWT#COLOR_TRANSPARENT pseudo-color. COLOR-TRANSPARENT allowed to simplify the dark theme significantly.
New 'inherit' value for CSS properties When CSS property gets 'inherit' value then the parent's value will be applied. See more in bug 419377

New CSS properties for the Section title bar The Forms Section title bar can now be styled with special CSS properties for a Section:

CSS for Section

By using the same color for the background-color-titlebar and background-color-gradient-titlebar CSS property, like in the sample above, you get a solid background color.

For more information see bug 431635.

Support for multiple style sheet rules for the same selector The CSS engines now scans all style sheets and combines all matching rules into a common style. This allows plug-ins to override previously defined styles:

CSS override

For more information see bug 458342.

Provisional EHelpService service Eclipse now provides the provisional help service EHelpService in the IEclipseContext. EHelpService is a thin wrapper to the WorkbenchHelpSystem in the Eclipse IDE and allows customers to provide their custom implementation in Eclipse RCP applications.
Message registry Added support for binding control attributes for localization to a value of a messages class. By using such a binding, the dynamic update of widgets due to locale changes at runtime (Eclipse Translation Pattern) gets easier to implement, since the localized widgets (e.g. Labels, Buttons, etc.) are managed by the message registry.

To use the message binding for a messages class named MyMessages, you need to create a specialized BaseMessageRegistry class like shown below:

@Creatable
public class MyMessageRegistry extends BaseMessageRegistry<MyMessages> {

	@Override
	@Inject
	public void updateMessages(@Translation MyMessages messages) {
		super.updateMessages(messages);
	}
}

It can then be used like this:

@Inject
MyMessageRegistry registry;

@PostConstruct
public void init(Composite parent) {
	Label myFirstLabel = new Label(parent, SWT.WRAP);
	Label mySecondLabel = new Label(parent, SWT.NONE);
	Label myThirdLabel = new Label(parent, SWT.NONE);
	
	// bind myFirstLabel via method reference
	registry.register(myFirstLabel::setText, (m) -> m.firstLabelMessage);
	// bind mySecondLabel via method name
	registry.register(mySecondLabel, "setText", "secondLabelMe
	ssage");
	// bind myThirdLabel via property name
	registry.registerProperty(myThirdLabel, "text", "thirdLabelMessage");
}

The BaseMessageRegistry supports bindings for Java version before Java 8.

e4 tools integrated into Eclipse platform Parts of the e4 tools have been integrated into the Eclipse platform project. Mainly the Eclipse 4 application model editor and related wizards are now directly available via the Eclipse update site. The e4 project wizard has been integrated into PDE, see the PDE section for more information.

XPath expressions for parent element ID in Model Fragments When specifying the target for a fragment contribution, you can now use an XPath expression or a comma-separated list of element IDs instead of a single element ID.

The XPath expression uses JXPath internally, so it should reference attributes of the model object, not the XML file.

These 2 samples are equivalent:

parentElementId="MyMenu1, MyMenu2"
parentElementId="xpath://*[@elementId='MyMenu1' or @elementId='MyMenu2']"

This feature opens up the possibility to:

  1. Add a fragment to multiple places in a model
  2. Target a fragment to multiple application models
  3. Specify attributes (such as tags) as the target
Icons are displayed in model editor and model spy If an Icon URI is defined, it is now displayed in the model editor and in the model spy:

Better CSS support for Forms-based editors CSS support for Forms-based editors has been improved. The dark theme included in the Eclipse SDK takes advantages of that, as depicted in the following screenshot:

Heap Monitor can be styled, dark theme uses that The heap monitor has been extended to allow to set its background color, and the dark theme uses that. The following screenshot show the heap monitor after the change.

Equinox Changes

IAdaptable#getAdapter(Class) generified The org.eclipse.core.runtime.IAdaptable interface has been enhanced to return the requested type from its getAdapter method:
public <T> T getAdapter(Class <T> adapter);

Implementations of this method should also be updated. This has already been done for some platform APIs like org.eclipse.ui.part.WorkbenchPart. Callers and implementers of these APIs can see compile errors or warnings due to this binary-compatible change.

For more information, see bug 442021.

Updated to Jetty version 9 Updated to the Jetty version 9.2.3 to provide the servlet container for the Equinox Http Service implementation. Jetty 9 implements the Servlet 3.1 specification. Both Jetty 9 and Servlet 3.1 require Java 7. Java 7 is now required in order to run the Equinox Http Service and the Eclipse Help system.
New Http Whiteboard implementation
  • New implementation of Http Whiteboard Draft specification. See Current Drafts.
  • Simplify your web development by using whiteboard pattern to create assemblies of servlets, filters, context listeners and grouping them logically in shared contexts.
  • The implementation is a near feature complete implementation of the draft specification.
  • In addition to the Http Whiteboard specification, the Equinox Http Service implementation provides a complete imperative API in order to support the traditional direct registration programming model.
  • Supports Servlet 3.0 features.
  • Ongoing work will continue to provide more tests, improve support for Servlet 3.1 features and to improve stability and performance.
Prompt for native dependencies It is now possible with p2 to express dependencies on OS packages and prompt the user to install those when they are not installed.

This functionality can be enabled by a new touchpoint instruction. For example:

org.eclipse.equinox.p2.touchpoint.natives.checkAndPromptNativePackage(distro:debian,package:handbrake,comparator:ge,version:0.9);

At this point, the support is limited to Ubuntu. Contributions to add this support for other OS are welcomed.

Integration with Tycho is available from 0.23.0-SNAPSHOT and above.

SWT Changes

The DateTime widget now uses GtkSpinButton on UNIX/Linux platforms The DateTime widget has been re-implemented to use the GtkSpinButton widget for SWT.DATE and SWT.TIME styles. The new look and feel is as illustrated below:

GTK+ 2:

GTK+ 3:

New monitoring events added in place of SWT.Sleep and SWT.Wakeup The SWT.Sleep and SWT.Wakeup events have been deprecated in favor of the more generic events SWT.PreExternalEventDispatch and SWT.PostExternalEventDispatch, respectively. Clients that were written using the old event names should be updated to refer to the new events.
Transparent background for Control SWT has added support to set a Control's background as transparent. The Color class now supports specifying an alpha value (integer: 0 to 255) for transparency. Calling Control#setBackground(Color color) with a transparent color (color with alpha value '0'), sets the control's background as transparent.

List of new classes and APIs:

  • Class: org.eclipse.swt.graphics.RGBA
  • Constant: SWT.COLOR_TRANSPARENT - This is a default transparent color
  • Methods added in org.eclipse.swt.graphics.Color
    • public Color (Device device, int red, int green, int blue, int alpha)
    • public Color (Device device, RGB rgb, int alpha)
    • public Color (Device device, RGBA rgba)
    • public RGBA getRGBA ()
    • public int getAlpha ()

Note:

  • Currently, SWT honors only extreme values for alpha i.e, '0'(transparent) or '255'(opaque).
  • Setting transparent background color fails for some controls on all platforms, they show the default background color instead. For e.g. Text, Combo.
  • Setting transparent background color for some controls works on GTK3 only, it fails on other platforms. For e.g. Table, Tree.
For an example on using the new APIs, see Snippet365.

Snippet365 in action (Controls with SWT.COLOR_TRANSPARENT background and Shell with gradient background image)

Transparent Background on Control widgets

APIs for high-DPI monitor support New APIs have been added to provide support for rendering high-resolution images on high-DPI monitors.

Two constructors have been added to the Image class. They accept image-provider callbacks that allow clients to supply resolution-dependent versions of images:

public interface ImageDataProvider {
	public ImageData getImageData (int zoom);
}
public interface ImageFileNameProvider {
	public String getImagePath (int zoom);
}

Depending on the user's monitor configuration, SWT will request images with the corresponding zoom level. Here's an example that displays 3 original images, followed by variants whose resolution changes depending your monitor's resolution: Snippet367.java.

Note that this is just the first step to support high-resolution images in SWT and Eclipse-based applications. Work is underway to adopt the new APIs in the platform. Futhermore, more work in SWT is required to properly support drawing into high-resolution images via GC.

API to choose security context in Browser#evaluate() A new API Browser#evaluate(String script, boolean trusted) has been added that allows the client to run Javascript code in the Chrome security context or in the normal security context for SWT.MOZILLA style browsers.
BIDI: SWT Controls now support AUTO text direction The auto (a.k.a. "contextual") text direction implies that the base text direction is derived from the direction of the first strong (either LTR or RTL) bidi character. Auto text direction is the most appropriate choice when the text content is not known in advance and, hence, it is not yet possible to decide which base direction value, LTR or RTL, would be most suitable at run time.
Support for auto text direction has been introduced at the SWT Control level. Auto text direction can be applied through the existing Control#setTextDirection API. The new value for auto direction is expressed as the bitwise disjunction of (SWT#LEFT_TO_RIGHT | SWT#RIGHT_TO_LEFT) bit fields. When applied onto a Composite control, the auto base direction (similarly to LTR and RTL ones) is inherited by the child components.
For example:
  • org.eclipse.swt.widgets.Table.setTextDirection(SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
Result:

Note: Auto text direction is not yet supported:
  • in StyledText
  • upon Control creation (but only through Control#setTextDirection call once the Control has been created)
SWT Tools SWT Tools are now available in the Eclipse Platform p2 repository. SWT Tools provides tools for developing SWT itself (JNIGen) but also general purpose tools like Sleak (monitors the creation and disposal of SWT graphics resources) and SWT Spy (prints out information like style, layout and parent about the widget under the cursor).