Thursday, August 8, 2013

Want to monitor your progress while rendering a BIRT report at a finer level then just page level and actually know how many elements you've done and how many are left?

First, record all the line numbers of every element in your report

            final TreeSet lineNos = new TreeSet();
            for (DesignElement de : rpd.getAllElements())
                lineNos.add(rpd.getLineNo(de));



Then you add a progress monitor to your task in the usual way, and at the start of each query you get the line number of the element being processed.


EventBus Annotation Processor

I was playing with EventBus to allow communication between classes. One thing that bothered me was that to use the Annotations system (eg,  @EventSubscriber(eventClass=StatusEvent.class) ), you have to have the annotation processed by calling:

org.bushe.swing.event.annotation.AnnotationProcessor.process(this)

Where this is the object that wants to register all it's annotations. However, you have to add a call to that in every class that will have that annotation.
Well, screw that. I got eclipse and I want it to be automatic.

Long story short, you gotta write your own annotation processor. Its not particularly complicated,but I'll just go and give you teh source and codez: Event Bus Annotation Processor
You plug it into Eclipse using the following instructions: Getting started with APT
Now, once that's working you'll get a file called eventbus.classes appearing in the .apt_generated directory.
That file contains a list of all classes that use the EventSubscriber annotation, but we still need a way to automatically get those classes to register with EventBus. You could play with classloading, but i chose Javassist.

Simply put, some code reads the eventbus.classes file, and uses Javassist to embed a call to register the instance at the end of every constructor in the class:

CtClass ctclass = ClassPool.getDefault().get(classname);
CtConstructor[] ctconstructor = ctclass.getConstructors();
for (CtConstructor c : ctconstructor)
{
 c.insertAfter("org.bushe.swing.event.annotation.AnnotationProcessor.process(this);");
}
ctclass.toClass(null, null);



And that is that. Everytime a class of that kind is instantiated, you'll get it auto registering to EventBus without you having to do it yourself.

All you need is a call to begin the reading of eventbus.classes.

Note: If you use some kind of serializing library that doesn't call constructors (eg, XStream), you'll need to register it yourself. You can either do that when it's loading, or if you are feeling adventurous you could extend the Javassist code above to include a call to the annotation processor in the readResolve() method XStream uses.

Tuesday, July 16, 2013

Upgrading the BIRT Web Viewer Example prototype.js version.

The latest version of BIRT (4.2) comes with an OLD version of prototype.js. 1.4.. It so old it doesn't even show on the prototype.js page anymore. If you want to use jquery you also need to upgrade the prototype.js version.

But if you upgrade the prototype.js version to 1.7 the viewer will suddenly stop working properly including things like the progress bar not showing, and being unable to click on stuff.

To fix it, you need to follow the advice in this article which mentions some things that have changed between 1.4 and 1.5. Specifically this part which talks about the backwards compatibility:


====================
Backward compatibility change: toggle(), show(), and hide(), as well as Field.clear() and Field.present(), no longer take an arbitrary number of arguments. Before upgrading to Prototype 1.5, check the various JS files in Birt/webcontent/birt/ajax for instances like this:

Element.toggle('page', 'sidebar', 'content') // Old way; won't work in 1.5
['page', 'sidebar', 'content'].each(Element.toggle) // New way; 1.5-compatible


Element.show('page', 'sidebar', 'content') // Old way; won't work in 1.5
['page', 'sidebar', 'content'].each(Element.show) // New way; 1.5-compatible


Element.hide('page', 'sidebar', 'content') // Old way; won't work in 1.5
['page', 'sidebar', 'content


====================

Sunday, June 9, 2013

Eve-Central Trade Finder results fix

When I was playing a bit of Eve Online, I loved using the Trade Finder from Eve-Central. It helped me make my first 100 million when some dude put a zero in the wrong place when buying some guns. A bit of trading here to there with heart beating hoping no-one would beat me and wooo! money enough to keep me going for a while.

However, the search results returned aren't exactly the best and are poorly formatted and hard to read.
Luckily for me, a bit of Greasemonkey lets me make the results into an actual table, and Stylish lets me make it easier to read. Problem is solved!

Source: Stylish Script
Source: GreaseMonkey script



Thursday, May 31, 2012

WMI Query failed. Provider failure.

While trying to use the Share and Storage Manager on a Windows 2008 R2 server, it kept throwing an error:

Volume Query Failed.
WMI Query Failed. Provider failure.

I eventually tracked it down to an issue with TrueCrypt 7.1a. It seems that when TrueCrypt unmounts a drive, it can sometimes leave behind a "ghost" volume, that is invalid and causes the manager to throw the error. You can test if this is the cause on your machine by typing "mountvol.exe" and looking for any errors like "The system cannot find the file specified". This bug/issue was mentioned on the TrueCrypt forums back in 2008, so it's not new.

The only solution I've come up with is to make a tiny TrueCrypt container, and leave it mounted on that drive.

Edit: Included link to Truecrypt forums post about issue.

Tuesday, May 29, 2012

Revit slow saving to SMB share

So you are using Revit, and notice that saving to a SMB share is horribly slow? Is the SMB share on a Domain Controller? When saving a file to the server do you notice 100% utilization of your server disk?

Well, it turns out that when saving a file, Revit uses a mode called "Write Through". What this means is that the "save" will not finish until the entire file has been written to disk. This bypasses any write cache that Windows might utilize. It's even worse if the share is on a Domain Controller since by default Domain Controllers will disable write caching on the disk.

So, this results in extremely slow writes.
The solution? Well, there isn't one really. You have to move the share off the domain controller. Then ensure the disk on the server you are saving to is fast enough to amount of data being written to it.

Monday, April 16, 2012

Help my walls show up on the plan but not the 3D View!

A common problem. So common I decided to write a checklist to follow if an object doesn't show up in a Revit view. This list is not exhaustive, but covers most of the problems we've had so far.

Examine View Properties

  • Check view range
  • Check region cut
  • Check view distance
  • Check view co-ordination – use coordination view if in doubt. Remember to mouse over view to cause it to redraw.
  • Check view detail fine/coarse – Use fine if in doubt
  • Check current render type - hidden line/shaded/realistic. Some materials only display properly when actually rendered.

Examine Object in View

  • Check object visibility settings – Ensure no settings are overridden.
    • By Element
    • By Category
    • By Filter
  • Check object override settings – Ensure no settings are overridden. In particular ensure you are checking the correct pattern. Surface Pattern is different to Cut pattern.
    • By Element
    • By Category
    • By Filter
  • Examine and remove extra paint applied to object. If in doubt, use the remove paint tool anyway just to ensure nothing is painted on.
  • Switch view to “Reveal hidden elements” mode, as it may be not visible.

Examine Material used

  • Examine Material
    • Examine use-render appearance
  • If surface fill pattern, check draft/model type

Examine Object Properties

  • Examine if using correct external/internal layers
  • If it's a wall, check its orientation, if the internal is facing out, then the wall will need to be flipped so the external layer is outside.
  • Check which phase the object is in.

Check Revisions or Work Set

  • Check which revision or work set the object is in; ensure your current view matches.