/**
   * {@inheritDoc}
   *
   * @see org.teiid.designer.vdb.connections.SourceHandler#getTranslatorTypes()
   */
  @Override
  public String[] getTranslatorTypes() {
    Server defaultServer = getDefaultServer();

    if ((defaultServer != null) && defaultServer.isConnected()) {
      Collection<TeiidTranslator> translators = null;

      try {
        translators = defaultServer.getAdmin().getTranslators();
      } catch (Exception e) {
        UTIL.log(
            IStatus.ERROR,
            e,
            UTIL.getString(
                "VdbSourceConnectionHandler.errorObtainingTranslators",
                defaultServer.getHost())); // $NON-NLS-1$
      }

      if (translators != null) {
        Collection<String> translatorTypes = new ArrayList<String>();

        for (TeiidTranslator translator : translators) {
          translatorTypes.add(translator.getName());
        }

        return translatorTypes.toArray(new String[translatorTypes.size()]);
      }
    }

    return null;
  }
  @Override
  public void selectionChanged(SelectionChangedEvent event) {
    TreeSelection selection = (TreeSelection) event.getSelection();
    if (selection.isEmpty()) {
      this.selectedTranslator = null;
      this.translatorNameText.setText(UNDEFINED);
      updateOnSelection(null);
      return;
    }

    Object firstElement = selection.getFirstElement();

    if (!(firstElement instanceof TeiidTranslator)) {
      this.selectedTranslator = null;
      this.translatorNameText.setText(UNDEFINED);
    } else {
      this.selectedTranslator = (TeiidTranslator) selection.getFirstElement();
      this.translatorNameText.setText(selectedTranslator.getName());
    }

    updateOnSelection(firstElement);
  }
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.teiid.designer.vdb.connections.SourceHandler#getTranslatorDefinitions(java.lang.String)
   */
  @Override
  public PropertyDefinition[] getTranslatorDefinitions(String translatorName) {
    if (StringUtilities.isEmpty(translatorName)) {
      throw new IllegalArgumentException();
    }

    Server defaultServer = getDefaultServer();

    if ((defaultServer != null) && defaultServer.isConnected()) {
      try {
        TeiidTranslator translator = defaultServer.getAdmin().getTranslator(translatorName);

        if (translator != null) {
          Collection<PropertyDefinition> props = new ArrayList<PropertyDefinition>();

          for (org.teiid.adminapi.PropertyDefinition propDefn :
              translator.getPropertyDefinitions()) {
            TranslatorProperty prop = new TranslatorProperty(propDefn.getPropertyTypeClassName());
            prop.advanced = propDefn.isAdvanced();
            prop.description = propDefn.getDescription();
            prop.displayName = propDefn.getDisplayName();
            prop.id = propDefn.getName();
            prop.masked = propDefn.isMasked();
            prop.modifiable = propDefn.isModifiable();
            prop.required = propDefn.isRequired();

            prop.defaultValue =
                (propDefn.getDefaultValue() == null)
                    ? StringUtilities.EMPTY_STRING
                    : propDefn.getDefaultValue().toString();

            if (propDefn.isConstrainedToAllowedValues()) {
              Collection values = propDefn.getAllowedValues();
              prop.allowedValues = new String[values.size()];
              int i = 0;

              for (Object value : values) {
                prop.allowedValues[i++] = value.toString();
              }
            } else {
              // if boolean type turn into allowed values
              String type = propDefn.getPropertyTypeClassName();

              if (Boolean.class.getName().equals(type) || Boolean.TYPE.getName().equals(type)) {
                prop.allowedValues =
                    new String[] {Boolean.TRUE.toString(), Boolean.FALSE.toString()};
              }
            }

            props.add(prop);
          }

          return props.toArray(new PropertyDefinition[props.size()]);
        }
      } catch (Exception e) {
        UTIL.log(
            IStatus.ERROR,
            e,
            UTIL.getString(
                "VdbSourceConnectionHandler.errorObtainingTranslatorProperties", //$NON-NLS-1$
                translatorName,
                defaultServer.getHost()));
      }
    }

    return null;
  }