com.clustercontrol.accesscontrol.composite.SystemPrivilegeListComposite.java Source code

Java tutorial

Introduction

Here is the source code for com.clustercontrol.accesscontrol.composite.SystemPrivilegeListComposite.java

Source

/*
    
Copyright (C) 2006 NTT DATA Corporation
    
This program is free software; you can redistribute it and/or
Modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, version 2.
    
This program is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the GNU General Public License for more details.
    
 */

package com.clustercontrol.accesscontrol.composite;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;

import com.clustercontrol.accesscontrol.action.GetSystemPrivilegeListTableDefine;
import com.clustercontrol.accesscontrol.bean.RoleSettingTreeConstant;
import com.clustercontrol.accesscontrol.util.AccessEndpointWrapper;
import com.clustercontrol.accesscontrol.util.SystemPrivilegePropertyUtil;
import com.clustercontrol.bean.Property;
import com.clustercontrol.util.HinemosMessage;
import com.clustercontrol.util.Messages;
import com.clustercontrol.util.WidgetTestUtil;
import com.clustercontrol.viewer.CommonTableViewer;
import com.clustercontrol.ws.access.InvalidRole_Exception;
import com.clustercontrol.ws.access.RoleInfo;
import com.clustercontrol.ws.access.SystemPrivilegeInfo;
import com.clustercontrol.ws.access.UserInfo;

/**
 * [?]????
 *
 * ?????
 *
 * @version 2.0.0
 * @since 2.0.0
 */
public class SystemPrivilegeListComposite extends Composite {

    // 
    private static Log m_log = LogFactory.getLog(SystemPrivilegeListComposite.class);

    /**  */
    private CommonTableViewer m_viewer = null;
    /**  */
    private Label m_labelType = null;
    /**  */
    private Label m_labelCount = null;
    /**  */
    private Object m_data = null;

    /**
     * 
     *
     * @param parent ??
     * @param style 
     *
     * @see org.eclipse.swt.SWT
     * @see org.eclipse.swt.widgets.Composite#Composite(Composite parent, int style)
     * @see #initialize()
     */
    public SystemPrivilegeListComposite(Composite parent, int style) {
        super(parent, style);
        initialize();
    }

    /**
     * ?????
     */
    private void initialize() {
        GridLayout layout = new GridLayout(1, true);
        this.setLayout(layout);
        layout.marginHeight = 0;
        layout.marginWidth = 0;

        m_labelType = new Label(this, SWT.LEFT);
        WidgetTestUtil.setTestId(this, "type", m_labelType);
        GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        m_labelType.setLayoutData(gridData);

        // ??
        Table table = new Table(this, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.SINGLE);
        WidgetTestUtil.setTestId(this, null, table);
        table.setHeaderVisible(true);
        table.setLinesVisible(true);

        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        table.setLayoutData(gridData);

        // ???
        m_labelCount = new Label(this, SWT.RIGHT);
        WidgetTestUtil.setTestId(this, "count", m_labelCount);
        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        m_labelCount.setLayoutData(gridData);

        // ??
        m_viewer = new CommonTableViewer(table);
        m_viewer.createTableColumn(GetSystemPrivilegeListTableDefine.get(),
                GetSystemPrivilegeListTableDefine.SORT_COLUMN_INDEX, GetSystemPrivilegeListTableDefine.SORT_ORDER);
        for (int i = 0; i < table.getColumnCount(); i++) {
            table.getColumn(i).setMoveable(true);
        }
    }

    /**
     * ???<BR>
     * ???????
     *
     * @see com.clustercontrol.accesscontrol.action.GetUserList#getAll()
     */
    @Override
    public void update() {
        update(null, null);
    }

    /**
     * ???<BR>
     * ??????<BR>
     * ????
     *
     * @param selectedInfo ???RoleInfo/UserInfo<br>
     * ???????null?
     *
     * @see com.clustercontrol.accesscontrol.action.GetUserList#getJobEditState(Property)
     */
    public void update(String managerName, Object selectedInfo) {

        //??
        List<SystemPrivilegeInfo> infoList = null;
        try {
            if (selectedInfo != null) {
                AccessEndpointWrapper wrapper = AccessEndpointWrapper.getWrapper(managerName);
                if (selectedInfo instanceof RoleInfo) {
                    if (!((RoleInfo) selectedInfo).getRoleId().equals(RoleSettingTreeConstant.ROOT_ID)
                            && !((RoleInfo) selectedInfo).getRoleId().equals(RoleSettingTreeConstant.MANAGER)) {
                        infoList = wrapper
                                .getSystemPrivilegeInfoListByRoleId(((RoleInfo) selectedInfo).getRoleId());
                    }
                } else if (selectedInfo instanceof UserInfo) {
                    infoList = wrapper.getSystemPrivilegeInfoListByUserId(((UserInfo) selectedInfo).getUserId());
                }
            }
        } catch (InvalidRole_Exception e) {
            // ???
            MessageDialog.openInformation(null, Messages.getString("message"),
                    Messages.getString("message.accesscontrol.16"));

            // TODO??????
            //         // ??????????
            //         infoList = getOwnUserList();

        } catch (Exception e) {
            // ?
            m_log.warn("update(), " + HinemosMessage.replace(e.getMessage()), e);
            MessageDialog.openError(null, Messages.getString("failed"),
                    Messages.getString("message.hinemos.failure.unexpected") + ", "
                            + HinemosMessage.replace(e.getMessage()));
        }

        ArrayList<Object> listInput = new ArrayList<Object>();
        if (selectedInfo != null && infoList != null) {
            for (SystemPrivilegeInfo info : infoList) {
                ArrayList<Object> obj = new ArrayList<Object>();
                obj.add(SystemPrivilegePropertyUtil.getSystemPrivilegeName(managerName, info));
                obj.add(null);
                listInput.add(obj);
            }
        }

        m_viewer.setInput(listInput);

        Object[] args = { listInput.size() };
        if (selectedInfo == null) {
            m_labelType.setText("");
            m_labelCount.setText(Messages.getString("records", args));
        } else {
            if (selectedInfo instanceof RoleInfo) {
                if (((RoleInfo) selectedInfo).getRoleId().equals(RoleSettingTreeConstant.ROOT_ID)) {
                    m_labelType.setText("");
                    m_labelCount.setText(Messages.getString("records", args));
                } else {
                    RoleInfo roleInfo = (RoleInfo) selectedInfo;
                    m_labelType.setText(Messages.getString("role.name") + " : " + roleInfo.getRoleName() + "("
                            + roleInfo.getRoleId() + ")");
                    m_labelCount.setText(Messages.getString("filtered.records", args));
                }
            } else if (selectedInfo instanceof UserInfo) {
                UserInfo userInfo = (UserInfo) selectedInfo;
                m_labelType.setText(Messages.getString("user.name") + " : " + userInfo.getUserName() + "("
                        + userInfo.getUserId() + ")");
                m_labelCount.setText(Messages.getString("filtered.records", args));
            }
        }
    }

    /**
     * ????????
     *
     * @return 
     */
    public TableViewer getTableViewer() {
        return m_viewer;
    }

    /**
     * ????????
     *
     * @return 
     */
    public Table getTable() {
        return m_viewer.getTable();
    }

    /**
     * ???
     *
     * @return ????
     */
    @Override
    public Object getData() {
        return m_data;
    }

    /**
     * ???
     *
     * @param data ????
     */
    @Override
    public void setData(Object data) {
        m_data = data;
    }
}