Sue had blogged on how to get an extension started in jdev in 10 steps. In the presentation at OOW, I showed how little code it could take to start an extension and said we'd get a skeleton out of how to start one yourself. Well here's the Skeleton and here's a zip of it. With this skeleton, there's 3 steps to getting started with an extension.


Step 1: Download the zip.

Step 2: Got to [unziped location]/etc and update the contents of the build.properties. Here's the content of the file and the only line that has to be updated is the sdev.home which points to your install of SQL Developer 1.1


build.dir=built

sdev.home=/Users/klrice/Documents/workspace/raptor_trunk/ide

extension.id=sample.skeleton

extension.name=Skeleton Sample

extension.author=Kris Rice

extension.author.url=http://krisrice.blogspot.com

extension.descr=A Skeleton of an extension

update.url=http://esdev.sf.net


Step 3: Run ant deploy


Well it's done and deployed to your local copy of sqldeveloper. Wasn't that easy and painless? :-) Take a look at the Help->About and the Extensions tab will show the name from Step2.




This added 2 things. First an ls command when a script is run ( F5 ). Second a Reconnect on the connection. Here's a screen capture of both.




In case you didn't look in the source of the extension, it adds 2 things. First just like in the OOW presentation I mentioned there's a new hook in the scripting engine which allows custom command to be added. In this case we add ls as a command here. This extends the abstract class CommandListener which has a few methods:


public abstract class CommandListener {

public abstract boolean handleEvent(Connection conn, ScriptRunnerContext ctx, SQLCommand cmd);

public abstract void beginEvent(Connection conn, ScriptRunnerContext ctx, SQLCommand cmd);

public abstract void endEvent(Connection conn, ScriptRunnerContext ctx, SQLCommand cmd);

public void beginScript(Connection conn, ScriptRunnerContext ctx, SQLCommand[] cmd){
}

public void endScript(Connection conn, ScriptRunnerContext ctx, SQLCommand[] cmd){
}
}


}



By implementing and registering a command listener, an extension writer has the ability to add new command and listen in on when commands are run as scripts. Hopefully the names on the methods are pretty simple. The beginScript is before anything is run and endScript is after everything. The other 3 are before each command, after each command and the command itself.


So in this case I only implemented the handleEvent so I could process the ls then finally return a true to say I did something.


public boolean handleEvent(Connection conn, ScriptRunnerContext ctx, SQLCommand cmd) {
44 ResultSet rs = null;
45 if (cmd.getSql().equals("ls")) {
....
68 return true;
69 }
70 return false;
71 }


The second extension for the Reconnect has been explained here and here. What's new in this example is that the xml references a java class: className="sample.ReconnectAction" . This class extends another abstract here :


public abstract class AbstractMenuAction {
public abstract void launch();
public abstract void setArgs(String args);
}


In this launch, all we did was get a handle to the connection which will cause the framework to reconnect if the connection was dropped and put a status out to the toolbar.

  // get the connection 
// this will force a reconnect
getDBObject().getDatabase().getConnection();
// status basr entry
Ide.getStatusBar().setText("Reconnected.");


Now that everyone knows how to get started with extension, we should see lots of cool stuff. When you do create an extension drop Sue or myself a note and we'll add it to the list of known extensions.