/**
   * {@inheritDoc}
   *
   * @see org.komodo.shell.BuiltInShellCommand#tabCompletion(java.lang.String, java.util.List)
   */
  @Override
  public TabCompletionModifier tabCompletion(
      final String lastArgument, final List<CharSequence> candidates) throws Exception {
    final Arguments args = getArguments();

    if (args.isEmpty()) {
      if (lastArgument == null) {
        candidates.addAll(ALL_PROPS);
      } else {
        for (final String item : ALL_PROPS) {
          if (item.toUpperCase().startsWith(lastArgument.toUpperCase())) {
            candidates.add(item);
          }
        }
      }
    }

    if ((args.size() == 1)) {
      String theArg = getArguments().get(0);
      if (MATERIALIZED.equals(theArg) || UPDATABLE.equals(theArg)) {
        updateCandidatesForBooleanProperty(lastArgument, candidates);
      } else if (ON_COMMIT_VALUE.equals(theArg)) {
        candidates.add(OnCommit.DELETE_ROWS.name());
        candidates.add(OnCommit.PRESERVE_ROWS.name());
      } else if (SCHEMA_ELEMENT_TYPE.equals(theArg)) {
        candidates.add(SchemaElement.SchemaElementType.FOREIGN.name());
        candidates.add(SchemaElement.SchemaElementType.VIRTUAL.name());
      } else if (TEMPORARY_TABLE_TYPE.equals(theArg)) {
        candidates.add(Table.TemporaryType.GLOBAL.name());
        candidates.add(Table.TemporaryType.LOCAL.name());
      }
    }
    return TabCompletionModifier.AUTO;
  }
  /**
   * {@inheritDoc}
   *
   * @see org.komodo.shell.BuiltInShellCommand#doExecute()
   */
  @Override
  protected CommandResult doExecute() {
    CommandResult result = null;

    try {
      final String name =
          requiredArgument(0, I18n.bind(WorkspaceCommandsI18n.missingPropertyNameValue));
      final String value =
          requiredArgument(1, I18n.bind(WorkspaceCommandsI18n.missingPropertyNameValue));

      final Table table = getTable();
      final UnitOfWork transaction = getTransaction();
      String errorMsg = null;

      switch (name) {
        case DESCRIPTION:
          table.setDescription(transaction, value);
          break;
        case CARDINALITY:
          try {
            final int cardinality = Integer.parseInt(value);
            table.setCardinality(transaction, cardinality);
          } catch (final NumberFormatException e) {
            errorMsg = I18n.bind(WorkspaceCommandsI18n.invalidIntegerPropertyValue, CARDINALITY);
          }

          break;
        case MATERIALIZED:
          if (Boolean.TRUE.toString().equals(value) || Boolean.FALSE.toString().equals(value)) {
            table.setMaterialized(transaction, Boolean.parseBoolean(value));
          } else {
            errorMsg = I18n.bind(WorkspaceCommandsI18n.invalidBooleanPropertyValue, MATERIALIZED);
          }

          break;
        case MATERIALIZED_TABLE:
          table.setMaterializedTable(transaction, value);
          break;
        case NAME_IN_SOURCE:
          table.setNameInSource(transaction, value);
          break;
        case UPDATABLE:
          if (Boolean.TRUE.toString().equals(value) || Boolean.FALSE.toString().equals(value)) {
            table.setUpdatable(transaction, Boolean.parseBoolean(value));
          } else {
            errorMsg = I18n.bind(WorkspaceCommandsI18n.invalidBooleanPropertyValue, UPDATABLE);
          }

          break;
        case UUID:
          table.setUuid(transaction, value);
          break;
        case ON_COMMIT_VALUE:
          if (OnCommit.DELETE_ROWS.name().equals(value)) {
            table.setOnCommitValue(transaction, OnCommit.DELETE_ROWS);
          } else if (OnCommit.PRESERVE_ROWS.name().equals(value)) {
            table.setOnCommitValue(transaction, OnCommit.PRESERVE_ROWS);
          } else {
            errorMsg = I18n.bind(TableCommandsI18n.invalidOnCommitPropertyValue, ON_COMMIT_VALUE);
          }

          break;
        case QUERY_EXPRESSION:
          table.setQueryExpression(transaction, value);
          break;
        case SCHEMA_ELEMENT_TYPE:
          if (SchemaElement.SchemaElementType.FOREIGN.name().equals(value)) {
            table.setSchemaElementType(transaction, SchemaElement.SchemaElementType.FOREIGN);
          } else if (SchemaElement.SchemaElementType.VIRTUAL.name().equals(value)) {
            table.setSchemaElementType(transaction, SchemaElement.SchemaElementType.VIRTUAL);
          } else {
            errorMsg = I18n.bind(TableCommandsI18n.invalidSchemaElementTypePropertyValue, value);
          }

          break;
        case TEMPORARY_TABLE_TYPE:
          if (Table.TemporaryType.GLOBAL.name().equals(value)) {
            table.setTemporaryTableType(transaction, Table.TemporaryType.GLOBAL);
          } else if (Table.TemporaryType.LOCAL.name().equals(value)) {
            table.setTemporaryTableType(transaction, Table.TemporaryType.LOCAL);
          } else {
            errorMsg = I18n.bind(TableCommandsI18n.invalidTemporaryTableTypePropertyValue, value);
          }

          break;
        default:
          errorMsg =
              I18n.bind(
                  WorkspaceCommandsI18n.invalidPropertyName, name, Table.class.getSimpleName());
          break;
      }

      if (StringUtils.isBlank(errorMsg)) {
        result = new CommandResultImpl(I18n.bind(WorkspaceCommandsI18n.setPropertySuccess, name));
      } else {
        result = new CommandResultImpl(false, errorMsg, null);
      }
    } catch (final Exception e) {
      result = new CommandResultImpl(e);
    }

    return result;
  }