pageableTable Not Updated Widget [message #1694836] |
Fri, 08 May 2015 11:26 |
Ashokkumar N Messages: 3 Registered: July 2013 |
Junior Member |
|
|
Here I tried in Nebula Table with Buttons.Its loading initial page fine.But After clicking some other page it will not override the Button.
package check;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.nebula.widgets.pagination.collections.PageResultLoaderList;
import org.eclipse.nebula.widgets.pagination.table.PageableTable;
import org.eclipse.nebula.widgets.pagination.table.SortTableColumnSelectionListener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
public class ModelSortPageableTableAndTotalChangedExample {
private static final String[] TOTAL_ITEMS = new String[] { "5", "200",
"1000", "2012" };
private static TableEditor editor;
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
GridLayout layout = new GridLayout(2, false);
shell.setLayout(layout);
Label totalLabel = new Label(shell, SWT.NONE);
totalLabel.setText("Total:");
final Combo combo = new Combo(shell, SWT.READ_ONLY);
combo.setItems(TOTAL_ITEMS);
combo.select(3);
int pageSize = 10;
final PageableTable pageableTable = new PageableTable(shell,
SWT.BORDER, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL, pageSize);
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.horizontalSpan = 2;
pageableTable.setLayoutData(gridData);
// 2) Initialize the table viewer SWT Table
TableViewer viewer = pageableTable.getViewer();
viewer.setContentProvider(ArrayContentProvider.getInstance());
viewer.setLabelProvider(new LabelProvider());
Table table = viewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
// 3) Create Table columns with sort of paginated list.
createColumns(viewer);
// 4) Set the page loader used to load a page (sublist of String)
// according the page index selected, the page size etc.
List<Person> items = createList(combo);
final PageResultLoaderList<Person> pageLoader = new PageResultLoaderList<Person>(
items);
pageableTable.setPageLoader(pageLoader);
// 5) Set current page to 0 to refresh the table
pageableTable.setCurrentPage(0);
combo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
List<Person> items = createList(combo);
pageLoader.setItems(items);
pageableTable.refreshPage(true);
}
});
shell.setSize(400, 250);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private static void createColumns(final TableViewer viewer) {
// First column is for the first name
TableViewerColumn col = createTableViewerColumn(viewer, "Name", 150);
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Person p = (Person) element;
return p.getFirstName();
}
@Override
public void update(ViewerCell cell) {
Person obj = (Person)cell.getItem().getData();
TableItem item = (TableItem) cell.getItem();
Button button=new Button(viewer.getTable(),SWT.NONE);
button.setText(obj.getFirstName());
editor = new TableEditor(item.getParent());
editor.grabHorizontal = true;
editor.grabVertical = true;
editor.setEditor(button , item, cell.getColumnIndex());
editor.layout();
}
});
col.getColumn().addSelectionListener(
new SortTableColumnSelectionListener("name"));
}
private static List<Person> createList(Combo combo) {
int total = Integer.valueOf(TOTAL_ITEMS[combo.getSelectionIndex()]);
List<Person> names = new ArrayList<Person>();
for (int i = 1; i < total; i++) {
names.add(new Person("Name " + i, i < 100 ? "Adress "
+ Math.random() : null));
}
return names;
}
private static TableViewerColumn createTableViewerColumn(
TableViewer viewer, String title, int bound) {
final TableViewerColumn viewerColumn = new TableViewerColumn(viewer,
SWT.NONE);
final TableColumn column = viewerColumn.getColumn();
column.setText(title);
column.setWidth(bound);
column.setResizable(true);
column.setMoveable(true);
return viewerColumn;
}
}
And the Person Class,
package check;
public class Person {
private final String firstName;
private final String lastName;
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public String getLastName() {
return lastName;
}
public String getFirstName() {
return firstName;
}
}
Here i attached two image.In first_page jpg is my first page result.And another image is clicked 4 th page but its not updated.Please some one suggest whats the issue.
Thanks,
Ashok.
|
|
|
|
Powered by
FUDForum. Page generated in 0.04960 seconds