Reputation: 3
I want to make my table viewer editable. I decide to use setEditingSupport and EdittingSupport. But the table content is stored in a string array, which has no setter and getter. How can I write code in the getValue() and setValue() in the class extends EdittingSupport? The code of the tableviewer shows below:
public class DatatypePage extends WizardPage
{
public static final String NAME = "type";
private MigratorWizard wizard;
private TableViewer tableViewer;
protected DatatypePage(MigratorWizard wizard)
{
super(NAME);
this.wizard = wizard;
setTitle("Data Type");
setDescription("This is a data type page");
}
@Override
public void createControl(Composite parent)
{
Composite compositeContent = new Composite(parent, SWT.NONE);
setControl(compositeContent);
//super.createControl(parent);
//updatePage(rbtnDatatype);
compositeContent.setLayout(new FormLayout());
Button btnEditConstraint = new Button(compositeContent, SWT.NONE);
FormData fd_btnEditConstraint = new FormData();
fd_btnEditConstraint.left = new FormAttachment(0, 287);
btnEditConstraint.setLayoutData(fd_btnEditConstraint);
btnEditConstraint.setText("Edit Constraint");
Button btnAddConstraint = new Button(compositeContent, SWT.NONE);
fd_btnEditConstraint.top = new FormAttachment(btnAddConstraint, 0, SWT.TOP);
fd_btnEditConstraint.right = new FormAttachment(btnAddConstraint, -63);
FormData fd_btnAddConstraint = new FormData();
fd_btnAddConstraint.bottom = new FormAttachment(100);
fd_btnAddConstraint.left = new FormAttachment(0, 500);
btnAddConstraint.setLayoutData(fd_btnAddConstraint);
btnAddConstraint.setText("Add Constraint");
btnAddConstraint.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
}
});
Button btnDeleteConstraint = new Button(compositeContent, SWT.NONE);
fd_btnAddConstraint.right = new FormAttachment(btnDeleteConstraint, -60);
FormData fd_btnDeleteConstraint = new FormData();
fd_btnDeleteConstraint.left = new FormAttachment(0, 710);
fd_btnDeleteConstraint.right = new FormAttachment(100, -2);
fd_btnDeleteConstraint.bottom = new FormAttachment(100);
btnDeleteConstraint.setLayoutData(fd_btnDeleteConstraint);
btnDeleteConstraint.setText("Delete Constraint");
btnDeleteConstraint.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ISelection selection = tableViewer.getSelection();
logger.debug("datatype selected");
if (selection != null || selection instanceof IStructuredSelection) {
IStructuredSelection sel = (IStructuredSelection) selection;
Iterator iterator = sel.iterator();
while(iterator.hasNext()) {
Object obj = iterator.next();
tableViewer.remove(obj);
}
}
}
});
tableViewer = new TableViewer(compositeContent, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
Table table = tableViewer.getTable();
FormData fd_table = new FormData();
fd_table.bottom = new FormAttachment(btnEditConstraint, -6);
fd_table.top = new FormAttachment(0);
fd_table.left = new FormAttachment(0);
fd_table.right = new FormAttachment(100);
table.setLayoutData(fd_table);
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableViewerColumn tcolOracle = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn tcOracle = tcolOracle.getColumn();
tcOracle.setText("oracle");
tcOracle.setWidth(300);
tcolOracle.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
String[] t = (String[]) element;
return t[0];
}
});
tcolOracle.setEditingSupport(new FirstColEdittingSupport(tableViewer));
TableViewerColumn tcolHighgo = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn tcHighgo = tcolHighgo.getColumn();
tcHighgo.setText("hgdb");
tcHighgo.setWidth(300);
tcolHighgo.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
String[] t = (String[]) element;
return t[1];
}
});
initConfig();
}
private void initConfig()
{
tableViewer.setContentProvider(new ArrayContentProvider());
//tableViewer.setInput(DataTypeFactory.getInstance().getCastList(wizard.getSourceInfo().getDBType()));
// make the selection available to other views
// getSite().setSelectionProvider(tableViewer);
}
public void update()
{
logger.debug("sourceDB=" + wizard.getSourceInfo().getDBType());
tableViewer.setInput(DataTypeFactory.getInstance().getCastList(wizard.getSourceInfo().getDBType()));
logger.debug("dataType = "+ wizard.getSourceInfo().getDBType());
tableViewer.refresh();
// tableViewer.getTable().selectAll();
}
}
Upvotes: 0
Views: 155
Reputation: 111141
You will have to change the design of the input so that it does not use just a string array. Use a class for each row containg the columns data and add get and set methods to that class.
You can either change the data you pass to setInput
to use this class or you can use a custom content provider to do the conversion.
Upvotes: 1