开发者

Detect Window Builder

开发者 https://www.devze.com 2023-01-18 05:57 出处:网络
I am using Google Window Bui开发者_开发知识库lder 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

I am using Google Window Bui开发者_开发知识库lder 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?


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;
}


You can print the Stacktrace as String this way (the getStackTraceAsString() method is missing from Daniel's answer):

public static String getStackTraceAsString(Throwable t) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    t.printStackTrace(pw);
    return sw.toString(); // stack trace as a string
}
0

精彩评论

暂无评论...
验证码 换一张
取 消