Source Code Cross Referenced for ExtensionAttributePointDectector.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) 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.jface.text.Region;
013:        import org.eclipse.jface.text.source.ISourceViewer;
014:        import org.eclipse.jface.viewers.ISelection;
015:        import org.eclipse.jface.viewers.StructuredSelection;
016:        import org.eclipse.pde.core.plugin.IPluginExtension;
017:        import org.eclipse.pde.core.plugin.IPluginObject;
018:        import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
019:        import org.eclipse.pde.internal.core.schema.SchemaRootElement;
020:        import org.eclipse.pde.internal.core.text.IDocumentAttributeNode;
021:        import org.eclipse.pde.internal.core.text.IDocumentElementNode;
022:        import org.eclipse.pde.internal.core.text.IDocumentRange;
023:        import org.eclipse.pde.internal.ui.editor.text.XMLUtil;
024:        import org.eclipse.swt.custom.StyledText;
025:        import org.eclipse.swt.events.KeyEvent;
026:        import org.eclipse.swt.events.KeyListener;
027:        import org.eclipse.swt.events.MouseEvent;
028:        import org.eclipse.swt.events.MouseListener;
029:        import org.eclipse.swt.graphics.Point;
030:
031:        /**
032:         * ExtensionAttributePointDectector
033:         *
034:         */
035:        public class ExtensionAttributePointDectector implements  MouseListener,
036:                KeyListener {
037:
038:            private ManifestSourcePage fSourcePage;
039:
040:            private StyledText fStyledText;
041:
042:            private ISelection fSelection;
043:
044:            /**
045:             * 
046:             */
047:            public ExtensionAttributePointDectector() {
048:                fSelection = null;
049:                fStyledText = null;
050:                fSourcePage = null;
051:            }
052:
053:            /**
054:             * @return
055:             */
056:            public ISelection getSelection() {
057:                return fSelection;
058:            }
059:
060:            /**
061:             * @param editor
062:             */
063:            public void setTextEditor(ManifestSourcePage editor) {
064:                fSourcePage = editor;
065:                // Get the new styled text widget
066:                ISourceViewer viewer = fSourcePage.getViewer();
067:                // If the source viewer is not initialized, we can't do anything here
068:                if (viewer == null) {
069:                    return;
070:                }
071:                StyledText newStyledText = viewer.getTextWidget();
072:                // If the new styled text equals the old one, keep the old one
073:                if ((fStyledText != null) && fStyledText.equals(newStyledText)) {
074:                    return;
075:                }
076:                // Remove the listeners on the old styled text
077:                removeListeners();
078:                // Replace the old with the new
079:                fStyledText = newStyledText;
080:                // Add the listeners to the new styled text
081:                addListeners();
082:                // Enable this action if the selection is within the point attribute on
083:                // an extension
084:                checkIfOnTarget();
085:            }
086:
087:            /**
088:             * @return
089:             */
090:            private void checkIfOnTarget() {
091:                // Reset the Selection
092:                fSelection = null;
093:                // Ensure the input is valid
094:                if (isInputInitialized() == false) {
095:                    return;
096:                }
097:                // Get the region selected
098:                Point selectionPoint = fStyledText.getSelection();
099:                Region selectionRegion = new Region(selectionPoint.x,
100:                        selectionPoint.y - selectionPoint.x);
101:                // Determine whether the region selected is the point attribute of
102:                // and extension
103:                if ((selectionRegion == null) || (fSourcePage == null)) {
104:                    return;
105:                }
106:                // Retrieve the document range corresponding to the selection region
107:                IDocumentRange element = fSourcePage.getRangeElement(
108:                        selectionRegion.getOffset(), true);
109:                // Validate the obtained document range
110:                if (XMLUtil.withinRange(element, selectionRegion.getOffset()) == false) {
111:                    return;
112:                }
113:                // Ensure we have a document attribute 
114:                if ((element instanceof  IDocumentAttributeNode) == false) {
115:                    return;
116:                }
117:                // Ignore IDocumentElementNode
118:                // Ignore IDocumentTextNode
119:                IDocumentAttributeNode documentAttribute = ((IDocumentAttributeNode) element);
120:                String attributeValue = documentAttribute.getAttributeValue();
121:                // Ensure the attribute value is defined
122:                if ((attributeValue == null) || (attributeValue.length() == 0)) {
123:                    return;
124:                }
125:                // Get the parent node: either extension or extension point
126:                IPluginObject node = XMLUtil
127:                        .getTopLevelParent((IDocumentElementNode) documentAttribute);
128:                // Ensure the node is defined and comes from and editable model
129:                if ((node == null) || (node.getModel().isEditable() == false)) {
130:                    return;
131:                }
132:                // Ensure the node is an extension
133:                if ((node instanceof  IPluginExtension) == false) {
134:                    return;
135:                }
136:                // Ignore IPluginExtensionPoint
137:                IPluginExtension extension = (IPluginExtension) node;
138:                // Retrieve the corresponding schema attribute to this node
139:                ISchemaAttribute schemaAttribute = XMLUtil.getSchemaAttribute(
140:                        documentAttribute, extension.getPoint());
141:                // Ensure the schema attribute is defined
142:                if (schemaAttribute == null) {
143:                    return;
144:                }
145:                // Ensure the attribute is a point
146:                if (((schemaAttribute.getParent() instanceof  SchemaRootElement) == false)
147:                        || (documentAttribute.getAttributeName().equals(
148:                                IPluginExtension.P_POINT) == false)) {
149:                    return;
150:                }
151:                fSelection = new StructuredSelection(extension);
152:            }
153:
154:            /**
155:             * 
156:             */
157:            private void removeListeners() {
158:                if (isInputInitialized() == false) {
159:                    return;
160:                }
161:                fStyledText.removeMouseListener(this );
162:                fStyledText.removeKeyListener(this );
163:            }
164:
165:            /**
166:             * @return
167:             */
168:            private boolean isInputInitialized() {
169:                if ((fStyledText == null) || (fStyledText.isDisposed())) {
170:                    return false;
171:                }
172:                return true;
173:            }
174:
175:            /**
176:             * 
177:             */
178:            private void addListeners() {
179:                if (isInputInitialized() == false) {
180:                    return;
181:                }
182:                fStyledText.addMouseListener(this );
183:                fStyledText.addKeyListener(this );
184:            }
185:
186:            /* (non-Javadoc)
187:             * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
188:             */
189:            public void mouseDoubleClick(MouseEvent e) {
190:                // Ignore
191:            }
192:
193:            /* (non-Javadoc)
194:             * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
195:             */
196:            public void mouseDown(MouseEvent e) {
197:                // Ignore
198:            }
199:
200:            public void mouseUp(MouseEvent e) {
201:                checkIfOnTarget();
202:            }
203:
204:            public void keyPressed(KeyEvent e) {
205:                checkIfOnTarget();
206:            }
207:
208:            /* (non-Javadoc)
209:             * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
210:             */
211:            public void keyReleased(KeyEvent e) {
212:                // Ignore
213:            }
214:
215:        }
w___w__w_._j_a_v_a_2s_._c_o__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.