Source Code Cross Referenced for Region.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » core » 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 » jdt » org.eclipse.jdt.internal.core 
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.jdt.internal.core;
011:
012:        import java.util.ArrayList;
013:
014:        import org.eclipse.jdt.core.IJavaElement;
015:        import org.eclipse.jdt.core.IParent;
016:        import org.eclipse.jdt.core.IRegion;
017:
018:        /**
019:         * @see IRegion
020:         */
021:
022:        public class Region implements  IRegion {
023:
024:            /**
025:             * A collection of the top level elements
026:             * that have been added to the region
027:             */
028:            protected ArrayList fRootElements;
029:
030:            /**
031:             * Creates an empty region.
032:             *
033:             * @see IRegion
034:             */
035:            public Region() {
036:                fRootElements = new ArrayList(1);
037:            }
038:
039:            /**
040:             * @see IRegion#add(IJavaElement)
041:             */
042:            public void add(IJavaElement element) {
043:                if (!contains(element)) {
044:                    //"new" element added to region
045:                    removeAllChildren(element);
046:                    fRootElements.add(element);
047:                    fRootElements.trimToSize();
048:                }
049:            }
050:
051:            /**
052:             * @see IRegion
053:             */
054:            public boolean contains(IJavaElement element) {
055:
056:                int size = fRootElements.size();
057:                ArrayList parents = getAncestors(element);
058:
059:                for (int i = 0; i < size; i++) {
060:                    IJavaElement aTop = (IJavaElement) fRootElements.get(i);
061:                    if (aTop.equals(element)) {
062:                        return true;
063:                    }
064:                    for (int j = 0, pSize = parents.size(); j < pSize; j++) {
065:                        if (aTop.equals(parents.get(j))) {
066:                            //an ancestor is already included
067:                            return true;
068:                        }
069:                    }
070:                }
071:                return false;
072:            }
073:
074:            /**
075:             * Returns a collection of all the parents of this element
076:             * in bottom-up order.
077:             *
078:             */
079:            private ArrayList getAncestors(IJavaElement element) {
080:                ArrayList parents = new ArrayList();
081:                IJavaElement parent = element.getParent();
082:                while (parent != null) {
083:                    parents.add(parent);
084:                    parent = parent.getParent();
085:                }
086:                parents.trimToSize();
087:                return parents;
088:            }
089:
090:            /**
091:             * @see IRegion
092:             */
093:            public IJavaElement[] getElements() {
094:                int size = fRootElements.size();
095:                IJavaElement[] roots = new IJavaElement[size];
096:                for (int i = 0; i < size; i++) {
097:                    roots[i] = (IJavaElement) fRootElements.get(i);
098:                }
099:
100:                return roots;
101:            }
102:
103:            /**
104:             * @see IRegion#remove(IJavaElement)
105:             */
106:            public boolean remove(IJavaElement element) {
107:
108:                removeAllChildren(element);
109:                return fRootElements.remove(element);
110:            }
111:
112:            /**
113:             * Removes any children of this element that are contained within this
114:             * region as this parent is about to be added to the region.
115:             *
116:             * <p>Children are all children, not just direct children.
117:             */
118:            protected void removeAllChildren(IJavaElement element) {
119:                if (element instanceof  IParent) {
120:                    ArrayList newRootElements = new ArrayList();
121:                    for (int i = 0, size = fRootElements.size(); i < size; i++) {
122:                        IJavaElement currentRoot = (IJavaElement) fRootElements
123:                                .get(i);
124:                        //walk the current root hierarchy
125:                        IJavaElement parent = currentRoot.getParent();
126:                        boolean isChild = false;
127:                        while (parent != null) {
128:                            if (parent.equals(element)) {
129:                                isChild = true;
130:                                break;
131:                            }
132:                            parent = parent.getParent();
133:                        }
134:                        if (!isChild) {
135:                            newRootElements.add(currentRoot);
136:                        }
137:                    }
138:                    fRootElements = newRootElements;
139:                }
140:            }
141:
142:            /**
143:             * Returns a printable representation of this region.
144:             */
145:            public String toString() {
146:                StringBuffer buffer = new StringBuffer();
147:                IJavaElement[] roots = getElements();
148:                buffer.append('[');
149:                for (int i = 0; i < roots.length; i++) {
150:                    buffer.append(roots[i].getElementName());
151:                    if (i < (roots.length - 1)) {
152:                        buffer.append(", "); //$NON-NLS-1$
153:                    }
154:                }
155:                buffer.append(']');
156:                return buffer.toString();
157:            }
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.