001: /*
002: * StatementParameterTableModel.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.gui.preparedstatement;
013:
014: import javax.swing.table.TableModel;
015: import workbench.resource.ResourceMgr;
016: import workbench.sql.preparedstatement.StatementParameters;
017: import workbench.util.SqlUtil;
018:
019: /**
020: * @author support@sql-workbench.net
021: */
022: public class StatementParameterTableModel implements TableModel {
023: private String[] columns = {
024: ResourceMgr.getString("TxtPSParameterIndex"),
025: ResourceMgr.getString("TxtPSParameterType"),
026: ResourceMgr.getString("TxtPSParameterValue") };
027: private Integer[] parameterIndex;
028: private String[] types;
029: private String[] values;
030: private StatementParameters parms;
031:
032: public StatementParameterTableModel(StatementParameters parm) {
033: this .parms = parm;
034: int count = parm.getParameterCount();
035: this .parameterIndex = new Integer[count];
036: this .types = new String[count];
037: this .values = new String[count];
038: for (int i = 0; i < count; i++) {
039: this .parameterIndex[i] = new Integer(i + 1);
040: this .types[i] = SqlUtil.getTypeName(parm
041: .getParameterType(i));
042: Object v = parm.getParameterValue(i);
043: this .values[i] = (v == null ? "" : v.toString());
044: }
045: }
046:
047: public void addTableModelListener(
048: javax.swing.event.TableModelListener l) {
049: }
050:
051: public Class getColumnClass(int columnIndex) {
052: if (columnIndex == 0) {
053: return Integer.class;
054: } else {
055: return String.class;
056: }
057: }
058:
059: public int getColumnCount() {
060: return 3;
061: }
062:
063: public String getColumnName(int columnIndex) {
064: return columns[columnIndex];
065: }
066:
067: public int getRowCount() {
068: return this .parms.getParameterCount();
069: }
070:
071: public String getParameterValue(int index) {
072: return this .values[index];
073: }
074:
075: public Object getValueAt(int rowIndex, int columnIndex) {
076: if (columnIndex == 0) {
077: return parameterIndex[rowIndex];
078: } else if (columnIndex == 1) {
079: return types[rowIndex];
080: } else {
081: return values[rowIndex];
082: }
083: }
084:
085: public boolean isCellEditable(int rowIndex, int columnIndex) {
086: return (columnIndex == 2);
087: }
088:
089: public void removeTableModelListener(
090: javax.swing.event.TableModelListener l) {
091: }
092:
093: public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
094: if (columnIndex == 2) {
095: this .values[rowIndex] = (aValue == null ? "" : aValue
096: .toString());
097: }
098: }
099:
100: }
|