GWT의 TreePanel 예: 드래그

5289 단어 UIextGooglegwt
이게 기초류예요.
package com.yingxia.assetmanager.client.commoncontrol;

import java.util.List;

import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.BaseTreeLoader;
import com.extjs.gxt.ui.client.data.ModelKeyProvider;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.data.TreeLoader;
import com.extjs.gxt.ui.client.store.TreeStore;
import com.extjs.gxt.ui.client.util.IconHelper;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.yingxia.assetmanager.client.common.ServiceContext;
import com.yingxia.assetmanager.client.entity.Dept;

public class DeptEmployeeTreePanel extends ContentPanel {

	private TreeLoader<BaseModelData> loader;
	protected TreePanel<BaseModelData> treePanel;
	
	public DeptEmployeeTreePanel() {
		
		setHeading(" ");
		setScrollMode(Scroll.AUTO);
		
		RpcProxy<List<BaseModelData>> proxy = new RpcProxy<List<BaseModelData>>() {
			
			@Override
			protected void load(Object loadConfig, AsyncCallback<List<BaseModelData>> callback) {
				int parentId = 0;
				if(loadConfig != null) {
					parentId = ((Dept) loadConfig).getGid();
				}
				ServiceContext.commonCtlSvc.selectDeptEmployeeByParentId(parentId, callback);
			}
		};
		
		loader = new BaseTreeLoader<BaseModelData>(proxy) {
			
			@Override
			public boolean hasChildren(BaseModelData parent) {
				return parent.getClass().equals(Dept.class);
			}
		};
		
		TreeStore<BaseModelData> store = new TreeStore<BaseModelData>(loader);
		store.setKeyProvider(new ModelKeyProvider<BaseModelData>() {
			
			@Override
			public String getKey(BaseModelData model) {
				return model.get("gid").toString();
			}
		});
		
		treePanel = new TreePanel<BaseModelData>(store);
		treePanel.setStateful(true);
		treePanel.setDisplayProperty("name");
		treePanel.getStyle().setLeafIcon(IconHelper.createPath("images/page_white.png"));
		
		add(treePanel);
	}
}

 
이것은 계승된 드래그 가능한 종류이다
package com.yingxia.assetmanager.client.employeemanager;

import java.util.List;

import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.BaseTreeModel;
import com.extjs.gxt.ui.client.dnd.TreePanelDragSource;
import com.extjs.gxt.ui.client.dnd.TreePanelDropTarget;
import com.extjs.gxt.ui.client.dnd.DND.Feedback;
import com.extjs.gxt.ui.client.event.DNDEvent;
import com.extjs.gxt.ui.client.event.DNDListener;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel.TreeNode;
import com.yingxia.assetmanager.client.common.MyAsyncCallback;
import com.yingxia.assetmanager.client.common.ServiceContext;
import com.yingxia.assetmanager.client.commoncontrol.DeptEmployeeTreePanel;
import com.yingxia.assetmanager.client.entity.CRUD;
import com.yingxia.assetmanager.client.entity.Dept;
import com.yingxia.assetmanager.client.entity.Employee;

public class ChangeDeptPanel extends DeptEmployeeTreePanel {

	public ChangeDeptPanel() {
		
		setHeading(" ");
		
		TreePanelDragSource source = new TreePanelDragSource(treePanel);
		source.addDNDListener(new DNDListener() {

			@Override
			public void dragStart(DNDEvent e) {

				BaseModelData sel = treePanel.getSelectionModel().getSelectedItem();
				if(sel != null && sel.getClass().equals(Dept.class)) {
					e.setCancelled(true);
					e.getStatus().setStatus(false);
					return;
				}
				super.dragStart(e);
			}
		});
		
		TreePanelDropTarget target = new TreePanelDropTarget(treePanel) {

			@SuppressWarnings("unchecked")
			@Override
			protected void onDragDrop(DNDEvent e) {
				
				super.onDragDrop(e);
				
				//  model
				BaseTreeModel model = (BaseTreeModel) ((List)e.getData()).get(0);
				Employee employee = model.get("model");
				
				//  model
				TreeNode node = this.activeItem;
				Dept dept = (Dept) node.getModel();
				
				employee.setDept_id(dept.getGid());
				
				MyAsyncCallback<Void> callback = new MyAsyncCallback<Void>() {
					
					@Override
					public void onSuccess(Void result) {
						MessageBox.alert(" ", " ", null);
					}
				};
				ServiceContext.commonSvc.executeEmployee(employee, CRUD.UPDATE, callback);
			}
		};
		target.setAllowSelfAsSource(true);
		target.setFeedback(Feedback.BOTH);
	}
}

좋은 웹페이지 즐겨찾기