DuaList SelectedList wont work properly if we sort the items

This forum is used by users to request and discuss new product features. Please do not use this forum for technical support including bug reports.

Moderator: JIDE Support

Forum rules
Product suggestions only. Please do not use this forum for technical support including bug reports.

DuaList SelectedList wont work properly if we sort the items

Postby vanitha » Thu May 03, 2012 2:18 am

IF we use a DualList and select some items, Then after if we sort the items in the List(means sort the items in the listModel) then the selectedList pane wont show what we selected previously . we have to select selctionMode as REMOVE_SELECTION

For example DualList contains below items
1. Border
2.Apple
3. Cat
4.Dog

we have selected as below

OriginalList selected List
Border Apple
Cat
Daog



After we sort the List the OriginalList and selected List Looks Like below

OriginalList selected List
Apple Border
Cat
Dog


It will be great help the List API has provision to show the selected items as it is after sorting also, means getting the original index after sorting
vanitha
 
Posts: 8
Joined: Thu May 03, 2012 2:04 am

Re: DuaList SelectedList wont work properly if we sort the i

Postby JIDE Support » Thu May 03, 2012 10:10 am

May I ask how you add sorting feature inside the selected list? That will help us try to reproduce the issue on our end. A code fraction would help.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: DuaList SelectedList wont work properly if we sort the i

Postby vanitha » Thu May 03, 2012 11:04 pm

Here is my Code I have a testclass contains a dualLIst and a button to sort elemnts of duallist. I have a duallist model which containd arrayList of Elements

Code: Select all
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collections;

import javax.swing.JButton;
import javax.swing.JDialog;

import com.jidesoft.list.DualList;
import com.jidesoft.swing.JideTitledBorder;
import com.jidesoft.swing.PartialEtchedBorder;
import com.jidesoft.swing.PartialSide;

public class TestDualList extends JDialog {
   
private DualList dualList;
private DualListModel dualListModel;
private JButton sort;

public TestDualList(){
   init();
   buildDialog();
}

private void buildDialog() {
   add(dualList,BorderLayout.CENTER);
   add(sort,BorderLayout.SOUTH);
   setSize(200,200);
   setVisible(true);
   
   
}

private void init() {
dualListModel=new DualListModel();   
dualListModel.updateModel();

 dualList=new DualList(dualListModel);
 dualList.setSelectionMode(DualListModel.REMOVE_SELECTION);
 dualList.setAllowDuplicates(false);
 dualList.getOriginalListPane().setBorder(
         new JideTitledBorder(new PartialEtchedBorder(
               PartialEtchedBorder.LOWERED, PartialSide.NORTH),
               "Available FIX Tags"));
 dualList.getSelectedListPane().setBorder(
         new JideTitledBorder(new PartialEtchedBorder(
               PartialEtchedBorder.LOWERED, PartialSide.NORTH),
               "Selected FIX Tags"));
   // Make all the button invisible exceptt move right and left
 dualList.setButtonVisible(DualList.COMMAND_MOVE_UP, false);
 dualList.setButtonVisible(DualList.COMMAND_MOVE_DOWN, false);
 dualList.setButtonVisible(DualList.COMMAND_MOVE_ALL_LEFT, false);
 dualList.setButtonVisible(DualList.COMMAND_MOVE_ALL_RIGHT, false);
 dualList.setButtonVisible(DualList.COMMAND_MOVE_TO_BOTTOM, false);
 dualList.setButtonVisible(DualList.COMMAND_MOVE_TO_TOP, false);

 sort=new JButton("Sort");
 sort.addActionListener(new ActionListener() {
   
   @Override
   public void actionPerformed(ActionEvent arg0) {
      dualListModel.sortByName();
      
   }
});
 
   
}

public static void main(String args[]){
   TestDualList list=new TestDualList();
}


}



Model class
Code: Select all

import java.util.ArrayList;
import java.util.Collections;

import com.jidesoft.list.AbstractDualListModel;



public class DualListModel extends AbstractDualListModel {

   
   ArrayList<String> testElemnts = new ArrayList<String>();
   @Override
   public Object getElementAt(int index) {
      return testElemnts.get(index);
   }

   @Override
   public int getSize() {
      return testElemnts.size();
   }
   
   public void sortByName() {
      Collections.sort(testElemnts);
      fireContentsChanged(this, 0, testElemnts.size());
   }
   
   public void updateModel(){      
      testElemnts.add("Ball");
      testElemnts.add("Apple");
      testElemnts.add("Cat");
      testElemnts.add("Dog");
      testElemnts.add("COW");
      
   }

}



Testcase is like below

1) select ball from original list so that selected list contains ball
2) click on sort button
3) Now you will see Apple in the selected list(This happend because previously ball is in the index one and after sorting apple cames to index one)
vanitha
 
Posts: 8
Joined: Thu May 03, 2012 2:04 am

Re: DuaList SelectedList wont work properly if we sort the i

Postby JIDE Support » Fri May 04, 2012 10:56 am

If you sort the entire DualListModel, the model does not have any clue how it should change the selected index. After all, there is no row identifier concept that could help a model to identifies the rows.

You could give the modified test case a try to sort the selected list only. A SortableListModel is installed to help the sorting feature.

Thanks,
Attachments
TestDualList.java
(2.83 KiB) Downloaded 1826 times
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am


Return to Product Suggestions

Who is online

Users browsing this forum: No registered users and 9 guests

cron