Example #1
0
 public DBSObjectFilter getNodeFilter(DBXTreeItem meta, boolean firstMatch) {
   DBPDataSourceContainer dataSource = getDataSourceContainer();
   if (dataSource != null && this instanceof DBNContainer) {
     Class<?> childrenClass = this.getChildrenClass(meta);
     if (childrenClass != null) {
       Object valueObject = getValueObject();
       DBSObject parentObject = null;
       if (valueObject instanceof DBSObject && !(valueObject instanceof DBPDataSource)) {
         parentObject = (DBSObject) valueObject;
       }
       return dataSource.getObjectFilter(childrenClass, parentObject, firstMatch);
     }
   }
   return null;
 }
Example #2
0
 public void setNodeFilter(DBXTreeItem meta, DBSObjectFilter filter) {
   DBPDataSourceContainer dataSource = getDataSourceContainer();
   if (dataSource != null && this instanceof DBNContainer) {
     Class<?> childrenClass = this.getChildrenClass(meta);
     if (childrenClass != null) {
       Object parentObject = getValueObject();
       if (parentObject instanceof DBPDataSource) {
         parentObject = null;
       }
       dataSource.setObjectFilter(this.getChildrenClass(meta), (DBSObject) parentObject, filter);
       dataSource.persistConfiguration();
     }
   } else {
     log.error("No active datasource - can't save filter configuration");
   }
 }
  @Override
  public void saveSettings(DBPDataSourceContainer dataSource) {
    DBPConnectionConfiguration connectionInfo = dataSource.getConnectionConfiguration();
    final Set<String> properties =
        metaURL == null ? Collections.<String>emptySet() : metaURL.getAvailableProperties();

    if (hostText != null && properties.contains(DriverDescriptor.PROP_HOST)) {
      connectionInfo.setHostName(hostText.getText().trim());
    }
    if (portText != null && properties.contains(DriverDescriptor.PROP_PORT)) {
      connectionInfo.setHostPort(portText.getText().trim());
    }
    if (serverText != null && properties.contains(DriverDescriptor.PROP_SERVER)) {
      connectionInfo.setServerName(serverText.getText().trim());
    }
    if (dbText != null && properties.contains(DriverDescriptor.PROP_DATABASE)) {
      connectionInfo.setDatabaseName(dbText.getText().trim());
    }
    if (pathText != null
        && (properties.contains(DriverDescriptor.PROP_FOLDER)
            || properties.contains(DriverDescriptor.PROP_FILE))) {
      connectionInfo.setDatabaseName(pathText.getText().trim());
    }
    if (userNameText != null) {
      connectionInfo.setUserName(userNameText.getText().trim());
    }
    if (passwordText != null) {
      connectionInfo.setUserPassword(passwordText.getText());
    }
    super.saveSettings(dataSource);
    if (isCustom) {
      if (urlText != null) {
        connectionInfo.setUrl(urlText.getText().trim());
      }
    } else {
      if (urlText != null && connectionInfo.getUrl() != null) {
        urlText.setText(connectionInfo.getUrl());
      }
    }
  }
Example #4
0
  /**
   * Extract items using reflect api
   *
   * @param monitor progress monitor
   * @param meta items meta info
   * @param oldList previous child items
   * @param toList list ot add new items @return true on success
   * @return true on success
   * @throws DBException on any DB error
   */
  private boolean loadTreeItems(
      DBRProgressMonitor monitor,
      DBXTreeItem meta,
      final DBNDatabaseNode[] oldList,
      final List<DBNDatabaseNode> toList)
      throws DBException {
    if (this.isDisposed()) {
      // Property reading can take really long time so this node can be disposed at this moment -
      // check it
      return false;
    }
    // Read property using reflection
    Object valueObject = getValueObject();
    if (valueObject == null) {
      return false;
    }
    String propertyName = meta.getPropertyName();
    Object propertyValue = extractPropertyValue(monitor, valueObject, propertyName);
    if (propertyValue == null) {
      return false;
    }
    if (!(propertyValue instanceof Collection<?>)) {
      log.warn(
          "Bad property '"
              + propertyName
              + "' value: "
              + propertyValue.getClass().getName()); // $NON-NLS-1$ //$NON-NLS-2$
      return false;
    }

    DBSObjectFilter filter = getNodeFilter(meta, false);
    this.filtered = filter != null && !filter.isEmpty();

    Collection<?> itemList = (Collection<?>) propertyValue;
    if (itemList.isEmpty()) {
      return false;
    }
    if (this.isDisposed()) {
      // Property reading can take really long time so this node can be disposed at this moment -
      // check it
      return false;
    }

    DBPDataSourceContainer dataSourceContainer = getDataSourceContainer();
    boolean showSystem = dataSourceContainer == null || dataSourceContainer.isShowSystemObjects();
    for (Object childItem : itemList) {
      if (childItem == null) {
        continue;
      }
      if (!(childItem instanceof DBSObject)) {
        log.warn("Bad item type: " + childItem.getClass().getName()); // $NON-NLS-1$
        continue;
      }
      if (DBUtils.isHiddenObject(childItem)) {
        // Skip hidden objects
        continue;
      }
      if (!showSystem
          && childItem instanceof DBPSystemObject
          && ((DBPSystemObject) childItem).isSystem()) {
        // Skip system objects
        continue;
      }
      if (filter != null && !filter.matches(((DBSObject) childItem).getName())) {
        // Doesn't match filter
        continue;
      }
      DBSObject object = (DBSObject) childItem;
      boolean added = false;
      if (oldList != null) {
        // Check that new object is a replacement of old one
        for (DBNDatabaseNode oldChild : oldList) {
          if (oldChild.getMeta() == meta && equalObjects(oldChild.getObject(), object)) {
            oldChild.reloadObject(monitor, object);

            if (oldChild.allowsChildren() && !oldChild.needsInitialization()) {
              // Refresh children recursive
              oldChild.reloadChildren(monitor);
            }
            getModel().fireNodeUpdate(this, oldChild, DBNEvent.NodeChange.REFRESH);

            toList.add(oldChild);
            added = true;
            break;
          }
        }
      }
      if (!added) {
        // Simply add new item
        DBNDatabaseItem treeItem = new DBNDatabaseItem(this, meta, object, oldList != null);
        toList.add(treeItem);
      }
    }

    if (oldList != null) {
      // Now remove all non-existing items
      for (DBNDatabaseNode oldChild : oldList) {
        if (oldChild.getMeta() != meta) {
          // Wrong type
          continue;
        }
        boolean found = false;
        for (Object childItem : itemList) {
          if (childItem instanceof DBSObject
              && equalObjects(oldChild.getObject(), (DBSObject) childItem)) {
            found = true;
            break;
          }
        }
        if (!found) {
          // Remove old child object
          oldChild.dispose(true);
        }
      }
    }
    return true;
  }