001: package net.sourceforge.squirrel_sql.plugins.oracle.sessioninfo;
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.gui.session.BaseSessionInternalFrame;
024: import net.sourceforge.squirrel_sql.client.session.ISession;
025: import net.sourceforge.squirrel_sql.fw.gui.ToolBar;
026: import net.sourceforge.squirrel_sql.fw.id.IIdentifier;
027: import net.sourceforge.squirrel_sql.fw.util.Resources;
028: import net.sourceforge.squirrel_sql.fw.util.StringManager;
029: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
030: import net.sourceforge.squirrel_sql.plugins.oracle.OracleInternalFrame;
031: import net.sourceforge.squirrel_sql.plugins.oracle.OracleInternalFrameCallback;
032: import net.sourceforge.squirrel_sql.plugins.oracle.dboutput.DBOutputPanel;
033:
034: import javax.swing.*;
035: import javax.swing.event.ChangeEvent;
036: import javax.swing.event.ChangeListener;
037: import javax.swing.event.InternalFrameAdapter;
038: import javax.swing.event.InternalFrameEvent;
039: import java.awt.*;
040: import java.awt.event.ActionEvent;
041: import java.awt.event.ActionListener;
042:
043: public class SessionInfoInternalFrame extends OracleInternalFrame {
044:
045: private static final String PREF_PART_INFO_FRAME = "InfoFrame";
046:
047: private static final StringManager s_stringMgr = StringManagerFactory
048: .getStringManager(SessionInfoInternalFrame.class);
049:
050: private SessionInfoPanel _sessionInfoPanel;
051: /**
052: * Toolbar for window.
053: */
054: private SessionInfoToolBar _toolBar;
055:
056: private Resources _resources;
057:
058: public SessionInfoInternalFrame(ISession session,
059: Resources resources) {
060: // I18n[oracle.infoTitle=Oracle Session info for: {0}]
061: super (session, s_stringMgr.getString("oracle.infoTitle",
062: session.getTitle()));
063: _resources = resources;
064: createGUI(session);
065: }
066:
067: public SessionInfoPanel getDBOutputPanel() {
068: return _sessionInfoPanel;
069: }
070:
071: private void createGUI(ISession session) {
072:
073: addInternalFrameListener(new InternalFrameAdapter() {
074: public void internalFrameClosing(InternalFrameEvent e) {
075: SessionInfoInternalFrame.super .internalFrameClosing(
076: _toolBar.isStayOnTop(), _sessionInfoPanel
077: .getAutoRefreshPeriod());
078: _sessionInfoPanel.setAutoRefresh(false);
079: }
080: });
081:
082: Icon icon = _resources.getIcon(getClass(), "frameIcon"); //i18n
083: if (icon != null) {
084: setFrameIcon(icon);
085: }
086:
087: OracleInternalFrameCallback cb = new OracleInternalFrameCallback() {
088:
089: public void createPanelAndToolBar(boolean stayOnTop,
090: int autoRefeshPeriod) {
091: _sessionInfoPanel = new SessionInfoPanel(getSession(),
092: autoRefeshPeriod);
093: _toolBar = new SessionInfoToolBar(getSession(),
094: stayOnTop, autoRefeshPeriod);
095: JPanel contentPanel = new JPanel(new BorderLayout());
096: contentPanel.add(_toolBar, BorderLayout.NORTH);
097: contentPanel
098: .add(_sessionInfoPanel, BorderLayout.CENTER);
099: setContentPane(contentPanel);
100:
101: _sessionInfoPanel
102: .setAutoRefreshPeriod(autoRefeshPeriod);
103: }
104: };
105:
106: initFromPrefs(PREF_PART_INFO_FRAME, cb);
107: }
108:
109: /**
110: * The class representing the toolbar at the top of a session info internal frame
111: */
112: private class SessionInfoToolBar extends OracleToolBar {
113: SessionInfoToolBar(ISession session, boolean stayOnTop,
114: int autoRefeshPeriod) {
115: super ();
116: createGUI(session, stayOnTop, autoRefeshPeriod);
117: }
118:
119: private void createGUI(ISession session, boolean stayOnTop,
120: int autoRefeshPeriod) {
121: IApplication app = session.getApplication();
122: setUseRolloverButtons(true);
123: setFloatable(false);
124: add(new GetSessionInfoAction(app, _resources,
125: _sessionInfoPanel));
126:
127: addStayOnTop(stayOnTop);
128:
129: //Create checkbox for enabling auto refresh
130: // i18n[oracle.auotRefresh2=Enable auto refresh]
131: final JCheckBox autoRefresh = new JCheckBox(s_stringMgr
132: .getString("oracle.auotRefresh2"), false);
133: autoRefresh.addActionListener(new ActionListener() {
134: public void actionPerformed(ActionEvent e) {
135: _sessionInfoPanel.setAutoRefresh(autoRefresh
136: .isSelected());
137: }
138: });
139: add(autoRefresh);
140:
141: //Create spinner for update period
142: final SpinnerNumberModel model = new SpinnerNumberModel(
143: autoRefeshPeriod, 1, 60, 5);
144: final JSpinner refreshRate = new JSpinner(model);
145: refreshRate.addChangeListener(new ChangeListener() {
146: public void stateChanged(ChangeEvent e) {
147: _sessionInfoPanel.setAutoRefreshPeriod(model
148: .getNumber().intValue());
149: }
150: });
151: add(refreshRate);
152: // i18n[oracle.secons3=(seconds)]
153: add(new JLabel(s_stringMgr.getString("oracle.secons3")));
154: }
155: }
156: }
|