Changes

Jump to: navigation, search

Teams Winter 2011/team1/RCP/Create RPC Application

2,451 bytes added, 13:06, 4 March 2011
Created page with '=== 1. Create project and data model === === 2. Show data in the application === 2.1 Columns data in a JFace table can be hold in <code>ModelProvider</code> and it is defined vi…'
=== 1. Create project and data model ===

=== 2. Show data in the application ===
2.1 Columns data in a JFace table can be hold in <code>ModelProvider</code> and it is defined via instances of <code>TableViewerColumn</code> object:<br/>
<code>viewer.setInput(ModelProvider.INSTANCE.getStudents());</code><br/>
and
<code>TableViewerColumn col = createTableViewerColumn(titles[0], bounds[0], 0);</code>
2.2 Add the following lines to <code>StudentsView.java</code> class:<br/>
Private variable: <br/>
<code>private TableViewer viewer;</code><br/>
Change the <code>createColumns()method:<br/>
<pre>
String[] titles = { "Id", "First name", "Last name", "Program" };
int[] bounds = { 100, 100, 100, 100 };
// First column is for the student id
TableViewerColumn col = createTableViewerColumn(titles[0], bounds[0], 0);
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Student s = (Student) element;
return s.getId();
}
});
</pre><br/>
Add the same functionality for other three columns
2.3 Run your application:<br/>
[[Image: Create1.png | 400px]]<br/>

=== 3. Add edit cell feature ===
3.1 To make the column editable you need to define an object of type <code>EditingSupport/<code> on your TableColumnViewer.
3.2 Create new class for each column that extends <code>EditingSupport</code> class:
<pre>
package cs.ecl.rcp.simplercp.edit;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;

import cs.ecl.rcp.simplercp.model.Student;

public class IdEditingSupport extends EditingSupport {
private final TableViewer viewer;

public IdEditingSupport(TableViewer viewer) {
super(viewer);
this.viewer = viewer;
}

@Override
protected CellEditor getCellEditor(Object element) {
return new TextCellEditor(viewer.getTable());
}

@Override
protected boolean canEdit(Object element) {
return true;
}

@Override
protected Object getValue(Object element) {
return ((Student) element).getId();
}

@Override
protected void setValue(Object element, Object value) {
((Student) element).setId(String.valueOf(value));
viewer.refresh();
}
}
</pre><br/>
2.3 Assign <code>EditorSupport</code> objects to your <code>TableColumnViewers </code>in your <code>StudentView</code> class.
1
edit

Navigation menu