01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal;
11:
12: import org.eclipse.jface.action.Action;
13: import org.eclipse.ui.IWorkbenchWindow;
14: import org.eclipse.ui.PlatformUI;
15: import org.eclipse.ui.actions.ActionFactory;
16:
17: /**
18: * Try to quit the application.
19: */
20: public class QuitAction extends Action implements
21: ActionFactory.IWorkbenchAction {
22:
23: /**
24: * The workbench window; or <code>null</code> if this
25: * action has been <code>dispose</code>d.
26: */
27: private IWorkbenchWindow workbenchWindow;
28:
29: /**
30: * Creates a new <code>QuitAction</code>.
31: *
32: * @param window the window
33: */
34: public QuitAction(IWorkbenchWindow window) {
35: // Although window is not currently used,
36: // this follows the same pattern as other ActionFactory actions.
37: if (window == null) {
38: throw new IllegalArgumentException();
39: }
40: this .workbenchWindow = window;
41: setText(WorkbenchMessages.Exit_text);
42: setToolTipText(WorkbenchMessages.Exit_toolTip);
43: setActionDefinitionId("org.eclipse.ui.file.exit"); //$NON-NLS-1$
44: window.getWorkbench().getHelpSystem().setHelp(this ,
45: IWorkbenchHelpContextIds.QUIT_ACTION);
46: }
47:
48: /* (non-Javadoc)
49: * Method declared on IAction.
50: */
51: public void run() {
52: if (workbenchWindow == null) {
53: // action has been disposed
54: return;
55: }
56: PlatformUI.getWorkbench().close();
57: }
58:
59: /* (non-Javadoc)
60: * Method declared on ActionFactory.IWorkbenchAction.
61: */
62: public void dispose() {
63: workbenchWindow = null;
64: }
65:
66: }
|