com.clustercontrol.monitor.view.ScopeView.java Source code

Java tutorial

Introduction

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

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
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.monitor.composite.ScopeListComposite;
import com.clustercontrol.monitor.preference.MonitorPreferencePage;
import com.clustercontrol.view.ScopeListBaseView;
import com.clustercontrol.ws.repository.FacilityInfo;
import com.clustercontrol.ws.repository.FacilityTreeItem;
import com.clustercontrol.repository.FacilityPath;
import com.clustercontrol.repository.bean.FacilityConstant;
import com.clustercontrol.repository.util.ScopePropertyUtil;
import com.clustercontrol.util.EndpointManager;
import com.clustercontrol.util.Messages;
import com.clustercontrol.util.WidgetTestUtil;

/**
 * []<BR>
 *
 * @version 5.0.0
 * @since 1.0.0
 */
public class ScopeView extends ScopeListBaseView {
    public static final String ID = ScopeView.class.getName();

    /** ? */
    private ScopeListComposite tableComposite = null;

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

    /**
     * ????
     * <p>
     * <ol>
     * <li>????</li>
     * <li>???</li>
     * <li>??[]??????????</li>
     * <li>??[]??????????</li>
     * <li>???</li>
     * </ol>
     *
     * @param parent ??
     * @return ?
     *
     * @see com.clustercontrol.monitor.composite.ScopeListComposite#ScopeListComposite(Composite, int)
     * @see #update()
     */
    @Override
    protected Composite createListContents(Composite parent) {
        GridLayout layout = new GridLayout(1, true);
        parent.setLayout(layout);
        layout.marginHeight = 0;
        layout.marginWidth = 0;

        this.tableComposite = new ScopeListComposite(parent, SWT.NONE);
        WidgetTestUtil.setTestId(this, null, tableComposite);
        GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        this.tableComposite.setLayoutData(gridData);

        this.update(false);

        // ??
        IPreferenceStore store = ClusterControlPlugin.getDefault().getPreferenceStore();

        this.setInterval(store.getInt(MonitorPreferencePage.P_SCOPE_UPDATE_CYCLE));

        if (store.getBoolean(MonitorPreferencePage.P_SCOPE_UPDATE_FLG)) {
            this.startAutoReload();
        }

        return this.tableComposite;
    }

    /**
     * ??????????
     *
     * @param item 
     *
     * @see com.clustercontrol.monitor.composite.ScopeListComposite#update(String)
     */
    @Override
    protected void doSelectTreeItem(FacilityTreeItem selectItem) {
        FacilityPath path = new FacilityPath(ClusterControlPlugin.getDefault().getSeparator());
        setPathLabel(Messages.getString("scope") + " : " + path.getPath(selectItem));

        // Select root if nothing selected
        if (selectItem == null && 0 < getScopeTreeComposite().getTree().getItemCount()) {
            selectItem = (FacilityTreeItem) getScopeTreeComposite().getTree().getItem(0).getData();
        }

        if (selectItem != null) {
            FacilityInfo itemData = selectItem.getData();

            String managerName;
            String facilityId;
            if (itemData.getFacilityType() == FacilityConstant.TYPE_COMPOSITE) {
                this.tableComposite.update(EndpointManager.getActiveManagerNameList());
            } else if (itemData.getFacilityType() == FacilityConstant.TYPE_MANAGER) {
                managerName = selectItem.getData().getFacilityId();
                this.tableComposite.update(managerName, "");
            } else {
                FacilityTreeItem manager = ScopePropertyUtil.getManager(selectItem);
                managerName = manager.getData().getFacilityId();
                facilityId = selectItem.getData().getFacilityId();
                this.tableComposite.update(managerName, facilityId);
            }
        }
    }

    /**
     * ???<BR>
     * <p>
     * <ol>
     * <li>?????????</li>
     * <li>?ID????</li>
     * <li>ID?????</li>
     * </ol>
     *
     * @see com.clustercontrol.monitor.composite.ScopeListComposite#update(String)
     */
    @Override
    public void update(boolean refreshFlag) {
        FacilityTreeItem item = this.getScopeTreeComposite().getSelectItem();
        doSelectTreeItem(item);
    }
}