001: package net.sourceforge.squirrel_sql.client.session.mainpanel;
002:
003: /*
004: * Copyright (C) 2007 Thorsten Mürell
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: */
020: import java.awt.BorderLayout;
021: import java.awt.Component;
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024: import java.sql.Statement;
025:
026: import javax.swing.JButton;
027: import javax.swing.JLayeredPane;
028: import javax.swing.JPanel;
029:
030: import net.sourceforge.squirrel_sql.client.IApplication;
031: import net.sourceforge.squirrel_sql.client.gui.BaseInternalFrame;
032: import net.sourceforge.squirrel_sql.client.session.CancelStatementThread;
033: import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
034: import net.sourceforge.squirrel_sql.fw.util.IMessageHandler;
035: import net.sourceforge.squirrel_sql.fw.util.StringManager;
036: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
037:
038: import com.jgoodies.forms.builder.PanelBuilder;
039: import com.jgoodies.forms.layout.CellConstraints;
040: import com.jgoodies.forms.layout.FormLayout;
041:
042: /**
043: * The dialog to ask the user to wait.
044: *
045: * @author Thorsten Mürell
046: */
047: public class PleaseWaitDialog extends BaseInternalFrame implements
048: ActionListener {
049: private static final long serialVersionUID = 8870277695490954084L;
050:
051: private static final StringManager stringMgr = StringManagerFactory
052: .getStringManager(PleaseWaitDialog.class);
053:
054: private JButton cancelButton;
055: private IMessageHandler messageHandler;
056: private Statement stmt;
057:
058: /**
059: * Creates the dialog.
060: *
061: * @param stmt The statement that is currently executed
062: * @param messageHandler The message handler to produce the log output to
063: */
064: public PleaseWaitDialog(Statement stmt,
065: IMessageHandler messageHandler) {
066: //i18n[PleaseWaitDialog.queryExecuting=Query is executing]
067: super (stringMgr.getString("PleaseWaitDialog.queryExecuting"),
068: true);
069: this .messageHandler = messageHandler;
070: this .stmt = stmt;
071:
072: GUIUtils.makeToolWindow(this , true);
073:
074: final JPanel content = new JPanel(new BorderLayout());
075: content.add(createMainPanel(), BorderLayout.CENTER);
076: setContentPane(content);
077: pack();
078: }
079:
080: private Component createMainPanel() {
081:
082: final FormLayout layout = new FormLayout(
083: // Columns
084: "center:pref",
085: // Rows
086: "pref, 6dlu, pref, 6dlu, pref, 6dlu, pref");
087:
088: PanelBuilder builder = new PanelBuilder(layout);
089: CellConstraints cc = new CellConstraints();
090: builder.setDefaultDialogBorder();
091:
092: int y = 1;
093: builder.addSeparator(title, cc.xywh(1, y, 1, 1));
094:
095: y += 2;
096: //i18n[PleaseWaitDialog.pleaseWait=Please wait while the query is executed]
097: builder.addLabel(stringMgr
098: .getString("PleaseWaitDialog.pleaseWait"), cc.xy(1, y));
099:
100: y += 2;
101: builder.addSeparator("", cc.xywh(1, y, 1, 1));
102:
103: //i18n[PleaseWaitDialog.cancel=Cancel]
104: cancelButton = new JButton(stringMgr
105: .getString("PleaseWaitDialog.cancel"));
106: cancelButton.addActionListener(this );
107:
108: y += 2;
109: builder.add(cancelButton, cc.xywh(1, y, 1, 1));
110:
111: return builder.getPanel();
112: }
113:
114: public void actionPerformed(ActionEvent e) {
115: if (stmt != null) {
116: CancelStatementThread cst = new CancelStatementThread(stmt,
117: messageHandler);
118: cst.tryCancel();
119: }
120: }
121:
122: /**
123: * Shows the dialog in front of all windows and centered.
124: *
125: * @param app The application to show the window in
126: */
127: public void showDialog(IApplication app) {
128: app.getMainFrame().addInternalFrame(this , true);
129: this .moveToFront();
130: this .setLayer(JLayeredPane.MODAL_LAYER);
131: GUIUtils.centerWithinDesktop(this );
132: this .setVisible(true);
133: }
134: }
|