Hi ,
I have a another solution for deletion of the row from table.I have used collection to fill table and delete row from table.
How it works,
When GUI is loaded first time, table is populate and button remove is disabled. when user select one of the row from table to delete it, button remove is enable. Clicking button will remove selected row from table.
it is the table class which will populate the value in table and row deletion method will delete selected row through rowId.
package myVaadin.Table;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Vector;
import com.vaadin.event.ItemClickEvent;
import com.vaadin.ui.Button;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Table;
public class FirstTable extends VerticalLayout {
private static final long serialVersionUID = 1L;
private Table table;
private Button btnRimuovi;
private Collection< String > collectionDtoTable;
public FirstTable(Button btnRimuovi) {
this.btnRimuovi =btnRimuovi; // Button is in my calling class, you can make it here also
table= new Table();
// size
table.setWidth("300.0px");
table.setHeight("300.0px");
addComponent(table);
table.setSelectable(true);
table.setImmediate(true); //react at once when something is selected
}
public void buildListOL() throws Exception
{
table.addContainerProperty("FirstHeader", String.class, null);
table.addContainerProperty("SecondHeader",String.class, null);
}
public void populateTable(Collection<String> collectionDtoTable){
this.collectionDtoTable=collectionDtoTable;
System.out.println("collectionDtoTable"+collectionDtoTable.size());
int itemId=1;
table.removeAllItems();
for(int i=0;i<5;i++){
Vector v = new Vector();
v.add(((ArrayList<String>)collectionDtoTable).get(i));
v.add(((ArrayList<String>)collectionDtoTable).get(i));
table.addItem(v.toArray(), new Integer(itemId));
itemId++;
}
table.addListener(new ItemClickEvent.ItemClickListener() { // for ebaling of the button on selecting a row
private static final long serialVersionUID = 1L;
public void itemClick(ItemClickEvent event) {
btnRimuovi.setEnabled(true);
}
});}
public void rowDeletion()// this will remove selected row from the table.
{
Integer rowId = (Integer)table.getValue();
((ArrayList<String>)collectionDtoTable).remove(rowId.intValue()-1);
try {
table.removeAllItems();
populateTable(collectionDtoTable);
} catch (Exception e) {
e.printStackTrace();
}}}
[b]
It is class which will create main Window.
[/b]
package myVaadin;
import com.vaadin.Application;
import com.vaadin.ui.Window;
public class TestApplication extends Application
{
public void init()
{
Window mainWindow = new Window(“Test Application”);
ShowTable myComponent = new ShowTable();
// may be needed if you haven’t set the size in the component
myComponent.setSizeFull(); // make sure the implicit layout of the main window fills the window
mainWindow.getContent().setSizeFull();
mainWindow.addComponent(myComponent);
setMainWindow(mainWindow);
}
}
it is class which will add table and button to mainLayout(large though)
public class ShowTable extends CustomComponent{
private AbsoluteLayout mainLayout;
private AbsoluteLayout absLytComponent;
private Panel pnlMain;
private Button btnRimuovi;
FirstTable firstTable;
private Collection <String> collectionDtoTable;
public ShowTable() {
// the main layout and components will be created here
mainLayout = new AbsoluteLayout();
mainLayout.setHeight("360.0px");
mainLayout.setWidth("100%");
mainLayout.setDebugId("mainLayout");
//add component level Height and Weight
pnlMain = mainPnlFunt();
mainLayout.addComponent(pnlMain);
setCompositionRoot(mainLayout);
}
private Panel mainPnlFunt()
{
pnlMain = new Panel();
pnlMain.setHeight("100%");
pnlMain.setWidth("100%");
pnlMain.setDebugId("mainPnlFunt");
absLytComponent = absLytComponent();
pnlMain.setContent(absLytComponent);
return pnlMain;
}
private AbsoluteLayout absLytComponent()
{
absLytComponent = new AbsoluteLayout();
absLytComponent.setHeight("100%");
absLytComponent.setWidth("100%");
absLytComponent.setDebugId("absLytComponent");
absLytComponent.setMargin(false);
btnRimuovi = new Button("remove");
btnRimuovi.setDebugId("AccordianInsTipoCodec-BttnAggiungi");
btnRimuovi.setImmediate(true);
btnRimuovi.setEnabled(false);
btnRimuovi.setWidth("-1.0px");
btnRimuovi.setHeight("-1.0px");
collectionDtoTable = new ArrayList<String>();
collectionDtoTable.add("value1");
collectionDtoTable.add("value2");
collectionDtoTable.add("value3");
collectionDtoTable.add("value4");
collectionDtoTable.add("value5");
collectionDtoTable.add("value6");
collectionDtoTable.add("value7");
collectionDtoTable.add("value8");
firstTable = new FirstTable(btnRimuovi);
try {
firstTable.buildListOL();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("collectionDtoTable"+collectionDtoTable.size());
firstTable.populateTable(collectionDtoTable);
btnRimuovi.addListener(new Button.ClickListener() {
private static final long serialVersionUID = 1L;
public void buttonClick(ClickEvent event) {
firstTable.rowDeletion();
}});
absLytComponent.addComponent(btnRimuovi,"left:450.0px");
absLytComponent.addComponent(firstTable,"top:5.0px;left:5.0px");
return absLytComponent;
}
}
Please write me if u need more infor on it ,
vconly4you@gmail.com