In this example I make on the rich employee table a collection Drag Source and on the department form a drop target for this collection. I changed the employee table so it support multiple selection so I can update the department of many employees at the same time
first we drop from the component palette collectionDragSource on the table
public class empDndBean {
public DnDAction drop(DropEvent dropEvent) {
try {
DataFlavor
RowKeySet droppedValue = dropEvent.getTransferable().getData(df);
if (droppedValue == null) {
return DnDAction.NONE;
} else {
// get the current department
DCIteratorBinding departmentsIter = (DCIteratorBinding) getBindings().get("DeptView1Iterator");
Row rw = departmentsIter.getCurrentRow();
Number department = (oracle.jbo.domain.Number)rw.getAttribute("Deptno");
AppModuleImpl am = getAm();
Object[] keys = droppedValue.toArray();
Key empKey= null;
// get the employee which we want to update the department
for (int i = 0; i < keys.length; i++) {
List l = (List)keys[i];
empKey = (Key)l.get(0);
EmpViewRowImpl empRow = (EmpViewRowImpl) am.getEmpView1().getRow(empKey);
empRow.setDeptno(department);
}
am.getDBTransaction().commit();
// requery the employees view
am.getEmpView2().clearCache();
am.getEmpView2().executeQuery();
am.getEmpView1().clearCache();
am.getEmpView1().executeQuery();
}
return DnDAction.COPY;
} catch (Exception ex) {
System.out.println("drop failed with : " + ex.getMessage());
return DnDAction.NONE;
}
}
private BindingContainer getBindings() {
FacesContext fc = FacesContext.getCurrentInstance();
Application app = fc.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = fc.getELContext();
ValueExpression valueExp = elFactory.createValueExpression(elContext, "#{bindings}", Object.class);
return (BindingContainer) valueExp.getValue(elContext);
}
private AppModuleImpl getAm(){
FacesContext fc = FacesContext.getCurrentInstance();
Application app = fc.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = fc.getELContext();
ValueExpression valueExp =
elFactory.createValueExpression(elContext,
"#{data.AppModuleDataControl.dataProvider}",
Object.class);
return (AppModuleImpl)valueExp.getValue(elContext);
}
}
No comments:
Post a Comment