1 23 package org.enhydra.kelp.jbuilder.wizard; 24 25 import org.enhydra.tool.common.IconSet; 27 import org.enhydra.tool.common.ProgressMeter; 28 29 import com.borland.jbuilder.node.HTMLFileNode; 31 import com.borland.jbuilder.node.JBProject; 32 import com.borland.primetime.ide.Browser; 33 import com.borland.primetime.node.Node; 34 import com.borland.primetime.wizard.BasicWizard; 35 import com.borland.primetime.wizard.BasicWizardPage; 36 import com.borland.primetime.wizard.Wizard; 37 import com.borland.primetime.wizard.WizardAction; 38 import com.borland.primetime.wizard.WizardHost; 39 import com.borland.primetime.wizard.WizardManager; 40 import com.borland.primetime.wizard.WizardPage; 41 import com.borland.primetime.util.VetoException; 42 43 import org.enhydra.kelp.KelpInfo; 45 import org.enhydra.kelp.common.ResUtil; 46 import org.enhydra.kelp.common.ValidationException; 47 import org.enhydra.kelp.common.importer.ImportPaths; 48 import org.enhydra.kelp.common.importer.ImportTool; 49 import org.enhydra.kelp.common.node.OtterProject; 50 import org.enhydra.kelp.common.node.OtterNodeFactory; 51 import org.enhydra.kelp.common.node.OtterFolderNode; 52 import org.enhydra.kelp.common.swing.KelpIconSet; 53 import org.enhydra.kelp.common.importer.ImportMapPanel; 54 import org.enhydra.kelp.common.importer.RootPanel; 55 import org.enhydra.kelp.common.importer.PathPanel; 56 import org.enhydra.kelp.common.importer.ImporterPanel; 57 import org.enhydra.kelp.jbuilder.wizard.AbstractBasicWizard; 58 import org.enhydra.kelp.jbuilder.node.PrimeProject; 59 import org.enhydra.kelp.jbuilder.node.PrimeProject; 60 61 import java.awt.BorderLayout ; 63 import java.io.File ; 64 import javax.swing.JPanel ; 65 import javax.swing.JOptionPane ; 66 import javax.swing.SwingUtilities ; 67 import java.util.ResourceBundle ; 68 69 74 public class ImportWizard extends AbstractBasicWizard { 75 76 private final String HELP_LINK = KelpInfo.getAddinHelpURL(); 79 private static String WIZARD_NAME = res.getString("Enhydra_Import"); 81 private ImportPaths paths = null; 82 private OtterProject project = null; 83 public static WizardAction action = new LocalWizardAction(); 84 85 88 static class LocalWizardAction extends WizardAction { 89 static ResourceBundle res = 90 ResourceBundle.getBundle("org.enhydra.kelp.jbuilder.Res"); 91 92 public LocalWizardAction() { 93 super(ResUtil.format(res.getString("_0_dots"), ImportWizard.WIZARD_NAME), 94 'p', res.getString("importNotEmpty1"), 95 KelpIconSet.getSmallIcon(), KelpIconSet.getLargeIcon(), 96 false); 97 } 98 99 protected Wizard createWizard() { 100 ImportWizard wizard = new ImportWizard(); 101 102 return wizard; 103 } 104 105 public void update(Object source) { 106 setEnabled(AbstractBasicWizard.enableMenu); 107 } 108 109 } 110 ; 111 112 118 public WizardPage finish(WizardPage currentPage, 119 WizardHost host) throws VetoException { 120 ImportTool tool = null; 121 ProgressMeter progress = null; 122 123 tool = new ImportTool(); 124 if (currentPage instanceof LocalWizardPage) { 125 LocalWizardPage localPage = (LocalWizardPage) currentPage; 126 127 localPage.checkPage(); 128 } 129 progress = new ProgressMeter(); 130 progress.setOwner(Browser.getActiveBrowser()); 131 progress.setModal(true); 132 progress.setTitle(getWizardTitle()); 133 tool.setPaths(paths); 134 tool.addProgressListener(progress); 135 progress.startDialogThread(); 136 tool.importFilesFromRoot(); 137 return super.finish(currentPage, host); 138 } 139 140 protected void finish() throws VetoException { 141 super.finish(); 142 } 143 144 151 public static void initOpenTool(byte majorVersion, byte minorVersion) { 152 WizardManager.registerWizardAction(action); 153 } 154 155 162 public String getHelpTopic() { 163 return HELP_LINK; 164 } 165 166 171 public String getDisplayName() { 172 return ImportWizard.WIZARD_NAME; 173 } 174 175 public static String getName() { 176 return ImportWizard.WIZARD_NAME; 177 } 178 179 public WizardPage invokeWizard(WizardHost host) { 180 WizardPage page = null; 181 boolean invokeIt = false; 182 183 try { 184 KelpInfo.verifyIDEClassPath(); 185 invokeIt = true; 186 } catch (Exception e) { 187 JOptionPane.showMessageDialog(host.getDialogParent(), 188 e.getMessage(), 189 KelpInfo.getMessageBoxTitle(), 190 JOptionPane.ERROR_MESSAGE); 191 } 192 193 if (invokeIt) { 194 195 setNativeProject((JBProject) host.getBrowser().getActiveProject()); 196 if (!isProjectEmpty(getNativeProject())) { 197 StringBuffer buf = new StringBuffer (); 198 int choice = -1; 199 200 buf.append(res.getString("importNotEmpty2")); 201 buf.append(res.getString("importNotEmpty3")); 202 buf.append(res.getString("importNotEmpty4")); 203 buf.append(res.getString("importNotEmpty5")); 204 choice = 205 JOptionPane.showConfirmDialog(host.getDialogParent(), 206 buf.toString(), 207 ResUtil.format(res.getString("_0_Wizard_Error"), getDisplayName()), 208 JOptionPane.WARNING_MESSAGE); 209 if (choice == JOptionPane.CANCEL_OPTION) { 210 invokeIt = false; 211 } 212 } 213 if (invokeIt) { 214 project = new PrimeProject(getNativeProject()); 215 paths = new ImportPaths(); 216 paths.setProject(project); 217 String rootPath = project.getRootPath(); 218 219 if (rootPath != null && rootPath.trim().length() > 0) { 220 try { 221 paths.setRootPath(rootPath); 222 } catch (ValidationException e) { 223 e.printStackTrace(); 224 } 225 } 226 LocalWizardPage rootPage = new LocalWizardPage(); 227 LocalWizardPage pathPage = new LocalWizardPage(); 228 LocalWizardPage mapPage = new LocalWizardPage(); 229 230 rootPage.setPanel(new RootPanel()); 231 rootPage.setPaths(paths); 232 pathPage.setPanel(new PathPanel()); 233 pathPage.setPaths(paths); 234 mapPage.setPanel(new ImportMapPanel()); 235 mapPage.setPaths(paths); 236 addWizardPage(rootPage); 237 addWizardPage(pathPage); 238 addWizardPage(mapPage); 239 page = super.invokeWizard(host); 240 } 241 } 242 return page; 243 } 244 245 253 private boolean isProjectEmpty(JBProject nativeProject) { 254 Node[] nodes = null; 255 boolean empty = true; 256 257 if (nativeProject != null) { 258 nodes = nativeProject.getChildren(); 259 } 260 if (nodes != null) { 261 if (nodes.length > 1) { 262 empty = false; 263 } else if (nodes.length == 1) { 264 if (!(nodes[0] instanceof HTMLFileNode)) { 265 empty = false; 266 } 267 } 268 } 269 return empty; 270 } 271 272 278 private class LocalWizardPage extends BasicWizardPage { 279 private ImporterPanel panel; 280 281 285 public LocalWizardPage() { 286 BorderLayout layout = new BorderLayout (); 287 288 layout.setHgap(5); 289 layout.setVgap(5); 290 this.setLayout(layout); 291 if (KelpInfo.isToolBoxVersionInSynch()) { 292 this.setLargeIcon(IconSet.getOtterWizard()); 293 } 294 } 295 296 301 public void activated(WizardHost host) { 302 panel.activated(); 303 } 304 305 310 public void checkPage() throws VetoException { 311 try { 312 panel.checkPage(); 313 } catch (ValidationException e) { 314 JOptionPane.showMessageDialog(getWizardHost().getDialogParent(), 315 e.getMessage(), 316 getDisplayName(), 317 JOptionPane.ERROR_MESSAGE); 318 throw new VetoException(e.toString()); 319 } 320 } 321 322 327 public void setPaths(ImportPaths paths) { 328 panel.setPaths(paths); 329 } 330 331 336 public ImportPaths getPaths() { 337 return panel.getPaths(); 338 } 339 340 protected void setPanel(ImporterPanel panel) { 341 this.panel = panel; 342 this.setPageTitle(panel.getPageTitle()); 343 this.setInstructions(panel.getInstructions()); 344 this.add(panel, BorderLayout.CENTER); 345 } 346 347 protected JPanel getPanel() { 348 return panel; 349 } 350 351 } 352 } 353 | Popular Tags |