3. The Context and the Interactions: Representing user intent

The context "knows" how to find or retrieve the objects that become the actual actors in this Use Case, and "casts" them to the appropriate roles in the Use Case scenarios. [...] The interactions, that describe end-user algorithms in terms of the roles.

article at Artima about DCI

Figure 2. Structure of a python file in context

Structure of a python file in context

3.1. NetBeans Action Context

When you select a Java file in the NetBeans IDE the so called "Navigator Window" automatically shows the structure of that Java file. At the same time, the "Save" button in the NetBeans toolbar is enabled (or disabled) depending on the file modified flag. And, at the same time too, the pop-up menus that appear when you right-click on the file change and add some useful actions such as "compile", "refactor" or "print".

If you select a Java file the NetBeans Platform adds it to a global context. It then scans for the "Methodless Roles" in the object (such as SaveCookie, or CloseCookie), and the GUI is changed automatically to ease some Use Cases ("compile java file", "save file", etc.) that are relevant for the object.

As I understand it, the Context in the DCI is what makes GUIs really usable for the user. Is about changing the GUI to make things easier for the user, "enabling" the Use Cases, empowering what things the user wants to do (and is allowed to do) on the object.

The fact is that the NetBeans Platform holds different contexts for different parts of your application. The so called "TopComponents" (something similar to "windows" or "panes" where the user interacts with the data) have a special context of its own. When you focus on such a "pane" its own context is merged with the global context, and the "methodless rules" (the cookies) of the file being edited, or the data being entered, are shown in the GUI automagically.

These operations are performed automatically through the NetBeans Platform, and you have to program nothing for this to happen. All you have to do is to worry about what your data is (your classes), how it behaves (defining your methodless and methodful roles) and how the user interacts with them (defining actions or "interactions" that run those methodful roles, as we'll see below). And most of these operations are performed declaratively, using XML files for example.

3.2. Interactions and Roles

An application built on top of the NetBeans Platform will have a set of Context-sensitive actions that will be enabled or disabled in the GUI depending on the "Methodless Roles" of the object(s) in the context.

For instance, there's a predefined "SaveAction" class (you don't have to code it, it comes for free with the Platform) that is context aware. Whenever an object with a "Save Methodless Role" (a SaveCookie) is included in the context (the so called "global lookup"), the "SaveAction" is enabled automatically for you.

That "SaveAction" is tied to different components in the GUI. Such as the "File/Save" menu item or the "Save button" in the toolbar. When the user runs the action by pressing the button (or selecting the File/Save menu item), all the action has to do is to get the methodful role from the objects in the context (the implementation of SaveCookie), and then invoke its "save()" method.

And most of this is done "for free" for you, within the Platform.

Note that it doesn't matter what the actual type of the object is in the context. All that matters is what the object can do: what methodless rules it implements. It can be an image, a project, a java file or a xml file. The only important thing is that the context contains a methodless role (the SaveCookie role) that indicates that the given object can be saved.

3.3. Summary

NetBeans Platform based GUIs hold a context, and modify the GUI depending on the methodless roles of the objects in that context. Most of this plumbing comes for free in the Platform, so you don't have to worry about its internals.

As an user of the NetBeans Platform you concentrate on defining what your objects are and on what they are allowed to do, and then implement context aware actions (interactions) to make things easier for the user. These features in the Platform allow you to build user-centric applications in an easy way.