Hi,
I made a small addition to the SQL Panel. This addition allows the user to
import files from their local file system. It comes handy when current users
have stored huge sql scripts in their local file system and want to directly
trigger instead of having to open /copy/paste the contents of such sql
scripts in the ISQL panel of Squirrel.
Below is the code. For sections I added I have put them inside
//start.sameer
....my code
//end.sameer
package net.sourceforge.squirrel_sql.fw.gui;
/*
* Copyright (C) 2001 Colin Bell
* co...@us...
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import net.sourceforge.squirrel_sql.fw.gui.BasePopupMenu;
import net.sourceforge.squirrel_sql.fw.gui.action.BaseAction;
public class TextPopupMenu extends BasePopupMenu {
private JTextComponent _comp;
private CutAction _cut = new CutAction();
private CopyAction _copy = new CopyAction();
private PasteAction _paste = new PasteAction();
private ClearAction _clear = new ClearAction();
private SelectAllAction _select = new SelectAllAction();
//start.sameer
private OpenAction _open = new OpenAction();
//end.sameer
public TextPopupMenu() {
super();
//start.sameer
add(_open);
//end.sameer
add(_cut);
add(_copy);
add(_paste);
addSeparator();
add(_clear);
addSeparator();
add(_select);
}
public void setTextComponent(JTextComponent value) {
_comp = value;
}
/**
* Show the menu.
*/
public void show(Component invoker, int x, int y) {
updateActions();
super.show(invoker, x, y);
}
public void show(MouseEvent evt) {
updateActions();
super.show(evt);
}
protected void updateActions() {
final boolean isEditable = _comp != null &&
_comp.isEditable();
_cut.setEnabled(isEditable);
_paste.setEnabled(isEditable);
}
private class ClearAction extends BaseAction {
ClearAction() {
super("Clear");
}
public void actionPerformed(ActionEvent evt) {
if (_comp != null) {
try {
Document doc = _comp.getDocument();
doc.remove(0, doc.getLength());
} catch (BadLocationException ignore) {
}
}
}
}
private class CutAction extends BaseAction {
CutAction() {
super("Cut");
}
public void actionPerformed(ActionEvent evt) {
if (_comp != null) {
_comp.cut();
}
}
}
private class CopyAction extends BaseAction {
CopyAction() {
super("Copy");
}
public void actionPerformed(ActionEvent evt) {
if (_comp != null) {
_comp.copy();
}
}
}
private class PasteAction extends BaseAction {
PasteAction() {
super("Paste");
}
public void actionPerformed(ActionEvent evt) {
if (_comp != null) {
_comp.paste();
}
}
}
private class SelectAllAction extends BaseAction {
SelectAllAction() {
super("Select All");
}
public void actionPerformed(ActionEvent evt) {
if (_comp != null) {
_comp.selectAll();
}
}
}
//start.sameer
private class OpenAction extends BaseAction {
OpenAction() {
super("OpenSQLScript");
}
public void actionPerformed(ActionEvent evt)
{
javax.swing.text.Document sqlDocument =
_comp.getDocument();
try
{
sqlDocument.remove(0,
sqlDocument.getLength());
}
catch (BadLocationException ignore)
{
}
java.awt.Component parent = _comp.getParent();
while(!(parent instanceof java.awt.Frame) &&
parent!=null)
{
parent = parent.getParent();
}
if(parent!=null)
{
// java.awt.FileDialog fileDialog = new
java.awt.FileDialog((java.awt.Frame)parent,"Open SQL File" );
//fileDialog.show();
javax.swing.JFileChooser chooseSQLFile = new
javax.swing.JFileChooser();
int returnVal = chooseSQLFile.showOpenDialog(parent);
//chooseSQLFile.setFileSelectionMode(javax.swing.JFileChooser.FILES_ONLY);
if(returnVal == javax.swing.JFileChooser.APPROVE_OPTION)
{
java.io.File selectedFile =
chooseSQLFile.getSelectedFile();
try
{
if(selectedFile.isFile())
{
java.io.BufferedReader buffReader = new
java.io.BufferedReader
(new
java.io.FileReader(selectedFile));
String input=buffReader.readLine();
StringBuffer sqlCommand = new StringBuffer("");
while (input != null)
{
input=input+"\n";
sqlCommand.append(input);
input = buffReader.readLine();
}
sqlDocument.insertString(0,sqlCommand.toString(),null);
SelectAllAction selectAllAction = new
SelectAllAction();
selectAllAction.actionPerformed(new
ActionEvent(_comp,0,""));
}
}
catch(Exception e)
{
}
}
}
else
{
}
}
}
//end.sameer
}
-----Original Message-----
From: squ...@li...
[mailto:squ...@li...]
Sent: Saturday, December 07, 2002 3:16 PM
To: squ...@li...
Subject: Squirrel-sql-develop digest, Vol 1 #94 - 2 msgs
Send Squirrel-sql-develop mailing list submissions to
squ...@li...
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.sourceforge.net/lists/listinfo/squirrel-sql-develop
or, via email, send a message with subject or body 'help' to
squ...@li...
You can reach the person managing the list at
squ...@li...
When replying, please edit your Subject line so it is more specific than
"Re: Contents of Squirrel-sql-develop digest..."
Today's Topics:
1. Re: Re: [Fwd: Re: CVS Hierarchy [Fwd: Re: help with eclipse?]] (Colin
Bell)
2. Re: Hello All / Javadoc (Colin Bell)
--__--__--
Message: 1
From: Colin Bell <col...@bi...>
To: squirrel-sql-develop <squ...@li...>
Subject: Re: [Squirrel-sql-develop] Re: [Fwd: Re: CVS Hierarchy [Fwd: Re:
help with eclipse?]]
Date: Sat, 7 Dec 2002 09:45:05 +1100
On Thu, 5 Dec 2002 03:59, Johnathan James wrote:
> Glenn, et al..
>
> Thanks for the instructions!
>
> I agree its possible to make Eclipse recognize where to get the source
> from, but this method involves setting IDE-wide properties [*1], which
> means it effects every project that would be loaded afterwards.=20
You don't have to change the defaults, you could simply add a src directo=
ry to=20 the individual project.
>
> Maybe I'm missing something, though.. is there a reason that the code
> i=
s
> not in CVS in package order (other than its always been done that
> way)? Would it not be easier to have it that way already rather than
> re-creating environments and so forth?
The thing to remember is that its really two projects. the fw source whic=
h=20 ends ups as fw.jar) is the beginnings of a framework that could be used
f= or=20 other projects, not just squirrel, and shouldn't "know" about any
of the=20 actual squirrel classes and the actual squirrel code which ends up
in=20 squirrel-sql.jar
The whole build process is going to be revamped very shortly based on wor=
k=20 Patrick Lacson has done. For an idea of what this is going to be like
you= can=20 take a look at the module squirrel in CVS and look back through
Patricks=20 postings to the dev list.
--=20
Colin Bell
http://squirrel-sql.sf.net
--__--__--
Message: 2
From: Colin Bell <col...@bi...>
To: squ...@li...
Subject: Re: [Squirrel-sql-develop] Hello All / Javadoc
Date: Sat, 7 Dec 2002 08:41:05 +1100
On Wed, 27 Nov 2002 14:51, Johnathan James wrote:
> ------------------------------------
>
> <<< This should be added to the 'help' target:
>
> <echo message=3D" javadoc: Compiles the javadoc from the app/
> =
and
> fw/ sources."/>
> <echo message=3D""/>
>
> <<< This is the new javadoc target.
>
> <!--
>
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Build the JavaDoc
> No parameters
>
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> -->
>
> <target name=3D"javadoc">
> <mkdir dir=3D"${basedir}/doc/javadoc"/>
> <javadoc packagenames=3D"net.sourceforge.squirrel_sql.*"
> sourcepath=3D"${basedir}/app/src;${basedir}/fw/src"
> destdir=3D"${basedir}/doc/javadoc">
> </javadoc>
> </target>
>
>
>
Thanks Johnathan, this has been added to the build.xml
--=20
Colin Bell
http://squirrel-sql.sf.net
--__--__--
_______________________________________________
Squirrel-sql-develop mailing list Squ...@li...
https://lists.sourceforge.net/lists/listinfo/squirrel-sql-develop
End of Squirrel-sql-develop Digest
|