我用的是:SmartGwt 3.0; gwt 2.4; firefox 11和Google Chrome 19.0.1084.52。
首先,我想为我的英语道歉,因为它非常糟糕。 我需要的是将组件(例如标签,图像等)拖放到listgrid中的单元格内。 我知道你可以拖动记录,但我想在单元格中添加任何类型的组件。 感谢任何帮助,无论多么小,因为否则我会玩来创建一个表组件,它具有大量属性listgrid,您可以在单元格中添加组件。事实并非如此解决问题。
我使用的是最新版本的smartgwt
我正在尝试使用方法“getShowRecordComponents”,“getShowRecordComponentsByCell”,“WillAcceptDrop”和“CreateRecordComponent”。我必须拖放一个组件smartgwt(通过先前的配置),但我在记录的末尾我Arreaga,我希望你把它放在你放弃组件的列行。
此类在其他类中调用。
private class CustomList extends ListGrid{
//record que hace el drop
private ListGridRecord currentRecord = null;
//elemento que se va a dropear
private Canvas currentCanvas = null;
//private int index;
public CustomList() {
this.setHeight(400);
this.setWidth(400);
this.setCanResizeFields(true);
this.setResizeFieldsInRealTime(true);
this.setShowRecordComponentsByCell(true);
this.setShowRecordComponents(true);
this.setCanAcceptDrop(true);
this.addRecordDropHandler(new RecordDropHandler() {
@Override
public void onRecordDrop(RecordDropEvent event) {
System.out.println("X: " + event.getX());
System.out.println("Y: " + event.getY());
System.out.println("index: " + event.getIndex());
System.out.println("event.getDropRecords() ==> "+ event.getDropRecords());
//guardamo el record y el canvas que se hace el drop
currentRecord = event.getTargetRecord();
currentCanvas = EventHandler.getDragTarget();
}
});
//defino columna ico
ListGridField field = new ListGridField("icon");
ListGridField field2 = new ListGridField("valor");
this.setFields(field, field2);
//añado record para poder aceptar drops
ListGridRecord record = new ListGridRecord();
ListGridRecord record2 = new ListGridRecord();
record.setCanAcceptDrop(true);
record.setAttribute("icon", "Hola");
record.setAttribute("valor", "adios");
record2.setAttribute("icon", "Segundo");
record2.setAttribute("valor", "Segundo Adios");
this.addData(record);
this.addData(record2);
}
//la llamada a createRecordComponent la hace el listgrid al crearse.
@Override
protected Canvas createRecordComponent (ListGridRecord record, Integer colNum) {
System.out.println("record: " + record);
System.out.println("colNum: " + colNum);
System.out.println("currentRecord: " + currentRecord);
if (record.equals(currentRecord)) {
System.out.println("createRecordComponent - REGRESARA: " + currentCanvas);
return currentCanvas;
}
return null;
}
@Override
public Boolean willAcceptDrop(){
return true;
}
@Override
public Canvas updateRecordComponent (ListGridRecord record, Integer colNum, Canvas component, boolean recordChange) {
System.out.println("***************************************************************************************");
System.out.println("Estoy en gridView");
System.out.println("***************************************************************************************");
System.out.println("record es : "+record);
System.out.println("colNum es : "+colNum);
System.out.println("component es : "+component);
System.out.println("recordChange es :"+recordChange);
System.out.println("***************************************************************************************");
return component;
}
}
你能帮帮我吗?
答案 0 :(得分:0)
我继续研究,我在listgrid中的单元格中插入了其他小部件,虽然我根本没有设法配置它,因此请求任何知道正确方法的人提供帮助。 1.- SmartGWT版本:
SmartClient版本:SC_SNAPSHOT-2011-12-05 /仅限LGPL开发(建于2011-12-05)
2.-浏览器版本:
VersGoogle Chrome 19.0.1084.52 m和Firefox 11.0
3.-问题: 如果设置为true,则此listGrid应在网格的每一行中创建并显示嵌入的组件。 使用此功能的开发人员应该实现ListGrid.createRecordComponent和ListGrid.updateRecordComponent方法,但是应用方法“updateRecordComponent”,但只调用此方法只是因为我从“createRecordComponent”调用它。为什么会出现这种情况?
每次运行方法“createRecordComponent”创建一个新行时,为什么这样做?我只想在单元格列表网格中删除
4.-代码:
private class CustomList extends ListGrid{
//record que hace el drop
private ListGridRecord currentRecord = null;
private ListGridRecord[] listRecord;
//elemento que se va a dropear
private Canvas currentCanvas = null;
private EmbeddedPosition position;
//posiciones offset respecto a diferentes indices.
private int x, x1, x2;
private int y, y1, y2;
private int col, fil;
public CustomList() {
this.setHeight(400);
this.setWidth(400);
this.setCanResizeFields(true);
this.setResizeFieldsInRealTime(true);
this.setRecordComponentPoolingMode(RecordComponentPoolingMode.RECYCLE);
this.setRecordComponentPosition(EmbeddedPosition.EXPAND);
this.setCanResizeFields(true);
this.setShowRecordComponentsByCell(true);
this.setShowRecordComponents(true);
this.setCanAcceptDrop(true);
this.setCanReorderRecords(true);
this.setCanAcceptDroppedRecords(true);
this.setCanDrop(true);
this.addRecordDropHandler(new RecordDropHandler() {
@Override
public void onRecordDrop(RecordDropEvent event) {
//guardamo el record y el canvas que se hace el drop
listRecord = event.getDropRecords();
currentRecord = event.getTargetRecord();
currentCanvas = EventHandler.getDragTarget();
position = getRecordComponentPosition();
x=event.getX();
y=event.getY();
col=getEventColumn();
fil=getEventRow();
}
});
//defino columna ico y valor
ListGridField field = new ListGridField("icon");
ListGridField field2 = new ListGridField("valor");
this.setFields(field, field2);
//añado record para poder aceptar drops
ListGridRecord record = new ListGridRecord();
ListGridRecord record2 = new ListGridRecord();
record.setCanAcceptDrop(true);
record.setAttribute("icon", "Hola");
record.setAttribute("valor", "adios");
record2.setAttribute("icon", "Segundo");
record2.setAttribute("valor", "Segundo Adios");
this.addData(record);
this.addData(record2);
}
//la llamada createRecordComponent ,debería hacersela al crearse.
@Override
protected Canvas createRecordComponent (ListGridRecord record, Integer colNum) {
//como comprueba, porque setShowRecordComponentsByCell está a true, celda por celda, me quedo para actualizar solo cuando coincide
//la fila y la columna en la que he hecho el drop.
if (record.equals(currentRecord) && (colNum.equals(col))) {
updateRecordComponent(currentRecord,colNum,currentCanvas, true);
}
return null;
}
@Override
public Boolean willAcceptDrop(){
return true;
}
@Override
public Canvas updateRecordComponent (ListGridRecord record, Integer colNum, Canvas component, boolean recordChange) {
x1=this.getAbsoluteLeft();
y1=this.getAbsoluteTop();
x2 = component.getAbsoluteLeft();
y2 = component.getAbsoluteTop();
//currentCanvas.setSnapTo("C");
addEmbeddedComponent(component, record, fil, colNum, EmbeddedPosition.WITHIN);
return component;
}
}