1 /* 2 * SVNStatusRenderer.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.core.client.GWT; 18 import com.google.gwt.resources.client.ClientBundle; 19 import com.google.gwt.resources.client.ImageResource; 20 import com.google.gwt.safehtml.shared.SafeHtml; 21 import com.google.gwt.safehtml.shared.SafeHtmlBuilder; 22 import com.google.gwt.safehtml.shared.SafeHtmlUtils; 23 import com.google.gwt.text.shared.SafeHtmlRenderer; 24 25 import org.rstudio.core.client.resources.ImageResource2x; 26 import org.rstudio.studio.client.workbench.views.vcs.common.ChangelistTable.ChangelistTableCellTableResources; 27 28 public class SVNStatusRenderer implements SafeHtmlRenderer<String> 29 { 30 interface StatusResources extends ClientBundle 31 { 32 @Source("images/statusAdded_2x.png") statusAdded2x()33 ImageResource statusAdded2x(); 34 @Source("images/statusConflicted_2x.png") statusConflicted2x()35 ImageResource statusConflicted2x(); 36 @Source("images/statusDeleted_2x.png") statusDeleted2x()37 ImageResource statusDeleted2x(); 38 @Source("images/statusExternal_2x.png") statusExternal2x()39 ImageResource statusExternal2x(); 40 @Source("images/statusIgnored_2x.png") statusIgnored2x()41 ImageResource statusIgnored2x(); 42 @Source("images/statusMissing_2x.png") statusMissing2x()43 ImageResource statusMissing2x(); 44 // @Source("images/statusMerged") 45 // ImageResource statusMerged(); 46 @Source("images/statusModified_2x.png") statusModified2x()47 ImageResource statusModified2x(); 48 @Source("images/statusNone_2x.png") statusNone2x()49 ImageResource statusNone2x(); 50 @Source("images/statusObstructed_2x.png") statusObstructed2x()51 ImageResource statusObstructed2x(); 52 @Source("images/statusUnversioned_2x.png") statusUnversioned2x()53 ImageResource statusUnversioned2x(); 54 } 55 SVNStatusRenderer()56 public SVNStatusRenderer() 57 { 58 } 59 60 @Override render(String str)61 public SafeHtml render(String str) 62 { 63 if (str.length() != 1) 64 return SafeHtmlUtils.fromString(str); 65 66 ImageResource2x img = imgForStatus(str.charAt(0)); 67 68 if (img == null) 69 return SafeHtmlUtils.fromString(str); 70 71 SafeHtmlBuilder builder = new SafeHtmlBuilder(); 72 builder.append(SafeHtmlUtils.fromTrustedString( 73 "<span " + 74 "class=\"" + ctRes_.cellTableStyle().status() + "\" " + 75 "title=\"" + 76 SafeHtmlUtils.htmlEscape(descForStatus(str)) + 77 "\">")); 78 79 builder.append(img.getSafeHtml()); 80 81 builder.appendHtmlConstant("</span>"); 82 83 return builder.toSafeHtml(); 84 } 85 descForStatus(String str)86 private String descForStatus(String str) 87 { 88 if (str.isEmpty()) 89 return ""; 90 91 char c = str.charAt(0); 92 93 switch (c) 94 { 95 case 'A': 96 return "Added"; 97 case 'C': 98 return "Conflicted"; 99 case 'D': 100 return "Deleted"; 101 case 'X': 102 return "External"; 103 case 'I': 104 return "Ignored"; 105 case '!': 106 return "Missing"; 107 // case 'G': 108 // return resources_.statusMerged(); 109 case 'M': 110 return "Modified"; 111 case ' ': 112 return ""; 113 case '~': 114 return "Obstructed"; 115 case '?': 116 return "Unversioned"; 117 default: 118 return ""; 119 } 120 121 } 122 123 124 imgForStatus(char c)125 private ImageResource2x imgForStatus(char c) 126 { 127 switch (c) 128 { 129 case 'A': 130 return new ImageResource2x(resources_.statusAdded2x()); 131 case 'C': 132 return new ImageResource2x(resources_.statusConflicted2x()); 133 case 'D': 134 return new ImageResource2x(resources_.statusDeleted2x()); 135 case 'X': 136 return new ImageResource2x(resources_.statusExternal2x()); 137 case 'I': 138 return new ImageResource2x(resources_.statusIgnored2x()); 139 case '!': 140 return new ImageResource2x(resources_.statusMissing2x()); 141 // case 'G': 142 // return resources_.statusMerged(); 143 case 'M': 144 return new ImageResource2x(resources_.statusModified2x()); 145 case ' ': 146 return new ImageResource2x(resources_.statusNone2x()); 147 case '~': 148 return new ImageResource2x(resources_.statusObstructed2x()); 149 case '?': 150 return new ImageResource2x(resources_.statusUnversioned2x()); 151 default: 152 return null; 153 } 154 } 155 156 @Override render(String str, SafeHtmlBuilder builder)157 public void render(String str, SafeHtmlBuilder builder) 158 { 159 SafeHtml safeHtml = render(str); 160 if (safeHtml != null) 161 builder.append(safeHtml); 162 } 163 164 private static final StatusResources resources_ = GWT.create(StatusResources.class); 165 private static final ChangelistTableCellTableResources ctRes_ = GWT.create(ChangelistTableCellTableResources.class); 166 } 167