com.clustercontrol.monitor.view.action.EventDetailAction.java Source code

Java tutorial

Introduction

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

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;

import com.clustercontrol.bean.Property;
import com.clustercontrol.monitor.action.CommentEvent;
import com.clustercontrol.monitor.action.GetEventListTableDefine;
import com.clustercontrol.monitor.composite.EventListComposite;
import com.clustercontrol.monitor.dialog.EventInfoDialog;
import com.clustercontrol.monitor.view.EventView;

/**
 * [?]???<BR>
 *
 * @version 5.0.0
 * @since 2.1.0
 */
public class EventDetailAction extends AbstractHandler {
    /**  */
    private static Log m_log = LogFactory.getLog(EventDetailAction.class);

    /** ID */
    public static final String ID = EventDetailAction.class.getName();

    private IWorkbenchWindow window;
    /**  */
    private IWorkbenchPart viewPart;

    /**
     * Dispose
     */
    @Override
    public void dispose() {
        this.viewPart = null;
        this.window = null;
    }

    /**
     * []????????
     * [?]????
     * <p>
     * <ol>
     * <li>[]??????????</li>
     * <li>????[?]???</li>
     * </ol>
     *
     * @see org.eclipse.core.commands.IHandler#execute
     * @see com.clustercontrol.monitor.view.EventView
     * @see com.clustercontrol.monitor.dialog.EventInfoDialog
     */
    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        this.window = HandlerUtil.getActiveWorkbenchWindow(event);
        // In case this action has been disposed
        if (null == this.window || !isEnabled()) {
            return null;
        }

        // ???
        this.viewPart = HandlerUtil.getActivePart(event);

        // ?????
        EventView view = null;
        try {
            view = (EventView) this.viewPart.getAdapter(EventView.class);
        } catch (Exception e) {
            m_log.info("execute " + e.getMessage());
            return null;
        }

        if (view == null) {
            m_log.info("execute: view is null");
            return null;
        }

        EventListComposite composite = (EventListComposite) view.getListComposite();

        StructuredSelection selection = (StructuredSelection) composite.getTableViewer().getSelection();

        List<?> list = (List<?>) selection.getFirstElement();

        if (list != null) {
            EventInfoDialog dialog = new EventInfoDialog(this.viewPart.getSite().getShell(), list);
            if (dialog.open() == IDialogConstants.OK_ID) {
                String managerName = (String) list.get(GetEventListTableDefine.MANAGER_NAME);
                Property prop = dialog.getInputData();
                CommentEvent comment = new CommentEvent();
                comment.updateComment(managerName, prop);
                view.update(false);
            }
        }
        return null;
    }
}