Ejemplo n.º 1
0
  /**
   * Create an image descriptor for the given image property in the text.properties file.
   *
   * @param propertyName
   * @return
   */
  public static ImageDescriptor getDescriptor(String propertyName) {

    try {

      if (propertyName == null) {
        return null;
      }

      // get image path
      String path = Messages.getString(propertyName);

      if (path == null || path.trim().length() == 0) {
        SqlBuilderPlugin.log(
            Messages.getString("ImageUtil.logMessage2", propertyName), null); // $NON-NLS-1$
        return null;
      }

      // create image
      URL url = URLUtil.getResourceURL(path);
      return ImageDescriptor.createFromURL(url);

    } catch (Exception e) {
      SqlBuilderPlugin.log(
          Messages.getString("ImageUtil.logMessage3", propertyName), e); // $NON-NLS-1$
      return null;
    }
  }
Ejemplo n.º 2
0
  /**
   * Dispose of an image in cache. Once there are no more open handles to the image it will be
   * disposed of.
   */
  @SuppressWarnings("unchecked") // $NON-NLS-1$
  public static void disposeImage(String propertyName) {

    try {

      Image image = (Image) pimages.get(propertyName);

      if (image == null) {
        return;
      }

      image.dispose();
      pimages.remove(propertyName);

      // decrease image handle count by one

      Integer handleCount = (Integer) pimageCount.get(propertyName);

      if (handleCount == null) {
        handleCount = new Integer(0);
      } else {
        handleCount = new Integer(handleCount.intValue() - 1);
      }
      pimageCount.put(propertyName, handleCount);

    } catch (Throwable e) {
      SqlBuilderPlugin.log(Messages.getString("ImageUtil.logMessage1"), e); // $NON-NLS-1$
    }
  }
Ejemplo n.º 3
0
  public static ImageDescriptor getFragmentDescriptor(String fragmentId, String path) {

    try {

      if (path == null || path.trim().length() == 0) {
        return null;
      }

      // create image
      URL url = URLUtil.getFragmentResourceURL(fragmentId, path);
      return ImageDescriptor.createFromURL(url);

    } catch (Exception e) {
      SqlBuilderPlugin.log(
          Messages.getString("ImageUtil.logMessage3") + fragmentId + ": " + path,
          e); //$NON-NLS-1$ //$NON-NLS-2$
      return null;
    }
  }