1 30 package com.genimen.djeneric.tools.modeler.extenteditor; 31 32 import java.awt.Component ; 33 import java.awt.event.ActionEvent ; 34 import java.awt.event.ActionListener ; 35 import java.awt.event.MouseEvent ; 36 import java.util.EventObject ; 37 38 import javax.swing.AbstractCellEditor ; 39 import javax.swing.JButton ; 40 import javax.swing.JTable ; 41 import javax.swing.table.TableCellEditor ; 42 43 import com.genimen.djeneric.language.Messages; 44 import com.genimen.djeneric.repository.DjExtent; 45 import com.genimen.djeneric.repository.DjProperty; 46 import com.genimen.djeneric.ui.DjTable; 47 import com.genimen.djeneric.ui.Util; 48 49 public class MappingCellEditor extends AbstractCellEditor implements ActionListener , TableCellEditor 50 { 51 private static final long serialVersionUID = 1L; 52 protected JButton editorComponent; 53 protected int clickCountToStart = 2; 54 55 DjExtent _extent; 56 PropertyTableModel _model; 57 58 public MappingCellEditor(DjExtent table, PropertyTableModel model) 59 { 60 _extent = table; 61 _model = model; 62 editorComponent = new JButton (); 63 editorComponent.addActionListener(this); 64 } 65 66 public Component getComponent() 67 { 68 return editorComponent; 69 } 70 71 public void setClickCountToStart(int count) 72 { 73 clickCountToStart = count; 74 } 75 76 public int getClickCountToStart() 77 { 78 return clickCountToStart; 79 } 80 81 public Object getCellEditorValue() 82 { 83 return _value; 84 } 85 86 Object _value = null; 87 88 public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) 89 { 90 _value = value; 91 DjProperty col = _extent.getProperty(row); 92 93 MappingChooser chooser = new MappingChooser(Util.findFrame(table), Messages 94 .getString("MappingCellEditor.SelectMapping"), value.toString(), _extent, col.getName()); 95 if (!chooser.isCancelled()) 96 { 97 if (chooser.getMapping() == null) return null; 98 _model.setValueAt(chooser.getMapping(), row, column); 99 if (table instanceof DjTable) 100 { 101 ((DjTable) table).nextCell(); 102 } 103 } 104 return null; 105 } 106 107 public boolean shouldSelectCell(EventObject anEvent) 108 { 109 return true; 110 } 111 112 public boolean startCellEditing(EventObject anEvent) 113 { 114 return true; 115 } 116 117 public boolean stopCellEditing() 118 { 119 fireEditingStopped(); 120 return true; 121 } 122 123 public void cancelCellEditing() 124 { 125 fireEditingCanceled(); 126 } 127 128 public void actionPerformed(ActionEvent e) 129 { 130 stopCellEditing(); 131 } 132 133 public boolean isCellEditable(EventObject anEvent) 134 { 135 if (anEvent instanceof MouseEvent ) 136 { 137 return ((MouseEvent ) anEvent).getClickCount() >= clickCountToStart; 138 } 139 return true; 140 } 141 } | Popular Tags |