コード例 #1
0
ファイル: UIUtils.java プロジェクト: ralic/dbeaver
 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;
   }
 }
コード例 #2
0
 private Object createXmlObject(JDBCSession session, InputStream stream) throws DBCException {
   try {
     return BeanUtils.invokeStaticMethod(
         DBUtils.getDriverClass(dataSource, OracleConstants.XMLTYPE_CLASS_NAME),
         "createXML",
         new Class[] {java.sql.Connection.class, java.io.InputStream.class},
         new Object[] {session.getOriginal(), stream});
   } catch (SQLException e) {
     throw new DBCException(e, session.getDataSource());
   } catch (Throwable e) {
     throw new DBCException("Internal error when creating XMLType", e, session.getDataSource());
   }
 }
コード例 #3
0
ファイル: DBNDatabaseNode.java プロジェクト: thecocce/dbeaver
 private Class<?> getChildrenClass(DBXTreeItem childMeta) {
   Object valueObject = getValueObject();
   if (valueObject == null) {
     return null;
   }
   String propertyName = childMeta.getPropertyName();
   Method getter = findPropertyReadMethod(valueObject.getClass(), propertyName);
   if (getter == null) {
     return null;
   }
   Type propType = getter.getGenericReturnType();
   return BeanUtils.getCollectionType(propType);
 }
コード例 #4
0
 private String getLocalizedString(String string, String type, String defaultValue) {
   if (Property.DEFAULT_LOCAL_STRING.equals(string)) {
     Method getter = getGetter();
     String propertyName = BeanUtils.getPropertyNameFromGetter(getter.getName());
     Class<?> propOwner = getter.getDeclaringClass();
     Bundle bundle = FrameworkUtil.getBundle(propOwner);
     ResourceBundle resourceBundle = Platform.getResourceBundle(bundle);
     String messageID = "meta." + propOwner.getName() + "." + propertyName + "." + type;
     String result = null;
     try {
       result = resourceBundle.getString(messageID);
     } catch (Exception e) {
       // Try to find the same property in parent classes
       for (Class parent = getter.getDeclaringClass().getSuperclass();
           parent != null && parent != Object.class;
           parent = parent.getSuperclass()) {
         try {
           Method parentGetter = parent.getMethod(getter.getName(), getter.getParameterTypes());
           Class<?> parentOwner = parentGetter.getDeclaringClass();
           Bundle parentBundle = FrameworkUtil.getBundle(parentOwner);
           if (parentBundle == null || parentBundle == bundle) {
             continue;
           }
           ResourceBundle parentResourceBundle = Platform.getResourceBundle(parentBundle);
           messageID = "meta." + parentOwner.getName() + "." + propertyName + "." + type;
           try {
             result = parentResourceBundle.getString(messageID);
             break;
           } catch (Exception e1) {
             // Just skip it
           }
         } catch (NoSuchMethodException e1) {
           // Just skip it
         }
       }
       if (result == null) {
         if (type.equals(Property.RESOURCE_TYPE_NAME)) {
           log.debug(
               "Resource '" + messageID + "' not found in bundle " + bundle.getSymbolicName());
         }
         return defaultValue;
       }
     }
     if (!result.equals(messageID)) {
       return result;
     }
     return defaultValue;
   }
   return string;
 }
コード例 #5
0
  public ObjectPropertyDescriptor(
      DBPPropertySource source,
      ObjectPropertyGroupDescriptor parent,
      Property propInfo,
      Method getter) {
    super(source, parent, getter, propInfo.id(), propInfo.order());
    this.propInfo = propInfo;

    final String propertyName = BeanUtils.getPropertyNameFromGetter(getter.getName());
    declaringClass = getter.getDeclaringClass();
    Class<?> c = declaringClass;
    while (setter == null && c != Object.class && c != null) {
      this.setter = BeanUtils.getSetMethod(c, propertyName);
      if (setter == null) {
        c = c.getSuperclass();
      }
    }

    // Obtain value transformer
    Class<? extends IPropertyValueTransformer> valueTransformerClass = propInfo.valueTransformer();
    if (valueTransformerClass != null && valueTransformerClass != IPropertyValueTransformer.class) {
      try {
        valueTransformer = valueTransformerClass.newInstance();
      } catch (Throwable e) {
        log.warn("Can't create value transformer", e);
      }
    }

    this.propName =
        propInfo.hidden()
            ? getId()
            : getLocalizedString(propInfo.name(), Property.RESOURCE_TYPE_NAME, getId());
    this.propDescription =
        CommonUtils.isEmpty(propInfo.description())
            ? propName
            : getLocalizedString(propInfo.name(), Property.RESOURCE_TYPE_DESCRIPTION, propName);
  }
コード例 #6
0
ファイル: DBNDatabaseNode.java プロジェクト: thecocce/dbeaver
 public static Method findPropertyReadMethod(Class<?> clazz, String propertyName) {
   String methodName = BeanUtils.propertyNameToMethodName(propertyName);
   return findPropertyGetter(clazz, "get" + methodName, "is" + methodName);
 }