Pages

Friday, July 25, 2008

GSOC2008: The Pluggable Editors for Guvnor

One of the goals in this year's GSoC project for me is to enable plugging of content editors as jars. Today I've completed the automation for this aim.

I've integrated the rolodex widget for using image data in Guvnor. Next, the aim was to isolate the code into a separate place, so that it doesn't affect the base source code, and using some code generation routines integrate the new widget to Guvnor.


Here's the summary:

  • The pluggable code is moved into modules/ directory under drools-guvnor

  • build.xml was extended to generate some code pieces to integrate the pluggable editors. Some classes in Guvnor required a minor refactoring in order to support code generation.


It is not as smooth as it could be in GuvnorNG, but the goal is achieved to some extent, I think :)

Friday, July 18, 2008

GSOC2008: Rolodex Panel Assembly for Guvnor

In my previous post about integrating rolodex into Guvnor I tried to create the example just with a set of pre-compiled images which are then assembled into drools-guvnor.war. But the real goal is actually to display the pictures stored in Jackrabbit repository for Guvnor.
Now, after some experiments with rolodex and Guvnor, I have a widget where one may upload a picture and display it.


Currently it can accept only one picture per RuleAsset class instance. Therefore the content handler for this asset should be extended to support multiple images per RuleAsset.

RolodexCardBundle images = getImagesFromAsset();
RolodexCard[] rolodexCards = images.getRolodexCards();
if (rolodexCards.length > 0) {
final RolodexPanel rolodex =
new RolodexPanel(images, 3, rolodexCards[0], true);
layout.addRow(rolodex);
}

I have set the hight of the panel manually as the picture was cropped otherwise in the widget. (Don't know the reason yet). getImagesFromAsset() is used for converting the asset's content to the RolodexCard:

public RolodexCardBundle getImagesFromAsset() {
return new RolodexCardBundle() {
public int getMaxHeight() {
return 200;
}

ClippedImagePrototype clip = new ClippedImagePrototype(
GWT.getModuleBaseURL() +
"asset?" + HTMLFileManagerFields.FORM_FIELD_UUID +
"=" + asset.uuid
,
0, 0, 300, 200 );

RolodexCard card =
new RolodexCard(clip, clip, clip, 300, 100, 10);

public RolodexCard[] getRolodexCards() {
return new RolodexCard[]{card};
}
};
}

I've cheated with the code that composes the RolodexCard, as ClippedImagePrototype's javadoc says:
This class is used internally by the image bundle generator and is not intended for general use. It is subject to change without warning.
But the implementation of ClippedImagePrototype is actually what I need. Probably, if it is really the subject to change at any time, I would rather cope'n'paste this class into Guvnor code base.

TODO:
A heavy part of the work will have to be carried out by the content handler. The content handler will have to support the multiple images per asset and also perform some graphics routines in order to replace the pre-compilation phase implemented in rolodex to adjust images.

Tuesday, July 15, 2008

The time applet in Ubuntu

Recently I discovered that there's one cool feature in the GNOME's time applet: the Locations tab. There I can specify my location and customize the applet look. One interesting feature attracted me the most - the "weather" label. I can see that the weather is if I take a look out of the window. But I think I couldn't say exactly how cold/warm is it - and the applet can show me this information. Small but neat feature I have to say! :)

GSOC2008: Integrating Rolodex to Guvnor

In Guvnor, there are many different widgets that are used to display or edit different assets. One interesting widget is about to be added - a widget that could accept images and display them. For this purpose, rolodex, a widget that can display a stack of images, can be used. Rolodex uses deferred binding for the image generation and animation. Let's see how can we quickly add a new widget displaying some predefined images.

First, create a class, implementing RolodexCardBundle interface (from the rolodex library) and declare a few methods that will return the images (just like ImageBundle described in the book):


public abstract class Images implements RolodexCardBundle {

/**
* @gwt.resource img_3861.jpg
*/
public abstract RolodexCard imgA();

/**
* @gwt.resource img_3863.jpg
*/
public abstract RolodexCard imgB();

/**
* @gwt.resource img_3865.jpg
*/
public abstract RolodexCard imgC();

...

private final RolodexCard[] cards = new RolodexCard[]{
imgA(), imgB(), imgC()
};

public RolodexCard[] getRolodexCards() {
return cards;
}


Next, to display those images, create ImageSetWidget (or you-name-it) class extending DirtyableComposite:

public class ImageSetEditor extends DirtyableComposite {
// asset and viewer are not used now...
public ImageSetEditor(RuleAsset asset, RuleViewer viewer) {
final Images images = (Images) GWT.create(Images.class);
final RolodexPanel rolodex
= new RolodexPanel(images, 3, images.imgA(), true);
initWidget(rolodex);
}
}


For Guvnor to be able to launch the editor, we have to modify EditorLauncher class:

...
else if (asset.metaData.format.equals(AssetFormats.IMAGE_SET)) {
return new ImageSetEditor(asset, viewer);
...

AssetFormats should be supplied with the new constant for this new type, of course.

To allow user to create such widgets in UI, a new menu item needs to be added.


This means, ExplorerLayoutManger#rulesNewMenu() should be modified:

m.addItem(new Item("New ImageSet",
new BaseItemListenerAdapter() {
public void onClick(BaseItem item, EventObject e) {
launchWizard(AssetFormats.IMAGE_SET, "New ImageSet", true);
}
}, "images/rule_asset.gif"));

And last, but not least we need to include the following line in Guvnor.gwt.xml:
<inherits name='com.yesmail.gwt.rolodex.Rolodex'/>


Now, after the project has been rebuilt and redeployed we get the following widget on the screen:


Currenly, the widget is displaying a predefined set of images and animates them as we roll the mouse over. So we have now a rolodex-powered widget inside Guvnor. Sounds cool! :)

Now, there are a lot of TODOs to make use of this new cool widget.

  • Menus should be pluggable. So far I knew that the only class that we should generate in order to support adding new rule editor widgets. Without doubt, a user needs a button to create the widget in his workspace, and therefor we should inject the new menu item. I suppose we can generate this part also. Therefore we need to extract the ExplorerLayoutManger#rulesNewMenu() method into a separate class.
    Currently I have an ant task ready to generate a new EditorLauncher class source to plug a new asset type editor. But perhaps, if we have more of these classes to be generated, I'd better add a new ruby script to do this job.

  • Upload of new images. There's no use of this widget if it can redisplay only the predefined set of images.



  • RuleAsset support for images.The images should be supplied via the RuleAsset, i.e. the content should be a class that could represent a set of images.


  • A content handler is required as well.

Friday, July 11, 2008

Google OSS Jam: Zurich Meetup for GSoC'08

I've spent 3 days in Zürich, again! I really like this city :)


Thanks to Maximilian Albert I'm now aware of Inkscape, an Open Source vector graphics editor, and lib2geom. Thanks to Peter Arrenbrecht a mentor for Mercurial GSoC project, I'm now totally convinced that the DVCS is what I really need, either Git or Mercurial :) And thanks to Stefano Tortarolo, a student from Mercurial, the next programming language in my arsenal should definitely be Python!

Some more interesting OSS projects that were presented at the OSS Jam:

Disqus for Code Impossible