1 19 20 package org.netbeans.modules.db.explorer.dlg; 21 22 import java.awt.*; 23 import java.awt.event.*; 24 import java.util.*; 25 import javax.swing.*; 26 import javax.swing.border.EmptyBorder ; 27 import org.openide.DialogDescriptor; 28 import org.openide.DialogDisplayer; 29 import org.openide.util.NbBundle; 30 import org.openide.NotifyDescriptor; 31 import org.netbeans.lib.ddl.impl.CreateView; 32 import org.netbeans.lib.ddl.impl.Specification; 33 import org.netbeans.lib.ddl.*; 34 import org.netbeans.modules.db.explorer.infos.DatabaseNodeInfo; 35 import org.netbeans.modules.db.explorer.*; 36 import org.openide.awt.Mnemonics; 37 38 public class AddViewDialog { 39 boolean result = false; 40 Dialog dialog = null; 41 JTextField namefld; 42 JTextArea tarea; 43 44 public AddViewDialog(final Specification spec, final DatabaseNodeInfo info) { 45 try { 46 ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle"); JPanel pane = new JPanel(); 48 pane.setBorder(new EmptyBorder (new Insets(5,5,5,5))); 49 GridBagLayout layout = new GridBagLayout(); 50 GridBagConstraints con = new GridBagConstraints (); 51 pane.setLayout (layout); 52 53 55 JLabel label = new JLabel(); 56 Mnemonics.setLocalizedText(label, bundle.getString("AddViewName")); 57 label.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_AddViewNameA11yDesc")); 58 con.anchor = GridBagConstraints.WEST; 59 con.insets = new java.awt.Insets (2, 2, 2, 2); 60 con.gridx = 0; 61 con.gridy = 0; 62 layout.setConstraints(label, con); 63 pane.add(label); 64 65 67 con.fill = GridBagConstraints.HORIZONTAL; 68 con.weightx = 1.0; 69 con.gridx = 1; 70 con.gridy = 0; 71 con.insets = new java.awt.Insets (2, 2, 2, 2); 72 namefld = new JTextField(35); 73 namefld.setToolTipText(bundle.getString("ACS_AddViewNameTextFieldA11yDesc")); 74 namefld.getAccessibleContext().setAccessibleName(bundle.getString("ACS_AddViewNameTextFieldA11yName")); 75 label.setLabelFor(namefld); 76 layout.setConstraints(namefld, con); 77 pane.add(namefld); 78 79 81 label = new JLabel(); 82 Mnemonics.setLocalizedText(label, bundle.getString("AddViewLabel")); 83 label.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_AddViewLabelA11yDesc")); 84 con.weightx = 0.0; 85 con.anchor = GridBagConstraints.WEST; 86 con.insets = new java.awt.Insets (2, 2, 2, 2); 87 con.gridx = 0; 88 con.gridy = 1; 89 con.gridwidth = 2; 90 layout.setConstraints(label, con); 91 pane.add(label); 92 93 95 tarea = new JTextArea(5,50); 96 tarea.setToolTipText(bundle.getString("ACS_AddViewTextAreaA11yDesc")); 97 tarea.getAccessibleContext().setAccessibleName(bundle.getString("ACS_AddViewTextAreaA11yName")); 98 label.setLabelFor(tarea); 99 100 con.weightx = 1.0; 101 con.weighty = 1.0; 102 con.gridwidth = 2; 103 con.fill = GridBagConstraints.BOTH; 104 con.insets = new java.awt.Insets (0, 0, 0, 0); 105 con.gridx = 0; 106 con.gridy = 2; 107 JScrollPane spane = new JScrollPane(tarea); 108 layout.setConstraints(spane, con); 109 pane.add(spane); 110 111 ActionListener listener = new ActionListener() { 112 public void actionPerformed(ActionEvent event) { 113 114 if (event.getSource() == DialogDescriptor.OK_OPTION) { 115 116 try { 117 CreateView cmd = spec.createCommandCreateView(getViewName()); 118 cmd.setQuery(getViewCode()); 119 cmd.setObjectOwner((String )info.get(DatabaseNodeInfo.SCHEMA)); 120 cmd.execute(); 121 result = !cmd.wasException(); 122 123 if (!cmd.wasException()) { 124 dialog.setVisible(false); 125 dialog.dispose(); 126 } 127 } catch (CommandNotSupportedException e) { 128 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE)); 129 } catch (DDLException e) { 130 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE)); 131 } catch (Exception e) { 132 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE)); 133 } 134 } 135 } 136 }; 137 138 pane.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_AddViewDialogA11yDesc")); 140 DialogDescriptor descriptor = new DialogDescriptor(pane, bundle.getString("AddViewTitle"), true, listener); Object [] closingOptions = {DialogDescriptor.CANCEL_OPTION}; 144 descriptor.setClosingOptions(closingOptions); 145 dialog = DialogDisplayer.getDefault().createDialog(descriptor); 146 dialog.setResizable(true); 147 } catch (MissingResourceException e) { 148 e.printStackTrace(); 149 } 150 } 151 152 public boolean run() 153 { 154 if (dialog != null) dialog.setVisible(true); 155 return result; 156 } 157 158 public void setViewName(String name) 159 { 160 namefld.setText(name); 161 } 162 163 public String getViewName() 164 { 165 return namefld.getText(); 166 } 167 168 public String getViewCode() 169 { 170 return tarea.getText(); 171 } 172 } 173 | Popular Tags |