hola a todos, he buscado un tree con checkboxes pero no he encontrado un componente o add on en el directorio de vaadin que se asemeje, asi que hice algo parecido a tree con checkbox (no es un componente nuevo), si tiene alguna sugerencia para mejorarlo les agradezco: esto es lo que hice
public class ArbolcheckApp extends Application {
private static final long serialVersionUID = -4849995480912548058L;
final static Object hw_PROPERTY_NAME = "name";
final static Object hw_PROPERTY_ICON = "icon";
final static ThemeResource x = new ThemeResource(
"../runo/icons/16/cancel.png" );
final static ThemeResource ok = new ThemeResource( "../runo/icons/16/ok.png" );
private Label label = new Label( "", 3 );
@Override
public void init() {
final Window mainWindow = new Window( "Arbolcheck Application" );
final Tree tree = new Tree( "Tree sortable using drag'n'drop",
getHardwareContainer() );
Button button = new Button( "Verificar", new Button.ClickListener() {
private static final long serialVersionUID = 638177444305472321L;
String values = "Elementos Seleccionados:<br>";
public void buttonClick( ClickEvent event ) {
for ( Object id : tree.rootItemIds() ) {
for ( Object id2 : tree.getChildren( id ) ) {
if (tree.getItemIcon( id2 ).toString() == "../runo/icons/16/ok.png") {
values += "Padre: " + id + " - Hijo: " + id2 + "<br>";
}
}
}
label.setValue( values );
values = "Elementos Seleccionados:<br>";
}
} );
mainWindow.addComponent( tree );
mainWindow.addComponent( button );
mainWindow.addComponent( label );
setMainWindow( mainWindow );
tree.setItemCaptionPropertyId( hw_PROPERTY_NAME );
tree.setItemIconPropertyId( hw_PROPERTY_ICON );
// Expand whole tree
for ( Object id : tree.rootItemIds() ) {
tree.expandItemsRecursively( id );
}
// Disallow selecting items from the tree
tree.setSelectable( false );
// listener
tree.addListener( new ItemClickEvent.ItemClickListener() {
private static final long serialVersionUID = -4061715387118131741L;
public void itemClick( ItemClickEvent event ) {
String ico = tree.getItemIcon( event.getItemId() ).toString();
// si presiono una x coloco un ok
if (event.getButton() == ItemClickEvent.BUTTON_LEFT
&& "../runo/icons/16/cancel.png".equals( ico ))
tree.setItemIcon( event.getItemId(), ok );
// si presiono un ok coloco un x
else if (event.getButton() == ItemClickEvent.BUTTON_LEFT
&& "../runo/icons/16/ok.png".equals( ico ))
tree.setItemIcon( event.getItemId(), x );
}
} );
}
public static HierarchicalContainer getHardwareContainer() {
final String[][]
hardware = { //
{ "Desktops", "Dell OptiPlex GX240", "Dell OptiPlex GX260",
"Dell OptiPlex GX280" },
{ "Monitors", "Benq T190HD", "Benq T220HD", "Benq T240HD" },
{ "Laptops", "IBM ThinkPad T40", "IBM ThinkPad T43", "IBM ThinkPad T60" } };
Item item = null;
int itemId = 0; // Increasing numbering for itemId:s
// Create new container
HierarchicalContainer hwContainer = new HierarchicalContainer();
// Create containerproperty for name
hwContainer.addContainerProperty( hw_PROPERTY_NAME, String.class, null );
// Create containerproperty for icon
hwContainer.addContainerProperty( hw_PROPERTY_ICON, ThemeResource.class, x );
for ( int i = 0; i < hardware.length; i++ ) {
// Add new item
item = hwContainer.addItem( itemId );
// Add name property for item
item.getItemProperty( hw_PROPERTY_NAME ).setValue( hardware[ i ]
[ 0 ]
);
// Allow children
hwContainer.setChildrenAllowed( itemId, true );
itemId++;
for ( int j = 1; j < hardware[ i ]
.length; j++ ) {
if (j == 1) {
item.getItemProperty( hw_PROPERTY_ICON ).setValue(
new ThemeResource( "../runo/icons/16/folder.png" ) );
}
// Add child items
item = hwContainer.addItem( itemId );
item.getItemProperty( hw_PROPERTY_NAME ).setValue( hardware[ i ]
[ j ]
);
hwContainer.setParent( itemId, itemId - j );
hwContainer.setChildrenAllowed( itemId, false );
itemId++;
}
}
return hwContainer;
}
}