1 package com.genimen.djeneric.tools.specifier.dialogs; 2 3 import java.awt.BorderLayout ; 4 import java.awt.Color ; 5 import java.awt.Component ; 6 import java.awt.Dimension ; 7 import java.awt.Frame ; 8 import java.awt.Toolkit ; 9 import java.awt.event.ActionEvent ; 10 import java.awt.event.ActionListener ; 11 import java.awt.event.KeyAdapter ; 12 import java.awt.event.KeyEvent ; 13 import java.awt.event.MouseAdapter ; 14 import java.awt.event.MouseEvent ; 15 import java.util.Collections ; 16 import java.util.Comparator ; 17 18 import javax.swing.DefaultComboBoxModel ; 19 import javax.swing.JButton ; 20 import javax.swing.JDialog ; 21 import javax.swing.JLabel ; 22 import javax.swing.JList ; 23 import javax.swing.JPanel ; 24 import javax.swing.JScrollPane ; 25 import javax.swing.JTabbedPane ; 26 import javax.swing.ListCellRenderer ; 27 28 import com.genimen.djeneric.language.Messages; 29 import com.genimen.djeneric.repository.DjObject; 30 import com.genimen.djeneric.repository.util.DjObjectImporter; 31 import com.genimen.djeneric.ui.Util; 32 import com.genimen.djeneric.util.DjLogger; 33 34 public class ImportResultDialog extends JDialog 35 { 36 private static final long serialVersionUID = 1L; 37 JPanel panel1 = new JPanel (); 38 BorderLayout borderLayout1 = new BorderLayout (); 39 JTabbedPane _tabs = new JTabbedPane (); 40 JPanel _buttonPanel = new JPanel (); 41 BorderLayout borderLayout2 = new BorderLayout (); 42 JPanel _buttonEast = new JPanel (); 43 JButton _butSave = new JButton (); 44 JButton _butCancel = new JButton (); 45 JPanel _pnlCreated = new JPanel (); 46 JPanel _pnlDeleted = new JPanel (); 47 JPanel _pnlUpdated = new JPanel (); 48 JScrollPane _scrDeleted = new JScrollPane (); 49 BorderLayout borderLayout3 = new BorderLayout (); 50 BorderLayout borderLayout4 = new BorderLayout (); 51 BorderLayout borderLayout5 = new BorderLayout (); 52 JScrollPane _scrUpdated = new JScrollPane (); 53 JScrollPane _scrCreated = new JScrollPane (); 54 JList _lstDeleted = new JList (); 55 JList _lstCreated = new JList (); 56 JList _lstUpdated = new JList (); 57 boolean _wasCancelled = true; 58 Frame _owner; 59 JPanel jPanel1 = new JPanel (); 60 BorderLayout borderLayout6 = new BorderLayout (); 61 JPanel jPanel2 = new JPanel (); 62 JButton _butDetails = new JButton (); 63 64 public ImportResultDialog(Frame owner, DjObjectImporter importer) 65 { 66 super(owner, Messages.getString("ObjectImporter.CheckResults"), true); 67 try 68 { 69 _owner = owner; 70 setDefaultCloseOperation(DISPOSE_ON_CLOSE); 71 jbInit(); 72 73 importer.getCreated().sort(); 74 importer.getUpdated().sort(); 75 importer.getDeleted().sort(); 76 77 ResultListCellRenderer renderer = new ResultListCellRenderer(); 78 79 _lstCreated.setCellRenderer(renderer); 80 _lstUpdated.setCellRenderer(renderer); 81 _lstDeleted.setCellRenderer(renderer); 82 83 ImportResultComparator irc = new ImportResultComparator(); 84 Collections.sort(importer.getCreated(), irc); 85 Collections.sort(importer.getUpdated(), irc); 86 Collections.sort(importer.getDeleted(), irc); 87 88 _lstCreated.setModel(new DefaultComboBoxModel (importer.getCreated().toArray())); 89 _lstUpdated.setModel(new DefaultComboBoxModel (importer.getUpdated().toArray())); 90 _lstDeleted.setModel(new DefaultComboBoxModel (importer.getDeleted().toArray())); 91 92 setSize(500, 400); 93 94 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 95 Dimension frameSize = getSize(); 96 setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); 97 setVisible(true); 98 } 99 catch (Exception x) 100 { 101 DjLogger.log(x); 102 } 103 } 104 105 public boolean wasCancelled() 106 { 107 return _wasCancelled; 108 } 109 110 private void jbInit() throws Exception 111 { 112 panel1.setLayout(borderLayout1); 113 _buttonPanel.setLayout(borderLayout2); 114 115 _butSave.setText(Messages.getString("global.Save")); 116 _butSave.addActionListener(new ImportResultDialog__butSave_actionAdapter(this)); 117 _butCancel.setText(Messages.getString("global.Cancel")); 118 _butCancel.addActionListener(new ImportResultDialog__butCancel_actionAdapter(this)); 119 _pnlDeleted.setLayout(borderLayout3); 120 _pnlCreated.setLayout(borderLayout4); 121 _pnlUpdated.setLayout(borderLayout5); 122 _lstUpdated.addMouseListener(new ImportResultDialog__lstCreated_mouseAdapter(this)); 123 _lstUpdated.addKeyListener(new ImportResultDialog__lstCreated_keyAdapter(this)); 124 jPanel1.setLayout(borderLayout6); 125 _butDetails.setText(Messages.getString("ObjectImporter.Details")); 126 _butDetails.addActionListener(new ImportResultDialog__butDetails_actionAdapter(this)); 127 getContentPane().add(panel1); 128 panel1.add(_tabs, java.awt.BorderLayout.CENTER); 129 panel1.add(_buttonPanel, java.awt.BorderLayout.SOUTH); 130 _buttonPanel.add(_buttonEast, java.awt.BorderLayout.EAST); 131 _buttonEast.add(_butCancel); 132 _buttonEast.add(_butSave); 133 _tabs.add(_pnlCreated, "Created"); 134 _tabs.add(_pnlUpdated, "Updated"); 135 _tabs.add(_pnlDeleted, "Deleted"); 136 _pnlDeleted.add(_scrDeleted, java.awt.BorderLayout.CENTER); 137 _scrDeleted.getViewport().add(_lstDeleted); 138 _pnlCreated.add(_scrCreated, java.awt.BorderLayout.CENTER); 139 _scrCreated.getViewport().add(_lstCreated); 140 _pnlUpdated.add(_scrUpdated, java.awt.BorderLayout.CENTER); 141 _scrUpdated.getViewport().add(_lstUpdated); 142 _pnlUpdated.add(jPanel1, java.awt.BorderLayout.SOUTH); 143 jPanel1.add(jPanel2, java.awt.BorderLayout.EAST); 144 jPanel2.add(_butDetails); 145 Util.sizeButtons(_buttonEast); 146 } 147 148 public void _butSave_actionPerformed(ActionEvent e) 149 { 150 _wasCancelled = false; 151 setVisible(false); 152 } 153 154 public void _butCancel_actionPerformed(ActionEvent e) 155 { 156 setVisible(false); 157 } 158 159 public void _lstCreated_mouseClicked(MouseEvent e) 160 { 161 if (e.getClickCount() >= 2) showDetails(); 162 } 163 164 public void _lstCreated_keyPressed(KeyEvent e) 165 { 166 if (e.getKeyCode() == KeyEvent.VK_ENTER) showDetails(); 167 } 168 169 private void showDetails() 170 { 171 DjObject object = (DjObject) _lstUpdated.getSelectedValue(); 172 if (object != null) new ObjectInspectorDialog(_owner, object); 173 } 174 175 public void _butDetails_actionPerformed(ActionEvent e) 176 { 177 showDetails(); 178 } 179 } 180 181 class ImportResultDialog__butDetails_actionAdapter implements ActionListener 182 { 183 private ImportResultDialog adaptee; 184 185 ImportResultDialog__butDetails_actionAdapter(ImportResultDialog adaptee) 186 { 187 this.adaptee = adaptee; 188 } 189 190 public void actionPerformed(ActionEvent e) 191 { 192 adaptee._butDetails_actionPerformed(e); 193 } 194 } 195 196 class ImportResultDialog__lstCreated_keyAdapter extends KeyAdapter 197 { 198 private ImportResultDialog adaptee; 199 200 ImportResultDialog__lstCreated_keyAdapter(ImportResultDialog adaptee) 201 { 202 this.adaptee = adaptee; 203 } 204 205 public void keyPressed(KeyEvent e) 206 { 207 adaptee._lstCreated_keyPressed(e); 208 } 209 } 210 211 class ImportResultDialog__lstCreated_mouseAdapter extends MouseAdapter 212 { 213 private ImportResultDialog adaptee; 214 215 ImportResultDialog__lstCreated_mouseAdapter(ImportResultDialog adaptee) 216 { 217 this.adaptee = adaptee; 218 } 219 220 public void mouseClicked(MouseEvent e) 221 { 222 adaptee._lstCreated_mouseClicked(e); 223 } 224 } 225 226 class ImportResultDialog__butCancel_actionAdapter implements ActionListener 227 { 228 private ImportResultDialog adaptee; 229 230 ImportResultDialog__butCancel_actionAdapter(ImportResultDialog adaptee) 231 { 232 this.adaptee = adaptee; 233 } 234 235 public void actionPerformed(ActionEvent e) 236 { 237 adaptee._butCancel_actionPerformed(e); 238 } 239 } 240 241 class ImportResultDialog__butSave_actionAdapter implements ActionListener 242 { 243 private ImportResultDialog adaptee; 244 245 ImportResultDialog__butSave_actionAdapter(ImportResultDialog adaptee) 246 { 247 this.adaptee = adaptee; 248 } 249 250 public void actionPerformed(ActionEvent e) 251 { 252 adaptee._butSave_actionPerformed(e); 253 } 254 } 255 256 class ResultListCellRenderer extends JLabel implements ListCellRenderer 257 { 258 private static final long serialVersionUID = 1L; 259 260 public ResultListCellRenderer() 261 { 262 } 263 264 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, 265 boolean cellHasFocus) 266 { 267 DjObject object = (DjObject) value; 268 setText(object.getExtent().getNameSingular() + ": " + value.toString()); 269 if (isSelected) 270 { 271 setOpaque(true); 272 setBackground(Color.BLACK); 273 setForeground(Color.WHITE); 274 } 275 else 276 { 277 setOpaque(false); 278 setBackground(Color.WHITE); 279 setForeground(Color.BLACK); 280 } 281 return this; 282 } 283 } 284 285 class ImportResultComparator implements Comparator 286 { 287 288 public int compare(Object o1, Object o2) 289 { 290 if (!(o1 instanceof DjObject && o2 instanceof DjObject)) return 0; 291 292 DjObject djo1 = (DjObject) o1; 293 DjObject djo2 = (DjObject) o2; 294 295 String s1 = djo1.getExtent().getName() + djo1.toString(); 296 String s2 = djo2.getExtent().getName() + djo2.toString(); 297 return s1.compareTo(s2); 298 } 299 } 300 | Popular Tags |