IDEMPIERE-364 Improve Grid Layout / Refactor customizegrid, enable multi-selection and drag-drop events both sides of the list

This commit is contained in:
Juan David Arboleda 2012-12-11 19:57:48 -05:00
parent 5662475b92
commit 6c06ec9f47
1 changed files with 51 additions and 45 deletions

View File

@ -186,35 +186,6 @@ public class CustomizeGridViewPanel extends Panel
bDown.setImage("images/Detail24.png"); bDown.setImage("images/Detail24.png");
bDown.addEventListener(Events.ON_CLICK, actionListener); bDown.addEventListener(Events.ON_CLICK, actionListener);
EventListener<Event> yesListMouseMotionListener = new EventListener<Event>()
{
public void onEvent(Event event) throws Exception {
if (event instanceof DropEvent)
{
DropEvent me = (DropEvent) event;
ListItem startItem = (ListItem) me.getDragged();
ListItem endItem = (ListItem) me.getTarget();
if (startItem.getListbox() == endItem.getListbox() && startItem.getListbox() == yesList)
{
int startIndex = yesList.getIndexOfItem(startItem);
int endIndex = yesList.getIndexOfItem(endItem);
Object endElement = yesModel.getElementAt(endIndex);
Object element = yesModel.getElementAt(startIndex);
yesModel.removeElement(element);
endIndex = yesModel.indexOf(endElement);
yesModel.add(endIndex, element);
yesList.setSelectedIndex(endIndex);
if ( yesList.getSelectedItem() != null)
{
AuFocus focus = new AuFocus(yesList.getSelectedItem());
Clients.response(focus);
}
}
}
}
};
yesList.addOnDropListener(yesListMouseMotionListener);
ListHead listHead = new ListHead(); ListHead listHead = new ListHead();
listHead.setParent(yesList); listHead.setParent(yesList);
ListHeader listHeader = new ListHeader(); ListHeader listHeader = new ListHeader();
@ -397,10 +368,15 @@ public class CustomizeGridViewPanel extends Panel
} }
Listbox listFrom = (source == bAdd || source == noList) ? noList : yesList; Listbox listFrom = (source == bAdd || source == noList) ? noList : yesList;
Listbox listTo = (source == bAdd || source == noList) ? yesList : noList; Listbox listTo = (source == bAdd || source == noList) ? yesList : noList;
migrateLists (listFrom,listTo); int endIndex = yesList.getIndexOfItem(listTo.getSelectedItem());
//Listto is empty.
if (endIndex<0 )
endIndex=0;
migrateLists (listFrom,listTo,endIndex);
} }
void migrateLists (Listbox listFrom , Listbox listTo) void migrateLists (Listbox listFrom , Listbox listTo , int endIndex )
{ {
int index = 0; int index = 0;
SimpleListModel lmFrom = (SimpleListModel) listFrom.getModel(); SimpleListModel lmFrom = (SimpleListModel) listFrom.getModel();
@ -419,21 +395,32 @@ public class CustomizeGridViewPanel extends Panel
continue; continue;
lmFrom.removeElement(selObject); lmFrom.removeElement(selObject);
lmTo.addElement(selObject); lmTo.add(endIndex, selObject);
} endIndex++;
index = 0;
for (ListElement selObject : selObjects)
{
index = lmTo.indexOf(selObject); index = lmTo.indexOf(selObject);
listTo.setSelectedIndex(index); listTo.setSelectedIndex(index);
} }
if ( listTo.getSelectedItem() != null)
{
AuFocus focus = new AuFocus(listTo.getSelectedItem());
Clients.response(focus);
}
} }
/**
* Move within Yes List with Drag Event and Multiple Choice
* @param event event
*/
void migrateValueWithinYesList (int endIndex, List<ListElement> selObjects)
{
int length = selObjects.size();
int iniIndex =0;
Arrays.sort(selObjects.toArray());
ListElement endObject = (ListElement)yesModel.getElementAt(endIndex);
for (int i = 0; i < length; i++) {
iniIndex = yesModel.indexOf(selObjects.get(i));
ListElement selObject = (ListElement)yesModel.getElementAt(iniIndex);
yesModel.removeElement(selObject);
endIndex = yesModel.indexOf(endObject);
yesModel.add(endIndex, selObject);
}
}
/** /**
* Move within Yes List * Move within Yes List
* @param event event * @param event event
@ -672,14 +659,33 @@ public class CustomizeGridViewPanel extends Panel
public void onEvent(Event event) throws Exception { public void onEvent(Event event) throws Exception {
if (event instanceof DropEvent) if (event instanceof DropEvent)
{ {
int endIndex = 0;
DropEvent me = (DropEvent) event; DropEvent me = (DropEvent) event;
ListItem endItem = (ListItem) me.getTarget(); ListItem endItem = (ListItem) me.getTarget();
ListItem startItem = (ListItem) me.getDragged(); ListItem startItem = (ListItem) me.getDragged();
if (!startItem.isSelected())
startItem.setSelected(true);
if (!(startItem.getListbox() == endItem.getListbox())) if (!(startItem.getListbox() == endItem.getListbox()))
{ {
Listbox listFrom = (Listbox)startItem.getListbox(); Listbox listFrom = (Listbox)startItem.getListbox();
Listbox listTo = (Listbox)endItem.getListbox(); Listbox listTo = (Listbox)endItem.getListbox();
migrateLists (listFrom,listTo); endIndex = yesList.getIndexOfItem(endItem);
migrateLists (listFrom,listTo,endIndex);
}else if (startItem.getListbox() == endItem.getListbox() && startItem.getListbox() == yesList)
{
List<ListElement> selObjects = new ArrayList<ListElement>();
endIndex = yesList.getIndexOfItem(endItem);
for (Object obj : yesList.getSelectedItems()) {
ListItem listItem = (ListItem) obj;
int index = yesList.getIndexOfItem(listItem);
ListElement selObject = (ListElement)yesModel.getElementAt(index);
selObjects.add(selObject);
}
migrateValueWithinYesList (endIndex, selObjects);
yesList.clearSelection();
} }
} }
} }