View Javadoc

1   package com.explosion.datastream.exql.gui;
2   
3   /* =============================================================================
4    *       
5    *     Copyright 2004 Stephen Cowx
6    *
7    *     Licensed under the Apache License, Version 2.0 (the "License");
8    *     you may not use this file except in compliance with the License.
9    *     You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *     Unless required by applicable law or agreed to in writing, software
14   *     distributed under the License is distributed on an "AS IS" BASIS,
15   *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *     See the License for the specific language governing permissions and
17   *     limitations under the License.
18   * 
19   * =============================================================================
20   */
21  
22  import java.awt.BorderLayout;
23  import java.awt.Font;
24  import javax.swing.JButton;
25  import javax.swing.JPanel;
26  import com.explosion.datastream.exql.EXQLConstants;
27  import com.explosion.datastream.exql.EXQLModuleManager;
28  import com.explosion.expf.Application;
29  import com.explosion.expf.ExpFrame;
30  import com.explosion.expfmodules.rdbmsconn.dbom.DBEntity;
31  import com.explosion.expfmodules.rdbmsconn.dbom.utils.SQLFormatter;
32  import com.explosion.expfmodules.texteditor.LineNumberTextEditor;
33  import com.explosion.utilities.exception.ExceptionManagerFactory;
34  
35  /***
36   * @author Steve.Cowx
37   *  Created on Dec 30, 2003
38   */
39  public class SQLPopup extends JPanel 
40  {
41  	  private LineNumberTextEditor textComponent;
42  	  private JPanel buttonPanel;
43  	  private JButton okButton;
44  	  private DBEntity dbed;
45  
46  	  
47  	  /*** Creates new form GenericExceptionDisplayDialog */
48  	  public SQLPopup(DBEntity dbed)
49  	  {
50  		try
51  		{
52  		  this.dbed = dbed;
53  		  textComponent = new LineNumberTextEditor(this, "SQL>", true);
54  		  init();
55  		}
56  		catch (Exception e)
57  		{
58  		  ExceptionManagerFactory.getExceptionManager().manageException(e,"Exception caught while initialising SQLPopup");
59  		}
60  	  }
61  
62  	  private void init() throws Exception
63  	  {
64  		textComponent.getMarginTextArea().setFont((Font)EXQLModuleManager.instance().getPreference(EXQLConstants.COMMANDER_FONT).getValue());
65  		textComponent.getEditorTextComponent().setFont((Font)EXQLModuleManager.instance().getPreference(EXQLConstants.COMMANDER_FONT).getValue());
66  		textComponent.getEditorTextComponent().setText(SQLFormatter.format(dbed.getDBEntityBuffer().getFetchSQL()));
67  		textComponent.getEditorTextComponent().setCaretPosition(0);
68  		
69  		SQLTextActionsListener listener = new SQLTextActionsListener(textComponent.getEditorTextComponent(),this);
70  				
71  		buttonPanel = new JPanel();
72  		okButton = new JButton("Ok");
73  		
74  		buttonPanel.add(okButton);
75  		
76  		this.setLayout(new BorderLayout());
77  		this.add(textComponent, java.awt.BorderLayout.CENTER);
78  		this.add(buttonPanel, java.awt.BorderLayout.SOUTH);
79  		validate();
80  
81  		okButton.addActionListener(new java.awt.event.ActionListener()
82  		{
83  		  public void actionPerformed(java.awt.event.ActionEvent evt)
84  		  {
85  			okButtonActionPerformed(evt);
86  		  }
87  		});
88  		
89  		setVisible(true);
90  	  }
91  	  
92  	  private void okButtonActionPerformed(java.awt.event.ActionEvent evt)
93  	  {
94  		//dbed.getDBEntityBuffer().setFetchSQL(textComponent.getEditorTextComponent().getText().trim());
95  		close();		
96  	  }
97  	  
98        private void close()
99        {
100 		try {
101 			  	((ExpFrame)Application.getApplicationFrame()).closeDialogWithComponent(this);
102                 //This change was made as a reslt of bug 1010044, I no longer want it to be refreshable 
103 		        //ActionEvent acev = new ActionEvent(this,0,EXQLConstants.MENU_REFRESH);
104                 //((ExpFrame)Application.getApplicationFrame()).getListener().actionPerformed(acev);
105 			} catch (Exception e) {
106 				ExceptionManagerFactory.getExceptionManager().manageException(e,"Exception caught while closing window.");
107 			}
108       }
109 }