0

我正在使用:SmartGwt 3.0;重量 2.4; 火狐 11 和谷歌浏览器 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;
  }
}

你能帮助我吗??

4

1 回答 1

0

我继续研究并设法在列表网格的单元格中插入其他小部件,尽管我根本没有设法配置它,因此向知道正确方法的任何人寻求帮助。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;
}

}

于 2012-05-30T15:35:14.077 回答