KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > schema > ElementSectionDropAdapter


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.pde.internal.ui.editor.schema;
12
13 import org.eclipse.jface.viewers.ViewerDropAdapter;
14 import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
15 import org.eclipse.pde.internal.core.ischema.ISchemaCompositor;
16 import org.eclipse.pde.internal.core.ischema.ISchemaElement;
17 import org.eclipse.pde.internal.core.ischema.ISchemaObjectReference;
18 import org.eclipse.pde.internal.ui.editor.ModelDataTransfer;
19 import org.eclipse.swt.dnd.TransferData;
20
21 public class ElementSectionDropAdapter extends ViewerDropAdapter {
22     private TransferData fCurrentTransfer;
23     private ElementSection fSsection;
24     private ElementSectionDragAdapter fDragAdapter;
25
26     public ElementSectionDropAdapter(ElementSectionDragAdapter dragAdapter, ElementSection section) {
27         super(section.getTreeViewer());
28         fSsection = section;
29         fDragAdapter = dragAdapter;
30     }
31
32     /**
33      * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
34      */

35     public boolean performDrop(Object JavaDoc data) {
36         fSsection.handleOp(getCurrentTarget(), fDragAdapter.getDragData(), getCurrentOperation());
37         return true;
38     }
39
40     /**
41      * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
42      */

43     public boolean validateDrop(Object JavaDoc target, int operation, TransferData transferType) {
44         fCurrentTransfer = transferType;
45         if (!ModelDataTransfer.getInstance().isSupportedType(fCurrentTransfer))
46             return false;
47         Object JavaDoc cargo = getSelectedObject();
48         
49         if (cargo instanceof ISchemaObjectReference) { // dropping an element reference
50
// onto a compositor or reference
51
if ((target instanceof ISchemaCompositor
52                     || target instanceof ISchemaObjectReference))
53                 return true;
54         } else if (cargo instanceof ISchemaElement) { // dropping an element
55
// onto a non referenced element
56
if (target instanceof ISchemaCompositor || target instanceof ISchemaObjectReference || isNonRefElement(target) || target == null)
57                 return true;
58         } else if (cargo instanceof ISchemaCompositor) { // dropping a compositor
59
// onto a non referenced element
60
if (isNonRefElement(target) || target instanceof ISchemaCompositor || target instanceof ISchemaObjectReference)
61                 return true;
62         } else if (cargo instanceof ISchemaAttribute) { // dropping an attribute
63
// onto a non referenced element or attribute
64
if (isNonRefElement(target) || target instanceof ISchemaAttribute)
65                 return true;
66         }
67         return false;
68     }
69     
70     private boolean isNonRefElement(Object JavaDoc obj) {
71         return (obj instanceof ISchemaElement && !(obj instanceof ISchemaObjectReference));
72     }
73 }
74
Popular Tags