1 19 20 package org.netbeans.modules.subversion.ui.commit; 21 22 import org.openide.util.NbBundle; 23 import org.netbeans.modules.subversion.SvnFileNode; 24 import org.netbeans.modules.subversion.FileInformation; 25 import org.netbeans.modules.subversion.util.SvnUtils; 26 import org.netbeans.modules.subversion.SvnModuleConfig; 27 28 import javax.swing.table.AbstractTableModel ; 29 import java.util.*; 30 import java.io.File ; 31 import org.tigris.subversion.svnclientadapter.SVNUrl; 32 33 38 public class CommitTableModel extends AbstractTableModel { 39 40 public static final String COLUMN_NAME_NAME = "name"; public static final String COLUMN_NAME_STATUS = "status"; public static final String COLUMN_NAME_ACTION = "action"; public static final String COLUMN_NAME_PATH = "path"; public static final String COLUMN_NAME_BRANCH = "branch"; 46 private class RootFile { 47 String repositoryPath; 48 String rootLocalPath; 49 } 50 private Set<SVNUrl> repositoryRoots; 51 private RootFile rootFile; 52 53 56 private static final Map<String , String []> columnLabels = new HashMap<String , String []>(4); 57 58 { 59 ResourceBundle loc = NbBundle.getBundle(CommitTableModel.class); 60 columnLabels.put(COLUMN_NAME_NAME, new String [] { 61 loc.getString("CTL_CommitTable_Column_File"), 62 loc.getString("CTL_CommitTable_Column_File")}); 63 columnLabels.put(COLUMN_NAME_BRANCH, new String [] { 64 loc.getString("CTL_CommitTable_Column_Branch"), 65 loc.getString("CTL_CommitTable_Column_Branch")}); 66 columnLabels.put(COLUMN_NAME_STATUS, new String [] { 67 loc.getString("CTL_CommitTable_Column_Status"), 68 loc.getString("CTL_CommitTable_Column_Status")}); 69 columnLabels.put(COLUMN_NAME_ACTION, new String [] { 70 loc.getString("CTL_CommitTable_Column_Action"), 71 loc.getString("CTL_CommitTable_Column_Action")}); 72 columnLabels.put(COLUMN_NAME_PATH, new String [] { 73 loc.getString("CTL_CommitTable_Column_Folder"), 74 loc.getString("CTL_CommitTable_Column_Folder")}); 75 } 76 77 private CommitOptions [] commitOptions; 78 private SvnFileNode [] nodes; 79 80 private String [] columns; 81 82 86 public CommitTableModel(String [] columns) { 87 setColumns(columns); 88 setNodes(new SvnFileNode[0]); 89 } 90 91 void setNodes(SvnFileNode [] nodes) { 92 this.nodes = nodes; 93 defaultCommitOptions(); 94 fireTableDataChanged(); 95 } 96 97 void setColumns(String [] cols) { 98 if (Arrays.equals(cols, columns)) return; 99 columns = cols; 100 fireTableStructureChanged(); 101 } 102 103 106 public Map<SvnFileNode, CommitOptions> getCommitFiles() { 107 Map<SvnFileNode, CommitOptions> ret = new HashMap<SvnFileNode, CommitOptions>(nodes.length); 108 for (int i = 0; i < nodes.length; i++) { 109 ret.put(nodes[i], commitOptions[i]); 110 } 111 return ret; 112 } 113 114 public String getColumnName(int column) { 115 return columnLabels.get(columns[column])[0]; 116 } 117 118 public int getColumnCount() { 119 return columns.length; 120 } 121 122 public int getRowCount() { 123 return nodes.length; 124 } 125 126 public Class getColumnClass(int columnIndex) { 127 String col = columns[columnIndex]; 128 if (col.equals(COLUMN_NAME_ACTION)) { 129 return CommitOptions.class; 130 } 131 return String .class; 132 } 133 134 public boolean isCellEditable(int rowIndex, int columnIndex) { 135 String col = columns[columnIndex]; 136 return col.equals(COLUMN_NAME_ACTION); 137 } 138 139 public Object getValueAt(int rowIndex, int columnIndex) { 140 SvnFileNode node; 141 String col = columns[columnIndex]; 142 if (col.equals(COLUMN_NAME_NAME)) { 143 return nodes[rowIndex].getName(); 144 } else if (col.equals(COLUMN_NAME_BRANCH)) { 145 String branch = SvnUtils.getCopy(nodes[rowIndex].getFile()); 146 return branch == null ? "" : branch; } else if (col.equals(COLUMN_NAME_STATUS)) { 148 node = nodes[rowIndex]; 149 FileInformation finfo = node.getInformation(); 150 finfo.getEntry(node.getFile()); return finfo.getStatusText(); 152 } else if (col.equals(COLUMN_NAME_ACTION)) { 153 return commitOptions[rowIndex]; 154 } else if (col.equals(COLUMN_NAME_PATH)) { 155 String shortPath = null; 156 if(rootFile != null) { 158 String relativePath = nodes[rowIndex].getFile().getAbsolutePath().substring(rootFile.rootLocalPath.length()); 160 shortPath = rootFile.repositoryPath + relativePath.replace(File.separatorChar, '/'); 161 } else { 162 Set<SVNUrl> url = getRepositoryRoots(); 163 for (Iterator<SVNUrl> it = url.iterator(); it.hasNext();) { 164 SVNUrl nextUrl = it.next(); 165 shortPath = SvnUtils.getRelativePath(nextUrl, nodes[rowIndex].getFile()); 166 } 167 if (shortPath == null) { 168 SVNUrl newUrl = SvnUtils.getRepositoryRootUrl(nodes[rowIndex].getFile()); 169 shortPath = SvnUtils.getRelativePath(newUrl, nodes[rowIndex].getFile()); 170 url.add(newUrl); 171 } 172 if (shortPath == null) { 174 shortPath = org.openide.util.NbBundle.getMessage(CommitTableModel.class, "CTL_CommitForm_NotInRepository"); } 176 } 177 return shortPath; 178 } 179 throw new IllegalArgumentException ("Column index out of range: " + columnIndex); } 181 182 public void setValueAt(Object aValue, int rowIndex, int columnIndex) { 183 String col = columns[columnIndex]; 184 if (col.equals(COLUMN_NAME_ACTION)) { 185 commitOptions[rowIndex] = (CommitOptions) aValue; 186 fireTableCellUpdated(rowIndex, columnIndex); 187 } else { 188 throw new IllegalArgumentException ("Column index out of range: " + columnIndex); } 190 } 191 192 private void defaultCommitOptions() { 193 boolean excludeNew = System.getProperty("netbeans.subversion.excludeNewFiles") != null; commitOptions = new CommitOptions[nodes.length]; 195 for (int i = 0; i < nodes.length; i++) { 196 SvnFileNode node = nodes[i]; 197 File file = node.getFile(); 198 if (SvnModuleConfig.getDefault().isExcludedFromCommit(file.getAbsolutePath())) { 199 commitOptions[i] = CommitOptions.EXCLUDE; 200 } else { 201 switch (node.getInformation().getStatus()) { 202 case FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY: 203 commitOptions[i] = excludeNew ? CommitOptions.EXCLUDE : getDefaultCommitOptions(node.getFile()); 204 break; 205 case FileInformation.STATUS_VERSIONED_DELETEDLOCALLY: 206 case FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY: 207 commitOptions[i] = CommitOptions.COMMIT_REMOVE; 208 break; 209 default: 210 commitOptions[i] = CommitOptions.COMMIT; 211 } 212 } 213 } 214 } 215 216 public SvnFileNode getNode(int row) { 217 return nodes[row]; 218 } 219 220 public CommitOptions getOptions(int row) { 221 return commitOptions[row]; 222 } 223 224 private CommitOptions getDefaultCommitOptions(File file) { 225 if (file.isFile()) { 226 if (SvnUtils.isFileContentBinary(file)) { 227 return CommitOptions.ADD_BINARY; 228 } else { 229 return CommitOptions.ADD_TEXT; 230 } 231 } else { 232 return CommitOptions.ADD_DIRECTORY; 233 } 234 } 235 236 private Set<SVNUrl> getRepositoryRoots() { 237 if(repositoryRoots == null) { 238 repositoryRoots = new HashSet<SVNUrl>(); 239 } 240 return repositoryRoots; 241 } 242 243 void setRootFile(String repositoryPath, String rootLocalPath) { 244 rootFile = new RootFile(); 245 rootFile.repositoryPath = repositoryPath; 246 rootFile.rootLocalPath = rootLocalPath; 247 } 248 249 } 250 | Popular Tags |