01: package net.sourceforge.squirrel_sql.plugins.mssql.util;
02:
03: /*
04: * Copyright (C) 2004 Ryan Walberg <generalpf@yahoo.com>
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20:
21: import java.awt.Component;
22:
23: import javax.swing.ImageIcon;
24: import javax.swing.JTable;
25: import javax.swing.table.DefaultTableCellRenderer;
26:
27: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
28: import net.sourceforge.squirrel_sql.plugins.mssql.MssqlPlugin;
29:
30: public class DatabaseObjectInfoRenderer extends
31: DefaultTableCellRenderer {
32:
33: private static final long serialVersionUID = 1L;
34:
35: /** Creates a new instance of DatabaseObjectInfoRenderer */
36: public DatabaseObjectInfoRenderer() {
37: }
38:
39: public Component getTableCellRendererComponent(JTable table,
40: Object value, boolean isSelected, boolean hasFocus,
41: int row, int column) {
42:
43: super .getTableCellRendererComponent(table, value, isSelected,
44: hasFocus, row, column);
45:
46: if (value instanceof IDatabaseObjectInfo) {
47: IDatabaseObjectInfo oi = (IDatabaseObjectInfo) value;
48:
49: String gif;
50: String simpleName = oi.getSimpleName();
51:
52: int mssqlType = MssqlIntrospector.getObjectInfoType(oi);
53: switch (mssqlType) {
54: case MssqlIntrospector.MSSQL_TABLE:
55: gif = "properties.gif";
56: break;
57: case MssqlIntrospector.MSSQL_VIEW:
58: gif = "arraypartition_obj.gif";
59: break;
60: case MssqlIntrospector.MSSQL_STOREDPROCEDURE:
61: simpleName = simpleName.replaceAll(";0", "");
62: gif = "thread_view.gif";
63: break;
64: case MssqlIntrospector.MSSQL_UDF:
65: simpleName = simpleName.replaceAll(";1", "");
66: gif = "variable_tab.gif";
67: break;
68: case MssqlIntrospector.MSSQL_UDT:
69: gif = "type.gif";
70: break;
71: default:
72: gif = "error_co.gif";
73: }
74:
75: java.net.URL url = MssqlPlugin.class
76: .getResource("resources/icons/eclipse/" + gif);
77: if (url != null) {
78: setText(simpleName);
79: setIcon(new ImageIcon(url, oi.getDatabaseObjectType()
80: .toString()));
81: return this;
82: } else
83: return null;
84: } else
85: return null;
86: }
87:
88: }
|