001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.dbschema.jdbcimpl;
043:
044: import java.util.ResourceBundle;
045:
046: import org.openide.loaders.*;
047: import org.openide.nodes.Node;
048: import org.openide.util.actions.*;
049: import org.openide.util.HelpCtx;
050: import org.openide.util.NbBundle;
051: import org.openide.windows.WindowManager;
052:
053: public class CaptureSchemaAction extends CallableSystemAction {
054:
055: private ResourceBundle bundle = NbBundle
056: .getBundle("org.netbeans.modules.dbschema.jdbcimpl.resources.Bundle"); //NOI18N
057:
058: /** Create. new ObjectViewAction. */
059: public CaptureSchemaAction() {
060: }
061:
062: /** Name of the action. */
063: public String getName() {
064: return bundle.getString("ActionName"); //NOI18N
065: }
066:
067: /** No help yet. */
068: public HelpCtx getHelpCtx() {
069: return new HelpCtx("dbschema_ctxhelp_wizard"); //NOI18N
070: }
071:
072: protected String iconResource() {
073: return "org/netbeans/modules/dbschema/jdbcimpl/DBschemaDataIcon.gif"; //NOI18N
074: }
075:
076: public void performAction() {
077: try {
078: TemplateWizard wizard = new TemplateWizard();
079:
080: DataObject templateDirs[] = wizard.getTemplatesFolder()
081: .getChildren();
082: for (int i = 0; i < templateDirs.length; i++)
083: if (templateDirs[i].getName().equals("Databases")) { //NOI18N
084: DataObject templates[] = ((DataFolder) templateDirs[i])
085: .getChildren();
086: for (int j = 0; j < templates.length; j++)
087: if (templates[j].getName().equals(
088: "Database Schema")) { //NOI18N
089: Node n[] = WindowManager.getDefault()
090: .getRegistry().getActivatedNodes();
091: int nId = -1;
092: for (int k = 0; k < n.length; k++)
093: if (n[k].getCookie(DataFolder.class) instanceof DataFolder) {
094: nId = k;
095: break;
096: }
097:
098: wizard.putProperty(
099: "WizardPanel_autoWizardStyle",
100: Boolean.TRUE); //NOI18N
101: wizard.putProperty(
102: "WizardPanel_contentDisplayed",
103: Boolean.TRUE); //NOI18N
104: wizard.putProperty(
105: "WizardPanel_contentNumbered",
106: Boolean.TRUE); //NOI18N
107: String[] prop = (String[]) wizard
108: .getProperty("WizardPanel_contentData"); // NOI18N
109: String[] stepsNames = new String[] {
110: wizard
111: .targetChooser()
112: .getClass()
113: .toString()
114: .trim()
115: .equalsIgnoreCase(
116: "class org.openide.loaders.TemplateWizard2") ? bundle
117: .getString("TargetLocation")
118: : prop[0],
119: bundle.getString("TargetLocation"),
120: bundle
121: .getString("ConnectionChooser"),
122: bundle.getString("TablesChooser") };
123: wizard.putProperty(
124: "WizardPanel_contentData",
125: stepsNames); //NOI18N
126: wizard.setTitle(bundle
127: .getString("WizardTitleName"));
128:
129: if (nId >= 0) {
130: wizard
131: .setTargetFolder((DataFolder) n[nId]
132: .getCookie(DataFolder.class));
133: wizard.instantiate(templates[j]);
134: } else
135: wizard.instantiate(templates[j]);
136:
137: break;
138: }
139: break;
140: }
141: } catch (Exception exc) {
142: exc.printStackTrace();
143: }
144: }
145: }
|