Is there a way to generate Nifty XML from a Nifty builder?

I think the topic title is clear enough for my question: is there a way to generate Nifty XML from a Nifty builder?

@void256,@madjack:

( Hope these marks reach call the person who know the answer? :p)



_______________________________________________________________-

Further more:

I intend to make a quick Nifty GUI editor and just thought this feature will help a lot!

@normen and guys:

I 've take my time to draw out few steps in for the job, tell me you opinions please:

1.The mission start by wrapping up every element with Node as in the SDK SceneExplorer,

2.Then put in a Element Manipulator . A modified “window control” which carry other elements in it.

3.From NiftyBuilder assume we the method to parse it into XML => The XML text is paste into place…

4.The existing code “fromXML” work like a charm so reuse it in the new code.

Concerning some situation:

1.User edit the XMLView and add some “!-- Comment Line --” which is meaningless in NiftyObject

2.User want to choose the path to the controller (or images, sound …), which in some java package, can we provide it somehow ( not require user to type in to prevent errors)

3.Support way to develop and test separated Nifty Element like in Matisse

After working with the well structure of Netbean Platform, I think the “quick Nifty editor” mission can be reached in soon but I’m asking here for all you guy opinions, may be you can give me some direction and existed plan which core team had for this improvements.

3 Likes

Wow, cool. What you describe is exactly the way to go, wrap the whole xml in nodes, then it can be easily integrated, last step is the drag&drop implementation through the preview. The NetBeans platform comes with lots of XML tools, you should be able to use the xsd description to check the XML and warn the user about malformed content and even use it to implement choosers for the right tags etc.



As you say its absolutely not a monumental task, it should be fairly easy, its just that I am working on so many areas in jMP that the nifty editor never saw its second iteration until now… I’d be very grateful if you decide to take this task upon you.



Cheers,

Normen

it wouldn’t just be normen who would be grateful :P, this would be really helpful, thx

@normen:

First of all, I download the current NiftyEditor from the SVN, and take a careful consider of the code structure. Now I want you to clarify for a “right” way to implements NiftyEditor - the way you guys can take ease to work with (if fix needed):



In NiftyGUI Support module, there are some Node (placeholder I guess) and no “Explorer TopComponent” implement yet…


  1. So the 1st thing I going to do is Make the “Explorer TopComponent”

    I saw that in SceneExplorer, you use a NodeUtility reference bunch of: Lookup.getDefault().lookupAll(SceneExplorerNode.class)

    then each create the appropriate Node…



    This abstract way is very good and easy to take control of so I copy paste it to my code. So the code structure(package name) will be transcribed from sceneexplorer package. Is that OK?


  2. I saw you use XmlHelper which belong to DOM parser to extract Attributes for the Sheet , in Nifty code there is a parser too, which one is more suitable for this case ?

    (I will preserve the XmlHelper in the first attempt)


  3. The action that you make available in SceneExplorer is various and helpful. I kind of Copy Paste it too but …


  4. The palette is what we really want, so tell me your opinion for this first attempt ? I should use modified working code or adventure with my own risk :stuck_out_tongue:


  5. I’ve got some “place holder” palette items works, now I want to support user to enter info for the new element via a dialog box, but consider the “AWT and GL thread issue” which I’m very confused in… The document said that we have to “requestScene”. It’s kind of good with PropertiesWindow but when I’m in a modal dialog, then I enter one in two textfield, I want SceneViewer display the result immediately…

    How can I?
  1. I think the “Navigator” TopComponent should be able to display the document structure correctly, its used for other xml documents too. It takes the node structure you build so maybe you dont have to create a new browser topcomponent. Its a bit picky about what kind of data it can display thats why theres the SceneExplorer too but normally the Navigator is built into NetBeans to do just that.


  2. I use the NetBeans classes as I expect to handle the data mostly on the NetBeans side (Nifty can handle its own xml ;)). I guess its better to use the default data converters and structures there but it probably dont matter.



    3/4) Theres some tutorials out there on the NetBeans default palette and how you can display it and use it with your own TopComponent


  3. Just make sure that all stuff you do happens on the AWT thread (e.g. started by a button press) and that all modifications you do to the nifty objects is encapsuled into Callables that are sent to the OpenGL thread. If its really really necessary you can also block the OpenGL thread from the AWT thread to get data (calling Future.get() on the AWT thread) but you should never block the AWT thread while on the OpenGL thread (calling EventQueue.invokeAndWait()).
1 Like

A similar question was asked not that long ago and @void was quite clear. Nifty’s builder doesn’t generate XML. But, all elements are linked to each other and it shouldn’t be too much trouble to walk “the tree” of connected elements to build the XML screen from it.

normen said:
The NetBeans platform comes with lots of XML tools, you should be able to use the xsd description to check the XML and warn the user about malformed content and even use it to implement choosers for the right tags etc.

@normen: Sir, I couldn't found how to use XSD in netbean XML yet, can to give me some links. They are going to help alot to make my own NiftyObject-> XML Parser (since there is not a built in yet).

http://xml.netbeans.org/

@atmonix: If you set up your nifty open tag as displayed bewlow, most of the features in netbeans should take care of themselves:

[xml]

<nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.3.xsd"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty-1.3.xsd">

[/xml]



This will tell netbeans the general layout possibilities of the xml file and will enable code completion.

@ractoc: Thank for the instruction. I’ve already known that…

The XML Editor side of Nifty can be easily done cause Netbean Platform has a very good support for XML…

The most difficulty I face at the moment is the problem :

I want to keep the XML code of the user with all the extra information ( comment tags, extra tags if DOM or CSS Nifty will be supported later) intact…

But when I want to insert a new element, create with my visual creator, the information (attributes and properties) should be full filled. The same for the modified elements…

For example : when I click in a element to choose it to modify the properties of the width, assume that the XPath tell me exactly where the XML code of the element is, then all the properties will be parse back and full filled with “default” value… That effect is not I really intend to make…

Can you tell me how to solve …?

hhmmzz…

So if I understand you correctly, you want to be able to change the XML code from java while maintaining the layout and comments.



I THINK comments are part of java DOM, so you should be able to preserve those. With respect to the layout, that is something that DOM will revert to some default format.



Aside from that, you should be able to read and convert the XML to a java DOM model, modify it, and write it back to XML without too much trouble. Just take a look at the standarad java xml api.



If you need more help, you can find me on MSN (mark_schrijver - at - hotmail.com). I’ve done stuff similar to this before.



If you want to generate the XML based on the Nifty layout model tree, that’s something different. There you would have to traverse the entire tree, just like madjack said. While this is not impossible, it’s a lot of work to get right. And for a lot of properties, you will encounter default or generated values. These generated values are for example the width and height of elements. These will be set in xml as a %. Later, when the XML is loaded, the will be converted to a pixel value based on the size of your screen.

Stuff like this makes it hard to generate the XML, since you would then set the pixel value in your XML, which makes the XML linked to a certain screen resolution. Which in most cases isn’t the desired behaviour.

Yes, I will explain my question clearer :


  • In the “Load document” phase :


  1. I want to preserve the structure of the layout tree (especially comments) … So if comments are parts of DOM, so it’s a good news cause we can still keep those comments and other tag intact…

    It will become an DOMElement too, and has value is the comment string ?


  2. In the future, as soon as @void256 upgrade the XSD for more extra tags, the system can automatic recognize the new think and work as expected (or thow “not supported yet” exception, not mismatch things !) . We still can generate NiftyElement from DOMElement without mismatch?


  • Now in the “Edit Phase”:
  1. I want to modify a separated, specific attribute of a tags, or some of them in the same time, but still preserve the structure of the Nifty XML (not sure this necessary) . May be we need preserve the number of attributes, value of them, the order is not necessary…


  2. I haven’t done the above feature yet but I thought it would be hard to deal with nested elements…?


  3. At the moment, my “Create new Element of Control” work like this: When User click “Add a Button” … An default “ButtonControl” code which defined by me ( saved in a XML file, load and put in properties) is generated and add to the specific position in XML Code, then all the thing are reloaded to display in the NiftyViewer … In some situation, is a flexible method cause the definition of new “Element or Control” can be change in the future by me or by user… But I want to find a “official method” which some HTML editor program such as DreamWeaver does… <= This feature is kind of ignored the well-supported palette system of Netbean but I find it’s hard to make the changes in XML file saved in Netbean Palette. May be I will move all the XML Code to Palette as soon as I understand it clearly

When you have the DOM representation of the XML you will always have to save it back to the XML file before you can load it to nifty anyway… So as long as you are on the DOM level … you are on the DOM level ^^

@normen: My basic strategy is :



From NiftyXML → to DOM → I get the positions where the begin and end tag of the specific Element (which I want to modify) are in the XML String → I replace all the string with my new modified/generated string of the Element, paste it in the String → Saved back to NiftyXML file → … load again.



So, the minimum modification is made for the XML String , it’s just at the moment, I want to make less modification, as just modify the attribute which is changed, every comment are there in the code must be kept!



@normen , If there a better way to do with the help of Netbean API, tell me… I’m just groping for the correct way (with as least afford as possible :p)

The current NiftyGUI editor does this already, decoding to DOM and creating Nodes from the screens, its just about continuing that down to every xml tag type etc. You edit the DOM tree and then that is saved. The Nifty GUI display reacts to FileChangeEvents (I think) to reload the XML.

Umh… If I understand this correctly:

normen said:
The current NiftyGUI editor does this already, decoding to DOM and creating Nodes from the screens, its just about continuing that down to every xml tag type etc. You edit the DOM tree and then that is saved. The Nifty GUI display reacts to FileChangeEvents (I think) to reload the XML.

That's all my need are servered ?? :p
My job is just creating all the Node type need for the Element, Control ... etc?

Yep, and the drag&drop stuff :slight_smile:

1 Like

@normen:

Yeah, thanks a lot ,sir…

Go for it right away!

:evil:

Oh and to actually browse the Nodes you should be able to display them in the “Navigator” window as said. Using the properties you can make them editable.

Just for the sake of completness I copy my answer that I gave atomix somewhere else so that others maybe find it later as well:


Nifty does not support that at the moment, unfortunatly.

What you can do however, is to manually iterate over all elements and request the attributes indivdually. I think you can even access the ElementType instance at every Element (element.getElementType()) which will get you access to the internal attribute based origin of the element. You can call elementType.getAttributes() which is basically a wrapper around the hashtable that contains all of the attributes that Nifty has loaded from the XML.

The getElementStateString() method of the Element already uses some of this to print out debug output. It shouldn't be too hard to take that as the base for an XML output method.