KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > actions > FormatAction


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.pde.internal.ui.editor.actions;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.pde.internal.ui.PDEPlugin;
17 import org.eclipse.pde.internal.ui.PDEUIMessages;
18 import org.eclipse.pde.internal.ui.editor.plugin.BundleSourcePage;
19 import org.eclipse.swt.widgets.Event;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.texteditor.ITextEditor;
22
23 public class FormatAction extends Action {
24
25     protected ITextEditor fTextEditor;
26     
27     public FormatAction() {
28         setText(PDEUIMessages.FormatManifestAction_actionText);
29     }
30
31     public void runWithEvent(Event event) {
32         run();
33     }
34     
35     public void run() {
36         if (fTextEditor == null || fTextEditor.getEditorInput() == null)
37             return;
38         
39         try {
40             PlatformUI.getWorkbench().getProgressService().busyCursorWhile(
41                     new FormatOperation(new Object JavaDoc[] {fTextEditor.getEditorInput()}));
42         } catch (InvocationTargetException JavaDoc e) {
43             PDEPlugin.log(e);
44         } catch (InterruptedException JavaDoc e) {
45             PDEPlugin.log(e);
46         }
47     }
48     
49     public void setTextEditor(ITextEditor textEditor) {
50         // TODO Temporary: Until plug-in manifest XML source page format
51
// functionality is completed
52
setEnabled(textEditor instanceof BundleSourcePage);
53         fTextEditor = textEditor;
54     }
55     
56 }
57
Popular Tags