Hello vaadiners,
I got stucked on the ThreeTable component. I am using hibernate to fill treeTable with datas and all I want to achieve is this: When i click on the user in tree i want to show notification. I defined my own notification where I am using an object of entity User as a constructor parameter. The problem is, how to get that object to notification from click in the TreeTable?
package com.cooldatasoft.taskManager.user.gui;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import com.cooldatasoft.domain.model.Roles;
import com.cooldatasoft.domain.model.User;
import com.cooldatasoft.domain.model.UserProjectRoles;
import com.cooldatasoft.domain.service.RolesService;
import com.cooldatasoft.domain.service.UserProjectRolesService;
import com.cooldatasoft.domain.service.UserService;
import com.cooldatasoft.security.TaskManagerSecurityManager;
import com.cooldatasoft.taskManager.MainPage;
import com.cooldatasoft.taskManager.component.TaskManagerNotification;
import com.vaadin.annotations.AutoGenerated;
import com.vaadin.data.Item;
import com.vaadin.event.ItemClickEvent;
import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.TreeTable;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window.Notification;
@Configurable(preConstruction = true)
public class LeftPanel extends CustomComponent implements ItemClickListener {
@AutoGenerated
private AbsoluteLayout mainLayout;
@AutoGenerated
private VerticalLayout verticalLayout_1;
@Autowired
TaskManagerSecurityManager securityManager;
@Autowired
UserProjectRolesService userProjectRolesService;
@Autowired
RolesService rolesService;
@Autowired
UserService userService;
protected static final String NAME_PROPERTY = "Name";
protected static final String ROLE_PROPERTY = "Role";
protected static final String PROJECT_PROPERTY = "Project";
protected TreeTable treetable;
protected MainPage mainPage;
public void setMainPage(MainPage mainPage) {
this.mainPage = mainPage;
}
/**
* The constructor should first build the main layout, set the composition
* root and then do any custom initialization.
*
* The constructor will not be automatically regenerated by the visual
* editor.
*/
public LeftPanel() {
buildMainLayout();
setCompositionRoot(mainLayout);
createTreeTable();
verticalLayout_1.addComponent(treetable);
verticalLayout_1.setExpandRatio(treetable, 1.0f);
}
@AutoGenerated
private AbsoluteLayout buildMainLayout() {
// common part: create layout
mainLayout = new AbsoluteLayout();
mainLayout.setImmediate(false);
mainLayout.setWidth("100%");
mainLayout.setHeight("100%");
mainLayout.setMargin(false);
// top-level component properties
setWidth("100.0%");
setHeight("100.0%");
// verticalLayout_1
verticalLayout_1 = new VerticalLayout();
verticalLayout_1.setImmediate(false);
verticalLayout_1.setWidth("100.0%");
verticalLayout_1.setHeight("100.0%");
verticalLayout_1.setMargin(false);
mainLayout.addComponent(verticalLayout_1, "top:0.0px;left:0.0px;");
return mainLayout;
}
public void createTreeTable() {
// Create the treetable
treetable = new TreeTable();
treetable.setWidth("100.0%");
treetable.setHeight("100.0%");
// Add Table columns
treetable.addContainerProperty(PROJECT_PROPERTY, String.class, "");
treetable.addListener(this);
treetable.setImmediate(true);
treetable.setSelectable(true);
List<UserProjectRoles> projects = userProjectRolesService
.getUserProjectRolesByIdUser(securityManager.getCurrentUser());
List<Roles> roles = rolesService.getAllRoles();
Object proj = null;
Object role = null;
Object user = null;
List<UserProjectRoles> userss = new ArrayList<UserProjectRoles>();
for (UserProjectRoles upr : projects) {
proj = treetable.addItem(new Object[] { upr.getIdProject()
.getName() }, null);
treetable.setParent(proj, null);
for (Roles r : roles) {
role = treetable
.addItem(new Object[] { r.getRoleName() }, null);
treetable.setParent(role, proj);
userss = userService.getUsersByRole(upr.getIdProject(), r);
for (UserProjectRoles u : userss) {
user = treetable.addItem(new Object[] { u.getIdUser()
.toString() /*
* ,user_on_project.getIdRole().getRoleName
* ()
*/}, null);
treetable.setParent(user, role);
treetable.setCollapsed(user, true);
treetable.setChildrenAllowed(user, false);
}
}
treetable.setCollapsed(proj, true);
}
}
@Override
public void itemClick(ItemClickEvent event) {
switch (event.getButton()) {
case ItemClickEvent.BUTTON_LEFT:
Item clickedItem = treetable.getContainerDataSource().getItem(event.getItemId());
String parameter = clickedItem.getItemProperty("email").getValue().toString();
User user = userService.getUserByEmail(parameter);
getWindow().showNotification(TaskManagerNotification.showTableNotification("User info", user));
break;
}
}
}
Any ides?