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


001:        /*******************************************************************************
002:         * Copyright (c) 2007 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;
011:
012:        import org.eclipse.jface.viewers.Viewer;
013:        import org.eclipse.jface.viewers.ViewerDropAdapter;
014:        import org.eclipse.swt.dnd.DND;
015:        import org.eclipse.swt.dnd.TransferData;
016:
017:        /**
018:         * PDEDropAdapter
019:         *
020:         */
021:        public class PDEDropAdapter extends ViewerDropAdapter {
022:
023:            private IPDEDropParticipant fDropParticipant;
024:
025:            private IPDESourceParticipant fSourceParticipant;
026:
027:            private int fLastValidOperation;
028:
029:            /**
030:             * @param viewer
031:             */
032:            public PDEDropAdapter(Viewer viewer,
033:                    IPDEDropParticipant dropParticipant,
034:                    IPDESourceParticipant sourceParticipant) {
035:                super (viewer);
036:                fDropParticipant = dropParticipant;
037:                fSourceParticipant = sourceParticipant;
038:                resetLastValidOperation();
039:            }
040:
041:            /**
042:             * 
043:             */
044:            protected void resetLastValidOperation() {
045:                fLastValidOperation = DND.DROP_NONE;
046:            }
047:
048:            /**
049:             * @param currentOperation
050:             * @return
051:             */
052:            protected int getLastValidOperation(int currentOperation) {
053:                if (currentOperation != DND.DROP_NONE) {
054:                    fLastValidOperation = currentOperation;
055:                }
056:                return fLastValidOperation;
057:            }
058:
059:            /* (non-Javadoc)
060:             * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
061:             */
062:            public boolean performDrop(Object data) {
063:                // Clear the last valid operation for the next drop event
064:                resetLastValidOperation();
065:                // Get the original target object to drop source objects on
066:                Object targetObject = getCurrentTarget();
067:                // Get the drop location relative to the target object
068:                int targetLocation = getCurrentLocation();
069:                // Get the serialized / deserialized source objects to drop
070:                Object[] sourceObjects = null;
071:                if (data instanceof  Object[]) {
072:                    sourceObjects = (Object[]) data;
073:                } else {
074:                    sourceObjects = new Object[] { data };
075:                }
076:                // Get the current operation
077:                int operation = getCurrentOperation();
078:                // Drop the source objects on the target
079:                // object given the specified operation
080:                if (operation == DND.DROP_COPY) {
081:                    fDropParticipant.doDropCopy(targetObject, sourceObjects,
082:                            targetLocation);
083:                } else if (operation == DND.DROP_MOVE) {
084:                    fDropParticipant.doDropMove(targetObject, sourceObjects,
085:                            targetLocation);
086:                } else if (operation == DND.DROP_LINK) {
087:                    fDropParticipant.doDropLink(targetObject, sourceObjects,
088:                            targetLocation);
089:                } else if (operation == DND.DROP_DEFAULT) {
090:                    fDropParticipant.doDropMove(targetObject, sourceObjects,
091:                            targetLocation);
092:                } else {
093:                    return false;
094:                }
095:
096:                return true;
097:            }
098:
099:            /* (non-Javadoc)
100:             * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
101:             */
102:            public boolean validateDrop(Object targetObject, int operation,
103:                    TransferData transferType) {
104:                // Current operation listed is not set until after the drop is validated
105:                // i.e. This method call
106:                // Replace the current operation with the last valid operation
107:                operation = getLastValidOperation(operation);
108:                // Get the original target object to drop source objects on
109:                targetObject = getCurrentTarget();
110:                // Get the drop location relative to the target object
111:                int targetLocation = getCurrentLocation();
112:                // Ensure we have a model transfer operation
113:                if (ModelDataTransfer.getInstance().isSupportedType(
114:                        transferType) == false) {
115:                    return false;
116:                }
117:                // Ensure the location is defined
118:                if (targetLocation == LOCATION_NONE) {
119:                    return false;
120:                }
121:                // Get the original source objects
122:                Object[] sourceObjects = fSourceParticipant.getSourceObjects();
123:                // Ensure we have source objects
124:                if (sourceObjects == null) {
125:                    return false;
126:                }
127:                if (sourceObjects.length == 0) {
128:                    return false;
129:                }
130:                // Ensure the target object is defined
131:                if (targetObject == null) {
132:                    return false;
133:                }
134:                // Determine whether the source objects can be dropped on the target
135:                // object given the specified operation
136:                if (operation == DND.DROP_COPY) {
137:                    return validateDropCopy(targetObject, sourceObjects,
138:                            targetLocation);
139:                } else if (operation == DND.DROP_MOVE) {
140:                    return validateDropMove(targetObject, sourceObjects,
141:                            targetLocation);
142:                } else if (operation == DND.DROP_LINK) {
143:                    return validateDropLink(targetObject, sourceObjects,
144:                            targetLocation);
145:                } else if (operation == DND.DROP_DEFAULT) {
146:                    return validateDropDefault(targetObject, sourceObjects,
147:                            targetLocation);
148:                }
149:                return false;
150:            }
151:
152:            /**
153:             * @param targetObject
154:             * @param sourceObjects
155:             * @param targetLocation
156:             * @return
157:             */
158:            protected boolean validateDropCopy(Object targetObject,
159:                    Object[] sourceObjects, int targetLocation) {
160:                return fDropParticipant.canDropCopy(targetObject,
161:                        sourceObjects, targetLocation);
162:            }
163:
164:            /**
165:             * @param targetObject
166:             * @param sourceObjects
167:             * @param targetLocation
168:             * @return
169:             */
170:            protected boolean validateDropMove(Object targetObject,
171:                    Object[] sourceObjects, int targetLocation) {
172:                // Source objects have not been serialized yet.
173:                // As a result we can compare whether a source and target object is
174:                // equal
175:                // Ensure the target is valid for a move operation and not redundant
176:                // Meaning there is no effect of the move
177:                for (int i = 0; i < sourceObjects.length; i++) {
178:                    if (targetObject.equals(sourceObjects[i])) {
179:                        // No source objects are allowed to be dropped on themselves for
180:                        // move operations
181:                        return false;
182:                    }
183:                }
184:                return fDropParticipant.canDropMove(targetObject,
185:                        sourceObjects, targetLocation);
186:            }
187:
188:            /**
189:             * @param targetObject
190:             * @param sourceObjects
191:             * @param targetLocation
192:             * @return
193:             */
194:            protected boolean validateDropLink(Object targetObject,
195:                    Object[] sourceObjects, int targetLocation) {
196:                return fDropParticipant.canDropLink(targetObject,
197:                        sourceObjects, targetLocation);
198:            }
199:
200:            /**
201:             * @param targetObject
202:             * @param sourceObjects
203:             * @param targetLocation
204:             * @return
205:             */
206:            protected boolean validateDropDefault(Object targetObject,
207:                    Object[] sourceObjects, int targetLocation) {
208:                return validateDropMove(targetObject, sourceObjects,
209:                        targetLocation);
210:            }
211:
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.