Search in sources :

Example 1 with AbstractAccessListElement

use of org.netxms.client.users.AbstractAccessListElement 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;
}
Also used : User(org.netxms.client.users.User) NXCSession(org.netxms.client.NXCSession) AbstractAccessListElement(org.netxms.client.users.AbstractAccessListElement) IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) AbstractUserObject(org.netxms.client.users.AbstractUserObject) AbstractUserObject(org.netxms.client.users.AbstractUserObject) UserGroup(org.netxms.client.users.UserGroup)

Aggregations

IWorkbenchAdapter (org.eclipse.ui.model.IWorkbenchAdapter)1 NXCSession (org.netxms.client.NXCSession)1 AbstractAccessListElement (org.netxms.client.users.AbstractAccessListElement)1 AbstractUserObject (org.netxms.client.users.AbstractUserObject)1 User (org.netxms.client.users.User)1 UserGroup (org.netxms.client.users.UserGroup)1