2012-05-28 30 views
0

我用:SmartGwt 3.0; gwt 2.4; Firefox 11和Google Chrome 19.0.1084.52。如何在listgrid中的單元格內拖放元素?

首先,我想爲我的英語道歉,因爲它很糟糕。 我需要的是將一個組件(例如標籤,圖像等)拖放到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

我繼續研究,我管理插入listgrid中的單元格內的其他部件,雖然我沒有設法配置它,因此呼籲任何人知道正確的方式幫助。 1.- SmartGWT的版本:

SmartClient的版本:SC_SNAPSHOT-2011-12-05/LGPL發展只有(建2011-12-05)

2:瀏覽器版本:

VersGoogle鉻19.0 .1084.52 m和Firefox 11.0

3.-問題: 如果設置爲true,則此listGrid應該在網格的每一行中創建並顯示嵌入式組件。 使用此功能的開發人員應實現ListGrid.createRecordComponent和ListGrid.updateRecordComponent方法,但實現方法「updateRecordComponent」,但僅調用此方法是因爲我從「createRecordComponent」中調用該方法。爲什麼會這樣?

每次運行方法「createRecordComponent」創建一個新行時,爲什麼要這樣做?我只想讓小區內的下降listgrid

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; 
} 

}