KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > QuitAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal;
12
13 import org.eclipse.jface.action.Action;
14 import org.eclipse.ui.IWorkbenchWindow;
15 import org.eclipse.ui.PlatformUI;
16 import org.eclipse.ui.actions.ActionFactory;
17
18 /**
19  * Try to quit the application.
20  */

21 public class QuitAction extends Action implements
22         ActionFactory.IWorkbenchAction {
23
24     /**
25      * The workbench window; or <code>null</code> if this
26      * action has been <code>dispose</code>d.
27      */

28     private IWorkbenchWindow workbenchWindow;
29
30     /**
31      * Creates a new <code>QuitAction</code>.
32      *
33      * @param window the window
34      */

35     public QuitAction(IWorkbenchWindow window) {
36         // Although window is not currently used,
37
// this follows the same pattern as other ActionFactory actions.
38
if (window == null) {
39             throw new IllegalArgumentException JavaDoc();
40         }
41         this.workbenchWindow = window;
42         setText(WorkbenchMessages.Exit_text);
43         setToolTipText(WorkbenchMessages.Exit_toolTip);
44         setActionDefinitionId("org.eclipse.ui.file.exit"); //$NON-NLS-1$
45
window.getWorkbench().getHelpSystem().setHelp(this,
46                 IWorkbenchHelpContextIds.QUIT_ACTION);
47     }
48
49     /* (non-Javadoc)
50      * Method declared on IAction.
51      */

52     public void run() {
53         if (workbenchWindow == null) {
54             // action has been disposed
55
return;
56         }
57         PlatformUI.getWorkbench().close();
58     }
59
60     /* (non-Javadoc)
61      * Method declared on ActionFactory.IWorkbenchAction.
62      */

63     public void dispose() {
64         workbenchWindow = null;
65     }
66
67 }
68
Popular Tags