Changes

Jump to: navigation, search

Teams Winter 2011/team1/RCP/Define and use JFace

206 bytes added, 13:36, 9 March 2011
7. Adding a perspective
==Define and view JFace Viewers = 2==== 1. Show Data in Application ===21.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>
21.2 Add the following lines to <code>StudentsView.java</code> class:<br/>
Private variable: <br/>
<code>private TableViewer viewer;</code><br/>
</pre><br/>
Add the same functionality for other three columns
21.3 Run your application:<br/>
[[Image: Create1.png | 400px]]<br/>
=== 32. Add Edit Cell Data Option ===32.1 To make the column editable you need to define an object of type <code>EditingSupport/<code> on your TableColumnViewer.32.2 Create new class for each column that extends <code>EditingSupport</code> class:
<pre>
package cs.ecl.rcp.simplercp.edit;
}
</pre><br/>
32.3 Assign <code>EditorSupport</code> objects to your <code>TableColumnViewers </code>in your <code>StudentView</code> class.<br/>
Add the following line at the end of the <code>LabelProvider</code> is set:<br/>
<code>col.setEditingSupport(new IdEditingSupport(viewer));</code><br/>
32.4 Run your application. You should now be able to modify the content of the table:<br/>
[[Image: Create2.png | 400px]]<br/>
=== 43. Add Sorting Option ===43.1 Create a new Class <code>StudentViewerComparator.java</code> put it in package <code>sorter</code>:<br/>
<pre>
package cs.ecl.rcp.simplercp.sorter;
}
</pre><br/>
43.2 Add new private variable to <code>StudentsView</code> class:<br/>
<code>private StudentViewerComparator comparator;</code><br/>
43.3 Add the following lines to the end of <code>createPartControl()</code> method:<br/>
<pre>
comparator = new StudentViewerComparator();
viewer.setComparator(comparator);
</pre><br/>
43.4 Add <code>SelectionListener</code> the to the <code>createTableViewerColumn()</code> method:
<code>column.addSelectionListener(getSelectionAdapter(column, colNumber));</code><br/>
43.5 Add new method:<br/>
<pre>
private SelectionAdapter getSelectionAdapter(final TableColumn column, final int index) {
}
</pre><br/>
43.6 Run the application. Click on a column header, the table should be sorted according to the content of this column.<br/>
There will also appear a sort-direction in the top of the column:<br/>
[[Image: Create3.png | 400px]]<br/>
=== 54. Add Filter(Search) Option ===54.1 Create new class that extends <code>ViewerFilter</code>. This class uses case-insensitive filtering:<br/>
<pre>
package cs.ecl.rcp.simplercp.filter;
}
</pre><br/>
54.2 Create a new private variable in the <code>StudentView</code> class:
<code>private StudentFilter filter;</code><br/>
54.3 Add the filter to <code>createPartControl()</code> method:<br/>
<pre>
filter = new StudentFilter();
viewer.addFilter(filter);
</pre><br/>
54.4 Run the application. Search for the student:<br/>
[[Image: Create4.png | 400px]]<br/>
=== 65. Add Highlights to Search ===65.1 Create a new helper class and put it in <code>util</code> package. <br/>
Method in this class use logic that is case-insensitive, because filter is case-insensitive:<br/>
<pre>
}
</pre><br/>
65.2 Change the way columns are created in the <code>createColumns()</code> method.<br/>
Following is the code for the first column, other columns need to be changed in similar way:<br/>
<pre>
col.setEditingSupport(new IdEditingSupport(viewer));
</pre><br/>
65.3 Run the application. Now your search matches are highlighted:<br/>
[[Image: Create5.png | 400px]]
7.5 Run the application. You should be able to select your perspective interactively:<br/>
[[Image: Perspective1.png | 400px]]
 
<br/>
[[Teams_Winter_2011/team1| Index Page]] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [[Teams_Winter_2011/team1/RCP/Create_configuration| Next>>]]
1
edit

Navigation menu