Source Code Cross Referenced for CreateFileOperation.java in  » IDE-Eclipse » ui-ide » org » eclipse » ui » ide » 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 » IDE Eclipse » ui ide » org.eclipse.ui.ide.undo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2006, 2007 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.ide.undo;
011:
012:        import java.io.ByteArrayInputStream;
013:        import java.io.InputStream;
014:        import java.net.URI;
015:
016:        import org.eclipse.core.resources.IFile;
017:        import org.eclipse.core.runtime.CoreException;
018:        import org.eclipse.ui.internal.ide.undo.ContainerDescription;
019:        import org.eclipse.ui.internal.ide.undo.FileDescription;
020:        import org.eclipse.ui.internal.ide.undo.IFileContentDescription;
021:
022:        /**
023:         * A CreateFileOperation represents an undoable operation for creating a file in
024:         * the workspace. If a link location is specified, the folder is considered to
025:         * be linked to the file at the specified location. If a link location is not
026:         * specified, the file will be created in the location specified by the handle,
027:         * and the entire containment path of the file will be created if it does not
028:         * exist. Clients may call the public API from a background thread.
029:         * 
030:         * This class is intended to be instantiated and used by clients. It is not
031:         * intended to be subclassed by clients.
032:         * 
033:         * @since 3.3
034:         * 
035:         */
036:        public class CreateFileOperation extends
037:                AbstractCreateResourcesOperation {
038:
039:            /**
040:             * Create a CreateFileOperation
041:             * 
042:             * @param fileHandle
043:             *            the file to be created
044:             * @param linkLocation
045:             *            the location of the file if it is to be linked
046:             * @param contents
047:             *            the initial contents of the file, or null if there is to be no
048:             *            contents
049:             * @param label
050:             *            the label of the operation
051:             */
052:            public CreateFileOperation(IFile fileHandle, URI linkLocation,
053:                    InputStream contents, String label) {
054:                super (null, label);
055:                ResourceDescription resourceDescription;
056:                if (fileHandle.getParent().exists()) {
057:                    resourceDescription = new FileDescription(fileHandle,
058:                            linkLocation, createFileContentDescription(
059:                                    fileHandle, contents));
060:                } else {
061:                    // must first ensure descriptions for the parent folders are
062:                    // created
063:                    ContainerDescription containerDescription = ContainerDescription
064:                            .fromContainer(fileHandle.getParent());
065:                    containerDescription.getFirstLeafFolder().addMember(
066:                            new FileDescription(fileHandle, linkLocation,
067:                                    createFileContentDescription(fileHandle,
068:                                            contents)));
069:                    resourceDescription = containerDescription;
070:                }
071:                setResourceDescriptions(new ResourceDescription[] { resourceDescription });
072:
073:            }
074:
075:            /*
076:             * Create a file state that represents the desired contents and attributes
077:             * of the file to be created. Used to mimic file history when a resource is
078:             * first created.
079:             */
080:            private IFileContentDescription createFileContentDescription(
081:                    final IFile file, final InputStream contents) {
082:                return new IFileContentDescription() {
083:                    /*
084:                     * (non-Javadoc)
085:                     * 
086:                     * @see org.eclipse.ui.internal.ide.undo.IFileContentDescription#getContents()
087:                     */
088:                    public InputStream getContents() {
089:                        if (contents != null) {
090:                            return contents;
091:                        }
092:                        return new ByteArrayInputStream(new byte[0]);
093:                    }
094:
095:                    /*
096:                     * (non-Javadoc)
097:                     * 
098:                     * @see org.eclipse.ui.internal.ide.undo.IFileContentDescription#getCharset()
099:                     */
100:                    public String getCharset() {
101:                        try {
102:                            return file.getCharset(false);
103:                        } catch (CoreException e) {
104:                            return null;
105:                        }
106:                    }
107:
108:                    /*
109:                     * (non-Javadoc)
110:                     * 
111:                     * @see org.eclipse.ui.internal.ide.undo.IFileContentDescription#exists()
112:                     */
113:                    public boolean exists() {
114:                        return true;
115:                    }
116:                };
117:            }
118:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.