View Javadoc

1   /**
2    * Copyright (C) 2008 Atlassian
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.atlassian.theplugin.idea.crucible.table.column;
18  
19  import com.atlassian.theplugin.idea.TableColumnInfo;
20  import com.atlassian.theplugin.idea.crucible.ReviewDataInfoAdapter;
21  import com.atlassian.theplugin.commons.crucible.api.model.User;
22  import com.atlassian.theplugin.commons.crucible.api.model.Reviewer;
23  
24  import java.util.Comparator;
25  import java.util.Iterator;
26  
27  
28  public class ReviewReviewersColumn extends TableColumnInfo {
29      private static final int COL_WIDTH = 200;
30  
31      public String getColumnName() {
32          return "Reviewers";
33      }
34  
35      public Object valueOf(Object o) {
36          String reviewers = "<html>";
37          reviewers += getReviewersAsText(o);
38          reviewers += "</html>";
39          return reviewers;
40      }
41  
42      private String getReviewersAsText(Object o) {
43          StringBuffer sb = new StringBuffer();
44          if (((ReviewDataInfoAdapter) o).getReviewers() != null) {
45              for (Iterator<Reviewer> iterator = ((ReviewDataInfoAdapter) o).getReviewers().iterator(); iterator.hasNext();) {
46                  sb.append(iterator.next().getUserName());
47                  if (iterator.hasNext()) {
48                      sb.append(", ");
49                  }
50              }
51          }
52          return sb.toString();
53      }
54  
55      public Class getColumnClass() {
56          return String.class;
57      }
58  
59      public Comparator getComparator() {
60          return new Comparator() {
61              public int compare(Object o, Object o1) {
62                  String r = getReviewersAsText(o);
63                  String r1 = getReviewersAsText(o1);
64                  return r.compareTo(r1);
65              }
66          };
67      }
68  
69      public int getPrefferedWidth() {
70          return COL_WIDTH;
71      }
72  
73  
74  }