/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/action/CloseAllSQLResultWindowsAction.java

https://github.com/igorhvr/squirrel-sql · Java · 76 lines · 35 code · 3 blank · 38 comment · 2 complexity · 02bda43aefe29e6f5439ac9b8d787aa3 MD5 · raw file

  1. package net.sourceforge.squirrel_sql.client.session.action;
  2. /*
  3. * Copyright (C) 2001-2004 Colin Bell
  4. * colbell@users.sourceforge.net
  5. *
  6. * Modifications Copyright (C) 2003-2004 Jason Height
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. import java.awt.event.ActionEvent;
  23. import net.sourceforge.squirrel_sql.fw.gui.CursorChanger;
  24. import net.sourceforge.squirrel_sql.client.IApplication;
  25. import net.sourceforge.squirrel_sql.client.gui.session.SessionInternalFrame;
  26. import net.sourceforge.squirrel_sql.client.gui.session.SQLInternalFrame;
  27. import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
  28. import net.sourceforge.squirrel_sql.client.session.ISQLPanelAPI;
  29. import net.sourceforge.squirrel_sql.client.session.ISession;
  30. /**
  31. * This <CODE>Action</CODE> allows the user to close all the SQL
  32. * result windows for the current session.
  33. *
  34. * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
  35. */
  36. public class CloseAllSQLResultWindowsAction extends SquirrelAction
  37. {
  38. /**
  39. * Ctor.
  40. *
  41. * @param app Application API.
  42. */
  43. public CloseAllSQLResultWindowsAction(IApplication app)
  44. {
  45. super(app);
  46. }
  47. /**
  48. * Perform this action. Uses the <TT>CloseAllSQLResultWindowsCommand</TT>.
  49. *
  50. * @param evt The current event.
  51. */
  52. public void actionPerformed(ActionEvent evt)
  53. {
  54. IApplication app = getApplication();
  55. CursorChanger cursorChg = new CursorChanger(app.getMainFrame());
  56. cursorChg.show();
  57. try
  58. {
  59. ISession activeSession = getApplication().getSessionManager().getActiveSession();
  60. if( activeSession.getActiveSessionWindow() instanceof SessionInternalFrame
  61. || activeSession.getActiveSessionWindow() instanceof SQLInternalFrame)
  62. {
  63. // Can't work with ISessionAction because if a result window is on top
  64. // the session in a ISessionAction is null.
  65. new CloseAllSQLResultWindowsCommand(activeSession.getSQLPanelAPIOfActiveSessionWindow()).execute();
  66. }
  67. }
  68. finally
  69. {
  70. cursorChg.restore();
  71. }
  72. }
  73. }