Source Code Cross Referenced for DefaultUndoAction.java in  » UML » jrefactory » org » acm » seguin » refactor » undo » 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 » UML » jrefactory » org.acm.seguin.refactor.undo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Author:  Chris Seguin
003:         *
004:         *  This software has been developed under the copyleft
005:         *  rules of the GNU General Public License.  Please
006:         *  consult the GNU General Public License for more
007:         *  details about use and distribution of this software.
008:         */
009:        package org.acm.seguin.refactor.undo;
010:
011:        import java.io.File;
012:        import java.io.Serializable;
013:        import java.util.Iterator;
014:        import java.util.LinkedList;
015:        import org.acm.seguin.util.FileSettings;
016:        import org.acm.seguin.util.MissingSettingsException;
017:
018:        /**
019:         *  Stores the undo operation. The undo operation consists of a description of
020:         *  the refactoring that was performed to create this UndoAction and a list of
021:         *  files that have changed. <P>
022:         *
023:         *  The files that have changed are indexed files, in that they have an index
024:         *  appended to the name of the file.
025:         *
026:         *@author    Chris Seguin
027:         */
028:        public class DefaultUndoAction implements  UndoAction, Serializable {
029:            /**
030:             *  A description of the refactoring
031:             *
032:             *@serial    true
033:             */
034:            private String description;
035:
036:            /**
037:             *  A linked list
038:             *
039:             *@serial    true
040:             */
041:            private LinkedList list;
042:
043:            /**
044:             *  Constructor for the UndoAction object
045:             *
046:             */
047:            public DefaultUndoAction() {
048:                //System.out.println("DefaultUndoAction()");
049:                description = "unknown";
050:                list = new LinkedList();
051:            }
052:
053:            /**
054:             *  Sets the Description attribute of the UndoAction object
055:             *
056:             *@param  description  the description of the action
057:             */
058:            public void setDescription(String description) {
059:                //System.out.println("DefaultUndoAction.setDescription("+description+")");
060:                this .description = description;
061:            }
062:
063:            /**
064:             *  Gets the Description attribute of the UndoAction object
065:             *
066:             *@return    The Description value
067:             */
068:            public String getDescription() {
069:                //System.out.println("DefaultUndoAction.setDescription() => "+description);
070:                return description;
071:            }
072:
073:            /**
074:             *  Adds a file to this action
075:             *
076:             *@param  oldFile  the original file
077:             *@param  newFile  the new file
078:             */
079:            public void add(File oldFile, File newFile) {
080:                //System.out.println("DefaultUndoAction.add("+oldFile+","+newFile+")");
081:                File dest = null;
082:                if (oldFile == null) {
083:                    dest = null;
084:                } else {
085:                    //  Get the parent directory and the name
086:                    File parent = oldFile.getParentFile();
087:                    String name = oldFile.getName();
088:
089:                    //  Find the file's next index location
090:                    dest = findNextStorageSlot(parent, name);
091:
092:                    //  Renames the file
093:                    oldFile.renameTo(dest);
094:                }
095:
096:                //System.out.println("  list.add(new FileSet("+oldFile+","+dest+","+newFile+"))");
097:                list.add(new FileSet(oldFile, dest, newFile));
098:            }
099:
100:            /**
101:             *  Undo the current action
102:             */
103:            public void undo() {
104:                //System.out.println("UndoAction.undo()");
105:                Iterator iter = list.iterator();
106:                while (iter.hasNext()) {
107:                    ((FileSet) iter.next()).undo();
108:                }
109:            }
110:
111:            /**
112:             *  Gets the NextName attribute of the UndoAction object
113:             *
114:             *@param  name     Description of Parameter
115:             *@param  index    Description of Parameter
116:             *@param  pattern  Description of Parameter
117:             *@return          The NextName value
118:             */
119:            private String getNextName(String name, int index, String pattern) {
120:                StringBuffer buffer = new StringBuffer(name);
121:                char ch;
122:
123:                for (int ndx = 0; ndx < pattern.length(); ndx++) {
124:                    ch = pattern.charAt(ndx);
125:                    if (ch == '#') {
126:                        buffer.append(index);
127:                    } else {
128:                        buffer.append(ch);
129:                    }
130:                }
131:
132:                return buffer.toString();
133:            }
134:
135:            /**
136:             *  Finds the next slot to store the original file
137:             *
138:             *@param  dir   the directory that the original file is contained in
139:             *@param  name  the name of the original file
140:             *@return       Description of the Returned Value
141:             */
142:            private File findNextStorageSlot(File dir, String name) {
143:                String pattern = ".#";
144:
145:                try {
146:                    FileSettings umlBundle = FileSettings
147:                            .getRefactorySettings("uml");
148:                    umlBundle.setContinuallyReload(true);
149:                    pattern = umlBundle.getString("backup.ext");
150:                } catch (MissingSettingsException mse) {
151:                    //  The default is fine
152:                }
153:
154:                File dest = null;
155:                int index = 0;
156:                do {
157:                    dest = new File(dir, getNextName(name, index, pattern));
158:                    index++;
159:                } while (dest.exists());
160:                return dest;
161:            }
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.