Using InctantUI to create dynamic user interfaces in Codenameone - codenameone

I have been struggling with creating Dynamic user interfaces or forms in Codenameone. InstantUI will work with PropertyBusinessObjects. However, the current documentation assumes that these will be defined a priori. I want a situation where I can go from a map to InstantUI. My real use case is to create an InstantUI from a JSONObject. IS this possible? If so how?

There is currently no support for that in the InstantUI class as the PropertyBusinessObject contains far more information than just key/value pairs e.g. it contains type information, labels, constraints etc.
So no that's not possible. However, you can look at the source of InstantUI and use that as a starting point to create your own implementation that doesn't require these things or fetches them from a different source.

Related

Leaflet draw: Keep limit editable objects, database consistency, make multi objects

Im planning to use Leaflet Draw as part of a special wiki with an embedded map. Users should be able to draw geo-objects that are related to one or more pages in the wiki. As the wiki-pages the objects are saved in a database and can be modified by every user.
Problems:
How can i limit the number of editable objects to only one at a time?
How to keep the database consistent if two users are editing the same object at the same time?
How can i generte multi-objects/combine several objects (e.g. polygons) to a super-object (multi-polygon)?
Does anybody know some similiar approches to my idea?
Thanks.
You will have a single FeatureGroup for leaflet.draw's objects that can be edited. Simply figure out which objects will be edited and which won't be and add them to seperate FeatureGroups.
This can be handled in a few ways, maybe have a look around at general database consistency for this.
I'm not sure what you mean, maybe have a look at Well Known Text it might help you with storage here.

Using SynonymFilterFactory with more than one dictionary

Right now SynonymFilterFactory only allows to use one dictionary. I am wondering in indexing time if there is a way to use different dictionary depending on some metadata of a document (for example a category of a document). I feel like this should be doable if I override something in the indexer side? One way is to create a separate index/core based on the metadata but I hope to avoid it.
There doesn't seem to be a way to do what I want at this point other than creating a separate core.

Ranorex winforms localization issues

I'm trying to write a common test module for a localized application.
The first issue I'm having is the fact that MenuItems do not support controlname attributes. Currently my menu items are located via text or accessiblename attribute. Is there a way to support controlname attribute?
I've tried to make text and accessiblename attribute point to a variable and then bind the variable to some external dictionary. As I understand the external data sources are treated as rows which contain various data items for a single variable. I don't see a way to use external data sources that treat first column as variable name and second column as variable value. Is there a way to achieve such functionality?
I've thought about a way to extend RanorexXPath to accept functions. Then I could write something like ...menuitem[text=localizationService.Translate("#ADMINISTRATION") and have Ranorex find the menu item based on the result of localizationService.Translate function. Is there a way to do this?
Finally I've somewhat managed to get the result I need by using global variables and module variables. What I did was create a module that uses localizationService to fill module variables with correct data. Next I bind the module variables to global parameters and use the data in subsequent test. This is quite error prone and difficult to implement for large number of variables. Is there a way to access and set global variables directly from code (without the need to use binding)?
If any of the 4. points is possible please let me know.
The recomendation from Ranorex support team:
In general only the whole menu is a control in WinForms. The elements within that control (MenuItems) can only be recognized via MSAA.
The problem is that the "Name" attribute of the MenuItems is not accessible.
As workaround I would suggest to use the attribute "AccessibleDescription" in your application in order to automate the menu. This attribute can also be used for language independent names.

Persisting Objects while Still Preserving Loose Coupling

I working on a project in a microcontroller and I need to persist some settings. Pretend this is an iPod. I need to save various settings like CurrentSongPlaying, CurrentVolume, etc. so that when I turn on again I can restore those settings. The trouble I'm running into is that makes sense to store all my Non-Volatile Settings in a single struct that I can serialize/de-serialize from memory but I can't find a way to make that happen without the class doing the serialization/de-serialization from non-volatile memory including every class that contains a setting that will need to be saved for size/type information. Is there some sort of design pattern that will allow me to persist all these settings to memory without having to know about what I'm saving?
Looks like you just need an associative array. An associative array (or map) is a container that allows you to map different values to unique keys. It can have a fixed or dynamic size depending on the implementation. Coupled with a proper serialization mechanism, it allows you to save and restore its state without having to know its content in advance.
However, C does not provide this data structure out-of-the-box. Look at this question for a few implementations. The most common implementation is the hash table, also called a hash map.
OOP and classes are not easy to implement in C.
If using C is a must, I would write the struct to file.
Then I would read them and parse them during initialization upon reboot.
You can think of this as serializing your structs yourself.

Grails - Where to store properties related to domains

This is something I have been struggling about for some time now. The thing is: I have many (20 or so) static arrays of values. I say static because that is how I'm actually storing them, as static arrays inside some domains. For example, if I have a list of known websites, I do:
class Website {
...
static websites = ["web1", "web2" ...]
}
But I do this just while developing, because I can easily change the arrays if needed, but what I'm going to do when the application is ready for deployment? In my project it is very probable that, at some point, these arrays of values change. I've been researching on that matter, one can store application properties inside an external .properties file, but it will be impossible to store an array, even futile, because if some array gets an additional value, the application can't recognize it until the name of the new property is added where needed.
Another approach is to store this information in the database, but for some reason it seems like a waste to add 20 or more tables that will have just two rows, an id and a name.
And the last option, as far as I know, would be an XML, but I'm not very experienced with those. It seems groovy has a way of creating and reading XML files relatively easy, but I don't know how difficult would be to modify an XML whose layout is predefined in the application.
Needless to say that storing them in the config.groovy is not an option since any change will require to recompile.
I haven't come across some "standard" (maybe a best practice?) way of dealing with these.
So the questions is: Where to store these arrays?
Use Enum for a fixed set of attributes. Do this, if you rely at some places in your code on some concrete values.
If you do not rely on the attributes within your code (which you obviously don't), use a String-type. In this case, if you need to provide a select box, just do a distinct-query on this property in your database.
Default: Use a domain class per dynamic set of attributes. Another table is OK.
For something as simple as arrays you should use groovy own type of property files. They allow you too define properties as proper groovy variables (not just strings) and obviously loading them would be done dinamically in a simple way by using ConfigSlurper. For an example on how to use this kind of file you can have a look at the following ConfigSlurper:
For defining properties:
my.property.array=[1,2,3,4]
For loading property files:
def config = new ConfigSlurper().parse(new File('myconfig.groovy').toURL())
assert [1,2,3,4] == config.my.property.array
Tip: When you want to access the property files you want to do it in a way that can work for any environment. To make paths environment-independent use the following path as the root path:
import org.codehaus.groovy.grails.commons.ApplicationHolder
def ctx = ApplicationHolder.application.mainContext.servletContext
def rootPath = ctx.contextPath

Resources