Error thrown while trying to expand model in GXT tree grid - gwt

I am trying to expand a node(model bean) using the below command
gmisRevenueGross.setExpanded(revenueGrossBean, true);
but I get the below error
java.lang.AssertionError: null
at com.sencha.gxt.widget.core.client.treegrid.TreeGrid.setExpanded(TreeGrid.java:673)
at com.sencha.gxt.widget.core.client.treegrid.TreeGrid.setExpanded(TreeGrid.java:644)
The same code when I put inside a handler of button, I was able to expand the node. So I guess I am trying to expand before the dom is loaded. So is there a way to expand some nodes soon after adding it to store. For grid.setAutoExpand(true) works fine, but that expands all the node.

Just guessing, are you using GXT version 2? I think your problem was because you tried to expand the tree node before the tree grid was rendered. Check your code and make sure your tree grid was already rendered before expanding the tree node. Post your code so I can help you better.

Related

Changing node icon to "folder" when adding child in fancyTree

It seems to me that the standard behaviour in fancyTree, when adding child nodes is NOT to change the parent node to have a folder icon.
For example, see http://wwwendt.de/tech/fancytree/demo/index.html#sample-multi-ext.html and try adding a child node.
How is it possible to dynamically change the icon of the parent to a "folder" when adding a child?
I thought that I could apply renderTitle() to the parent node, but this did not do anything.
This question Dynamically change icon in fancy tree is similar, but (a) I could not get it to work, and also (b) I wanted a solution that didn't involve having to create new icons.
Folders may be empty, so this status is defined by node.folder = true (not by the fact that children are present or not).
So you could set node.folder and call node.render().
Note that setting an additional class may give the same effect, but may get lost when the tree is updated.
In jquery.fancytree.edit.js I added the following line
newNode.parent.addClass("fancytree-ico-ef");
The code snippet is as follows:
newNode.makeVisible(/*{noAnimation: true}*/).done(function(){
$(newNode[tree.statusClassPropName]).addClass("fancytree-edit-new");
self.tree.ext.edit.relatedNode = self;
newNode.parent.addClass("fancytree-ico-ef");
newNode.editStart();
});

VerticalLayout dynamically hiding visibility

I was wondering whats the best way around dynamically hiding some menu items. At the moment I have 6 items just in a matrix layout row. I want to have 3 items aligned left and 3 items alligned right. If one of the items is set to not visible I want it to move accross. I've done something similiar in a horizontal layout and setting the visibility to hidden. I was wondering if this would work with a vertical layout? Having trouble trying to figure out exactly how I would do it as I'm quite new to UI5 xml css and javscript. Any help would be great.
Also I'm having one other issue unrelated to this, I cant seem to bind my json model to my xml fragment, if I use the same code on my normal xml view it prints out the model data. But on my fragment it just prints it like {person>/fullName} any ideas ?
Belongs to your second question.
Maybe your binding was quoted on copy and paste? Check the native XML Code.
If no data are shown (not "{person>/fullName}"), add dependent to connect the models of your view
var oFragment = sap.ui.xmlfragment(sFragment, "fragmentName", this);
oView.addDependent(oFragment);

GXT add doesn't seem to work after LayoutContainer.removeAll()

GXT 2.25.
I have a screen with a layout container with a TableLayout with two columns. The left column has a tree grid. The right column is a layout container with table layout, one column.
When I click on various items on the tree grid, I want to display editable fields in the layout container on the right that match to the item clicked on.
When I first start the form and am loading the data from the server, I add text to the layout container and it seems to be fine.
After the text is loaded, I call secondLayout.removeAll() to remove all items. Then I click on an item in the tree. The selection method calls secondLayout.removeAll() and then adds a new text item "Loaded..." for testing.
private LayoutContainer secondaryLayout;
And then...
secondaryLayout.removeAll();
secondaryLayout.add(new Text("Loaded..."));
Ideas?
After making structural changes to a container, be sure to invoke (in GXT 2) the layout method to re-run the layout routines. The alternative is to configure the LayoutContainer to re-run layouts on each modification (using setLayoutOnChange), but that would in this case be at least two re-layouts - one for removeAll, and another for each new object added. Could be needlessly expensive, so better to run once and for all when you are finished making changes.
(Worth pointing out perhaps that GXT 2.2.5 is just over two years old, 2.2.6, 2.3.0 have gone out since then, and it is being superseded by GXT 3. In GXT 3, the method here would be forceLayout.)

GWT Widget not properly set in the DOM

I would like to print a GWT widget which extends Composite. This widget is composed of a grid whose cells are built with a ListDataProvider. When the user clic on a button print, the widget to print is built. Once this is done, I launch the print:
Element element = widgetToPrint.getElement();
String content = element.getInnerHTML();
print(content);
public static native boolean print(String content)
/*-{
var mywindow = window.open('', 'Printing', '');
mywindow.document.write('<html><head><title>Test</title>');
mywindow.document.write('<link rel="stylesheet" href="/public/stylesheets/ToPrintWidget.css" type="text/css" media="all"/></head><body>');
mywindow.document.write(content);
mywindow.document.write('</body></html>');
mywindow.print();
return true;
}-*/;
So, here is my problem:
The window which is opened by this method contains the core of the widget (built by the UI Binder), but some children are missing...
If I look inside the ListDataProvider and its related FlowPanel, the data are consistent, i.e. I've got several item in my list and in the flowPanel.
Consequently, it should be visible on the printing window...
I thought that maybe the problem was related to the method used to print the widget, so I also tried to add this widget into a dialogbox just before launching the print, to see if the widget was properly built... and it was.
So my widget displays well on a dialogbox, but if I try to give its innerHTML to the print method, by using getElement(), some widgets are missing... I've the feeling that the widgets which should have been built when the ListDataProvider changes are not properly set in the DOM... Somehow it works when I add the widget to a regular component, but it doesn't work when I have to give directly its innerHTML...
Do you have any idea ?
Thanks in advance.
Widgets are not just the sum of their elements, and DOM elements are not just the string that they are serialized to. Widgets are the element, and all events sunk to the dom to listen for any changes or interactions by the user. Elements then have callback functions or handlers they invoke when the user interacts with them.
By serializing the element (i.e. invoking getInnerHTML()), you are only reading out the structure of the dom, not the callbacks, and additionally not the styles set by CSS. This probably shouldn't be expected to work correctly, and as your experience is demonstrating, it doesn't.
As this is just a print window you are trying to create, event handling is probably not a concern. You just want the ability to see, but not interact with, the content that would be in that set of widgets. Styles are probably the main problem here then (though your question doesn't specify 'some children are missing' doesn't tell us what is missing, or give us any more clues as to why...) - you are adding one stylesheet in your JSNI code, but CellTable (which I assume you are using since you reference ListDataProvider) needs additional CssResource instances to appear correctly. I'm not sure how you can hijack those to draw in a new window.
Are you only using this to print content, not to let the user directly interact with the data? If so, consider another approach - use a SafeHtmlBuilder to create a giant, properly escaped string of content to draw in the new window.
String content = element.toString();
This will include all hierarchy elements in the node.
Just a reminder, all the GWT handlers will not work, and you have to sink all the events using DOM.
You might want to grab the outer HTML rather than the inner one.
GWT unfortunately has no getOuterHTML, but it's relatively easy to emulate.
If your widget is the only child within an element, then simply get the inner HTML of the parent element (w.getElement().getParentElement().getInnerHTML())
Otherwise, clone your widget's node add it to a newly created parent element, from which you'll be able to get the inner HTML:
DivElement temp = Document.get().createDivElement();
temp.appendChild(w.getElement().cloneNode(true));
return temp.getInnerHTML();
First thank you for your answers, it helped me to work out this problem.
I've almost solve the problem:
First, I do not use ListDataProvider anymore, because it wasn't clear for me when and how the view was refreshed. Instead I add my widgets by hand, which makes sense since, they are not going to move anyway.
Then, I define the style of my widgets using a common CSS stylesheet. However, in order to do it, I can't rely on CssResource, which was the way I was used to do it with GWT. I think that this comes from the JS method which gets lost by this kind of styles... Instead, I have to specify everything in a static CSS stylesheet, and to give it to the JS.
It works perfectly well, ie, I have my widgets, with thei styles, and I can print it.
But...
The color of some widgets depends on the color of the object that they represent. Consequently, I cannot write a generic CSS stylesheet... And as I said, I can't add a style using CssResource... Do you have any ideas on the way to handle that ?
To make sure I'm clear on the way I'm adding styles, here is an example:
Label l = new Label("Here is a cell in my grid to be printed");
l.addStyleName("PrintLineCell-kind_1");
With, in a public CSS stylesheet:
.PrintLineCell-kind_1{
background-color: red;
}
I hope there is a better way than to write 300 styles to cover 300 different colors...

GWT : cell tree and initial keyboard selected node

I'm using a CellTree with the KeyboardSelectionPolicy.BOUND_TO_SELECTION.
I'd like to open the tree with a given path selected.
The code opening the child path and selecting the node is working fine when KeyboardSelectionPolicy is ENABLED/DISABLED but when BOUND_TO_SELECTION I can see that the keyboard-selected-node in the tree is never updated from : cellTree.selectionModel.setSelected( ... )
So I'm wondering if setSelected can work with BOUND_TO_SELECTION and how to do it.
See http://code.google.com/p/google-web-toolkit/issues/detail?id=6310
I suppose you could find a way to call setKeyboardSelectedRow in response to SelectionChangeEvents.