Question

I have a basic question. I have developed a Python component that just prints the value of a simple property to the console screen and a waveform that just runs the component.

I'm trying to create a component control panel that displays the current property value (a string) and also allows me to change the value of the property. When I change the value of the property, I would like the value printed to the console window to change too. My understanding is that I need to bind the property to a text box on the control panel.

I attempted to follow the binding example in section 24.4.1 of the documentation (http://redhawksdr.github.io/Documentation/mainch24.html), by adding their bind code to the refresh() function that was automatically generated by the SCA Component Control Panel wizard. However, when I view the control panel, I get the error:

An internal error occurred during: "Refresh Component".
null argument: Validation realm cannot be null

I am fairly new to Java, but my guess is that I'm receiving the error because there was some problem when creating the local copy of the SCA component (variable named "component" in the code below).

Here is my control panel code:

public void createPartControl(final Composite main) {
    main.setLayout(new GridLayout(2, false));
    propValue = new Text(main, SWT.BORDER);
    propValue.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
}


public void refresh() {
    Job refreshJob = new Job("Refresh Component") {
        @Override
        protected IStatus run(IProgressMonitor monitor) {
            // bind text box to component property value
            final ScaComponent component = getInput();
            EMFDataBindingContext context = new EMFDataBindingContext();
            IObservableValue observable = SCAObservables.observeSimpleProperty(component,"someText");
            context.bindValue(WidgetProperties.text().observeDelayed(5000, propValue),observable);
            return Status.OK_STATUS;
        }
    };
    refreshJob.setSystem(true);

    refreshJob.schedule();
}

For reference, I am running REDHAWK version 1.8.2 on RHEL 5.8.

Was it helpful?

Solution

I believe the problem here is you are trying to create a binding from within a Job.

Creation of bindings should be done within the SWT thread. The error you are getting is indicating that was unable to acquire a realm to execute within. If this code is executed within the SWT thread it will correctly acquire the SWT realm.

Text propValue = new Text(main, SWT.BORDER);
EMFDataBindingContext context = new EMFDataBindingContext();

IObservableValue observable = SCAObservables.observeSimpleProperty(component, "simplePropId");
context.bindValue(WidgetProperties.text().observeDelayed(5000, propValue), observable);

Notice in the example how the bindings are immediately created. This ensures the bindings are within the correct realm.

Control panels will have the input model change occasionally. Therefore it may be necessary to create the bindings within the refresh or setInput methods. These methods are also called from the SWT thread.

Note you should free the old context before rebinding to the new model by using context.dispose and creating a new context.

For an example on how data bindings work checkout: http://www.vogella.com/articles/EclipseDataBinding/article.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top