Wijsmullerbros.nl

No talk will cure
What's lost, or save what's left
For the deaf

— Josh Homme

Apr
28

Move window to other monitor screen

A simple shortcut to move the active window to another screen inside your multi-monitor setup, not that absurd I would think.
Well with gnome-shell, it does not exist (with compiz it was available for configuration).

But I have a workaround that's simple and fast, using the following script:

#!/usr/bin/xdotool
getactivewindow windowmove $1 y windowactivate windowfocus

You do need to install the xdotool package (on a debian based linux):

sudo apt-get install xdotool

Then, configure the shortcut, for me that's one to go left, and one to go to the right screen.
- Go to system settings >> Keyboard >> Shortcuts
- Add a custom shortcut, I chose CTRL+windowskey+left
- the command will be /[path to script] [x location]

The x location should be either zero for all the way left, or 1280 for instance which is my right screen left edge x location.

Done.

1 comment

braam

I realized that the script does not work for maximized windows unfortunately.
Oh well, I later found this: http://ubuntuforums.org/showpost.php?p=10856657&postcount=13
Not that elegant, but gets the job done.

Mar
31

E4 XWT allows for xml layout with SWT

As I explained earlier (http://wijsmullerbros.nl/content/SWT-and-XWT), I've tried some stuff with the eclipse 4 XWT system.
Personally I don't like the data binding very much, but I am very satisfied with the xml layout functionality that XWT delivers.

To work in a highly testable way (unit testing), I've set up a project with helper classes to support the MVP design.
Have a look at: http://code.google.com/p/xwt-passive-view

I hope that eclipse 4 will be released this year, and that on the other hand the XWT libraries will be released as maven artifacts with proper versioning.

In the meantime I still think that using my library (and SWT) beats Swing anytime. SWT remains simple, has a native look and it's fast.

Mar
29

Contract first JAX-WS and Boolean getters

During my efforts to implement a contract first SOAP webservice using JAX-WS I ran into some trouble with Boolean (object) getters on generated classes.

The problem got bigger when the objects were included in JSF pages that force the use of the javabeans standard for property access.

The maven plugin we use is "jaxws-maven-plugin" and by default it generates using the default settings for the java class generating steps, that is bugged.

In the earlier versions of JAX-WS, there is a problem with the Boolean object getters, they are generated using the "is" pattern, which is wrong (according to the java beans standard). The accessors should be named getters instead because the field may be null.

The solution for us was to add the following to the configuration part of the plugin:

<xjcArgs>
     <xjcArg>-enableIntrospection</xjcArg>
</xjcArgs>

This activates the fixed behavior of JAX-WS. Note that this only works on recent minor versions of the JVM, in which the fix is included. This goes for both java 5 & 6.

All is well now :)

Feb
3

Selecting wicket components using Selenium WebDriver

When testing a wicket application using selenium you're bound to run into some trouble.
Wicket uses id's with the wicket namespace prefix, which works fine until you try to execute xpath queries against it. This is what Selenium does.
One workaround would be to just use the normal html id's, but this poses limitations on your css/javascript code and polutes the production output code.

Wicket provides a way to add a unique identifier for each rendered component, that only renders in development mode, named the "wicketpath" attribute.

To use wicketpath, enable the output of wicket paths in your application class:

    @Override
    protected void init() {
           super.init();
           getDebugSettings().setOutputComponentPath(true);
    }

My question: is there a way to configure this ouside code? (without writing it myself ;D)

To make searching on wicket paths a little more convenient I created a little extension to the By class of selenium:

public class WicketBy extends By {
   
    private final String xpathExpression;
    private final String wicketPath;

    /**
     * Creates a new instance of {@link WicketBy}.
     * @param wicketPath the wicket path (eg: "id1:id2:id3")
     */
    private WicketBy(String wicketPath) {
      this.wicketPath = wicketPath;
      this.xpathExpression = convert(wicketPath);
    }
   
    /**
     * Factory method to create this specific By.
     * @param wicketPath the wicket path (eg: "id1:id2:id3")
     * @return By of type WicketBy
     */
    public static By wicketPath(String wicketPath) {
        return new WicketBy(wicketPath);
    }

    private String convert(String wicketPath) {
        String renderedPathVal = wicketPath.replaceAll(":", "_");
        return String.format("//*[@wicketpath='%s']", renderedPathVal);
    }

    @Override
    public List<WebElement> findElements(SearchContext context) {
      return ((FindsByXPath) context).findElementsByXPath(xpathExpression);
    }

    @Override
    public WebElement findElement(SearchContext context) {
      return ((FindsByXPath) context).findElementByXPath(xpathExpression);
    }

    @Override
    public String toString() {
      return "By.wicketPath: " + wicketPath + " (xpath: " + xpathExpression + ")" ;
    }

}

This allows selecting on "content:tabs:tab1:titlebar:title" for instance. Just using the actual output from the page (Selenium IDE will do that) is also perfectly ok, then it would become: "content_tabs_tab1_titlebar_title" which will be found.

Small example of how to use it:

     getDriver().findElement(ByWicket.wicketPath("container:submit")).click();

Ok, this is starting to look nice.

Nov
29

Linux mint on a dell precision m4500 laptop

For everyone that is trying to install or wants to install the latest edition of linux mint "lisa" on a dell m4500, you'll be in some trouble.
The live dvd boots really nice, but only the external monitor gets a signal! Very unpractical.
I've finally gotten it to work by tweaking the nvidia adapter. The trick is to press alt on the grub boot menu, the countdown. Then add the options nomodeset and vga=normal.
Now you can install and download drivers etc, maybe later improve the resolution ;-) Nice.

1 comment

Anonymous

After having installed mint, choosing the newest version of the nvidea driver fixes things. Just to clarify, it's not all that bad :)

Nov
19

SWT is awesome again using e4 XWT

Eclipse 4 is definitely going to be a major improvement, first of all because of the fixed maven support, but there is more!

Part of e4 (the new eclipse), is a new way to describe SWT layouts, named "XWT" (do not confuse with xwt.org).
In one of the projects I was working on, we used Google web toolkit, that has this thing called UIBinder to help creating layouts. I found it quite convenient and an easy way to get a good feel for the actual layout.

It turns out that there's a tool called WindowBuilder pro, created by Google and recently donated to eclipse. This allows for designers to visually create layouts for Swt, Swing, GWT, etc. It works like a charm!

Now, since I'm using maven to fetch my dependencies, the project setup was not completely trivial. The libraries for XWT are not documented that well and are not available in any public maven repositories.
So, to get started I had to copy libraries from my eclipse installation (that uses swt), and mix and match the right ones. After having done this though, it's rock stable.

Actually there was a typo of the e4 XWT site which totally broke the system. After long dwellings along forums, I finally found the problem. I updated the e4 XWT page to show the correct examples.

http://wiki.eclipse.org/E4/XWT

I'm very glad that I don't have to fall back to the Netbeans Swing designer and/or code generation.
I will post the list of libraries needed here asap, since I can highly recommend using XWT!

2 comments

braam

I'm currently trying out some Model-View-Presenter tricks with XWT, it's looking quite promising, so maybe I'll be posting some more soon.

braam

These are the libraries I used to get things started with e4 XWT:

org.eclipse.core.commands_3.6.0.I20110111-0800.jar
org.eclipse.core.databinding.observable_1.4.0.I20110222-0800.jar
org.eclipse.core.databinding_1.4.0.I20110111-0800.jar
org.eclipse.e4.xwt.forms_0.9.1.SNAPSHOT.jar
org.eclipse.e4.xwt_0.9.1.SNAPSHOT.jar
org.eclipse.equinox.common_3.6.0.v20110523.jar
org.eclipse.jface.databinding_1.5.0.I20100907-0800.jar
org.eclipse.jface_3.7.0.I20110522-1430.jar
swt-debug.jar

Oct
27

Fixing Oneiric's gui

I've been running and using the latest release of Ubuntu, named Oneiric Ocelot, since the first beta version. There are many improvements, and I do really like to keep up with the newest features.

There is one problem though, both the new Gnome(3) shell and Unity, the other shell, or both nasty! I honestly don't like all the fancy graphics uselessly boring me to death, and the "clean" interface which means for me that all useful quick ways to do stuff, are gone.

But I've stopped worrying and learned to love the [bomb] Unity gui, with the following tweaks though:

* Install synaptic using the "software center", because the latter one is really slow, does not do what I want, has less software listed somehow and is just not ready for any serious use.

* Change the default Unity behavior using "compizconfig-settings-manager". For instance, I don't use the mouse that much, so I just want the windows button to pop up the menu bar thingy, otherwise just leave it alone. Also I want to cycle through ALL applications using ALT+Tab, not just some of them. This is possible, just tweak the right combination of compiz plugins.

* Check out this list of "indicators" which bring back all the nice applets for cpu freq settings, international characters, weather updates, cpu usage, etc. Some of these I just need, end of discussion.
http://askubuntu.com/questions/30334/list-of-application-indicators/3799...

* Customize the new login screen, put your own image there, by installing "simple lightdm manager":
http://www.ubuntugeek.com/simple-lightdm-manager.html

Given all these tweaks I'm kind of ready to also start using it at work. It is a shame that such a drop in usability is apparently needed to migrate from the deprecated system that gnome 2 really was. Hopefully, and I do expect that it will, the default gui experience will improve a lot in the next version.

2 comments

Anonymous

Same here, upgraded home and work pc/laptop from Ubuntu 11.04 to 11.10. Played a bit with Gnome 3 and with Unity. I feel more attracted to Gnome 3 than Unity, but because Unity it so much better integrated in Ubuntu I'll stick with Unity for now.
But I'll really keep a VM running Gnome 3 to keep up with that, as I really like the possible tweaking Gnome 3 supports, and.. it's Gnome, it's waaaay better tested than Unity can ever be (in my humble opinion :)). They both just miss the nice little tools that were already build for Gnome 2 in the last decade.

braam

Yesterday I was once more frustrated about the all to well known usability problems with unity, and thought "why again am I using this?". So I finally gave up and just installed gnome-shell and I have now started using the classic! session.
With some tweaking here and there I now have the old way of working back again, including the good version of alt-tab, virtual desktops, sensible menus, awesome keyboard shortcuts, application status bar, a gnome bar having shortcuts always available, etc. Ahhhhh, so good to be back.

Oct
10

Working with currencies in GWT

Another hurdle taken; currencies.

Say you want to display a product priced at 25 dollars an 45 cents, you should be able to use the GWT NumberFormat to get $ 25.45 or $ 25,45 using the Dutch locale for instance.

It turns out though, that there is no way to specify the currency symbol, so your always supposed to use the "default" currency for your locale. This is quite strange because I can imagine that there are countries using more than one currency?

My solution is has been to use the Messages system to define a format, such as:

@DefaultMessage("{0} {1,number,###,###.00}")

where 0 is the symbol and 1 is the amount. This allows a different format for each language, so it's quite flexible.
Next is the currency symbol itself. It can't be determined on the server, and sending it from the client just seems a little to much trouble.
Thankfully GWT does provide a way to access the list of symbols that it houses, you just have to know where to find it (I found it here).
private static CurrencyCodeMapConstants lookup = GWT.create(CurrencyCodeMapConstants.class);
Map currencyMap = lookup.getCurrencyMap();
String symbol = currencyMap.get(currencyCode);

That's it, combining the formatting with this lookup solves my use case. Google does not document these things that well, but I'm glad we have the sources so we can figure it out anyway.

Oct
8

GWT: Example on how to pass init data through the host page

In my last post I talked a little about how the host page can supply data for the client application.

Now I would like to show in some more detail how to use the AutoBean system for this purpose.

The MyInitDataFactory is my custom arbitrary marker interface that extends the AutoBeanFactory interface which is responsible for the AutoBean magic.

The MyInitData class implements my simple custom IMyInitData interface, which allows the client side to generate a implementation, compile time, that can be parsed from Json code.

Server side:

MyInitData data = new MyInitData("interestingValue");

MyInitDataFactory factory = AutoBeanFactorySource.create(MyInitDataFactory.class);
       
        AutoBean<IMyInitData> autoBean = factory.create(IMyInitData.class, data);
       
        Splittable splittable = AutoBeanCodex.encode(autoBean);
       
        // not strictly needed, but highly advisable if data is dynamic!
        String json = ESAPI.encoder().encodeForJavaScript(splittable.getPayload());
       
        String formattedJson = String.format("var hostPageVar = {\n\tjson : \"%s\"\n}\n", json);

// render the formattedJson inside a script tag on the host page, using spring or some template system

Client side:

MyInitDataFactory factory = GWT.create(MyInitDataFactory.class)

        Dictionary dictionary = Dictionary.getDictionary("hostPageVar");
        String json = dictionary.get("json");

        AutoBean<IMyInitData> autoBean = AutoBeanCodex.decode(factory, IMyInitData.class, json);

        IMyInitData result = autoBean.as();

I hope that this sheds some light on how to pass data to the client through the host page without to much custom code. Google does not really seem to give any hints about how to do this, and I couldn't find any examples really showing how to use the AutoBean system for this.

1 comment

Anonymous

Something that I did not realize before was that though collections and custom interfaces are supported as properties of an AutoBean, collections containing custom interfaces are not.
The reason is that the AutoBean mechanism is supposed to work server and client side. On the client side, there is no support for reflection and generics, so the information about the contents of a list is lost.
This is quite a restriction and basically means that we will need to change the layout of our data to not produce any lists having custom class contents.

Oct
6

more gwt, the host page

To start a GWT application, the client will often need some data to work with. Ideally this needs to happen without any extra requests fired. So not using rpc calls.
so, how to get server based data to the javascript world?

Our solution first was to use the Dictionary system. A spring requesthandler (servlet) renders the data to the page using a custom formatter and simple maps.
It worked, but in time the data became more complex and using simple maps was getting really complicated!

The next step has been to introduce the AutoBean system, part of GWT. It allows to covert a hierarchy of classes into json, and back into java/javascript. So combining this with a single dictionary works really nicely!

I'll post some urls later on these steps.

Oh and when passing javascript to the client, take security into consideration. Take a look at the Owasp threats and the ESAPI responses to them. Its actually not that hard to use, though the amount of features is a bit overwhelming.

Whats next?