com.clustercontrol.jobmanagement.composite.DetailComposite.java Source code

Java tutorial

Introduction

Here is the source code for com.clustercontrol.jobmanagement.composite.DetailComposite.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.jobmanagement.composite;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
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.Tree;

import com.clustercontrol.util.WidgetTestUtil;
import com.clustercontrol.accesscontrol.util.ClientSession;
import com.clustercontrol.jobmanagement.action.GetJobDetailTableDefine;
import com.clustercontrol.jobmanagement.composite.action.JobDetailSelectionChangedListener;
import com.clustercontrol.jobmanagement.composite.action.SessionJobDoubleClickListener;
import com.clustercontrol.jobmanagement.util.JobEndpointWrapper;
import com.clustercontrol.jobmanagement.viewer.JobTableTreeViewer;
import com.clustercontrol.util.HinemosMessage;
import com.clustercontrol.util.Messages;
import com.clustercontrol.ws.jobmanagement.InvalidRole_Exception;
import com.clustercontrol.ws.jobmanagement.JobInfo;
import com.clustercontrol.ws.jobmanagement.JobTreeItem;

/**
 * []????
 *
 * @version 1.0.0
 * @since 1.0.0
 */
public class DetailComposite extends Composite {

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

    /**  */
    private JobTableTreeViewer m_viewer = null;
    /** ID */
    private String m_sessionId = null;
    /** ?ID */
    private String m_jobunitId = null;
    /** ID */
    private String m_jobId = null;
    /** ID */
    private Label m_sessionIdLabel = null;
    /** ??? */
    private String m_managerName = null;

    /**
     * 
     *
     * @param parent ??
     * @param style 
     *
     * @see org.eclipse.swt.SWT
     * @see org.eclipse.swt.widgets.Composite#Composite(Composite parent, int style)
     * @see #initialize()
     */
    public DetailComposite(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;

        //ID?
        m_sessionIdLabel = new Label(this, SWT.LEFT);
        WidgetTestUtil.setTestId(this, "sessionid", m_sessionIdLabel);
        GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        m_sessionIdLabel.setLayoutData(gridData);

        //?
        Tree tree = new Tree(this, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.SINGLE);
        WidgetTestUtil.setTestId(this, null, tree);

        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        gridData.horizontalSpan = 1;
        tree.setLayoutData(gridData);
        tree.setHeaderVisible(true);
        tree.setLinesVisible(true);

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

        m_viewer.addSelectionChangedListener(new JobDetailSelectionChangedListener(this));

        m_viewer.addDoubleClickListener(new SessionJobDoubleClickListener(this));

        update(null, null, null);
    }

    /**
     * ???<BR>
     * ???ID????
     * ????
     * <p>
     * <ol>
     * <li>???ID?????</li>
     * <li>????</li>
     * </ol>
     *
     * @param managerName ???
     * @param sessionId ID
     * @param jobunitId ?ID
     *
     * @see com.clustercontrol.jobmanagement.action.GetJobDetail#getJobDetail(String, String)
     * @see #setJobId(String)
     */
    public void update(String managerName, String sessionId, String jobunitId) {
        //?
        JobTreeItem item = null;
        if (sessionId != null && sessionId.length() > 0) {
            try {
                JobEndpointWrapper wrapper = JobEndpointWrapper.getWrapper(managerName);
                item = wrapper.getJobDetailList(sessionId);
            } catch (InvalidRole_Exception e) {
                if (ClientSession.isDialogFree()) {
                    ClientSession.occupyDialog();
                    MessageDialog.openInformation(null, Messages.getString("message"),
                            Messages.getString("message.accesscontrol.16"));
                    ClientSession.freeDialog();
                }
            } catch (Exception e) {
                m_log.warn("update() getJobDetailList, " + e.getMessage(), e);
                if (ClientSession.isDialogFree()) {
                    ClientSession.occupyDialog();
                    MessageDialog.openError(null, Messages.getString("failed"),
                            Messages.getString("message.hinemos.failure.unexpected") + ", "
                                    + HinemosMessage.replace(e.getMessage()));
                    ClientSession.freeDialog();
                }
            }
        }
        setItem(managerName, sessionId, jobunitId, item);
    }

    /**
     * ??????
     * @param managerName ???
     * @param sessionId ID
     * @param jobunitId ID
     * @param item 
     */
    public void setItem(String managerName, String sessionId, String jobunitId, JobTreeItem item) {
        if (item == null) {
            return;
        }
        m_viewer.setInput(item);
        m_viewer.expandAll();

        if (m_sessionId != null && m_sessionId.length() > 0 && sessionId != null && sessionId.length() > 0
                && m_sessionId.compareTo(sessionId) == 0) {
            selectDetail(item.getChildren().get(0));
        } else {
            setJobId(null);
        }
        m_managerName = managerName;
        m_sessionId = sessionId;
        m_jobunitId = jobunitId;

        //ID
        if (m_sessionId != null) {
            m_sessionIdLabel.setText(Messages.getString("session.id") + " : " + m_sessionId);
        } else {
            m_sessionIdLabel.setText(Messages.getString("session.id") + " : ");
        }
    }

    /**
     * ?????<BR>
     * ????ID???ID?????
     *
     * @param item 
     */
    public void selectDetail(JobTreeItem item) {
        if (getJobId() != null && getJobId().length() > 0) {
            if (m_viewer.getSelection().isEmpty()) {
                boolean select = false;
                JobInfo info = item.getData();
                if (info == null) {
                    m_log.info("selectDetail info is null");
                    return;
                }
                String jobId = info.getId();
                if (getJobId().compareTo(jobId) == 0) {
                    select = true;
                }

                if (select) {
                    m_viewer.setSelection(new StructuredSelection(item), true);
                } else {
                    for (int i = 0; i < item.getChildren().size(); i++) {
                        JobTreeItem children = item.getChildren().get(i);
                        selectDetail(children);
                    }
                }
            }
        }
    }

    /**
     * ????????
     *
     * @return 
     */
    public TreeViewer getTableTreeViewer() {
        return m_viewer;
    }

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

    public Tree getTree() {
        return m_viewer.getTree();
    }

    /**
     * ????????
     *
     * @return 
     */
    //   public TableTree getTableTree() {
    //      return m_viewer.getTableTree();
    //   }

    /**
     * ID???
     *
     * @return ID
     */
    public String getSessionId() {
        return m_sessionId;
    }

    /**
     * ID???
     *
     * @param sessionId ID
     */
    public void setSessionId(String sessionId) {
        m_sessionId = sessionId;
    }

    /**
     * ID???
     *
     * @return ID
     */
    public String getJobId() {
        return m_jobId;
    }

    /**
     * ID???
     *
     * @param jobId ID
     */
    public void setJobId(String jobId) {
        m_jobId = jobId;
    }

    /**
     * ?ID???
     *
     * @return ?ID
     */
    public String getJobunitId() {
        return m_jobunitId;
    }

    /**
     * ?ID???
     *
     * @param jobunitId ?ID
     */
    public void setJobunitId(String jobunitId) {
        m_jobunitId = jobunitId;
    }

    /**
     * ???????
     * @return the m_managerName
     */
    public String getManagerName() {
        return m_managerName;
    }

    /**
     * ??????
     * @param m_managerName the m_managerName to set
     */
    public void setManagerName(String managerName) {
        this.m_managerName = managerName;
    }

}