Meta-programming a window?

Kind of out of the realm of the typical questions there but I figure it's worth an ask. I created my own scripts that serializes/marshalls the form data from a window, and inserts/updates forms based on a naming convention I made for components. This is nice insofar as now my forms are all very standardized and the way I set an initial value, default value, and calculated vaule is pretty much the same for every single component less very tiny differences.

This led me to think about the next step in automating this process. If I could write a python script that would grab the DESCRIBE tablename info, get column types, then I know what all my component names would be, what my root container properties would have to be, what custom properties on components I would need to have etc. And if the window was built in XML or something similar, I could just then use that info to make the window, I don't care about making it pretty but if I had all the components already made it'd just be a matter of dragging/dropping for me at that point. This would not only be helpful for me for making new forms, but also refactoring old windows to my new methodology. Is there any way to make this possible?

If youā€™re using Perspective, it would be currently possible via a gateway script to insert an appropriately formatted resource.json and view.json in a new resource folder in your project via direct file operations, which the gateway will automatically register as project resources after a short delay.

Thereā€™s also a separate singleton resource page-config with its own config.json that youā€™d theoretically have to override.

Weā€™ve talked internally a few times about a ā€˜dynamicā€™ endpoint route - where you could mount a specific route, and then Perspective would just run some script thatā€™s able to return correctly formatted JSON to build a view - similar to the idea of Webdev, but more limited in scope, and specific to Perspective. No idea if thatā€™ll ever happen, but itā€™s a fun idea.

Ok, my question was actually for Vision unfortunately lol. Iā€™m not sure where I thought I heard this but that the windows are all XML? Someway to make a XML file, then do something to it, so that I could import it into my project properly? I donā€™t know, Iā€™m just hoping thereā€™d be some way to do this, it would cut down most of the tedious parts of my refactoring process.

So, yes, (far) under the hood, all Vision windows are technically XML. However, itā€™s basically impossible to work with in the same way as Perspective. I believe the data.bin for Vision windows is essentially that XML, packed into a binary format - but even if you could unpack the binary data into XML, itā€™s going to be very difficult to parse. There are a lot of disk-efficiency optimizations in place, so manually generating ā€˜compliantā€™ XML is going to require basically reinventing the Vision module, warts and all. Thereā€™s also a lot of non-obvious implementation details once you get to the low level; for instance, in Vision all bindings are actually ā€œattachedā€ to the root container, not individual components - so theyā€™re stored in an entirely different segment of the XML, but still have to map 1:1 with the components or youā€™ll get deserialization errors.

What Iā€™m trying to say is that, at least for Vision, at least with the current serialization, thereā€™s basically no way I can see this working, let alone recommend it.

At some point in the future we may improve the way Vision windows are serialized; human-readable diffing is a common request, and an improved serialization format is basically a requirement for that. But itā€™s a huge technical task, with a lot of regression potential, and limited upsides, so weā€™re not likely to do it anytime soon.

1 Like

Ok, guess its time to program a Java robot to handle this :wink:

If you want the Vision Window XML to be friendlier, I recommend changing the handler for the window itself to save encoding the InteractionController for last. You may also want to encode the root container first, or nearly first. Almost all of the misery in the existing file format is due to the ā€˜iā€™ of the interaction controller coming before the ā€˜rā€™ of the root container. (I suspect field serialization is alphabetical.) This one change should cause VisionComponent serialization to approximately follow the display order of the tree.

With this change, the bindings would have object references pointing into the display tree, instead of the display tree having object references into the InteractionControllerā€™s bindings.

The next major improvement would come from using window path object references for named components instead of numeric references.

Just these two changes would get you 95% of the way to a reasonably editable XML format.

Another optimization would be an XML shorthand for encoding netbeans-compliant properties without having to spell out all the method names.

{ Edit: I would argue that these areā€“or ought to beā€“relatively simple changes to the XML encoder/decoder pair, with very low regression risk. Especially the first one. Iā€™ll bet deferring the InteractionController encoding would yield XML readable without change to the decoder at all.}

3 Likes

Ooooooo!

When I get back from my current travels, I will have to explore how much of my advice was taken... :grin:

3 Likes

Don't get too excited. Basically it's just that the nodes under the interaction controller are explicitly sorted. Nothing else exciting (yet).

Hmmm. Another three years?

2 Likes

:grimacing:

No guarantees on timeline. The more power users making a stink, the more compelling the argument is for more changes to Vision. Just bully Carl at ICC :slight_smile:

2 Likes

Heh. You mean ply with adult beverages, I presume?

Going back to the question from years ago now, does this change mean it would be possible to write a pure XML window and bring that into Vision? Or is that still way off

If my advice is implemented, I would be comfortable generating window XML from scratch. The key is the elimination of ref ids for components by using component names instead.

1 Like