01: /*******************************************************************************
02: * Copyright (c) 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.cheatsheet;
11:
12: import java.lang.reflect.InvocationTargetException;
13:
14: import org.eclipse.core.resources.IFile;
15: import org.eclipse.jface.operation.IRunnableWithProgress;
16: import org.eclipse.jface.viewers.IStructuredSelection;
17: import org.eclipse.pde.internal.ui.PDEPlugin;
18: import org.eclipse.pde.internal.ui.PDEPluginImages;
19: import org.eclipse.pde.internal.ui.PDEUIMessages;
20: import org.eclipse.ui.INewWizard;
21: import org.eclipse.ui.IWorkbench;
22: import org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard;
23:
24: /**
25: * NewCheatSheetWizard
26: *
27: */
28: public class NewCSFileWizard extends BasicNewFileResourceWizard
29: implements INewWizard {
30:
31: protected CSFileWizardPage fMainPage;
32:
33: /**
34: *
35: */
36: public NewCSFileWizard() {
37: super ();
38: }
39:
40: /* (non-Javadoc)
41: * @see org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard#addPages()
42: */
43: public void addPages() {
44: fMainPage = new CSFileWizardPage("cheatsheet", getSelection()); //$NON-NLS-1$
45: addPage(fMainPage);
46: }
47:
48: /* (non-Javadoc)
49: * @see org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
50: */
51: public void init(IWorkbench workbench,
52: IStructuredSelection currentSelection) {
53: super .init(workbench, currentSelection);
54: setWindowTitle(PDEUIMessages.NewCheatSheetFileWizard_0);
55: setNeedsProgressMonitor(true);
56: }
57:
58: /* (non-Javadoc)
59: * @see org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard#initializeDefaultPageImageDescriptor()
60: */
61: protected void initializeDefaultPageImageDescriptor() {
62: setDefaultPageImageDescriptor(PDEPluginImages.DESC_CHEATSHEET_WIZ);
63: }
64:
65: /* (non-Javadoc)
66: * @see org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard#performFinish()
67: */
68: public boolean performFinish() {
69: try {
70: getContainer().run(false, true, getOperation());
71: } catch (InvocationTargetException e) {
72: PDEPlugin.logException(e);
73: return false;
74: } catch (InterruptedException e) {
75: return false;
76: }
77: return true;
78: }
79:
80: /**
81: * @return
82: */
83: private IRunnableWithProgress getOperation() {
84:
85: IFile file = fMainPage.createNewFile();
86: int option = fMainPage.getCheatSheetType();
87: if (option == CSFileWizardPage.F_SIMPLE_CHEAT_SHEET) {
88: return new SimpleCSCreationOperation(file);
89: } else if (option == CSFileWizardPage.F_COMPOSITE_CHEAT_SHEET) {
90: return new CompCSCreationOperation(file);
91: }
92: // This can never happen
93: PDEPlugin
94: .logErrorMessage("Unknown cheat sheet type encountered"); //$NON-NLS-1$
95: return null;
96: }
97: }
|