KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 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
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.jface.operation.IRunnableWithProgress;
18 import org.eclipse.jface.viewers.IStructuredSelection;
19 import org.eclipse.pde.internal.ui.PDEPlugin;
20 import org.eclipse.pde.internal.ui.PDEPluginImages;
21 import org.eclipse.pde.internal.ui.PDEUIMessages;
22 import org.eclipse.ui.INewWizard;
23 import org.eclipse.ui.IWorkbench;
24 import org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard;
25
26 /**
27  * NewCheatSheetWizard
28  *
29  */

30 public class NewCSFileWizard extends BasicNewFileResourceWizard implements INewWizard {
31
32     protected CSFileWizardPage fMainPage;
33     
34     /**
35      *
36      */

37     public NewCSFileWizard() {
38         super();
39     }
40
41     /* (non-Javadoc)
42      * @see org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard#addPages()
43      */

44     public void addPages() {
45         fMainPage = new CSFileWizardPage("cheatsheet", getSelection()); //$NON-NLS-1$
46
addPage(fMainPage);
47     }
48
49     /* (non-Javadoc)
50      * @see org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
51      */

52     public void init(IWorkbench workbench, 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 JavaDoc e) {
72             PDEPlugin.logException(e);
73             return false;
74         } catch (InterruptedException JavaDoc 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.logErrorMessage("Unknown cheat sheet type encountered"); //$NON-NLS-1$
94
return null;
95     }
96 }
97
Popular Tags