writing widgets & custom script api for boy xihui chen [email protected]

18
Writing Widgets & Custom Script API for BOY Xihui Chen [email protected]

Upload: alban-johns

Post on 29-Dec-2015

225 views

Category:

Documents


0 download

TRANSCRIPT

Writing Widgets & Custom Script API for BOY

Xihui Chen

[email protected]

2 Managed by UT-Battellefor the U.S. Department of Energy

BOY Architecture

Abstract Widget

Macro

GEF

Properties

Utility PV

Eclipse

OPI Editor

PaletteNavigator

Outline

Console

Toolbar

Properties Sheet

Context MenuScript Engine

Actions

OPI RuntimeToolba

rContext Menu

Console

XML Reader

& Writer

Color & Font Macro

BOY Framework

CSS Platform

3 Managed by UT-Battellefor the U.S. Department of Energy

MVC Pattern

• All BOY widgets should follow Model-View-Controller Pattern– Separate responsibilities– Decouple complexity– Increase flexibility– Code reuse

4 Managed by UT-Battellefor the U.S. Department of Energy

Widget Model

• Definition– Defines the set of properties– Stores the according values– Only properties in model will be persisted to .opi file

• Implementation– All widgets model must subclass

org.csstudio.opibuilder.model.AbstractWidgetModel

– All PV widgets should subclass org.csstudio.opibuilder.model.AbstractPVWidgetModel

– All Container Widgets must subclass org.csstudio.opibuilder.model.AbstractContainerModel

5 Managed by UT-Battellefor the U.S. Department of Energy

Widget Model Example

public class SimpleBarGraphModel extends AbstractPVWidgetModel{

/** Lower limit of the widget. */public static final String PROP_MIN = "max"; //$NON-NLS-1$

/** Higher limit of the widget. */public static final String PROP_MAX = "min"; //$NON-NLS-1$

public final String ID = "org.csstudio.opibuilder.widgetExample.SimpleBarGraph"; //$NON-NLS-1$

/** * Initialize the properties when the widget is first created. */public SimpleBarGraphModel() {

setForegroundColor(new RGB(255, 0, 0));setBackgroundColor(new RGB(0,0,255));setSize(50, 100);

}

@Overrideprotected void configureProperties() {

addProperty(new DoubleProperty(PROP_MIN, "Min", WidgetPropertyCategory.Behavior, 0));

addProperty(new DoubleProperty(PROP_MAX, "Max",WidgetPropertyCategory.Behavior, 100));

}

@Overridepublic String getTypeID() {

return ID;}

...}

6 Managed by UT-Battellefor the U.S. Department of Energy

Widget Properties

• Currently supported property types:

• Create your own property type by extending org.csstudio.opibuilder.properties.AbstractWidgetProperty

Property Type Example PropertiesBoolean Property Enabled, VisibleInteger Property Height, Width, X, YDouble Property Meter.Level HIHI, Meter.MaximumCombo Property Border StyleString Property Name, PV Name, TextColor Property Background Color, Foreground ColorFont Property Font

File Path Property Image.Image File, Linking Container.OPI File

PointList Property Polyline.Points, Polygon.PointsMacros Property MacrosColorMap Property IntensityGraph.Color MapString List Property ItemsRules Property RulesActions Property ActionsScripts Property Scripts

7 Managed by UT-Battellefor the U.S. Department of Energy

Widget Figure (View)

• Definition– The graphical representation of the widget– No dependency on model and controller.– It should be autonomous, which means it should have its own

behavior independent from model and controller

• Implementation– All widgets figure must be an instance of

org.eclipse.draw2d.IFigure– In most cases, just subclass org.eclipse.draw2d.Figure or other

existing figures will make it easier

8 Managed by UT-Battellefor the U.S. Department of Energy

Widget Figure(cont’d)

• To use SWT widgets, subclass org.csstudio.opibuilder.widgets.figures.AbstractSWTWidgetFigure– Example: combo, web browser, table widget in BOY

• You may use SWT_AWT bridge to use Swing widget in BOY

9 Managed by UT-Battellefor the U.S. Department of Energy

Available Figure Resources

• A widget figure can be assembled from several other figures, so you can reuse exist figures:– org.csstudio.swt.xygraph

• Linear Scale

• SWT XYGraph

– org.csstudio.swt.widgets• Round Scale

• Existing Widgets

10 Managed by UT-Battellefor the U.S. Department of Energy

Widget Figure Examplepublic class SimpleBarGraphFigure extends Figure {

private double min =0;private double max = 100;private double value = 50;

@Overrideprotected void paintClientArea(Graphics graphics) {

super.paintClientArea(graphics);//fill background rectanglegraphics.setBackgroundColor(getBackgroundColor());graphics.fillRectangle(getClientArea());

//fill foreground rectangle which show the value's positiongraphics.setBackgroundColor(getForegroundColor());//coerce drawing value in rangedouble coercedValue = value;if(value < min)

coercedValue = min;else if (value > max)

coercedValue = max;int valueLength = (int) ((coercedValue-min)*getClientArea().height/(max-min));graphics.fillRectangle(getClientArea().x, getClientArea().y + getClientArea().height -valueLength, getClientArea().width, valueLength);

}

public void setValue(double value) {this.value = value;repaint();}

public double getValue() {return value;}...

}

11 Managed by UT-Battellefor the U.S. Department of Energy

Widget Editpart (Controller)

• Definition– The coordinator between model and view– Responsible for the behavior of the widget when properties

value changed

• Implementation– All widgets editpart must subclass

org.csstudio.opibuilder.editparts.AbstractWidgetEditPart

– All PV widgets should subclass org.csstudio.opibuilder.editparts.AbstractPVWidgetEditPart

– All Container Widgets must subclass org.csstudio.opibuilder.editparts.AbstractContainerEditpart

12 Managed by UT-Battellefor the U.S. Department of Energy

Widget Editpart Example

13 Managed by UT-Battellefor the U.S. Department of Energy

Register the widget with BOY

• Use the standard Eclipse extension point mechanism

• Extension point: org.csstudio.opibuilder.widget

14 Managed by UT-Battellefor the U.S. Department of Energy

Integrate the widget with CSS

• CSS Developer– Include the widget plugin into your build

• CSS User– Export it to a deployable Plugin JAR file and copy it to your

CSS dropins folder

15 Managed by UT-Battellefor the U.S. Department of Energy

Example

• Follow steps on– BOY online help->Creating Customized Widget

16 Managed by UT-Battellefor the U.S. Department of Energy

Create Custom Script API

• Purpose: call your own Java API from BOY scripts– For example, retrieve data from MySQL database and display

the data on BOY widgets.

• Technology: Eclipse Fragment– A fragment on host of org.csstudio.opibuilder plugin will be

recognized as part of the host– It allows adding third party libraries or plugins– Add static method to your utility class– Export the package from MANIFEST.MF/Runtime page

17 Managed by UT-Battellefor the U.S. Department of Energy

Example

• Follow steps on– BOY online help-> Script->Creating Custom ScriptUtil

18 Managed by UT-Battellefor the U.S. Department of Energy

Summary

• BOY Widgets– All BOY widgets must follow the MVC pattern– Each widget should have at least three classes: Model,

Editpart and Figure– Using Eclipse extension point to register widgets with BOY– Glad to have your widgets included in BOY as standard

widgets• contact [email protected]

• Custom Script API– Use Fragment on host of org.csstudio.opibuilder

Thank you!