/* * * Created on January 24, 2002 */ package com.nuance.tools.voicexml.template; import javax.swing.*; import org.openide.util.NbBundle; import org.openide.loaders.DataFolder; import org.openide.loaders.DataObject; import org.openide.cookies.*; import org.openide.loaders.TemplateWizard; import java.io.File; import java.io.IOException; import org.openide.WizardDescriptor.Panel; import org.openide.filesystems.FileObject; /** A template wizard iterator (sequence of panels). * Used to fill in the second and subsequent panels in the New wizard. * Associate this to a template inside a layer using the * Sequence of Panels extra property. * Create one or more panels from template as needed too. * * @author jsinai */ public class TemplateWizardIterator implements org.openide.loaders.TemplateWizard.Iterator { protected Panel[] createPanels() { return new Panel[] { new VoicexmlWizardPanel(), }; } // And the list of step names: protected String[] createSteps () { return new String[] { null }; } public java.util.Set instantiate(final TemplateWizard wiz) throws IOException { Runnable r = new Runnable () { public void run () { try { String name = (String)wiz.getProperty("name"); FileObject dir = (FileObject)wiz.getProperty("folder"); if (dir == null) { com.nuance.tools.swing.SwingUtils.showErrorMessageDialog( "No V-Builder Project Open", "You must open or create a V-Builder Project first!"); return; } DataFolder targetFolder = DataFolder.findFolder (dir); DataObject template = wiz.getTemplate(); DataObject result; if (name == null) { // Default name. result = template.createFromTemplate(targetFolder); } else { result = template.createFromTemplate(targetFolder, name); } // Do something with the result, e.g. open it: OpenCookie open = (OpenCookie) result.getCookie(OpenCookie.class); if (open != null) { open.open(); } } catch (IOException e) { com.nuance.tools.swing.SwingUtils.showErrorMessageDialog( "Cannot create file", "Error creating " + wiz.getProperty("name") + ".vxml -- please try a different name"); return; } }}; org.openide.util.Task task = new org.openide.util.Task(r); org.openide.util.RequestProcessor.getDefault().post(task); return null; } // --- The rest probably does not need to be touched. --- private transient int index; private transient Panel[] panels; private transient TemplateWizard wiz; private static final long serialVersionUID = 5510302492703140173L; // You can keep a reference to the TemplateWizard which can // provide various kinds of useful information such as // the currently selected target name. // Also the panels will receive wiz as their "settings" object. public void initialize (TemplateWizard wiz) { this.wiz = wiz; index = 0; panels = createPanels (); // Make sure list of steps is accurate. String[] steps = createSteps (); for (int i = 0; i < panels.length; i++) { java.awt.Component c = panels[i].getComponent (); if (steps[i] == null) { // Default step name to component name of panel. // Mainly useful for getting the name of the target // chooser to appear in the list of steps. steps[i] = c.getName (); } if (c instanceof javax.swing.JComponent) { // assume Swing components javax.swing.JComponent jc = (javax.swing.JComponent) c; // Step #. jc.putClientProperty ("WizardPanel_contentSelectedIndex", new Integer (i)); // NOI18N // Step name (actually the whole list for reference). jc.putClientProperty ("WizardPanel_contentData", steps); // NOI18N } } } public void uninitialize (TemplateWizard wiz) { this.wiz = null; panels = null; } // --- WizardDescriptor.Iterator METHODS: --- // Note that this is very similar to WizardDescriptor.Iterator, but with a // few more options for customization. If you e.g. want to make panels appear // or disappear dynamically, go ahead. public String name () { return NbBundle.getMessage(TemplateWizardIterator.class, "TITLE_x_of_y", new Integer (index + 1), new Integer (panels.length)); } public boolean hasNext () { return index < panels.length - 1; } public boolean hasPrevious () { return index > 0; } public void nextPanel () { if (! hasNext ()) throw new java.util.NoSuchElementException (); index++; } public void previousPanel () { if (! hasPrevious ()) throw new java.util.NoSuchElementException (); index--; } public Panel current() { return panels[index]; } // If nothing unusual changes in the middle of the wizard, simply: public final void addChangeListener(javax.swing.event.ChangeListener l) {} public final void removeChangeListener(javax.swing.event.ChangeListener l) {} }