[Logo] Enterprise Client Community
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Resort () a Grid  XML
Forum Index -> Development
Author Message
unger

Power User

Joined: 22/07/2008 05:19:28
Messages: 261
Offline

Hello,

overloading FIXGRIDListBinding<ItemClass> with a resort method.

I call resort () directly in caller method,, after building the grid (items), but grid isn't presented sorted.

Code:
 public class FIXGRIDListBindingExtended<ItemClass extends FIXGRIDItem> extends FIXGRIDListBinding<ItemClass> {
 
 	private static final long serialVersionUID = 1L;
 	private String sortReference = null;
 	// private String objectBindingString = null;
 	private boolean ascending = true;
 	private Comparator<FIXGRIDItem> comparator = null;
 
 	public FIXGRIDListBindingExtended() {
 		super();
 	}
 
 	public FIXGRIDListBindingExtended(Comparator<FIXGRIDItem> comparator) {
 		super();
 		this.comparator = comparator;
 	}
 
 	public FIXGRIDListBindingExtended(boolean changeIndexIsSupported) {
 		super(changeIndexIsSupported);
 	}
 
 	public void reSort() {
 		if (sortReference != null)
 			super.sort(sortReference, ascending);
 		else
 			sortByDefault();
 	}
 
 	public void resetSorting() {
 		sortReference = null;
 	}
 
 	private void sortByDefault() {
 		// Vorsicht: Selektion geht verloren???
 		Set<ItemClass> selectedItems = getSelectedItems();
 		if (comparator != null)
 			Collections.sort(getItems(), comparator);
 
 		System.out.println("\nSort");
 		for (ItemClass item : getItems()) {
 			if (item instanceof ConnectListItem) {
 				ConnectListItem item1 = (ConnectListItem) item;
 				if (item1.getObject() instanceof Produkt) {
 					Produkt prod1 = (Produkt) item1.getObject();
 					Spezifikation spez1 = prod1.getAktProduktSpezifikation().getSpezifikation();
 
 					System.out.println("Z:" + spez1.getZeichnungsNummer());
 				}
 			}
 		}
 		for (ItemClass item : selectedItems)
 			selectItem(item, false); 
 	}
 
 	@Override
 	/*
 	 * Methode wird aufgerufen beim Sortieren durch Header-Click
 	 */
 	protected void sortGrid(String sortReference, String objectBindingString, boolean ascending) {
 		System.out.println("\nSortGrid");
 		this.sortReference = sortReference;
 		// this.objectBindingString = objectBindingString;
 		this.ascending = ascending;
 		super.sortGrid(sortReference, objectBindingString, ascending);
 	}
 
 }


What is wrong?

Regards,
Joachim
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5510
Offline

Hi Joachim,

please check demo "Grid & Trees => Sorting => Initial Sorting" in the demo workplace.

The initial sorting needs to be done within the initialize method of the FIXGRIDListBinding.

The initialize() method is called when the actual server-side FIXGRID-component is "connecting" to the FIXGRIDListBinding instance (in means of using it by API).

Kind regards, Björn

Björn Müller, CaptainCasa GmbH
unger

Power User

Joined: 22/07/2008 05:19:28
Messages: 261
Offline

Hi Björn,

thank You. The question is more about a direct call to resort (), not how an initial sort works. So Collections.sort (getItems (), comparator); is executed, but the sort result is not what we expected. I'm building a test case for it.

Regards,
Joachim
unger

Power User

Joined: 22/07/2008 05:19:28
Messages: 261
Offline

Code:
 private void sortByDefault() {
 	if (comparator != null) {
 		ArrayList<ItemClass> itemList = new ArrayList<>(getItems());
 		getItems().clear();
 
 		Collections.sort(itemList, comparator);
 		getItems().addAll(itemList);
 	}
 }
 


This code works.
May be Collections.sort(getItems(), comparator); leaves the list untouched, so no redraw was done.

 
Forum Index -> Development
Go to:   
Powered by JForum 2.1.6 © JForum Team