webpumpprojectabstractactiondelegate.java

来自「一个eclipse插件源代码。用于web开发」· Java 代码 · 共 131 行

JAVA
131
字号
/*
 * $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/addmodule/WebpumpProjectAbstractActionDelegate.java,v 1.1.1.1 2004/07/01 09:07:39 wang_j Exp $
 * $Revision: 1.1.1.1 $
 * $Date: 2004/07/01 09:07:39 $
 *
 * ====================================================================
 *
 * The NanJing HopeRun(IT-FOREST) Software License, Version 2.0.0
 *
 * Copyright 2003-2004 by NanJing HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and
 *                        IT Forest Corporation
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
 * You shall not disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into with
 * HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
 */

package com.webpump.ui.addmodule;
 

import org.eclipse.core.resources.IProject;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;

import com.webpump.ui.perspective.WebpumpIDEPlugin;
import com.webpump.ui.wizard.WebpumpProject;

abstract public class WebpumpProjectAbstractActionDelegate implements IWorkbenchWindowActionDelegate {
    private IWorkbenchWindow window;
    private String msg;

    /*
     * @see IWorkbenchWindowActionDelegate#dispose()
     */
    public IWorkbenchWindow getWindow(){
        return this.window;
    }
    
    public void dispose() {
    }

    /*
     * @see IWorkbenchWindowActionDelegate#init(IWorkbenchWindow)
     */
    public void init(IWorkbenchWindow window) {
        this.window = window;
    }

    /*
     * @see IActionDelegate#run(IAction)
     */
    public void run(IAction action) {   
//        setMsgToSuccess(); //delete by caohx
        this.window = JavaPlugin.getActiveWorkbenchWindow();//add by caohx
        try {
            WebpumpProject prj = this.getCurrentSelection();
            
            if(prj != null) {
                this.doActionOn(prj);
            }
        } catch (WebpumpActionException ex) {
            setMsgToFail(ex.getMessage(), false);
        } catch (Exception ex) {
           // WebpumpLauncherPlugin.log(ex);
            setMsgToFail(ex.getMessage(), true);
        }
        
 /*       if(showMessageBox()) {
            Shell shell= JavaPlugin.getActiveWorkbenchShell();          
            MessageDialog.openInformation(shell,"Tomcat", msg);         
        }*/ //delete by caohx
    }

    /*
     * @see IActionDelegate#selectionChanged(IAction, ISelection)
     */
    public void selectionChanged(IAction action, ISelection selection) {

    }

    protected WebpumpProject getCurrentSelection() {
        IWorkbenchWindow window= JavaPlugin.getActiveWorkbenchWindow();
        WebpumpProject result = null;
        if (window != null) {
            ISelection selection= window.getSelectionService().getSelection();
            if (selection instanceof IStructuredSelection) {
                Object project = ((IStructuredSelection)selection).getFirstElement();
                if(project instanceof IProject)
                    result = WebpumpProject.create((IProject)project);
                if(project instanceof IJavaProject)
                    result = WebpumpProject.create((IJavaProject)project);
            }           
        }
        return result;
    }
    
    abstract public void doActionOn(WebpumpProject prj) throws Exception;
    public boolean showMessageBox() {
        return true;    
    };

    /**
     * Sets the msg.
     * @param msg The msg to set
     */
    private void setMsgToFail(String detail, boolean seelog) {
        this.msg = WebpumpIDEPlugin.getResourceString("msg.action.failed");
        this.msg += "\n" + detail;
        if(seelog) {    
            this.msg += WebpumpIDEPlugin.getResourceString("msg.action.seelog"); 
        }
    }
    
    /**
     * Sets the msg.
     * @param msg The msg to set
     */
    private void setMsgToSuccess() {
        this.msg = WebpumpIDEPlugin.getResourceString("msg.action.succeeded");
    }   
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?