49 import org.symbian.tools.tmw.internal.ui.wizard.NewApplicationTemplateWizardPage; |
49 import org.symbian.tools.tmw.internal.ui.wizard.NewApplicationTemplateWizardPage; |
50 import org.symbian.tools.tmw.internal.ui.wizard.PageContributions; |
50 import org.symbian.tools.tmw.internal.ui.wizard.PageContributions; |
51 import org.symbian.tools.tmw.internal.ui.wizard.WizardContext; |
51 import org.symbian.tools.tmw.internal.ui.wizard.WizardContext; |
52 |
52 |
53 /** |
53 /** |
|
54 * This is the wizard that guides through new mobile application project creation. |
|
55 * |
54 * @author Eugene Ostroukhov (eugeneo@symbian.org) |
56 * @author Eugene Ostroukhov (eugeneo@symbian.org) |
55 */ |
57 */ |
56 public final class NewApplicationWizard extends ModifyFacetedProjectWizard implements INewWizard { |
58 public final class NewApplicationWizard extends ModifyFacetedProjectWizard implements INewWizard { |
57 public static final String ID = "org.symbian.tools.tmw.newproject"; |
59 public static final String ID = "org.symbian.tools.tmw.newproject"; |
|
60 |
58 private final PageContributions contributions = new PageContributions(); |
61 private final PageContributions contributions = new PageContributions(); |
59 private final DataBindingContext databindingContext = new DataBindingContext(); |
62 private final DataBindingContext databindingContext = new DataBindingContext(); |
60 private NewApplicationFacetsWizardPage facetsPage; |
63 private IWizardPage[] staticPages; |
61 private NewApplicationDetailsWizardPage firstPage; |
64 private NewApplicationDetailsWizardPage firstPage; |
62 private IStructuredSelection selection; |
|
63 private IProjectTemplate template = null; |
65 private IProjectTemplate template = null; |
64 private INewApplicationWizardPage[] templatePages = new INewApplicationWizardPage[0]; |
66 private INewApplicationWizardPage[] templatePages = new INewApplicationWizardPage[0]; |
65 private NewApplicationTemplateWizardPage templatesPage; |
|
66 private final WizardContext wizardContext = new WizardContext(); |
67 private final WizardContext wizardContext = new WizardContext(); |
67 private IWorkbench workbench; |
|
68 |
68 |
69 public NewApplicationWizard() { |
69 public NewApplicationWizard() { |
70 setShowFacetsSelectionPage(false); |
70 setShowFacetsSelectionPage(false); |
71 } |
71 } |
72 |
72 |
73 public void addPages() { |
73 public void addPages() { |
74 this.firstPage = createFirstPage(); |
74 firstPage = new NewApplicationDetailsWizardPage(wizardContext, databindingContext); |
75 addPage(this.firstPage); |
75 addPage(this.firstPage); |
76 final IFacetedProject project = getFacetedProject(); |
76 final IFacetedProject project = getFacetedProject(); |
77 final Set<IProjectFacetVersion> facets; |
77 final Set<IProjectFacetVersion> facets; |
78 if (project == null) { |
78 if (project == null) { |
79 facets = Collections.emptySet(); |
79 facets = Collections.emptySet(); |
80 } else { |
80 } else { |
81 facets = project.getProjectFacets(); |
81 facets = project.getProjectFacets(); |
82 } |
82 } |
83 facetsPage = new NewApplicationFacetsWizardPage(facets, getFacetedProjectWorkingCopy()); |
83 final IWizardPage facetsPage = new NewApplicationFacetsWizardPage(facets, getFacetedProjectWorkingCopy()); |
84 addPage(facetsPage); |
84 addPage(facetsPage); |
85 templatesPage = new NewApplicationTemplateWizardPage(wizardContext, databindingContext); |
85 final IWizardPage templatesPage = new NewApplicationTemplateWizardPage(wizardContext, databindingContext); |
86 addPage(templatesPage); |
86 addPage(templatesPage); |
|
87 staticPages = new IWizardPage[3]; |
|
88 staticPages[0] = firstPage; |
|
89 staticPages[1] = templatesPage; |
|
90 staticPages[2] = facetsPage; |
87 super.addPages(); |
91 super.addPages(); |
88 } |
92 } |
89 |
93 |
90 public boolean canFinish() { |
94 public boolean canFinish() { |
91 return getNextPage(getContainer().getCurrentPage()) == null && this.firstPage.isPageComplete() |
95 return getNextPage(getContainer().getCurrentPage()) == null && this.firstPage.isPageComplete() |
92 && super.canFinish(); |
96 && super.canFinish(); |
93 } |
|
94 |
|
95 protected NewApplicationDetailsWizardPage createFirstPage() { |
|
96 firstPage = new NewApplicationDetailsWizardPage(wizardContext, databindingContext); |
|
97 return firstPage; |
|
98 } |
97 } |
99 |
98 |
100 @Override |
99 @Override |
101 public IWizardPage getNextPage(final IWizardPage page) { |
100 public IWizardPage getNextPage(final IWizardPage page) { |
102 final IFacetedProjectWorkingCopy fpjwc = getFacetedProjectWorkingCopy(); |
101 final IFacetedProjectWorkingCopy fpjwc = getFacetedProjectWorkingCopy(); |
105 fpjwc.setProjectLocation(getProjectLocation()); |
104 fpjwc.setProjectLocation(getProjectLocation()); |
106 final IFProjSupport fprojSupport = TMWCore.getFProjSupport(); |
105 final IFProjSupport fprojSupport = TMWCore.getFProjSupport(); |
107 IRuntime runtime = fprojSupport.getRuntime(wizardContext.getRuntime()); |
106 IRuntime runtime = fprojSupport.getRuntime(wizardContext.getRuntime()); |
108 fpjwc.setTargetedRuntimes(Collections.singleton(runtime)); |
107 fpjwc.setTargetedRuntimes(Collections.singleton(runtime)); |
109 fpjwc.setPrimaryRuntime(runtime); |
108 fpjwc.setPrimaryRuntime(runtime); |
110 Set<IProjectFacetVersion> facets = getCurrentFixedFacetVersions(); |
|
111 facets.addAll(fpjwc.getProjectFacets()); |
|
112 fpjwc.setProjectFacets(facets); |
|
113 fpjwc.setFixedProjectFacets(getCurrentFixedFacets()); |
|
114 } else if (page == this.templatesPage) { |
|
115 Set<IProjectFacetVersion> facets = getCurrentFixedFacetVersions(); |
|
116 facets.addAll(fpjwc.getProjectFacets()); |
|
117 fpjwc.setProjectFacets(facets); |
|
118 fpjwc.setFixedProjectFacets(getCurrentFixedFacets()); |
|
119 } |
109 } |
120 final Collection<Action> actions = fpjwc.getProjectFacetActions(); |
110 final Collection<Action> actions = fpjwc.getProjectFacetActions(); |
121 final Collection<Action> toReplace = new HashSet<IFacetedProject.Action>(); |
111 final Collection<Action> toReplace = new HashSet<IFacetedProject.Action>(); |
122 for (Action action : actions) { |
112 for (Action action : actions) { |
123 if (action.getConfig() == ProjectCreationConfigFactory.CONFIG_STANDIN) { |
113 if (action.getConfig() == ProjectCreationConfigFactory.CONFIG_STANDIN) { |
125 } |
115 } |
126 } |
116 } |
127 for (Action action : toReplace) { |
117 for (Action action : toReplace) { |
128 fpjwc.setProjectFacetActionConfig(action.getProjectFacetVersion().getProjectFacet(), wizardContext); |
118 fpjwc.setProjectFacetActionConfig(action.getProjectFacetVersion().getProjectFacet(), wizardContext); |
129 } |
119 } |
130 |
120 final IWizardPage nextPage = super.getNextPage(page); |
131 IWizardPage nextPage = super.getNextPage(page); |
121 synchronized (currentFacets) { |
|
122 if (nextPage instanceof NewApplicationFacetsWizardPage && !reentry) { |
|
123 try { |
|
124 reentry = true; |
|
125 final IFacetedProjectWorkingCopy projectWorkingCopy = getFacetedProjectWorkingCopy(); |
|
126 final Set<IProjectFacetVersion> facets = projectWorkingCopy.getProjectFacets(); |
|
127 final Set<IProjectFacet> fixed = projectWorkingCopy.getFixedProjectFacets(); |
|
128 currentFacets.retainAll(facets); |
|
129 for (IProjectFacetVersion facetVersion : facets) { |
|
130 if (!fixed.contains(facetVersion.getProjectFacet())) { |
|
131 currentFacets.add(facetVersion); |
|
132 } |
|
133 } |
|
134 final Set<IProjectFacetVersion> f = getCurrentFixedFacetVersions(); |
|
135 f.addAll(currentFacets); |
|
136 fpjwc.setProjectFacets(f); |
|
137 fpjwc.setFixedProjectFacets(getCurrentFixedFacets()); |
|
138 } finally { |
|
139 reentry = false; |
|
140 } |
|
141 } |
|
142 } |
132 return nextPage; |
143 return nextPage; |
133 } |
144 } |
|
145 |
|
146 private boolean reentry = false; |
|
147 private final Collection<IProjectFacetVersion> currentFacets = new HashSet<IProjectFacetVersion>(); |
134 |
148 |
135 private Set<IProjectFacet> getCurrentFixedFacets() { |
149 private Set<IProjectFacet> getCurrentFixedFacets() { |
136 final Set<IProjectFacetVersion> fixedFacets = getCurrentFixedFacetVersions(); |
150 final Set<IProjectFacetVersion> fixedFacets = getCurrentFixedFacetVersions(); |
137 final Set<IProjectFacet> facets = new HashSet<IProjectFacet>(); |
151 final Set<IProjectFacet> facets = new HashSet<IProjectFacet>(); |
138 for (IProjectFacetVersion facet : fixedFacets) { |
152 for (IProjectFacetVersion facet : fixedFacets) { |
169 page.init(wizardContext, databindingContext); |
183 page.init(wizardContext, databindingContext); |
170 } |
184 } |
171 } |
185 } |
172 } |
186 } |
173 final IWizardPage[] base = super.getPages(); |
187 final IWizardPage[] base = super.getPages(); |
174 final IWizardPage[] pages = new IWizardPage[base.length + 3 + templatePages.length]; |
188 final IWizardPage[] pages = new IWizardPage[staticPages.length + templatePages.length]; |
175 |
189 System.arraycopy(staticPages, 0, pages, 0, 3); |
176 pages[0] = this.firstPage; |
|
177 pages[1] = this.templatesPage; |
|
178 pages[2] = this.facetsPage; |
|
179 if (templatePages.length > 0) { |
190 if (templatePages.length > 0) { |
180 System.arraycopy(templatePages, 0, pages, 3, templatePages.length); |
191 System.arraycopy(templatePages, 0, pages, 3, templatePages.length); |
181 } |
192 } |
182 System.arraycopy(base, 0, pages, 2, base.length); |
193 System.arraycopy(base, 0, pages, 2, base.length); |
183 |
194 |
190 |
201 |
191 protected String getProjectName() { |
202 protected String getProjectName() { |
192 return wizardContext.getProjectName(); |
203 return wizardContext.getProjectName(); |
193 } |
204 } |
194 |
205 |
195 /** |
|
196 * Returns the selection that this wizard was launched from. |
|
197 * |
|
198 * @return the selection that this wizard was launched from |
|
199 * @since 1.4 |
|
200 */ |
|
201 public IStructuredSelection getSelection() { |
|
202 return this.selection; |
|
203 } |
|
204 |
|
205 /** |
|
206 * Returns the workbench that this wizard belongs to. |
|
207 * |
|
208 * @return the workbench that this wizard belongs to |
|
209 * @since 1.4 |
|
210 */ |
|
211 public IWorkbench getWorkbench() { |
|
212 return this.workbench; |
|
213 } |
|
214 |
|
215 public void init(final IWorkbench workbench, final IStructuredSelection selection) { |
206 public void init(final IWorkbench workbench, final IStructuredSelection selection) { |
216 this.workbench = workbench; |
207 // Do nothing |
217 this.selection = selection; |
|
218 } |
208 } |
219 |
209 |
220 @Override |
210 @Override |
221 protected void performFinish(IProgressMonitor monitor) throws CoreException { |
211 protected void performFinish(IProgressMonitor monitor) throws CoreException { |
222 monitor.beginTask("Preparing project", 300); |
212 monitor.beginTask("Preparing project", 300); |