userList = userDao.getAllUsers();
userTable.addContainerProperty("UserID", String.class, null);
userTable.addContainerProperty("User Name", String.class, null);
userTable.addContainerProperty("Active", String.class, null);
for (int i = 0; i < userList.size(); i++) {
User e = userList.get(i);
Resource r = null;
try {
r = resDao.getResourceOfUser(e);
} catch (ResourceNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
boolean active = false;
if (r != null)
active = r.isActive();
userTable.addItem(
new Object[] { Integer.toString(e.getUserID()),
e.getUserName(), Boolean.toString(active) }, i);
}
} catch (DAOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("loading table failed");
}
//
userTable.setSelectable(true);
userTable.addListener(new ItemClickListener() {
/**
*
*/
private static final long serialVersionUID = -141353553631857791L;
public void itemClick(ItemClickEvent event) {
/*
* Space reserved for handling the proper event
*/
}
});
changeButton.addListener(new ClickListener() {
/**
*
*/
private static final long serialVersionUID = 2529988983021196127L;
public void buttonClick(ClickEvent event) {
Object o = userTable.getValue();
String uid = userTable.getItem(o).getItemProperty("UserID")
.toString();
try {
User changedUser = userDao.getUserByUserID(Integer
.parseInt(uid));
try {
Resource changedResource = resDao
.getResourceOfUser(changedUser);
changedResource.setActive(!changedResource.isActive());
resDao.updateResource(changedResource);
} catch (ResourceHasActiveProjectException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ResourceNotFoundException e) {
me.getApplication()
.getMainWindow()
.showNotification(
"Selected user is not associated with a resource");
e.printStackTrace();
} catch (ResourceNameExistsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DAOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UserNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
me.getApplication().getMainWindow()
.setContent(new DeleteUserPageUI(user));
}
});
resetPassButton.addListener(new ClickListener() {
/**
*
*/
private static final long serialVersionUID = 6620284795373485530L;
public void buttonClick(ClickEvent event) {
Object o = userTable.getValue();
String uid = userTable.getItem(o).getItemProperty("UserID")
.toString();
try {
User changedUser = userDao.getUserByUserID(Integer
.parseInt(uid));
changedUser.setPassword(Hash.hashString("1234"));
userDao.updateUser(changedUser);
me.getApplication().getMainWindow().showNotification("password set to 1234");
} catch (Exception e) {
}