Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Skalli/User Guide/Tutorial/Extensions/Five Minutes Tutorial"
m (→Add Required Dependencies) |
m (→Create a Bundle Project) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
[[Image:Skalli_UserGuide_Tutorial_Extensions_FiveMinutesTutorial_HelloWorld.jpg]] | [[Image:Skalli_UserGuide_Tutorial_Extensions_FiveMinutesTutorial_HelloWorld.jpg]] | ||
− | We will skip over most of the details here. For more in-depth explanations please refer to the [[Skalli/User_Guide/Tutorial/Extensions/Extended_Tutorial|extended tutorial]]. | + | We will skip over most of the details here. For more in-depth explanations please refer to the [[Skalli/User_Guide/Tutorial/Extensions/Extended_Tutorial|extended tutorial]]. If you have cloned the Skalli source code you can find the complete example code in the folder ''org.eclipse.skalli.examples''. |
= Preparation = | = Preparation = | ||
Line 15: | Line 15: | ||
= Create a Bundle Project = | = Create a Bundle Project = | ||
− | Create a new bundle project called ''org.example.skalli.ext.simplehelloworld''. | + | Create a new bundle (plugin) project called ''org.example.skalli.ext.simplehelloworld''. In the ''Target Platform'' area choose ''Equinox'' as OSGi framework. If you want to build your bundle project with Maven/Tycho, make sure to use ''src/main/java'' as source folder and ''target/classes'' as output folder. On the second screen of the project creation wizard in the ''Options'' area deselect ''Generate an Activator...''. Skalli plugins in general should not have an activator. |
= Create the ProjectInfoBox = | = Create the ProjectInfoBox = | ||
Line 33: | Line 33: | ||
import com.vaadin.ui.Layout; | import com.vaadin.ui.Layout; | ||
− | public class ExtensionServiceProjectHelloWorldBox implements | + | public class ExtensionServiceProjectHelloWorldBox extends InfoBoxBase implements InfoBox { |
@Override | @Override | ||
Line 86: | Line 86: | ||
Create a folder OSGI-INF containing a file named ''ExtensionServiceProjectHelloWorldBox.xml'' with the following content: | Create a folder OSGI-INF containing a file named ''ExtensionServiceProjectHelloWorldBox.xml'' with the following content: | ||
− | <source lang=" | + | <source lang="text"> |
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="org.example.skalli.ext.simplehelloworld.infobox"> | <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="org.example.skalli.ext.simplehelloworld.infobox"> | ||
<implementation class="org.example.skalli.ext.simplehelloworld.ui.ExtensionServiceProjectHelloWorldBox"/> | <implementation class="org.example.skalli.ext.simplehelloworld.ui.ExtensionServiceProjectHelloWorldBox"/> | ||
<service> | <service> | ||
− | <provide interface="org.eclipse.skalli.view.ext. | + | <provide interface="org.eclipse.skalli.view.ext.InfoBox"/> |
</service> | </service> | ||
</scr:component> | </scr:component> | ||
Line 97: | Line 97: | ||
Furthermore, add the line | Furthermore, add the line | ||
+ | |||
<source lang="text"> | <source lang="text"> | ||
Service-Component: OSGI-INF/ExtensionServiceProjectHelloWorldBox.xml | Service-Component: OSGI-INF/ExtensionServiceProjectHelloWorldBox.xml | ||
</source> | </source> | ||
− | to the bundle's ''MANIFEST.MF''. | + | |
− | This will register the info box as OSGi service so that Skalli can find it. | + | to the bundle's ''MANIFEST.MF''. This will register the info box as OSGi service so that Skalli can find it. |
= Testing the Extension = | = Testing the Extension = |
Latest revision as of 05:58, 21 May 2012
Contents
Introduction
In this tutorial we will create a small info box with static text content, which will be displayed on every project detail page in Skalli.
This is how the infobox will look like:
We will skip over most of the details here. For more in-depth explanations please refer to the extended tutorial. If you have cloned the Skalli source code you can find the complete example code in the folder org.eclipse.skalli.examples.
Preparation
You have set up Skalli and you are able to work with it locally.
Create a Bundle Project
Create a new bundle (plugin) project called org.example.skalli.ext.simplehelloworld. In the Target Platform area choose Equinox as OSGi framework. If you want to build your bundle project with Maven/Tycho, make sure to use src/main/java as source folder and target/classes as output folder. On the second screen of the project creation wizard in the Options area deselect Generate an Activator.... Skalli plugins in general should not have an activator.
Create the ProjectInfoBox
To render info in read-only mode you need to implement a ProjectInfoBox. Create the class org.example.skalli.ext.simplehelloworld.ui.ExtensionServiceProjectHelloWorldBox.java:
package org.example.skalli.ext.simplehelloworld.ui; import org.eclipse.skalli.model.Project; import org.eclipse.skalli.view.ext.ExtensionUtil; import org.eclipse.skalli.view.ext.ProjectInfoBox; import com.vaadin.ui.Component; import com.vaadin.ui.CssLayout; import com.vaadin.ui.Label; import com.vaadin.ui.Layout; public class ExtensionServiceProjectHelloWorldBox extends InfoBoxBase implements InfoBox { @Override public String getCaption() { return "Hello World"; } @Override public float getPositionWeight() { // some high value to have it displayed as one of the last extensions return 100; } @Override public int getPreferredColumn() { return COLUMN_EAST; } @Override public boolean isVisible(Project project, String userId) { // the Hello World info box should be visible in all projects return true; } @Override public String getIconPath() { return null; } @Override public Component getContent(Project project, ExtensionUtil util) { Layout layout = new CssLayout(); layout.setSizeFull(); layout.addComponent(new Label("The project you are viewing is called \"" + project.getName() + "\".")); return layout; } }
Add Required Dependencies
Add the following bundles to the list of imported packages and required bundles in MANIFEST.MF to get your project building again:
Import-Package: org.eclipse.skalli.model, org.eclipse.skalli.view.component, org.eclipse.skalli.view.ext
Register ProjectInfoBox as OSGi Service
Create a folder OSGI-INF containing a file named ExtensionServiceProjectHelloWorldBox.xml with the following content:
<?xml version="1.0" encoding="UTF-8"?> <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="org.example.skalli.ext.simplehelloworld.infobox"> <implementation class="org.example.skalli.ext.simplehelloworld.ui.ExtensionServiceProjectHelloWorldBox"/> <service> <provide interface="org.eclipse.skalli.view.ext.InfoBox"/> </service> </scr:component>
Furthermore, add the line
Service-Component: OSGI-INF/ExtensionServiceProjectHelloWorldBox.xml
to the bundle's MANIFEST.MF. This will register the info box as OSGi service so that Skalli can find it.
Testing the Extension
Add the new plugin to your launch configuration and (re)start Skalli. You will see the new Hello World extension on all project detail pages now.
Further Steps
You can now add a data entry form so that the user can enter data for the extension, export your data through the rest API and much more. This will all be covered in the Extended Tutorial .