KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > editors > text > RefreshEditorAction


1 /*******************************************************************************
2  * Copyright (c) 2007 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.editors.text;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.runtime.Assert;
17
18 import org.eclipse.core.resources.IResource;
19
20 import org.eclipse.jface.action.Action;
21
22 import org.eclipse.ui.actions.RefreshAction;
23 import org.eclipse.ui.texteditor.ITextEditor;
24 import org.eclipse.ui.texteditor.IUpdate;
25
26
27 /**
28  * Refresh text editor action.
29  * <p>
30  * XXX: This class illegally sublcasses {@link RefreshAction},
31  * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=182105 for details.
32  * </p>
33  *
34  * @since 3.3
35  */

36 public class RefreshEditorAction extends Action implements IUpdate {
37     
38     private ITextEditor fTextEditor;
39
40     public RefreshEditorAction(ITextEditor textEditor) {
41         Assert.isLegal(textEditor != null);
42         fTextEditor= textEditor;
43         update();
44     }
45     
46     /*
47      * @see org.eclipse.jface.action.Action#run()
48      */

49     public void run() {
50         final IResource resource= fTextEditor == null ? null : (IResource)fTextEditor.getEditorInput().getAdapter(IResource.class);
51         if (resource == null)
52             return;
53
54         RefreshAction impl= new RefreshAction(fTextEditor.getSite().getShell()) {
55             protected List JavaDoc getSelectedResources() {
56                 List JavaDoc result= new ArrayList JavaDoc(1);
57                 result.add(resource);
58                 return result;
59             }
60         };
61         impl.run();
62     }
63
64     /*
65      * @see org.eclipse.ui.texteditor.IUpdate#update()
66      */

67     public void update() {
68         final IResource resource= fTextEditor == null ? null : (IResource)fTextEditor.getEditorInput().getAdapter(IResource.class);
69         setEnabled(resource != null);
70     }
71
72 }
73
Popular Tags