1 19 20 package org.netbeans.modules.versioning.system.cvss.ui.actions.commit; 21 22 import org.openide.util.NbBundle; 23 import org.netbeans.modules.versioning.system.cvss.CvsFileNode; 24 import org.netbeans.modules.versioning.system.cvss.FileInformation; 25 import org.netbeans.modules.versioning.system.cvss.CvsVersioningSystem; 26 import org.netbeans.modules.versioning.system.cvss.util.Utils; 27 import org.netbeans.modules.versioning.system.cvss.CvsModuleConfig; 28 import org.netbeans.lib.cvsclient.command.KeywordSubstitutionOptions; 29 30 import javax.swing.table.AbstractTableModel ; 31 import java.util.*; 32 import java.io.File ; 33 34 39 class CommitTableModel extends AbstractTableModel { 40 41 44 private final Map<String , String []> columnLabels = new HashMap<String , String []>(5); 45 { 46 ResourceBundle loc = NbBundle.getBundle(CommitTableModel.class); 47 columnLabels.put(CommitSettings.COLUMN_NAME_NAME, new String [] { 48 loc.getString("CTL_CommitTable_Column_File"), 49 loc.getString("CTL_CommitTable_Column_File")}); 50 columnLabels.put(CommitSettings.COLUMN_NAME_STICKY, new String [] { 51 loc.getString("CTL_CommitTable_Column_Sticky"), 52 loc.getString("CTL_CommitTable_Column_Sticky")}); 53 columnLabels.put(CommitSettings.COLUMN_NAME_STATUS, new String [] { 54 loc.getString("CTL_CommitTable_Column_Status"), 55 loc.getString("CTL_CommitTable_Column_Status")}); 56 columnLabels.put(CommitSettings.COLUMN_NAME_ACTION, new String [] { 57 loc.getString("CTL_CommitTable_Column_Action"), 58 loc.getString("CTL_CommitTable_Column_Action")}); 59 columnLabels.put(CommitSettings.COLUMN_NAME_PATH, new String [] { 60 loc.getString("CTL_CommitTable_Column_Folder"), 61 loc.getString("CTL_CommitTable_Column_Folder")}); 62 } 63 64 private CommitOptions [] commitOptions; 65 private CvsFileNode [] nodes; 66 67 private String [] columns; 68 69 public CommitTableModel() { 70 setColumns(new String [0]); 71 setNodes(new CvsFileNode[0]); 72 } 73 74 void setNodes(CvsFileNode [] nodes) { 75 this.nodes = nodes; 76 createCommitOptions(); 77 fireTableDataChanged(); 78 } 79 80 void setColumns(String [] cols) { 81 if (Arrays.equals(cols, columns)) return; 82 columns = cols; 83 fireTableStructureChanged(); 84 } 85 86 public CommitSettings.CommitFile[] getCommitFiles() { 87 CommitSettings.CommitFile [] files = new CommitSettings.CommitFile[nodes.length]; 88 for (int i = 0; i < nodes.length; i++) { 89 files[i] = new CommitSettings.CommitFile(nodes[i], commitOptions[i]); 90 } 91 return files; 92 } 93 94 public String getColumnName(int column) { 95 return ((String []) columnLabels.get(columns[column]))[0]; 96 } 97 98 public int getColumnCount() { 99 return columns.length; 100 } 101 102 public int getRowCount() { 103 return nodes.length; 104 } 105 106 public Class getColumnClass(int columnIndex) { 107 String col = columns[columnIndex]; 108 if (col.equals(CommitSettings.COLUMN_NAME_ACTION)) { 109 return CommitOptions.class; 110 } 111 return String .class; 112 } 113 114 public boolean isCellEditable(int rowIndex, int columnIndex) { 115 String col = columns[columnIndex]; 116 return col.equals(CommitSettings.COLUMN_NAME_ACTION); 117 } 118 119 public Object getValueAt(int rowIndex, int columnIndex) { 120 String col = columns[columnIndex]; 121 if (col.equals(CommitSettings.COLUMN_NAME_NAME)) { 122 return nodes[rowIndex].getName(); 123 } else if (col.equals(CommitSettings.COLUMN_NAME_STICKY)) { 124 String sticky = Utils.getSticky(nodes[rowIndex].getFile()); 125 return sticky == null ? "" : sticky.substring(1); } else if (col.equals(CommitSettings.COLUMN_NAME_STATUS)) { 127 return nodes[rowIndex].getInformation().getStatusText(); 128 } else if (col.equals(CommitSettings.COLUMN_NAME_ACTION)) { 129 return commitOptions[rowIndex]; 130 } else if (col.equals(CommitSettings.COLUMN_NAME_PATH)) { 131 return Utils.getRelativePath(nodes[rowIndex].getFile()); 132 } 133 throw new IllegalArgumentException ("Column index out of range: " + columnIndex); } 135 136 public void setValueAt(Object aValue, int rowIndex, int columnIndex) { 137 String col = columns[columnIndex]; 138 if (col.equals(CommitSettings.COLUMN_NAME_ACTION)) { 139 commitOptions[rowIndex] = (CommitOptions) aValue; 140 fireTableCellUpdated(rowIndex, columnIndex); 141 } else { 142 throw new IllegalArgumentException ("Column index out of range: " + columnIndex); } 144 } 145 146 private void createCommitOptions() { 147 boolean excludeNew = CvsModuleConfig.getDefault().getPreferences().getBoolean(CvsModuleConfig.PROP_EXCLUDE_NEW_FILES, false); 148 commitOptions = new CommitOptions[nodes.length]; 149 for (int i = 0; i < nodes.length; i++) { 150 CvsFileNode node = nodes[i]; 151 if (CvsModuleConfig.getDefault().isExcludedFromCommit(node.getFile())) { 152 commitOptions[i] = CommitOptions.EXCLUDE; 153 } else { 154 switch (node.getInformation().getStatus()) { 155 case FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY: 156 commitOptions[i] = excludeNew ? CommitOptions.EXCLUDE : getDefaultCommitOptions(node.getFile()); 157 break; 158 case FileInformation.STATUS_VERSIONED_DELETEDLOCALLY: 159 case FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY: 160 commitOptions[i] = CommitOptions.COMMIT_REMOVE; 161 break; 162 default: 163 commitOptions[i] = CommitOptions.COMMIT; 164 } 165 } 166 } 167 } 168 169 CommitSettings.CommitFile getCommitFile(int row) { 170 return new CommitSettings.CommitFile(nodes[row], commitOptions[row]); 171 } 172 173 private CommitOptions getDefaultCommitOptions(File file) { 174 KeywordSubstitutionOptions options = CvsVersioningSystem.getInstance().getDefaultKeywordSubstitution(file); 175 return options == KeywordSubstitutionOptions.BINARY ? CommitOptions.ADD_BINARY : CommitOptions.ADD_TEXT; 176 } 177 } 178 | Popular Tags |