ExtJS Filter Across All Grid Cells

ExtJS offers the ability to filter rows based on a column. By setting filters features in grid like so :

and defining filters on your columns like so :

You can get some pretty cool filtering functionality in your grids by clicking on the column drop down

However what if you wanted to filter grid rows globally (Ie. not restricted on a column) ?

The best way would be to add a textfield to your toolbar, or somewhere above your grid, and then have some method that filters across all rows based on the text you input.

The following code filters rows based on a text string.

Notes :

  1. To get all visible columns the codes uses the Ext.ComponentQuery functionality. This allows us to query components in the grid. Don’t ask me how it works, but the following returns just the columns that are visible : grid.query(‘gridcolumn:not([hidden])’);
  2. we need to iterate over each row, and then each cell so we have two loops here
  3. this function gets a column for a given field ID. We need this column later.
  4. A field may not be associated with a column. In extJS your store’s table of data may include additional columns that are not visible in the extjs grid.
  5. Now we check if the column has a renderer. With our filter function we can only filter on string values. Because column types may vary, the only way we can filter across strings is to get the rendered value. So we get the render function and pass our rec data value through it to get the string value.
  6. comparison
  7. set filterMeOut flag
  8. call the filterBy method on the store, passing in a custom function which does the comparison on our filterMeOut flag.

You can then call the method through a text field like this.

Posted in extjs | Tagged , | Leave a comment

Using JSDoc

Enhancing Javascript with JSDoc and JSDoc-checking IDEs

JSDoc is a way of documentating Javascript much like JavaDoc and Java annotations for Java. JSDoc does pretty much the same thing. It documents and annotates Javascript elements. However given that Javascript has much looser language rules than Java, these annotations can be leveraged to tighten parts of the code that may appear ambiguous particularly in a large project.

Probably the most useful features of JSDoc is the ability to sprinkle annotations amongst Javascript code which can then give semantic meaning to a function or variable. Using an advanced Javascript IDE, these annotations can be interpreted at compile time, and provide a kind of compile time checking, while also aiding in code-completion.

As of writing, the only IDE that can interpret JSDoc to any reasonable level is Webstorm. So all examples in this article are using the Webstorm IDE.

Simple Type Checking

Parameters types can be defined in the comments of the function. In this example we are annotating the x value being passed into the popup() method :


Now we are passing in a number :


Notice the squiggly line underneath the number 12345?

If we hover our mouse over the squiggly line, we should see a tooltip telling us what the problem is :







That’s pretty neat! Type checking at last! 

The @param JSDoc annotation allows us to say what we want passed into a function. We can also use this annotation on other primitive types such as number and boolean. Let’s have a look at how we can use the @param annotation on some more interesting objects.


Arrays and the Type Annotation

Javascript also has arrays and objects which can be considered types.

In the following example we are passing an array into a function :


In the above we create two types of fruit, and make an array for each of them. By using angular brackets, we can define the type of the array being passed in (Array.<Apple> )

Using the @type annotation we can annotate a variable. In our array example we are stating that we want out element to be of type Banana. As the second array being passed in is of type Apple, our JSDoc annotation is being infringed and we get the squiggly gray line again.

At the time of writing Webstorm does not support the JSDoc checking of the inner type of an array when being passed to a function (See the comments).

Parameter annotations on arrays can also help in code completion.


The JS compiler knows the element in an array is of type apple and shows the apple elements in the drop down list. This is unbelievably helpful!

Object Literals

Javascript objects can be very arbitrary objects. There is no real sense of type .

In the following example we are using the @param tag annotation again. Here we are annotating an object literal with two fields: name, and email which are both strings :








In the method body, a variable is assigned to the user.name. This variable has to be of type string, and matches up with the name type being passed into the method.

The following two examples show where the IDE complains and the squiggly gray lines start appearing again :








The @param annotation expects a number but we are passing in an array. Our @type annotation declares a variable to be string, but out @param says our user object can only be number.

In this case we are trying to treat one of the string fields as a number :









We can even document an array of literals.











In the following example the IDE will complain about the variable i being assigned to a string :












Again, code completion is enhanced. The IDE deals with the fields in an object literal :





Return Types

Returns can be annotated too.

In this example the IDE indicates there is a problem on the line where x is assigned the return value.








In this example the assignment is correct, however there is now a problem with the return statement. The IDE picks up on what is happening inside the function is incorrect.







Finally this example has everything working correctly :


Mixed Type

Because Javascript is duck typed, methods can accepted objects of various types. Sometimes you want to document a function and tell it that it can only accept objects of these ‘types’.












The IDE will complain at exactly this line : processFruit(new Orange())

Wrapping up..

I hope this introduction to JSDoc was useful. I don’t believe in strictly enforcing JSDoc across a whole project, but I do feel that JSDoc with a JSDoc-checking IDE becomes necessary as the project grows bigger. It allows one to treat javascript functions as black boxes, and prevents lots of picking around inside a function to try and understand what is going wrong.

This is particularly useful when you have Javascript project modules, ie. Common projects that are used across other javascript projects. A typical real world implementation I have come across is a table component that is used across many projects. It has a setModel(..) method, where the table model is passed into the component (Just like in Swing J ). Using a JSDoc-checking IDE, the developer would be notified that this object being passed in requires an array of columns, an array of entities, and a method getValueAt among other things.

Posted in JavaScript, Tutorial | Tagged , , , | 5 Comments

Bar Chart in Java Swing

Update !

This bar chart compoment has now been moved into the Iceberg Charts project . Please use Iceberg Charts for a more complete charting experience.

I’ve created a little Java component which creates bar graphs. It only displays bars along the Y axis, however the component is very versatile and configurable. You can change its size, fonts, ticks on the Y-axis, and bar width.

Here are some examples of using it :





The code is below. It’s basically three classes: BarChart, Bar and Axis.
A few things to note :

  • It is highly customizable. All the package level fields in BarChart can modified.
  • The Y-Axis can have up to 3 categories of ticks. In the Axis constructor, you just need to set the second and third to zero if you don’t want to used them (See my examples).
  • It is geometrically relative, however you can have problems with it. The key things to know are width and height, and leftOffset, rightOffset, topOffset and bottomOffset. The offsets need to be big enough to accomodate a title with a very large font (again see my examples).

Please let me know if this component has been useful to you. I spent a lot of time creating it, so a little feedback would be very important to me 

Posted in Swing, Swing Components | Tagged , , | 6 Comments

Maven Tutorial

..FOR dummys, duffers and the perpetually confused.

Maven is a system for building software; a build automation tool that helps you ship out your software. If you have the vaguest understanding of Maven, you will also know that there is this thing called a POM file (pom.xml) which looks something like this :

Maven attempts to treat projects in an object oriented fashion, and one of the central tenants in Maven is that a project is an object. This project only needs to be described once, in one XML file called the POM file.

The project has a primary key, and this is defined by its coordinates: groupId, artifactId, and version. Effectively its package root, a name, and a version number.

That is basically the only prerequisite. Then you can just build your project, through your IDE most typically, or by using the Maven command line:

mvn clean install

which executes the clean lifecycle, and all phases up to the install phase in the default lifecycle. This is most commonly considered “building” a project.

A look at dependencies

The easiest thing to understand about Maven is also the most beautiful thing about Maven. Rather than managing a number of libraries across a number of projects, everything is tied to this thing called a maven reactor, a type of super library that contains all your libraries that you are using. You can see it in an .m2 directory under your user profile usually (It doesn’t really have a sexy name because it is best to be hidden. ‘Out of sight out of mind’ as they say).


The above example is from when I was working on my multi level pie chart project. It’s not too hard to see what was going on here. My pom.xml file looked like

As I was working on it I incremented the version number to 1.1, and after I did a build on the project, a new folder appeared called 1.1 with the file multi_level_pie_chart.jar in it.

The older versions are not deleted. There still hang around in the reactor. Who knows what other projects use these old versions?

Maven also allows you to point to the projects you need. As your own project is shipped to your .m2 directory, your own project is free to use whatever is in the .m2 directory. You just place in your dependency tags like so :

Maven will look for it in your .m2 directory. If it is not there then it will try and find the dependency on the web, and if it exists, download it to your .m2 directory. So in fact your dependency doesn’t have to exist in the .m2 directory. As long as you have an internet connection, it can exist as any Maven project in the internet.

As you work on multiple projects the maven reactor collates libraries that are needed as dependencies. On one project you may need JUnit1.4, but on another project you can only use JUnit1.3. The maven reactor neatly orders them based on version number.


If you hate configuration, Maven is for you.

Your project is its own source definition. There is no longer the hassle of faffing about with JAR files to make your project work, you no longer need to monkey around with pages and pages of configuration documents.

It’s all about the POM file. That’s what’s so cool about Maven!!

The configuration battles trying to get projects running across different IDEs, are no longer fought in the setups of IDEs. The battle front has been reduced to tinkering with the POM XML file.

Maven also allows for transitive dependencies. This dependency would only exists in the test phase:

A further five scopes are available, which describe a number of scenarios, such as having a dependency only at runtime, or that the dependency is provided by the application container.

A look at LifeCycles and Phases.

A lifecycle can contain many phases, and a phase contains many goals


Maven has 3 built in lifecycles.

Lifecycles contain a number of goals, grouped in phases. Maven has these lifecycles pre-configured for you to use, rather than offer an ad-hoc environment for you to chain them together as you please.

The clean :

Clean is what you would expect it to be. It blows away the target directory and that is about it. The reason that clean is not included in the default lifecycle is because a ‘clean’ is a time expensive activity. Once the target folder has been cleaned out, everything needs to be generated again (all the class files etc.). If clean were to be part of the default life cycle things would be slow because it would not be possible to build iterative changes. That is why the clean has been separated out of the default lifecycle.

The default :

The default life cycle is the main lifecycle that is used when building a project. I have enlargened the phases that you will encounter more often, and which are more important to understand.


Three of these phases should be familiar to most developers:

Compile – the software is compiled. Nothing too complicated here. Java code is converted to binary classes and put in the binary directory.

Test – All the unit tests are run. That’s all your JUnit tests that are sitting in your Test folder!

Package – after everything checks out as OK, the software needs to be bundled up ready for consumption. Ear file for JEE project, War file for Web project etc.

A couple of other commonly used phases

Validate – This checks all the directory structure is correction, that the conventions have been followed. Maven can’t work if people don’t follow the rules. The directory structure should look like this.


Install – (and his cousin deploy). These two are very similar. Install puts your packaged file, be it JAR, war, ear in the maven reactor (your .m2 directory). We have discussed this before. Doing an ‘install’ is usually considered doing a ‘build’

Deploy – takes this one step further, and moves your finished product to an internet location where it can be accessed from anywhere in the world.

[One word of warning, do not confuse the install and deploy phases with the actual deploying of your application. For example, these phases have nothing to do with the actual deploying of your web application to your server.]

Site :

Generates Documentation. We won’t cover this.

A look at Goals :

Goals describe actions. They are the atomic parts of Maven and are analogous to tasks in ANT. How they are accessed and manipulated is one of the hardest things to understand about Maven.

If you are familiar with ANT, ANT has tasks that are organized in a dependency tree. When one task executes, all the lower branches of the tree need to execute first. Well Maven is kind of similar, except that the tasks (the goals) are organized in a linear fashion.

So under the hood, Maven actually looks something like this :


It really is just a series of goals with no branching. Where ANT is tree-like, Maven is linear.

Plugins are a way that you can mess with this chain of goals, by attaching custom goals in certain phases.

A plugin, for example the wsimport plugin

If you visit the website https://jax-ws-commons.java.net/jaxws-maven-plugin/ you will see that it binds to the “generate-sources” phase. If you run a clean install, then the goal of this plugin, wsimport, will execute along with along the other goals in the generate-source phase.

Goals in plugins can also be executed independently:

mvn [plugin]:[goal]

In the above wsimport example, you would execute :

mvn jaxws:wsimport

While it is not advisable to change the phase in which a plugin executes, the phase can be overridden by modifying the execution XML like so :

So in summary, it is hard to understand what goals exist in Maven, and it is also hard to control where a goal executes in Maven. It is all under the hood stuff that only the plugins really know about. There really is little information about what goals exist in the default lifecycle.



A look at Project inheritance and project aggregation

All POMs inherit from the super pom. The super POM contains a lot of default configuration values. (eg. build.sourceDirectory = src/main/java) as well as other folder structures/properties that belong in the maven convention. You can look at the ‘effective pom’ which shows the merging of the pom files.


It is also possible to make your projects inherit from other projects that you have created. Common configuration can be refactored out into the parent making maintenance much easier.


Projects can also reference sub projects. This is called project aggregation.
This example shows how you might aggregate a number of child projects (called modules) in the parent project. When the parent project is built, all the modules will be built.

This example is a common pattern in JEE. It is a web application which is a packaging of a WAR and an EJB (as JAR) file, into an EAR file.

Note: you still need to define dependencies between projects, if order is important. For example, in the above, the WAR and JAR modules need to build before the EAR. In the EAR project I would expect to see something like this in the POM-file:

Anyway, I hope this tutorial was useful to some. It hasn’t covered everything, but I have tried to present the core concepts that people need to understand.

Posted in Tutorial | Tagged , , | Leave a comment

Multi Level Pie Chart in Java


Update !

This pie chart compoment has now been moved into the Iceberg Charts project . Please use Iceberg Charts for a more complete charting experience.

Pie charts are pretty boring. I hadn’t found anything out there which resembled a multi level pie chart. A multi level pie chart, is basically a pie chart with a number of levels (Excel 2016 has something similar called Sunburst charts). Each level is in effect an expansion of the slice below it. A multi level pie chart basically represents a tree structure, where each node has a magnitude. The component I have written requires a tree structure of Segment objects. A typical real world scenario where you would use a multi level pie chart would be to view the disk usage on a computer. A simplistic example I created is shown below.


The code I needed to generate the above chart is just this :

In order for it to not look like a multi colored mess, I have applied a gradient-like effect, by darkening the colors sequentially after the initial color is set for a segment. My darken method is simply :

I think this is quite effective, but there may be other ways or algorithms to implement a set of related colors. You could experiment with incrementally adjusting the hue, saturation or a rgb value.

A bit about the design of this component :

For a simple pie chart there are really only three things to consider for a pie slice. They are

  1. the starting angle (calculated from what slices have previously been drawn),
  2. the magnitude (if it is a percent it needs to be converted to an angle)
  3. and of course the color.


This is simple enough to implement. However for a multi level pie slice there are many other things to consider :

  • Relative start angle.The start angle needs to be converted, because this pie slice may not be the first level, and therefore a scaling would need to be applied.
  • Parent. The slice will have a parent, if it is not on the first level.
  • Relative magnitude. The angle, or percent, needs to be scaled based on what its parent is. If the parent represents 50% and the parents parent is on the first level and represents 50%, then the scalings would have to be combined to 25%. This 25% would then have to be applied to the original magnitude.



Also to consider would be

  • Circle1 – a circle that represents the outer rim of the slice.
  • Circle2 – a circle that would need to be subtracted from the arch created from circle1.

These circles would need to be calculated depending on a number of factors. The extend and starting point would of course need to be taken into account, and the number of circles needed would also depend on the total depth of the tree structure.

Given all these things to consider, the segment is a special type of object. Omitting the getters and setters for clarity, here is the class I came up with for a segment. A lot of the values need to be calculated.

(jar file is here)

If you would like to use this component in a project, or would like to look at the source code, please contact me 

Posted in Swing, Swing Components | Tagged , , , | 4 Comments

Swing and Web Services Tutorial


Swing and web services have been around for many years, however it has only been in recent times that things have gotten much easier in implementing web services and building complex Swing applications. This is mainly due to improvements in the Java language and better IDEs.

This tutorial aims to be a comprehensive guide to getting an end-to-end configuration of a Swing application communicating with a web service deployed on the server.

This tutorial also touches on Maven and the Netbeans IDE, two technologies that go hand in hand. You don’t specifically need either of these technologies to get up and running, but for the purposes of this tutorial it is highly recommended.

Part 1. Client

We are going to start off with a basic application. In our example we are going to be building an airline application that talks to a web service. Its very simple, just a table which lists all the airlines, and a button which creates a new row in the table.

Create Project

Lets create a Maven project and call it ‘client’. It is going to be our desktop client, so we want it to be packaged as a jar file.


Write Some Swing Code

We want a simple entry point to our application, so we will add a main method to our MainFrame class which serves as the main Window for the application.

Inside out frame code you may notice an AirlinePanel class, which is basically a JPanel with a JTable and buttons. Let’s add our table inside a scrollpane, and add a button to the top. The aim of the table is to list all the airlines in the system, and the button will eventually create new rows in the table after persisting across the network.

Swing uses the MVC pattern for its complex components, so for our table object, we need to have a model object that contains the business data. Lets create AirlineTableModel, an AbstractTableModel, which acts as a model for AirlineVO objects.

So now we should have three classes :

  • MainFrame
  • AirlinePanel
  • AirlineTableModel

However AirlineVO is missing.

Create an AirlineVO class somewhere in the project. We will be deleting this local AirlineVO class a bit later, and instead we will be using the web service generated AilineVO object. But for now you can add some dummy getter and setters into the code just so that the client application code works.

Now let’s move on to the web service project.

Part 2. Webservices

Create Web Service Project

Create a web application project. In Netbeans you can do this via choosing a Web Application project.


The Pom project you have should be named like this. We want the groupId to be the same for the client and the server. It needs to be packaged as a WAR file, and dependencies should be present which includes javaee-web-api and webservices-rt. Both these scopes should be set to PROVIDED. This basically means the web server has its own versions of these two libraries which it will use instead.


Create the Web Service Class

Create a java class called AirlineWS. This will be our entry point for our airline application. All methods that we need will exist in this class.

On Netbeans go to New —> WebService

Annotate the class with the @WebService annotation, which tell the application server to treat the class as a web service.

Create the Value Object Class

In our client code we can see that the code uses something called an AirlineVO object. We want to define this on the server side as well. If we also have the AirlineVO defined in the web service (WSDL), then there is no need to have a separately maintained copy on the client side. The AirlineVO object can be generated via a ws-import (more on that later).

NOTE : While in this example we are using the AirlineVO object throughout the client code, this in general is bad practise. Once the VO object is received by the client, it should be converted to a client specific object: eg: Airline guiAirlineObject = new Airline(airlineVO). This reduced the dependencies on the generated code, and also allows for decorations. That is to say, it is a decorator pattern.

So we create an AirlineVO class and put it in the web server project.

Implement the WebService Methods

We can now add some business logic to the web server. Normally a web server delegates to another layer such as the EJB layer, however for demonstration purposes this web service will be our end point. In a constructor we will create some of these Value objects and put them into an array list.

We will then create a couple of methods. We need to annotate them, this way the web server know to treat them as a web service end point.

We can add a constructor which creates some dummy data. Of course we should have a proper database for our application, but for illustrative purposes this should suffice. The other two methods do a basic add, and a basic create.

Clean, Build, and Deploy

Now that we have our server code we can clean and build the project. In Netbeans there is a Clean and Build option on the context menu for the project.


Follow this up with Run. This can also be found on the project context menu.

‘Running’ a server project in Netbeans and in most other IDEs, actually deploys the application to the server. Per default Netbeans has a Glassfish instance running on localhost, so an instance of Glassfish is booted up, if it hasn’t already been started, and the WAR file is deployed as an application.

If you visit the administration console for glassfish, you will see something like this.


From this screen you can select ‘View Endpoint’ and view that the WSDL is there. This is what is exposed to the outside world, and is what ws-import uses to figure out what classes are needed to talk to this interface.





Part 3. Back to the Client…


Let’s create the skeleton of a delegate class as we want to use the delegate pattern to shield the GUI code from all the backend code. Swing is also not Thread-safe so we also need to make all calls to the backend through a thread safe singleton.


Now we need to add wsimport support. WsImport is a maven plugin that needs to be defined in the POM file, in the plugins section. The webservice endpoints that we are interested in should be defined in the <wsdlUrl> tag. In our case, it is the AirlineWS web service.


Clean and build the client project. The wsimport plugin attaches itself to the build process, and you may notice that building has gotten a little slower. After it has finished you may now notice a folder called ‘Generated Sources (wsimport)’.


It contains all the artefacts that the wsimport has created during the build process. We can get access to a port for a particular web service, and from that port object we can call any method we want. This is how we use the generated code to do this:

Notice how the AirlineVO class is also there. This is not the same object as exists on the server side. This object was generated based on the Web Service definition (WSDL).

Lets add two methods to the delegate object, using the generated code :

Now we can call these delegate methods from within the Swing code.

We can do two things.

  1. On the create button add an actionlistener. In a later tutorial we will add a proper dialog for creating a new airline object. For now, we just send the same data across to the server, as in this tutorial we are just interested in a proof of concept.
  2. At the end of the initComponents method we call getAll from the web service. This will getall the value object from the backend and display them in the table. We also call a getAll in the create button code, because we want to perform a refresh of the data once we have created something.

You should see something like this. The table is being filled from data supplied by the web service, and clicking on the Create button creates a new row in the table.




(Source Code is here)

Comments are very appreciated J

Posted in Swing, Tutorial | Tagged , , , , | Leave a comment

Setting up an Oracle Database in Glassfish for JEE Applications

Setting up an Oracle database connection in Glassfish 4 is relatively simple, but can be confusing and a little frustrating at times. Hopefully this mini tutorial will get you up and running quickly and painlessly.

Setup Pool

Select Resources –> JDBC –> JDBC Connection Pools and then select New.

For Step 1., enter in a name (in this example jdbc). Select Resource Type to be of type javax.sql.DataSource, and select Oracle as Database driver vendor :


Leave everything as is in Step 2.

Look at your database settings in your DB explorer. This example shows how my database looks like in Oracle SQL Developer


You need to get values from this properties screen and create a properties string that glassfish server can understand.

Click on the pool you created previously and leave everything as is in General and in Advanced tabs. However in the Additional Properties tab add three strings. The username and password (username would be SYS from the previous screenshot).

The URL is formed by adding jdbc:oracle:thin at the start. Looking at the previous screenshot, this would be followed by the username again (SYS), the characters @//, the server hostname (mydbserver), the port number (1522) and the service name (DB1).


Setup Resource

Save these connection pool properties. Now go to the JDBC-Resource node and select New. Select the pool in the drop-down list (In this case it would be jdbc). Give the resource a name (which is also its JNDI name). In this example we will call it myJDBC.



Configure Persistence XML

Finally we just need to reference this resource in our persistence XML file. The name we gave the resource (myJDBC) needs to be set in the XML file like so :



Now you should be connected. Write some EJBs and see if they talk to the database.


Posted in Uncategorized | Tagged , , , | Leave a comment

Simple Piechart in HTML5 and Javascript


I created a little pie-chart component in Javascript for anyone who wants to spice up the HTML5 webs-site.

Basically the requirements are that you define the slices like this:

The slices object contains two arrays in it. The first array is a list of the percentages, and the second array contains the corresponding colors. Create the pie chart as a variable via Object.create, and call drawPieChart(..) method passing in the slices object, and a string which is the id of a canvas on your page.

There are two modes.

  • Standard Pie Chart – a basic pie chart with black outline.
  • Segment Pie Chart – the center is hollowed out giving it a slick looking feel. To use this mode just write piechart.segmentMode = true.

Here is the Piechart component code :

There is some basic maths involved in creating the pie chart. The most odd thing is that in HTML5 you do not define the angles from 360 degrees, but as a percent of 2 * PIE.

There is no legend in this component, but it would be pretty easy to create. Given a table element with id legend, we can write some code like this to show the colors in a table.

The complete code for the image at the top of the page is shown below. You may use it any way you wish. Just remember it will only work in a modern browser with HTML5 support suh as the latest browser from Chrome or Firefox.

Enjoy! Please leave a Comment!

Posted in JavaScript | Tagged , , | 6 Comments

Javascript IDE Review

…a look at refactoring, intellisense, navigability, and usability.


As agile software development becomes more commonplace, it becomes more and more essential that the tools we use allow us to develop software in a fast and flexible fashion. Particularly important is refactoring. Being able to refactor is what allows us to respond to change, and makes our code evolve over time.

For the last year I have been using Javascript for a project. After 10 years of Java it has been a pretty hellish ride for the first few months, but things have improved once I learned how much a good IDE can take the pain away. Javascript’s dynamic nature will never allow for smooth refactoring like Java in Eclipse, but looking at modern IDEs it is possible to get at least SOME intellisense and refactoring support.

Having an IDE that understands the language you are developing in allows project wide changes, as it can offer a layer of control like the Eclipse platform does for Java developement. A Javascript IDE should understand Javascript. Ideally a Javascript IDE should also understand JSDoc which can also offer type checking.

I set up a list of criteria below, and ran these criteria against four Javascript IDEs that I would consider the Javascript IDE main players.

Object Rename  If I rename the method methodXYZ in the method test in the below example, it should not affect the method in ObjectA.
Javascript File Rename If I rename a javascript file, then I want the rename to also be carried through to my HTML index file. Ie. The IDE has to know of the relationship between the index.html file and the javascript files in the project.
Rename var or param Can I rename local variable or parameters in the scope of a method?
Intelligent Intellisense Entering a ‘dot’ will bring up a pop up list of methods.If I type ‘.’ After declaring ‘v’ in the example below :

Then I want my IDE to intelligently know that methodB is an available method of v because v is an ObjectB object.
Create Method Hint If I type in a method that does not yet exist, I want a graphical hint or shortcut to allow the quick creation of a method stub (offering perhaps various options for scope).
Unreachable Code Example

I want my IDE to highlight or underline unsed code in some way to make it stand out.
jQuery intellisense Whenever I press ‘.’ In this scenario :

I want to have a list of all JQuery methods.
Code Navigation
Method Step Into I want my IDE to know how to navigate to the methodXYZ in ObjectA, through the use of a function key or short cut key.

This should also work across javascript files.
Var Step Into In the case of a simple locally scoped variable When doing the ‘step into’, I want my cursor to move to the line of the ‘var’ assignment.In the case of a variable defined with this. The Step Into should be as intelligent as possible, and try to determine where it first has been defined/instantiated.Ideally all instances of the variable should be clearly highlighted.
Find Usages I want my IDE to know how to find usages of an object or method across the whole project.In Eclipse CTRL-SHIFT-G is used to fine Java methods. A list is brought up showing where this object is being used across the project or projects. Something similar should also be possible in Javascript. Although Javascripts dynamic nature prevents this from being perfect, some basic string matching across the whole project should be at least offered.
JSDoc Does the IDE support JSDoc to some degree?
JSDoc Type Checking Is it possible to do Type Checking by using JSDoc or perhaps another means? Can the IDE perform some basic error checking before sending the code to runtime?For example in the below example the call of methodXYZ in test is wrong because it is expecting an object of ‘type’ ObjectA through JSDoc markup. Can the IDE visually underline or highlight these errors in code?
Method Encapsulation and JSDoc Using the JSDoc @private annotation, is it possible to hide methods?Does intellisense then hide the method? Or at least indicate that it should treated as private?

These are the results :


Aptana 3.4.2


Visual Studio

Object Rename Yes. But sometimes it doesn’t understand the context and does a string replace. No Yes.Weirdly does not allow a rename from the menu. No
Javascript File Rename Yes. No Yes. No
Rename var or param Yes. No. Seems to lack any refactoring capabilities. yes No
Intelligent Intellisense Yes No. Only shows methods from javascript Function and Object object Yes Yes.
Create Method Hint Webstorm :Creates in method or globally in file. Cant figure out type. No No. Offers ‘Surround with function’ which is almost as good. No
Unreachable Code Yes. Underlines in gray with tooltip No No. No.
Unused variables yes No Yes no
jQuery intellisense yes No Yes No
Method Step Into Yes.Across files? = yes No. Some code navigation, but extremely limited. Yes.Across files? = yes YesAcross files? = No
Var Step Into Yes No yes yes
Find Usages Yes No No No. Not apparent to me that it can.
Pull Out local to global variable Webstorm: doesn’t seem to work No No No
JSDoc Yes No Yes No
JSDoc Type Checking Yes. Reasonable support No Yes No.
Method Encapsulation and JSDoc Yes. No No. No.


I have been developing in Webstorm for the past 8 months or so, and I thought the refactoring abilities, intellisense and code navigation were tools that are standard for serious Javascript developement environment. Without these refactoring tools, developing complex Javascript applications has been like stumbling around in the dark, a trip back to the ‘stone age’ of software development where everything was developed in text editors. Understanding how a small piece of code works could cost days.

I assumed that Javascript IDEs would have this kind of stuff per default, but I have been pretty surprised at how much lacking the software is out there. Javascript is so ubiquitous on the web, so its something all web IDEs should have.

Webstorm comes out way ahead in my research. Jetbrains, a pioneer in Java refactoring have tried as hard as possible to squeeze out as much refactoring as is possible in a dynamic language such as Javascript. Some things aren’t perfect, refactorings have sometimes just behaved as a text ‘search’ and ‘replace’, and have some nasty side effects at times, but a preview screen offers pre-emptive screening, and renaming methods has been overall quite pleasing. (TIP : Make you Javascript methods unique to avoid conflicts!). Using JSDoc in Webstorm has been great too.

Netbeans is also pretty good, however it lacks some basic features. Why can’t I ‘find usages’ for a method, even if it is just a string search? It would help immensely. You can’t delete or change code if you don’t know where its being used. Renaming a method doesn’t seem to register across files which is a shame too.

Visual Studio is fairly poor with its Javascript support and on top of that it feels like driving a ten ton truck through a Japanese rock garden. Aptana offers almost nothing, and is really just a glorified text editor. Maybe it offers great PHP/Ruby development? In any case you can throw it in the same basket as Spket, Sublime.

So Webstorm comes out on top. Even though I have been using it, i was quite surprised that there isn’t anything out there to compete with it. Hopefully that will change.



Posted in JavaScript | Tagged , , , , , , | 7 Comments

Swing and Design Patterns – Part 4. Mediator Pattern

Assume we have a component hierarchy that looks like the following diagram. Some component on one branch (say a button), wants to update something on another branch (say text in a text field).


This scenario occurs very often in complex GUIs. Some examples may be :

  • Blinking of a mail icon when mail is recieved.
  • Update a table cell of a trade, after closing it in a dialog.
  • Any inner-framed application that requires inter frame communication (like photoshop)

To solve this communication dillema we can ‘bubble’ through a reference to the parent frame. In the constructor of the container components we pass this reference through.

We thread the parent frame through the constructor of our initial panel.

We want this parent frame to permeate all our components so we keep passing it through the constructors of embedded panels :

…and so on. Lets assume the class AnotherPanel calls a Dialog. The parent frame object also needs to be passed through the dialog too :

The dialog embeds yet another panel, and threads the frame through.

Notice that each embedded panel/dialog has a getter method associated with it.

The whole point to this is that we can access any node in the hierarchy from any other node. Assume we are in some other part of the GUI hierarchy. Since we have a handle to the parent frame, we can make a call like this, which in our hypothetical situation would blink some text.





The Mediator Pattern is Really Just a Thread-Safe Singleton

To overcome a lot of the bloat that the previously described technique describes, use a thread safe singleton to hold any interested components.

This singleton object contains all the components that we are interested in. This kills the bloat as we don’t need getters for all the panels, these horrible chained method calls, and passing the frame through all the constructors.

In the constructor of our interested objects we add it to the constructor like this :

…then in some far away panel we can use the mediator to access this panel, and call a hypothetical method called blinkSomeText().

Some find the way the singleton holds references to the components is a little bloated. It is fairly bloated, and another option would be to store all these references as a map, and access the components using get and put from the map object. It’s a matter of taste.

Further reading:

Posted in Design Pattern, Swing, Swing Design Pattern | Tagged , , , | Leave a comment