1 /*
2  * SVNChangelistTable.java
3  *
4  * Copyright (C) 2021 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant
7  * to the terms of a commercial license agreement with RStudio, then
8  * this program is licensed to you under the terms of version 3 of the
9  * GNU Affero General Public License. This program is distributed WITHOUT
10  * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
11  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
12  * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
13  *
14  */
15 package org.rstudio.studio.client.workbench.views.vcs.svn;
16 
17 import com.google.gwt.text.shared.SafeHtmlRenderer;
18 import com.google.gwt.user.cellview.client.Column;
19 import org.rstudio.core.client.StringUtil;
20 import org.rstudio.studio.client.common.vcs.StatusAndPath;
21 import org.rstudio.studio.client.workbench.views.vcs.common.ChangelistTable;
22 
23 import java.util.Comparator;
24 
25 public class SVNChangelistTable extends ChangelistTable
26 {
SVNChangelistTable()27    public SVNChangelistTable()
28    {
29    }
30 
setChangelistColumnVisible(boolean visible)31    public void setChangelistColumnVisible(boolean visible)
32    {
33       if ((changelistColumn_ != null) != visible)
34       {
35          if (!visible)
36          {
37             table_.removeColumn(changelistColumn_);
38             changelistColumn_ = null;
39          }
40          else
41          {
42             changelistColumn_ = new Column<StatusAndPath, String>(
43                   new NotEditingTextCell())
44             {
45                @Override
46                public String getValue(StatusAndPath object)
47                {
48                   return object.getChangelist();
49                }
50             };
51             changelistColumn_.setSortable(true);
52             sortHandler_.setComparator(changelistColumn_, new Comparator<StatusAndPath>()
53             {
54                @Override
55                public int compare(StatusAndPath a,
56                                   StatusAndPath b)
57                {
58                   return StringUtil.notNull(a.getChangelist())
59                         .compareToIgnoreCase(
60                               b.getChangelist());
61                }
62             });
63             table_.addColumn(changelistColumn_, "Changelist");
64          }
65       }
66    }
67 
68    @Override
getStatusRenderer()69    protected SafeHtmlRenderer<String> getStatusRenderer()
70    {
71       return new SVNStatusRenderer();
72    }
73 
74    private Column<StatusAndPath, String> changelistColumn_;
75 }
76