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


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 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.plugin;
011:
012:        import org.eclipse.core.runtime.CoreException;
013:        import org.eclipse.pde.core.IModelChangeProvider;
014:        import org.eclipse.pde.core.IModelChangedEvent;
015:        import org.eclipse.pde.core.build.IBuild;
016:        import org.eclipse.pde.core.build.IBuildEntry;
017:        import org.eclipse.pde.core.build.IBuildModel;
018:        import org.eclipse.pde.core.plugin.IPluginAttribute;
019:        import org.eclipse.pde.core.plugin.IPluginBase;
020:        import org.eclipse.pde.core.plugin.IPluginElement;
021:        import org.eclipse.pde.core.plugin.IPluginExtension;
022:        import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
023:        import org.eclipse.pde.core.plugin.IPluginImport;
024:        import org.eclipse.pde.core.plugin.IPluginLibrary;
025:        import org.eclipse.pde.core.plugin.IPluginModelBase;
026:        import org.eclipse.pde.core.plugin.IPluginObject;
027:        import org.eclipse.pde.core.plugin.IPluginParent;
028:        import org.eclipse.pde.internal.core.build.BuildObject;
029:        import org.eclipse.pde.internal.core.build.IBuildObject;
030:        import org.eclipse.pde.internal.core.plugin.AttributeChangedEvent;
031:        import org.eclipse.pde.internal.core.plugin.PluginAttribute;
032:        import org.eclipse.pde.internal.core.plugin.PluginElement;
033:        import org.eclipse.pde.internal.core.plugin.PluginObject;
034:        import org.eclipse.pde.internal.core.text.plugin.PluginElementNode;
035:        import org.eclipse.pde.internal.core.text.plugin.PluginLibraryNode;
036:        import org.eclipse.pde.internal.core.text.plugin.PluginObjectNode;
037:        import org.eclipse.pde.internal.ui.PDEPlugin;
038:        import org.eclipse.pde.internal.ui.editor.ModelUndoManager;
039:        import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
040:
041:        public class PluginUndoManager extends ModelUndoManager {
042:
043:            public PluginUndoManager(PDEFormEditor editor) {
044:                super (editor);
045:                setUndoLevelLimit(30);
046:            }
047:
048:            protected String getPageId(Object obj) {
049:                if (obj instanceof  IPluginBase)
050:                    return OverviewPage.PAGE_ID;
051:                if (obj instanceof  IPluginImport)
052:                    return DependenciesPage.PAGE_ID;
053:                if (obj instanceof  IPluginLibrary
054:                        || (obj instanceof  IPluginElement && ((IPluginElement) obj)
055:                                .getParent() instanceof  IPluginLibrary))
056:                    return RuntimePage.PAGE_ID;
057:                if (obj instanceof  IPluginExtension
058:                        || (obj instanceof  IPluginElement && ((IPluginElement) obj)
059:                                .getParent() instanceof  IPluginParent)
060:                        || obj instanceof  IPluginAttribute)
061:                    return ExtensionsPage.PAGE_ID;
062:                if (obj instanceof  IPluginExtensionPoint)
063:                    return ExtensionPointsPage.PAGE_ID;
064:                return null;
065:            }
066:
067:            protected void execute(IModelChangedEvent event, boolean undo) {
068:                Object[] elements = event.getChangedObjects();
069:                int type = event.getChangeType();
070:                String propertyName = event.getChangedProperty();
071:                IModelChangeProvider model = event.getChangeProvider();
072:
073:                switch (type) {
074:                case IModelChangedEvent.INSERT:
075:                    if (undo)
076:                        executeRemove(model, elements);
077:                    else
078:                        executeAdd(model, elements);
079:                    break;
080:                case IModelChangedEvent.REMOVE:
081:                    if (undo)
082:                        executeAdd(model, elements);
083:                    else
084:                        executeRemove(model, elements);
085:                    break;
086:                case IModelChangedEvent.CHANGE:
087:                    if (event instanceof  AttributeChangedEvent) {
088:                        executeAttributeChange((AttributeChangedEvent) event,
089:                                undo);
090:                    } else {
091:                        if (undo)
092:                            executeChange(elements[0], propertyName, event
093:                                    .getNewValue(), event.getOldValue());
094:                        else
095:                            executeChange(elements[0], propertyName, event
096:                                    .getOldValue(), event.getNewValue());
097:                    }
098:                }
099:            }
100:
101:            private void executeAdd(IModelChangeProvider model,
102:                    Object[] elements) {
103:                IPluginBase pluginBase = null;
104:                IBuild build = null;
105:                if (model instanceof  IPluginModelBase)
106:                    pluginBase = ((IPluginModelBase) model).getPluginBase();
107:                if (model instanceof  IBuildModel)
108:                    build = ((IBuildModel) model).getBuild();
109:
110:                try {
111:                    for (int i = 0; i < elements.length; i++) {
112:                        Object element = elements[i];
113:
114:                        if (element instanceof  IPluginImport) {
115:                            pluginBase.add((IPluginImport) element);
116:                        } else if (element instanceof  IPluginLibrary) {
117:                            pluginBase.add((IPluginLibrary) element);
118:                        } else if (element instanceof  IPluginExtensionPoint) {
119:                            pluginBase.add((IPluginExtensionPoint) element);
120:                        } else if (element instanceof  IPluginExtension) {
121:                            pluginBase.add((IPluginExtension) element);
122:                        } else if (element instanceof  IPluginElement) {
123:                            IPluginElement e = (IPluginElement) element;
124:                            Object parent = e.getParent();
125:                            if (parent instanceof  PluginLibraryNode
126:                                    && e instanceof  PluginElementNode) {
127:                                ((PluginLibraryNode) parent)
128:                                        .addContentFilter((PluginElementNode) e);
129:                            } else if (parent instanceof  IPluginParent) {
130:                                ((IPluginParent) parent).add(e);
131:                            }
132:                        } else if (element instanceof  IBuildEntry) {
133:                            IBuildEntry e = (IBuildEntry) element;
134:                            build.add(e);
135:                        }
136:                    }
137:                } catch (CoreException e) {
138:                    PDEPlugin.logException(e);
139:                }
140:            }
141:
142:            private void executeRemove(IModelChangeProvider model,
143:                    Object[] elements) {
144:                IPluginBase pluginBase = null;
145:                IBuild build = null;
146:                if (model instanceof  IPluginModelBase)
147:                    pluginBase = ((IPluginModelBase) model).getPluginBase();
148:                if (model instanceof  IBuildModel)
149:                    build = ((IBuildModel) model).getBuild();
150:
151:                try {
152:                    for (int i = 0; i < elements.length; i++) {
153:                        Object element = elements[i];
154:
155:                        if (element instanceof  IPluginImport) {
156:                            pluginBase.remove((IPluginImport) element);
157:                        } else if (element instanceof  IPluginLibrary) {
158:                            pluginBase.remove((IPluginLibrary) element);
159:                        } else if (element instanceof  IPluginExtensionPoint) {
160:                            pluginBase.remove((IPluginExtensionPoint) element);
161:                        } else if (element instanceof  IPluginExtension) {
162:                            pluginBase.remove((IPluginExtension) element);
163:                        } else if (element instanceof  IPluginElement) {
164:                            IPluginElement e = (IPluginElement) element;
165:                            Object parent = e.getParent();
166:                            if (parent instanceof  PluginLibraryNode
167:                                    && e instanceof  PluginElementNode) {
168:                                ((PluginLibraryNode) parent)
169:                                        .removeContentFilter((PluginElementNode) e);
170:                            } else if (parent instanceof  IPluginParent) {
171:                                ((IPluginParent) parent).remove(e);
172:                            }
173:                        } else if (element instanceof  IBuildEntry) {
174:                            IBuildEntry e = (IBuildEntry) element;
175:                            build.remove(e);
176:                        }
177:                    }
178:                } catch (CoreException e) {
179:                    PDEPlugin.logException(e);
180:                }
181:            }
182:
183:            private void executeAttributeChange(AttributeChangedEvent e,
184:                    boolean undo) {
185:                PluginElement element = (PluginElement) e.getChangedObjects()[0];
186:                PluginAttribute att = (PluginAttribute) e.getChangedAttribute();
187:                Object oldValue = e.getOldValue();
188:                Object newValue = e.getNewValue();
189:                try {
190:                    if (undo)
191:                        element
192:                                .setAttribute(att.getName(), oldValue
193:                                        .toString());
194:                    else
195:                        element
196:                                .setAttribute(att.getName(), newValue
197:                                        .toString());
198:                } catch (CoreException ex) {
199:                    PDEPlugin.logException(ex);
200:                }
201:            }
202:
203:            private void executeChange(Object element, String propertyName,
204:                    Object oldValue, Object newValue) {
205:                if (element instanceof  PluginObject) {
206:                    PluginObject pobj = (PluginObject) element;
207:                    try {
208:                        pobj.restoreProperty(propertyName, oldValue, newValue);
209:                    } catch (CoreException e) {
210:                        PDEPlugin.logException(e);
211:                    }
212:                } else if (element instanceof  BuildObject) {
213:                    BuildObject bobj = (BuildObject) element;
214:                    try {
215:                        bobj.restoreProperty(propertyName, oldValue, newValue);
216:                    } catch (CoreException e) {
217:                        PDEPlugin.logException(e);
218:                    }
219:                } else if (element instanceof  PluginObjectNode) {
220:                    PluginObjectNode node = (PluginObjectNode) element;
221:                    String newString = newValue != null ? newValue.toString()
222:                            : null;
223:                    node.setXMLAttribute(propertyName, newString);
224:                }
225:            }
226:
227:            public void modelChanged(IModelChangedEvent event) {
228:                if (event.getChangeType() == IModelChangedEvent.CHANGE) {
229:                    Object changedObject = event.getChangedObjects()[0];
230:                    if (changedObject instanceof  IPluginObject) {
231:                        IPluginObject obj = (IPluginObject) event
232:                                .getChangedObjects()[0];
233:                        //Ignore events from objects that are not yet in the model.
234:                        if (!(obj instanceof  IPluginBase)
235:                                && obj.isInTheModel() == false)
236:                            return;
237:                    }
238:                    if (changedObject instanceof  IBuildObject) {
239:                        IBuildObject obj = (IBuildObject) event
240:                                .getChangedObjects()[0];
241:                        //Ignore events from objects that are not yet in the model.
242:                        if (obj.isInTheModel() == false)
243:                            return;
244:                    }
245:                }
246:                super.modelChanged(event);
247:            }
248:        }
ww__w_._ja_va_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.