2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
26 * The Original Software is NetBeans. The Initial Developer of the Original
27 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28 * Microsystems, Inc. All Rights Reserved.
29 * Portions Copyright 2008 Alexander Coles (Ikonoklastik Productions).
31 * If you wish your version of this file to be governed by only the CDDL
32 * or only the GPL Version 2, indicate your decision by adding
33 * "[Contributor] elects to include this software in this distribution
34 * under the [CDDL or GPL Version 2] license." If you do not indicate a
35 * single choice of license, a recipient has the option to distribute
36 * your version of this file under either the CDDL, the GPL Version 2 or
37 * to extend the choice of license to its licensees as provided above.
38 * However, if you add GPL Version 2 code and therefore, elected the GPL
39 * Version 2 license, then the option applies only if the new code is
40 * made subject to such option by the copyright holder.
42 package org
.nbgit
.ui
.commit
;
45 import java
.util
.Arrays
;
46 import java
.util
.HashMap
;
48 import java
.util
.ResourceBundle
;
49 import javax
.swing
.table
.AbstractTableModel
;
50 import org
.nbgit
.GitModuleConfig
;
51 import org
.nbgit
.StatusInfo
;
52 import org
.nbgit
.ui
.GitFileNode
;
53 import org
.nbgit
.util
.GitUtils
;
54 import org
.openide
.util
.NbBundle
;
57 * Table model for the Commit dialog table.
59 * @author Maros Sandor
61 public class CommitTableModel
extends AbstractTableModel
{
63 public static final String COLUMN_NAME_NAME
= "name"; // NOI18N
64 public static final String COLUMN_NAME_STATUS
= "status"; // NOI18N
65 public static final String COLUMN_NAME_ACTION
= "action"; // NOI18N
66 public static final String COLUMN_NAME_PATH
= "path"; // NOI18N
67 public static final String COLUMN_NAME_BRANCH
= "branch"; // NOI18N
69 private class RootFile
{
71 String repositoryPath
;
74 //private Set<SVNUrl> repositoryRoots;
75 private RootFile rootFile
;
77 * Defines labels for Versioning view table columns.
79 private static final Map
<String
, String
[]> columnLabels
= new HashMap
<String
, String
[]>(4);
83 ResourceBundle loc
= NbBundle
.getBundle(CommitTableModel
.class);
84 columnLabels
.put(COLUMN_NAME_NAME
, new String
[]{
85 loc
.getString("CTL_CommitTable_Column_File"), // NOI18N
86 loc
.getString("CTL_CommitTable_Column_File")
88 columnLabels
.put(COLUMN_NAME_BRANCH
, new String
[]{
89 loc
.getString("CTL_CommitTable_Column_Branch"), // NOI18N
90 loc
.getString("CTL_CommitTable_Column_Branch")
92 columnLabels
.put(COLUMN_NAME_STATUS
, new String
[]{
93 loc
.getString("CTL_CommitTable_Column_Status"), // NOI18N
94 loc
.getString("CTL_CommitTable_Column_Status")
96 columnLabels
.put(COLUMN_NAME_ACTION
, new String
[]{
97 loc
.getString("CTL_CommitTable_Column_Action"), // NOI18N
98 loc
.getString("CTL_CommitTable_Column_Action")
100 columnLabels
.put(COLUMN_NAME_PATH
, new String
[]{
101 loc
.getString("CTL_CommitTable_Column_Folder"), // NOI18N
102 loc
.getString("CTL_CommitTable_Column_Folder")
106 private CommitOptions
[] commitOptions
;
107 private GitFileNode
[] nodes
;
108 private String
[] columns
;
111 * Create stable with name, status, action and path columns
112 * and empty nodes {@link #setNodes model}.
114 public CommitTableModel(String
[] columns
)
117 setNodes(new GitFileNode
[0]);
120 void setNodes(GitFileNode
[] nodes
)
123 defaultCommitOptions();
124 fireTableDataChanged();
127 void setColumns(String
[] cols
)
129 if (Arrays
.equals(cols
, columns
))
132 fireTableStructureChanged();
136 * @return Map<GitFileNode, CommitOptions>
138 public Map
<GitFileNode
, CommitOptions
> getCommitFiles()
140 Map
<GitFileNode
, CommitOptions
> ret
= new HashMap
<GitFileNode
, CommitOptions
>(nodes
.length
);
141 for (int i
= 0; i
< nodes
.length
; i
++) {
142 ret
.put(nodes
[i
], commitOptions
[i
]);
148 public String
getColumnName(int column
)
150 return columnLabels
.get(columns
[column
])[0];
153 public int getColumnCount()
155 return columns
.length
;
158 public int getRowCount()
164 public Class
getColumnClass(int columnIndex
)
166 String col
= columns
[columnIndex
];
167 if (col
.equals(COLUMN_NAME_ACTION
))
168 return CommitOptions
.class;
173 public boolean isCellEditable(int rowIndex
, int columnIndex
)
175 String col
= columns
[columnIndex
];
176 return col
.equals(COLUMN_NAME_ACTION
);
179 public Object
getValueAt(int rowIndex
, int columnIndex
)
182 String col
= columns
[columnIndex
];
183 if (col
.equals(COLUMN_NAME_NAME
))
184 return nodes
[rowIndex
].getName();
185 else if (col
.equals(COLUMN_NAME_STATUS
)) {
186 node
= nodes
[rowIndex
];
187 StatusInfo finfo
= node
.getInformation();
188 //TODO what should we do with this?
189 //finfo.getEntry(node.getFile()); // HACK returned value is not interesting, point is side effect, it loads ISVNStatus structure
190 return finfo
.getStatusText();
191 } else if (col
.equals(COLUMN_NAME_ACTION
))
192 return commitOptions
[rowIndex
];
193 else if (col
.equals(COLUMN_NAME_PATH
)) {
194 String shortPath
= null;
195 // XXX this is a mess
196 if (rootFile
!= null) {
197 // must convert from native separators to slashes
198 String relativePath
= nodes
[rowIndex
].getFile().getAbsolutePath().substring(rootFile
.rootLocalPath
.length());
199 shortPath
= rootFile
.repositoryPath
+ relativePath
.replace(File
.separatorChar
, '/');
201 shortPath
= GitUtils
.getRelativePath(nodes
[rowIndex
].getFile());
202 if (shortPath
== null)
203 shortPath
= org
.openide
.util
.NbBundle
.getMessage(CommitTableModel
.class, "CTL_CommitForm_NotInRepository");
207 throw new IllegalArgumentException("Column index out of range: " + columnIndex
); // NOI18N
211 public void setValueAt(Object aValue
, int rowIndex
, int columnIndex
)
213 String col
= columns
[columnIndex
];
214 if (col
.equals(COLUMN_NAME_ACTION
)) {
215 commitOptions
[rowIndex
] = (CommitOptions
) aValue
;
216 fireTableCellUpdated(rowIndex
, columnIndex
);
218 throw new IllegalArgumentException("Column index out of range: " + columnIndex
);
221 private void defaultCommitOptions()
223 boolean excludeNew
= System
.getProperty("netbeans.git.excludeNewFiles") != null; // NOI18N
224 commitOptions
= new CommitOptions
[nodes
.length
];
225 for (int i
= 0; i
< nodes
.length
; i
++) {
226 GitFileNode node
= nodes
[i
];
227 File file
= node
.getFile();
228 if (GitModuleConfig
.getDefault().isExcludedFromCommit(file
.getAbsolutePath()))
229 commitOptions
[i
] = CommitOptions
.EXCLUDE
;
231 switch (node
.getInformation().getStatus()) {
232 case StatusInfo
.STATUS_VERSIONED_DELETEDLOCALLY
:
233 case StatusInfo
.STATUS_VERSIONED_REMOVEDLOCALLY
:
234 commitOptions
[i
] = CommitOptions
.COMMIT_REMOVE
;
237 commitOptions
[i
] = CommitOptions
.COMMIT
;
242 public GitFileNode
getNode(int row
)
247 public CommitOptions
getOptions(int row
)
249 return commitOptions
[row
];
252 void setRootFile(String repositoryPath
, String rootLocalPath
)
254 rootFile
= new RootFile();
255 rootFile
.repositoryPath
= repositoryPath
;
256 rootFile
.rootLocalPath
= rootLocalPath
;