Example #1
0
 public static boolean hasStyle(final Widget w, final int style) {
   if ((w == null) || w.isDisposed()) return false;
   return UIThreadRunnable.syncExec(
       w.getDisplay(),
       new BoolResult() {
         public boolean run() {
           return (w.getStyle() & style) != 0;
         }
       });
 }
Example #2
0
 /** See {@link #getIcon(File, Image)}. */
 @Nullable
 public Image getIcon(@NotNull String filename, @Nullable Image defaultIcon) {
   String extension = Util.getExtension(filename);
   Image image = fileIconMap.get(extension);
   if (image != null) return image;
   Program program = Program.findProgram(extension);
   if (program == null) return defaultIcon;
   ImageData imgData = program.getImageData();
   if (imgData == null) return defaultIcon;
   image = new Image(disposeWidget.getDisplay(), imgData);
   fileIconMap.put(extension, image);
   return image;
 }
Example #3
0
  public static String getText(final Object w) {
    if ((w instanceof Widget) && !((Widget) w).isDisposed()) {
      final Widget widget = (Widget) w;
      return UIThreadRunnable.syncExec(
          widget.getDisplay(),
          new StringResult() {

            public String run() {
              Object returnV = ReflectionUtil.invokeMethod("getText", widget);
              return (String) returnV;
            }
          });
    }
    return null;
  }
Example #4
0
  /**
   * Invokes method
   *
   * @param object
   * @param methodName
   * @return
   */
  public static Object invokeMethod(final Object object, String methodName) {

    final Method method;
    try {
      method = object.getClass().getMethod(methodName, new Class[0]);
    } catch (Exception e) {
      throw new RuntimeException("Cannot get method : " + e.getMessage());
    }
    Widget widget = null;
    final Object result;
    if (object instanceof Widget) {
      widget = (Widget) object;
      result =
          UIThreadRunnable.syncExec(
              widget.getDisplay(),
              new Result<Object>() {
                public Object run() {
                  Object o = null;
                  try {
                    o = method.invoke(object, new Object[0]);
                  } catch (Exception e) {
                    try {
                      throw new RuntimeException("Cannot invoke method : " + e.getMessage());
                    } catch (Exception e1) {
                      // TODO Auto-generated catch block
                      e1.printStackTrace();
                    }
                  }
                  return o;
                }
              });
    } else
      try {
        result = method.invoke(object, new Object[0]);
      } catch (Exception e) {
        throw new RuntimeException("Cannot invoke method : " + e.getMessage());
      }

    return result;
  }
Example #5
0
 /**
  * Loads an image from the jar
  *
  * @param widget the SWT widget
  * @param image the path to image to be loaded
  * @return the loaded image
  */
 public static Image loadImage(Widget widget, String image) {
   return loadImage(widget.getDisplay(), image);
 }