I have some kind of UIComponent grouping which may look something like this with the classes "Group" and "Element".
Groups can have children and children may be elements or groups again, basically similar to a file system or the str+g group function in several graphics programs. The simplest form of a group is a group with only children which are also the most low level groups in the tree.
Edit:
The display hierarchy is already existant, i try to persist it to xml.
Group
- element
- Group
- element
- Group
-element
-element
- element
- element
I want to rebuild this structure in an xml-document for persistence.
I know how to build an xml document in Flex but not how to (recursively) traverse this n-tree correctly.
Update:
For getting only the child nodes one could make use of the following algorithm (pseudo code). But somehow i don't understand how to create the xml from this.
walkTree(group) {
children = node.getChildren
if(children != null) {
for(int i=0; i<children.length; i++) {
if(children[i].isGroup()) {
walkTree(group[i]);
} else {
trace(child);
}
}
}
}
As a starter, I'd suggest this : http://www.sephiroth.it/tutorials/flashPHP/E4X/
So, basically, what you are looking for seems like E4X in Actionscript 3
My suggestion would be to have your structure be data driven from the start, so the XML controls the draw of the screen. Then you would have the XML and wouldn't need to make it.
However, if you really want to do this, you'll need to loop through all the children at each level and add some sort of node that describes the child. However, if you don't have a view that is data driven, I don't see what good this will do you (and if you do, and it's not XML, you're better off writing data export from the data side, not the view side).
Related
I am using a grid in vaadin flow. When it is a row in edit state I would like to get the row index of the grid.
I guess I have to use the following but I can't make it.
grid.getEditor().isOpen();
grid.getEditor().getItem()
Can you help me?
You could look up the item in your grid's collection:
grid.getEditor().addOpenListener(event -> {
System.out.println("Opened editor on item " + myItems.indexOf(event.getItem()));
});
Although the 'index' will be the index in that collection rather than the index in the displayed grid, which is influenced by the sort order and filtering. I believe that not exposing an index on the EditorOpenEvent is intentional, as the concept of an index is presentation specific and abstracted away from the server-side initialization of the grid.
If you really needed to get to the index of the row in the current grid presentation (which respects sort order), you could make a Javascript call. Given this isn't part of the documented API, it's likely subject to change.
PendingJavaScriptResult pendingJavaScriptResult = grid.getElement().executeJs("return this._focusedItemIndex");
pendingJavaScriptResult.then(jsonValue -> {
System.out.println("From JS:" + jsonValue.asNumber());
});
How can i get all children recursively in jointjs.
I have done embedding in correct order.
I have done some homework in trying to find the answer, I have been using cell.getNeighbours().
But this does not help me in retrieving what i want.It only give the first child or first neighbours.
Since the embedding is done correct, I was thinking to use cell.getEmbeddedCells().
I am looking for help in creating a recursive function using cell.getEmbeddedCells()
getNeightbors() is for retrieving neighbors of an element in terms of links (both inbound and outbound) that are connected to that element. This has nothing to do with embeds. For retrieving all the embedded cells and their embedded cells recursively, you can do something like this:
var subtree = [];
function collectDeepEmbedded(cell) {
_.each(cell.getEmbeddedCells(), function(c) {
subtree.push(c);
collectDeepEmbedded(c);
})
}
collectDeepEmbedded(myCell);
I am creating an application using MeteorJS that allows users to create items (e.g, text, images) and to collaboratively spatially organize these on a canvas. Multiple canvases can be created. In the future, items may be reused in or copied between (I am unsure yet) multiple canvases. I have never designed a collaborative (or even database driven) application before.
I could not find the possibility to create nested MeteorJS collections, and I am unsure about the (dis)advantages (e.g. considering scalability, speed) of using multiple collections vs. using an array of objects inside a collection, so I wonder what a good design pattern would be:
A:
Collection Canvases {
Canvas {
Array Items;
}
Canvas {
Array Items;
}
}
B:
Collection Items {
Item {
_id
}
Item {
_id
}
}
Collection Canvases {
Canvas {
Array ItemIDs;
}
Canvas {
Array ItemIDs;
}
}
Or perhaps something different?
Since Meteor "identifies changes based on the fields of the MongoDB document. But ... does not support nested fields and arrays", I'd use some data structure like you suggested in your proposal B: two collections. This ensures that only new/ updated items get pushed out to clients and not all items of a canvas.
Then make the relation between Canvas and Items as saimeunt pointed out in his comment above: Canvas{_id:"xxx"} Item{_id:"xxx",canvasId:"xxx"}. (I'm using a similar approach in my project minutocash which works fine.)
Furthermore, you can publish all related items of a canvas with the publish-with-relations package as David Weldon pointed out in this answer to a question of mine, about an issue which you might run into later with this data structure.
I have a flat data array that comes form a remoteobject, I want to group whatever is to be grouped, but leave single items (the ones with no common data with anything else) alone and without grouping, it's annoying to open each node only to find there's just one item inside, so there was no need to put it inside that group anyway.
Is this something anyone has done? I can't find any reference and I don't know if getting the hierarchicaldata out of the groupingcollection and then iterate thru it would be any good, sounds like a lot of duplicate work.
I ended up doing what shaunhusain said, I created my own copy of groupingcollection and monkeypatched the way it creates the groups, not clean enough for posting or general use yet, but working on it.
can also be accomplished by using a groupitemrenderer and hiding the disclosure icon based
on the number of children.
<mx:AdvancedDataGrid id="adg"
groupItemRenderer="my.namespace.GroupedItemRenderer"
</mx:AdvancedDataGrid>
GroupedItemRenderer is a subclass of AdvancedDataGridGroupItemRenderer
In updateDisplayList :
if (data && data.hasOwnProperty("children")) {
disclosureIcon.visible = (data.children.length > 0);
}
what's the best way to remove a row (QTreeWidgetItem) from a QTreeWidget?
The QTreeWidget content has been set by:
myQTreeWidget->insertTopLevelItems(0, items); // items = QList<QTreeWidgetItem*>
then I remove an item from my QList "items" and I try to clear/reset the QTreeWidget
packList->clear();
packList->insertTopLevelItems(0, items);
but my app crashes here!
Suggestions?
Your problem is that calling packList->clear() deletes the tree widget items contained by the tree. (See the documentation about QTreeWidget::clear(), which includes a note about the items being removed from the tree before deleting.) You'll either need to find a way to remove the items, or not maintain a list of them separately from the tree.
On a slightly-related note, if you are trying to keep track of other data along with the tree, I'd recommend you try to use the models paradigm. In non-trivial cases, it has usually been worth my while to convert to that technique, rather than using the widgets/items.
From what this documentation says, you should be able to do it with:
packList->takeTopLevelItem(index);
Which returns removes and returns the item at the supplied index.