1 19 20 package org.netbeans.modules.derby; 21 22 import java.io.IOException ; 23 import java.util.logging.Level ; 24 import java.util.logging.Logger ; 25 import javax.swing.SwingUtilities ; 26 import org.netbeans.api.db.explorer.DatabaseException; 27 import org.netbeans.api.java.platform.JavaPlatform; 28 import org.netbeans.api.java.platform.JavaPlatformManager; 29 import org.netbeans.api.progress.ProgressHandle; 30 import org.netbeans.api.progress.ProgressHandleFactory; 31 import org.netbeans.modules.derby.api.DerbyDatabases; 32 import org.openide.filesystems.FileObject; 33 import org.openide.filesystems.FileUtil; 34 import org.openide.modules.ModuleInstall; 35 import org.openide.modules.SpecificationVersion; 36 import org.openide.util.NbBundle; 37 import org.openide.util.RequestProcessor; 38 import org.openide.windows.WindowManager; 39 40 43 public class Installer extends ModuleInstall { 44 45 public void restored() { 46 WindowManager.getDefault().invokeWhenUIReady(new RegisterJDKDerby()); 47 } 48 49 private static final class RegisterJDKDerby implements Runnable { 50 51 public void run() { 52 if (SwingUtilities.isEventDispatchThread()) { 53 RequestProcessor.getDefault().post(this); 54 return; 55 } 56 57 JavaPlatform javaPlatform = JavaPlatformManager.getDefault().getDefaultPlatform(); 58 SpecificationVersion version = javaPlatform.getSpecification().getVersion(); 59 if (new SpecificationVersion("1.6").compareTo(version) > 0) { return; 61 } 62 63 ProgressHandle handle = ProgressHandleFactory.createSystemHandle(NbBundle.getMessage(Installer.class, "MSG_RegisterJavaDB")); 64 handle.start(); 65 try { 66 if (registerJDKDerby(javaPlatform)) { 67 registerSampleDatabase(); 68 } 69 } finally { 70 handle.finish(); 71 } 72 } 73 74 private boolean registerJDKDerby(JavaPlatform javaPlatform) { 75 if (DerbyOptions.getDefault().getLocation().length() > 0) { 76 return false; 77 } 78 for (Object dir : javaPlatform.getInstallFolders()) { 79 FileObject derbyDir = ((FileObject)dir).getFileObject("db"); if (derbyDir != null) { 81 DerbyOptions.getDefault().setLocation(FileUtil.toFile(derbyDir).getAbsolutePath()); 82 return true; 83 } 84 } 85 return false; 86 } 87 88 private void registerSampleDatabase() { 89 try { 90 DerbyDatabases.createSampleDatabase(); 91 } catch (DatabaseException e) { 92 Logger.getLogger(Installer.class.getName()).log(Level.WARNING, null, e); 93 } catch (IOException e) { 94 Logger.getLogger(Installer.class.getName()).log(Level.WARNING, null, e); 95 } 96 } 97 } 98 } 99 | Popular Tags |