001: package net.sourceforge.squirrel_sql.client.gui.session;
002:
003: /*
004: * Copyright (C) 2003-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: import java.io.File;
022:
023: import javax.swing.event.InternalFrameAdapter;
024: import javax.swing.event.InternalFrameEvent;
025:
026: import net.sourceforge.squirrel_sql.client.gui.BaseInternalFrame;
027: import net.sourceforge.squirrel_sql.client.session.ISession;
028: import net.sourceforge.squirrel_sql.fw.util.StringManager;
029: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
030:
031: /**
032: * Base functionality for Squirrels internal frames that are attached directly
033: * to a session.
034: *
035: * @author <A HREF="mailto:jmheight@users.sourceforge.net">Jason Height</A>
036: */
037: public class BaseSessionInternalFrame extends BaseInternalFrame {
038: protected ISession _session;
039: private String _titleWithoutFile = "";
040: private String _sqlFilePath = null;
041:
042: /** Internationalized strings for this class. */
043: private static final StringManager s_stringMgr = StringManagerFactory
044: .getStringManager(BaseSessionInternalFrame.class);
045:
046: /**
047: * Creates a non-resizable, non-closable, non-maximizable,
048: * non-iconifiable JInternalFrame with no title.
049: */
050: public BaseSessionInternalFrame(ISession session) {
051: super ();
052: setupSheet(session);
053: }
054:
055: /**
056: * Creates a non-closable, non-maximizable, non-iconifiable
057: * JInternalFrame with the specified title and with
058: * resizability specified.
059: *
060: * @param title Title for internal frame.
061: * @param resizable <TT>true</TT> if frame can be resized.
062: */
063: public BaseSessionInternalFrame(ISession session, String title,
064: boolean resizable) {
065: super (title, resizable);
066: _titleWithoutFile = title;
067: setupSheet(session);
068: }
069:
070: /**
071: * Creates a JInternalFrame with the specified title and with
072: * resizability, closability, maximizability and
073: * iconifability specified.
074: *
075: * @param title Title for internal frame.
076: * @param resizable <TT>true</TT> if frame can be resized.
077: * @param closeable <TT>true</TT> if frame can be closed.
078: * @param maximizable <TT>true</TT> if frame can be maximized.
079: * @param iconifiable <TT>true</TT> if frame can be iconified.
080: */
081: public BaseSessionInternalFrame(ISession session, String title,
082: boolean resizable, boolean closable, boolean maximizable,
083: boolean iconifiable) {
084: super (title, resizable, closable, maximizable, iconifiable);
085: _titleWithoutFile = title;
086: setupSheet(session);
087: }
088:
089: public void setTitle(String title) {
090: _titleWithoutFile = title;
091:
092: if (null == _sqlFilePath) {
093: super .setTitle(_titleWithoutFile);
094: } else {
095: // i18n[BaseSessionInternalFrame.title={0} SQL file: {1}]
096: String compositetitle = s_stringMgr.getString(
097: "BaseSessionInternalFrame.title", new String[] {
098: _titleWithoutFile, _sqlFilePath });
099: super .setTitle(compositetitle);
100: }
101: }
102:
103: private final void setupSheet(ISession session) {
104: if (session == null) {
105: throw new IllegalArgumentException("Null ISession passed");
106: }
107: _session = session;
108: _session.getApplication().getWindowManager()
109: .registerSessionSheet(this );
110: addInternalFrameListener(new SheetActivationListener());
111: }
112:
113: public ISession getSession() {
114: return _session;
115: }
116:
117: public void setSqlFile(File sqlFile) {
118: if (sqlFile == null) {
119: _sqlFilePath = null;
120: } else {
121: _sqlFilePath = sqlFile.getAbsolutePath();
122: }
123: setTitle(_titleWithoutFile);
124: }
125:
126: /**
127: * Toggles the "*" at the end of the filename based on the value of
128: * unsavedEdits. Just to provide the user with a visual hint that they may
129: * need to save their changes.
130: *
131: * @param unsavedEdits
132: */
133: public void setUnsavedEdits(boolean unsavedEdits) {
134: String title = super .getTitle();
135:
136: if (unsavedEdits && !title.endsWith("*")) {
137: super .setTitle(title + "*");
138: }
139: if (!unsavedEdits && title.endsWith("*")) {
140: super .setTitle(title.substring(0, title.length() - 1));
141: }
142: }
143:
144: public boolean hasSQLPanelAPI() {
145: return false;
146: }
147:
148: public void closeFrame(boolean withEvents) {
149: if (!_session.isfinishedLoading()) {
150: return;
151: }
152: if (withEvents) {
153: fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
154: }
155: dispose();
156:
157: if (withEvents) {
158: fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED);
159: }
160: }
161:
162: /**
163: * Sets the session behind this sheet to the active session when the
164: * frame is activated
165: */
166: private class SheetActivationListener extends InternalFrameAdapter {
167: public void internalFrameActivated(InternalFrameEvent e) {
168: _session
169: .setActiveSessionWindow((BaseSessionInternalFrame) e
170: .getInternalFrame());
171: _session.getApplication().getSessionManager()
172: .setActiveSession(_session);
173: }
174: }
175: }
|