001: package net.sourceforge.squirrel_sql.plugins.oracle.invalidobjects;
002:
003: /*
004: * Copyright (C) 2004 Jason Height
005: * jmheight@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021:
022: import net.sourceforge.squirrel_sql.client.IApplication;
023: import net.sourceforge.squirrel_sql.client.session.ISession;
024: import net.sourceforge.squirrel_sql.fw.util.StringManager;
025: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
026: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
027: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
028: import net.sourceforge.squirrel_sql.plugins.oracle.common.AutoWidthResizeTable;
029:
030: import javax.swing.*;
031: import javax.swing.table.DefaultTableModel;
032: import java.awt.*;
033: import java.sql.PreparedStatement;
034: import java.sql.ResultSet;
035: import java.sql.SQLException;
036:
037: public class InvalidObjectsPanel extends JPanel {
038: private static final StringManager s_stringMgr = StringManagerFactory
039: .getStringManager(InvalidObjectsPanel.class);
040:
041: /**
042: * Logger for this class.
043: */
044: private static final ILogger s_log = LoggerController
045: .createLogger(InvalidObjectsPanel.class);
046:
047: /**
048: * Current session.
049: */
050: private ISession _session;
051:
052: private AutoWidthResizeTable _invalidObjects;
053: private boolean hasResized = false;
054:
055: private static final String invalidObjectSQL = "SELECT owner, "
056: + "object_name, " + "object_type "
057: + "FROM sys.all_objects " + "WHERE status = 'INVALID'";
058:
059: /**
060: * Ctor.
061: *
062: * @param session Current session.
063: * @throws IllegalArgumentException Thrown if a <TT>null</TT> <TT>ISession</TT> passed.
064: */
065: public InvalidObjectsPanel(ISession session) {
066: super ();
067: _session = session;
068: createGUI();
069: }
070:
071: /**
072: * Current session.
073: */
074: public ISession getSession() {
075: return _session;
076: }
077:
078: protected DefaultTableModel createTableModel() {
079: DefaultTableModel tm = new DefaultTableModel() {
080: public boolean isCellEditable(int row, int column) {
081: return false;
082: }
083: };
084:
085: // i18n[oracle.owner=Owner]
086: tm.addColumn(s_stringMgr.getString("oracle.owner"));
087: // i18n[oracle.objectName=Object Name]
088: tm.addColumn(s_stringMgr.getString("oracle.objectName"));
089: // i18n[oracle.objectType=Object Type]
090: tm.addColumn(s_stringMgr.getString("oracle.objectType"));
091: return tm;
092: }
093:
094: public synchronized void repopulateInvalidObjects() {
095: try {
096: PreparedStatement s = _session.getSQLConnection()
097: .getConnection().prepareStatement(invalidObjectSQL);
098: if (s.execute()) {
099: ResultSet rs = s.getResultSet();
100: DefaultTableModel tm = createTableModel();
101: while (rs.next()) {
102: String owner = rs.getString(1);
103: String object_name = rs.getString(2);
104: String object_type = rs.getString(3);
105: //Should probably create my own table model but i am being a bit slack.
106: tm.addRow(new Object[] { owner, object_name,
107: object_type });
108: }
109: _invalidObjects.setModel(tm);
110: if (!hasResized) {
111: //Only resize once.
112: hasResized = true;
113: _invalidObjects.resizeColumnWidth(300);
114: }
115: }
116: } catch (SQLException ex) {
117: _session.showErrorMessage(ex);
118: }
119: }
120:
121: private void createGUI() {
122: setLayout(new BorderLayout());
123: _invalidObjects = new AutoWidthResizeTable();
124: _invalidObjects.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
125: add(new JScrollPane(_invalidObjects));
126:
127: repopulateInvalidObjects();
128: }
129:
130: }
|