コード例 #1
0
ファイル: DBNDatabaseNode.java プロジェクト: thecocce/dbeaver
  private static Method findPropertyGetter(Class<?> clazz, String getName, String isName) {
    Method[] methods = clazz.getDeclaredMethods();

    for (Method method : methods) {
      if ((!Modifier.isPublic(method.getModifiers()))
          || (!Modifier.isPublic(method.getDeclaringClass().getModifiers()))
          || (method.getReturnType().equals(void.class))) {
        // skip
      } else if (method.getName().equals(getName)
          || (method.getName().equals(isName) && method.getReturnType().equals(boolean.class))) {
        // If it matches the get name, it's the right method
        Class<?>[] parameterTypes = method.getParameterTypes();
        if (parameterTypes.length == 0
            || (parameterTypes.length == 1 && parameterTypes[0] == DBRProgressMonitor.class)) {
          return method;
        }
      }
    }
    return clazz == Object.class
        ? null
        : findPropertyGetter(clazz.getSuperclass(), getName, isName);
  }
コード例 #2
0
  @Override
  public Object getAdapter(Object adaptableObject, Class adapterType) {
    if (adapterType == DBSDataSourceContainer.class) {
      if (adaptableObject instanceof DBNDataSource) {
        return ((DBNDataSource) adaptableObject).getDataSourceContainer();
      }
      DBSObject object = null;
      if (adaptableObject instanceof DBSWrapper) {
        object = ((DBSWrapper) adaptableObject).getObject();
      } else if (adaptableObject instanceof DBSObject) {
        object = (DBSObject) adaptableObject;
      }
      if (object == null) {
        return null;
      }
      if (object instanceof DBSDataSourceContainer) {
        return object;
      }
      DBPDataSource dataSource = object.getDataSource();
      return dataSource == null ? null : dataSource.getContainer();
    } else if (DBPObject.class.isAssignableFrom(adapterType)) {
      DBPObject object = null;
      if (adaptableObject instanceof DBSWrapper) {
        object = ((DBSWrapper) adaptableObject).getObject();
      } else if (adaptableObject instanceof DBPObject) {
        object = (DBPObject) adaptableObject;
      }
      if (object != null && adapterType.isAssignableFrom(object.getClass())) {
        return object;
      }
    } else if (IResource.class.isAssignableFrom(adapterType)) {
      if (adaptableObject instanceof DBNResource) {
        IResource resource = ((DBNResource) adaptableObject).getResource();
        if (resource != null && adapterType.isAssignableFrom(resource.getClass())) {
          return resource;
        } else {
          return null;
        }
      }
    } else if (adapterType == IPropertySource.class) {
      DBPObject dbObject = null;
      if (adaptableObject instanceof DBSWrapper) {
        dbObject = ((DBSWrapper) adaptableObject).getObject();
      } else if (adaptableObject instanceof DBPObject) {
        dbObject = (DBPObject) adaptableObject;
      }
      if (dbObject instanceof IPropertySource) {
        return dbObject;
      }
      if (dbObject instanceof DBPPropertySource) {
        return new PropertySourceDelegate((DBPPropertySource) dbObject);
      }
      if (dbObject instanceof IAdaptable) {
        Object adapter = ((IAdaptable) dbObject).getAdapter(IPropertySource.class);
        if (adapter != null) {
          return adapter;
        }
        adapter = ((IAdaptable) dbObject).getAdapter(DBPPropertySource.class);
        if (adapter != null) {
          return new PropertySourceDelegate((DBPPropertySource) adapter);
        }
      }
      if (dbObject != null) {
        PropertyCollector props = new PropertyCollector(adaptableObject, dbObject, true);
        props.collectProperties();
        if (props.isEmpty() && adaptableObject instanceof DBSObject) {
          // Add default properties
          DBSObject meta = (DBSObject) adaptableObject;
          props.addProperty(
              null, "name", CoreMessages.model_navigator_Name, meta.getName()); // $NON-NLS-1$
          props.addProperty(
              null,
              "desc",
              CoreMessages.model_navigator_Description,
              meta.getDescription()); // $NON-NLS-1$
        }
        return new PropertySourceDelegate(props);
      }
    } else if (adapterType == IWorkbenchAdapter.class) {
      // Workbench adapter
      if (adaptableObject instanceof DBNNode) {
        final DBNNode node = (DBNNode) adaptableObject;
        return new WorkbenchAdapter() {
          @Override
          public ImageDescriptor getImageDescriptor(Object object) {
            return DBeaverIcons.getImageDescriptor(node.getNodeIconDefault());
          }

          @Override
          public String getLabel(Object o) {
            return node.getNodeName();
          }

          @Override
          public Object getParent(Object o) {
            return node.getParentNode();
          }
        };
      } else {
        return null;
      }
    }
    return null;
  }