use of org.netxms.client.users.UserGroup in project netxms by netxms.
the class UserAdapterFactory method getAdapter.
/* (non-Javadoc)
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
if (adapterType == IWorkbenchAdapter.class) {
// NXCUser
if (adaptableObject instanceof User) {
return new IWorkbenchAdapter() {
@Override
public Object[] getChildren(Object o) {
return null;
}
@Override
public ImageDescriptor getImageDescriptor(Object object) {
// $NON-NLS-1$
return Activator.getImageDescriptor("icons/user.png");
}
@Override
public String getLabel(Object o) {
return ((User) o).getName();
}
@Override
public Object getParent(Object o) {
return null;
}
};
}
// NXCUserGroup
if (adaptableObject instanceof UserGroup) {
return new IWorkbenchAdapter() {
@Override
public Object[] getChildren(Object o) {
long[] members = ((UserGroup) o).getMembers();
AbstractUserObject[] childrens = new User[members.length];
for (int i = 0; i < members.length; i++) childrens[i] = ConsoleSharedData.getSession().findUserDBObjectById(members[i]);
return childrens;
}
@Override
public ImageDescriptor getImageDescriptor(Object object) {
// $NON-NLS-1$
return Activator.getImageDescriptor("icons/group.png");
}
@Override
public String getLabel(Object o) {
return ((UserGroup) o).getName();
}
@Override
public Object getParent(Object o) {
return null;
}
};
}
// AccessListElement
if (adaptableObject instanceof AbstractAccessListElement) {
return new IWorkbenchAdapter() {
@Override
public Object[] getChildren(Object o) {
return null;
}
@Override
public ImageDescriptor getImageDescriptor(Object object) {
long userId = ((AbstractAccessListElement) object).getUserId();
// $NON-NLS-1$ //$NON-NLS-2$
return Activator.getImageDescriptor((userId < 0x80000000L) ? "icons/user.png" : "icons/group.png");
}
@Override
public String getLabel(Object object) {
long userId = ((AbstractAccessListElement) object).getUserId();
NXCSession session = ConsoleSharedData.getSession();
AbstractUserObject dbo = session.findUserDBObjectById(userId);
// $NON-NLS-1$ //$NON-NLS-2$
return (dbo != null) ? dbo.getName() : ("{" + Long.toString(userId) + "}");
}
@Override
public Object getParent(Object o) {
return null;
}
};
}
}
return null;
}
Aggregations