KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > navigator > dnd > NavigatorPluginDropAction


1 /*******************************************************************************
2  * Copyright (c) 2003, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.navigator.dnd;
12
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.jface.util.LocalSelectionTransfer;
15 import org.eclipse.jface.viewers.IStructuredSelection;
16 import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
17 import org.eclipse.ui.navigator.INavigatorContentService;
18 import org.eclipse.ui.part.IDropActionDelegate;
19 import org.eclipse.ui.part.PluginTransferData;
20
21 /**
22  *
23  *
24  * @since 3.2
25  *
26  */

27 public class NavigatorPluginDropAction implements IDropActionDelegate {
28
29     private static final boolean DEBUG = false;
30
31     private static final String JavaDoc CN_PLUGIN_ACTION_ID = "org.eclipse.ui.navigator.PluginDropAction"; //$NON-NLS-1$
32

33     /**
34      * A default no-args constructor is required by the
35      * <b>org.eclipse.ui.dropAdapters</b> extension point
36      */

37     public NavigatorPluginDropAction() {
38         super();
39     }
40
41     /*
42      * (non-Javadoc)
43      *
44      * @see org.eclipse.ui.part.IDropActionDelegate#run(java.lang.Object,
45      * java.lang.Object)
46      */

47     public boolean run(Object JavaDoc sourceData, Object JavaDoc target) {
48
49         if (DEBUG) {
50             System.out.println("NavigatorPluginDropAction.run (begin)"); //$NON-NLS-1$
51
}
52
53         String JavaDoc sourceViewerId = new String JavaDoc((byte[]) sourceData);
54
55         IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer
56                 .getTransfer().getSelection();
57
58         INavigatorContentService contentService = NavigatorContentServiceTransfer
59                 .getInstance().findService(sourceViewerId);
60
61         if (contentService == null) {
62             return false;
63         }
64         try {
65             CommonDropAdapterAssistant[] assistants = contentService
66                     .getDnDService().findCommonDropAdapterAssistants(target,
67                             selection);
68
69             IStatus valid = null;
70             for (int i = 0; i < assistants.length; i++) {
71                 valid = assistants[i].validatePluginTransferDrop(selection, target);
72                 if (valid != null && valid.isOK()) {
73                     valid = assistants[i].handlePluginTransferDrop(selection, target);
74                     return valid != null && valid.isOK();
75                 }
76             }
77         } finally {
78             NavigatorContentServiceTransfer.getInstance()
79                     .unregisterContentService(contentService);
80         }
81
82         if (DEBUG) {
83             System.out.println("NavigatorPluginDropAction.run (exit)"); //$NON-NLS-1$
84
}
85
86         return false;
87     }
88
89     /**
90      *
91      * @param aContentService
92      * The associated content service that is the source of the drag
93      * @return A PluginTransferData properly configured to call the Common
94      * Navigator's PluginDropAction.
95      */

96     public static PluginTransferData createTransferData(
97             INavigatorContentService aContentService) {
98         NavigatorContentServiceTransfer.getInstance().registerContentService(
99                 aContentService);
100         return new PluginTransferData(CN_PLUGIN_ACTION_ID, aContentService
101                 .getViewerId().getBytes());
102     }
103
104 }
105
Popular Tags