Add a checkbox to most parent tree element? - java

I want to add a checkbox widget to the most upper parent tree element like shown in http://www.smartclient.com/smartgwt/showcase/#tree_checkbox
How could I do this by just using GWT?
I only found that I can create a Tree*Item* with a checkbox and add it to the Tree:
TreeItem item = new TreeItem(new CheckBox("box"));
But how can I create a box for the Tree itself?

You need to assemble your own widget that extends gwt Composite class and wrap in it a tree/celltree , flowpanels and any widget you like to add like a select all checkbox.
You should be trying to use cell widget based CellTree - http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwCellTree
It is much more customizable and ensures better performance.

Related

JavaFx How to hide / show TreeItem

I have a TreeItem (a Tree with 100+ TreeItems elements).
I want to give the user the ability to hide (or show again) some TreeItems. (So the user will see just the items he care about).
I cant see a property of TreeItem which give me the ability to show or hide.
How can I do it ?
If you want to show/hide any TreeItem in TreeView you should add or remove it:
parentTreeItem.getChildren().remove(treeItem);
...
parentTreeItem.getChildren().add(treeItem);

How can I add a TableItem as a child to a TreeItem in SWT

When I expand a TreeItem, I want to show a Table with some data populated, instead of the usual tree items. I am not looking for something like TableTree.
Below is what I tried
Created a Tree(parent)
Created a treeItem(TI) within the parent
I want to show a table when I expand TI.
I tried
to create a TableItem with parent as TI, but found out it only takes Table as parent.
So I tried to create a Table with parent as TI, but found out it takes a Composite as parent, and TreeItem is not a composite
Thanks in advance

treeviewer does not deselect the tree item

I wanted to create dynamic tree struture in my application.
There my requirement is When the user selects any tree node
and click insert the child should be inserted below the selected parent. That is working fine. Now the problem is
i am unable to deselect the currently selected tree item in order to change tree item .
I clicked the background of the view and tried to insert
a new tree item, but still it goes to the previously selected tree node as still it highlight as the selected one. How to solve this issue?
If you create a TreeViewer with style SWT.SINGLE then the tree will insist on keeping an item selected unless you explicitly clear the selection.
To clear a selection use:
treeViewer.setSelection(StructuredSelection.EMPTY);
If you use SWT.MULTI as the tree style you can clear the selection with Ctrl+Click

add checkbox item inside Listbox gwt

How can we add Checkbox item inside Listbox or there is a checkboxlist i did not see ?
i want to get a list of checkboxes that i will after filter a list of appointments by checking those checkboxes
GWT 2.2 , java , eclipse
You can't add widgets like a CheckBox to a ListBox, nor is there a CheckBoxList, but you can use a CellList with a CompositeCell (TextCell + CheckboxCell) and it'll do what you want.
I don't think you can add checkboxes within the Listboxe.
You can probably create a List box with multiple selection enabled.
ListBox list = new ListBox();
list.setVisibleItemCount(10);
list.setMultipleSelect(true);
Here is something using GXT's XTemplate (if you want only GWT then use Template).
Other than that, how you pass your data is something you can define, but if you go with GXTs ModelData then this could work.
https://gist.github.com/Aadi1/4949994

Show/Hide JMenuItems in a JPopupMenu based on a JTree's selection

I have a JTree which displays a JPopupMenu when I right click nodes in the JTree. What is the best way to hide/show or enable/disable certain JMenuItems in my JPopupMenu based on the node selected in the JTree?
The first solution that came to mind was to add a TreeSelectionListener to the JTree for the 'value changed' event. In the event handling code I would use the TreeSelectionEvent's getNewLeadSelectionPath() method to get the path of the most recent selection, and use the resulting TreePath object's getLastPathComponent() to get the selected node. From here I would have a series of IF statements that access my JPopupMenu object and perform the modifications necessary to hide/show specific JMenuItems.
However, something feels off about this, and so I decided I would ask SO if there was a better approach.
The way that I chose to tackle this within my own app was to use the "userObject" property of the DefaultMutableTreeNode class which allows you to just store any data you want along with your node. I have a variety of types of things that extend from an abstract base class which defines a "createPopupMenu()" method. Then, in the selection listener (just as you described in your question) I get the user object and ask it to create a popup menu appropriate for the selected object and display that.
Getting the selected tree node is straight forward and should work as you described it. To modify the popup menu I would recommend using Actions. This way you wouldn’t have to modify your live menu and could also add e.g. a JToolBar that contains the same actions that react the same way the items in your menu do.

Categories

Resources