Problems Binding Text Box in Component Control Panel To Component Property - redhawksdr

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.

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

Related

Dynamics AX 2012 - Custom Lookup in a dialog

So, I am working on a class called DMFWriteExportData and trying to get it run in Batch.
I am at a point where I need to figure out a way to get rid of fieldControl and the reason being it does not let me Run the class on the server and throws an error because it is not supposed to be running on server? (not sure)
Error: "The method Dialog Control.control cannot be called from the server; use methods on the Dialog Field class instead."
-
public Object dialog()
{
DialogRunbase dialog = new DialogRunbase("#DMF372", this);
FormStringControl control;
dialogExecution = dialog.addFieldValue(extendedTypeStr(dMFExecutionId), executionId);
control = dialogExecution.fieldControl();
control.mandatory(true);
control.displayLength(24);
control.registerOverrideMethod(methodstr(FormStringControl, lookup), methodstr(DMFWriteExecutionParameters, executionIdLookup), this);
control.registerOverrideMethod(methodstr(FormStringControl, modified), methodstr(DMFWriteExecutionParameters, executionIdModified), this);
dialogdescription=dialog.addFieldValue(extendedTypeStr(description),DMFExecution::find(executionId).Description);
dialogdescription.enabled(false);
return dialog;
}
I am wondering:
If it is actually true that this class cannot be set to server
when using control.registerOverrideMethod
If yes, what would be the ideal solution to overcome this situation,
is there any way I can create custom lookups? I see there is method
called registerOverrideMethod in the DialogField class.
Any help would be appreciated.
Thanks,
Khosla
The reason why you cannot (and should) run the code above in batch is because it uses dialog controls that only exist on the client side. You should never run this kind of code on server. Please check runon property of your class and set it to called from.
However, I assume you are using RunBaseBatch. If you are on AX 2012, you should use the SysOperation framework instead.
When using RunBaseBatch, all code is on the same class. This way, you are mixing client side code (main method, dialog method etc) with the code that should run on server (run method). For this reason you should set the "runon" property of the class to CalledFrom, not Server.
You can solve this by using SysOperation which applies the Model View Controller (MVC) pattern that neatly sepperates the two.
For an introduction to SysOperation, check my blog here:
AX2012: SysOperation introduction

JSF Converter implementation

I have implemented Autoconverter (with forceSelection=false) in maintainance screen.
To edit existing record, User will select ID from Autocomplete list.
To add new record, user will enter new ID in same box.
In converter, Application will try to search record in DB using ID.
If not found, New empty object is created with supplied ID and to avoid duplications, this object is added to array list maintained in Converter.
This works as expected on single browser session. but while testing with multiple browser, I found that Array list is shared across all instances.
I am not sure whether approach I have taken is right? if not can you please suggest me an alternative approach.
private List<SchoolMasterDetails> schoolMasterDetailsDB = new ArrayList<SchoolMasterDetails>();
#Override
public Object getAsObject(FacesContext facesContext, UIComponent component, String submittedValue) {
SchoolMasterDetails selectedObject = null;
System.out.println("getAsObject ==> Entering.");
System.out.println("getAsObject ==> '" + submittedValue + "'");
if (!submittedValue.trim().equals("")) {
selectedObject = (SchoolMasterDetails) getMasterService().getSchoolbyCode(submittedValue);
if (selectedObject == null) {
// search Object on localDB
for (SchoolMasterDetails p : schoolMasterDetailsDB) {
if (p.getSchoolCode().equalsIgnoreCase(submittedValue.trim())) {
System.out.println("getAsObject from ArrayList ==> " + p);
return p; // return selectedObject from list of created objects
}
}
System.out.println("getAsObject ==> selectedObject is null, Hence Creating new Object");
selectedObject = new SchoolMasterDetails();
selectedObject.setSchoolCode(submittedValue.trim());
selectedObject.setSchoolName("TEST TEST TEST");
schoolMasterDetailsDB.add(selectedObject);
}
else {
System.out.println("getAsObject from Database ==> " + selectedObject);
}
}
System.out.println("getAsObject ==> " + selectedObject);
}
System.out.println("getAsObject ==> Exiting.");
return selectedObject;
}
Regards,
Shirish
As far as I understand this (still learning myself), a converter fulfills exactly one purpose: It prepares your custom objects to be used in the views (getAsString) and translates Strings back into objects (getAsObject). It will be used whenever an input (a radio list, textfield, autocomplete) is tied to a variable in a backing bean that is of the type of your custom object. It is in your freedom to decide what String should be used to represent your object and how you use this String in return to look up objects.
With this in mind I would not use a converter to store a local list of objects, nor let it handle the creation process itself. Instead, I'd assume there is a backing bean somewhere, which holds your data objects and takes care of all your logic. This bean can have a list of, say, schoolMasters that can be queried for the objects it contains (similar to what your doing). You could then either implement the lookup there in a way that it handles the not-found case and always returns a valid object (which may be a new one), or you could catch the not-found-case in the converter and then trigger a createNew() from the bean to get a new instance.
IMHO this separates the management of the instances more clearly from the translating purpose of your converter. Also, from your code, it seems like you have two places to look up objects - via getMasterService() (a local method?) and inside your stored ArrayList. I don't quite get this...
As for your problem with the browsers sharing an instance: This sounds like a scope issue. If your backing bean, which is supposed to store and manage your data, is in application scope then the same set of data will be available as long as the application runs. This data will be available across browsers and also across users.
On the other hand, if you put the bean in session scope, each session will create its own instance of the bean and store unique data. Similarly, view scoped beans live as long as a single view and request beans are trashed and regenerate for each http request. You can read more here: How to choose the right scope
The answers there talk about beans (which is where your data usually lives). I'm not sure about converters, I see them as classes that are available application wide, so that each session and view can use them for translation - if you maintain a list there, it may well be globally available.

Data binding with plugins using MEF?

I have an application that has a class named: UploadItem. The application creates uploading tasks based on information it has, for example, an upload needs to be created to upload a file to sitex.com with this the application creates a new UploadItem and adds that to an ObservableCollection, the collection is bound to a listview.
Now comes the part that I cannot solve.. I decided to change the structure so that people can create their own plugins that can upload a file, the problem lies with the fact that the UploadItem class has properties such as:
string _PercentagedDone;
public string PercentageDone
{
get { return _PercentagedDone; }
set { _PercentagedDone = value + "%"; NotifyPropertyChanged("PercentageDone"); }
}
But the plugin controls on how a file is uploaded, so how would the plugin edit the PercentageDone property that is located in the UploadItem class? If there is no way to do such a thing, then is there another way to achieve the same, i.e. showing the progress on the main GUI?
You'll want to define an interface for the plugins. Something like:
public interface IUploadPlugin
{
Task<bool> Upload(IEnumerable<Stream> files);
int Progress { get; }
}
The plugins then need to implement this interface and export themselves:
[Export(typeof(IUploadPlugin))]
public class MyUploader : IUploadPlugin, INotifyPropertyChanged
{
// ...
}
Notice that this plugin implements INotifyPropertyChanged. This is an easy way to handle updating the progress. Fire PropertyChanged on the Progress property and then databind your ProgressBar control in the main view to this property. Make sure that you fire PropertyChanged on the UI thread.
Another option would be to fire a custom event when the property changes. You could handle this event in the main view logic and update the progress.
Notice that I'm using Task for the return. This allows the caller to wait until the upload task finishes. You could use a callback instead, but with the CTP of the next version of .NET, using Task<> will allow you to use the await keyword for your async programming. Check it out here and here.

How to make OnMButtonDblClk work in Windows ce 6.0?

i have added following coe in my view class but still it's not working.
BOOL CtestView::PreCreateWindow(CREATESTRUCT& cs)
{
if (CView::PreCreateWindow(cs))
{
WNDCLASS wc;
// Get the class information for the default MFC view class.
::GetClassInfo(AfxGetInstanceHandle(),cs.lpszClass,&wc);
// Register a new class using the attributes of the default
// view class, and make it the new default class.
cs.lpszClass = AfxRegisterWndClass(wc.style | CS_DBLCLKS,
wc.hCursor,wc.hbrBackground,wc.hIcon);
return TRUE;
}
return FALSE;
}
Is your window set to receive double click events? See this MSDN article. Quote:
An application-defined window does
not, by default, receive double-click
messages. Because of the system
overhead involved in generating
double-click messages, these messages
are generated only for windows
belonging to classes that have the
CS_DBLCLKS class style. Your
application must set this style when
registering the window class.
You can also create your own double-clicks by managing up/down events, the delta between the cursor locations of those events and the time between them.
So for example, this sequence:
Down message (save control)
start timer
less than 250 milliseconds passed
up message (on same control)
less than 250 milliseconds
Down message (on same control)
less than 250 milliseconds
up message (on same control)
= double click
If in that sequence your timeout expires or the control changes you reset your counters and variables since the action was not a double click.

how to bind Eclipse RCP Table View to other thread data

I have just started with Eclipse RCP.
I created Eclipse RCP View with TableViewer and WritableList to get data from other thread.
But I cannot see any changes. I need only to show content of List that other thread is managing.
public class View extends ViewPart {
private TableViewer viewer;
private WritableList input;
I also can get error,
org.eclipse.core.runtime.AssertionFailedException: assertion failed: Getter called outside realm of observable org.eclipse.core.databinding.observable.list.WritableList
I know what is UI Thread. I just don't know how to write. Please help with example.
UPDATE. Was not solved, because of lack of time, and missing good and focused tutorial.
I received this error message also with my code.
Databinding observables (WritableList, WritableValue...) inherit from ChangeManager, which provides ChangeManager#getRealm and the realm has Realm#exec. Within the runnable provided to exec, the operation runs in the correct thread.
This line caused the error (Getter called outside realm of observable):
WritableValue value = getEditor().getWritableValue();
System.out.println(((RcpEditorModel) value.getValue()).getNumber());
And this prevented the exception:
WritableValue value = getEditor().getWritableValue();
value.getRealm().exec(() -> System.out.println(((RcpEditorModel) value.getValue()).getNumber()));
The same will work with WritableList since it also inherits from ChangeManager.

Resources