KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > cheatsheet > BaseCSCreationOperation


1 /*******************************************************************************
2  * Copyright (c) 2006, 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
12 package org.eclipse.pde.internal.ui.wizards.cheatsheet;
13
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15
16 import org.eclipse.core.resources.IFile;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.core.runtime.jobs.ISchedulingRule;
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.jface.viewers.StructuredSelection;
22 import org.eclipse.pde.internal.ui.PDEPlugin;
23 import org.eclipse.pde.internal.ui.PDEUIMessages;
24 import org.eclipse.swt.widgets.Display;
25 import org.eclipse.ui.IWorkbenchPage;
26 import org.eclipse.ui.IWorkbenchPart;
27 import org.eclipse.ui.IWorkbenchWindow;
28 import org.eclipse.ui.PartInitException;
29 import org.eclipse.ui.actions.WorkspaceModifyOperation;
30 import org.eclipse.ui.ide.IDE;
31 import org.eclipse.ui.part.ISetSelectionTarget;
32
33 /**
34  * BaseCheatSheetCreationOperation
35  *
36  */

37 public abstract class BaseCSCreationOperation extends
38         WorkspaceModifyOperation {
39
40     protected IFile fFile;
41     
42     /**
43      *
44      */

45     public BaseCSCreationOperation(IFile file) {
46         fFile = file;
47     }
48
49     /**
50      * @param rule
51      */

52     public BaseCSCreationOperation(ISchedulingRule rule) {
53         super(rule);
54     }
55
56     /* (non-Javadoc)
57      * @see org.eclipse.ui.actions.WorkspaceModifyOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
58      */

59     protected void execute(IProgressMonitor monitor) throws CoreException,
60             InvocationTargetException JavaDoc, InterruptedException JavaDoc {
61         monitor.beginTask(PDEUIMessages.BaseCheatSheetCreationOperation_0, 2);
62         createContent();
63         monitor.worked(1);
64         openFile();
65         monitor.done();
66     }
67     
68     /**
69      *
70      */

71     protected abstract void createContent();
72     
73     /**
74      *
75      */

76     private void openFile() {
77         Display.getCurrent().asyncExec(new Runnable JavaDoc() {
78             public void run() {
79                 IWorkbenchWindow window = PDEPlugin.getActiveWorkbenchWindow();
80                 if (window == null) {
81                     return;
82                 }
83                 IWorkbenchPage page = window.getActivePage();
84                 if ((page == null) ||
85                         !fFile.exists()) {
86                     return;
87                 }
88                 IWorkbenchPart focusPart = page.getActivePart();
89                 if (focusPart instanceof ISetSelectionTarget) {
90                     ISelection selection = new StructuredSelection(fFile);
91                     ((ISetSelectionTarget) focusPart).selectReveal(selection);
92                 }
93                 try {
94                     IDE.openEditor(page, fFile);
95                 } catch (PartInitException e) {
96                     // Ignore
97
}
98             }
99         });
100     }
101     
102     /**
103      * @param text
104      * @return
105      */

106     public static String JavaDoc formatTextBold(String JavaDoc text) {
107         // TODO: MP: CompCS: Create generalized HTML formatter utility
108
StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
109         buffer.append("<b>"); //$NON-NLS-1$
110
buffer.append(text);
111         buffer.append("</b>"); //$NON-NLS-1$
112
return buffer.toString();
113     }
114 }
115
Popular Tags