Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » how to get latest UI data after sorting the tableViewer or moving one column(need to save the changed data)
how to get latest UI data after sorting the tableViewer or moving one column [message #637937] Tue, 09 November 2010 12:12 Go to next message
Ping Luo is currently offline Ping LuoFriend
Messages: 8
Registered: January 2010
Location: Beijing
Junior Member
hi guys,

sorry to interrupt you again. maybe a simple question.

In TableViewer, after set the column moveable, we can change the columns sequence, such as drag the whole last column to be the first one. In UI, we can see the table item data has changed(the sequence), now I want to save all input data as it shows in UI, but the tableViewer.getInput() call always return the same old intput model data. here is the code:

Object input = tableViewer.getInput();
Table table = tableViewer.getTable();
TableColumn[] columns = table.getColumns();
for(TableColumn column : columns){
System.out.print(column.getText() + " ");
System.out.println();
}
System.out.println("data");
TableItem[] items2 = tableViewer.getTable().getItems();
for(TableItem item : items2){
for(int i = 0; i < columns.length; i++){
System.out.print(item.getText(i) + " ");
}
System.out.println();
}

the same situation is when using sorter, after change the order of lines, it seems that the TableViewer only change the way how to show the input data, now I want to save the changed table data(at least the sequence is changed) , can you give some suggestion?

thanks,
Ping
Re: how to get latest UI data after sorting the tableViewer or moving one column [message #637944 is a reply to message #637937] Tue, 09 November 2010 12:33 Go to previous messageGo to next message
T. Wilhelm is currently offline T. WilhelmFriend
Messages: 129
Registered: July 2009
Senior Member
HI Ping Luo,

it seems that you go a very strange way to get the input. Did you register a ContentProvider and a LabelProvider? Getting the input via the table items is a very bad way.

You should have both and then use a list of POJOs as Input, so you dont have to care about the column order.

See an example howto do here:
http://www.vogella.de/articles/EclipseJFaceTable/article.htm l

The best way would be if you use Databinding, its a little bit more complicated but a very cool way to bind your model to your table.

Greetz
Thomas
Re: how to get latest UI data after sorting the tableViewer or moving one column [message #638121 is a reply to message #637944] Wed, 10 November 2010 01:37 Go to previous messageGo to next message
Ping Luo is currently offline Ping LuoFriend
Messages: 8
Registered: January 2010
Location: Beijing
Junior Member
Hi Thomas,

actually I have content and label provider, and also, each column has its own cellEditor. after I change one cell text, I can use the code Object input = tableViewer.getInput(); to get the latest model data.
My question is, after exchange two column, such as column1, column2, has been changed to column2, column1, the Data in UI seems be changed, but when I still use Object input = tableViewer.getInput() , I always get the old model(I want to get the data like it shows in UI). here is the example:

column1 column2 column 3
11 12 13
21 22 23

after move the column2 to be the first one, in UI it shows:

column2 column1 column 3
12 11 13
22 21 23

now I want to save the new data, my table input is a EList<EList<String>>, not use any POJO class.

getting the input via the table items is not the way, I just want to have a try in this case if I can use table items to get the sequence changed data, but it failed too.

any other suggestions?

thanks,
Ping

Re: how to get latest UI data after sorting the tableViewer or moving one column [message #638127 is a reply to message #638121] Wed, 10 November 2010 03:34 Go to previous message
Ping Luo is currently offline Ping LuoFriend
Messages: 8
Registered: January 2010
Location: Beijing
Junior Member

the problem is solved, table.getColumnOrder(); can get the UI column order, using the order index we can re save data through the old input.

thanks,
Ping
Previous Topic:how to change and add TableViewer's columns dynamically
Next Topic:[DataBinding] How to bind a FileDialog to a bean property
Goto Forum:
  


Current Time: Fri Apr 19 21:27:02 GMT 2024

Powered by FUDForum. Page generated in 0.03525 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top