com.clustercontrol.collect.view.CollectGraphView.java Source code

Java tutorial

Introduction

Here is the source code for com.clustercontrol.collect.view.CollectGraphView.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.collect.view;

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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

import com.clustercontrol.ClusterControlPlugin;
import com.clustercontrol.collect.composite.CollectGraphComposite;
import com.clustercontrol.collect.composite.CollectSettingComposite;
import com.clustercontrol.composite.FacilityTreeComposite;
import com.clustercontrol.util.WidgetTestUtil;
import com.clustercontrol.view.CommonViewPart;
import com.clustercontrol.ws.repository.FacilityTreeItem;

/**
 * []
 *
 * @version 5.0.0
 * @since 4.0.0
 *
 */
public class CollectGraphView extends CommonViewPart {
    private static final Log m_log = LogFactory.getLog(CollectGraphView.class);

    public static final String ID = CollectGraphView.class.getName();

    // ?
    private FacilityTreeComposite scopeTreeComposite = null;
    private CollectSettingComposite collectSettingComposite = null;
    private CollectGraphComposite collectGraphComposite;

    /**  */
    private SashForm treeSash = null;

    /** ?? */
    private Composite baseComposite = null;

    /** ????????? */
    private int sashPer = 25;
    /** (##@##) */
    protected static final String SEPARATOR_HASH_HASH_AT_HASH_HASH = "##@##";

    /**
     * 
     */
    public CollectGraphView() {
    }

    protected String getViewName() {
        return this.getClass().getName();
    }

    /**
     * ????
     *
     * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
     */
    @Override
    public void createPartControl(Composite parent) {
        super.createPartControl(parent);
        // 
        GridLayout layout = new GridLayout(1, true);
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        parent.setLayout(layout);

        // ???
        treeSash = new SashForm(parent, SWT.HORIZONTAL);
        GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        gridData.horizontalSpan = 1;
        treeSash.setLayoutData(gridData);

        //// ??
        baseComposite = new Composite(treeSash, SWT.NONE);
        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        gridData.horizontalSpan = 1;
        baseComposite.setLayoutData(gridData);
        WidgetTestUtil.setTestId(this, null, baseComposite);
        FillLayout flayout = new FillLayout(SWT.VERTICAL);
        flayout.marginHeight = 0;
        flayout.marginWidth = 0;
        baseComposite.setLayout(flayout);

        SashForm baseCompositeSash = new SashForm(baseComposite, SWT.VERTICAL);
        Composite treeBaseComposite = new Composite(baseCompositeSash, SWT.NONE);
        treeBaseComposite.setLayout(new FillLayout(SWT.HORIZONTAL));

        // ?
        scopeTreeComposite = new FacilityTreeComposite(treeBaseComposite, SWT.NONE, null, false, // scope only
                false, // unregistered
                false, // internal
                true, // topic refresh
                true // checkflg
        );

        // ??
        collectSettingComposite = new CollectSettingComposite(baseCompositeSash, SWT.NONE, this);

        //// ???
        // ????
        collectGraphComposite = new CollectGraphComposite(treeSash, SWT.NONE, this);
        WidgetTestUtil.setTestId(this, null, collectGraphComposite);

        gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.horizontalSpan = 5;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        collectGraphComposite.setLayoutData(gridData);

        // Sash? 20% ?80%
        treeSash.setWeights(new int[] { sashPer, 100 - sashPer });
        baseCompositeSash.setWeights(new int[] { 40, 60 });

        // ??
        this.scopeTreeComposite.getTreeViewer().addSelectionChangedListener(new ISelectionChangedListener() {
            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                // ??(?????????)
                StructuredSelection selection = (StructuredSelection) event.getSelection();
                FacilityTreeItem selectItem = (FacilityTreeItem) selection.getFirstElement();
                if (selectItem != null) {
                    baseComposite.layout(true, true);
                    // ??
                    // doSelectTreeItem(selectItem);
                }
            }
        });
        ((CheckboxTreeViewer) this.scopeTreeComposite.getTreeViewer())
                .addCheckStateListener(new ICheckStateListener() {

                    @Override
                    public void checkStateChanged(CheckStateChangedEvent event) {
                        // itemCodeList????????
                        setItemCodeCheckedTreeItems();
                    }
                });

        // ??
        setSelectTreeItem(null);

    }

    /**
     * 
     */
    public void update() {
        long start = System.currentTimeMillis();
        m_log.debug("update()");
        //      graphComposite.update();

        m_log.debug(String.format("update: %dms", System.currentTimeMillis() - start));
    }

    /**
     * ???????????
     * Manager??itemCode????????<br>
     * ????itemCode????
     * 
     */
    public void setItemCodeCheckedTreeItems() {
        m_log.debug("setItemCodeCheckedTreeItems()");
        // ???????????
        collectSettingComposite.clearItem();

        List<String> selectStrList = scopeTreeComposite.getCheckedTreeInfo();
        if (selectStrList != null && selectStrList.size() != 0) {

            m_log.debug("setItemCodeCheckedTreeItems() itemCodeManager?????????");
            // ????itemName??????????
            collectSettingComposite.setCollectorItemCombo();
            collectSettingComposite.setSummaryItemCombo();
            collectSettingComposite.setGraphTypeItemCombo();
        }
    }

    @Override
    public void setFocus() {
    }

    /**
     * ?????Object???
     * FacilityTreeItem?????FacilityTreeItem????
     * @return
     */
    public List<FacilityTreeItem> getCheckedTreeItemList() {
        Object[] objs = ((CheckboxTreeViewer) this.scopeTreeComposite.getTreeViewer()).getCheckedElements();
        List<FacilityTreeItem> itemList = new ArrayList<>();
        for (Object obj : objs) {
            if (obj instanceof FacilityTreeItem) {
                itemList.add((FacilityTreeItem) obj);
            }
        }
        return itemList;
    }

    public CollectGraphComposite getCollectGraphComposite() {
        return collectGraphComposite;
    }

    public CollectSettingComposite getCollectSettingComposite() {
        return collectSettingComposite;
    }

    /**
     * ???
     */
    public void show() {
        m_log.debug("show");
        treeSash.setMaximizedControl(null);
    }

    /**
     * ???
     */
    public void hide() {
        m_log.debug("hide");
        treeSash.setMaximizedControl(collectGraphComposite);
    }

    /**
     * ???????
     * 
     * @param treeItem
     */
    private void setSelectTreeItem(List<String> selectNodeMapList) {

        m_log.debug(
                "setSelectTreeItem ????Preference????");

        // Preference??
        List<String> selectList = selectNodeMapList;
        if (selectList == null) {
            selectList = getSelectedInfoList();
        }

        // ???
        this.scopeTreeComposite.setSelectFacilityList(selectList);

        // ?????itemCode???????
        if (getCheckedTreeItemList().size() == 0)
            return;
        setItemCodeCheckedTreeItems();
        collectSettingComposite.setDefaultItemInfo();

    }

    /**
     * Preference??????P_COLLECT_GRAPH_SELECT_NODE_INFO(?)?"##@##"?split???String?????
     * 
     */
    private List<String> getSelectedInfoList() {
        String treeSelect = ClusterControlPlugin.getDefault().getPreferenceStore()
                .getString(CollectSettingComposite.P_COLLECT_GRAPH_SELECT_NODE_INFO);
        if (treeSelect == null || treeSelect.equals("")) {
            return null;
        }
        String array[] = treeSelect.split(SEPARATOR_HASH_HASH_AT_HASH_HASH);
        List<String> selectList = Arrays.asList(array);
        return selectList;
    }

    /**
     * ???????FacilityTreeComposite???
     * @return
     */
    public FacilityTreeComposite getFacilityTreeComposite() {
        return this.scopeTreeComposite;
    }

    public void setSelectFacilityListFromNodemap(List<String> selectNodeMapList) {
        setSelectTreeItem(selectNodeMapList);
        this.scopeTreeComposite.update();
    }

}