1 11 12 package org.eclipse.pde.internal.ui.wizards.cheatsheet; 13 14 import java.lang.reflect.InvocationTargetException ; 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 37 public abstract class BaseCSCreationOperation extends 38 WorkspaceModifyOperation { 39 40 protected IFile fFile; 41 42 45 public BaseCSCreationOperation(IFile file) { 46 fFile = file; 47 } 48 49 52 public BaseCSCreationOperation(ISchedulingRule rule) { 53 super(rule); 54 } 55 56 59 protected void execute(IProgressMonitor monitor) throws CoreException, 60 InvocationTargetException , InterruptedException { 61 monitor.beginTask(PDEUIMessages.BaseCheatSheetCreationOperation_0, 2); 62 createContent(); 63 monitor.worked(1); 64 openFile(); 65 monitor.done(); 66 } 67 68 71 protected abstract void createContent(); 72 73 76 private void openFile() { 77 Display.getCurrent().asyncExec(new Runnable () { 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 } 98 } 99 }); 100 } 101 102 106 public static String formatTextBold(String text) { 107 StringBuffer buffer = new StringBuffer (); 109 buffer.append("<b>"); buffer.append(text); 111 buffer.append("</b>"); return buffer.toString(); 113 } 114 } 115 | Popular Tags |