Exemplo n.º 1
0
 @Override
 public String getNodeName() {
   DBSObject object = getObject();
   if (object == null) {
     return DBConstants.NULL_VALUE_LABEL;
   }
   String objectName;
   if (object instanceof DBPOverloadedObject) {
     objectName = ((DBPOverloadedObject) object).getOverloadedName();
   } else {
     objectName = object.getName();
   }
   if (CommonUtils.isEmpty(objectName)) {
     objectName = object.toString();
     if (CommonUtils.isEmpty(objectName)) {
       objectName = object.getClass().getName() + "@" + object.hashCode(); // $NON-NLS-1$
     }
   }
   /*
           if (object instanceof DBSObjectUnique) {
               String uniqueName = ((DBSObjectUnique) object).getUniqueName();
               if (!uniqueName.equals(objectName)) {
                   if (uniqueName.startsWith(objectName)) {
                       uniqueName = uniqueName.substring(objectName.length());
                   }
                   objectName += " (" + uniqueName + ")";
               }
           }
   */
   return objectName;
 }
Exemplo n.º 2
0
 private void makeProposalsFromChildren(
     DBRProgressMonitor monitor,
     DBSObject parent,
     @Nullable String startPart,
     List<SQLCompletionProposal> proposals) {
   if (startPart != null) {
     startPart = wordDetector.removeQuotes(startPart).toUpperCase();
     int divPos = startPart.lastIndexOf(editor.getSyntaxManager().getStructSeparator());
     if (divPos != -1) {
       startPart = startPart.substring(divPos + 1);
     }
   }
   try {
     Collection<? extends DBSObject> children = null;
     if (parent instanceof DBSObjectContainer) {
       children = ((DBSObjectContainer) parent).getChildren(monitor);
     } else if (parent instanceof DBSEntity) {
       children = ((DBSEntity) parent).getAttributes(monitor);
     }
     if (children != null && !children.isEmpty()) {
       for (DBSObject child : children) {
         if (startPart != null && !child.getName().toUpperCase().startsWith(startPart)) {
           continue;
         }
         proposals.add(makeProposalsFromObject(monitor, child));
       }
     }
   } catch (DBException e) {
     log.error(e);
   }
 }
Exemplo n.º 3
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;
  }