com.clustercontrol.calendar.etc.action.CalendarWeekAction.java Source code

Java tutorial

Introduction

Here is the source code for com.clustercontrol.calendar.etc.action.CalendarWeekAction.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.calendar.etc.action;

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.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;

import com.clustercontrol.calendar.view.CalendarWeekView;

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

    /* (non-Javadoc)
     * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
     */
    @Override
    public void dispose() {

    }

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        //?
        IWorkbenchPage page = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();

        //?
        try {
            page.showView(CalendarWeekView.ID);
            IViewPart viewPart = page.findView(CalendarWeekView.ID);
            if (viewPart == null)
                throw new InternalError("viewPart is null.");
            CalendarWeekView view = (CalendarWeekView) viewPart.getAdapter(CalendarWeekView.class);
            if (view == null) {
                m_log.info("execute: view is null");
                return null;
            }
            view.setFocus();
        } catch (PartInitException e) {
        }
        return null;
    }

}