From: Till S. <til...@tu...> - 2014-04-07 14:37:51
Attachments:
signature.asc
|
Hi Shamshad, first of all i have to say sorry for the mess in the table view. I have looked through the code and many things are implemented in a non-standard way. Therefore, it is not easy to add the new functionality here. I did not expect this bug to be so messy, otherwise we would not have proposed to fix it on the mailing list. Normally one should just use the TableRowSorter and add a comparator that handles the sorting. The TableView is using a custom TableViewRowSorter, instead. To apply a sorting, that is not based on the values of the model (they are lazy loaded and therefore not available all the time) it creates a wrapper around the model that replaces the values with the sorting values (which are calculated by the database). Regarding your patch: Although it might work, there are some things that need to be fixed before we can apply it. 1. Usage: There should be an option to toggle the behavior between "selection first" and "selection has no influence" 2. Code Structure: - It is a no go to re-implement the TableRowSorter and DefaultRowSorter and apply a different ordering there. The best practice would be to overload a comparator (see above). and fix the current ugly implementation in the TableRowSorter, which replaces the sort values. Since we do not expect this depth of changes from you, it would also be fine if you just add a comparator, that only handles the selection case, and keep the value replacing code for the normal sorting. - System.out.println should be removed (there is some debug output) Greetings Till Am Montag, 7. April 2014, 12:07:30 schrieb Shamshad Alam: > Hi Sir, > > "Feature Request #41 : Table View Sort by Selection" has been implemented. > Find patches attached with mail. > > I have tested it on small dataset which consists of just 602 molecules and > I found no any performance issue. > > There might be performance issue because two lists, one for selected rows > and other for unselected rows, are sorted separately and thereafter both > are merged together. > > Could you provide a database which have relatively large number of > molecules? It will help me to assess the performance of whatever I > implement. > > > Thanks > Shamshad > > -- Dipl.-Inf. Till Schäfer TU Dortmund University Chair 11 - Algorithm Engineering Otto-Hahn-Str. 14 / Room 237 44227 Dortmund, Germany e-mail: til...@cs... phone: +49(231)755-7706 fax: +49(231)755-7740 web: http://ls11-www.cs.uni-dortmund.de/staff/schaefer pgp: https://keyserver2.pgp.com/vkd/SubmitSearch.event?&&SearchCriteria=0xD84DED79 |
From: Anjenson <hot...@gm...> - 2014-04-08 10:19:44
|
Hi Shamshad, I have been thinking about how to implement this feature as well, so I had an idea of creating some kind of function that will calculate new index for selected items. This index will be returned when asking for the row of molecule and used when asking for the value in the row. Because as I understand it may take resorting all the dataset when selecting item after the table had been loaded. I suppose it can be done by manipulating with mappings field in Sortie class (however, I am very much not sure I understand the the purpose of this field correctly) or creating additional one. Regards, Andrew "Anjenson" Zhilka On 04/07/2014 08:33 PM, Shamshad Alam wrote: > Hi, > > Sorry, I tried first to solve it by implementing comparator. But it > could not be feasible for me because parameters passed in compare() > method of comparator are the two values to be compared instead of row > index (row index is required to determine a row is selected or not). > So, we have no idea about values we have in compare() method that they > belong to selected or unselected row. > > Currently my aim is to get to know how the entire system is working > and familiarize myself with the coding style and architecture of > Scaffold Hunter. So, should I try other features request such as '#38 > Split subsets by scaffolds on a specified level'? > > Actually I have not made efforts to develop such messy codes. I > created a copy of DefaultRowSorter and TableRowSorter implementation > available in java swing and added single method (sort(int[] > selectedRows)) in DefaultRowSorter (You can see the changes in > attachment. It is quite simple). > > > Thanks > Shamshad |
From: Shamshad A. <sha...@gm...> - 2014-04-08 11:18:43
|
Hi Anjenson, It might be possible. Before each comparison for sorting getValueAt() of ModelWrapper is called. In this method we are determining that values of the column are loaded or not, and if not then we perform lazy loading, based on the column index we have in the method. Since we also have row index in the method getValueAt(), we can determine the state of row in table. We can return an object, which has both its state information (a boolean field) and its value, from method getValueAt(). In compare() method of Comparator now we have both state and value. It seems manipulation of sortie class is not required. We may do it by just modifying getValueAt() of ModelWrapper, getComparator() of TableViewRowSorter and compare() of MyComparator. Regards, Shamshad |
From: Till S. <til...@tu...> - 2014-04-11 15:56:59
|
Hi, it is possible without manipulating the data. you can just pass the set of selected molecules to the constructor of the comparator. in the compare method you just check if the item is in the set. If only one item is in the set, you return that the item is lower in the ordering, otherwise you compare the values. Normally the translation from values to positions should also be handled by a map from object to posiotion (which should also be a member of the comparator). Regards, Till Am Dienstag, 8. April 2014, 16:48:37 schrieb Shamshad Alam: > Hi Anjenson, > > It might be possible. Before each comparison for sorting getValueAt() of > ModelWrapper is called. In this method we are determining that values of > the column are loaded or not, and if not then we perform lazy loading, > based on the column index we have in the method. > > Since we also have row index in the method getValueAt(), we can determine > the state of row in table. We can return an object, which has both its > state information (a boolean field) and its value, from method > getValueAt(). In compare() method of Comparator now we have both state and > value. It seems manipulation of sortie class is not required. We may do it > by just modifying getValueAt() of ModelWrapper, getComparator() of > TableViewRowSorter and compare() of MyComparator. > > Regards, > Shamshad -- Dipl.-Inf. Till Schäfer TU Dortmund University Chair 11 - Algorithm Engineering Otto-Hahn-Str. 14 / Room 237 44227 Dortmund, Germany e-mail: til...@cs... phone: +49(231)755-7706 fax: +49(231)755-7740 web: http://ls11-www.cs.uni-dortmund.de/staff/schaefer pgp: https://keyserver2.pgp.com/vkd/SubmitSearch.event?&&SearchCriteria=0xD84DED79 |
From: Shamshad A. <sha...@gm...> - 2014-04-07 17:33:50
|
--Method Modified in copy of DefaultRowSorter available java swing library-- sort() : replaced Arrays.sort(viewToModel) with sort(table.getSelectedRows()); sortExistingData() : again replaced Arrays.sort(viewToModel) with sort(table.getSelectedRows()); //--Method Added private void sort(int[] selected) { if (selected.length != 0) { Row[] selectedRows = new Row[selected.length]; Row[] remaining = new Row[viewToModel.length - selected.length]; int k = 0; int lastSelectedIndex = selected[selected.length - 1]; for (int i = 0, j = 0; i <= lastSelectedIndex; i++) { if (selected[j] == i) { selectedRows[j++] = viewToModel[i]; } else { remaining[k++] = viewToModel[i]; } } System.arraycopy(viewToModel, lastSelectedIndex + 1, remaining, k, viewToModel.length - lastSelectedIndex - 1); Arrays.sort(selectedRows); Arrays.sort(remaining); System.arraycopy(selectedRows, 0, viewToModel, 0, selectedRows.length); System.arraycopy(remaining, 0, viewToModel, selectedRows.length, remaining.length); } else { Arrays.sort(viewToModel); } } --Everything else is a copy of DefaultRowSorter and TableRowSorter implementation available in java swing-- |