# HG changeset patch # User Jesse Glick # Date 1314823578 14400 #191951: introduce BackgroundInstantiatingIterator to perform work after the wizard has been closed. diff --git a/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NbmWizardIterator.java b/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NbmWizardIterator.java --- a/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NbmWizardIterator.java +++ b/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NbmWizardIterator.java @@ -55,7 +55,6 @@ import javax.swing.event.ChangeListener; import javax.xml.namespace.QName; import org.apache.maven.cli.MavenCli; -import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectManager; import org.netbeans.api.validation.adapters.WizardDescriptorAdapter; @@ -84,7 +83,7 @@ import org.openide.util.NbBundle.Messages; import static org.netbeans.modules.maven.apisupport.Bundle.*; -public class NbmWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator { +public class NbmWizardIterator implements WizardDescriptor.BackgroundInstantiatingIterator { public static final String NBM_ARTIFACTID = "nbm_artifactId"; @@ -154,30 +153,21 @@ @Override public Set instantiate() throws IOException { - assert false : "Cannot call this method if implements WizardDescriptor.ProgressInstantiatingIterator."; //NOI18N - return null; - } - - @Override - public Set instantiate(ProgressHandle handle) throws IOException { ProjectInfo vi = new ProjectInfo((String) wiz.getProperty("groupId"), (String) wiz.getProperty("artifactId"), (String) wiz.getProperty("version"), (String) wiz.getProperty("package")); //NOI18N ArchetypeWizards.logUsage(archetype.getGroupId(), archetype.getArtifactId(), archetype.getVersion()); - try { String nbm_artifactId = (String) wiz.getProperty(NBM_ARTIFACTID); - int max = nbm_artifactId != null ? 7 : 4; - handle.start(max); File projFile = FileUtil.normalizeFile((File) wiz.getProperty("projdir")); // NOI18N String version = (String) wiz.getProperty(NB_VERSION); Map additional = version != null ? Collections.singletonMap("netbeansVersion", version) : null; // NOI18N - ArchetypeWizards.createFromArchetype(handle, projFile, vi, archetype, additional, 0, true); + ArchetypeWizards.createFromArchetype(projFile, vi, archetype, additional, true); if (nbm_artifactId != null && projFile.exists()) { //NOW we have the nbm-Platform or nbm suite template //create the nbm module ProjectInfo nbm = new ProjectInfo(vi.groupId, nbm_artifactId, vi.version, vi.packageName); File nbm_folder = FileUtil.normalizeFile(new File(projFile, nbm_artifactId)); - ArchetypeWizards.createFromArchetype(handle, nbm_folder, nbm, NB_MODULE_ARCH, additional, 2, false); + ArchetypeWizards.createFromArchetype(nbm_folder, nbm, NB_MODULE_ARCH, additional, false); trimInheritedFromNbmProject(nbm_folder); if (archetype == NB_APP_ARCH) { File appDir = new File(projFile, "application"); //NOI18N @@ -228,11 +218,7 @@ addSnapshotRepo(projFile); } Templates.setDefinesMainProject(wiz, projects.size() > 1); - handle.progress(max); return projects; - } finally { - handle.finish(); - } } @Override diff --git a/maven/src/org/netbeans/modules/maven/api/archetype/ArchetypeWizards.java b/maven/src/org/netbeans/modules/maven/api/archetype/ArchetypeWizards.java --- a/maven/src/org/netbeans/modules/maven/api/archetype/ArchetypeWizards.java +++ b/maven/src/org/netbeans/modules/maven/api/archetype/ArchetypeWizards.java @@ -47,7 +47,6 @@ import java.util.Map; import java.util.Set; import org.netbeans.api.annotations.common.NullAllowed; -import org.netbeans.api.progress.ProgressHandle; import org.netbeans.modules.maven.model.ModelOperation; import org.netbeans.modules.maven.model.pom.POMModel; import org.netbeans.modules.maven.newproject.ArchetypeWizardUtils; @@ -65,16 +64,14 @@ /** * Run a single archetype. - * @param handle a progress handle * @param projDir the new project directory (must be normalized first!) (note: parent dir is actually passed to plugin, i.e. assumes that project name matches this basedir) * @param vi metadata for new project * @param arch the archetype to process * @param additionalProperties any additional archetype properties, or null - * @param progressCounter step to set progress handle to (will step to this number +1 and +2) * @param updateLastUsedProjectDir true to update last-used project directory for next wizard run */ - public static void createFromArchetype(ProgressHandle handle, File projDir, ProjectInfo vi, Archetype arch, @NullAllowed Map additionalProperties, int progressCounter, boolean updateLastUsedProjectDir) throws IOException { - ArchetypeWizardUtils.createFromArchetype(handle, projDir, vi, arch, additionalProperties, progressCounter, updateLastUsedProjectDir); + public static void createFromArchetype(File projDir, ProjectInfo vi, Archetype arch, @NullAllowed Map additionalProperties, boolean updateLastUsedProjectDir) throws IOException { + ArchetypeWizardUtils.createFromArchetype(projDir, vi, arch, additionalProperties, updateLastUsedProjectDir); } /** diff --git a/maven/src/org/netbeans/modules/maven/newproject/ArchetypeWizardUtils.java b/maven/src/org/netbeans/modules/maven/newproject/ArchetypeWizardUtils.java --- a/maven/src/org/netbeans/modules/maven/newproject/ArchetypeWizardUtils.java +++ b/maven/src/org/netbeans/modules/maven/newproject/ArchetypeWizardUtils.java @@ -64,7 +64,6 @@ import org.netbeans.modules.maven.api.execute.RunUtils; import org.netbeans.modules.maven.execute.BeanRunConfig; import org.netbeans.modules.maven.options.MavenCommandSettings; -import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectManager; import org.netbeans.modules.maven.api.ModelUtils; @@ -72,7 +71,6 @@ import org.netbeans.modules.maven.api.archetype.ProjectInfo; import org.netbeans.modules.maven.indexer.api.RepositoryPreferences; import org.netbeans.modules.maven.model.ModelOperation; -import org.netbeans.modules.maven.model.Utilities; import org.netbeans.modules.maven.model.pom.Dependency; import org.netbeans.modules.maven.model.pom.POMModel; import org.netbeans.spi.project.ui.support.ProjectChooser; @@ -281,9 +279,9 @@ } /** - * Instantiates archetype stored in given wizard descriptor, with progress UI notification. + * Instantiates archetype stored in given wizard descriptor. */ - static Set instantiate(ProgressHandle handle, WizardDescriptor wiz) throws IOException { + static Set instantiate(WizardDescriptor wiz) throws IOException { ProjectInfo vi = new ProjectInfo((String) wiz.getProperty("groupId"), (String) wiz.getProperty("artifactId"), (String) wiz.getProperty("version"), (String) wiz.getProperty("package")); //NOI18N Archetype arch = (Archetype) wiz.getProperty("archetype"); //NOI18N @@ -292,46 +290,11 @@ @SuppressWarnings("unchecked") Map additional = (Map) wiz.getProperty(ADDITIONAL_PROPS); - try { - ProjectInfo ear_vi = (ProjectInfo)wiz.getProperty("ear_versionInfo"); //NOI18N - if (ear_vi != null) { - // enterprise application wizard, multiple archetypes to run - ProjectInfo web_vi = (ProjectInfo)wiz.getProperty("web_versionInfo"); //NOI18N - ProjectInfo ejb_vi = (ProjectInfo)wiz.getProperty("ejb_versionInfo"); //NOI18N - - handle.start(8 + (web_vi != null ? 3 : 0) + (ejb_vi != null ? 3 : 0)); - File rootFile = FileUtil.normalizeFile((File) wiz.getProperty("projdir")); // NOI18N - createFromArchetype(handle, rootFile, vi, arch, additional, 0, true); - File earFile = FileUtil.normalizeFile((File) wiz.getProperty("ear_projdir")); // NOI18N - createFromArchetype(handle, earFile, ear_vi, (Archetype) wiz.getProperty("ear_archetype"), null, 4, false); //NOI18N - int progressCounter = 6; - if (web_vi != null) { - createFromArchetype(handle, FileUtil.normalizeFile((File)wiz.getProperty("web_projdir")), web_vi, //NOI18N - (Archetype)wiz.getProperty("web_archetype"), null, progressCounter, false); //NOI18N - progressCounter += 3; - } - if (ejb_vi != null) { - createFromArchetype(handle, FileUtil.normalizeFile((File)wiz.getProperty("ejb_projdir")), ejb_vi, //NOI18N - (Archetype)wiz.getProperty("ejb_archetype"), null, progressCounter, false); //NOI18N - progressCounter += 3; - } - addEARDeps((File)wiz.getProperty("ear_projdir"), ejb_vi, web_vi); - progressCounter++; - Set projects = openProjects(rootFile, earFile); - handle.progress(++progressCounter); - return projects; - } else { - handle.start(4); - File projFile = FileUtil.normalizeFile((File) wiz.getProperty("projdir")); // NOI18N - createFromArchetype(handle, projFile, vi, arch, additional, 0, true); - Set projects = openProjects(projFile, null); - handle.progress(4); - Templates.setDefinesMainProject(wiz, projects.size() > 1); - return projects; - } - } finally { - handle.finish(); - } + File projFile = FileUtil.normalizeFile((File) wiz.getProperty("projdir")); // NOI18N + createFromArchetype(projFile, vi, arch, additional, true); + Set projects = openProjects(projFile, null); + Templates.setDefinesMainProject(wiz, projects.size() > 1); + return projects; } private static final String loggerName = "org.netbeans.ui.metrics.maven"; // NOI18N @@ -345,9 +308,7 @@ Logger.getLogger(loggerName).log(logRecord); } - public static void createFromArchetype(ProgressHandle handle, File projDir, ProjectInfo vi, Archetype arch, @NullAllowed Map additional, int progressCounter, boolean updateLastUsedProjectDir) throws IOException { - handle.progress(++progressCounter); - + public static void createFromArchetype(File projDir, ProjectInfo vi, Archetype arch, @NullAllowed Map additional, boolean updateLastUsedProjectDir) throws IOException { final File parent = projDir.getParentFile(); if (parent == null) { throw new IOException("no parent of " + projDir); @@ -358,11 +319,7 @@ if (!parent.isDirectory() && !parent.mkdirs()) { throw new IOException("could not create " + parent); } - handle.progress(NbBundle.getMessage(MavenWizardIterator.class, "PRG_Processing_Archetype"), ++progressCounter); - runArchetype(parent, vi, arch, additional); - - handle.progress(++progressCounter); } public static Set openProjects(File dirF, File mainProjectDir) throws IOException { @@ -410,24 +367,6 @@ } } - private static void addEARDeps (File earDir, ProjectInfo ejbVi, ProjectInfo webVi) { - FileObject earDirFO = FileUtil.toFileObject(FileUtil.normalizeFile(earDir)); - if (earDirFO == null) { - return; - } - List> operations = new ArrayList>(); - if (ejbVi != null) { - // EAR ---> ejb - operations.add(new AddDependencyOperation(ejbVi, "ejb")); - } - if (webVi != null) { - // EAR ---> war - operations.add(new AddDependencyOperation(webVi, "war")); - } - - Utilities.performPOMModelOperations(earDirFO.getFileObject("pom.xml"), operations); - } - public static class AddDependencyOperation implements ModelOperation { private final String group; private final String artifact; diff --git a/maven/src/org/netbeans/modules/maven/newproject/BasicEEWizardIterator.java b/maven/src/org/netbeans/modules/maven/newproject/BasicEEWizardIterator.java --- a/maven/src/org/netbeans/modules/maven/newproject/BasicEEWizardIterator.java +++ b/maven/src/org/netbeans/modules/maven/newproject/BasicEEWizardIterator.java @@ -48,7 +48,6 @@ import java.util.Set; import javax.swing.JComponent; import javax.swing.event.ChangeListener; -import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.validation.adapters.WizardDescriptorAdapter; import org.netbeans.modules.maven.api.archetype.Archetype; import org.netbeans.validation.api.ui.ValidationGroup; @@ -59,7 +58,7 @@ * *@author Dafe Simonek */ -public class BasicEEWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator { +public class BasicEEWizardIterator implements WizardDescriptor.BackgroundInstantiatingIterator { private int index; private WizardDescriptor.Panel[] panels; @@ -98,12 +97,7 @@ } public Set/**/ instantiate() throws IOException { - assert false : "Cannot call this method if implements WizardDescriptor.ProgressInstantiatingIterator."; //NOI18N - return null; - } - - public Set instantiate(ProgressHandle handle) throws IOException { - return ArchetypeWizardUtils.instantiate(handle, wiz); + return ArchetypeWizardUtils.instantiate(wiz); } public void initialize(WizardDescriptor wiz) { diff --git a/maven/src/org/netbeans/modules/maven/newproject/EAWizardIterator.java b/maven/src/org/netbeans/modules/maven/newproject/EAWizardIterator.java --- a/maven/src/org/netbeans/modules/maven/newproject/EAWizardIterator.java +++ b/maven/src/org/netbeans/modules/maven/newproject/EAWizardIterator.java @@ -43,30 +43,37 @@ package org.netbeans.modules.maven.newproject; import java.awt.Component; +import java.io.File; import java.io.IOException; import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; import javax.swing.JComponent; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.validation.adapters.WizardDescriptorAdapter; +import org.netbeans.modules.maven.api.archetype.Archetype; +import org.netbeans.modules.maven.api.archetype.ProjectInfo; +import org.netbeans.modules.maven.model.ModelOperation; +import org.netbeans.modules.maven.model.Utilities; +import org.netbeans.modules.maven.model.pom.POMModel; import org.netbeans.validation.api.ui.ValidationGroup; import org.openide.WizardDescriptor; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; import org.openide.util.NbBundle; /** * *@author Dafe Simonek */ -public class EAWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator { +public class EAWizardIterator implements WizardDescriptor.BackgroundInstantiatingIterator { private static final long serialVersionUID = 1L; - private static final String USER_DIR_PROP = "user.dir"; //NOI18N static final String PROPERTY_CUSTOM_CREATOR = "customCreator"; //NOI18N private transient int index; private transient WizardDescriptor.Panel[] panels; @@ -97,14 +104,49 @@ } public Set/**/ instantiate() throws IOException { - assert false : "Cannot call this method if implements WizardDescriptor.ProgressInstantiatingIterator."; //NOI18N - return null; + ProjectInfo ear_vi = (ProjectInfo) wiz.getProperty("ear_versionInfo"); //NOI18N + assert ear_vi != null; + // enterprise application wizard, multiple archetypes to run + ProjectInfo web_vi = (ProjectInfo) wiz.getProperty("web_versionInfo"); //NOI18N + ProjectInfo ejb_vi = (ProjectInfo) wiz.getProperty("ejb_versionInfo"); //NOI18N + File rootFile = FileUtil.normalizeFile((File) wiz.getProperty("projdir")); // NOI18N + ProjectInfo vi = new ProjectInfo((String) wiz.getProperty("groupId"), (String) wiz.getProperty("artifactId"), (String) wiz.getProperty("version"), (String) wiz.getProperty("package")); //NOI18N + Archetype arch = (Archetype) wiz.getProperty("archetype"); //NOI18N + @SuppressWarnings("unchecked") + Map additional = (Map) wiz.getProperty(ArchetypeWizardUtils.ADDITIONAL_PROPS); + ArchetypeWizardUtils.createFromArchetype(rootFile, vi, arch, additional, true); + File earFile = FileUtil.normalizeFile((File) wiz.getProperty("ear_projdir")); // NOI18N + ArchetypeWizardUtils.createFromArchetype(earFile, ear_vi, (Archetype) wiz.getProperty("ear_archetype"), null, false); //NOI18N + if (web_vi != null) { + ArchetypeWizardUtils.createFromArchetype(FileUtil.normalizeFile((File) wiz.getProperty("web_projdir")), web_vi, //NOI18N + (Archetype) wiz.getProperty("web_archetype"), null, false); //NOI18N + } + if (ejb_vi != null) { + ArchetypeWizardUtils.createFromArchetype(FileUtil.normalizeFile((File) wiz.getProperty("ejb_projdir")), ejb_vi, //NOI18N + (Archetype) wiz.getProperty("ejb_archetype"), null, false); //NOI18N + } + addEARDeps((File) wiz.getProperty("ear_projdir"), ejb_vi, web_vi); + return ArchetypeWizardUtils.openProjects(rootFile, earFile); } - public Set instantiate(ProgressHandle handle) throws IOException { - return ArchetypeWizardUtils.instantiate(handle, wiz); + private static void addEARDeps (File earDir, ProjectInfo ejbVi, ProjectInfo webVi) { + FileObject earDirFO = FileUtil.toFileObject(FileUtil.normalizeFile(earDir)); + if (earDirFO == null) { + return; + } + List> operations = new ArrayList>(); + if (ejbVi != null) { + // EAR ---> ejb + operations.add(new ArchetypeWizardUtils.AddDependencyOperation(ejbVi, "ejb")); + } + if (webVi != null) { + // EAR ---> war + operations.add(new ArchetypeWizardUtils.AddDependencyOperation(webVi, "war")); + } + + Utilities.performPOMModelOperations(earDirFO.getFileObject("pom.xml"), operations); } - + public void initialize(WizardDescriptor wiz) { this.wiz = wiz; index = 0; diff --git a/maven/src/org/netbeans/modules/maven/newproject/MavenWizardIterator.java b/maven/src/org/netbeans/modules/maven/newproject/MavenWizardIterator.java --- a/maven/src/org/netbeans/modules/maven/newproject/MavenWizardIterator.java +++ b/maven/src/org/netbeans/modules/maven/newproject/MavenWizardIterator.java @@ -50,7 +50,6 @@ import java.util.Set; import javax.swing.JComponent; import javax.swing.event.ChangeListener; -import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.validation.adapters.WizardDescriptorAdapter; import org.netbeans.modules.maven.api.archetype.Archetype; import org.netbeans.validation.api.ui.ValidationGroup; @@ -62,7 +61,7 @@ * *@author mkleint */ -public class MavenWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator { +public class MavenWizardIterator implements WizardDescriptor.BackgroundInstantiatingIterator { private static final long serialVersionUID = 1L; static final String PROPERTY_CUSTOM_CREATOR = "customCreator"; //NOI18N @@ -95,13 +94,7 @@ } public @Override Set instantiate() throws IOException { - assert false : "Cannot call this method if implements WizardDescriptor.ProgressInstantiatingIterator."; //NOI18N - return null; - } - - @Override - public Set instantiate(ProgressHandle handle) throws IOException { - return ArchetypeWizardUtils.instantiate(handle, wiz); + return ArchetypeWizardUtils.instantiate(wiz); } @Override diff --git a/openide.dialogs/src/org/openide/WizardDescriptor.java b/openide.dialogs/src/org/openide/WizardDescriptor.java --- a/openide.dialogs/src/org/openide/WizardDescriptor.java +++ b/openide.dialogs/src/org/openide/WizardDescriptor.java @@ -1510,9 +1510,10 @@ assert panels != null; - err.log (Level.FINE, "Is AsynchronousInstantiatingIterator? " + (panels instanceof AsynchronousInstantiatingIterator)); - err.log (Level.FINE, "Is ProgressInstantiatingIterator? " + (panels instanceof ProgressInstantiatingIterator)); - if (panels instanceof ProgressInstantiatingIterator) { + if (panels instanceof BackgroundInstantiatingIterator) { + err.fine("is BackgroundInstantiatingIterator"); + } else if (panels instanceof ProgressInstantiatingIterator) { + err.fine("is ProgressInstantiatingIterator"); handle = ProgressHandleFactory.createHandle (PROGRESS_BAR_DISPLAY_NAME); JComponent progressComp = ProgressHandleFactory.createProgressComponent (handle); @@ -1522,6 +1523,7 @@ err.log (Level.FINE, "Show progressPanel controlled by iterator later."); } else if (panels instanceof AsynchronousInstantiatingIterator) { + err.fine("is AsynchronousInstantiatingIterator"); handle = ProgressHandleFactory.createHandle (PROGRESS_BAR_DISPLAY_NAME); JComponent progressComp = ProgressHandleFactory.createProgressComponent (handle); @@ -1879,6 +1881,23 @@ } /** + * Iterator for a wizard that will create new objects after the wizard has been closed. + * Suitable for cases where the instantiation might be quite time consuming, has its own progress/cancellation UI, + * or otherwise would be undesirable to run with the wizard dialog open. + * @param in practice this should be {@link WizardDescriptor} + * @since XXX + */ + public interface BackgroundInstantiatingIterator extends AsynchronousInstantiatingIterator { + + /** + * Called in a separate thread when the Finish button is clicked and the wizard is closed. + * @return a set of objects created (the exact type is at the discretion of the caller) + * @throws IOException when instantiate fails + */ + Set/**/ instantiate() throws IOException; + } + + /** * Iterator for a wizard that wants to notify users while instantiate is running by a progress bar. * The method instantiate is called outside ATW queue. * (This interface can replace @@ -2143,12 +2162,20 @@ if (panels instanceof AsynchronousInstantiatingIterator) { err.log (Level.FINE, "Do ASYNCHRONOUS_JOBS_RP.post(performFinish)."); // NOI18N ASYNCHRONOUS_JOBS_RP.post (performFinish); + if (panels instanceof BackgroundInstantiatingIterator) { + Window parentWindow = SwingUtilities.getWindowAncestor((Component) getMessage()); + if (parentWindow != null) { + parentWindow.setVisible(false); + } else { + err.log(Level.WARNING, "could not find parent window of {0}", getMessage()); + } + } } else { err.log (Level.FINE, "Run performFinish."); // NOI18N performFinish.run (); } - err.log (Level.FINE, "onValidPerformer on finish button exit."); // NOI18N + err.log(Level.FINE, "onValidPerformer on finish button exit on {0}", panels); } }; diff --git a/openide.loaders/src/org/openide/actions/NewTemplateAction.java b/openide.loaders/src/org/openide/actions/NewTemplateAction.java --- a/openide.loaders/src/org/openide/actions/NewTemplateAction.java +++ b/openide.loaders/src/org/openide/actions/NewTemplateAction.java @@ -163,7 +163,7 @@ } protected boolean asynchronous() { - return false; + return true; } /* Enables itself only when activates node is DataFolder. diff --git a/openide.loaders/src/org/openide/loaders/TemplateWizard.java b/openide.loaders/src/org/openide/loaders/TemplateWizard.java --- a/openide.loaders/src/org/openide/loaders/TemplateWizard.java +++ b/openide.loaders/src/org/openide/loaders/TemplateWizard.java @@ -52,6 +52,8 @@ import java.net.*; import java.text.MessageFormat; import java.util.*; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; @@ -118,7 +120,7 @@ /** Component which we are listening on for changes of steps */ private Component lastComp; - private Set newObjects = null; + private BlockingQueue,IOException>> newObjects = null; private ProgressHandle progressHandle; @@ -160,7 +162,7 @@ protected void initialize () { if (iterator != null) { iterator.initialize(this); - newObjects = null; + newObjects = new ArrayBlockingQueue,IOException>>(1); } super.initialize (); } @@ -189,6 +191,10 @@ TemplateWizardIteratorWrapper newIterImplWrapper = new TemplateWizardIteratorWrapper.ProgressInstantiatingIterator (this.iterator.getOriginalIterImpl ()); this.iterator = newIterImplWrapper; this.setPanelsAndSettings(newIterImplWrapper, this); + } else if (newIt instanceof WizardDescriptor.BackgroundInstantiatingIterator) { + TemplateWizardIteratorWrapper newIterImplWrapper = new TemplateWizardIteratorWrapper.BackgroundInstantiatingIterator (this.iterator.getOriginalIterImpl ()); + this.iterator = newIterImplWrapper; + this.setPanelsAndSettings(newIterImplWrapper, this); } else if (newIt instanceof WizardDescriptor.AsynchronousInstantiatingIterator) { TemplateWizardIteratorWrapper newIterImplWrapper = new TemplateWizardIteratorWrapper.AsynchronousInstantiatingIterator (this.iterator.getOriginalIterImpl ()); this.iterator = newIterImplWrapper; @@ -358,6 +364,9 @@ } /** Chooses the template and instantiates it. + *

Beware that this blocks while the wizard is running; + * and if a {@link org.openide.WizardDescriptor.BackgroundInstantiatingIterator} might be selected, + * should not be called from the AWT event queue. * @return set of instantiated data objects (DataObject) * or null if user canceled the dialog * @exception IOException I/O error @@ -368,7 +377,7 @@ } /** Chooses the template and instantiates it. - * + * See {@link #instantiate()} regarding threading behavior. * @param template predefined template that should be instantiated * @return set of instantiated data objects (DataObject) * or null if user canceled the dialog @@ -380,7 +389,7 @@ } /** Chooses the template and instantiates it. - * + * See {@link #instantiate()} regarding threading behavior. * @param template predefined template that should be instantiated * @param targetFolder the target folder * @@ -401,7 +410,7 @@ Set instantiateNewObjects (ProgressHandle handle) throws IOException { progressHandle = handle; - try { + Union2,IOException> val; // #17341. The problem is handling ESC -> value is not // set to CANCEL_OPTION for such cases. Object option = getValue(); @@ -410,27 +419,27 @@ // show wait cursor when handling instantiate showWaitCursor (); - - newObjects = handleInstantiate (); - if (lastComp != null) { - lastComp.removePropertyChangeListener(propL()); - lastComp = null; + try { + val = Union2.createFirst(handleInstantiate()); + } catch (IOException x) { + val = Union2.createSecond(x); + } finally { + showNormalCursor(); } } else { - if (lastComp != null) { - lastComp.removePropertyChangeListener(propL()); - lastComp = null; - } - newObjects = null; + val = Union2.createFirst(null); } - - } finally { + if (lastComp != null) { + lastComp.removePropertyChangeListener(propL()); + lastComp = null; + } - // set normal cursor back - showNormalCursor (); + newObjects.add(val); + if (val.hasFirst()) { + return val.first(); + } else { + throw val.second(); } - - return newObjects; } /** Chooses the template and instantiates it. @@ -501,10 +510,19 @@ } catch (IllegalStateException ise) { thrownMessage = ise; } - // here can return newObjects because instantiateNewObjects() was called // from WizardDescriptor before close dialog (on Finish) - return newObjects; + Union2,IOException> val; + try { + val = newObjects.take(); + } catch (InterruptedException x) { + throw new IOException(x); + } + if (val.hasFirst()) { + return val.first(); + } else { + throw val.second(); + } } private void showWaitCursor () { diff --git a/openide.loaders/src/org/openide/loaders/TemplateWizardIteratorWrapper.java b/openide.loaders/src/org/openide/loaders/TemplateWizardIteratorWrapper.java --- a/openide.loaders/src/org/openide/loaders/TemplateWizardIteratorWrapper.java +++ b/openide.loaders/src/org/openide/loaders/TemplateWizardIteratorWrapper.java @@ -179,7 +179,13 @@ super (it); } } - + + static class BackgroundInstantiatingIterator extends InstantiatingIterator implements WizardDescriptor.BackgroundInstantiatingIterator { + public BackgroundInstantiatingIterator (TemplateWizardIterImpl it) { + super (it); + } + } + static class ProgressInstantiatingIterator extends InstantiatingIterator implements WizardDescriptor.ProgressInstantiatingIterator { private TemplateWizardIterImpl itImpl; public ProgressInstantiatingIterator (TemplateWizardIterImpl it) { diff --git a/projectui/src/org/netbeans/modules/project/ui/actions/NewFile.java b/projectui/src/org/netbeans/modules/project/ui/actions/NewFile.java --- a/projectui/src/org/netbeans/modules/project/ui/actions/NewFile.java +++ b/projectui/src/org/netbeans/modules/project/ui/actions/NewFile.java @@ -137,7 +137,7 @@ doPerform( context, null, true ); } - private void doPerform( Lookup context, DataObject template, boolean inProject ) { + private void doPerform( Lookup context, final DataObject template, boolean inProject ) { if ( context == null ) { context = getLookup(); @@ -154,13 +154,15 @@ return; } - NewFileWizard wd = new NewFileWizard( preselectedProject( context ) /* , null */ ); + final NewFileWizard wd = new NewFileWizard( preselectedProject( context ) /* , null */ ); DataFolder preselectedFolder = preselectedFolder( context ); if ( preselectedFolder != null ) { wd.setTargetFolder( preselectedFolder ); } + RP.post(new Runnable() { + @Override public void run() { try { Set resultSet = template == null ? wd.instantiate () : wd.instantiate( template ); @@ -199,7 +201,8 @@ //Project project = Templates.getProject( wd ); FileObject foTemplate = Templates.getTemplate( wd ); OpenProjectList.getDefault().updateTemplatesLRU( foTemplate ); - + } + }); } // Context Aware action implementation ------------------------------------- diff --git a/projectui/src/org/netbeans/modules/project/ui/actions/NewProject.java b/projectui/src/org/netbeans/modules/project/ui/actions/NewProject.java --- a/projectui/src/org/netbeans/modules/project/ui/actions/NewProject.java +++ b/projectui/src/org/netbeans/modules/project/ui/actions/NewProject.java @@ -131,13 +131,13 @@ FileObject fo = FileUtil.getConfigFile( "Templates/Project" ); //NOI18N final NewProjectWizard wizard = prepareWizardDescriptor(fo); - - SwingUtilities.invokeLater( new Runnable() { - - public void run() { - try { - - Set newObjects = wizard.instantiate(); + final Set newObjects; + try { + newObjects = wizard.instantiate(); + } catch (IOException e) { + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); + return; + } // #75960 - test if any folder was created during the wizard and if yes and it's empty delete it Preferences prefs = NbPreferences.forModule(OpenProjectListSettings.class); String nbPrjDirPath = prefs.get(OpenProjectListSettings.PROP_CREATED_PROJECTS_FOLDER, null); @@ -148,9 +148,13 @@ prjDir.delete(); } } - + //#69618: the non-project cache may contain a project folder listed in newObjects: ProjectManager.getDefault().clearNonProjectCache(); + + SwingUtilities.invokeLater( new Runnable() { + + public void run() { ProjectUtilities.WaitCursor.show(); if ( newObjects != null && !newObjects.isEmpty() ) { @@ -225,9 +229,6 @@ } ProjectUtilities.WaitCursor.hide(); - } catch ( IOException e ) { - ErrorManager.getDefault().notify( ErrorManager.INFORMATIONAL, e ); - } } } );