tags:

views:

13

answers:

1

Hi,

I am using Google Window Builder Pro for SWT and we use a lot of custom components here. The components rely on being used within our framework, but this makes them unusable in Window Builder (exeptions are thrown when used outside of our framework, like, in Window Builder).

How do I detect that Window Builder is using our components to skip the code that relies on our framework?

A: 

I implemented a Utility function that dumps a StackTrace and looks for stuff from Instantiations in it. This works perfectly:

/**
 * Designer mode. This is used to detect if the widgets are running
 * from SWT designer, because in this case we have to skip some
 * initialization code.
 */
private static Boolean designerMode;

/**
 * This is used to detect if the widgets are running
 * from SWT designer, because in this case we have to skip some
 * initialization code.
 */
public static boolean isDesignerMode() {
    if( designerMode == null ) {
        String s = StacktraceUtils.getStackTraceAsString(
                new RuntimeException("Just to get the Stacktrace."));
        designerMode = s.contains("com.instantiations.designer");  
    }
    return designerMode;
}
Daniel