KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.ui.IEditorPart;
14 import org.eclipse.ui.ISaveablePart;
15 import org.eclipse.ui.IWorkbenchWindow;
16
17 /**
18  * Workbench common <code>Save As</code> action.
19  */

20 public class SaveAsAction extends BaseSaveAction {
21
22     /**
23      * Create an instance of this class
24      *
25      * @param window the window
26      */

27     public SaveAsAction(IWorkbenchWindow window) {
28         super(WorkbenchMessages.SaveAs_text, window);
29         setActionDefinitionId("org.eclipse.ui.file.saveAs"); //$NON-NLS-1$
30
setText(WorkbenchMessages.SaveAs_text);
31         setToolTipText(WorkbenchMessages.SaveAs_toolTip);
32         setId("saveAs"); //$NON-NLS-1$
33
window.getWorkbench().getHelpSystem().setHelp(this,
34                 IWorkbenchHelpContextIds.SAVE_AS_ACTION);
35         setImageDescriptor(WorkbenchImages
36                 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_SAVEAS_EDIT));
37         setDisabledImageDescriptor(WorkbenchImages
38                 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_SAVEAS_EDIT_DISABLED));
39     }
40
41     /* (non-Javadoc)
42      * Method declared on Action.
43      */

44     public void run() {
45         if (getWorkbenchWindow() == null) {
46             // action has been disposed
47
return;
48         }
49         /* **********************************************************************************
50          * The code below was added to track the view with focus
51          * in order to support save actions from a view (see bug 10234).
52          */

53         ISaveablePart saveView = getSaveableView();
54         if (saveView != null) {
55             saveView.doSaveAs();
56             return;
57         }
58         /* **********************************************************************************/
59
60         IEditorPart editor = getActiveEditor();
61         if (editor != null) {
62             editor.doSaveAs();
63         }
64     }
65
66     /* (non-Javadoc)
67      * Method declared on ActiveEditorAction.
68      */

69     protected void updateState() {
70         /* **********************************************************************************
71          * The code below was added to track the view with focus
72          * in order to support save actions from a view (see bug 10234).
73          */

74         ISaveablePart saveView = getSaveableView();
75         if (saveView != null) {
76             setEnabled(saveView.isSaveAsAllowed());
77             return;
78         }
79         /* **********************************************************************************/
80
81         IEditorPart editor = getActiveEditor();
82         setEnabled(editor != null && editor.isSaveAsAllowed());
83     }
84 }
85
Popular Tags