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);
  }
Exemple #2
0
 public static CellEditor createPropertyEditor(
     final IServiceLocator serviceLocator,
     Composite parent,
     DBPPropertySource source,
     DBPPropertyDescriptor property) {
   if (source == null) {
     return null;
   }
   final Object object = source.getEditableValue();
   if (!property.isEditable(object)) {
     return null;
   }
   CellEditor cellEditor = UIUtils.createCellEditor(parent, object, property);
   if (cellEditor != null) {
     final Control editorControl = cellEditor.getControl();
     UIUtils.addFocusTracker(serviceLocator, UIUtils.INLINE_WIDGET_EDITOR_ID, editorControl);
     editorControl.addDisposeListener(
         new DisposeListener() {
           @Override
           public void widgetDisposed(DisposeEvent e) {
             UIUtils.removeFocusTracker(serviceLocator, editorControl);
           }
         });
   }
   return cellEditor;
 }
Exemple #3
0
 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;
   }
 }