KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > dbschema > jdbcimpl > CaptureSchemaAction


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 package org.netbeans.modules.dbschema.jdbcimpl;
21
22 import java.util.ResourceBundle JavaDoc;
23
24 import org.openide.loaders.*;
25 import org.openide.nodes.Node;
26 import org.openide.util.actions.*;
27 import org.openide.util.HelpCtx;
28 import org.openide.util.NbBundle;
29 import org.openide.windows.WindowManager;
30
31 public class CaptureSchemaAction extends CallableSystemAction {
32
33     private ResourceBundle JavaDoc bundle = NbBundle.getBundle("org.netbeans.modules.dbschema.jdbcimpl.resources.Bundle"); //NOI18N
34

35     /** Create. new ObjectViewAction. */
36     public CaptureSchemaAction() {
37     }
38
39     /** Name of the action. */
40     public String JavaDoc getName () {
41         return bundle.getString("ActionName"); //NOI18N
42
}
43
44     /** No help yet. */
45     public HelpCtx getHelpCtx () {
46         return new HelpCtx("dbschema_ctxhelp_wizard"); //NOI18N
47
}
48
49     protected String JavaDoc iconResource () {
50         return "org/netbeans/modules/dbschema/jdbcimpl/DBschemaDataIcon.gif"; //NOI18N
51
}
52
53     public void performAction() {
54         try {
55             TemplateWizard wizard = new TemplateWizard();
56             
57             DataObject templateDirs[] = wizard.getTemplatesFolder().getChildren();
58             for (int i = 0; i < templateDirs.length; i++)
59                 if (templateDirs[i].getName().equals("Databases")) { //NOI18N
60
DataObject templates[] = ((DataFolder) templateDirs[i]).getChildren();
61                     for (int j = 0; j < templates.length; j++)
62                         if (templates[j].getName().equals("Database Schema")) { //NOI18N
63
Node n[] = WindowManager.getDefault().getRegistry().getActivatedNodes();
64                             int nId = -1;
65                             for (int k = 0; k < n.length; k++)
66                                 if (n[k].getCookie(DataFolder.class) instanceof DataFolder) {
67                                     nId = k;
68                                     break;
69                                 }
70                             
71                             wizard.putProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); //NOI18N
72
wizard.putProperty("WizardPanel_contentDisplayed", Boolean.TRUE); //NOI18N
73
wizard.putProperty("WizardPanel_contentNumbered", Boolean.TRUE); //NOI18N
74
String JavaDoc[] prop = (String JavaDoc[]) wizard.getProperty("WizardPanel_contentData"); // NOI18N
75
String JavaDoc[] stepsNames = new String JavaDoc[] {
76                                 wizard.targetChooser().getClass().toString().trim().equalsIgnoreCase("class org.openide.loaders.TemplateWizard2") ? bundle.getString("TargetLocation") :
77                                     prop[0],
78                                     bundle.getString("TargetLocation"),
79                                     bundle.getString("ConnectionChooser"),
80                                     bundle.getString("TablesChooser")
81                             };
82                             wizard.putProperty("WizardPanel_contentData", stepsNames); //NOI18N
83
wizard.setTitle(bundle.getString("WizardTitleName"));
84                             
85                             if(nId >= 0) {
86                                 wizard.setTargetFolder((DataFolder) n[nId].getCookie(DataFolder.class));
87                                 wizard.instantiate(templates[j]);
88                             } else
89                                 wizard.instantiate(templates[j]);
90                             
91                             break;
92                         }
93                     break;
94                 }
95         } catch(Exception JavaDoc exc) {
96             exc.printStackTrace();
97         }
98     }
99 }
100
Popular Tags