001: /*******************************************************************************
002: * Copyright (c) 2006, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.cheatsheet;
011:
012: import java.lang.reflect.InvocationTargetException;
013:
014: import org.eclipse.core.resources.IFile;
015: import org.eclipse.core.runtime.CoreException;
016: import org.eclipse.core.runtime.IProgressMonitor;
017: import org.eclipse.core.runtime.jobs.ISchedulingRule;
018: import org.eclipse.jface.viewers.ISelection;
019: import org.eclipse.jface.viewers.StructuredSelection;
020: import org.eclipse.pde.internal.ui.PDEPlugin;
021: import org.eclipse.pde.internal.ui.PDEUIMessages;
022: import org.eclipse.swt.widgets.Display;
023: import org.eclipse.ui.IWorkbenchPage;
024: import org.eclipse.ui.IWorkbenchPart;
025: import org.eclipse.ui.IWorkbenchWindow;
026: import org.eclipse.ui.PartInitException;
027: import org.eclipse.ui.actions.WorkspaceModifyOperation;
028: import org.eclipse.ui.ide.IDE;
029: import org.eclipse.ui.part.ISetSelectionTarget;
030:
031: /**
032: * BaseCheatSheetCreationOperation
033: *
034: */
035: public abstract class BaseCSCreationOperation extends
036: WorkspaceModifyOperation {
037:
038: protected IFile fFile;
039:
040: /**
041: *
042: */
043: public BaseCSCreationOperation(IFile file) {
044: fFile = file;
045: }
046:
047: /**
048: * @param rule
049: */
050: public BaseCSCreationOperation(ISchedulingRule rule) {
051: super (rule);
052: }
053:
054: /* (non-Javadoc)
055: * @see org.eclipse.ui.actions.WorkspaceModifyOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
056: */
057: protected void execute(IProgressMonitor monitor)
058: throws CoreException, InvocationTargetException,
059: InterruptedException {
060: monitor.beginTask(
061: PDEUIMessages.BaseCheatSheetCreationOperation_0, 2);
062: createContent();
063: monitor.worked(1);
064: openFile();
065: monitor.done();
066: }
067:
068: /**
069: *
070: */
071: protected abstract void createContent() throws CoreException;
072:
073: /**
074: *
075: */
076: private void openFile() {
077: Display.getCurrent().asyncExec(new Runnable() {
078: public void run() {
079: IWorkbenchWindow window = PDEPlugin
080: .getActiveWorkbenchWindow();
081: if (window == null) {
082: return;
083: }
084: IWorkbenchPage page = window.getActivePage();
085: if ((page == null) || !fFile.exists()) {
086: return;
087: }
088: IWorkbenchPart focusPart = page.getActivePart();
089: if (focusPart instanceof ISetSelectionTarget) {
090: ISelection selection = new StructuredSelection(
091: fFile);
092: ((ISetSelectionTarget) focusPart)
093: .selectReveal(selection);
094: }
095: try {
096: IDE.openEditor(page, fFile);
097: } catch (PartInitException e) {
098: // Ignore
099: }
100: }
101: });
102: }
103:
104: /**
105: * @param text
106: * @return
107: */
108: public static String formatTextBold(String text) {
109: // TODO: MP: CompCS: Create generalized HTML formatter utility
110: StringBuffer buffer = new StringBuffer();
111: buffer.append("<b>"); //$NON-NLS-1$
112: buffer.append(text);
113: buffer.append("</b>"); //$NON-NLS-1$
114: return buffer.toString();
115: }
116: }
|