}
}
}
break;
case WPaloEvent.EXPANDED_ACCOUNT_SECTION: //load tree data
TreeNode node = (TreeNode) event.data;
if (node != null) {
treeLoader.load(node);
}
break;
case WPaloEvent.SAVED_ACCOUNT_ITEM:
case WPaloEvent.SAVED_CONNECTION_ITEM:
if (treeStore == null) {
return;
}
TreeNode nd = (TreeNode) event.data;
if (nd != null) {
if(nd.getParent() != null)
treeStore.update(nd);
else {
int index = event.type == WPaloEvent.SAVED_ACCOUNT_ITEM ? 1 : 0;
treeStore.add(root.getChild(index), nd, false);
root.getChild(index).add(nd);
//shouldn't the store take care of this???
if(nd.getParent() == null)
nd.setParent(root.getChild(index));
}
}
if (event.type == WPaloEvent.SAVED_CONNECTION_ITEM) {
lastCreatedConnection = (XConnection) nd.getXObject();
final XUser admin = ((Workbench)Registry.get(Workbench.ID)).getUser();
final String adminUserId = admin.getId();
WPaloAdminServiceProvider.getInstance().hasAccount(admin.getSessionId(), lastCreatedConnection, new AsyncCallback<Boolean>(){
public void onFailure(Throwable arg0) {
}
public void onSuccess(Boolean result) {
if (!result) {
AdminHelpDialog dia = new AdminHelpDialog(
constants.adminHintAccountCreation(), adminUserId);
dia.showDialog();
}
}
});
}
break;
case WPaloEvent.DELETED_ITEM:
if (event.data instanceof TreeNode) {
XObject target = ((TreeNode) event.data).getXObject();
if (target != null && target instanceof XUser) {
HashSet <String> allIds = new HashSet<String>();
for (String accountId: ((XUser) target).getAccountIDs()) {
allIds.add(accountId);
}
ArrayList <TreeNode> toBeRemoved = new ArrayList<TreeNode>();
for (TreeNode nod: treeStore.getAllItems()) {
if (nod.getXObject() != null && nod.getXObject() instanceof XAccount) {
XAccount acc = (XAccount) nod.getXObject();
if (acc.getId() != null && allIds.contains(acc.getId())) {
toBeRemoved.add(nod);
}
}
}
for (TreeNode n: toBeRemoved) {
TreeNode parent = n.getParent();
treeStore.remove(parent, n);
}
treeStore.update(root);
} else if (target != null && target instanceof XConnection) {
ArrayList <TreeNode> toBeRemoved = new ArrayList<TreeNode>();
for (TreeNode nod: treeStore.getAllItems()) {
if (nod.getXObject() != null && nod.getXObject() instanceof XAccount) {
XAccount acc = (XAccount) nod.getXObject();
if (acc.getConnection().getId().equals(((XConnection) target).getId())) {
toBeRemoved.add(nod);
}
}
}
for (TreeNode n: toBeRemoved) {
TreeNode parent = n.getParent();
treeStore.remove(parent, n);
}
treeStore.update(root);
}
}