View Javadoc

1   package com.explosion.datastream.exql.gui.table.editandrender;
2   
3   import java.awt.Component;
4   
5   import javax.swing.JTable;
6   
7   import org.apache.log4j.LogManager;
8   import org.apache.log4j.Logger;
9   
10  import com.explosion.expfmodules.rdbmsconn.dbom.DBEntity;
11  import com.explosion.expfmodules.rdbmsconn.dbom.DBEntityColumn;
12  import com.explosion.expfmodules.texteditor.ExpfTextField;
13  import com.explosion.utilities.exception.ExceptionManagerFactory;
14  
15  
16  /***
17   * @author Steve.Cowx
18   */
19  /***
20   * This includes support for cut copy paste select all etc from the main menu
21   * 
22   * @author Stephen Created on May 15, 2004
23   */
24  public class TextBasedTableCellEditor extends DefaultDsProCellEditor {
25  
26  	private DBEntity entity;
27  	private JTable table;
28  	private DBEntityColumn dbColumn;
29  	private static Logger log = LogManager.getLogger(TextBasedTableCellEditor.class);
30  
31  	public TextBasedTableCellEditor(Component highLevelParent, JTable table, final DBEntityColumn dbColumn) {
32  		super(new ExpfTextField(highLevelParent)); 
33  		
34          this.dbColumn = dbColumn;
35  		this.editorComponent.setForeground(table.getForeground());
36  		this.editorComponent.setBackground(table.getBackground());
37  
38  		/* We need to override the behaviour in the parent class 
39  		 * so that when the setValue method is called, it doesn;t just do a toString, 
40  		 * it converts the value properly instead of just doing the toString.*/
41  		delegate = new EditorDelegate() 
42  		{
43              public void setValue(Object value) 
44              {
45                  
46                  ((ExpfTextField)editorComponent).setText(EditorAndRenderFactory.renderValueForColumn(value, dbColumn));
47              }
48  		};
49  		
50  	}
51  
52  	protected void fireEditingStopped() {
53  		try
54  		{
55  		    //This is only done for the purpose of validating the value that has been edited.
56  		    // If it is not valid, then the editing is not stopped. 
57  		    EditorAndRenderFactory.convertIntoCorrectTypeForColumn(((ExpfTextField)editorComponent).getText(), dbColumn);
58  		}
59  		catch (Exception e)
60  		{
61  		    ExceptionManagerFactory.getExceptionManager().manageException(e,"Unacceptable data.");
62  		    return;
63  		}
64  	    super.fireEditingStopped();
65  	}
66  
67  	
68  	
69  	/***
70  	 * Returns the cellEditorValue
71  	 * @see javax.swing.CellEditor#getCellEditorValue()
72  	 * @return
73  	 */
74  	public Object getCellEditorValue() {
75  		if (((ExpfTextField)editorComponent).getText().equals(""))
76  		{
77  		    return null;
78  		}
79  		else
80  		{
81  		    if (dbColumn != null)
82  		    {
83  		          try {
84  		              
85  		              String valueToConvert = ((ExpfTextField)editorComponent).getText();
86  		              log.debug("Sending cell editor value " + valueToConvert + " of type " + valueToConvert.getClass().getName());
87  		              Object value = EditorAndRenderFactory.convertIntoCorrectTypeForColumn(valueToConvert, dbColumn);
88  		              log.debug("Returning cell editor value " + value + " of type " + value.getClass().getName());
89  		              return value;
90                  } catch (Exception e) {
91                      ExceptionManagerFactory.getExceptionManager().manageException(e,"Exception caught while obtaining value of cell");
92                      return "";
93                  }
94  		    }
95  		    else
96  		    {
97  		        String value = ((ExpfTextField)editorComponent).getText();
98  		        log.debug("Column is null, returning value as String " + value);
99  		        return value;
100 		    }
101 		}
102 	}
103 	
104 	
105 
106 }