/**
  * Returns an {@link Image} stored in the file at the specified path relative to the specified
  * class.
  *
  * @param clazz the {@link Class} relative to which to find the image
  * @param path the path to the image file, if starts with <code>'/'</code>
  * @return the {@link Image} stored in the file at the specified path
  */
 public static Image getImage(Class<?> clazz, String path) {
   String key = clazz.getName() + '|' + path;
   Image image = m_imageMap.get(key);
   if (image == null) {
     try {
       image = getImage(clazz.getResourceAsStream(path));
       m_imageMap.put(key, image);
     } catch (Exception e) {
       image = getMissingImage();
       m_imageMap.put(key, image);
     }
   }
   return image;
 }
Example #2
0
 public static CellEditor createCellEditor(
     Composite parent, Object object, DBPPropertyDescriptor property) {
   // List
   if (property instanceof IPropertyValueListProvider) {
     final IPropertyValueListProvider listProvider = (IPropertyValueListProvider) property;
     final Object[] items = listProvider.getPossibleValues(object);
     if (!ArrayUtils.isEmpty(items)) {
       final String[] strings = new String[items.length];
       for (int i = 0, itemsLength = items.length; i < itemsLength; i++) {
         strings[i] =
             items[i] instanceof DBPNamedObject
                 ? ((DBPNamedObject) items[i]).getName()
                 : CommonUtils.toString(items[i]);
       }
       final CustomComboBoxCellEditor editor =
           new CustomComboBoxCellEditor(
               parent,
               strings,
               SWT.DROP_DOWN | (listProvider.allowCustomValue() ? SWT.NONE : SWT.READ_ONLY));
       return editor;
     }
   }
   Class<?> propertyType = property.getDataType();
   if (propertyType == null || CharSequence.class.isAssignableFrom(propertyType)) {
     return new CustomTextCellEditor(parent);
   } else if (BeanUtils.isNumericType(propertyType)) {
     return new CustomNumberCellEditor(parent, propertyType);
   } else if (BeanUtils.isBooleanType(propertyType)) {
     return new CustomCheckboxCellEditor(parent);
     // return new CheckboxCellEditor(parent);
   } else if (propertyType.isEnum()) {
     final Object[] enumConstants = propertyType.getEnumConstants();
     final String[] strings = new String[enumConstants.length];
     for (int i = 0, itemsLength = enumConstants.length; i < itemsLength; i++) {
       strings[i] = ((Enum) enumConstants[i]).name();
     }
     return new CustomComboBoxCellEditor(parent, strings, SWT.DROP_DOWN | SWT.READ_ONLY);
   } else {
     log.warn("Unsupported property type: " + propertyType.getName());
     return null;
   }
 }