Purpose
This tutorial shows you how to develop a custom editor for a node using a Java defined extensions to Oracle SQL Developer.
Time to Complete
Approximately 30 minutes
Oracle SQL Developer is a free graphical tool that enhances productivity and simplifies database development tasks. Using Oracle SQL Developer, users can browse database objects, run SQL statements, edit and debug PL/SQL statements and run reports, whether provided or created. Developed in Java, Oracle SQL Developer runs on Windows, Linux and the Mac OS X. This is a great advantage to the increasing numbers of developers using alternative platforms. Oracle SQL Developer is built on an extensible framework and, as such, is extensible itself.
Users can create basic XML extensions or more involved Java extensions to add utilities or other functionality to the product.
This tutorial demonstrates how to create a simple custom editor for a particular node type.
Prerequisites
Before you perform this tutorial, you should:
1.
Install Oracle Database 11g
Note: You can use any Oracle Database above 9.2.0.1
2.
Install Oracle SQL Developer 1.5.1.
Note: Oracle SQL Developer is available for download for FREE from OTN.
To install Oracle SQL Developer, unzip it into any directory on your machine.
3.
Install Java 1.5 or higher. A Java IDE is recommended.
4.
Install the latest version of ANT. JDeveloper or Eclipse Java IDEs will have this.
5.
Download and unzip java_simple_tablespace.zip into your working directory (i.e. d:\wkdir)
ftp://ftp.oracle.com/svrtech/outgoing/sqldev_sdk/java_simple_editor.zip
Customer Editor Hook
A customer editor class can be specified in the Editor XML file.
The DDLViewer class will be used as the editor for objects of MYTABLE objectType.
<?xml version="1.0" encoding="UTF-8"?>
<displays>
<display objectType="MYTABLE" editorClass="oracle.dbtools.simple_editor.editors.DDLViewer">
<name>SQL</name>
</display>
</displays>Customer Editor
package oracle.dbtools.simple_editor.editors;
import javax.swing.JComponent;
import oracle.dbtools.raptor.controls.IProgressFeedback;
import oracle.dbtools.raptor.oviewer.base.ViewerEditor;
import oracle.dbtools.raptor.utils.DBObject;
import oracle.dbtools.raptor.utils.Log;
import oracle.dbtools.raptor.utils.Translate;
import oracle.ide.ceditor.keymap.EditorFactory;
import oracle.ide.dialogs.ProgressException;
import oracle.ide.dialogs.ProgressRunnable;
import oracle.javatools.editor.BasicEditorPane;
public class DDLViewer extends ViewerEditor {
private BasicEditorPane m_basicEditorPane = null;
private DBObject m_dbObject = null;
@Override
protected JComponent createViewerUI() {
setCodeArea(EditorFactory.createIdeEditorPane());
getCodeArea().setEditable(false);
getCodeArea().setCaretPosition(0);
return getCodeArea();
}
@Override
protected void updateContent() {
m_dbObject = getViewerNode().getDBObject();
System.out.println(m_dbObject);
getCodeArea().setEditable(true);
final ProgressRunnable runner = new ProgressRunnable() {
protected void doCancel() {
super.doCancel();
getCodeArea().setText("--Generation of DDL was cancelled");
}
@Override
protected Object doWork() throws Exception {
return "DROP TABLE " + m_dbObject.getObjectName() + " CASCADE ;";
}
protected void finish(Object result) {
if (result != null)
getCodeArea().setText(result.toString());
else
getCodeArea().setText("--Generation of DDL was cancelled");
}
};
// provide feedback
final IProgressFeedback feedback = new IProgressFeedback() {
public void feedback(String s) {
Log.status(s);
}
};
// set the title
runner.setTitle(Translate.translate("Generating DDL...."));
// allow a cancel
runner.setCancelable(true);
// start the export
try {
runner.start(true);
} catch (ProgressException e) {
getCodeArea().setText("--Generation of DDL was cancelled");
}
getCodeArea().setEditable(false);
getCodeArea().setCaretPosition(0);
}
@Override
public Object getPrintable() {
return getCodeArea();
}
@Override
protected void cleanUp() {
}
protected void setCodeArea(BasicEditorPane basicEditorPane) {
m_basicEditorPane = basicEditorPane;
}
protected BasicEditorPane getCodeArea() {
return m_basicEditorPane;
}
}
Conclusion
Hopefully the above examples have outlined how to create your own customer editor for a node.
Please add to this wiki any notes you would like to share regarding SQL Developer extension framework.
Resources
File to build this sample extension
ftp://ftp.oracle.com/svrtech/outgoing/sqldev_sdk/java_simple_editor.zip
Similar, Oracle By Example paper for SQL Developer 1.2.1
http://www.oracle.com/technology/obe/sqldev_obe/extension/extensions.htmExtending SQL Developer 1.2.1
http://www.oracle.com/technology/oramag/oracle/07-jul/o47sql.html