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.util.ArrayList ; 38 import java.util.Collections ; 39 40 import javax.swing.DefaultComboBoxModel ; 41 import javax.swing.JButton ; 42 import javax.swing.JCheckBox ; 43 import javax.swing.JComboBox ; 44 import javax.swing.JDialog ; 45 import javax.swing.JLabel ; 46 import javax.swing.JOptionPane ; 47 import javax.swing.JPanel ; 48 import javax.swing.JTextField ; 49 50 import com.genimen.djeneric.language.Messages; 51 import com.genimen.djeneric.repository.DjExtent; 52 import com.genimen.djeneric.structure.EditorDefinition; 53 import com.genimen.djeneric.tools.modeler.ModelEditor; 54 import com.genimen.djeneric.ui.DjVerticalFlowLayout; 55 import com.genimen.djeneric.ui.Util; 56 import com.genimen.djeneric.util.DjLogger; 57 import com.genimen.djeneric.util.DjStringComparator; 58 59 public class CreateEditorDialog extends JDialog 60 { 61 private static final long serialVersionUID = 1L; 62 JPanel panel1 = new JPanel (); 63 BorderLayout borderLayout1 = new BorderLayout (); 64 JPanel jPanel1 = new JPanel (); 65 BorderLayout borderLayout2 = new BorderLayout (); 66 JPanel jPanel2 = new JPanel (); 67 BorderLayout borderLayout3 = new BorderLayout (); 68 JButton _butOk = new JButton (); 69 JButton _butCancel = new JButton (); 70 JPanel jPanel3 = new JPanel (); 71 JPanel jPanel4 = new JPanel (); 72 JLabel jLabel1 = new JLabel (); 73 JLabel jLabel2 = new JLabel (); 74 DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout(); 75 DjVerticalFlowLayout verticalFlowLayout2 = new DjVerticalFlowLayout(); 76 JTextField _edtEditorName = new JTextField (); 77 DjExtent _master; 78 DjExtent _detail; 79 String _mapping; 80 ModelEditor _modelEditor; 81 JComboBox _cbbExtent = new JComboBox (); 82 boolean _wasCanceled = true; 83 EditorDefinition[] _editorsDefined; 84 EditorDefinition _existingEditor; 85 JCheckBox _chkShowDiagOnly = new JCheckBox (); 86 87 public CreateEditorDialog(ModelEditor editor, EditorDefinition[] editorsDefined) 88 { 89 super(editor, Messages.getString("CreateEditorDialog.NewEditor"), true); 90 try 91 { 92 _editorsDefined = editorsDefined; 93 _modelEditor = editor; 94 95 jbInit(); 96 97 reloadExtentList(); 98 99 if (_cbbExtent.getSelectedIndex() == -1) return; 100 101 setSize(new Dimension (300, 150)); 102 103 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 104 Dimension frameSize = getSize(); 105 setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); 106 setVisible(true); 107 } 108 catch (Exception ex) 109 { 110 DjLogger.log(ex); 111 } 112 } 113 114 void jbInit() throws Exception 115 { 116 panel1.setLayout(borderLayout1); 117 this.getContentPane().setLayout(borderLayout2); 118 jPanel1.setLayout(borderLayout3); 119 _butOk.setText(Messages.getString("global.Ok")); 120 _butOk.addActionListener(new java.awt.event.ActionListener () 121 { 122 public void actionPerformed(ActionEvent e) 123 { 124 _butOk_actionPerformed(e); 125 } 126 }); 127 _butCancel.setText(Messages.getString("global.Cancel")); 128 _butCancel.addActionListener(new java.awt.event.ActionListener () 129 { 130 public void actionPerformed(ActionEvent e) 131 { 132 _butCancel_actionPerformed(e); 133 } 134 }); 135 jLabel1.setText(Messages.getString("global.Extent")); 136 jLabel2.setText(Messages.getString("global.Name")); 137 jPanel3.setLayout(verticalFlowLayout1); 138 jPanel4.setLayout(verticalFlowLayout2); 139 _edtEditorName.setPreferredSize(new Dimension (200, 21)); 140 _edtEditorName.addKeyListener(new java.awt.event.KeyAdapter () 141 { 142 public void keyPressed(KeyEvent e) 143 { 144 handleEnterEscape(e); 145 } 146 }); 147 _cbbExtent.setPreferredSize(new Dimension (240, 21)); 148 _chkShowDiagOnly.setSelected(true); 149 _chkShowDiagOnly.setText(Messages.getString("ViewEditor.DiagramExtentsOnly")); 150 _chkShowDiagOnly.addActionListener(new java.awt.event.ActionListener () 151 { 152 public void actionPerformed(ActionEvent e) 153 { 154 _chkShowDiagOnly_actionPerformed(e); 155 } 156 }); 157 getContentPane().add(panel1, BorderLayout.CENTER); 158 this.getContentPane().add(jPanel1, BorderLayout.SOUTH); 159 jPanel1.add(jPanel2, BorderLayout.EAST); 160 jPanel2.add(_butCancel, null); 161 jPanel2.add(_butOk, null); 162 jPanel1.add(_chkShowDiagOnly, BorderLayout.NORTH); 163 panel1.add(jPanel3, BorderLayout.WEST); 164 jPanel3.add(jLabel1, null); 165 jPanel3.add(jLabel2, null); 166 panel1.add(jPanel4, BorderLayout.CENTER); 167 jPanel4.add(_cbbExtent, null); 168 jPanel4.add(_edtEditorName, null); 169 Util.sizeButtons(this); 170 Util.sizeLabels(jPanel3); 171 } 172 173 void _butOk_actionPerformed(ActionEvent e) 174 { 175 String name = _edtEditorName.getText().trim(); 176 if (name.length() == 0 && _cbbExtent.getSelectedItem() != null) 177 { 178 name = _cbbExtent.getSelectedItem().toString() + "Editor"; 179 } 180 181 for (int i = 0; i < _editorsDefined.length; i++) 182 { 183 if (_editorsDefined[i].getName().equals(name) && (_editorsDefined[i] != _existingEditor)) 184 { 185 JOptionPane.showMessageDialog(this, Messages.getString("CreateEditorDialog.NameInUse", name), Messages 186 .getString("CreateEditorDialog.DuplicateName"), JOptionPane.WARNING_MESSAGE); 187 return; 188 } 189 } 190 _edtEditorName.setText(name); 191 _wasCanceled = false; 192 setVisible(false); 193 } 194 195 public boolean wasCanceled() 196 { 197 return _wasCanceled; 198 } 199 200 void _butCancel_actionPerformed(ActionEvent e) 201 { 202 setVisible(false); 203 } 204 205 void handleEnterEscape(KeyEvent e) 206 { 207 if (e.getKeyCode() == KeyEvent.VK_ENTER) _butOk_actionPerformed(null); 208 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) _butCancel_actionPerformed(null); 209 } 210 211 public String getEditorName() 212 { 213 return _edtEditorName.getText().trim(); 214 } 215 216 public DjExtent getExtent() 217 { 218 return (DjExtent) _cbbExtent.getSelectedItem(); 219 } 220 221 void _chkShowDiagOnly_actionPerformed(ActionEvent e) 222 { 223 reloadExtentList(); 224 } 225 226 private void reloadExtentList() 227 { 228 DefaultComboBoxModel model; 229 230 ArrayList onDiag = _modelEditor.getExtentsOnDiagram(); 231 Collections.sort(onDiag, new DjStringComparator(false)); 232 233 if (_chkShowDiagOnly.isSelected()) model = new DefaultComboBoxModel (onDiag.toArray()); 234 else model = new DefaultComboBoxModel (_modelEditor.getPersistenceManager().getExtentsSorted()); 235 236 _cbbExtent.setModel(model); 237 if (model.getSize() > 0) 238 { 239 _cbbExtent.setSelectedIndex(0); 240 } 241 } 242 } | Popular Tags |