001: package net.sourceforge.squirrel_sql.client.gui.session;
002:
003: /*
004: * Copyright (C) 2001-2004 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * Modifications Copyright (C) 2003-2004 Jason Height
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022: */
023: import java.awt.Component;
024: import java.awt.Window;
025: import java.awt.event.FocusEvent;
026: import java.beans.PropertyVetoException;
027:
028: import javax.swing.Action;
029: import javax.swing.Icon;
030: import javax.swing.SwingUtilities;
031: import javax.swing.event.InternalFrameAdapter;
032: import javax.swing.event.InternalFrameEvent;
033:
034: import net.sourceforge.squirrel_sql.client.IApplication;
035: import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
036: import net.sourceforge.squirrel_sql.client.session.IObjectTreeInternalFrame;
037: import net.sourceforge.squirrel_sql.client.session.ISQLInternalFrame;
038: import net.sourceforge.squirrel_sql.client.session.ISQLPanelAPI;
039: import net.sourceforge.squirrel_sql.client.session.ISession;
040: import net.sourceforge.squirrel_sql.client.Version;
041:
042: public class SessionInternalFrame extends BaseSessionInternalFrame
043: implements ISQLInternalFrame, IObjectTreeInternalFrame {
044: static final long serialVersionUID = 6961615570741567740L;
045:
046: /** Application API. */
047: private final IApplication _app;
048:
049: private SessionPanel _sessionPanel;
050:
051: public SessionInternalFrame(ISession session) {
052: super (session, session.getTitle(), true, true, true, true);
053: _app = session.getApplication();
054: setVisible(false);
055: createGUI(session);
056: }
057:
058: public SessionPanel getSessionPanel() {
059: return _sessionPanel;
060: }
061:
062: public ISQLPanelAPI getSQLPanelAPI() {
063: return _sessionPanel.getSQLPaneAPI();
064: }
065:
066: public IObjectTreeAPI getObjectTreeAPI() {
067: return _sessionPanel.getObjectTreePanel();
068: }
069:
070: /**
071: * Add the passed action to the toolbar of the sessions main window.
072: *
073: * @param action Action to be added.
074: */
075: void addToToolbar(Action action) {
076: _sessionPanel.addToToolbar(action);
077: }
078:
079: public void addSeparatorToToolbar() {
080: _sessionPanel.addSeparatorToToolbar();
081: }
082:
083: public void addToToolsPopUp(String selectionString, Action action) {
084: _sessionPanel.addToToolsPopUp(selectionString, action);
085: }
086:
087: public void setSelected(boolean selected)
088: throws PropertyVetoException {
089: super .setSelected(selected);
090:
091: // Without this when using alt left/right to move
092: // between sessions the focus is left in the SQL
093: // entry area of the previous session.
094: // TODO: Once Java 5 is minimum supported
095: // we don't need this,
096: if (Version.isJDK14()) {
097: if (selected) {
098: SwingUtilities.invokeLater(new Runnable() {
099: public void run() {
100: _sessionPanel.getSQLEntryPanel().requestFocus();
101: }
102: });
103: }
104: }
105: }
106:
107: private void createGUI(final ISession session) {
108: setVisible(false);
109: setDefaultCloseOperation(SessionInternalFrame.DO_NOTHING_ON_CLOSE);
110: final IApplication app = session.getApplication();
111: Icon icon = app.getResources().getIcon(getClass(), "frameIcon"); //i18n
112: if (icon != null) {
113: setFrameIcon(icon);
114: }
115:
116: addInternalFrameListener(new InternalFrameAdapter() {
117: // This is to fix a problem with the JDK (up to version 1.3)
118: // where focus events were not generated correctly. The sympton
119: // is being unable to key into the text entry field unless you click
120: // elsewhere after focus is gained by the internal frame.
121: // See bug ID 4309079 on the JavaSoft bug parade (plus others).
122: public void internalFrameActivated(InternalFrameEvent evt) {
123: Window window = SwingUtilities
124: .windowForComponent(SessionInternalFrame.this ._sessionPanel
125: .getSQLPanel());
126: Component focusOwner = (window != null) ? window
127: .getFocusOwner() : null;
128: if (focusOwner != null) {
129: FocusEvent lost = new FocusEvent(focusOwner,
130: FocusEvent.FOCUS_LOST);
131: FocusEvent gained = new FocusEvent(focusOwner,
132: FocusEvent.FOCUS_GAINED);
133: window.dispatchEvent(lost);
134: window.dispatchEvent(gained);
135: window.dispatchEvent(lost);
136: focusOwner.requestFocus();
137: }
138: }
139:
140: public void internalFrameClosing(InternalFrameEvent evt) {
141: if (!session.isfinishedLoading()) {
142: return;
143: }
144: final ISession mySession = getSession();
145: if (mySession != null) {
146: _sessionPanel.sessionWindowClosing();
147: _app.getSessionManager().closeSession(mySession);
148: }
149: }
150: });
151:
152: _sessionPanel = new SessionPanel(session);
153: setContentPane(_sessionPanel);
154: validate();
155: }
156:
157: public void requestFocus() {
158: _sessionPanel.getSQLEntryPanel().requestFocus();
159: }
160:
161: public boolean hasSQLPanelAPI() {
162: return true;
163: }
164:
165: }
|