1 package com.genimen.djeneric.tools.specifier.dialogs; 2 3 import java.awt.BorderLayout ; 4 import java.awt.Dimension ; 5 import java.awt.Frame ; 6 import java.awt.Toolkit ; 7 import java.awt.event.ActionEvent ; 8 import java.awt.event.ActionListener ; 9 import java.util.ArrayList ; 10 11 import javax.swing.JButton ; 12 import javax.swing.JDialog ; 13 import javax.swing.JPanel ; 14 import javax.swing.JScrollPane ; 15 import javax.swing.JTable ; 16 import javax.swing.table.TableCellEditor ; 17 import javax.swing.table.TableCellRenderer ; 18 19 import com.genimen.djeneric.language.Messages; 20 import com.genimen.djeneric.repository.DjDomain; 21 import com.genimen.djeneric.repository.DjObject; 22 import com.genimen.djeneric.repository.DjProperty; 23 import com.genimen.djeneric.repository.exceptions.DjenericException; 24 import com.genimen.djeneric.repository.exceptions.ObjectNotDefinedException; 25 import com.genimen.djeneric.ui.DjModelColumn; 26 import com.genimen.djeneric.ui.DjTableModel; 27 import com.genimen.djeneric.ui.Util; 28 import com.genimen.djeneric.util.DjLogger; 29 30 public class ObjectInspectorDialog extends JDialog 31 { 32 private static final long serialVersionUID = 1L; 33 JPanel _buttonPanel = new JPanel (); 34 BorderLayout borderLayout2 = new BorderLayout (); 35 JPanel _buttonEast = new JPanel (); 36 JButton _butOk = new JButton (); 37 JScrollPane _scroller = new JScrollPane (); 38 JTable _table = new JTable (); 39 BorderLayout borderLayout3 = new BorderLayout (); 40 41 public ObjectInspectorDialog(Frame owner, DjObject object) 42 { 43 super(owner, object == null ? "Inspect" : object.toString(), true); 44 try 45 { 46 setDefaultCloseOperation(DISPOSE_ON_CLOSE); 47 jbInit(); 48 49 if (object != null) _table.setModel(new ChangesTableModel(object)); 50 setSize(400, 200); 51 52 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 53 Dimension frameSize = getSize(); 54 setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); 55 setVisible(true); 56 } 57 catch (Exception x) 58 { 59 DjLogger.log(x); 60 } 61 } 62 63 public ObjectInspectorDialog() 64 { 65 this(new Frame (), null); 66 } 67 68 private void jbInit() throws Exception 69 { 70 _buttonPanel.setLayout(borderLayout2); 71 _butOk.setText(Messages.getString("global.Ok")); 72 _butOk.addActionListener(new ObjectInspectorDlg__butOk_actionAdapter(this)); 73 this.getContentPane().setLayout(borderLayout3); 74 _buttonPanel.add(_buttonEast, java.awt.BorderLayout.EAST); 75 _buttonEast.add(_butOk); 76 _scroller.getViewport().add(_table); 77 this.getContentPane().add(_scroller, java.awt.BorderLayout.CENTER); 78 this.getContentPane().add(_buttonPanel, java.awt.BorderLayout.SOUTH); 79 Util.sizeButtons(_buttonEast); 80 81 } 82 83 public void _butOk_actionPerformed(ActionEvent e) 84 { 85 setVisible(false); 86 } 87 } 88 89 class ObjectInspectorDlg__butOk_actionAdapter implements ActionListener 90 { 91 private ObjectInspectorDialog adaptee; 92 93 ObjectInspectorDlg__butOk_actionAdapter(ObjectInspectorDialog adaptee) 94 { 95 this.adaptee = adaptee; 96 } 97 98 public void actionPerformed(ActionEvent e) 99 { 100 adaptee._butOk_actionPerformed(e); 101 } 102 } 103 104 class ChangesTableModel extends DjTableModel 105 { 106 private static final long serialVersionUID = 1L; 107 private final static int _colCount = 3; 108 109 private final static int IDX_NAME = 0; 110 private final static int IDX_OLD = 1; 111 private final static int IDX_NEW = 2; 112 113 String _propertyNames[]; 114 DjObject _object; 115 116 public ChangesTableModel(DjObject object) 117 { 118 _columns = new DjModelColumn[_colCount]; 119 _object = object; 120 121 ArrayList changedProps = new ArrayList (); 122 for (int i = 0; i < object.getPropertyCount(); i++) 123 { 124 if (object.isPropertyChanged(i)) changedProps.add(object.getProperty(i).getName()); 125 } 126 _propertyNames = (String []) changedProps.toArray(new String [0]); 127 128 _columns[IDX_NAME] = new DjModelColumn(Messages.getString("ObjectInspector.Property"), 60, null); 129 _columns[IDX_OLD] = new DjModelColumn(Messages.getString("ObjectInspector.OldValue"), 60, null); 130 _columns[IDX_NEW] = new DjModelColumn(Messages.getString("ObjectInspector.NewValue"), 60, null); 131 setEditable(false); 132 setInsertable(false); 133 setDeleteable(false); 134 } 135 136 public TableCellEditor getColumnEditor(int column) 137 { 138 return null; 139 } 140 141 public TableCellRenderer getColumnRenderer(int column) 142 { 143 return _columns[column].getCellRenderer(); 144 } 145 146 public int getRowCount() 147 { 148 return _propertyNames.length; 149 } 150 151 public int getColumnCount() 152 { 153 return _colCount; 154 } 155 156 public Object getValueAt(int row, int col) 157 { 158 try 159 { 160 if (col == IDX_NAME) return _object.getExtent().getProperty(_propertyNames[row]).getPrompt(); 161 if (col == IDX_OLD) return getDspValue(_propertyNames[row], _object.getString(_propertyNames[row])); 162 if (col == IDX_NEW) return getDspValue(_propertyNames[row], _object.getOriginalValueString(_propertyNames[row])); 163 return "Unknown idx: " + col; 164 } 165 catch (Exception x) 166 { 167 DjLogger.log(x); 168 return x.getMessage(); 169 } 170 } 171 172 private Object getDspValue(String propName, String value) throws ObjectNotDefinedException 173 { 174 DjProperty prop = _object.getProperty(propName); 175 if (prop.getType() instanceof DjDomain) 176 { 177 DjDomain domain = (DjDomain) prop.getType(); 178 String descr = domain.translateCode(value); 179 if (descr != null) value = descr; 180 } 181 return value; 182 } 183 184 public void setValueAt(Object aValue, int rowIndex, int columnIndex) 185 { 186 } 187 188 public int insertRow(int atIdx) throws DjenericException 189 { 190 return 0; 191 } 192 193 public boolean deleteRow(int atIdx) throws DjenericException 194 { 195 return false; 196 } 197 } 198 | Popular Tags |