Source Code Cross Referenced for SchemaRearranger.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) 2005, 2006 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 org.eclipse.pde.internal.core.ischema.ISchema;
013:        import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
014:        import org.eclipse.pde.internal.core.ischema.ISchemaComplexType;
015:        import org.eclipse.pde.internal.core.ischema.ISchemaCompositor;
016:        import org.eclipse.pde.internal.core.ischema.ISchemaElement;
017:        import org.eclipse.pde.internal.core.ischema.ISchemaObject;
018:        import org.eclipse.pde.internal.core.ischema.ISchemaObjectReference;
019:        import org.eclipse.pde.internal.core.ischema.ISchemaRootElement;
020:        import org.eclipse.pde.internal.core.ischema.ISchemaType;
021:        import org.eclipse.pde.internal.core.schema.Schema;
022:        import org.eclipse.pde.internal.core.schema.SchemaAttribute;
023:        import org.eclipse.pde.internal.core.schema.SchemaComplexType;
024:        import org.eclipse.pde.internal.core.schema.SchemaCompositor;
025:        import org.eclipse.pde.internal.core.schema.SchemaElement;
026:        import org.eclipse.pde.internal.core.schema.SchemaElementReference;
027:        import org.eclipse.pde.internal.core.schema.SchemaSimpleType;
028:        import org.eclipse.pde.internal.ui.util.PDELabelUtility;
029:
030:        public class SchemaRearranger {
031:
032:            private Schema fSchema;
033:
034:            public SchemaRearranger(Schema schema) {
035:                fSchema = schema;
036:            }
037:
038:            public void moveCompositor(ISchemaObject newParent,
039:                    ISchemaCompositor compositor) {
040:                ISchemaObject oldParent = compositor.getParent();
041:                if (!(newParent != null && compositor != null
042:                        && !newParent.equals(oldParent) && !newParent
043:                        .equals(compositor)))
044:                    return;
045:                if (newParent instanceof  SchemaElement) {
046:                    SchemaElement element = (SchemaElement) newParent;
047:                    SchemaComplexType type = null;
048:                    if (element.getType() instanceof  SchemaComplexType) {
049:                        type = (SchemaComplexType) element.getType();
050:                        type.setCompositor(compositor);
051:                    } else {
052:                        type = new SchemaComplexType(element.getSchema());
053:                        type.setCompositor(compositor);
054:                        element.setType(type);
055:                    }
056:                } else if (newParent instanceof  SchemaCompositor) {
057:                    ((SchemaCompositor) newParent).addChild(compositor);
058:                } else
059:                    // unknown new parent, abort
060:                    return;
061:
062:                if (oldParent instanceof  SchemaElement) {
063:                    ISchemaType oldType = ((SchemaElement) oldParent).getType();
064:                    if (oldType instanceof  ISchemaComplexType) {
065:                        ((SchemaComplexType) oldType).setCompositor(null);
066:                    }
067:                } else if (oldParent instanceof  SchemaCompositor) {
068:                    ((SchemaCompositor) oldParent).removeChild(compositor);
069:                }
070:                compositor.setParent(newParent);
071:            }
072:
073:            public void moveReference(SchemaElementReference reference,
074:                    ISchemaCompositor compositor, ISchemaObject sibling) {
075:                ISchemaCompositor oldCompositor = reference.getCompositor();
076:                if (!(compositor != null && reference != null && oldCompositor != null))
077:                    return;
078:                if (compositor instanceof  SchemaCompositor) {
079:                    if (compositor.equals(oldCompositor)) {
080:                        ((SchemaCompositor) compositor).moveChildToSibling(
081:                                reference, sibling);
082:                    } else {
083:                        ((SchemaCompositor) oldCompositor)
084:                                .removeChild(reference);
085:                        reference.setCompositor(compositor);
086:                        ((SchemaCompositor) compositor).addChild(reference);
087:                    }
088:                }
089:            }
090:
091:            public void moveElement(ISchemaObject parent,
092:                    ISchemaElement element, ISchemaObject sibling) {
093:                if (element == null)
094:                    return;
095:                if (fSchema.equals(parent)) {
096:                    fSchema.moveElementToSibling(element, sibling);
097:                } else if (parent instanceof  ISchemaCompositor) {
098:                    linkReference((ISchemaCompositor) parent, element, sibling);
099:                }
100:            }
101:
102:            public void moveAttribute(ISchemaElement newParent,
103:                    ISchemaAttribute attribute, ISchemaAttribute sibling) {
104:                ISchemaObject oldParent = attribute.getParent();
105:                if (!(attribute != null && newParent != null && oldParent != null))
106:                    return;
107:                SchemaComplexType type = null;
108:                if (newParent.getType() instanceof  SchemaComplexType) {
109:                    type = (SchemaComplexType) newParent.getType();
110:                } else {
111:                    type = new SchemaComplexType(newParent.getSchema());
112:                    ((SchemaElement) newParent).setType(type);
113:                }
114:                if (newParent.equals(oldParent)) {
115:                    type.moveAttributeTo(attribute, sibling);
116:                } else {
117:                    if (oldParent instanceof  ISchemaElement
118:                            && ((ISchemaElement) oldParent).getType() instanceof  SchemaComplexType) {
119:                        SchemaComplexType oldType = (SchemaComplexType) ((ISchemaElement) oldParent)
120:                                .getType();
121:                        oldType.removeAttribute(attribute);
122:                    }
123:                    attribute.setParent(newParent);
124:                    if (attribute instanceof  SchemaAttribute)
125:                        ((SchemaAttribute) attribute).setName(PDELabelUtility
126:                                .generateName(newParent.getAttributeNames(),
127:                                        PDELabelUtility.getBaseName(attribute
128:                                                .getName(), false), false));
129:                    type.addAttribute(attribute, sibling);
130:                }
131:            }
132:
133:            public void pasteCompositor(ISchemaObject realTarget,
134:                    ISchemaCompositor compositor, ISchemaObject sibling) {
135:                if (realTarget instanceof  SchemaElement) {
136:                    SchemaElement element = (SchemaElement) realTarget;
137:                    SchemaComplexType type = null;
138:                    if (element.getType() instanceof  SchemaComplexType) {
139:                        type = (SchemaComplexType) element.getType();
140:                        type.setCompositor(compositor);
141:                    } else {
142:                        type = new SchemaComplexType(element.getSchema());
143:                        element.setType(type);
144:                        type.setCompositor(compositor);
145:                    }
146:                } else if (realTarget instanceof  SchemaCompositor) {
147:                    ((SchemaCompositor) realTarget).addChild(compositor,
148:                            sibling);
149:                }
150:            }
151:
152:            public void pasteReference(ISchemaObject realTarget,
153:                    ISchemaObjectReference object, ISchemaObject sibling) {
154:                if (realTarget instanceof  SchemaCompositor) {
155:                    SchemaCompositor parent = (SchemaCompositor) realTarget;
156:                    ((SchemaElementReference) object).setCompositor(parent);
157:                    parent.addChild((SchemaElementReference) object, sibling);
158:                }
159:            }
160:
161:            public void pasteElement(ISchemaElement object,
162:                    ISchemaObject sibling) {
163:                SchemaElement element = (SchemaElement) object;
164:                element.setParent(fSchema);
165:                element.setName(PDELabelUtility.generateName(element
166:                        .getSchema().getElementNames(), PDELabelUtility
167:                        .getBaseName(element.getName(), false), false));
168:                fSchema.addElement(element, (ISchemaElement) sibling);
169:                fSchema.updateReferencesFor(element, ISchema.REFRESH_ADD);
170:            }
171:
172:            public void pasteAttribute(ISchemaElement realTarget,
173:                    ISchemaAttribute object, ISchemaObject sibling) {
174:                SchemaElement element = (SchemaElement) realTarget;
175:                SchemaAttribute attribute = (SchemaAttribute) object;
176:                attribute.setParent(element);
177:                attribute.setName(PDELabelUtility.generateName(element
178:                        .getAttributeNames(), PDELabelUtility.getBaseName(
179:                        attribute.getName(), false), false));
180:                ISchemaType type = element.getType();
181:                SchemaComplexType complexType = null;
182:                if (!(type instanceof  ISchemaComplexType)) {
183:                    complexType = new SchemaComplexType(element.getSchema());
184:                    element.setType(complexType);
185:                } else {
186:                    complexType = (SchemaComplexType) type;
187:                }
188:                if (sibling instanceof  ISchemaAttribute)
189:                    complexType.addAttribute(attribute,
190:                            (ISchemaAttribute) sibling);
191:                else
192:                    complexType.addAttribute(attribute);
193:            }
194:
195:            public void linkReference(ISchemaCompositor realTarget,
196:                    ISchemaElement object, ISchemaObject sibling) {
197:                if (sibling instanceof  SchemaElementReference)
198:                    realTarget = ((SchemaElementReference) sibling)
199:                            .getCompositor();
200:
201:                SchemaCompositor parent = (SchemaCompositor) realTarget;
202:                String refName = object.getName();
203:                SchemaElementReference reference = new SchemaElementReference(
204:                        parent, refName);
205:                reference.setReferencedObject(fSchema.findElement(refName));
206:                parent.addChild(reference, sibling);
207:            }
208:
209:            public void deleteCompositor(ISchemaCompositor compositor) {
210:                ISchemaObject cparent = compositor.getParent();
211:                if (cparent instanceof  ISchemaElement) {
212:                    SchemaElement element = (SchemaElement) cparent;
213:                    ISchemaType type = element.getType();
214:                    if (type instanceof  SchemaComplexType
215:                            && ((SchemaComplexType) type).getAttributeCount() != 0)
216:                        ((SchemaComplexType) type).setCompositor(null);
217:                    else
218:                        element.setType(new SchemaSimpleType(element
219:                                .getSchema(), "string")); //$NON-NLS-1$
220:
221:                } else if (cparent instanceof  SchemaCompositor) {
222:                    ((SchemaCompositor) cparent).removeChild(compositor);
223:                }
224:            }
225:
226:            public void deleteAttribute(ISchemaAttribute attribute) {
227:                ISchemaElement element = (ISchemaElement) attribute.getParent();
228:                SchemaComplexType type = (SchemaComplexType) element.getType();
229:                type.removeAttribute(attribute);
230:            }
231:
232:            public void deleteElement(ISchemaElement element) {
233:                if (!(element instanceof  ISchemaRootElement)) {
234:                    Schema schema = (Schema) element.getParent();
235:                    schema.removeElement(element);
236:                    schema.updateReferencesFor(element, ISchema.REFRESH_DELETE);
237:                }
238:            }
239:
240:            public void deleteReference(SchemaElementReference reference) {
241:                SchemaCompositor compositor = (SchemaCompositor) reference
242:                        .getCompositor();
243:                compositor.removeChild(reference);
244:            }
245:        }
w___w__w___.___j_a___v_a_2__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.