1 11 package org.eclipse.ant.internal.ui.views; 12 13 import org.eclipse.ant.internal.ui.AntUtil; 14 import org.eclipse.ant.internal.ui.model.AntProjectNode; 15 import org.eclipse.ant.internal.ui.model.AntProjectNodeProxy; 16 import org.eclipse.core.resources.IFile; 17 import org.eclipse.swt.custom.BusyIndicator; 18 import org.eclipse.swt.dnd.DND; 19 import org.eclipse.swt.dnd.DropTargetAdapter; 20 import org.eclipse.swt.dnd.DropTargetEvent; 21 22 25 public class AntViewDropAdapter extends DropTargetAdapter { 26 27 private AntView view; 28 29 33 public AntViewDropAdapter(AntView view) { 34 this.view= view; 35 } 36 37 41 public void drop(DropTargetEvent event) { 42 Object data = event.data; 43 if (data instanceof String []) { 44 final String [] strings = (String []) data; 45 BusyIndicator.showWhile(null, new Runnable () { 46 public void run() { 47 for (int i = 0; i < strings.length; i++) { 48 processString(strings[i]); 49 } 50 } 51 }); 52 } 53 } 54 55 62 private void processString(String buildFileName) { 63 IFile buildFile = AntUtil.getFileForLocation(buildFileName, null); 64 if (buildFile == null || !buildFileName.toLowerCase().endsWith(".xml")) { return; 66 } 67 buildFileName = buildFile.getFullPath().toString(); 68 AntProjectNode[] existingProjects = view.getProjects(); 69 for (int j = 0; j < existingProjects.length; j++) { 70 AntProjectNodeProxy existingProject = (AntProjectNodeProxy)existingProjects[j]; 71 if (existingProject.getBuildFileName().equals(buildFileName)) { 72 return; 74 } 75 } 76 AntProjectNode project = new AntProjectNodeProxy(buildFileName); 77 view.addProject(project); 78 } 79 80 83 public void dragEnter(DropTargetEvent event) { 84 event.detail= DND.DROP_COPY; 85 super.dragEnter(event); 86 } 87 88 91 public void dragOperationChanged(DropTargetEvent event) { 92 event.detail= DND.DROP_COPY; 93 super.dragOperationChanged(event); 94 } 95 } 96 | Popular Tags |