public String getTitle(DockingWindow window) {
    ArrayList viewTitles = new ArrayList();
    ArrayList viewPrimary = new ArrayList();
    getViews(window, viewTitles, viewPrimary, true);

    int length = 0;

    for (int i = 0; i < viewTitles.size(); i++) {
      if (((Boolean) viewPrimary.get(i)).booleanValue()) {
        length += ((String) viewTitles.get(i)).length();
      }
    }

    StringBuffer title = new StringBuffer(40);
    int count = 0;

    for (int i = 0; i < viewTitles.size() && title.length() < maxLength; i++) {
      boolean primary = ((Boolean) viewPrimary.get(i)).booleanValue();

      if (primary || length < maxLength) {
        if (title.length() > 0)
          title.append(", ");

        title.append((String) viewTitles.get(i));
        count++;

        if (!primary)
          length += ((String) viewTitles.get(i)).length();
      }
    }

    if (count < viewTitles.size())
      title.append(", ...");

    return title.toString();
  }