Source Code Cross Referenced for JavaDropAdapterAssistant.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » ui » navigator » 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.navigator 
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.jdt.internal.ui.navigator;
011:
012:        import java.lang.reflect.InvocationTargetException;
013:        import java.util.List;
014:
015:        import org.eclipse.core.runtime.IStatus;
016:        import org.eclipse.core.runtime.Status;
017:
018:        import org.eclipse.core.resources.IContainer;
019:        import org.eclipse.core.resources.IResource;
020:
021:        import org.eclipse.swt.dnd.DND;
022:        import org.eclipse.swt.dnd.DropTargetEvent;
023:        import org.eclipse.swt.dnd.FileTransfer;
024:        import org.eclipse.swt.dnd.TransferData;
025:
026:        import org.eclipse.jface.viewers.ISelection;
027:        import org.eclipse.jface.viewers.IStructuredSelection;
028:
029:        import org.eclipse.ui.actions.CopyFilesAndFoldersOperation;
030:        import org.eclipse.ui.navigator.CommonDropAdapter;
031:        import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
032:
033:        import org.eclipse.ui.views.navigator.LocalSelectionTransfer;
034:
035:        import org.eclipse.jdt.core.IJavaElement;
036:        import org.eclipse.jdt.core.JavaModelException;
037:
038:        import org.eclipse.jdt.internal.corext.refactoring.reorg.JavaCopyProcessor;
039:        import org.eclipse.jdt.internal.corext.refactoring.reorg.JavaMoveProcessor;
040:        import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgDestinationFactory;
041:        import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgPolicyFactory;
042:        import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgUtils;
043:        import org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgPolicy.ICopyPolicy;
044:        import org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgPolicy.IMovePolicy;
045:
046:        import org.eclipse.jdt.internal.ui.packageview.PackagesMessages;
047:        import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages;
048:        import org.eclipse.jdt.internal.ui.refactoring.reorg.ReorgCopyStarter;
049:        import org.eclipse.jdt.internal.ui.refactoring.reorg.ReorgMoveStarter;
050:        import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
051:
052:        public class JavaDropAdapterAssistant extends
053:                CommonDropAdapterAssistant {
054:
055:            private List fElements;
056:            private JavaMoveProcessor fMoveProcessor;
057:            private int fCanMoveElements;
058:            private JavaCopyProcessor fCopyProcessor;
059:            private int fCanCopyElements;
060:
061:            public IStatus handleDrop(CommonDropAdapter dropAdapter,
062:                    DropTargetEvent dropTargetEvent, Object target) {
063:                if (LocalSelectionTransfer.getInstance().isSupportedType(
064:                        dropAdapter.getCurrentTransfer())) {
065:                    try {
066:
067:                        switch (dropAdapter.getCurrentOperation()) {
068:                        case DND.DROP_MOVE:
069:                            handleDropMove(target);
070:                            break;
071:                        case DND.DROP_COPY:
072:                            handleDropCopy(target);
073:                            break;
074:                        }
075:                    } catch (JavaModelException e) {
076:                        ExceptionHandler
077:                                .handle(
078:                                        e,
079:                                        PackagesMessages.SelectionTransferDropAdapter_error_title,
080:                                        PackagesMessages.SelectionTransferDropAdapter_error_message);
081:                    } catch (InvocationTargetException e) {
082:                        ExceptionHandler
083:                                .handle(
084:                                        e,
085:                                        RefactoringMessages.OpenRefactoringWizardAction_refactoring,
086:                                        RefactoringMessages.OpenRefactoringWizardAction_exception);
087:                    } catch (InterruptedException e) {
088:                        //ok
089:                    } finally {
090:                        // The drag source listener must not perform any operation
091:                        // since this drop adapter did the remove of the source even
092:                        // if we moved something.
093:                        //event.detail= DND.DROP_NONE;
094:                    }
095:                    clear();
096:                    return Status.OK_STATUS;
097:                } else if (FileTransfer.getInstance().isSupportedType(
098:                        dropAdapter.getCurrentTransfer())) {
099:                    try {
100:
101:                        final Object data = FileTransfer.getInstance()
102:                                .nativeToJava(dropAdapter.getCurrentTransfer());
103:                        if (!(data instanceof  String[]))
104:                            return Status.CANCEL_STATUS;
105:
106:                        final IContainer targetContainer = getActualTarget(target);
107:                        if (targetContainer == null)
108:                            return Status.CANCEL_STATUS;
109:
110:                        getShell().forceActive();
111:                        new CopyFilesAndFoldersOperation(getShell()).copyFiles(
112:                                (String[]) data, targetContainer);
113:                    } catch (JavaModelException e) {
114:                        String title = PackagesMessages.DropAdapter_errorTitle;
115:                        String message = PackagesMessages.DropAdapter_errorMessage;
116:                        ExceptionHandler.handle(e, getShell(), title, message);
117:                    }
118:                    return Status.OK_STATUS;
119:                }
120:                return Status.CANCEL_STATUS;
121:            }
122:
123:            public IStatus validateDrop(Object target, int operation,
124:                    TransferData transferType) {
125:                IStatus result = Status.OK_STATUS;
126:                if (LocalSelectionTransfer.getInstance().isSupportedType(
127:                        transferType)) {
128:                    initializeSelection();
129:                    try {
130:                        switch (operation) {
131:                        case DND.DROP_DEFAULT:
132:                            if (handleValidateDefault(target) != DND.DROP_NONE) {
133:                                result = Status.OK_STATUS;
134:                            } else {
135:                                result = Status.CANCEL_STATUS;
136:                            }
137:                            break;
138:                        case DND.DROP_COPY:
139:                            if (handleValidateCopy(target) != DND.DROP_NONE) {
140:                                result = Status.OK_STATUS;
141:                            } else {
142:                                result = Status.CANCEL_STATUS;
143:                            }
144:                            break;
145:                        case DND.DROP_MOVE:
146:                            if (handleValidateMove(target) != DND.DROP_NONE) {
147:                                result = Status.OK_STATUS;
148:                            } else {
149:                                result = Status.CANCEL_STATUS;
150:                            }
151:                            break;
152:                        }
153:                    } catch (JavaModelException e) {
154:                        ExceptionHandler
155:                                .handle(
156:                                        e,
157:                                        PackagesMessages.SelectionTransferDropAdapter_error_title,
158:                                        PackagesMessages.SelectionTransferDropAdapter_error_message);
159:                        //event.detail= DND.DROP_NONE;
160:                        result = Status.CANCEL_STATUS;
161:                    }
162:                }
163:                return result;
164:            }
165:
166:            public boolean isSupportedType(TransferData transferType) {
167:                return super .isSupportedType(transferType)
168:                        || FileTransfer.getInstance().isSupportedType(
169:                                transferType);
170:            }
171:
172:            private IContainer getActualTarget(Object dropTarget)
173:                    throws JavaModelException {
174:                if (dropTarget instanceof  IContainer)
175:                    return (IContainer) dropTarget;
176:                else if (dropTarget instanceof  IJavaElement)
177:                    return getActualTarget(((IJavaElement) dropTarget)
178:                            .getCorrespondingResource());
179:                return null;
180:            }
181:
182:            protected void initializeSelection() {
183:                if (fElements != null)
184:                    return;
185:                ISelection s = LocalSelectionTransfer.getInstance()
186:                        .getSelection();
187:                if (!(s instanceof  IStructuredSelection))
188:                    return;
189:                fElements = ((IStructuredSelection) s).toList();
190:            }
191:
192:            private void handleDropMove(final Object target)
193:                    throws JavaModelException, InvocationTargetException,
194:                    InterruptedException {
195:                IJavaElement[] javaElements = ReorgUtils
196:                        .getJavaElements(fElements);
197:                IResource[] resources = ReorgUtils.getResources(fElements);
198:                ReorgMoveStarter starter = ReorgMoveStarter.create(
199:                        javaElements, resources, ReorgDestinationFactory
200:                                .createDestination(target));
201:                ;
202:
203:                if (starter != null)
204:                    starter.run(getShell());
205:            }
206:
207:            private void handleDropCopy(final Object target)
208:                    throws JavaModelException, InvocationTargetException,
209:                    InterruptedException {
210:                IJavaElement[] javaElements = ReorgUtils
211:                        .getJavaElements(fElements);
212:                IResource[] resources = ReorgUtils.getResources(fElements);
213:                ReorgCopyStarter starter = ReorgCopyStarter.create(
214:                        javaElements, resources, ReorgDestinationFactory
215:                                .createDestination(target));
216:
217:                if (starter != null)
218:                    starter.run(getShell());
219:            }
220:
221:            private int handleValidateCopy(Object target)
222:                    throws JavaModelException {
223:
224:                final ICopyPolicy policy = ReorgPolicyFactory.createCopyPolicy(
225:                        ReorgUtils.getResources(fElements), ReorgUtils
226:                                .getJavaElements(fElements));
227:                fCopyProcessor = policy.canEnable() ? new JavaCopyProcessor(
228:                        policy) : null;
229:
230:                if (!canCopyElements())
231:                    return DND.DROP_NONE;
232:
233:                if (fCopyProcessor == null)
234:                    return DND.DROP_NONE;
235:
236:                if (!fCopyProcessor.setDestination(
237:                        ReorgDestinationFactory.createDestination(target))
238:                        .isOK())
239:                    return DND.DROP_NONE;
240:
241:                return DND.DROP_COPY;
242:            }
243:
244:            private int handleValidateDefault(Object target)
245:                    throws JavaModelException {
246:                if (target == null)
247:                    return DND.DROP_NONE;
248:
249:                return handleValidateMove(target);
250:            }
251:
252:            private int handleValidateMove(Object target)
253:                    throws JavaModelException {
254:                if (target == null)
255:                    return DND.DROP_NONE;
256:
257:                IMovePolicy policy = ReorgPolicyFactory.createMovePolicy(
258:                        ReorgUtils.getResources(fElements), ReorgUtils
259:                                .getJavaElements(fElements));
260:                fMoveProcessor = (policy.canEnable()) ? new JavaMoveProcessor(
261:                        policy) : null;
262:
263:                if (!canMoveElements())
264:                    return DND.DROP_NONE;
265:
266:                if (fMoveProcessor == null)
267:                    return DND.DROP_NONE;
268:
269:                if (!fMoveProcessor.setDestination(
270:                        ReorgDestinationFactory.createDestination(target))
271:                        .isOK())
272:                    return DND.DROP_NONE;
273:
274:                return DND.DROP_MOVE;
275:            }
276:
277:            private boolean canMoveElements() {
278:                if (fCanMoveElements == 0) {
279:                    fCanMoveElements = 2;
280:                    if (fMoveProcessor == null)
281:                        fCanMoveElements = 1;
282:                }
283:                return fCanMoveElements == 2;
284:            }
285:
286:            private boolean canCopyElements() {
287:                if (fCanCopyElements == 0) {
288:                    fCanCopyElements = 2;
289:                    if (fCopyProcessor == null)
290:                        fCanCopyElements = 1;
291:                }
292:                return fCanCopyElements == 2;
293:            }
294:
295:            private void clear() {
296:                fElements = null;
297:                fMoveProcessor = null;
298:                fCanMoveElements = 0;
299:                fCopyProcessor = null;
300:                fCanCopyElements = 0;
301:            }
302:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.