-
Notifications
You must be signed in to change notification settings - Fork 51
Create Eclipse bundle and use it in RCP app
We already prepared RCP app for multiproject build. Now we create Eclipse plugin and use it in RCP app.
Create folder "tutorials/MyPlugin", create file "build.gradle" in it, insert code:
apply plugin: 'java'
apply plugin: 'org.akhikhl.wuff.eclipse-bundle'
Create folder "tutorials/MyPlugin/src/main/java/myplugin", create file "HelloWorld.java" in it, insert code:
package myplugin;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
public class HelloWorld {
public static void showMessageDialog(Shell shell) {
MessageDialog.openInformation(shell, "Information", "I am Eclipse plugin!");
}
}
Edit file "tutorials/settings.gradle", insert code:
include 'MyPlugin'
so that there are two includes - "MyRcpApp" and "MyPlugin".
Edit file "tutorials/MyRcpApp/build.gradle", insert code:
dependencies {
compile project(':MyPlugin')
}
Edit file "tutorials/MyRcpApp/src/main/java/myrcpapp/View.java", replace content with:
package myrcpapp;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.ui.part.ViewPart;
public class View extends ViewPart {
@Override
public void createPartControl(final Composite parent) {
parent.setLayout(new RowLayout());
Button btnShowDialog = new Button(parent, SWT.PUSH);
btnShowDialog.setText("Show dialog");
btnShowDialog.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
myplugin.HelloWorld.showMessageDialog(parent.getShell());
}
});
}
@Override
public void setFocus() {
}
}
Invoke on command line in "tutorials" folder: gradle build
Check: folder "tutorials/MyPlugin/build/libs" must contain file "MyPlugin-1.0.0.0.jar", which is proper OSGi bundle with automatically generated manifest.
Check: each product in "tutorials/MyRcpApp/build/output" must contain "MyPlugin" and "MyRcpApp" bundles in "plugins" subfolder and in "configuration/config.ini".
Run the compiled product from command line. Expect to see:
When we click on "Show dialog" button, the program shows message dialog:
The example code for this page: examples/RcpApp-4.
Next page: add splash to RCP app.