/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.nbstudio.core.mac; import com.intersys.objects.Database; import java.awt.Component; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.NoSuchElementException; import java.util.Set; import javax.swing.JComponent; import javax.swing.event.ChangeListener; import org.nbstudio.cachefilesystem.CacheFileObject; import org.nbstudio.cachefilesystem.CacheFileSystem; import org.nbstudio.project.CacheProject; import org.netbeans.api.templates.TemplateRegistration; import org.netbeans.spi.project.ui.templates.support.Templates; import org.openide.WizardDescriptor; import org.openide.filesystems.FileStateInvalidException; import org.openide.loaders.DataObject; import org.openide.loaders.DataObjectNotFoundException; @TemplateRegistration(folder = "Cache", displayName = "MAC Routine", iconBase = "org/nbstudio/core/mac/mac.gif", scriptEngine = "freemarker") public final class newfileWizard implements WizardDescriptor.InstantiatingIterator<WizardDescriptor> { private int index; private WizardDescriptor wizard; private List<WizardDescriptor.Panel<WizardDescriptor>> panels; private List<WizardDescriptor.Panel<WizardDescriptor>> getPanels() { if (panels == null) { panels = new ArrayList<>(); panels.add(new newfileWizardPanel1()); String[] steps = createSteps(); for (int i = 0; i < panels.size(); i++) { Component c = panels.get(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 JComponent) { // assume Swing components JComponent jc = (JComponent) c; jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, i); jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps); jc.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, true); jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED, true); jc.putClientProperty(WizardDescriptor.PROP_CONTENT_NUMBERED, true); } } } return panels; } private String[] createSteps() { String[] beforeSteps = (String[]) wizard.getProperty("WizardPanel_contentData"); assert beforeSteps != null : "This wizard may only be used embedded in the template wizard"; String[] res = new String[(beforeSteps.length - 1) + panels.size()]; for (int i = 0; i < res.length; i++) { if (i < (beforeSteps.length - 1)) { res[i] = beforeSteps[i]; } else { res[i] = panels.get(i - beforeSteps.length + 1).getComponent().getName(); } } return res; } @Override public Set instantiate() throws IOException { wizard.getProperties(); CacheProject project = (CacheProject) Templates.getProject(wizard); try { String rtnName = (String) wizard.getProperty("routineName"); if (!rtnName.isEmpty()) { rtnName +=".mac"; CacheFileSystem fs = project.getConnection().getFileSystem(); CacheFileObject fo = new CacheFileObject(fs, (CacheFileObject) fs.getRoot(), rtnName); Database db = fs.getConnection().getAssociatedConnection(); DataObject rdo = DataObject.find(fo); System.out.println("instantiate: " + fo + " - " + rdo); return Collections.singleton(fo); } } catch (DataObjectNotFoundException ex) { ex.printStackTrace(); } return Collections.emptySet(); } @Override public void initialize(WizardDescriptor wizard) { this.wizard = wizard; } @Override public void uninitialize(WizardDescriptor wizard) { panels = null; } @Override public WizardDescriptor.Panel<WizardDescriptor> current() { return getPanels().get(index); } @Override public String name() { return "New MAC Routine"; } @Override public boolean hasNext() { return index < getPanels().size() - 1; } @Override public boolean hasPrevious() { return index > 0; } @Override public void nextPanel() { if (!hasNext()) { throw new NoSuchElementException(); } index++; } @Override public void previousPanel() { if (!hasPrevious()) { throw new NoSuchElementException(); } index--; } // If nothing unusual changes in the middle of the wizard, simply: @Override public void addChangeListener(ChangeListener l) { } @Override public void removeChangeListener(ChangeListener l) { } }