KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > codegen > ecore > ui > EmptyProjectWizard


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2005 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * EmptyProjectWizard.java,v 1.1 2005/05/06 02:19:59 marcelop Exp
16  */

17 package org.eclipse.emf.codegen.ecore.ui;
18
19 import java.util.Collections JavaDoc;
20
21 import org.eclipse.core.resources.IProject;
22 import org.eclipse.core.runtime.IPath;
23 import org.eclipse.core.runtime.IProgressMonitor;
24 import org.eclipse.core.runtime.Path;
25 import org.eclipse.core.runtime.Platform;
26 import org.eclipse.jface.viewers.ISelection;
27 import org.eclipse.jface.viewers.IStructuredSelection;
28 import org.eclipse.jface.viewers.StructuredSelection;
29 import org.eclipse.jface.wizard.Wizard;
30 import org.eclipse.ui.INewWizard;
31 import org.eclipse.ui.IWorkbench;
32 import org.eclipse.ui.IWorkbenchPage;
33 import org.eclipse.ui.IWorkbenchPart;
34 import org.eclipse.ui.actions.WorkspaceModifyOperation;
35 import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
36 import org.eclipse.ui.part.ISetSelectionTarget;
37
38 import org.eclipse.emf.codegen.ecore.Generator;
39 import org.eclipse.emf.codegen.ecore.genmodel.provider.GenModelEditPlugin;
40 import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
41
42
43 /**
44  * @since 2.1.0
45  */

46 public class EmptyProjectWizard extends Wizard implements INewWizard
47 {
48   protected IWorkbench workbench;
49   protected IPath genModelProjectLocation;
50   protected IPath genModelContainerPath;
51   protected IProject project;
52
53   public void init(IWorkbench workbench, IStructuredSelection selection)
54   {
55     this.workbench = workbench;
56     setDefaultPageImageDescriptor(ExtendedImageRegistry.INSTANCE.getImageDescriptor(GenModelEditPlugin.INSTANCE.getImage("full/wizban/NewEmptyEMFProject")));
57     setWindowTitle(GenModelEditPlugin.INSTANCE.getString("_UI_NewEmptyProject_title"));
58   }
59
60   public void addPages()
61   {
62     WizardNewProjectCreationPage newProjectCreationPage = new WizardNewProjectCreationPage("NewProjectCreationPage")
63       {
64         protected boolean validatePage()
65         {
66           if (super.validatePage())
67           {
68             IPath locationPath = getLocationPath();
69             genModelProjectLocation = Platform.getLocation().equals(locationPath) ? null : locationPath;
70             IPath projectPath = getProjectHandle().getFullPath();
71             genModelContainerPath = projectPath.append("src");
72             return true;
73           }
74           else
75           {
76             return false;
77           }
78         }
79       };
80
81     newProjectCreationPage.setTitle(GenModelEditPlugin.INSTANCE.getString("_UI_EmptyProject_title"));
82     newProjectCreationPage.setDescription(GenModelEditPlugin.INSTANCE.getString("_UI_EmptyProject_description"));
83     addPage(newProjectCreationPage);
84   }
85
86   public boolean performFinish()
87   {
88     WorkspaceModifyOperation operation = new WorkspaceModifyOperation()
89       {
90         protected void execute(IProgressMonitor progressMonitor)
91         {
92           try
93           {
94             project = Generator.createEMFProject(
95               new Path(genModelContainerPath.toString()),
96               genModelProjectLocation,
97               Collections.EMPTY_LIST,
98               progressMonitor,
99               Generator.EMF_MODEL_PROJECT_STYLE);
100           }
101           catch (Exception JavaDoc exception)
102           {
103             GenModelEditPlugin.INSTANCE.log(exception);
104           }
105           finally
106           {
107             progressMonitor.done();
108           }
109         }
110       };
111
112     try
113     {
114       getContainer().run(false, false, operation);
115     }
116     catch (Exception JavaDoc exception)
117     {
118       GenModelEditPlugin.INSTANCE.log(exception);
119       return false;
120     }
121
122     if (project != null)
123     {
124       IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
125       final IWorkbenchPart activePart = page.getActivePart();
126       if (activePart instanceof ISetSelectionTarget)
127       {
128         final ISelection targetSelection = new StructuredSelection(project);
129         getShell().getDisplay().asyncExec(new Runnable JavaDoc()
130           {
131             public void run()
132             {
133               ((ISetSelectionTarget)activePart).selectReveal(targetSelection);
134             }
135           });
136       }
137     }
138     
139     return true;
140   }
141 }
142
Popular Tags