コード例 #1
0
  /*
   * Turns the vector into an Array of ICompletionProposal objects
   */
  protected SQLCompletionProposal createCompletionProposal(
      String replaceString,
      String displayString,
      String description,
      @Nullable DBPImage image,
      boolean isObject,
      @Nullable DBPNamedObject object) {
    DBPPreferenceStore store = getPreferences();
    DBPDataSource dataSource = editor.getDataSource();
    if (dataSource != null) {
      if (isObject) {
        // Escape replace string if required
        replaceString = DBUtils.getQuotedIdentifier(dataSource, replaceString);
      }
    }

    // If we have quoted string then ignore pref settings
    boolean quotedString = wordDetector.isQuoted(replaceString);
    final int proposalCase =
        quotedString
            ? SQLPreferenceConstants.PROPOSAL_CASE_DEFAULT
            : store.getInt(SQLPreferenceConstants.PROPOSAL_INSERT_CASE);
    switch (proposalCase) {
      case SQLPreferenceConstants.PROPOSAL_CASE_UPPER:
        replaceString = replaceString.toUpperCase();
        break;
      case SQLPreferenceConstants.PROPOSAL_CASE_LOWER:
        replaceString = replaceString.toLowerCase();
        break;
      default:
        DBPIdentifierCase convertCase =
            quotedString && dataSource instanceof SQLDataSource
                ? ((SQLDataSource) dataSource).getSQLDialect().storesQuotedCase()
                : DBPIdentifierCase.MIXED;
        replaceString = convertCase.transform(replaceString);
        break;
    }

    Image img = image == null ? null : DBeaverIcons.getImage(image);
    return new SQLCompletionProposal(
        editor.getSyntaxManager(),
        displayString,
        replaceString, // replacementString
        wordDetector, // wordDetector
        replaceString.length(), // cursorPosition the position of the cursor following the insert
        // relative to replacementOffset
        img, // image to display
        new ContextInformation(
            img,
            displayString,
            displayString), // the context information associated with this proposal
        description,
        object);
  }
コード例 #2
0
  private SQLCompletionProposal makeProposalsFromObject(
      DBPNamedObject object, @Nullable DBPImage objectIcon) {
    String objectName = DBUtils.getObjectFullName(object);

    StringBuilder info = new StringBuilder();
    PropertyCollector collector = new PropertyCollector(object, false);
    collector.collectProperties();
    for (DBPPropertyDescriptor descriptor : collector.getPropertyDescriptors2()) {
      Object propValue = collector.getPropertyValue(descriptor.getId());
      if (propValue == null) {
        continue;
      }
      String propString = propValue.toString();
      info.append("<b>").append(descriptor.getDisplayName()).append(":  </b>");
      info.append(propString);
      info.append("<br>");
    }

    boolean isSingleObject = true;
    String replaceString = null;
    DBPDataSource dataSource = editor.getDataSource();
    if (dataSource != null) {
      // If we replace short name with referenced object
      // and current active schema (catalog) is not this object's container then
      // replace with full qualified name
      if (!getPreferences().getBoolean(SQLPreferenceConstants.PROPOSAL_SHORT_NAME)
          && object instanceof DBSObjectReference) {
        if (wordDetector.getFullWord().indexOf(editor.getSyntaxManager().getStructSeparator())
            == -1) {
          DBSObjectReference structObject = (DBSObjectReference) object;
          if (structObject.getContainer() != null) {
            DBSObject selectedObject = getSelectedObject(dataSource);
            if (selectedObject != structObject.getContainer()) {
              replaceString =
                  DBUtils.getFullQualifiedName(dataSource, structObject.getContainer(), object);
              isSingleObject = false;
            }
          }
        }
      }
      if (replaceString == null) {
        replaceString = DBUtils.getQuotedIdentifier(dataSource, object.getName());
      }
    } else {
      replaceString = DBUtils.getObjectShortName(object);
    }
    return createCompletionProposal(
        replaceString, objectName, info.toString(), objectIcon, isSingleObject, object);
  }