Source Code Cross Referenced for SchemaInputContext.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » internal » ui » editor » schema » 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 » Eclipse plug in development » org.eclipse.pde.internal.ui.editor.schema 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 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.pde.internal.ui.editor.schema;
011:
012:        import java.io.ByteArrayInputStream;
013:        import java.io.File;
014:        import java.io.IOException;
015:        import java.io.InputStream;
016:        import java.io.PrintWriter;
017:        import java.io.StringWriter;
018:        import java.io.UnsupportedEncodingException;
019:        import java.util.ArrayList;
020:
021:        import org.eclipse.core.resources.IFile;
022:        import org.eclipse.core.resources.IStorage;
023:        import org.eclipse.core.runtime.CoreException;
024:        import org.eclipse.jface.text.IDocument;
025:        import org.eclipse.pde.core.IBaseModel;
026:        import org.eclipse.pde.core.IEditable;
027:        import org.eclipse.pde.core.IModelChangedEvent;
028:        import org.eclipse.pde.internal.core.ischema.ISchema;
029:        import org.eclipse.pde.internal.core.schema.EditableSchema;
030:        import org.eclipse.pde.internal.core.schema.Schema;
031:        import org.eclipse.pde.internal.core.schema.SchemaDescriptor;
032:        import org.eclipse.pde.internal.core.schema.StorageSchemaDescriptor;
033:        import org.eclipse.pde.internal.ui.PDEPlugin;
034:        import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
035:        import org.eclipse.pde.internal.ui.editor.SystemFileEditorInput;
036:        import org.eclipse.pde.internal.ui.editor.context.XMLInputContext;
037:        import org.eclipse.ui.IEditorInput;
038:        import org.eclipse.ui.IFileEditorInput;
039:        import org.eclipse.ui.IStorageEditorInput;
040:        import org.eclipse.ui.texteditor.IDocumentProvider;
041:
042:        /**
043:         *
044:         */
045:        public class SchemaInputContext extends XMLInputContext {
046:            public static final String CONTEXT_ID = "schema-context"; //$NON-NLS-1$
047:
048:            /**
049:             * @param editor
050:             * @param input
051:             * @param primary
052:             */
053:            public SchemaInputContext(PDEFormEditor editor, IEditorInput input,
054:                    boolean primary) {
055:                super (editor, input, primary);
056:                create();
057:            }
058:
059:            /* (non-Javadoc)
060:             * @see org.eclipse.pde.internal.ui.neweditor.context.InputContext#getId()
061:             */
062:            public String getId() {
063:                return CONTEXT_ID;
064:            }
065:
066:            /* (non-Javadoc)
067:             * @see org.eclipse.pde.internal.ui.neweditor.context.InputContext#createModel(org.eclipse.ui.IEditorInput)
068:             */
069:            protected IBaseModel createModel(IEditorInput input)
070:                    throws CoreException {
071:                if (input instanceof  SystemFileEditorInput)
072:                    return createExternalModel((SystemFileEditorInput) input);
073:
074:                if (!(input instanceof  IFileEditorInput)) {
075:                    if (input instanceof  IStorageEditorInput)
076:                        return createStorageModel((IStorageEditorInput) input);
077:                    return null;
078:                }
079:
080:                IFile file = ((IFileEditorInput) input).getFile();
081:                SchemaDescriptor sd = new SchemaDescriptor(file, true);
082:                ISchema schema = sd.getSchema(false);
083:                if (schema instanceof  EditableSchema) {
084:                    ((EditableSchema) schema).setNotificationEnabled(true);
085:                }
086:                return schema;
087:            }
088:
089:            private IBaseModel createExternalModel(SystemFileEditorInput input) {
090:                File file = (File) input.getAdapter(File.class);
091:                SchemaDescriptor sd = new SchemaDescriptor(file);
092:
093:                ISchema schema = sd.getSchema(false);
094:                if (schema instanceof  EditableSchema) {
095:                    ((EditableSchema) schema).setNotificationEnabled(true);
096:                }
097:                return schema;
098:            }
099:
100:            private IBaseModel createStorageModel(IStorageEditorInput input) {
101:                try {
102:                    IStorage storage = input.getStorage();
103:                    StorageSchemaDescriptor sd = new StorageSchemaDescriptor(
104:                            storage);
105:                    ISchema schema = sd.getSchema(false);
106:                    return schema;
107:                } catch (CoreException e) {
108:                    PDEPlugin.logException(e);
109:                    return null;
110:                }
111:            }
112:
113:            /* (non-Javadoc)
114:             * @see org.eclipse.pde.internal.ui.neweditor.context.InputContext#addTextEditOperation(java.util.ArrayList, org.eclipse.pde.core.IModelChangedEvent)
115:             */
116:            protected void addTextEditOperation(ArrayList ops,
117:                    IModelChangedEvent event) {
118:            }
119:
120:            protected void flushModel(IDocument doc) {
121:                // if model is dirty, flush its content into
122:                // the document so that the source editor will
123:                // pick up the changes.
124:                if (!(getModel() instanceof  IEditable))
125:                    return;
126:                IEditable editableModel = (IEditable) getModel();
127:                if (editableModel.isDirty() == false)
128:                    return;
129:                try {
130:                    StringWriter swriter = new StringWriter();
131:                    PrintWriter writer = new PrintWriter(swriter);
132:                    editableModel.save(writer);
133:                    writer.flush();
134:                    swriter.close();
135:                    doc.set(swriter.toString());
136:                } catch (IOException e) {
137:                    PDEPlugin.logException(e);
138:                }
139:            }
140:
141:            /* (non-Javadoc)
142:             * @see org.eclipse.pde.internal.ui.editor.context.InputContext#flushEditorInput()
143:             */
144:            public void flushEditorInput() {
145:                // Override parent, since this editor does not utilize edit operations
146:                IDocumentProvider provider = getDocumentProvider();
147:                IEditorInput input = getInput();
148:                IDocument doc = provider.getDocument(input);
149:                provider.aboutToChange(input);
150:                flushModel(doc);
151:                provider.changed(input);
152:                setValidated(false);
153:            }
154:
155:            protected boolean synchronizeModel(IDocument doc) {
156:                Schema schema = (Schema) getModel();
157:                if (schema == null) {
158:                    // if model is null try to recreate it
159:                    create();
160:                    return getModel() == null;
161:                }
162:                String text = doc.get();
163:                try {
164:                    InputStream stream = new ByteArrayInputStream(text
165:                            .getBytes("UTF8")); //$NON-NLS-1$
166:                    schema.reload(stream);
167:                    if (schema instanceof  IEditable)
168:                        ((IEditable) schema).setDirty(false);
169:                    try {
170:                        stream.close();
171:                    } catch (IOException e) {
172:                    }
173:                } catch (UnsupportedEncodingException e) {
174:                    PDEPlugin.logException(e);
175:                    return false;
176:                }
177:                return true;
178:            }
179:
180:            /* (non-Javadoc)
181:             * @see org.eclipse.pde.internal.ui.neweditor.context.XMLInputContext#reorderInsertEdits(java.util.ArrayList)
182:             */
183:            protected void reorderInsertEdits(ArrayList ops) {
184:            }
185:
186:            protected String getPartitionName() {
187:                return "___schema_partition"; //$NON-NLS-1$
188:            }
189:        }
w___w_w__.__j_a_v_a2___s___.c__o_m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.