1 30 package com.genimen.djeneric.tools.modeler.dialogs; 31 32 import java.awt.BorderLayout ; 33 import java.awt.Dimension ; 34 import java.awt.Toolkit ; 35 import java.awt.event.ActionEvent ; 36 import java.awt.event.KeyEvent ; 37 import java.awt.event.MouseEvent ; 38 import java.awt.event.WindowEvent ; 39 40 import javax.swing.DefaultComboBoxModel ; 41 import javax.swing.JButton ; 42 import javax.swing.JDialog ; 43 import javax.swing.JLabel ; 44 import javax.swing.JList ; 45 import javax.swing.JOptionPane ; 46 import javax.swing.JPanel ; 47 import javax.swing.JScrollPane ; 48 import javax.swing.JTextField ; 49 import javax.swing.event.ListSelectionEvent ; 50 51 import com.genimen.djeneric.language.Messages; 52 import com.genimen.djeneric.repository.DjModelView; 53 import com.genimen.djeneric.tools.modeler.ModelEditor; 54 import com.genimen.djeneric.ui.Util; 55 56 public class SaveAsDialog extends JDialog 57 { 58 private static final long serialVersionUID = 1L; 59 BorderLayout borderLayout1 = new BorderLayout (); 60 JScrollPane jScrollPane1 = new JScrollPane (); 61 JList _lstViews = new JList (); 62 JPanel jPanel1 = new JPanel (); 63 BorderLayout borderLayout2 = new BorderLayout (); 64 JPanel jPanel2 = new JPanel (); 65 JPanel jPanel3 = new JPanel (); 66 BorderLayout borderLayout3 = new BorderLayout (); 67 JPanel jPanel4 = new JPanel (); 68 JButton _butOk = new JButton (); 69 JButton _butCancel = new JButton (); 70 JLabel jLabel1 = new JLabel (); 71 72 boolean _canceled = true; 73 DjModelView[] _allViews; 74 DjModelView _modelView; 75 JPanel jPanel5 = new JPanel (); 76 BorderLayout borderLayout4 = new BorderLayout (); 77 JTextField _edtFileName = new JTextField (); 78 BorderLayout borderLayout5 = new BorderLayout (); 79 80 public SaveAsDialog(ModelEditor editor, DjModelView modelView) throws Exception 81 { 82 super(editor, Messages.getString("SaveAsDialog.SaveView"), true); 83 _modelView = modelView; 84 jbInit(); 85 86 _allViews = editor.getPersistenceManager().getViews(); 87 88 _lstViews.setModel(new DefaultComboBoxModel (_allViews)); 89 _edtFileName.setText(modelView.getCode()); 90 checkOkButtonEnabled(); 91 setSize(290, 230); 92 93 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 94 Dimension frameSize = getSize(); 95 setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); 96 } 97 98 public void execute() throws Exception 99 { 100 setVisible(true); 101 if (_canceled) throw new Exception (Messages.getString("SaveAsDialog.SaveAborted")); 102 } 103 104 void jbInit() throws Exception 105 { 106 this.getContentPane().setLayout(borderLayout1); 107 jPanel1.setLayout(borderLayout2); 108 jPanel3.setLayout(borderLayout3); 109 _butOk.setEnabled(false); 110 _butOk.setText(Messages.getString("global.Ok")); 111 _butOk.addActionListener(new java.awt.event.ActionListener () 112 { 113 public void actionPerformed(ActionEvent e) 114 { 115 _butOk_actionPerformed(e); 116 } 117 }); 118 _butCancel.setText(Messages.getString("global.Cancel")); 119 _butCancel.addActionListener(new java.awt.event.ActionListener () 120 { 121 public void actionPerformed(ActionEvent e) 122 { 123 _butCancel_actionPerformed(e); 124 } 125 }); 126 jPanel2.setLayout(borderLayout4); 127 jLabel1.setText(" " + Messages.getString("SaveAsDialog.SaveAs") + " "); 128 _lstViews.addListSelectionListener(new javax.swing.event.ListSelectionListener () 129 { 130 public void valueChanged(ListSelectionEvent e) 131 { 132 _lstViews_valueChanged(e); 133 } 134 }); 135 _edtFileName.setPreferredSize(new Dimension (230, 21)); 136 _edtFileName.setToolTipText(""); 137 _edtFileName.addKeyListener(new java.awt.event.KeyAdapter () 138 { 139 public void keyPressed(KeyEvent e) 140 { 141 _edtFileName_keyPressed(e); 142 } 143 }); 144 jPanel5.setLayout(borderLayout5); 145 _lstViews.addMouseListener(new java.awt.event.MouseAdapter () 146 { 147 public void mouseClicked(MouseEvent e) 148 { 149 _lstViews_mouseClicked(e); 150 } 151 }); 152 _lstViews.addKeyListener(new java.awt.event.KeyAdapter () 153 { 154 public void keyPressed(KeyEvent e) 155 { 156 _lstViews_keyPressed(e); 157 } 158 }); 159 this.addWindowListener(new java.awt.event.WindowAdapter () 160 { 161 public void windowOpened(WindowEvent e) 162 { 163 this_windowOpened(e); 164 } 165 }); 166 this.getContentPane().add(jScrollPane1, BorderLayout.CENTER); 167 this.getContentPane().add(jPanel1, BorderLayout.SOUTH); 168 jPanel1.add(jPanel2, BorderLayout.CENTER); 169 jPanel2.add(jLabel1, BorderLayout.WEST); 170 jPanel2.add(jPanel5, BorderLayout.CENTER); 171 jPanel5.add(_edtFileName, BorderLayout.CENTER); 172 jPanel1.add(jPanel3, BorderLayout.SOUTH); 173 jPanel3.add(jPanel4, BorderLayout.EAST); 174 jPanel4.add(_butCancel, null); 175 jPanel4.add(_butOk, null); 176 jScrollPane1.getViewport().add(_lstViews, null); 177 Util.sizeButtons(jPanel4); 178 } 179 180 void _lstViews_valueChanged(ListSelectionEvent e) 181 { 182 if (_lstViews.getSelectedIndex() == -1) return; 183 184 _edtFileName.setText(_lstViews.getSelectedValue().toString()); 185 checkOkButtonEnabled(); 186 } 187 188 void _butOk_actionPerformed(ActionEvent e) 189 { 190 String fn = getFileName(); 191 if (fn.trim().length() == 0) return; 192 193 String definition = _modelView.getDefinition(); 194 195 for (int i = 0; i < _allViews.length; i++) 196 { 197 if (fn.equalsIgnoreCase(_allViews[i].getCode())) 198 { 199 int result = JOptionPane.showOptionDialog(this, Messages.getString("SaveAsDialog.Overwrite1", fn), Messages 200 .getString("global.Sure2Overwrite", fn), JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, 201 new String []{Messages.getString("global.Overwrite"), 202 Messages.getString("global.Cancel")}, null); 203 if (result != 0) return; 204 _modelView = _allViews[i]; 205 break; 206 } 207 } 208 _canceled = false; 209 _modelView.setCode(getFileName().trim()); 210 _modelView.setDefinition(definition); 211 setVisible(false); 212 } 213 214 void _butCancel_actionPerformed(ActionEvent e) 215 { 216 setVisible(false); 217 } 218 219 protected String getFileName() 220 { 221 return _edtFileName.getText().trim(); 222 } 223 224 public DjModelView getModelView() 225 { 226 return _modelView; 227 } 228 229 void checkOkButtonEnabled() 230 { 231 _butOk.setEnabled(_edtFileName.getText().trim().length() != 0); 232 } 233 234 void _edtFileName_keyPressed(KeyEvent e) 235 { 236 checkOkButtonEnabled(); 237 if (e.getKeyCode() == KeyEvent.VK_ENTER) _butOk_actionPerformed(null); 238 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) _butCancel_actionPerformed(null); 239 } 240 241 void _lstViews_mouseClicked(MouseEvent e) 242 { 243 if (e.getClickCount() > 1) _butOk_actionPerformed(null); 244 } 245 246 void _lstViews_keyPressed(KeyEvent e) 247 { 248 if (e.getKeyCode() == KeyEvent.VK_ENTER) _butOk_actionPerformed(null); 249 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) _butCancel_actionPerformed(null); 250 } 251 252 void this_windowOpened(WindowEvent e) 253 { 254 _edtFileName.requestFocus(); 255 _edtFileName.selectAll(); 256 } 257 258 public void setViewName(String openedViewName) 259 { 260 _edtFileName.setText(openedViewName); 261 262 } 263 } | Popular Tags |