我在 vaadin 有两张桌子。一种是作为表主表。另一个是ScrollTable freezeTable。我需要两个表之间的同步滚动。如果我将垂直滚动 mainTable,则 freezeTable 应该滚动相同但在水平滚动的情况下我不想要任何同步滚动。我从 vaadin 论坛得到了一些想法,如下所示。但是由于某些已弃用的方法,我无法继续。
在MyViewPage.java我将这两个表添加为
addComponent(loadTables());
public HorizontalSplitPanel loadTables(){
final HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
Table mainTable = new Table();
ScrollTable freezeTable=new ScrollTable();
freezeTable.setDependentTable( mainTable );
freezeTable.setWidth( "300px" );
mainTable.setWidth( "800px" );
freezeTable.setContainerDataSource(myContainer);
freezeTable.setVisibleColumns(viscol);
freezeTable.setColumnHeaders(vishead);
freezeTable.setPageLength(15);
mainTable.setContainerDataSource(myAnotherContainer);
mainTable.setVisibleColumns(viscolmain);
mainTable.setColumnHeaders(visheadmain);
mainTable.setPageLength(15);
splitPanel.setFirstComponent(freezeTable);
splitPanel.setSecondComponent(mainTable);
return splitPanel;
}
ScrollTable 类是这样的。
滚动表.java
package com.abhiram.app.myproject.freezetable;
import com.vaadin.data.Container;
import com.vaadin.server.PaintException;
import com.vaadin.server.PaintTarget;
import com.vaadin.shared.ui.Connect;
import com.vaadin.ui.Table;
@SuppressWarnings("serial")
public class ScrollTable extends Table{
private Table mainTable;
public ScrollTable()
{
super();
}
public void setDependentTable( Table mainTable)
{
this.mainTable= mainTable;
}
@Override
public void paintContent( PaintTarget target ) throws PaintException
{
target.addAttribute( "scrollPane", this );
if ( table != null ) target.addAttribute( "dependentTable", mainTable);
super.paintContent( target );
}
}
我创建了另一个类 VMyScrollTable 并像这样扩展 VScrollTable。
VMyScrollTable.java
package com.abhiram.app.myproject.freezetable.client.ui;
import com.google.gwt.event.dom.client.ScrollEvent;
import com.google.gwt.event.dom.client.ScrollHandler;
import com.abhiram.app.myproject.freezetable.ScrollTable;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.UIDL;
import com.vaadin.client.ui.FocusableScrollPanel;
import com.vaadin.client.ui.VScrollTable;
import com.vaadin.shared.ui.Connect;
@Connect(com.abhiram.app.myproject.freezetable.ScrollTable.class)
public class VMyScrollTable extends VScrollTable{
public VMyScrollTable()
{
super();
}
@Override
public void updateFromUIDL( final UIDL uidl, final ApplicationConnection client )
{
super.updateFromUIDL(uidl,client );
final String tableId = uidl.getStringAttribute( "dependentTable" );
if ( tableId == null )
return;
String id = uidl.getStringAttribute( "scrollPane" );
VScrollTable scrollPane = (VScrollTable) client.getPaintable(id);
final FocusableScrollPanel scrollBody = (FocusableScrollPanel) scrollPane.getWidget(1);
scrollBody.addScrollHandler( new ScrollHandler()
{
@Override
public void onScroll( ScrollEvent event )
{
VMyScrollTable.this.onScroll( event );
VScrollTable dependentPane = (VScrollTable) client.getPaintable(tableId );
FocusableScrollPanel scrollToBeBody = (FocusableScrollPanel) dependentPane.getWidget( 1 );
scrollToBeBody.setScrollPosition( scrollBody.getScrollPosition() );
}
} );
}
}
这里的问题是VScrollTable类没有像updateFromUIDL(...)这样的方法,而ApplicationConnection没有像 getPaintable(String) 这样的方法。因此,我无法继续。请任何机构帮助我如何做到这一点。