Source Code Cross Referenced for CommitTableModel.java in  » IDE-Netbeans » subversion » org » netbeans » modules » subversion » ui » commit » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » subversion » org.netbeans.modules.subversion.ui.commit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.subversion.ui.commit;
043:
044:        import org.openide.util.NbBundle;
045:        import org.netbeans.modules.subversion.SvnFileNode;
046:        import org.netbeans.modules.subversion.FileInformation;
047:        import org.netbeans.modules.subversion.util.SvnUtils;
048:        import org.netbeans.modules.subversion.SvnModuleConfig;
049:        import javax.swing.table.AbstractTableModel;
050:        import java.util.*;
051:        import java.io.File;
052:        import org.netbeans.modules.subversion.Subversion;
053:        import org.netbeans.modules.subversion.client.SvnClientExceptionHandler;
054:        import org.netbeans.modules.versioning.util.Utils;
055:        import org.tigris.subversion.svnclientadapter.SVNClientException;
056:        import org.tigris.subversion.svnclientadapter.SVNUrl;
057:
058:        /**
059:         * Table model for the Commit dialog table.
060:         *
061:         * @author Maros Sandor
062:         */
063:        public class CommitTableModel extends AbstractTableModel {
064:
065:            public static final String COLUMN_NAME_NAME = "name"; // NOI18N
066:            public static final String COLUMN_NAME_STATUS = "status"; // NOI18N
067:            public static final String COLUMN_NAME_ACTION = "action"; // NOI18N
068:            public static final String COLUMN_NAME_PATH = "path"; // NOI18N
069:            public static final String COLUMN_NAME_BRANCH = "branch"; // NOI18N
070:
071:            private class RootFile {
072:                String repositoryPath;
073:                String rootLocalPath;
074:            }
075:
076:            private Set<SVNUrl> repositoryRoots;
077:            private RootFile rootFile;
078:
079:            /**
080:             * Defines labels for Versioning view table columns.
081:             */
082:            private static final Map<String, String[]> columnLabels = new HashMap<String, String[]>(
083:                    4);
084:
085:            {
086:                ResourceBundle loc = NbBundle.getBundle(CommitTableModel.class);
087:                columnLabels.put(COLUMN_NAME_NAME, new String[] {
088:                        loc.getString("CTL_CommitTable_Column_File"),
089:                        loc.getString("CTL_CommitTable_Column_File") });
090:                columnLabels.put(COLUMN_NAME_BRANCH, new String[] {
091:                        loc.getString("CTL_CommitTable_Column_Branch"),
092:                        loc.getString("CTL_CommitTable_Column_Branch") });
093:                columnLabels.put(COLUMN_NAME_STATUS, new String[] {
094:                        loc.getString("CTL_CommitTable_Column_Status"),
095:                        loc.getString("CTL_CommitTable_Column_Status") });
096:                columnLabels.put(COLUMN_NAME_ACTION, new String[] {
097:                        loc.getString("CTL_CommitTable_Column_Action"),
098:                        loc.getString("CTL_CommitTable_Column_Action") });
099:                columnLabels.put(COLUMN_NAME_PATH, new String[] {
100:                        loc.getString("CTL_CommitTable_Column_Folder"),
101:                        loc.getString("CTL_CommitTable_Column_Folder") });
102:            }
103:
104:            private CommitOptions[] commitOptions;
105:            private SvnFileNode[] nodes;
106:
107:            private String[] columns;
108:
109:            /**
110:             * Create stable with name, status, action and path columns
111:             * and empty nodes {@link #setNodes model}.
112:             */
113:            public CommitTableModel(String[] columns) {
114:                setColumns(columns);
115:                setNodes(new SvnFileNode[0]);
116:            }
117:
118:            void setNodes(SvnFileNode[] nodes) {
119:                this .nodes = nodes;
120:                defaultCommitOptions();
121:                fireTableDataChanged();
122:            }
123:
124:            void setColumns(String[] cols) {
125:                if (Arrays.equals(cols, columns))
126:                    return;
127:                columns = cols;
128:                fireTableStructureChanged();
129:            }
130:
131:            /**
132:             * @return Map&lt;SvnFileNode, CommitOptions>
133:             */
134:            public Map<SvnFileNode, CommitOptions> getCommitFiles() {
135:                Map<SvnFileNode, CommitOptions> ret = new HashMap<SvnFileNode, CommitOptions>(
136:                        nodes.length);
137:                for (int i = 0; i < nodes.length; i++) {
138:                    ret.put(nodes[i], commitOptions[i]);
139:                }
140:                return ret;
141:            }
142:
143:            public String getColumnName(int column) {
144:                return columnLabels.get(columns[column])[0];
145:            }
146:
147:            public int getColumnCount() {
148:                return columns.length;
149:            }
150:
151:            public int getRowCount() {
152:                return nodes.length;
153:            }
154:
155:            public Class getColumnClass(int columnIndex) {
156:                String col = columns[columnIndex];
157:                if (col.equals(COLUMN_NAME_ACTION)) {
158:                    return CommitOptions.class;
159:                }
160:                return String.class;
161:            }
162:
163:            public boolean isCellEditable(int rowIndex, int columnIndex) {
164:                String col = columns[columnIndex];
165:                return col.equals(COLUMN_NAME_ACTION);
166:            }
167:
168:            public Object getValueAt(int rowIndex, int columnIndex) {
169:                SvnFileNode node;
170:                String col = columns[columnIndex];
171:                if (col.equals(COLUMN_NAME_NAME)) {
172:                    return nodes[rowIndex].getName();
173:                } else if (col.equals(COLUMN_NAME_BRANCH)) {
174:                    String branch = SvnUtils.getCopy(nodes[rowIndex].getFile());
175:                    return branch == null ? "" : branch; // NOI18N
176:                } else if (col.equals(COLUMN_NAME_STATUS)) {
177:                    node = nodes[rowIndex];
178:                    FileInformation finfo = node.getInformation();
179:                    finfo.getEntry(node.getFile()); // HACK returned value is not interesting, point is side effect, it loads ISVNStatus structure
180:                    return finfo.getStatusText();
181:                } else if (col.equals(COLUMN_NAME_ACTION)) {
182:                    return commitOptions[rowIndex];
183:                } else if (col.equals(COLUMN_NAME_PATH)) {
184:                    String shortPath = null;
185:                    // XXX this is a mess
186:                    if (rootFile != null) {
187:                        // must convert from native separators to slashes
188:                        String relativePath = nodes[rowIndex].getFile()
189:                                .getAbsolutePath().substring(
190:                                        rootFile.rootLocalPath.length());
191:                        shortPath = rootFile.repositoryPath
192:                                + relativePath.replace(File.separatorChar, '/');
193:                    } else {
194:                        Set<SVNUrl> url = getRepositoryRoots();
195:                        try {
196:                            for (Iterator<SVNUrl> it = url.iterator(); it
197:                                    .hasNext();) {
198:                                SVNUrl nextUrl = it.next();
199:                                shortPath = SvnUtils.getRelativePath(nextUrl,
200:                                        nodes[rowIndex].getFile());
201:                            }
202:                            if (shortPath == null) {
203:
204:                                SVNUrl newUrl = SvnUtils
205:                                        .getRepositoryRootUrl(nodes[rowIndex]
206:                                                .getFile());
207:                                shortPath = SvnUtils.getRelativePath(newUrl,
208:                                        nodes[rowIndex].getFile());
209:                                url.add(newUrl);
210:
211:                            }
212:                        } catch (SVNClientException ex) {
213:                            SvnClientExceptionHandler.notifyException(ex,
214:                                    false, false);
215:                        }
216:                        if (shortPath == null) {
217:                            shortPath = org.openide.util.NbBundle.getMessage(
218:                                    CommitTableModel.class,
219:                                    "CTL_CommitForm_NotInRepository"); // NOI18N
220:                        }
221:                    }
222:                    return shortPath;
223:                }
224:                throw new IllegalArgumentException(
225:                        "Column index out of range: " + columnIndex); // NOI18N
226:            }
227:
228:            public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
229:                String col = columns[columnIndex];
230:                if (col.equals(COLUMN_NAME_ACTION)) {
231:                    commitOptions[rowIndex] = (CommitOptions) aValue;
232:                    fireTableCellUpdated(rowIndex, columnIndex);
233:                } else {
234:                    throw new IllegalArgumentException(
235:                            "Column index out of range: " + columnIndex); // NOI18N
236:                }
237:            }
238:
239:            private void defaultCommitOptions() {
240:                boolean excludeNew = System
241:                        .getProperty("netbeans.subversion.excludeNewFiles") != null; // NOI18N
242:                commitOptions = new CommitOptions[nodes.length];
243:                for (int i = 0; i < nodes.length; i++) {
244:                    SvnFileNode node = nodes[i];
245:                    File file = node.getFile();
246:                    if (SvnModuleConfig.getDefault().isExcludedFromCommit(
247:                            file.getAbsolutePath())) {
248:                        commitOptions[i] = CommitOptions.EXCLUDE;
249:                    } else {
250:                        switch (node.getInformation().getStatus()) {
251:                        case FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY:
252:                            commitOptions[i] = excludeNew ? CommitOptions.EXCLUDE
253:                                    : getDefaultCommitOptions(node.getFile());
254:                            break;
255:                        case FileInformation.STATUS_VERSIONED_DELETEDLOCALLY:
256:                        case FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY:
257:                            commitOptions[i] = CommitOptions.COMMIT_REMOVE;
258:                            break;
259:                        default:
260:                            commitOptions[i] = CommitOptions.COMMIT;
261:                        }
262:                    }
263:                }
264:            }
265:
266:            public SvnFileNode getNode(int row) {
267:                return nodes[row];
268:            }
269:
270:            public CommitOptions getOptions(int row) {
271:                return commitOptions[row];
272:            }
273:
274:            private CommitOptions getDefaultCommitOptions(File file) {
275:                if (file.isFile()) {
276:                    if (SvnUtils.getMimeType(file).startsWith("text")) {
277:                        return CommitOptions.ADD_TEXT;
278:                    } else {
279:                        return CommitOptions.ADD_BINARY;
280:                    }
281:                } else {
282:                    return CommitOptions.ADD_DIRECTORY;
283:                }
284:            }
285:
286:            private Set<SVNUrl> getRepositoryRoots() {
287:                if (repositoryRoots == null) {
288:                    repositoryRoots = new HashSet<SVNUrl>();
289:                }
290:                return repositoryRoots;
291:            }
292:
293:            void setRootFile(String repositoryPath, String rootLocalPath) {
294:                rootFile = new RootFile();
295:                rootFile.repositoryPath = repositoryPath;
296:                rootFile.rootLocalPath = rootLocalPath;
297:            }
298:
299:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.