博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Eclipse插件开发- view to view drag drop
阅读量:6558 次
发布时间:2019-06-24

本文共 3285 字,大约阅读时间需要 10 分钟。

hot3.png

定义Drop:

package public_project.view.dnd;import org.eclipse.jface.dialogs.MessageDialog;import org.eclipse.jface.viewers.TreeViewer;import org.eclipse.jface.viewers.Viewer;import org.eclipse.jface.viewers.ViewerDropAdapter;import org.eclipse.swt.dnd.DND;import org.eclipse.swt.dnd.DropTargetEvent;import org.eclipse.swt.dnd.TransferData;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.TreeItem;import public_project.view.model.descriptors.ProjectDetail;import public_project.view.model.descriptors.ProjectGroup;public class ViewDropListener extends ViewerDropAdapter {		private TreeViewer treeViewer;		public ViewDropListener(Viewer viewer) {		super(viewer);		this.treeViewer = (TreeViewer) viewer;	}	@Override	public void drop(DropTargetEvent event) {		if (event.data == null) {	          event.detail = DND.DROP_NONE;	          return;	        }	        String [] strData = (String[]) event.data;	        String text = (String) strData[0];	        if (event.item == null) {	         MessageDialog.openWarning(Display.getCurrent().getActiveShell(), "哈哈!!", "哈哈哈!!!!你想多了。!!!功能太鸡肋,不开放!!");	        } else {	          TreeItem item = (TreeItem) event.item;	          Object objItem = item.getData();	          if(objItem instanceof ProjectGroup){	        	  ProjectGroup group = (ProjectGroup) objItem;	        	  ProjectDetail [] details = group.getProjectDetail();	        	  String addProjectName = text.substring(text.lastIndexOf("\\")+1);//	        	  genJar(addProjectName);//	        	  ftpUpload();	        	  if(details != null && details.length >0){	        		  //判断是否存在	        		  for(ProjectDetail detail : details){	        			  if(addProjectName.equals(detail.getProjectName())){	    		        	  return;	        			  }	        		  }	        		  ProjectDetail detail1 = new ProjectDetail();		        	  detail1.setProjectName(addProjectName);		        	  detail1.setProjectStatus("0");		        	  group.addProjectDetail(detail1);		        	  treeViewer.refresh();	        	  }else{	        		  ProjectDetail detail1 = new ProjectDetail();		        	  detail1.setProjectName(addProjectName);		        	  detail1.setProjectStatus("0");		        	  group.addProjectDetail(detail1);		        	  treeViewer.refresh();	        	  }	          }	        }	      				super.drop(event);	}	@Override	public boolean performDrop(Object data) {				return false;	}	@Override	public boolean validateDrop(Object target, int operation,			TransferData transferType) {		return true;	}}
定义Drag:

package public_project.view.dnd;import org.eclipse.swt.dnd.DragSourceEvent;import org.eclipse.swt.dnd.DragSourceListener;public class ViewDragListener implements DragSourceListener{	@Override	public void dragStart(DragSourceEvent event) {		System.out.println();	}	@Override	public void dragSetData(DragSourceEvent event) {		System.out.println();	}	@Override	public void dragFinished(DragSourceEvent event) {		System.out.println();	}}
调用:

int operations = DND.DROP_COPY | DND.DROP_MOVE;	    Transfer[] transferTypes = new Transfer[]{FileTransfer.getInstance()};		treeViewer.addDropSupport(operations, transferTypes, new ViewDropListener(treeViewer));		treeViewer.addDragSupport(operations, transferTypes, new ViewDragListener());

转载于:https://my.oschina.net/liuyi126/blog/157957

你可能感兴趣的文章
List集合具体对象的特点
查看>>
网络信息安全之防火墙***检测方法 (五)
查看>>
怎样为用户写“招标书”
查看>>
1.7 文件目录管理及相关的命令使用方法
查看>>
实际案例告诉你大数据在农业中如何应用
查看>>
LAMP优化策略
查看>>
PDF中添加页面/合并 PDF 内容
查看>>
JS仿FLASH特效可跳转回首页的CSS二级联动菜单
查看>>
页面导入样式时,使用link和@import有什么区别?
查看>>
类成员与类的实例成员
查看>>
Spark源码编译并在YARN上运行WordCount实例
查看>>
Spring AOP + AspectJ annotation example
查看>>
Spring VS EJB 3 的若干认识误区(转)
查看>>
React.js初探(一)
查看>>
Neo4j CQL -(17)- NULL值
查看>>
BZOJ4554: [Tjoi2016&Heoi2016]游戏 luoguP2825 loj2057
查看>>
json_encode后的中文不编码成unicode
查看>>
iOS 导航栏title显示右偏移
查看>>
修改纵断面图标注栏
查看>>
Flex创建带有空间信息的椭圆(Polygon)
查看>>