Source Code Cross Referenced for ResourceDragAdapterAssistant.java in  » IDE-Eclipse » ui » org » eclipse » ui » navigator » resources » 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 » ui » org.eclipse.ui.navigator.resources 
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.ui.navigator.resources;
011:
012:        import java.util.Iterator;
013:        import java.util.LinkedHashSet;
014:        import java.util.Set;
015:
016:        import org.eclipse.core.resources.IResource;
017:        import org.eclipse.core.runtime.IAdaptable;
018:        import org.eclipse.core.runtime.IPath;
019:        import org.eclipse.core.runtime.Platform;
020:        import org.eclipse.jface.viewers.IStructuredSelection;
021:        import org.eclipse.swt.dnd.DragSourceEvent;
022:        import org.eclipse.swt.dnd.FileTransfer;
023:        import org.eclipse.swt.dnd.Transfer;
024:        import org.eclipse.ui.navigator.CommonDragAdapterAssistant;
025:        import org.eclipse.ui.navigator.INavigatorDnDService;
026:        import org.eclipse.ui.part.ResourceTransfer;
027:        import org.eclipse.ui.views.navigator.LocalSelectionTransfer;
028:
029:        /**
030:         * Clients may reference this class in the <b>dragAssistant</b> element of a
031:         * <b>org.eclipse.ui.navigator.viewer</b> extension point.
032:         * 
033:         * <p>
034:         * Clients may not extend or instantiate this class for any purpose other than
035:         * {@link INavigatorDnDService#bindDragAssistant(CommonDragAdapterAssistant)}.
036:         * Clients may have no direct dependencies on the contract of this class.
037:         * </p>
038:         * 
039:         * @since 3.2
040:         * 
041:         */
042:        public final class ResourceDragAdapterAssistant extends
043:                CommonDragAdapterAssistant {
044:
045:            private static final boolean DEBUG = false;
046:
047:            private static final Transfer[] SUPPORTED_TRANSFERS = new Transfer[] {
048:                    ResourceTransfer.getInstance(),
049:                    LocalSelectionTransfer.getInstance(),
050:                    FileTransfer.getInstance() };
051:
052:            private static final Class IRESOURCE_TYPE = IResource.class;
053:
054:            /*
055:             * (non-Javadoc)
056:             * 
057:             * @see org.eclipse.ui.navigator.CommonDragAdapterAssistant#getSupportedTransferTypes()
058:             */
059:            public Transfer[] getSupportedTransferTypes() {
060:                return SUPPORTED_TRANSFERS;
061:            }
062:
063:            /*
064:             * (non-Javadoc)
065:             * 
066:             * @see org.eclipse.ui.navigator.CommonDragAdapterAssistant#setDragData(org.eclipse.swt.dnd.DragSourceEvent,
067:             *      org.eclipse.jface.viewers.IStructuredSelection)
068:             */
069:            public boolean setDragData(DragSourceEvent anEvent,
070:                    IStructuredSelection aSelection) {
071:
072:                if (LocalSelectionTransfer.getInstance().isSupportedType(
073:                        anEvent.dataType)) {
074:                    anEvent.data = aSelection;
075:                    if (DEBUG) {
076:                        System.out
077:                                .println("ResourceDragAdapterAssistant.dragSetData set LocalSelectionTransfer"); //$NON-NLS-1$
078:                    }
079:                    return true;
080:                } else if (ResourceTransfer.getInstance().isSupportedType(
081:                        anEvent.dataType)) {
082:                    anEvent.data = getSelectedResources(aSelection);
083:                    if (DEBUG) {
084:                        System.out
085:                                .println("ResourceDragAdapterAssistant.dragSetData set ResourceTransfer"); //$NON-NLS-1$
086:                    }
087:                    return true;
088:                } else if (FileTransfer.getInstance().isSupportedType(
089:                        anEvent.dataType)) {
090:
091:                    IResource[] resources = getSelectedResources(aSelection);
092:
093:                    // Get the path of each file and set as the drag data
094:                    final int length = resources.length;
095:                    int actualLength = 0;
096:                    String[] fileNames = new String[length];
097:                    for (int i = 0; i < length; i++) {
098:                        IPath location = resources[i].getLocation();
099:                        // location may be null. See bug 29491.
100:                        if (location != null) {
101:                            fileNames[actualLength++] = location.toOSString();
102:                        }
103:                    }
104:                    if (actualLength > 0) {
105:                        // was one or more of the locations null?
106:                        if (actualLength < length) {
107:                            String[] tempFileNames = fileNames;
108:                            fileNames = new String[actualLength];
109:                            for (int i = 0; i < actualLength; i++)
110:                                fileNames[i] = tempFileNames[i];
111:                        }
112:                        anEvent.data = fileNames;
113:
114:                        if (DEBUG)
115:                            System.out
116:                                    .println("ResourceDragAdapterAssistant.dragSetData set FileTransfer"); //$NON-NLS-1$
117:                        return true;
118:                    }
119:                }
120:                return false;
121:
122:            }
123:
124:            private IResource[] getSelectedResources(
125:                    IStructuredSelection aSelection) {
126:                Set resources = new LinkedHashSet();
127:                IResource resource = null;
128:                for (Iterator iter = aSelection.iterator(); iter.hasNext();) {
129:                    Object selected = iter.next();
130:                    resource = adaptToResource(selected);
131:                    if (resource != null) {
132:                        resources.add(resource);
133:                    }
134:                }
135:                return (IResource[]) resources.toArray(new IResource[resources
136:                        .size()]);
137:            }
138:
139:            private IResource adaptToResource(Object selected) {
140:                IResource resource;
141:                if (selected instanceof  IResource) {
142:                    resource = (IResource) selected;
143:                } else if (selected instanceof  IAdaptable) {
144:                    resource = (IResource) ((IAdaptable) selected)
145:                            .getAdapter(IRESOURCE_TYPE);
146:                } else {
147:                    resource = (IResource) Platform.getAdapterManager()
148:                            .getAdapter(selected, IRESOURCE_TYPE);
149:                }
150:                return resource;
151:            }
152:
153:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.