To migrate your Views and Editors to Eclipse 4 you can choice to use org.eclipse.e4.tools.compat plug-in from the e4 tooling projects. This bridge was developed by Tom Schindl a while ago.
To use this bridge in Eclipse 4.2 or Eclipse 3.8 install the org.eclipse.e4.tools.e3x.bridge feature into your Eclipse IDE.
Afterwards add the following plug-ins to your MANIFEST.MF.
org.eclipse.e4.tools.compat;bundle-version=”0.12.0″,
org.eclipse.e4.core.contexts;bundle-version=”1.1.0″
You can now develop your Parts as Pojos:
[code type=”java”]
package example.compat.parts;
import javax.annotation.PostConstruct;
import org.eclipse.e4.ui.di.Focus;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
public class View {
public static final String ID = "example.compat.view";
private TableViewer viewer;
@PostConstruct
public void createPartControl(Composite parent) {
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL);
viewer.setContentProvider(ArrayContentProvider.getInstance());
TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
column.getColumn().setWidth(100);
column.setLabelProvider(new ColumnLabelProvider(){
@Override
public String getText(Object element) {
return element.toString();
}
});
// Provide the input to the ContentProvider
viewer.setInput(new String[] { "One", "Two", "Three" });
}
@Focus
public void setFocus() {
viewer.getControl().setFocus();
}
}
[/code]
You only have to wrap them into an instance of DIViewPart:
[code type=”java”]
package example.compat;
import org.eclipse.e4.tools.compat.parts.DIViewPart;
import example.compat.parts.View;
public class ViewWrapper extends DIViewPart<View> {
public ViewWrapper() {
super(View.class);
}
}
[/code]
In your plugin.xml you use ViewWrapper to define your Views.
This way you can use the dependency injection already in your Eclipse 3.x plugin, have a better possibility to test your user interface components in plain JUnit test (they are just POJO) and get ready for for a full Eclipse 4 migration.