Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Skalli/User Guide/Tutorial/Extensions/Five Minutes Tutorial"

m (Register ProjectInfoBox as OSGi Service)
m (Create a Bundle Project)
 
Line 15: Line 15:
 
= Create a Bundle Project =
 
= 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. 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 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 =

Latest revision as of 05:58, 21 May 2012

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:

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 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 .

Back to the top