Source Code Cross Referenced for InclusivePositionUpdater.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » ui » text » template » contentassist » 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.ui.text.template.contentassist 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2005 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.ui.text.template.contentassist;
011:
012:        import org.eclipse.jface.text.BadPositionCategoryException;
013:        import org.eclipse.jface.text.DocumentEvent;
014:        import org.eclipse.jface.text.IPositionUpdater;
015:        import org.eclipse.jface.text.Position;
016:
017:        /**
018:         * Position updater that takes any change in [position.offset, position.offset + position.length] as
019:         * belonging to the position.
020:         *
021:         * @since 3.0
022:         */
023:        class InclusivePositionUpdater implements  IPositionUpdater {
024:
025:            /** The position category. */
026:            private final String fCategory;
027:
028:            /**
029:             * Creates a new updater for the given <code>category</code>.
030:             *
031:             * @param category the new category.
032:             */
033:            public InclusivePositionUpdater(String category) {
034:                fCategory = category;
035:            }
036:
037:            /*
038:             * @see org.eclipse.jface.text.IPositionUpdater#update(org.eclipse.jface.text.DocumentEvent)
039:             */
040:            public void update(DocumentEvent event) {
041:
042:                int eventOffset = event.getOffset();
043:                int eventOldLength = event.getLength();
044:                int eventNewLength = event.getText() == null ? 0 : event
045:                        .getText().length();
046:                int deltaLength = eventNewLength - eventOldLength;
047:
048:                try {
049:                    Position[] positions = event.getDocument().getPositions(
050:                            fCategory);
051:
052:                    for (int i = 0; i != positions.length; i++) {
053:
054:                        Position position = positions[i];
055:
056:                        if (position.isDeleted())
057:                            continue;
058:
059:                        int offset = position.getOffset();
060:                        int length = position.getLength();
061:                        int end = offset + length;
062:
063:                        if (offset > eventOffset + eventOldLength)
064:                            // position comes way
065:                            // after change - shift
066:                            position.setOffset(offset + deltaLength);
067:                        else if (end < eventOffset) {
068:                            // position comes way before change -
069:                            // leave alone
070:                        } else if (offset <= eventOffset
071:                                && end >= eventOffset + eventOldLength) {
072:                            // event completely internal to the position - adjust length
073:                            position.setLength(length + deltaLength);
074:                        } else if (offset < eventOffset) {
075:                            // event extends over end of position - adjust length
076:                            int newEnd = eventOffset + eventNewLength;
077:                            position.setLength(newEnd - offset);
078:                        } else if (end > eventOffset + eventOldLength) {
079:                            // event extends from before position into it - adjust offset
080:                            // and length
081:                            // offset becomes end of event, length ajusted acordingly
082:                            // we want to recycle the overlapping part
083:                            position.setOffset(eventOffset);
084:                            int deleted = eventOffset + eventOldLength - offset;
085:                            position.setLength(length - deleted
086:                                    + eventNewLength);
087:                        } else {
088:                            // event consumes the position - delete it
089:                            position.delete();
090:                        }
091:                    }
092:                } catch (BadPositionCategoryException e) {
093:                    // ignore and return
094:                }
095:            }
096:
097:            /**
098:             * Returns the position category.
099:             *
100:             * @return the position category
101:             */
102:            public String getCategory() {
103:                return fCategory;
104:            }
105:
106:        }
w_ww_._jav_a___2s___.__c___om_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.