Netbeans actions toolbar with local lookup context

This article talks about Netbeans and an action toolbar that is sensitive to a local selection lookup context. Actually, global selection context sensitive actions is powerful mechanism with a subtle limitation: everything happens globally. It is no use for a local actions menu or toolbar sensitive to a limited selection context restricted to a JPanel or TopComponent. Not surprisingly, the Netbeans Java IDE itself reinvents the wheel each time this requirement arises, for example, on the ‘variables’ and ‘breakpoint’ windows.

Simplest JTable icon cell renderer ever

While there are many examples of JTable cell renderers spread on the Internet, they lack a clear understanding about how they were proposed to work. This article presents and explains a minimal and correct cell renderer, extending the default cell renderer as supposed by the Java API. The example explains how to display icons instead of text.

Originally published at https://techtavern.wordpress.com.

For the hurried, first the code:


public class EnumIconCellRenderer extends DefaultTableCellRenderer {

private final Map<!--?, ImageIcon--> icones;

  public EnumIconCellRenderer(final Map<!--?, ImageIcon--> icones) {
    // Initialize data used to render cells.
    this.icones = icones;

    // Set properties that never change.
    this.setHorizontalAlignment(JLabel.CENTER);
    this.setVerticalAlignment(JLabel.CENTER);
    this.setText(null);
  }

  @Override
  protected void setValue(Object value) {
    // Set properties that change on individual cells.
    this.setIcon(icones.get(value));
  }
}

A cell renderer works like a rubber-stamp for each cell in the table. The renders uses a Swing component to draw the first cell, changes the contents of that cell renderer, and for each following row shifts the origin of the component to the new location, then re-draws it. The default cell renderer uses the convenient JLabel to stamp a potentially inconvenient toString() representation of data objects. Note that getTableCellRendererComponent() returns itself (the JLabel), but properly configured for an individual cell. Therefore, setting properties of the renderes itself actually configures the component returned by getTableCellRendererComponent().

MySQL, Scheduled Events and Amazon RDS

This article explains how to enable SQL database scheduled events for the Amazon Relational Database Service (RDS). By default, Amazon does not allow one to create (in other words, to schedule) events. Events are SQL code intended to execute periodically or in future. The solution is quite similar my last article. One needs to provide the ‘event_scheduler’ parameter set to “ON” or “1”. Parameters are set by creating a new parameter group (or editing an existing one) and assigning this parameter group to the database instance.

MySQL, Triggers and Amazon RDS

This article explains how to enable SQL database triggers for the Amazon Relational Database Service (RDS).

If one attempts to create a SQL database trigger, then the database server will complain a confusing and misleading message like: “ERROR 1419 (HY000) at line #: You do not have the SUPER privilege and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable)“.

It happens that Amazon decided to disable all user defined SQL code, as binary procedures could compromise the RDS architecture. And for this purpose, Amazon blocked granting the missing ‘SUPER’ privileges to any database user except the ‘rdsadmin’ user owned by Amazon itself.

Logging practices on running solver processes in Java

We implemented a java computer program that solves a certain mathematical problem. The program runs for a long time and produces a textual representation of the best solution found.

It was the opportunity to discover the importance of adopting two usually unnoticed components: the Simple Logging Facade for Java (SLF4J) and the Logback logging framework. By employing both components a step further than they were originally designed, we increased our coding, debugging, testing and validation productivity in means far away than expected for traditional logging. All benefits were nearly for free and required no additional coding.

SymmetricDS syncronizing two tables with different names

While working with our newly discovered SymmetricDS tool, I realized that their manual does not clearly state how to synchronize two databases if their table names do not match. That might happen while matching tables between databases of two different companies, each one with its own table name policies. Blame those Database Administrators!

Here is how I accomplished synchronized two tables with different names:

First, I did the usual configuration: I defined two node groups A and B, defined a link between those node groups, defined a channel and a router for each direction (A to B  and B to A).

How SymmetricDS successfully replaced our complicated client-server architecture

With SymmetricDS , we avoided investing effort in designing, implementing and testing a complex, asynchronous communication protocol over web-service layer. Instead, we achieved a simple, intuitive interface that allowed us to deliver out solution within few days.

Our application started with a local standalone server that processes long running transactions. It naturally evolved to a distributed architecture. While benefits of the new architecture were clear to us and our customers, an issue arose : we would force our customers to enable their applications with boring and non intuitive web-services to communicate with our transaction server.

Eclipse Subversive does not frustrate me anymore… Now I use EGit!

A considerably time ago, I wrote down my frustration on using the Eclipse Subversive Plugin. At that time, I was annoyed just because refactoring did not work properly. Now, Subversive has gone worse.

SVN itself does a good job tracking history of moved and copied files, even if directories are moved or renamed. By 2009, the Subversive plugin stopped supporting this features and a simple directory rearrangements may now lead your local copy to an irreversible inconsistent state.

Firefox memory footprint

Firefox is releasing one new version after the other. And each new version, Mozilla claims to have enhanced memory usage to reduce the amount of resource required to load each page. Is that a valid claim?

As a curious computer engineer, I decided to install several legacy Firefox versions and compare the amount of memory required to load two greedy pages: http://www.gmail.com and http://www.spiegel.de.

Here are the results.

One observes that at Firefox 3.6, reading emails from gmail suddenly doubled memory usage. And from Firefox 4.0 on, it requires the triple of memory. I suspect that gmail also loads more content on newer versions since Firefox enhanced javascript support.

ILOG OPL syntax highlighting for gEdit

This article offers the syntax highlighting definition file for gEdit 2.16.

Place the following content into the file ~/.gnome2/gtksourceview-1.0/language-specs/opl.lang. The definitions are not yet complete, I will update them eventually.

Due to gEdit limitations, the definitions allow highlighting according to lexical analysis, but they do not understand grammar. That means that the syntax will be highlighted according to the token used, but not according to their meaning within the model.