Beispiel #1
0
  private void printTitle() {
    StringBuffer buffer = new StringBuffer();

    buffer.append("╭──────┬─ Step ").append(step + 1);
    buffer.append(" of ").append(groups.length).append(" ────────┈┈┈┈\n");

    buffer.append("│            │\n");

    if (group.getConfigDescriptor().getDescription() != null) {
      buffer
          .append(
              formatLines(
                  group.getConfigDescriptor().getDescription(),
                  60,
                  LocaleInfo.getDefault().getLocale(),
                  "│Description │ ",
                  "│            │   "))
          .append("\n");

      buffer.append("│┈┈┈┈┈┈│┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈\n");
    }

    buffer
        .append(
            formatLines(
                group.getConfigDescriptor().getURL().toString(),
                60,
                LocaleInfo.getDefault().getLocale(),
                "│Descriptor  │ ",
                "│            │   "))
        .append("\n");

    buffer.append("│┈┈┈┈┈┈│┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈\n");

    buffer
        .append(
            formatLines(
                getURI(),
                60,
                LocaleInfo.getDefault().getLocale(),
                "│Properties  │ ",
                "│            │   "))
        .append("\n");

    buffer.append("│            │").append("\n");
    buffer.append("└──────┴┈┈┈┈┈┈┈┈┈┈┈").append("\n");

    println();
    println(buffer);
  }
Beispiel #2
0
  /**
   * 设置当前步数。
   *
   * @param step 当前步数
   */
  private void setStep(int step) {
    if (step >= groups.length) {
      step = groups.length - 1;
    }

    if (step < 0) {
      step = 0;
    }

    this.step = step;

    if (step < groups.length) {
      this.group = groups[step];
      this.props = group.getProperties();
    } else {
      this.group = null;
    }
  }
Beispiel #3
0
  private void printGroup() {
    if (group.getDescription() != null) {
      println(" " + group.getDescription() + " (? - 该值在用户配置文件中不存在,* - 必填项,S - 覆盖共享默认值,s - 共享值)");
    } else {
      println(" (? - 该值在用户配置文件中不存在,* - 必填项,S - 覆盖共享默认值,s - 共享值)");
    }

    println();

    // 找出最长的名称和值
    int maxLength = -1;
    int maxLengthValue = -1;

    for (ConfigProperty prop : props) {
      int length = prop.getName().length();

      if (length > maxLength && length < MAX_ALIGN) {
        maxLength = length;
      }
    }

    for (ConfigProperty prop : props) {
      String value = getPropertyValue(prop, true);
      int length =
          Math.max(prop.getName().length(), maxLength)
              + (value == null ? 0 : "  = ".length() + value.length());

      if (length > maxLengthValue && length < MAX_ALIGN * 2) {
        maxLengthValue = length;
      }
    }

    for (int i = 0; i < props.length; i++) {
      ConfigProperty prop = props[i];

      StringBuffer buffer = new StringBuffer();

      // 如果项目在配置文件中不存在,则显示?
      boolean absent = !getKeys().contains(prop.getName());

      // 如果是必填项, 则显示*号
      boolean required = prop.isRequired();

      // 如果项目定义在shared properties中,则显示S
      boolean shared = propSet.isShared(prop.getName());

      if (shared) {
        if (absent) {
          buffer.append("s");
        } else {
          buffer.append("S");
        }
      } else {
        if (absent) {
          buffer.append("?");
        } else {
          buffer.append(" ");
        }
      }

      if (required) {
        buffer.append("* ");
      } else {
        buffer.append("  ");
      }

      // 显示property序号
      buffer.append(i + 1).append(" - ");

      // 显示property名称
      buffer.append(prop.getName());

      // 显示property值
      String value = getPropertyValue(prop, true);

      if (value != null) {
        for (int j = 0; j < maxLength - prop.getName().length(); j++) {
          buffer.append(' ');
        }

        buffer.append("  = ").append(value);
      }

      // 显示property描述
      if (prop.getDescription() != null) {
        int length =
            value == null
                ? prop.getName().length()
                : Math.max(prop.getName().length(), maxLength) + "  = ".length() + value.length();

        for (int j = 0; j < maxLengthValue - length; j++) {
          buffer.append(' ');
        }

        buffer.append("   # ").append(prop.getDescription());
      }

      // 如果值是表达式,则同时显示表达式的计算值
      String evaluatedValue = evaluatePropertyValue(prop, true);

      if (evaluatedValue != null && !ObjectUtil.equals(value, evaluatedValue)) {
        buffer.append("\n");

        for (int j = 0; j < maxLength; j++) {
          buffer.append(' ');
        }

        buffer.append("          (").append(evaluatedValue).append(")");

        if (i < props.length - 1) {
          buffer.append("\n");
        }
      }

      println(buffer);
    }

    println();
  }