Lines 52-57
Link Here
|
52 |
import java.net.URL; |
52 |
import java.net.URL; |
53 |
import java.util.ArrayList; |
53 |
import java.util.ArrayList; |
54 |
import java.util.Arrays; |
54 |
import java.util.Arrays; |
|
|
55 |
import java.util.Collection; |
55 |
import java.util.Collections; |
56 |
import java.util.Collections; |
56 |
import java.util.HashMap; |
57 |
import java.util.HashMap; |
57 |
import java.util.HashSet; |
58 |
import java.util.HashSet; |
Lines 60-69
Link Here
|
60 |
import java.util.Map; |
61 |
import java.util.Map; |
61 |
import java.util.NoSuchElementException; |
62 |
import java.util.NoSuchElementException; |
62 |
import java.util.Objects; |
63 |
import java.util.Objects; |
|
|
64 |
import java.util.Optional; |
63 |
import java.util.Set; |
65 |
import java.util.Set; |
64 |
import javax.swing.JComponent; |
66 |
import javax.swing.JComponent; |
65 |
import javax.swing.event.ChangeEvent; |
67 |
import javax.swing.event.ChangeEvent; |
66 |
import javax.swing.event.ChangeListener; |
68 |
import javax.swing.event.ChangeListener; |
|
|
69 |
import org.netbeans.api.annotations.common.NonNull; |
70 |
import org.netbeans.api.annotations.common.NullAllowed; |
67 |
import org.netbeans.api.java.classpath.ClassPath; |
71 |
import org.netbeans.api.java.classpath.ClassPath; |
68 |
import org.netbeans.api.java.classpath.JavaClassPathConstants; |
72 |
import org.netbeans.api.java.classpath.JavaClassPathConstants; |
69 |
import org.netbeans.api.java.project.JavaProjectConstants; |
73 |
import org.netbeans.api.java.project.JavaProjectConstants; |
Lines 90-95
Link Here
|
90 |
import org.openide.loaders.DataObject; |
94 |
import org.openide.loaders.DataObject; |
91 |
import org.openide.util.Exceptions; |
95 |
import org.openide.util.Exceptions; |
92 |
import org.openide.util.NbBundle.Messages; |
96 |
import org.openide.util.NbBundle.Messages; |
|
|
97 |
import org.netbeans.spi.java.project.support.ui.templates.JavaFileWizardIteratorFactory; |
93 |
|
98 |
|
94 |
/** |
99 |
/** |
95 |
* Wizard to create a new Java file. |
100 |
* Wizard to create a new Java file. |
Lines 161-167
Link Here
|
161 |
return new NewJavaFileWizardIterator(Type.MODULE_INFO); |
166 |
return new NewJavaFileWizardIterator(Type.MODULE_INFO); |
162 |
} |
167 |
} |
163 |
|
168 |
|
164 |
private WizardDescriptor.Panel[] createPanels (WizardDescriptor wizardDescriptor) { |
169 |
private WizardDescriptor.Panel[] createPanels ( |
|
|
170 |
@NonNull final WizardDescriptor wizardDescriptor, |
171 |
@NonNull final Collection<WizardDescriptor.Iterator<WizardDescriptor>> itOut) { |
165 |
|
172 |
|
166 |
// Ask for Java folders |
173 |
// Ask for Java folders |
167 |
Project project = Templates.getProject( wizardDescriptor ); |
174 |
Project project = Templates.getProject( wizardDescriptor ); |
Lines 178-195
Link Here
|
178 |
}; |
185 |
}; |
179 |
} |
186 |
} |
180 |
else { |
187 |
else { |
181 |
|
188 |
final List<WizardDescriptor.Panel<?>> panels = new ArrayList<>(); |
182 |
if (this.type == Type.FILE) { |
189 |
if (this.type == Type.FILE) { |
183 |
return new WizardDescriptor.Panel[] { |
190 |
panels.add(JavaTemplates.createPackageChooser( project, groups )); |
184 |
JavaTemplates.createPackageChooser( project, groups ), |
|
|
185 |
}; |
186 |
} else if (type == Type.PKG_INFO) { |
191 |
} else if (type == Type.PKG_INFO) { |
187 |
return new WizardDescriptor.Panel[] { |
192 |
panels.add(new JavaTargetChooserPanel(project, groups, null, Type.PKG_INFO, true)); |
188 |
new JavaTargetChooserPanel(project, groups, null, Type.PKG_INFO, true), |
|
|
189 |
}; |
190 |
} else if (type == Type.MODULE_INFO) { |
193 |
} else if (type == Type.MODULE_INFO) { |
191 |
List<WizardDescriptor.Panel> pnls = new ArrayList<>(); |
194 |
panels.add(new JavaTargetChooserPanel(project, groups, null, Type.MODULE_INFO, false)); |
192 |
pnls.add(new JavaTargetChooserPanel(project, groups, null, Type.MODULE_INFO, false)); |
|
|
193 |
Map<FileObject, Set<ClassPathItem>> group2items = new HashMap<>(); |
195 |
Map<FileObject, Set<ClassPathItem>> group2items = new HashMap<>(); |
194 |
for (SourceGroup group : groups) { |
196 |
for (SourceGroup group : groups) { |
195 |
try { |
197 |
try { |
Lines 211-219
Link Here
|
211 |
} catch (Exception ex) {} |
213 |
} catch (Exception ex) {} |
212 |
} |
214 |
} |
213 |
if (!group2items.isEmpty()) { |
215 |
if (!group2items.isEmpty()) { |
214 |
pnls.add(new MoveToModulePathPanel(group2items)); |
216 |
panels.add(new MoveToModulePathPanel(group2items)); |
215 |
} |
217 |
} |
216 |
return pnls.toArray(new WizardDescriptor.Panel[pnls.size()]); |
|
|
217 |
} else { |
218 |
} else { |
218 |
assert type == Type.PACKAGE; |
219 |
assert type == Type.PACKAGE; |
219 |
SourceGroup[] groovySourceGroups = sources.getSourceGroups(SOURCE_TYPE_GROOVY); |
220 |
SourceGroup[] groovySourceGroups = sources.getSourceGroups(SOURCE_TYPE_GROOVY); |
Lines 232-243
Link Here
|
232 |
all.addAll(Arrays.asList(resources)); |
233 |
all.addAll(Arrays.asList(resources)); |
233 |
groups = all.toArray(new SourceGroup[all.size()]); |
234 |
groups = all.toArray(new SourceGroup[all.size()]); |
234 |
} |
235 |
} |
235 |
return new WizardDescriptor.Panel[] { |
236 |
panels.add(new JavaTargetChooserPanel(project, groups, null, Type.PACKAGE, false)); |
236 |
new JavaTargetChooserPanel(project, groups, null, Type.PACKAGE, false), |
|
|
237 |
}; |
238 |
} |
237 |
} |
|
|
238 |
final JavaFileWizardIteratorFactory templateProvider = project.getLookup().lookup(JavaFileWizardIteratorFactory.class); |
239 |
if (templateProvider != null) { |
240 |
final WizardDescriptor.Iterator it = templateProvider.createIterator(Templates.getTemplate(wizardDescriptor )); |
241 |
if (it != null) { |
242 |
itOut.add(it); |
243 |
panels.add(it.current()); |
244 |
while(it.hasNext()) { |
245 |
it.nextPanel(); |
246 |
panels.add(it.current()); |
247 |
} |
248 |
} |
249 |
} |
250 |
return panels.toArray(new WizardDescriptor.Panel<?>[panels.size()]); |
239 |
} |
251 |
} |
240 |
|
|
|
241 |
} |
252 |
} |
242 |
|
253 |
|
243 |
private static SourceGroup[] checkNotNull (SourceGroup[] groups, Sources sources) { |
254 |
private static SourceGroup[] checkNotNull (SourceGroup[] groups, Sources sources) { |
Lines 284-297
Link Here
|
284 |
if (this.type == Type.PACKAGE) { |
295 |
if (this.type == Type.PACKAGE) { |
285 |
targetName = targetName.replace( '.', '/' ); // NOI18N |
296 |
targetName = targetName.replace( '.', '/' ); // NOI18N |
286 |
createdFile = FileUtil.createFolder( dir, targetName ); |
297 |
createdFile = FileUtil.createFolder( dir, targetName ); |
287 |
} |
298 |
} else { |
288 |
else { |
|
|
289 |
DataObject dTemplate = DataObject.find( template ); |
299 |
DataObject dTemplate = DataObject.find( template ); |
290 |
DataObject dobj = dTemplate.createFromTemplate( df, targetName ); |
300 |
DataObject dobj = dTemplate.createFromTemplate( df, targetName ); |
291 |
createdFile = dobj.getPrimaryFile(); |
301 |
createdFile = dobj.getPrimaryFile(); |
292 |
} |
302 |
} |
293 |
|
303 |
final Set<FileObject> res = new HashSet<>(); |
294 |
return Collections.singleton( createdFile ); |
304 |
res.add(createdFile); |
|
|
305 |
asInstantiatingIterator(projectSpecificIterator) |
306 |
.map((it)->{ |
307 |
try { |
308 |
return it.instantiate(); |
309 |
} catch (IOException ioe) { |
310 |
Exceptions.printStackTrace(ioe); |
311 |
return null; |
312 |
} |
313 |
}) |
314 |
.ifPresent(res::addAll); |
315 |
return Collections.unmodifiableSet(res); |
295 |
} |
316 |
} |
296 |
|
317 |
|
297 |
private void moveCPItems(Iterable<ClassPathItem> cpItemsToMove, FileObject folder) { |
318 |
private void moveCPItems(Iterable<ClassPathItem> cpItemsToMove, FileObject folder) { |
Lines 343-358
Link Here
|
343 |
} catch (Exception ex) {} |
364 |
} catch (Exception ex) {} |
344 |
} |
365 |
} |
345 |
} |
366 |
} |
|
|
367 |
|
368 |
@NonNull |
369 |
private static Optional<WizardDescriptor.InstantiatingIterator<WizardDescriptor>> asInstantiatingIterator( |
370 |
@NullAllowed final WizardDescriptor.Iterator<WizardDescriptor> it) { |
371 |
return Optional.ofNullable(it) |
372 |
.map((p)->{ |
373 |
return p instanceof WizardDescriptor.InstantiatingIterator ? |
374 |
(WizardDescriptor.InstantiatingIterator<WizardDescriptor>) p: |
375 |
null; |
376 |
}); |
377 |
} |
346 |
|
378 |
|
347 |
private transient int index; |
379 |
private transient int index; |
348 |
private transient WizardDescriptor.Panel[] panels; |
380 |
private transient WizardDescriptor.Panel[] panels; |
349 |
private transient WizardDescriptor wiz; |
381 |
private transient WizardDescriptor wiz; |
|
|
382 |
private transient WizardDescriptor.Iterator<WizardDescriptor> projectSpecificIterator; |
350 |
|
383 |
|
351 |
@Override |
384 |
@Override |
352 |
public void initialize(WizardDescriptor wiz) { |
385 |
public void initialize(WizardDescriptor wiz) { |
353 |
this.wiz = wiz; |
386 |
this.wiz = wiz; |
354 |
index = 0; |
387 |
index = 0; |
355 |
panels = createPanels( wiz ); |
388 |
final List<WizardDescriptor.Iterator<WizardDescriptor>> itOut = new ArrayList<>(1); |
|
|
389 |
panels = createPanels(wiz, itOut); |
390 |
projectSpecificIterator = itOut.get(0); |
391 |
asInstantiatingIterator(projectSpecificIterator) |
392 |
.ifPresent((it)->it.initialize(wiz)); |
356 |
// Make sure list of steps is accurate. |
393 |
// Make sure list of steps is accurate. |
357 |
String[] beforeSteps = null; |
394 |
String[] beforeSteps = null; |
358 |
Object prop = wiz.getProperty(WizardDescriptor.PROP_CONTENT_DATA); |
395 |
Object prop = wiz.getProperty(WizardDescriptor.PROP_CONTENT_DATA); |
Lines 380-387
Link Here
|
380 |
|
417 |
|
381 |
@Override |
418 |
@Override |
382 |
public void uninitialize (WizardDescriptor wiz) { |
419 |
public void uninitialize (WizardDescriptor wiz) { |
|
|
420 |
asInstantiatingIterator(projectSpecificIterator) |
421 |
.ifPresent((it)->it.uninitialize(wiz)); |
383 |
this.wiz = null; |
422 |
this.wiz = null; |
384 |
panels = null; |
423 |
panels = null; |
|
|
424 |
projectSpecificIterator = null; |
385 |
} |
425 |
} |
386 |
|
426 |
|
387 |
@Override |
427 |
@Override |