IDEMPIERE-364 Improve Grid Layout / Refactor customizegrid, enable multi-selection and drag-drop events both sides of the list
This commit is contained in:
parent
e4c946215b
commit
9fc9c8e4f2
|
@ -131,9 +131,6 @@ public class CustomizeGridViewPanel extends Panel
|
||||||
noLabel.setValue(Msg.getMsg(Env.getCtx(), "Available"));
|
noLabel.setValue(Msg.getMsg(Env.getCtx(), "Available"));
|
||||||
yesLabel.setValue(Msg.getMsg(Env.getCtx(), "Selected"));
|
yesLabel.setValue(Msg.getMsg(Env.getCtx(), "Selected"));
|
||||||
|
|
||||||
|
|
||||||
yesList.setHeight("100%");
|
|
||||||
noList.setHeight("100%");
|
|
||||||
yesList.setVflex(true);
|
yesList.setVflex(true);
|
||||||
noList.setVflex(true);
|
noList.setVflex(true);
|
||||||
|
|
||||||
|
@ -157,8 +154,8 @@ public class CustomizeGridViewPanel extends Panel
|
||||||
migrateValueAcrossLists(event);
|
migrateValueAcrossLists(event);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
yesList.setSeltype("multiple");
|
yesModel.setMultiple(true);
|
||||||
noList.setSeltype("multiple");
|
noModel.setMultiple(true);
|
||||||
|
|
||||||
bAdd.setImage("images/Next24.png");
|
bAdd.setImage("images/Next24.png");
|
||||||
bAdd.addEventListener(Events.ON_CLICK, actionListener);
|
bAdd.addEventListener(Events.ON_CLICK, actionListener);
|
||||||
|
@ -396,14 +393,19 @@ 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;
|
||||||
SimpleListModel lmFrom = (source == bAdd || source == noList) ?
|
migrateLists (listFrom,listTo);
|
||||||
noModel : yesModel;
|
}
|
||||||
SimpleListModel lmTo = (lmFrom == yesModel) ? noModel : yesModel;
|
|
||||||
|
void migrateLists (Listbox listFrom , Listbox listTo)
|
||||||
|
{
|
||||||
|
int index = 0;
|
||||||
|
SimpleListModel lmFrom = (SimpleListModel) listFrom.getModel();
|
||||||
|
SimpleListModel lmTo = (SimpleListModel) listTo.getModel();
|
||||||
Set<?> selectedItems = listFrom.getSelectedItems();
|
Set<?> selectedItems = listFrom.getSelectedItems();
|
||||||
List<ListElement> selObjects = new ArrayList<ListElement>();
|
List<ListElement> selObjects = new ArrayList<ListElement>();
|
||||||
for (Object obj : selectedItems) {
|
for (Object obj : selectedItems) {
|
||||||
ListItem listItem = (ListItem) obj;
|
ListItem listItem = (ListItem) obj;
|
||||||
int index = listFrom.getIndexOfItem(listItem);
|
index = listFrom.getIndexOfItem(listItem);
|
||||||
ListElement selObject = (ListElement)lmFrom.getElementAt(index);
|
ListElement selObject = (ListElement)lmFrom.getElementAt(index);
|
||||||
selObjects.add(selObject);
|
selObjects.add(selObject);
|
||||||
}
|
}
|
||||||
|
@ -415,10 +417,10 @@ public class CustomizeGridViewPanel extends Panel
|
||||||
lmFrom.removeElement(selObject);
|
lmFrom.removeElement(selObject);
|
||||||
lmTo.addElement(selObject);
|
lmTo.addElement(selObject);
|
||||||
}
|
}
|
||||||
|
index = 0;
|
||||||
for (ListElement selObject : selObjects)
|
for (ListElement selObject : selObjects)
|
||||||
{
|
{
|
||||||
int index = lmTo.indexOf(selObject);
|
index = lmTo.indexOf(selObject);
|
||||||
listTo.setSelectedIndex(index);
|
listTo.setSelectedIndex(index);
|
||||||
}
|
}
|
||||||
if ( listTo.getSelectedItem() != null)
|
if ( listTo.getSelectedItem() != null)
|
||||||
|
@ -426,8 +428,7 @@ public class CustomizeGridViewPanel extends Panel
|
||||||
AuFocus focus = new AuFocus(listTo.getSelectedItem());
|
AuFocus focus = new AuFocus(listTo.getSelectedItem());
|
||||||
Clients.response(focus);
|
Clients.response(focus);
|
||||||
}
|
}
|
||||||
} // migrateValueAcrossLists
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move within Yes List
|
* Move within Yes List
|
||||||
|
@ -667,29 +668,14 @@ public class CustomizeGridViewPanel extends Panel
|
||||||
if (event instanceof DropEvent)
|
if (event instanceof DropEvent)
|
||||||
{
|
{
|
||||||
DropEvent me = (DropEvent) event;
|
DropEvent me = (DropEvent) event;
|
||||||
|
|
||||||
ListItem endItem = (ListItem) me.getTarget();
|
ListItem endItem = (ListItem) me.getTarget();
|
||||||
if (!(endItem.getListbox() == yesList))
|
|
||||||
{
|
|
||||||
return; // move within noList
|
|
||||||
}
|
|
||||||
|
|
||||||
ListItem startItem = (ListItem) me.getDragged();
|
ListItem startItem = (ListItem) me.getDragged();
|
||||||
if (startItem.getListbox() == endItem.getListbox())
|
if (!(startItem.getListbox() == endItem.getListbox()))
|
||||||
{
|
{
|
||||||
return; //move within same list
|
Listbox listFrom = (Listbox)startItem.getListbox();
|
||||||
|
Listbox listTo = (Listbox)endItem.getListbox();
|
||||||
|
migrateLists (listFrom,listTo);
|
||||||
}
|
}
|
||||||
int startIndex = noList.getIndexOfItem(startItem);
|
|
||||||
Object element = noModel.getElementAt(startIndex);
|
|
||||||
noModel.removeElement(element);
|
|
||||||
int endIndex = yesList.getIndexOfItem(endItem);
|
|
||||||
yesModel.add(endIndex, element);
|
|
||||||
//
|
|
||||||
noList.clearSelection();
|
|
||||||
yesList.clearSelection();
|
|
||||||
|
|
||||||
yesList.setSelectedIndex(endIndex);
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue