Configure EulerGUI through an N3 preference file

© Jean-Marc Vanel - $Date: 2012-04-23$ - under Creative Commons License by-nc-nd 3.0

Posted on forum deductions-user and eulergui-user .

Introduction

Configuration files in N3 offer features like Eclipse extensions points and Spring and Guice dependency injection. The extra advantage is that you can have rules adding intelligence, and, being built on a dynamic (stateful) Knowledge Base, it can react to events, platform and property changes.

The configuration file allows both:

In all cases,

Example: adding an Action in the GUI for N3 sources

Currently this does work; it adds a new button in Toolbar And Menu for N3 sources.

This works thanks to recent modifications: generated Drools binds a variable to property value, LocalAction is not abstract anymore, and ProjectGUI constructor does not start internal KB (ApplicationKB) anymore.

{ ?P a java:n3_project-ProjectGUI .
} => {
  ?P javap:sourceFilesManagement ?SFM .
  _:ACTION a java:n3_project-LocalAction .
  _:ACTION javam:setProperties ( _:ACTION "bla" "internet.png" "bla bli" "Z" ) .
  ?SFM javam:addInToolbarAndMenu ( _:ACTION ) .
}.

This rules says: "For ProjectGUI".

HowTo :

Just paste the above rule in in the preference file ( from menu File / preferences ) , and restart EulerGUI .

The N3 user preferences file in N3 is $HOME/.eulergui_preferences.n3 .

Works too ( no parentheses ) :

{ ?P a java:n3_project-ProjectGUI .
} => {
  ?P javap:sourceFilesManagement ?SFM .
  _:ACTION a java:n3_project-LocalAction .
  _:ACTION javam:setProperties ( _:ACTION "bla" "internet.png" "bla bli" "Z" ) .
  ?SFM javam:addInToolbarAndMenu _:ACTION .
}.

It works also with question mark variables and parenthesis :

{ ?P a java:n3_project-ProjectGUI .
} => {
  _:d eg:trace ( "addInToolbarAndMenu" ?P ).
  ?P javap:sourceFilesManagement ?SFM .
  ?ACTION a java:n3_project-LocalAction .
  ?ACTION javam:setProperties ( ?ACTION "bla" "internet.png" "bla bli" "Z" ) .
  ?SFM javam:addInToolbarAndMenu ( ?ACTION ) .
}.

Example: adding an Action in the GUI for showing results

With Revision 2980, the extension point capabilities of EulerGUI are used for real. Now the result display features are set by N3 configuration rules in

src/main/resources/eulergui/gui/controller/application-rules.n3

These result display features are displayed by 4 buttons on upper right corner of main window, and are implemented by there classes:

ResultEditorAction, ResultEditorN3Action, ResultGraphvizAction, ResultTableAction

There is just one rule to configure these features :

{
  ?GUI a java:n3_project-ProjectGUI
  ; javap:resultManagement ?R .
} => {
 ?ResultEditorAction a java:eulergui-gui-actions-ResultEditorAction
 ; javam:setProjectGUI( ?GUI ).
 ?ResultEditorN3Action a java:eulergui-gui-actions-ResultEditorN3Action
  ; javam:setProjectGUI( ?GUI ).
 ?ResultGraphvizAction a java:eulergui-gui-actions-ResultGraphvizAction
 ; javam:setProjectGUI( ?GUI ).
  ?ResultTableAction a java:eulergui-gui-actions-ResultTableAction
; javam:setProjectGUI( ?GUI ).
 ?R
    javam:addAction ( ?ResultEditorAction )
  ; javam:addAction ( ?ResultEditorN3Action )
  ; javam:addAction ( ?ResultGraphvizAction )
 ; javam:addAction ( ?ResultTableAction )
}.

This rule says : "for each main window ProjectGUI, with a field resultManagement ?R, create the 4 objects ?ResultEditorAction ,

etc, and add them to ?R through method addAction".

The method addAction on class ResultManagement is just one of 10 extension points that are planned . See also the Roadmap for EulerGUI 2.0 .

Note that the main architectural advantage of extensions point à la eclipse is to be able to add a feature without modifying a line in the Java code. But contrary to Spring or eclipse stuff, we have the whole power of rules here: it is possible to take in account machine and user context and history. This mechanism is usable also in applications built with the EulerGUI framework.

For a user to add such an action:

CAVEAT:

Conclusion

In this article, I showed how one can add features and customize EulerGUI, expressed by rules, Java classes, or a mixture of both. Currently (2012-04-22) EulerGUI is not built like this, but new some features ( actions in the GUI for showing results ) are added in an N3 configuration file: application-rules.n3 . The extensions points are listed here in architecture page.

For a comprehensive account, see : EulerGUI application building Framework .

About in Java + N3 mixing, to know exactly what is implemented and works, look at the test class BasicRuntimeTest .