I have created a tree using the following code. Is there a way to expand the tree till a particular child node from the code?
TreeGrid treeGrid = new TreeGrid();
Tree tree = new Tree();
tree.setRoot(new TreeNode("root", new TreeNode("File",
new TreeNode("FileChild")), new TreeNode("Edit", new TreeNode(
"EditChild", new TreeNode("EditGrandChild"))), new TreeNode(
"Window")));
treeGrid.setData(tree);
treeGrid.draw();
I want to display the "EditGrandChild" node when the tree is rendered. How do i do that?
Thanks
I used to open some parts of a treegrid depending on the result of a search and I used this bits of code
TreeNode[] tabNode = leTree.getParents(t);
leTree.openFolders(tabNode);
Hope it could help...
Related
I have a GWT UI Panel Created with Elements , and I need to add a GWT tree to the UI
I did
TreeItem department = new TreeItem("Packages");
TreeItem salesDepartment = new TreeItem("Package1");
TreeItem marketingDepartment = new TreeItem("Package2");
TreeItem manufacturingDepartment = new TreeItem("Package3");
TreeItem employee1 = new TreeItem("Flight");
TreeItem employee2 = new TreeItem("Cruilse");
TreeItem employee3 = new TreeItem("Flight");
salesDepartment.addItem(employee1);
salesDepartment.addItem(employee2);
salesDepartment.addItem(employee3);
TreeItem employee4 = new TreeItem("Cruise");
TreeItem employee5 = new TreeItem("Hotel");
marketingDepartment.addItem(employee4);
marketingDepartment.addItem(employee5);
TreeItem employee6 = new TreeItem("Cruise");
TreeItem employee7 = new TreeItem("Hotel");
manufacturingDepartment.addItem(employee6);
manufacturingDepartment.addItem(employee7);
department.addItem(salesDepartment);
department.addItem(marketingDepartment);
department.addItem(manufacturingDepartment);
Tree tree = new Tree();
tree.addItem(department);
// consider that treeDiv is already added
private Element treeDiv = DOM.createDiv();
DOM.appendChild( treeDiv , tree.getElement() );
when I added the tree widget as a Element it shows only text inputs no expand buttons or anything,its not working as a tree just texts.
please tell me is there any fix for this.
// consider that treeDiv is already added
private Element treeDiv = DOM.createDiv();
DOM.appendChild( treeDiv , tree.getElement() );
when I added the tree widget as a Element it shows only text inputs no expand buttons or anything,its not working as a tree just texts. please tell me is there any fix for this.
I'm not sure what that comment means, given that the tree was just created so could not have already been added, but even if that was a concern, I'm not sure why we must use the tree's element directly. If there are more pieces to this question you are skipping, please add them. For example: what is the treeDiv ever added to?
As a direct answer to the question, Don't Do This. Instead, use the widget's own add method, add widgets to other widgets, rather than directly manipulating the dom elements.
For example, if you are adding the tree to the <body> directly, this would look like this:
RootPanel.get().add(tree);
Or, if you already have a parent widget (called here panel), just add it directly to that parent:
panel.add(tree);
The reason for this is that the Widget wiring has its own event wiring that needs to be set up - to avoid memory leaks in the crappier browsers, it is important to make sure that event wiring is removed when the widgets are taken off the page. See http://www.gwtproject.org/articles/dom_events_memory_leaks_and_you.html for more details, but the short version is that after actually adding a widget's dom element to the greater dom, the widget's onAttach must be called, and any children widgets must also have their onAttach called as well. This is automatically done when adding a widget to another widget - you should stick to that API.
I am working on Eclipse plugin. In this I am creating a view like console which is based on tree structure.
I am creating tree like below --
ScrolledComposite sc = new ScrolledComposite(parent, SWT.V_SCROLL );
Composite composite1 = new Composite(sc, SWT.NONE);
Composite composite_1 = creatingcomposite(composite1);
final Tree tree = new Tree(composite_1, SWT.FULL_SELECTION );
TreeItem item = new TreeItem(tree, SWT.NONE);
TreeItem subItem = new TreeItem(item, SWT.NONE);
TreeItem subsubItem = new TreeItem(subItem, SWT.NONE);
Now I want to copy some data of node(Like item or sub item),
In any node of tree or tree item suppose there is some data like " Hi this is ram and my contact number is 123456789658" now from this row i want to select/copy the contact number.
so how can I do it with the help of mouse (as we use in any other interface like wordpad).
Look at swt snippets for basic swt tree and menu examples.
Create menu(pop up menu) on tree item(s).
On click of menu items (say copy phone number) get the selected node text and extract the phone number out of this.
I'm looking for a widget like this.
http://ppt.cc/RPfL
Clicking "View" and triangle (drop down icon) need to perform two different functions.
Clicking the triangle opening the menu.
I tried creating 2 buttons to emulate, but the 2 buttons have extra space in between them.
How can I eliminate the space between buttons or, is there a convenient way to accomplish this?
thank you all!!
An IconMenuButton (which is a sub class of IconButton) will provide what you need.
Menu menu = new Menu();
MenuItem newItem = new MenuItem("New");
MenuItem openItem = new MenuItem("Open");
MenuItem saveItem = new MenuItem("Save");
MenuItem saveAsItem = new MenuItem("Save As");
menu.setItems(newItem, openItem, saveItem, saveAsItem);
IconMenuButton menuButton = new IconMenuButton("View", menu);
Also check SmartGWT samples I've given in my comment and RibbonBar sample.
I'm trying to nest a FormPanel inside another FormPanel. It seems that any field in the nested panel is never rendered.
This screenshot is produced by the code below it:
TabItem tabItem = new TabItem("Tab Item");
FormPanel formPanel = new FormPanel();
formPanel.setHeading("Form Panel");
formPanel.setFrame(true);
TextField textField = new TextField();
textField.setFieldLabel("Text Field");
FormPanel nestedPanel = new FormPanel();
nestedPanel.setHeading("Nested Panel");
TextField nestedField = new TextField();
nestedField.setFieldLabel("Nested Field");
nestedPanel.add(nestedField);
TextField anotherField = new TextField();
anotherField.setFieldLabel("Another Field");
formPanel.add(textField);
formPanel.add(nestedPanel);
formPanel.add(anotherField);
tabItem.add(formPanel);
tabPanel.add(tabItem);
Can anyone explain why the nested field does not show in the nested panel?
I've also tried using a CaptionPanel instead of a FormPanel as the nested panel, but the caption panel does not show the field label.
Any suggestions as to how I can get this to work would be most welcome. Thank you :)
As Jason mentioned, <form> cannot be nested. The GXT FormPanel draws a form as part of how it works, so consider drawing this layout in another way.
To emulate the appearance of the FormPanel, there are two basic steps.
To get the header, border, create a ContentPanel, and add the content to that
To get the GXT 2 layout of drawing the field labels, use a FormLayout in the content panel.
This will look something like this (from your example)
//...
ContentPanel nestedPanel = new ContentPanel(new FormLayout();
nestedPanel.setHeading("Nested Panel");
TextField nestedField = new TextField();
nestedField.setFieldLabel("Nested Field");
nestedPanel.add(nestedField);
//...
The outer field will still manage any binding, and the nested field will look as if they were in a FormPanel. If not using other features of the FormPanel, it may in general make more sense to use a ContentPanel (or LayoutContainer, if you don't want the border/header) with a FormLayout.
I create a GWT Tree, and I would like it to be initially displayed with open nodes. Let's take the standard Tree example from GWT javadocs:
public class TreeExample implements EntryPoint {
public void onModuleLoad() {
// Create a tree with a few items in it.
TreeItem root = new TreeItem("root");
root.addItem("item0");
root.addItem("item1");
root.addItem("item2");
// Add a CheckBox to the tree
TreeItem item = new TreeItem(new CheckBox("item3"));
root.addItem(item);
Tree t = new Tree();
t.addItem(root);
// Add it to the root panel.
RootPanel.get().add(t);
}
}
I want it initially displayed as:
root
item0
item1
item2
item3
Now, I thought that it was as simple as setting the state of the TreeItem that I want to be opened by calling setState(true): javadoc for setState says "Sets whether this item's children are displayed". However, if I add for example
root.setState(true);
to the above example, I don't get the expected effect. Apparently nothing changes when I do root.setState(true); or root.setState(false);: the tree is always displayed with its nodes closed.
How do I get the desired behaviour?
The call to setState() depends on the sequence of the method calls to TreeItem and Tree (as stated here).
As a rule of thumb call setState(true) after adding all the items to the TreeItem and after adding the root item to the Tree.