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.db.explorer.dlg;
043:
044: import java.awt.*;
045: import java.awt.event.*;
046: import java.util.*;
047: import javax.swing.*;
048: import javax.swing.border.EmptyBorder;
049: import org.openide.DialogDescriptor;
050: import org.openide.DialogDisplayer;
051: import org.openide.util.NbBundle;
052: import org.openide.NotifyDescriptor;
053: import org.netbeans.lib.ddl.impl.CreateView;
054: import org.netbeans.lib.ddl.impl.Specification;
055: import org.netbeans.lib.ddl.*;
056: import org.netbeans.modules.db.explorer.infos.DatabaseNodeInfo;
057: import org.netbeans.modules.db.explorer.*;
058: import org.openide.awt.Mnemonics;
059:
060: public class AddViewDialog {
061: boolean result = false;
062: Dialog dialog = null;
063: JTextField namefld;
064: JTextArea tarea;
065:
066: public AddViewDialog(final Specification spec,
067: final DatabaseNodeInfo info) {
068: try {
069: ResourceBundle bundle = NbBundle
070: .getBundle("org.netbeans.modules.db.resources.Bundle"); //NOI18N
071: JPanel pane = new JPanel();
072: pane.setBorder(new EmptyBorder(new Insets(5, 5, 5, 5)));
073: GridBagLayout layout = new GridBagLayout();
074: GridBagConstraints con = new GridBagConstraints();
075: pane.setLayout(layout);
076:
077: // Index name
078:
079: JLabel label = new JLabel();
080: Mnemonics.setLocalizedText(label, bundle
081: .getString("AddViewName"));
082: label.getAccessibleContext().setAccessibleDescription(
083: bundle.getString("ACS_AddViewNameA11yDesc"));
084: con.anchor = GridBagConstraints.WEST;
085: con.insets = new java.awt.Insets(2, 2, 2, 2);
086: con.gridx = 0;
087: con.gridy = 0;
088: layout.setConstraints(label, con);
089: pane.add(label);
090:
091: // Index name field
092:
093: con.fill = GridBagConstraints.HORIZONTAL;
094: con.weightx = 1.0;
095: con.gridx = 1;
096: con.gridy = 0;
097: con.insets = new java.awt.Insets(2, 2, 2, 2);
098: namefld = new JTextField(35);
099: namefld.setToolTipText(bundle
100: .getString("ACS_AddViewNameTextFieldA11yDesc"));
101: namefld
102: .getAccessibleContext()
103: .setAccessibleName(
104: bundle
105: .getString("ACS_AddViewNameTextFieldA11yName"));
106: label.setLabelFor(namefld);
107: layout.setConstraints(namefld, con);
108: pane.add(namefld);
109:
110: // Items list title
111:
112: label = new JLabel();
113: Mnemonics.setLocalizedText(label, bundle
114: .getString("AddViewLabel"));
115: label.getAccessibleContext().setAccessibleDescription(
116: bundle.getString("ACS_AddViewLabelA11yDesc"));
117: con.weightx = 0.0;
118: con.anchor = GridBagConstraints.WEST;
119: con.insets = new java.awt.Insets(2, 2, 2, 2);
120: con.gridx = 0;
121: con.gridy = 1;
122: con.gridwidth = 2;
123: layout.setConstraints(label, con);
124: pane.add(label);
125:
126: // Editor list
127:
128: tarea = new JTextArea(5, 50);
129: tarea.setToolTipText(bundle
130: .getString("ACS_AddViewTextAreaA11yDesc"));
131: tarea.getAccessibleContext().setAccessibleName(
132: bundle.getString("ACS_AddViewTextAreaA11yName"));
133: label.setLabelFor(tarea);
134:
135: con.weightx = 1.0;
136: con.weighty = 1.0;
137: con.gridwidth = 2;
138: con.fill = GridBagConstraints.BOTH;
139: con.insets = new java.awt.Insets(0, 0, 0, 0);
140: con.gridx = 0;
141: con.gridy = 2;
142: JScrollPane spane = new JScrollPane(tarea);
143: layout.setConstraints(spane, con);
144: pane.add(spane);
145:
146: ActionListener listener = new ActionListener() {
147: public void actionPerformed(ActionEvent event) {
148:
149: if (event.getSource() == DialogDescriptor.OK_OPTION) {
150:
151: try {
152: boolean wasException = AddViewDDL
153: .addView(
154: spec,
155: (String) info
156: .get(DatabaseNodeInfo.SCHEMA),
157: getViewName(),
158: getViewCode());
159:
160: result = !wasException;
161:
162: if (!wasException) {
163: dialog.setVisible(false);
164: dialog.dispose();
165: }
166: } catch (Exception e) {
167: DialogDisplayer
168: .getDefault()
169: .notify(
170: new NotifyDescriptor.Message(
171: e.getMessage(),
172: NotifyDescriptor.ERROR_MESSAGE));
173: }
174: }
175: }
176: };
177:
178: pane.getAccessibleContext().setAccessibleDescription(
179: bundle.getString("ACS_AddViewDialogA11yDesc")); //NOI18N
180:
181: DialogDescriptor descriptor = new DialogDescriptor(pane,
182: bundle.getString("AddViewTitle"), true, listener); //NOI18N
183: // inbuilt close of the dialog is only after CANCEL button click
184: // after OK button is dialog closed by hand
185: Object[] closingOptions = { DialogDescriptor.CANCEL_OPTION };
186: descriptor.setClosingOptions(closingOptions);
187: dialog = DialogDisplayer.getDefault().createDialog(
188: descriptor);
189: dialog.setResizable(true);
190: } catch (MissingResourceException e) {
191: e.printStackTrace();
192: }
193: }
194:
195: public boolean run() {
196: if (dialog != null)
197: dialog.setVisible(true);
198: return result;
199: }
200:
201: public void setViewName(String name) {
202: namefld.setText(name);
203: }
204:
205: public String getViewName() {
206: return namefld.getText();
207: }
208:
209: public String getViewCode() {
210: return tarea.getText();
211: }
212: }
|