1 19 20 package org.netbeans.modules.dbschema.jdbcimpl.wizard; 21 22 import java.io.IOException ; 23 import java.util.*; 24 25 import javax.swing.event.ChangeListener ; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.spi.project.ui.templates.support.Templates; 28 29 import org.openide.loaders.TemplateWizard; 30 import org.openide.NotifyDescriptor; 31 import org.openide.util.NbBundle; 32 import org.openide.WizardDescriptor; 33 import org.openide.filesystems.FileObject; 34 import org.openide.loaders.DataFolder; 35 36 39 public class DBSchemaWizardIterator implements TemplateWizard.Iterator { 40 41 static final long serialVersionUID = 9197272899287477324L; 42 43 ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.dbschema.jdbcimpl.resources.Bundle"); 45 private WizardDescriptor.Panel panels[]; 46 private static String panelNames[]; 47 private static final int PANEL_COUNT = 3; 48 private int panelIndex; 49 private static DBSchemaWizardIterator instance; 50 private TemplateWizard wizardInstance; 51 private boolean guiInitialized; 52 private DBSchemaWizardData myData; 53 54 public DBSchemaWizardIterator() { 55 super(); 56 panelIndex = 0; 57 } 58 59 public static synchronized DBSchemaWizardIterator singleton() { 60 if(instance == null) 61 instance = new DBSchemaWizardIterator(); 62 63 return instance; 64 } 65 66 public Set instantiate(TemplateWizard wiz) throws IOException { 67 myData.setName(wiz.getTargetName()); 69 myData.setDestinationPackage(wiz.getTargetFolder()); 70 71 CaptureSchema capture = new CaptureSchema(myData); 72 capture.start(); 73 74 return null; } 76 77 public org.openide.WizardDescriptor.Panel current() { 78 return panels[panelIndex]; 79 } 80 81 public String name() { 82 return panelNames[panelIndex]; 83 } 84 85 public boolean hasNext() { 86 return panelIndex < PANEL_COUNT - 1; 87 } 88 89 public boolean hasPrevious() { 90 return panelIndex > 0; 91 } 92 93 public void nextPanel() { 94 if (panelIndex == 1) { ((DBSchemaConnectionPanel) panels[1].getComponent()).initData(); 96 if (! (((DBSchemaTablesPanel) panels[2].getComponent()).init())) 97 return; 98 } 99 100 panelIndex++; 101 } 102 103 public void previousPanel() { 104 panelIndex--; 105 } 106 107 public void addChangeListener(ChangeListener l) { 108 } 109 110 public void removeChangeListener(ChangeListener l) { 111 } 112 113 public void initialize(TemplateWizard wizard) { 114 wizardInstance = wizard; 115 setDefaultTarget(); 116 String [] prop = (String []) wizard.getProperty("WizardPanel_contentData"); String [] stepsNames; 118 if (wizard.targetChooser().getClass().toString().trim().equalsIgnoreCase("class org.openide.loaders.TemplateWizard2")) { 119 stepsNames = new String [] { 120 bundle.getString("TargetLocation") , 121 bundle.getString("TargetLocation"), 122 bundle.getString("ConnectionChooser"), 123 bundle.getString("TablesChooser") 124 }; 125 } else if (null != prop) { 126 stepsNames = new String [] { 127 prop[0], 128 bundle.getString("TargetLocation"), 129 bundle.getString("ConnectionChooser"), 130 bundle.getString("TablesChooser") 131 }; 132 } else { 133 stepsNames = new String [] { 134 bundle.getString("TargetLocation"), 135 bundle.getString("ConnectionChooser"), 136 bundle.getString("TablesChooser") 137 }; 138 } 139 wizardInstance.putProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); wizardInstance.putProperty("WizardPanel_contentDisplayed", Boolean.TRUE); wizardInstance.putProperty("WizardPanel_contentNumbered", Boolean.TRUE); wizardInstance.putProperty("WizardPanel_contentData", stepsNames); 144 if(!guiInitialized) { 145 initialize(); 146 147 myData = new DBSchemaWizardData(); 148 panels = new WizardDescriptor.Panel[PANEL_COUNT]; 149 150 DBSchemaTargetPanel targetPanel = new DBSchemaTargetPanel(); 151 targetPanel.setPanel(wizard.targetChooser()); 152 153 java.awt.Component panel = targetPanel.getComponent(); 154 if (panel instanceof javax.swing.JComponent ) { 155 ((javax.swing.JComponent ) panel).putClientProperty("WizardPanel_contentData", stepsNames); ((javax.swing.JComponent ) panel).putClientProperty("WizardPanel_contentSelectedIndex", new Integer (0)); } 158 159 panels[0] = targetPanel.getPanel(); 160 panels[1] = new DBSchemaConnectionWizardPanel(myData); 161 panels[2] = new DBSchemaTablesWizardPanel(myData); 162 } 163 164 panelIndex = 0; 165 } 166 167 public void uninitialize(TemplateWizard wiz) { 168 if (wiz.getValue() == NotifyDescriptor.CANCEL_OPTION) 169 ((DBSchemaTablesPanel) panels[2].getComponent()).uninit(); 170 171 panels = null; 172 myData = null; 173 guiInitialized = false; 174 } 175 176 protected void initialize() { 177 if(panelNames == null) { 178 panelNames = new String [PANEL_COUNT]; 179 panelNames[0] = ""; panelNames[1] = ""; panelNames[2] = ""; } 183 } 184 185 189 private void setDefaultTarget() { 190 FileObject targetFO; 191 try { 192 DataFolder target = wizardInstance.getTargetFolder(); 193 targetFO = target.getPrimaryFile(); 194 } catch (IOException e) { 195 targetFO = null; 196 } 197 198 Project targetProject = Templates.getProject(wizardInstance); 199 if (targetProject != null) { 200 FileObject projectDir = targetProject.getProjectDirectory(); 201 if (targetFO == null || targetFO.equals(projectDir)) { 202 FileObject newTargetFO = projectDir.getFileObject("src/conf"); if (newTargetFO == null || !newTargetFO.isValid()) { 204 newTargetFO = projectDir.getFileObject("src/META-INF"); if (newTargetFO == null || !newTargetFO.isValid()) { 206 newTargetFO = projectDir.getFileObject("src"); if (newTargetFO == null || !newTargetFO.isValid()) { 208 return; 209 } 210 } 211 } 212 213 DataFolder newTarget = DataFolder.findFolder(newTargetFO); 214 wizardInstance.setTargetFolder(newTarget); 215 } 216 } 217 } 218 } 219 | Popular Tags |