Nifty control children

hello everybody, i am trying to create a “table” control. Right now, it’s not bad, i can align things properly. The problem is about the style.

Ok, i would like to write a code like this:

[java]
<control name=“xii-table” id=“someId”>
<tr>
<td>blabla</td><td>something</td>

</tr>
<tr>

</tr>

</control>

[/java]

I don’t expect to see anything magic here, i only want to write this and access these values from inside the code. The problem is, the “control” approach that nifty has seems to be “replace everything in the control body with some other stuff”. As it’s pretty good to modify the result, it’s REALLY annoying when you want to parametrize your control more than just with its attributes. You know, it’s just like we throw away all the xml stuff and do everything in code.

And the part that afraid me is everytime you want to do something that is not in the core of the nifty, the only advice you get is “create your own control”. I wouldn’t have any problem with that if it wasn’t equivalent to “throw away the xml, the inheritence of style, the interoperability, the reusability, the readibility, the separation between presentation and logic” etc.

Hey, i have no problem with creating my own “presentation stuff” if i can still create something that is xml based. But it seems that the control tag is more a gate between the xml-carebear world and the java’s world. And it shouldn’t.

So, i HOPE that i am wrong, that i missed something. But when i read that there is no more a way to add item into a dropdown list with the new versions of nifty … i am scared.

A control tag should mean “i will modify the way it’s displayed”, no “i will do everything myself (and throw away everything other people did), including storing the data myself”.
We are supposed to store as much data as possible in the xml. We are NOT supposed to use xml to DISPLAY things. The control approach (if i understood it well) is just a non-sense.

So, am i wrong ? I hope that i am.

I’m not entirely sure what you are trying to ask here because it just reads like a rant but doesn’t give anything concrete that is happening. You do know that “td” and “tr” elements don’t exist within nifty, correct? You could make controls for them but it would still be:

[java]<control name=“tr” />[/java]

A control tag in nifty is describing a discrete component that can then be reused. For example, I have a “bar” control that I reuse for health and mana bars. I also have a nifty control within java that defines how it functions and behaves.

Maybe you could give concrete examples as to what is happening?

yes, i know that there is no such thing as “tr” and “td” in nifty, and that is not my problem.

I would like (for a more simple exemple) to be able to write

[java]
<control name=“duh” id=“whatever”>
<myCustomTab text=“trololol”>
<anOtherCustomTab blip=“blop” />
</myCustomTab>
</control>
[/java]

The problem is, i CAN’T to that : when the control is instantiate, everything that is in the control instance is replaced by everything in the control definition. It should not. Because when this happen, i am not able to give parameters to my control except in attributes, and attributes only allow parameters with a “simple” structure. The whole point of xml is to be able to have objects with complex structure into it.

I know that there is nothing like tr/td etc in nifty, but i CAN’T recreate them, because i can’t put them in my control, because they will just be removed when i’ll instantiate it.

And the problem is also here with the list thing. Before, you was able to put item in the list in the xml document. Now, you can only add item with java code. But the java code should be there only to manipulate datas, and the content should be in the xml document, at least for all the “static stuff”.

It is a GOOD thing to have static AND dynamic elements, because dynamic only exists when you actually run the program, and cannot be edited/viewed outside of it. I want to be able to create controls and STILL store datas in the xml file. And i don’t ask for a magic thing : i only ask for a way to access elements that are actually in the xml file with a method or whatever.

Attributes are only good for small and simple data.

EDIT : also, it seems that not ALL the content is removed - as you still can put some “interact” stuff in it.

But i tried with some elements like labels and i get a LabelNull when i try to access it when it is inside the control tag.

See, that makes a lot more sense :slight_smile:

Googling for a static nifty listbox gave me the this link which should address your use case.

As far as nesting controls goes… I know its possible since they use that mechanic in a few other control classes (such as droppable). It may require some special setup or naming. You would have to link your actual code for me to have a better idea as to why its not working.

I think I just found out how to do it for custom controls when I looked at my code I copied from the droppable nifty component.

[java]
<controlDefinition name=“itemDroppable” childRootId="#droppableContent" controller=“com.voxelcraft.gui.controls.ItemDroppable”>
<panel childLayout=“absolute”>
<panel id="#droppableContent" x=“0px” y=“0px” width=“100%” height=“100%” childLayout=“center”/>
</panel>
</controlDefinition>
[/java]

I think the magic sauce that makes it all work is the childRootId.

no, once again you didn’t understand.

The code you showed is the code to add elements in the control DEFINITION. For exemple, you CANNOT use it if you want to have default elements to your list, unless you create a new control definition for each list - which is pretty much dumb.

Plus, this only allow you to add EXISTING tag in it. You cannot use tr/td and give to them a signification yourself.

for exemple, this is a code i would enjoy to write

[java]
<controlDefinition name=“myList” controller=“foo.bar.SomeController”>
<panel id="#container" /*usual stuff */>
</panel>
</controlDefinition>
[/java]

[java]
<control name=“myList”>
<elt value=“toto”>Toto</elt>
<elt value=“foo”>Bar</elt>
</control>
[/java]

And in the java code of SomeController

[java]

public void bind(Nifty nifty,
Screen screen,
Element element,
Properties parameter,
Attributes controlDefinitionAttributes)
{

List<Element> elts = element.getChildrenWithTag(“elt”); //<- this method doesn’t exists but you get the idea…

for ( Element elt : elts )
{
//create a text element
//add it to the panel #container
}
}
[/java]

But right now, it’s impossible to do that, because all the “elt” are removed (i can’t access to them).

I cannot put anything between <control> and </control> except interract stuff. So, i can’t give to my controller some data with a structure (a list, a tree, a table, whatever). So, even if the output is ok (i can create, add things etc in the java code) the input doesn’t exist really.

@bubuche said: The code you showed is the code to add elements in the control DEFINITION. For exemple, you CANNOT use it if you want to have default elements to your list, unless you create a new control definition for each list - which is pretty much dumb.
Calling something dumb just because it functions differently than you expect is an easy way to get labeled a novice engineer (I know from experience :) ). You can specify child elements when you instantiate them in xml or during the definition. That being said, it doesn't work like that for the dropdown control as far as I know but does work for other list elements. Under the hood, clicking on a dropdown opens a popup which is separate from the list control. I imagine you could parse the children of the dropdown and make it work with a custom control class. Void would have a better idea than I would.

As far as your other problem goes… You are looking at nifty as an xml engine like an html dom which it is not. From what I can tell nifty uses a schema definition to parse the xml input files. As a result, anything that doesn’t match I assume gets rejected. While it can’t be nearly as succinct as “td” or “tr” you could do something like:

[java]
<control name=”myList” controller=“SomeController”>
<control name=“elt” value=”toto” />
<control name=“elt” value=”foobar” />
</control>
[/java]

Then in “SomeController” you can do what you want with it. That being said, why are you going through so much trouble for a table control? It’s already pretty trivial to just create a table with the existing code.

@glh3586 said: Calling something dumb just because it functions differently than you expect is an easy way to get labeled a novice engineer (I know from experience :) )
I would agree with you if nifty was a mature lib, developped and used by thousands of people for years. Yeah, in things like that (for exemple c++, java, ubuntu etc.) the chance that someone can find something "dumb" is small. But it's not true for nifty, which is closer to a "big" student project.

No, here there is really something dumb.

You are looking at nifty as an xml engine like an html dom which it is not.
If it's anything else than an xml tree + a tool to provide a view of this tree, nifty goes wrong somewhere. xml is nothing more than that, a way to store data and some relation between them. Html is not what browser do with it, it's a lot more than that. Browsers give a view of an xml tree with a doctype which is commonly known as "html". Just like C is not defined as "what gcc compile", it can be a lot more, gcc is an implementation of a compiler of a version of the norm C.
While it can't be nearly as succinct as "td" or "tr" you could do something like:

[java]
<control name=”myList” controller=“SomeController”>
<control name=“elt” value=”toto” />
<control name=“elt” value=”foobar” />
</control>
[/java]

No, i CAN’T :wink:

Yeah, maybe know you will start to realize why i said that is “dumb”. No, i tried this already, and when i try to access elements in it i just get “null” as a result.

To make things clear:

[java]
<!-- stuff about open nifty, screen, layer etc. –>
<control name=“xii-table” id=“aTest”>
<control name=“label” text=“toto” id=“getMe” ></control>
</control>
<control name=“label” text=“toto” id=“getMe2” ></control>
<!-- stuff about close things privously opened –>
[/java]

In the bind of the control:
[java]
System.out.println("In is: "+screen.findElementByName(“getMe”));
System.out.println("Out is: "+screen.findElementByName(“getMe2”));
[/java]

Will print :

[java]
In is: null
Out is: getMe2 (de.lessvoid.nifty.elements.Element@14a40bd)
[/java]

It's already pretty trivial to just create a table with the existing code.
it's trivial to create a table with values wrote in the xml file ? Show me. Even a list for that matter.

Yes, it’s easy to write a table control and fill it with data while execution, with java. But you cannot fill it xml side.

And that is the problem. The XML language is FIRST a language to describe data structure. Then, you can put on the top of it things to give an appearance to these data. The tag is a link, not “a text in blue until you click on it”. This is the presentation of the datas.

And it’s why a lot of browser can open xml files and give a “basic” presentation. It’s because xml is only for datas.
And it’s also why xml is interoperable, because it doesn’t give itself a meaning to the data. Xml is neutral, and it should remain like that if you want to be keep its interoperability. And if you don’t care about interoperability, well … just don’t use xml, because you have a lot of other way to do things shortly and you just lost the only advantage that xml give.

@bubuche said: yes, i know that there is no such thing as "tr" and "td" in nifty, and that is not my problem.

Although that’s true for the core Nifty module … did you see the HTML module:

? I know, that’s probably not what you want/need but you might be able to use it as a reference or so. Oh, and yeah, it’s really “limited” HTML only but it supports “table”, “tr” and “td” tags so it might be helpful for some people.

@bubuche said: [java] <!-- stuff about open nifty, screen, layer etc. --> <control name="xii-table" id="aTest"> <control name="label" text="toto" id="getMe" ></control> </control> <control name="label" text="toto" id="getMe2" ></control> <!-- stuff about close things privously opened --> [/java]

In the bind of the control:
[java]
System.out.println("In is: "+screen.findElementByName(“getMe”));
System.out.println("Out is: "+screen.findElementByName(“getMe2”));
[/java]

Will print :

[java]
In is: null
Out is: getMe2 (de.lessvoid.nifty.elements.Element@14a40bd)
[/java]

That works fine for me. I had to use a different control, however (droppable).

[java]
<panel id=“myTable” childLayout=“vertical” width=“100%” height=“100%”>
<panel id=“row1” childLayout=“horizontal”>
<panel id=“row1Col1” width=“50%” childLayout=“horizontal”>
<control name=“label” text=“1”></control>
</panel>
<panel id=“row1Col2” width=“50%” childLayout=“horizontal”>
<control name=“label” text=“2”></control>
</panel>
</panel>
<panel id=“row2” childLayout=“horizontal”>
<panel id=“row2Col1” width=“50%” childLayout=“horizontal”>
<control name=“label” text=“3”></control>
</panel>
<panel id=“row2Col2” width=“50%” childLayout=“horizontal”>
<control name=“label” text=“4”></control>
</panel>
</panel>
</panel>
[/java]

That could be shortened by using control definitions.

hmm, i’ll have a look at the html part.
But the problem is deeper than that. Image that for exemple i want to create a component that display a graph (not just a tree, a graph). I know from my student class that a graph is basically a set of apex + a set of link between 2 apex. So, i can represent this graph as 2 list of element in xml. Then, i create a control, and this control read these data and create a 2d representation of this graph easily readable by humans.
I can do this only if what i put in the control is not remove before i can get my hand on it.

I know that after a certain moment, i need to replace the content of the control by the things that are in the control definition. So, a good “middle” solution would be to have a method which would be called before that replacement. In that way, my control can read these data, then do what it need to do in the panel from the control-definition. The first call (with the data about the graph definition) is the “input” where the stuff with the control-definition is the output.