Entrance Extensions and the X Menu
Tod Landis
March 31, 2008
You can now write Entrance extensions using Java and add them to the Entrance X Menu. Shell commands, Applescript, PHP scripts, and so on, can also be wrapped as EntranceExtensoins.
EntranceExtension
One way to write a Java extension is by implementing the EntranceExtension interface, which consists of a single method:
package com.dbentrance.entrance.tools;
import com.dbentrance.entrance.JavaClient;
public interface EntranceExtension {
public void go(JavaClient client);
}
For example, here is our “hello world”:
// creeate a query pane containing "Hello World!"
public class HelloWorldX implements EntranceExtension {
public void go(JavaClient client) {
QueryPane qPane = new QueryPane(client, "-- Hello World!");
client.addEntrancePane(qPane, "Hello");
}
}
Installing extensions
Users install extensions using the X Menu editor, or you can add extensions programmatically. To get the feel of this, open the menu editor by selecting X Menu | Edit this menu... , and then add HelloWorldX:
HelloWorldX comes bundled with releases after 1.2.43, so when you click the Test button, it will actually run. You should see a new query tab pop open in the Entrance window:
Sample extensions
A number of other extensions are now built into Entrance releases, and their sources are in the “extensions” directory in the Community source download.. Any of them can be added in the same way as HelloWorldX:
CopyColumnNamesX put column names from the current table on the clipboard
CopyQuotedX copy the current query as a quoted Java string
CopyThisColumnX copy values from the current column (eg. for pasting
in a BCC field)
DisplayRowX display column names and field values from the current row
ContextX display a few of things an extension can see
GetSyntaxX this became the HelpMenu syntax tool
MailingLabelX bare bones mailing labels
OpenURLX open the currently selected text of table cell as a URL
(also scans table cells to thre right looking for a URL)
CheckLogsX shows how to connect as an FTP client, download files,
then run a query to import them (something similar
used daily here)
Building and installing extensions
The source for the sample extensions is in source code releases, in the top level “extensions” directory. Any Java file in the extensions directory is automatically included n the jar when you do the default ant build.
You can also add extensions to the IDE or Community versions by putting them a jar file named “entrancex.jar” and copying it to the Entrance “lib” directory in the directory containing entrance.jar.
Adding X Menu items programmatically
If you are careful (!), you can add menu items to the X Menu programmatically. The X Menu is defined by the text file xmenu.menu, found in the Entrance system directory. The file is structured like this:
<xmenu>
<xaction>
<itemName value="Copy quoted string"/>
<type value="Entrance Extension"/>
<topstring value="CopyQuotedX"/>
<middlestring value=""/>
<bottomstring value=""/>
<key value="Q"/>
<modifier value="Ctrl"/>
<access value=""/>
</xaction>
<xaction>
... more xactioss...
</xmenu>
Specify your class name for the “topstring” value, and the text you want displayed in the X Menu for the “itemName” value.
Note: The menu format includes some values that are not yet used: “middlesttring” and “bottomstring” will be used as new extensions types are added, and “access” will be used to specify accessibility strings.
EntranceDialog
EntranceDialog is the base class for most dialogs in the program. You can also implement extensions by extending EntranceDialog and specifying type “Entrance Dialog”, however this approach is not recommended.
Earlier posts:
Copyright (c) 2008 Tod Landis, All Rights Reserved
MySQL is a registered trademark of MySQL AB in the United States, the European Union and other countries.