GWT의 TreePanel 예: 드래그
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);
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Application Development in WebOSDevelop applications in WebOS Recognize the abstract class Application The operating system accepts classes that impleme...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.