SciCoDE project

From Sccswiki
Jump to navigation Jump to search

Creating a simple project in sciCoDE

In this section we will create the Hello World project in sciCoDE. As implementation language we are going to use java.

Creating the project

  1. Inside Eclipse select the menu item File > New > Project.... to open the New Project wizard
  2. Select sciCoDE Project then click Next to start the Open the new sciCoDE project wizard New Java Project wizard:
    • On this page, type "HelloWorld" in the Project name field, and then click Finish.

      project_1.png

      File:Project 1.png
  3. In the Package Explorer view, expand the HelloWorld project. The project is structured as followed:
    • src : contains the main "sci"-file, which stores the state of the workbench and a sidl file with the SIDL description of the components.
    • components : contains the java or c++ sources of the components in this project
    • includes : contains dependent SIDL files
    • import : a folder where scicode stores the files of imported components
project.png

File:Project.png

Writing the SIDL description

The next step is to define the Hello World components. The application will consist of three parts:

  • a user interface, which will be used to enter the user name
  • a kernel, which will merge the user name with the "hello world" string
  • a visualization, which will print the whole string on the console.

In this example this three parts are converted to components. The main idea is to pass the string entered in the first component(UI) to the kernel. The kernel will compute the new value of the string and forward it to the visualization. The only thing what we need to implement this scenario is a simple interface to pass strings between components. Our workbench setup should look like this: hello_world.png File:Hello world.png

Compiling the SIDL description

After creating SIDL description we need to compile it with the build-in SIDL-Compiler. Initially the compiler is not turned on. To do this select Project->Properties and then the sciCoDE compiler option to see the configuration setup. compiler_settings.png

File:Compiler settings.png

The compiler configuration provides three options:

  • create the components classes in Java
  • create the components classes in C++/JNI
  • create the java-Wrapper classes of an existing remote application

If your SIDL is dependent from another external SIDL document, you can insert such kind of dependencies in the Include Path-box.The output folder shows where to store the generated files. Normally the builder is set to "build automatically". This means that after activating the compiler the component classes will be generated immediately and Package-explorer view will be refreshed.

Instantiation of components

After finishing the compilation of the components you can insert them in the workbench. To do this you should click with the right mouse button on the palette and select the Import xml option. Each compiled component has a meta-description written in a XML-file(description.xml). To include the component in the palette the user should import this xml.

import_xml.png

File:Import xml.png

Now the components can be dropped on the workspace and connected via the connection tool as shown above.

Impementing the components

After invoking the compiler the skeletons of our components should be generated according to the SIDL specification. A full list and a complete description of the automatic generated methods are given in [[#cca-stubs|CCA stubs section].

Adding a user interface

The next step will be to add user interfaces to the HelloUI-component. As described in the User Interfaces section the following steps should be done:

  1. mark HelloUI as UI-component by returning true in the hasGUI function of the Implementation class.
  2. create an UI class which extends the abstract class de.tum.scicode.plugin.services.ui.Tab in order to use the UI Container.
  3. Create a member of UI in the implementation class (HelloUIImplmentation.java)
    1. Instatiate the UI member in the constructor
    2. Set the UI reference to be visible in the openGUI method
    3. Set the UI reference to be unvisible in the shutDown method

Members of UI.java:

member name arguments function
UI String label,TabFolder parent,int style constructor of the ui class
void createControlGroup - instantiates the controls of the UI
void setImplementation HelloUIImplementation implmentation setter

Source of UI.java:


package hello;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.Text;
import de.tum.scicode.plugin.sciCoDEPlugin;
import de.tum.scicode.plugin.services.ui.UITab;

/**
 * UI class of the HelloUI component
 * @author atanasoa
 *
 */
public class UI extends UITab {
	
	//reference to the implementation
	private HelloUIImplementation implementation;
	
	//the textbox for the name
	private Text txt;
	
	//constructor
	public UI(HelloUIImplementation impl, String label, TabFolder parent) {
		super(impl,label, parent);
		implementation=null;
	}
	
	
	//instantiates the ui controls
	@Override
	protected void createControlGroup() {
		
		this.tabFolderPage.setLayout(new org.eclipse.swt.layout.RowLayout());
		txt=new Text(this.tabFolderPage,SWT.NONE);
		
		Button submit=new Button(this.tabFolderPage,SWT.NONE);
		submit.setText("Submit");
		submit.addSelectionListener(new SelectionListener(){

			@Override
			public void widgetDefaultSelected(SelectionEvent arg0) {
				
				
			}

			@Override
			public void widgetSelected(SelectionEvent arg0) {
				implementation.submitName(txt.getText());
			}
			
		});
	}

}

Source of HelloWorldImlementation.java


Constructor:

public HelloUIImplementation() {
    super();
    /* 1 arg: name of the ui
     * 2 arg: parent control
     * 3 arg: swt style
     */
    ui=new UI(this,"Hello UI",
		sciCoDEPlugin.getDefault().getUIservice().getUIContainer(),
		SWT.NONE);
		
}

openGUI method:

public void openGUI() {
    ui.setVisible(true);
}

shutDown method:

public void shutDown() {
    ui.setVisible(false);
}

Submitting the string to the kernel:

public void submitName(String text) {
    //check if the component is connected and only then send the string
    if(isValid())
	kernel.forwardString(text);
}

The kernel implementation

The kernel component has the task to receive the string from the HelloUI component and to concatenate the "hello"-String in front of it. After that it should forward the new data to the visualization. As described in the sidl file the component should implement(provide) the IProcessString interface and it should forward the data afterwards(uses).

To implement this we need to modify the forwardString method as followed:

public void forwardString(String value) {
    if(isValid())
    	vis.forwardString("Hello "+value+"\n");
}

The visualization implementation

The visualization component is the most simple one from this example. It should provide the IProcessString interface. When called the component should pipe the string to the console.

Implementation:

public void forwardString(String value) {
   System.out.print(value);
}