com.clustercontrol.hub.view.LogScopeTreeView.java Source code

Java tutorial

Introduction

Here is the source code for com.clustercontrol.hub.view.LogScopeTreeView.java

Source

/*
    
Copyright (C) 2016 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.hub.view;

import org.apache.log4j.Logger;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
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.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;

import com.clustercontrol.accesscontrol.util.ClientSession;
import com.clustercontrol.composite.FacilityTreeComposite;
import com.clustercontrol.repository.util.ScopePropertyUtil;
import com.clustercontrol.util.Messages;
import com.clustercontrol.view.AutoUpdateView;
import com.clustercontrol.ws.repository.FacilityTreeItem;

/**
 * ??[]<BR>
 * ?[]????????
 * 
 */
public class LogScopeTreeView extends AutoUpdateView {

    public static final String ID = LogScopeTreeView.class.getName();
    // 
    private static Logger m_log = Logger.getLogger(LogScopeTreeView.class);

    // ----- instance  ----- //

    /** ?? */
    private FacilityTreeComposite scopeTreeComposite = null;

    /** ? */
    private Label pathLabel = null;

    /** ???? */
    private boolean scopeOnly = false;

    /** ????**/
    private boolean unregistered = true;

    /** ????**/
    private boolean internal = true;

    /** ???????? **/
    private boolean topicRefresh = true;

    // -----  ----- //

    /**
     * ?????
     * @wbp.parser.constructor
     */
    public LogScopeTreeView() {
        super();
        this.scopeOnly = false;
        this.unregistered = true;
        this.internal = true;
        this.topicRefresh = true;
    }

    /**
     * ?????
     *
     * @param scopeOnly ?????????
     * @param unregistered UNREGISTERED???????
     * @param internal INTERNAL???????
     * @param topicRefresh ???????????
     */
    public LogScopeTreeView(boolean scopeOnly, boolean unregistered, boolean internal, boolean topicRefresh) {
        super();
        this.scopeOnly = scopeOnly;
        this.unregistered = unregistered;
        this.internal = internal;
        this.topicRefresh = topicRefresh;
    }

    // ----- instance  ----- //

    /**
     * ????
     *
     * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
     */
    @Override
    public void createPartControl(Composite parent) {

        // 
        GridLayout layout = new GridLayout(1, true);
        parent.setLayout(layout);
        layout.marginHeight = 0;
        layout.marginWidth = 0;

        // ?
        this.scopeTreeComposite = new FacilityTreeComposite(parent, SWT.NONE, null, this.scopeOnly,
                this.unregistered, this.internal, this.topicRefresh);
        GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.verticalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        gridData.horizontalSpan = 1;
        this.scopeTreeComposite.setLayoutData(gridData);

        // ??
        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) {
                    // ??
                    doSelectTreeItem(selectItem);
                }
            }
        });
        this.scopeTreeComposite.getTreeViewer().addDoubleClickListener(new IDoubleClickListener() {
            @Override
            public void doubleClick(DoubleClickEvent event) {
                // ??(?????????)
                StructuredSelection selection = (StructuredSelection) event.getSelection();
                FacilityTreeItem selectItem = (FacilityTreeItem) selection.getFirstElement();
                if (selectItem != null) {
                    // ??
                    IWorkbenchWindow window = LogScopeTreeView.this.getSite().getWorkbenchWindow();
                    IWorkbenchPage page = window.getActivePage();
                    FacilityTreeItem managerTreeItem = ScopePropertyUtil.getManager(selectItem);
                    //?TOP?????????return
                    if (managerTreeItem == null) {
                        return;
                    }
                    String manager = managerTreeItem.getData().getFacilityId();
                    //??????????return
                    if (manager.equals(selectItem.getData().getFacilityId())) {
                        return;
                    }
                    try {
                        LogSearchView view = LogSearchView.createSearchView(page, manager,
                                selectItem.getData().getFacilityId());
                        m_log.debug("doubleClick(), open " + view.getTitle());

                        view.setFocus();
                        view.update();
                        //
                        //                  AbstractSearcher searcher
                        //                     = AbstractSearcher.simpleSearchBuilder(view.getManager()).setFacilityId(view.getFacilityId()).build();
                        //
                        //                  Integer fromPos = 0;
                        //                  Integer sizePos = LogPluginService.getDefault().getPreferenceStore().getInt(LogPreferencePage.P_SIZE_POS);
                        //                  
                        //                  LogSearchResponse res = searcher.search(fromPos, sizePos);
                        //
                        //                  view.setSearcher(searcher);
                        //                  view.getLogSearchComposite().getSearchResultComposite().reflectResult(res, fromPos, sizePos);
                        //                  String esQuery = searcher.convertToESQuery(null, null, false, null, null);
                        //                  view.getLogSearchComposite().getLogSearchConditionComposite().reflectAdvancedSearchQuery(esQuery);
                    } catch (PartInitException e) {
                        m_log.warn("doubleClick(), " + e.getMessage(), e);
                        //               } catch(LogSearchException e) {
                        //                  m_log.warn("LogSearch is Failed " + e.getMessage());
                        //                  MessageDialog.openWarning(
                        //                        null,
                        //                        Messages.getString("word.warn"),
                        //                        Messages.getString("message.search.failed") + "\n" + e.toString());
                    } catch (Exception e) {
                        m_log.warn("LogSearch is Failed " + e.getMessage());
                        MessageDialog.openWarning(null, Messages.getString("word.warn"),
                                Messages.getString("message.search.failed") + "\n" + e.toString());
                    }
                }
            }
        });
    }

    /**
     * ????
     * <p>
     *
     * ??????????
     *
     * @param parent
     *            ??
     */
    protected Composite createListContents(Composite parent) {
        return null;
    }

    /**
     * ???????????
     * <p>
     *
     * ??????????????
     *
     * @param item
     *            
     */
    protected void doSelectTreeItem(FacilityTreeItem item) {

    }

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

    /**
     * ????
     *
     * @return ?
     */
    public Label getPathLabel() {
        return this.pathLabel;
    }

    public void update() {
        //this.scopeTreeComposite.update();
        ClientSession.doCheck();
    }

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

    @Override
    public void update(boolean refreshFlag) {
        // TODO ???

    }
}