0

I have two table in vaadin. One is as Table mainTable. Another is ScrollTable freezeTable. I need a synchronize scroll between two table. If i will scroll mainTable vertically the freezeTable should scroll as same but in case of horizontal scroll I don't want any synchronize scroll. I got some idea from vaadin forum like belows. But I am unable to proceed because of some deprecated method.

In MyViewPage.java I am adding this two table as

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 class is like this.

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

I have created another class VMyScrollTable and extend VScrollTable like this.

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

Here problem is VScrollTable class have no method like updateFromUIDL(...) and ApplicationConnection have no method like getPaintable(String). I am unable to proceed because of this. Please any body help me how to do this.

Mina
  • 29
  • 1
  • 8

1 Answers1

1

You're on the right track, but you seem to be confusing the Widget with the ComponentConnector. Here's a working version, modified from your code:

ScrollTable.java - identical to yours

public class ScrollTable extends Table {
    private Table mainTable;

    public void setDependentTable(Table mainTable) {
        this.mainTable = mainTable;
    }

    @Override
    public void paintContent(PaintTarget target) throws PaintException {

        target.addAttribute("scrollPane", this);
        if (mainTable != null) {
            target.addAttribute("dependentTable", mainTable);
        }
        super.paintContent(target);
    }
}

ScrollTableConnector.java - this is the connector class that sits on the client between the Widget and the server

@Connect(ScrollTable.class)
public class ScrollTableConnector extends TableConnector implements
        ScrollHandler {

    private VScrollTable dependentPane = null;

    @Override
    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
        super.updateFromUIDL(uidl, client);
        String tableId = uidl.getStringAttribute("dependentTable");
        if (tableId == null) {
            return;
        }
        if (dependentPane == null) {
            FocusableScrollPanel scrollBody = (FocusableScrollPanel) getWidget()
                    .getWidget(1);
            scrollBody.addScrollHandler(this);
        }
        dependentPane = ((TableConnector) client.getConnector(tableId, 0))
                .getWidget();
    }

    @Override
    public void onScroll(ScrollEvent event) {
        FocusableScrollPanel scrollBody = (FocusableScrollPanel) getWidget()
                .getWidget(1);
        FocusableScrollPanel scrollToBeBody = (FocusableScrollPanel) dependentPane
                .getWidget(1);
        scrollToBeBody.setScrollPosition(scrollBody.getScrollPosition());
    }
}

...and that's it. No need to modify the Widget; instead we're directly reusing VScrollTable. And your original test UI should work as-is since nothing on the server-side changed.

Now, ScrollTableConnector, being a ComponentConnector, is client-side code and should be placed in your client package—that is, the source path of your widgetset. For example, if your *.gwt.xml file is in the package com.example.foo, ScrollTableConnector should go to the package com.example.foo.client or one of its subpackages. That way the widgetset compiler will know where to look for it.

And finally, remember to recompile your widgetset. If you're using the Vaadin Eclipse plugin, just click the Compile Widgetset button. If you're using Maven, run mvn vaadin:compile.

jupenur
  • 1,005
  • 6
  • 8
  • Hi Jupenur, Thank you for your response. But it is not working. I am giving sysout inside these three overridden method. PaintContent method is executed for the first time when page is loaded.updateFromUIDL() and onScroll() methods are not executed. – Mina Jun 02 '14 at 16:52
  • Does it still render both of the Tables on the client-side? Did you remember to recompile the widgetset? Is your ScrollTableConnector in the widgetset's source path? – jupenur Jun 02 '14 at 17:10
  • I am not creating any Widgetset. I am using this project. In netbeans I am only building my project and deploying in liferay jboss server. Please check the below link. [https://www.dropbox.com/s/4qqjp81vgrjlaoh/myproject.zip](https://www.dropbox.com/s/4qqjp81vgrjlaoh/myproject.zip) @jupenur – Mina Jun 02 '14 at 23:31
  • You should move `ScrollTableConnector` to the `com.abhiram.app.client` package and then recompile the widgetset. I've updated my answer with info on how to do that. – jupenur Jun 03 '14 at 05:32
  • I moved `ScrollTableConnector` to `com.abhiram.app.client` package. I updated the widgetset using `vaadin:update-widgetset`. It build successfully. But When I am compiling using `vaadin:compile` it is showing the error as ` [ERROR] Errors in 'file:/E:/New%20folder/myproject-parent/myproject/target/classes/com/abhiram/app/client/ScrollTableConnector.java` [ERROR] Line 19: com.abhiram.app.ScrollTable cannot be resolved to a type [ERROR] Line 19: Class cannot be resolved to a type [ERROR] Aborting compile due to errors in some input files` @jupenur – Mina Jun 04 '14 at 16:37
  • I'm guessing the widgetset compiler is looking for the class from the `target` directory and, for one reason or another, it's not there. This is just a guess, though. Try recompiling the project in your IDE and then running `mvn vaadin:compile` again. – jupenur Jun 04 '14 at 17:05
  • Actually I am using netbeans IDE. First time it was not recognising the `vaadin:compile`. Then I changed something in pom.xml. After compiling in using `compiler:compile` also it is showing the Error I mentioned in previous comment. Please see the link [https://www.dropbox.com/s/ouo2k9nc3ls8cac/myproject-parent.zip](https://www.dropbox.com/s/ouo2k9nc3ls8cac/myproject-parent.zip) for my whole parent project with module.Thank You @jupenur – Mina Jun 04 '14 at 18:19
  • Adding this to the configuration of `vaadin-maven-plugin` did the trick: `${project.build.directory}` – jupenur Jun 04 '14 at 18:33
  • Same error is coming after adding `${project.build.directory}` to the configuration of `vaadin-maven-plugin` @jupenur – Mina Jun 04 '14 at 18:52
  • After the change, run `mvn clean compiler:compile vaadin:compile` – jupenur Jun 04 '14 at 19:01
  • Now Compiling correctly. But synchronized scroll is not working. @jupenur – Mina Jun 04 '14 at 20:21
  • Really? I tested it even with the project you pointed me to, and I got it working fine. What exactly is happening? Do you see anything strange in the Vaadin debug window? Or maybe I just understood your question wrong in some way? – jupenur Jun 05 '14 at 10:30
  • Here's what I have: http://goo.gl/Fe9eWA If it looks different on your machine, there's still something wrong with the build. – jupenur Jun 05 '14 at 11:02
  • Now its working fine. My latest project is [https://www.dropbox.com/s/rz1ghabbp4ispj5/freezetable.zip](https://www.dropbox.com/s/rz1ghabbp4ispj5/freezetable.zip). But one problem. I don't want scroll bar in case of dependent table. I am hiding it by writing css as overflow:hidden. Both table have same height. When I scrolled down fully the line miss match occur at the end. Because there is a horizontal-scroll bar on right table but not in left table. If I am having a cell of more height in any table then line mismatch occur. Please, Is there any solution for this..@jupenur – Mina Jun 11 '14 at 08:56
  • Try `overflow-y: hidden` instead; that way the horizontal scrollbar stays visible. – jupenur Jun 11 '14 at 09:20
  • I need both scrollbar invisible. Another thing is that if I will make `overflow-y:hidden` and I have not more column in left table for a scrollbar, any way the horizontal scrollbar will stay invisible.@jupenur – Mina Jun 11 '14 at 10:00
  • Hello Jupenur, I solved the problem. Thank you so much for your help. I want to ask another doubt. Like `onScroll` method in `ScrollHandler` interface is there any thing for `column resize handler`?? @jupenur – Mina Jun 13 '14 at 07:26
  • This is getting a bit too off-topic. :) Why don't you make a new question instead and include some more details on what you're trying to achieve. I have [tag:vaadin] in my favorites, so I'll definitely see it and answer in case no-one else does. – jupenur Jun 13 '14 at 07:58