KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > derby > CreateDatabaseAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.modules.derby;
22
23 import java.awt.Dialog JavaDoc;
24 import java.io.File JavaDoc;
25 import org.netbeans.modules.derby.ui.CreateDatabasePanel;
26 import org.netbeans.modules.derby.ui.DerbySystemHomePanel;
27 import org.openide.DialogDescriptor;
28 import org.openide.DialogDisplayer;
29 import org.openide.ErrorManager;
30 import org.openide.util.HelpCtx;
31 import org.openide.util.NbBundle;
32 import org.openide.util.actions.CallableSystemAction;
33
34 /**
35  *
36  * @author Petr Jiricka
37  */

38 public class CreateDatabaseAction extends CallableSystemAction {
39
40     /** Generated sreial version UID. */
41     //static final long serialVersionUID =3322896507302889271L;
42

43     public CreateDatabaseAction() {
44         putValue("noIconInMenu", Boolean.TRUE);
45     }
46     
47     public void performAction() {
48         if (!Util.hasInstallLocation()) {
49             Util.showInformation(NbBundle.getMessage(RegisterDerby.class, "MSG_DerbyLocationIncorrect"));
50             return;
51         }
52         
53         String JavaDoc derbySystemHome = DerbyOptions.getDefault().getSystemHome();
54         if (derbySystemHome.length() <= 0) {
55             derbySystemHome = DerbySystemHomePanel.findDerbySystemHome();
56             if (derbySystemHome.length() > 0) {
57                 DerbyOptions.getDefault().setSystemHome(derbySystemHome);
58             }
59         }
60         if (derbySystemHome.length() <= 0) {
61             return;
62         }
63         
64         CreateDatabasePanel panel = new CreateDatabasePanel(derbySystemHome);
65         DialogDescriptor desc = new DialogDescriptor(panel, NbBundle.getMessage(CreateDatabaseAction.class, "LBL_CreateDatabaseTitle"), true, null);
66         panel.setDialogDescriptor(desc);
67         Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog(desc);
68         String JavaDoc acsd = NbBundle.getMessage(CreateDatabaseAction.class, "ACSD_CreateDatabaseAction");
69         dialog.getAccessibleContext().setAccessibleDescription(acsd);
70         dialog.setVisible(true);
71         dialog.dispose();
72         
73         if (!DialogDescriptor.OK_OPTION.equals(desc.getValue())) {
74             return;
75         }
76         
77         String JavaDoc databaseName = panel.getDatabaseName();
78         String JavaDoc user = panel.getUser();
79         String JavaDoc password = panel.getPassword();
80         
81         // if only the username or password is null, ensure they are both null
82
if (user == null || password == null) {
83             user = null;
84             password = null;
85         }
86         
87         try {
88             makeDatabase(databaseName, user, password);
89         } catch (Exception JavaDoc e) {
90             ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
91         }
92     }
93     
94     void makeDatabase(String JavaDoc dbname, String JavaDoc user, String JavaDoc password) throws Exception JavaDoc {
95         RegisterDerby.getDefault().postCreateNewDatabase(dbname, user, password);
96     }
97
98     protected boolean asynchronous() {
99         return false;
100     }
101
102     /** Gets localized name of action. Overrides superclass method. */
103     public String JavaDoc getName() {
104         return NbBundle.getBundle(CreateDatabaseAction.class).getString("LBL_CreateDBAction");
105     }
106
107     /** Gets the action's help context. Implemenst superclass abstract method. */
108     public HelpCtx getHelpCtx() {
109         return new HelpCtx(CreateDatabaseAction.class);
110     }
111
112 }
113
Popular Tags