|Home | Screenshots | Download | Forums | Feature Requests | Bugs|
Creating a new detail tab in SQL Explorer
This tutorial shows you how you can add new tabs in the database detail view.
In the image below, you can see that the database node was selected in the database structure view. Now, when we look at the database detail view, all we can see is the 'Connection Info' tab.
Wouldn't it be nice if we could have a tab that shows the process list info for the database? This way, we wouldn't have to keep executing the 'show full processlist' SQL statement to get to this information.
Step 1: If you haven't done so already, open the manifest.mf file. The file is located in the META-INF folder of your fragment project.
Step 2: In the window that is presented, you'll need to locate and select the net.sourceforge.sqlexplorer.nodeDetailTab extension point.
Step 3: Now right click on the extension point and select New > detailtab.
Step 4: Here we enter the details of our extension point.
The name can be anything you like, but make sure
that the id starts with 'net.sourceforge.sqlexplorer.<yourdbname>.'
The database-product-name field is used by SQL Explorer to determine when a feature should be available. We wouldn't want this new process tab to show up when connected to an Oracle database, so we enter 'MySQL*' to match any MySQL database. To identify the correct name, you can look at the database connection info tab. SQL Explorer uses the Database Product Name attribute to do the matching. If you scroll back up to the very first image in this tutorial, you can see it lists MySQL.
Good, you found your way back down here. Let's continue.
Every node in the database structure view has got a type. This allows us to correctly identify when the detail page should be displayed. In this case, we only want to show the tab when the database node is selected, so we enter 'database'. If you want the tab to be available to more than one type, just add more types, seperated by commas.
Other types that are generally available are: catalog, schema, table, index, procedure, materialized_view, package, package_body, ... it really depends on what database you are using.
Now, let's click on the 'class' link to generate our class file.
Step 5: Normally, we wouldn't have to do anything here, but the default super class is AbstractTab. This class gives us a blank canvas to draw the detail page on and that's too much work in this case.
SQL Explorer currently provides 5 different base classes that can be extended to create a new tab:
Let's change AbstractTab to AbstractSQLTab. This will provide us with an easy to use tab that is preconfigured for handling SQL statements.
Step 6: We have our new class now, but before we change it, let's open the text.properties file and add some text variables that we can use in our detail tab. When you name your properties, I recommend always starting with <yourdbname>. , this will avoid conflicts with other extensions.
Step 7: In our new class, we override 3 methods of the parent AbstractSQL class.
getLabelText(): This method should return the value that will be displayed on the 'tab' of our new tab.
getSQL(): All we need to here is return the SQL statement we want to execute.
getStatusMessage(): This method returns the text that is displayed at the bottom of the tab.
Step 8: To test our application, we need to create a new run configuration. Select Run > Run... from the menu.
Highlight 'eclipse application', right click and select New.
Below you can see the result. A brand new tab when the database node is selected.
A slighty more difficult example
In the above example we used a simple sql statement. Using the AbstractSQLTab, it is also possible to use a SQL statement that requires parameters. All that is required in addition to all the steps followed above, is to override an additional method: getSQLParameters(). This method should return all the parameter values that are required for the SQL statement. An example is shown below.
Creating a source tab
To create source tabs in the detail view, you can extend the AbstractSQLSourceTab or the AbstractSourceTab. The AbstractSQLSourceTab provides you with a preconfigured SQL based source tab. The AbstractSourceTab requires a little more work, but also gives you more control.
Below you can see a sample extension point for an AbstractSQLSourceTab. In this particular case, the extension point is valid for many different node types.
The code itself turns out to be even shorter than for a regular resultset based tab like we described above.
And here is the result of the source tab: