Thursday, February 16, 2006

Forgotten datatypes part 2....

It was just pointed out to me that many people many not know how to get the code for a custom renderer into an extension that SQL Developer will use. So here's the rest of the steps to getting your custom column renderer into SQL Developer.


The first thing which will be needed is an extensio.xml file to describe the extension.


<extension xmlns="http://jcp.org/jsr/198/extension-manifest"
id="net.jokr.columnrenderer"
version="0.0.0.1"
esdk-version="1.0">
<name>Example Custom Column Renderer</name>
<owner>Kris Rice</owner>
<hooks>
<jdeveloper-hook xmlns="http://xmlns.oracle.com/jdeveloper/1013/extension">
<addins>
<addin>CustomColRendererAddin</addin>
</addins>
</jdeveloper-hook>
<feature-hook>
<description>Example Column Display</description>
<optional>true</optional>
</feature-hook>
</hooks>
</extension>


Now to stich it all together, here's the ant build file I used for this example. There's a few properties to setup the location of SQL Developer which will of course have to be changed per install. The extension.xml from above is use in the jar which created. The final step to getting this all to work is simply putting the produced jar file into the /jdev/extensions folder.


<project name="Custom Columns Renderer" default="deploy">
<target name="init">
<property name="sdev.home" value="../raptor/ide/" />
<property name="extension.filename" value="net.jokr.xmlcolumnrenderer.jar" />
<property name="built" value="build" />

<path id="compile.classpath">
<fileset dir="${sdev.home}/ide/lib" includes="*.jar" />
<fileset dir="${sdev.home}/jdbc/lib" includes="*.jar" />
<fileset dir="${sdev.home}/jdev/extensions" includes="oracle.onlinedb.jar" />
<fileset dir="${sdev.home}/jdev/extensions" includes="oracle.sqldeveloper.jar" />
<fileset dir="${sdev.home}/jdev/lib" includes="jdev.jar, ojc.jar, jdev-patch.jar" />
</path>
</target>

<target name="compile" depends="init"
description="Compile java code">
<delete dir="${built}/classes" />
<mkdir dir="${built}/classes" />
<javac classpathref="compile.classpath" destdir="${built}/classes"
source="1.5" target="1.5" debug="true" includeAntRuntime="false">
<src path="src" />
</javac>
</target>

<target name="jar" depends="compile"
description="Create the extension jar">

<jar basedir="${built}/classes"
destfile="${built}/${extension.filename}">
<zipfileset prefix="META-INF" dir="." includes="extension.xml" />
</jar>
</target>

<target name="deploy" depends="jar"
description="Deploy into the ide extensions directory">
<copy file="${built}/${extension.filename}"
tofile="${sdev.home}/jdev/extensions/${extension.filename}" />
</target>

</project>

Wednesday, February 15, 2006

Forgotten datatypes

After seeing the Georaptor project, I figured SQL Developer could use a method for rendering custom datatypes. Here's a quick example of how this is now possible in EA4.

The first thing is to make a class which is an Addin which registers the custom renderer.


import oracle.dbtools.raptor.controls.cellrenderers.CellRenderingFactory;
import oracle.ide.Addin;
import oracle.sql.CLOB;

public class CustomColRendererAddin implements Addin{

public void initialize() {
// register the custom renderer
CellRenderingFactory.registerCellRenderer(CLOB.class, new CLOBRenderer());

}
}


Next the actual renderer. This is a very simple example. The ICellRenderer interface has 2 methods on it. The getComponent is called first. If nothing is returned from any of the registered addins the getText is called next and will just be used in the standard component.



import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import oracle.dbtools.raptor.controls.cellrenderers.ICellRenderer;
import oracle.sql.CLOB;

public class CLOBRenderer implements ICellRenderer {

public String getText(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
// if getComponent returns null
// get text will be called to get the text for to be placed in the
// default component
return null;
}

public Component getComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
//
Component ret = null;
CLOB lob = (CLOB) value;
try {
JLabel l = new JLabel(lob.getSubString(1,20));
// the only real difference over the base renderer
// is the added tooltip
l.setToolTipText(lob.getSubString(1,1000));
ret = l;
} catch (Exception e) {
e.printStackTrace();
}
return ret;
}

}


The end results....

clob_tt.png

Disqus for Kris' Blog