IDEMPIERE-379 Reporting wizard for end users / Refactor

This commit is contained in:
Juan David Arboleda 2012-12-17 18:19:21 -05:00
parent bbba2cdd72
commit 7516e37f1f
7 changed files with 322 additions and 322 deletions

View File

@ -16,6 +16,7 @@ package org.adempiere.webui.apps.form;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
@ -82,7 +83,7 @@ public class WReportCustomization implements IFormController,EventListener<Even
private boolean m_isCanExport; private boolean m_isCanExport;
private ReportEngine m_reportEngine=null; private ReportEngine m_reportEngine=null;
public MPrintFormatItem[] pfi ; public ArrayList<MPrintFormatItem> pfi ;
private Auxheader headerPanel=new Auxheader(); private Auxheader headerPanel=new Auxheader();
private Listbox comboReport = new Listbox(); private Listbox comboReport = new Listbox();
@ -140,7 +141,11 @@ public class WReportCustomization implements IFormController,EventListener<Even
m_reportEngine = re; m_reportEngine = re;
m_isCanExport=MRole.getDefault().isCanExport(); m_isCanExport=MRole.getDefault().isCanExport();
pfi= m_reportEngine.getPrintFormat().getAllItems("IsPrinted DESC, NULLIF(SeqNo,0), Name"); pfi = new ArrayList<MPrintFormatItem>() ;
for (MPrintFormatItem item : m_reportEngine.getPrintFormat().getAllItems("IsPrinted DESC, NULLIF(SeqNo,0), Name")) {
pfi.add(item);
}
try try
{ {
m_ctx = m_reportEngine.getCtx(); m_ctx = m_reportEngine.getCtx();
@ -229,6 +234,7 @@ public class WReportCustomization implements IFormController,EventListener<Even
tpsc3.setMPrintFormat(fm); tpsc3.setMPrintFormat(fm);
tpsc3.setPrintFormatItems(pfi); tpsc3.setPrintFormatItems(pfi);
tpsc3.setListsColumns();
tpsc3.init(); tpsc3.init();
tpsc3.refresh(); tpsc3.refresh();
tpsc3.setWReportCustomization(this); tpsc3.setWReportCustomization(this);
@ -359,10 +365,12 @@ public class WReportCustomization implements IFormController,EventListener<Even
} }
private void onSave() { private void onSave() {
for (int i=0; i < pfi.length ;i++){
pfi[i].saveEx(); for (MPrintFormatItem item : pfi)
} if (item.is_Changed())
setIsChanged(false); item.saveEx();
setIsChanged(false);
} }
@Override @Override
@ -519,8 +527,10 @@ public class WReportCustomization implements IFormController,EventListener<Even
public void copyFormat(){ public void copyFormat(){
MPrintFormat newpf=MPrintFormat.copyToClient(m_ctx, m_reportEngine.getPrintFormat().get_ID() ,Env.getAD_Client_ID(m_ctx)); MPrintFormat newpf=MPrintFormat.copyToClient(m_ctx, m_reportEngine.getPrintFormat().get_ID() ,Env.getAD_Client_ID(m_ctx));
pfi = newpf.getAllItems("IsPrinted DESC, NULLIF(SeqNo,0), Name");
for (MPrintFormatItem item : newpf.getAllItems("IsPrinted DESC, NULLIF(SeqNo,0), Name"))
pfi.add(item);
tpdf1.setMPrintFormat(newpf); tpdf1.setMPrintFormat(newpf);
tpdf1.setPrintFormatItems(pfi); tpdf1.setPrintFormatItems(pfi);
tpdf1.refresh(); tpdf1.refresh();
@ -532,6 +542,7 @@ public class WReportCustomization implements IFormController,EventListener<Even
tpsc3.setMPrintFormat(newpf); tpsc3.setMPrintFormat(newpf);
tpsc3.setPrintFormatItems(pfi); tpsc3.setPrintFormatItems(pfi);
tpfo2.setListColumns();
tpsc3.refresh(); tpsc3.refresh();
tpgc4.setMPrintFormat(newpf); tpgc4.setMPrintFormat(newpf);

View File

@ -23,6 +23,7 @@ import org.adempiere.webui.component.Rows;
import org.adempiere.webui.component.Textbox; import org.adempiere.webui.component.Textbox;
import org.adempiere.webui.component.Window; import org.adempiere.webui.component.Window;
import org.compiere.print.MPrintFormat; import org.compiere.print.MPrintFormat;
import org.compiere.print.MPrintFormatItem;
import org.compiere.util.KeyNamePair; import org.compiere.util.KeyNamePair;
import org.compiere.util.Util; import org.compiere.util.Util;
import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Event;
@ -59,9 +60,9 @@ public class WRC1DisplayFieldsPanel extends WRCTabPanel implements EventListener
public void init() { public void init() {
m_chkboxes = new Checkbox[m_pfi.length]; m_chkboxes = new Checkbox[m_pfi.size()];
m_textBoxes = new Textbox[m_pfi.length]; m_textBoxes = new Textbox[m_pfi.size()];
m_oldLabel = new String[m_pfi.length]; m_oldLabel = new String[m_pfi.size()];
Window wind=new Window(); Window wind=new Window();
wind.setWidth("90%"); wind.setWidth("90%");
@ -99,20 +100,21 @@ public class WRC1DisplayFieldsPanel extends WRCTabPanel implements EventListener
int curCol=0; int curCol=0;
Rows rows = grid.newRows(); Rows rows = grid.newRows();
org.zkoss.zul.Row row = null; org.zkoss.zul.Row row = null;
for(int i=0;i<m_pfi.length;i++){ int i=0;
for (MPrintFormatItem printItem : m_pfi){
if(curCol==0){ if(curCol==0){
row = new Row(); row = new Row();
rows.appendChild(row); rows.appendChild(row);
} }
m_chkboxes[i] = new Checkbox(); m_chkboxes[i] = new Checkbox();
m_chkboxes[i].setChecked(m_pfi[i].isPrinted()); m_chkboxes[i].setChecked(printItem.isPrinted());
m_chkboxes[i].addEventListener(Events.ON_CHECK,this); m_chkboxes[i].addEventListener(Events.ON_CHECK,this);
row.appendChild(m_chkboxes[i]); row.appendChild(m_chkboxes[i]);
m_textBoxes[i] = new Textbox(); m_textBoxes[i] = new Textbox();
String strValue = m_pfi[i].getPrintName(); String strValue = printItem.getPrintName();
if(strValue ==null || strValue.length()==0){ if(strValue ==null || strValue.length()==0){
strValue = m_pfi[i].getName(); strValue = printItem.getName();
} }
m_oldLabel[i] = strValue; m_oldLabel[i] = strValue;
m_textBoxes[i].setText(strValue); m_textBoxes[i].setText(strValue);
@ -120,26 +122,26 @@ public class WRC1DisplayFieldsPanel extends WRCTabPanel implements EventListener
row.appendChild(m_textBoxes[i]); row.appendChild(m_textBoxes[i]);
curCol++; curCol++;
i++;
curCol = curCol%RENDER_IN_COLUMNS; curCol = curCol%RENDER_IN_COLUMNS;
} }
} }
public void save(){ public void save(){
for(int i=0;i<m_pfi.length;i++){ int i=0;
m_pfi[i].setIsActive(m_chkboxes[i].isChecked()); for (MPrintFormatItem item : m_pfi){
m_pfi[i].setPrintName(m_textBoxes[i].getText()); item.setIsActive(m_chkboxes[i].isChecked());
m_pfi[i].saveEx(); item.setPrintName(m_textBoxes[i].getText());
} item.saveEx();
i++;
}
} }
public KeyNamePair[] getChecked(){ public KeyNamePair[] getChecked(){
KeyNamePair [] listcheck=new KeyNamePair[m_pfi.length]; KeyNamePair [] listcheck=new KeyNamePair[m_pfi.size()];
for(int i=0;i<m_chkboxes.length;i++){ for(int i=0;i<m_chkboxes.length;i++){
if(m_chkboxes[i].isChecked()){ if(m_chkboxes[i].isChecked()){
int ID=m_pfi[i].get_ID(); listcheck[i]= new KeyNamePair(m_pfi.get(i).get_ID(),m_pfi.get(i).getName());
String name=m_pfi[i].getName();
KeyNamePair pair=new KeyNamePair(ID, name);
listcheck[i]=pair;
} }
} }
@ -148,8 +150,8 @@ public class WRC1DisplayFieldsPanel extends WRCTabPanel implements EventListener
@Override @Override
public void refresh() { public void refresh() {
for (int i=0 ; i< m_pfi.length ; i++){ for (int i=0 ; i< m_pfi.size(); i++){
m_chkboxes[i].setChecked(m_pfi[i].isPrinted()); m_chkboxes[i].setChecked(m_pfi.get(i).isPrinted());
} }
} }
@ -157,21 +159,21 @@ public class WRC1DisplayFieldsPanel extends WRCTabPanel implements EventListener
public void updatePFI() { public void updatePFI() {
for (int i=0 ;i < m_chkboxes.length ;i++){ for (int i=0 ;i < m_chkboxes.length ;i++){
if(m_chkboxes[i].isChecked()){ if(m_chkboxes[i].isChecked()){
m_pfi[i].setIsPrinted(true); m_pfi.get(i).setIsPrinted(true);
} }
else{ else{
m_pfi[i].setIsPrinted(false); m_pfi.get(i).setIsPrinted(false);
} }
String printname = m_textBoxes[i].getValue(); String printname = m_textBoxes[i].getValue();
if (!Util.isEmpty(printname)) if (!Util.isEmpty(printname))
if (! printname.equals(m_pfi[i].getPrintName())) if (! printname.equals(m_pfi.get(i).getPrintName()))
m_pfi[i].setPrintName(m_textBoxes[i].getValue()); m_pfi.get(i).setPrintName(m_textBoxes[i].getValue());
} }
} }
public void updatePrinted(boolean value){ public void updatePrinted(boolean value){
for(int j=0 ; j< m_pfi.length ; j++){ for(int j=0 ; j< m_pfi.size() ; j++){
m_pfi[j].setIsPrinted(value); m_pfi.get(j).setIsPrinted(value);
m_chkboxes[j].setChecked(value); m_chkboxes[j].setChecked(value);
} }
} }

View File

@ -15,8 +15,10 @@
package org.adempiere.webui.panel; package org.adempiere.webui.panel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List;
import org.adempiere.webui.component.Button; import org.adempiere.webui.component.Button;
import org.adempiere.webui.component.ListHead; import org.adempiere.webui.component.ListHead;
@ -46,12 +48,12 @@ public class WRC2FieldOrderPanel extends WRCTabPanel implements EventListener<Ev
/** /**
* *
*/ */
private Listbox sortList;
private Button bUp = new Button(); private Button bUp = new Button();
private Button bDown = new Button(); private Button bDown = new Button();
private ArrayList<MPrintFormatItem> listColumns=new ArrayList<MPrintFormatItem>(); private ArrayList<MPrintFormatItem> listColumns=new ArrayList<MPrintFormatItem>();
SimpleListModel sortModel; SimpleListModel sortModel;
private Listbox sortList;
public WRC2FieldOrderPanel() { public WRC2FieldOrderPanel() {
super(); super();
@ -59,13 +61,9 @@ public class WRC2FieldOrderPanel extends WRCTabPanel implements EventListener<Ev
public void setListColumns() { public void setListColumns() {
listColumns = new ArrayList<MPrintFormatItem>(); listColumns = new ArrayList<MPrintFormatItem>();
if (m_pfi != null && m_pfi.length > 0) { for (MPrintFormatItem item : m_pfi)
for (int i = 0; i < m_pfi.length; i++) { if(item!=null && item.isPrinted())
if (m_pfi[i] != null && m_pfi[i].isPrinted()) { listColumns.add(item);
listColumns.add(m_pfi[i]);
}
}
}
} }
public void init() public void init()
@ -100,37 +98,21 @@ public class WRC2FieldOrderPanel extends WRCTabPanel implements EventListener<Ev
ListItem targetItem = (ListItem) me.getTarget(); ListItem targetItem = (ListItem) me.getTarget();
if (draggedItem.getListbox() == targetItem.getListbox() && draggedItem.getListbox() == sortList) if (draggedItem.getListbox() == targetItem.getListbox() && draggedItem.getListbox() == sortList)
{ {
int draggedIndex = sortList.getIndexOfItem(draggedItem); List<ListElement> selObjects = new ArrayList<ListElement>();
int targetIndex = sortList.getIndexOfItem(targetItem); int targetIndex = sortList.getIndexOfItem(targetItem);
ListElement targetElement = (ListElement) sortModel.getElementAt(targetIndex);
ListElement draggedElement = (ListElement) sortModel.getElementAt(draggedIndex); if (!draggedItem.isSelected())
draggedItem.setSelected(true);
int firstposition=0, secondposition=0;
MPrintFormatItem targetPFI = null;
MPrintFormatItem draggedPFI = null;
for(int j=0 ;j <m_pfi.length ;j++){
if(m_pfi[j].get_ID() == targetElement.getKey()){
targetPFI = m_pfi[j];
firstposition=j;
}
if(m_pfi[j].get_ID() == draggedElement.getKey()){
draggedPFI = m_pfi[j];
secondposition=j;
}
}
draggedPFI.setSeqNo(targetPFI.getSeqNo()-5);
MPrintFormatItem fi=m_pfi[firstposition];
m_pfi[firstposition]=m_pfi[secondposition];
m_pfi[secondposition]=fi;
sortModel.removeElement(draggedElement);
targetIndex = sortModel.indexOf(targetElement);
sortModel.add(targetIndex, draggedElement);
for (Object obj : sortList.getSelectedItems()) {
ListItem listItem = (ListItem) obj;
int index = sortList.getIndexOfItem(listItem);
ListElement selObject = (ListElement)sortModel.getElementAt(index);
selObjects.add(selObject);
}
migrateValueWithinYesList (targetIndex, selObjects);
wc.setIsChanged(true); wc.setIsChanged(true);
refresh(); refresh();
sortList.setSelectedIndex(targetIndex);
if ( sortList.getSelectedItem() != null) if ( sortList.getSelectedItem() != null)
{ {
AuFocus focus = new AuFocus(sortList.getSelectedItem()); AuFocus focus = new AuFocus(sortList.getSelectedItem());
@ -168,12 +150,38 @@ public class WRC2FieldOrderPanel extends WRCTabPanel implements EventListener<Ev
vbox.appendChild(bDown); vbox.appendChild(bDown);
vbox.setWidth("50px"); vbox.setWidth("50px");
vbox.setHflex("60"); vbox.setHflex("60");
//vbox.setParent(wind);
hlayout.appendChild(vbox); hlayout.appendChild(vbox);
this.appendChild(hlayout); this.appendChild(hlayout);
} }
/**
* Move within Yes List with Drag Event and Multiple Choice
* @param event event
*/
void migrateValueWithinYesList (int endIndex, List<ListElement> selObjects)
{
int iniIndex =0;
Arrays.sort(selObjects.toArray());
ListElement selObject= null;
ListElement endObject = (ListElement)sortModel.getElementAt(endIndex);
int targetPFISeq = 0;
MPrintFormatItem draggedPFI = null;
for (ListElement selected : selObjects) {
iniIndex = sortModel.indexOf(selected);
selObject = (ListElement)sortModel.getElementAt(iniIndex);
draggedPFI =listColumns.get(iniIndex);
sortModel.removeElement(selObject);
listColumns.remove(draggedPFI);
endIndex = sortModel.indexOf(endObject);
targetPFISeq = listColumns.get(endIndex).getSeqNo();
listColumns.add(endIndex, draggedPFI);
sortModel.add(endIndex, selObject);
draggedPFI.setSeqNo(targetPFISeq - 5);
}
}
@Override @Override
public void onEvent(Event event) throws Exception { public void onEvent(Event event) throws Exception {
@ -194,26 +202,15 @@ public class WRC2FieldOrderPanel extends WRCTabPanel implements EventListener<Ev
if (listColumns.size() > 0 && listColumns != null) { if (listColumns.size() > 0 && listColumns != null) {
int seq = 10; int seq = 10;
sortModel.removeAllElements(); sortModel.removeAllElements();
for (int i=0; i<listColumns.size(); i++) { for (MPrintFormatItem pfi : listColumns){
MPrintFormatItem pfi = listColumns.get(i); pfi.setSeqNo(seq);
if (pfi != null) { m_pfi.get(m_pfi.indexOf(pfi)).setSeqNo(seq);
pfi.setSeqNo(seq); String name= pfi.getPrintName()== null ? pfi.getName(): pfi.getPrintName() ;
for(int j=0 ;j<m_pfi.length;j++){ ListElement element =new ListElement(pfi.get_ID(), name, pfi.getSeqNo(), pfi.getAD_Client_ID(), pfi.getAD_Org_ID());
if(m_pfi[j].get_ID()== pfi.get_ID()){ sortModel.addElement(element);
m_pfi[j].setSeqNo(seq); sortList.addItem(new KeyNamePair(m_pfi.get(m_pfi.indexOf(pfi)).get_ID(), name));
} seq = seq + 10;
} }
seq = seq + 10;
int ID = pfi.get_ID();
String name=pfi.getPrintName();
if(name == null)
name=pfi.getName();
ListElement element =new ListElement(ID, name, pfi.getSeqNo(), pfi.getAD_Client_ID(), pfi.getAD_Org_ID());
sortModel.addElement(element);
KeyNamePair pair=new KeyNamePair(ID, name);
sortList.addItem(pair);
}
}
} }
} }
@ -236,9 +233,8 @@ public class WRC2FieldOrderPanel extends WRCTabPanel implements EventListener<Ev
return; return;
// //
int[] indices = sortList.getSelectedIndices(); int[] indices = sortList.getSelectedIndices();
int firstposition=0, secondposition=0;
boolean change = false; boolean change = false;
// MPrintFormatItem orig = null;
Object source = event.getTarget(); Object source = event.getTarget();
if (source == bUp) if (source == bUp)
{ {
@ -246,26 +242,19 @@ public class WRC2FieldOrderPanel extends WRCTabPanel implements EventListener<Ev
int index = indices[i]; int index = indices[i];
if (index == 0) if (index == 0)
break; break;
ListElement selObject = (ListElement) sortModel.getElementAt(index); ListElement selObject = (ListElement) sortModel.getElementAt(index);
ListElement newObject = (ListElement)sortModel.getElementAt(index - 1); ListElement newObject = (ListElement)sortModel.getElementAt(index - 1);
sortModel.setElementAt(newObject, index); sortModel.setElementAt(newObject, index);
sortModel.setElementAt(selObject, index - 1); sortModel.setElementAt(selObject, index - 1);
for(int j=0 ;j <m_pfi.length ;j++){
if(m_pfi[j].get_ID() == selObject.getKey()){ listColumns.get(index).setSeqNo(listColumns.get(index).getSeqNo()-10);
m_pfi[j].setSeqNo(m_pfi[j].getSeqNo()-10); orig = listColumns.get(index);
firstposition=j; listColumns.get(index - 1).setSeqNo(listColumns.get(index - 1).getSeqNo()+10);
} listColumns.set(index, listColumns.get(index-1));
if(m_pfi[j].get_ID() == newObject.getKey()){ listColumns.set(index-1 , orig);
m_pfi[j].setSeqNo(m_pfi[j].getSeqNo()+10);
secondposition=j;
}
}
indices[i] = index - 1; indices[i] = index - 1;
change = true; change = true;
MPrintFormatItem fi=m_pfi[firstposition];
m_pfi[firstposition]=m_pfi[secondposition];
m_pfi[secondposition]=fi;
} }
} // up } // up
@ -277,36 +266,24 @@ public class WRC2FieldOrderPanel extends WRCTabPanel implements EventListener<Ev
break; break;
ListElement selObject = (ListElement) sortModel.getElementAt(index); ListElement selObject = (ListElement) sortModel.getElementAt(index);
ListElement newObject = (ListElement)sortModel.getElementAt(index + 1); ListElement newObject = (ListElement)sortModel.getElementAt(index + 1);
/*if (!selObject.isUpdateable() || !newObject.isUpdateable())
break;*/
sortModel.setElementAt(newObject, index); sortModel.setElementAt(newObject, index);
sortModel.setElementAt(selObject, index + 1); sortModel.setElementAt(selObject, index + 1);
sortList.setSelectedIndex(index + 1); //
for(int j=0 ;j <m_pfi.length ;j++){ listColumns.get(index).setSeqNo(listColumns.get(index).getSeqNo()+10);
if(m_pfi[j].get_ID() == selObject.getKey()){ orig = m_pfi.get(index);
m_pfi[j].setSeqNo(m_pfi[j].getSeqNo()+10); listColumns.get(index + 1).setSeqNo(listColumns.get(index + 1).getSeqNo()-10);
firstposition=j; listColumns.set(index, listColumns.get(index+1));
} listColumns.set(index+1,orig);
if(m_pfi[j].get_ID() == newObject.getKey()){
m_pfi[j].setSeqNo(m_pfi[j].getSeqNo()-10);
secondposition=j;
}
}
indices[i] = index + 1; indices[i] = index + 1;
change = true; change = true;
MPrintFormatItem fi=m_pfi[firstposition];
m_pfi[firstposition]=m_pfi[secondposition];
m_pfi[secondposition]=fi;
} }
} // down } // down
//
if (change) { if (change) {
sortList.setSelectedIndices(indices); sortList.setSelectedIndices(indices);
int idx = sortList.getSelectedIndex();
refresh(); refresh();
wc.setIsChanged(true); wc.setIsChanged(true);
sortList.setSelectedIndex(idx);
if ( sortList.getSelectedItem() != null) if ( sortList.getSelectedItem() != null)
{ {
AuFocus focus = new AuFocus(sortList.getSelectedItem()); AuFocus focus = new AuFocus(sortList.getSelectedItem());

View File

@ -15,6 +15,7 @@
package org.adempiere.webui.panel; package org.adempiere.webui.panel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
@ -37,6 +38,7 @@ import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.util.Clients; import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Hlayout; import org.zkoss.zul.Hlayout;
import org.zkoss.zul.Vbox; import org.zkoss.zul.Vbox;
public class WRC3SortCriteriaPanel extends WRCTabPanel implements EventListener<Event> public class WRC3SortCriteriaPanel extends WRCTabPanel implements EventListener<Event>
@ -53,15 +55,13 @@ public class WRC3SortCriteriaPanel extends WRCTabPanel implements EventListener
private Button bRemove = new Button(); private Button bRemove = new Button();
private Button bUp = new Button(); private Button bUp = new Button();
private Button bDown = new Button(); private Button bDown = new Button();
public ArrayList<MPrintFormatItem> yesItems=new ArrayList<MPrintFormatItem>();
public ArrayList<MPrintFormatItem> noItems=new ArrayList<MPrintFormatItem>();
// //
SimpleListModel noModel = new SimpleListModel(); SimpleListModel noModel = new SimpleListModel();
SimpleListModel yesModel = new SimpleListModel(); SimpleListModel yesModel = new SimpleListModel();
Listbox noList = new Listbox(); Listbox noList = new Listbox();
Listbox yesList = new Listbox(); Listbox yesList = new Listbox();
ArrayList<MPrintFormatItem> yesItems =new ArrayList<MPrintFormatItem>();
ArrayList<MPrintFormatItem> noItems =new ArrayList<MPrintFormatItem>();
public WRC3SortCriteriaPanel() { public WRC3SortCriteriaPanel() {
super(); super();
@ -110,59 +110,7 @@ public class WRC3SortCriteriaPanel extends WRCTabPanel implements EventListener
noList.addOnDropListener(crossListMouseListener); noList.addOnDropListener(crossListMouseListener);
yesList.setItemDraggable(true); yesList.setItemDraggable(true);
noList.setItemDraggable(true); noList.setItemDraggable(true);
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);
ListElement endElement = (ListElement) yesModel.getElementAt(endIndex);
ListElement startElement = (ListElement) yesModel.getElementAt(startIndex);
yesModel.removeElement(startElement);
endIndex = yesModel.indexOf(endElement);
yesModel.add(endIndex, startElement);
yesList.setSelectedIndex(endIndex);
int firstposition=0, secondposition=0;
MPrintFormatItem targetPFI = null;
MPrintFormatItem draggedPFI = null;
for(int j=0 ;j <m_pfi.length ;j++){
if(m_pfi[j].get_ID() == endElement.getKey()){
targetPFI = m_pfi[j];
firstposition=j;
}
if(m_pfi[j].get_ID() == startElement.getKey()){
draggedPFI = m_pfi[j];
secondposition=j;
}
}
draggedPFI.setSeqNo(targetPFI.getSeqNo()-5);
wc.setIsChanged(true);
updateYesList();
MPrintFormatItem fi=m_pfi[firstposition];
m_pfi[firstposition]=m_pfi[secondposition];
m_pfi[secondposition]=fi;
if ( yesList.getSelectedItem() != null)
{
AuFocus focus = new AuFocus(yesList.getSelectedItem());
Clients.response(focus);
}
//setIsChanged(true);
}
}
}
};
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();
@ -219,69 +167,54 @@ public class WRC3SortCriteriaPanel extends WRCTabPanel implements EventListener
public void onEvent(Event event) throws Exception { public void onEvent(Event event) throws Exception {
} }
@Override public void setListsColumns() {
public void refresh() {
yesItems =new ArrayList<MPrintFormatItem>(); yesItems =new ArrayList<MPrintFormatItem>();
noItems =new ArrayList<MPrintFormatItem>(); noItems =new ArrayList<MPrintFormatItem>();
if (m_pfi.length > 0 && m_pfi != null ) { for(int i=0 ; i< m_pfi.size();i++){
int seq = 10; MPrintFormatItem item = m_pfi.get(i);
for(int i=0 ; i < m_pfi.length ; i++ ){ if(item!=null && item.isPrinted()){
if (m_pfi[i].isPrinted() && m_pfi[i] != null) { if(item.isOrderBy()){
if (m_pfi[i].isOrderBy()) { yesItems.add(item);
m_pfi[i].setSortNo(seq); }else{
seq=seq+10; noItems.add(item);
yesItems.add(m_pfi[i]); }
} else{ }
noItems.add(m_pfi[i]);
}
}
}
} }
Collections.sort(yesItems, new Comparator<MPrintFormatItem>() { Collections.sort(yesItems, new Comparator<MPrintFormatItem>() {
@Override @Override
public int compare(MPrintFormatItem o1, MPrintFormatItem o2) { public int compare(MPrintFormatItem o1, MPrintFormatItem o2) {
return o1.getSortNo()-o2.getSortNo(); return o1.getSortNo()-o2.getSortNo();
} }
}); });
}
@Override
public void refresh() {
this.setListsColumns();
yesList.removeAllItems(); yesList.removeAllItems();
noList.removeAllItems(); noList.removeAllItems();
if (yesItems.size() > 0 && yesItems != null) { if (yesItems.size() > 0 && yesItems != null) {
yesModel.removeAllElements(); yesModel.removeAllElements();
for (int i=0 ; i < yesItems.size() ; i++) { for (int i=0 ; i < yesItems.size() ; i++) {
MPrintFormatItem pfi = yesItems.get(i); int ID= yesItems.get(i).get_ID();
if (pfi != null) { String name = yesItems.get(i).getPrintName()==null? yesItems.get(i).getName():yesItems.get(i).getPrintName();
int ID= pfi.get_ID(); yesList.addItem(new KeyNamePair(ID, name));
String name =pfi.getPrintName(); yesModel.addElement(new ListElement(ID, name, yesItems.get(i).getSortNo(), true, yesItems.get(i).getAD_Client_ID(), yesItems.get(i).getAD_Org_ID()));
if(name == null)
name=pfi.getName();
KeyNamePair pair =new KeyNamePair(ID, name);
yesList.addItem(pair);
ListElement element =new ListElement(pfi.get_ID(), pfi.getName(), pfi.getSortNo(), true, pfi.getAD_Client_ID(), pfi.getAD_Org_ID());
yesModel.addElement(element);
}
} }
} }
if (noItems.size() > 0 && noItems != null) { if (noItems.size() > 0 && noItems != null) {
noModel.removeAllElements(); noModel.removeAllElements();
for (int i=0 ; i < noItems.size() ; i++) { for (int i=0 ; i < noItems.size() ; i++) {
MPrintFormatItem pfi = noItems.get(i); int ID= noItems.get(i).get_ID();
if (pfi != null) { String name = noItems.get(i).getPrintName()== null ? noItems.get(i).getName() : noItems.get(i).getPrintName();
int ID= pfi.get_ID(); noItems.get(i).setSortNo(0);
pfi.setSortNo(0); noItems.get(i).setIsOrderBy(false);
pfi.setIsOrderBy(false); noList.addItem(new KeyNamePair(ID, name));
String name =pfi.getPrintName(); noModel.add(i,new ListElement(ID, name, noItems.get(i).getSortNo(), false, noItems.get(i).getAD_Client_ID(), noItems.get(i).getAD_Org_ID()));
if(name == null)
name=pfi.getName();
KeyNamePair pair =new KeyNamePair(ID, name);
noList.addItem(pair);
ListElement element =new ListElement(pfi.get_ID(), pfi.getName(), pfi.getSortNo(), false, pfi.getAD_Client_ID(), pfi.getAD_Org_ID());
noModel.add(i,element);
}
} }
} }
} }
@ -302,45 +235,104 @@ public class WRC3SortCriteriaPanel extends WRCTabPanel implements EventListener
} }
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) ?
noModel : yesModel; int endIndex = yesList.getIndexOfItem(listTo.getSelectedItem());
SimpleListModel lmTo = (lmFrom == yesModel) ? noModel : yesModel; //Listto is empty.
if (endIndex<0 )
endIndex=0;
migrateLists (listFrom,listTo,endIndex);
} // migrateValueAcrossLists
void migrateLists (Listbox listFrom , Listbox listTo , int endIndex)
{
int index = 0;
SimpleListModel lmFrom = (listFrom == yesList) ? yesModel:noModel;
SimpleListModel lmTo = (lmFrom == yesModel) ? noModel:yesModel;
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);
} }
index = 0;
boolean reOrder = false;
Arrays.sort(selObjects.toArray());
for (ListElement selObject : selObjects) for (ListElement selObject : selObjects)
{ {
if (selObject == null) if (selObject == null)
continue; continue;
lmFrom.removeElement(selObject); lmFrom.removeElement(selObject);
lmTo.addElement(selObject); lmTo.add(endIndex, selObject);
index = m_pfi.indexOf(getPrintFormatItem(selObject.m_key));
for (int j=0 ; j<m_pfi.length ; j++) { if(listFrom.equals(noList)) {
if (m_pfi[j].get_ID() == selObject.m_key) { m_pfi.get(index).setIsOrderBy(true);
if (listFrom.equals(noList)) { reOrder =true;
m_pfi[j].setIsOrderBy(true); }else{
} else { m_pfi.get(index).setIsOrderBy(false);
m_pfi[j].setIsOrderBy(false);
}
}
} }
wc.setIsChanged(true);
} }
if(reOrder){
int sortNo =10;
ArrayList<ListElement> pp = new ArrayList<ListElement>();
for(int i=0 ; i<lmTo.getSize(); i++) {
ListElement aux = (ListElement)lmTo.getElementAt(i);
aux.setSortNo(sortNo);
sortNo =+10;
pp.add(aux);
}
Collections.sort(pp, new Comparator<ListElement>() {
@Override
public int compare(ListElement o1, ListElement o2) {
return o1.getSortNo()-o2.getSortNo();
}
});
for(ListElement ele : pp) {
int auxIndex = m_pfi.indexOf(getPrintFormatItem(ele.m_key));
m_pfi.get(auxIndex).setSortNo(sortNo);
sortNo = sortNo + 10;
}
wc.setIsChanged(true);
}
refresh(); refresh();
if ( listTo.getSelectedItem() != null) if ( listTo.getSelectedItem() != null)
{ {
AuFocus focus = new AuFocus(listTo.getSelectedItem()); AuFocus focus = new AuFocus(listTo.getSelectedItem());
Clients.response(focus); Clients.response(focus);
} }
}
} // migrateValueAcrossLists
/**
* Move within Yes List with Drag Event and Multiple Choice
* @param event event
*/
void migrateValueWithinYesList (int endIndex, List<ListElement> selObjects)
{
int iniIndex =0;
Arrays.sort(selObjects.toArray());
ListElement selObject= null;
ListElement endObject = (ListElement)yesModel.getElementAt(endIndex);
for (ListElement selected : selObjects) {
iniIndex = yesModel.indexOf(selected);
selObject = (ListElement)yesModel.getElementAt(iniIndex);
yesModel.removeElement(selObject);
endIndex = yesModel.indexOf(endObject);
yesModel.add(endIndex, selObject);
}
int sortNo = 10;
int auxIndex =0;
yesList.removeAllItems();
for(int i=0 ; i<yesModel.getSize(); i++) {
ListElement pp = (ListElement)yesModel.getElementAt(i);
auxIndex = m_pfi.indexOf(getPrintFormatItem(pp.m_key));
m_pfi.get(auxIndex).setSortNo(sortNo);
yesList.addItem(new KeyNamePair(pp.m_key, pp.getName()));
sortNo = sortNo + 10;
}
}
/** /**
* Move within Yes List * Move within Yes List
@ -358,7 +350,8 @@ public class WRC3SortCriteriaPanel extends WRCTabPanel implements EventListener
int[] indices = yesList.getSelectedIndices(); int[] indices = yesList.getSelectedIndices();
// //
boolean change = false; boolean change = false;
// int selectedPI = 0 , targetPI = 0;
MPrintFormatItem orig = null;
Object source = event.getTarget(); Object source = event.getTarget();
if (source == bUp) if (source == bUp)
{ {
@ -371,6 +364,18 @@ public class WRC3SortCriteriaPanel extends WRCTabPanel implements EventListener
yesModel.setElementAt(newObject, index); yesModel.setElementAt(newObject, index);
yesModel.setElementAt(selObject, index - 1); yesModel.setElementAt(selObject, index - 1);
yesList.setSelectedIndex(index - 1);
selectedPI = m_pfi.indexOf(getPrintFormatItem(selObject.m_key));
targetPI = m_pfi.indexOf(getPrintFormatItem(newObject.m_key));
updateSortNo (selectedPI,targetPI);
yesItems.get(index).setSortNo(yesItems.get(index).getSortNo()-10);
orig = yesItems.get(index);
yesItems.get(index - 1).setSeqNo(yesItems.get(index - 1).getSeqNo()+10);
yesItems.set(index, yesItems.get(index-1));
yesItems.set(index-1 , orig);
indices[i] = index - 1; indices[i] = index - 1;
change = true; change = true;
} }
@ -388,15 +393,30 @@ public class WRC3SortCriteriaPanel extends WRCTabPanel implements EventListener
yesModel.setElementAt(newObject, index); yesModel.setElementAt(newObject, index);
yesModel.setElementAt(selObject, index + 1); yesModel.setElementAt(selObject, index + 1);
yesList.setSelectedIndex(index + 1); yesList.setSelectedIndex(index + 1);
selectedPI = m_pfi.indexOf(getPrintFormatItem(selObject.m_key));
targetPI = m_pfi.indexOf(getPrintFormatItem(newObject.m_key));
updateSortNo (selectedPI,targetPI);
yesItems.get(index).setSeqNo(yesItems.get(index).getSeqNo()+10);
orig = m_pfi.get(index);
yesItems.get(index + 1).setSeqNo(yesItems.get(index + 1).getSeqNo()-10);
yesItems.set(index, yesItems.get(index+1));
yesItems.set(index+1,orig);
indices[i] = index + 1; indices[i] = index + 1;
change = true; change = true;
} }
} // down } // down
// //
if (change) { if (change) {
yesList.setSelectedIndices(indices); yesList.removeAllItems();
updateYesList(); for(int i=0 ; i<yesModel.getSize(); i++) {
ListElement pp = (ListElement)yesModel.getElementAt(i);
yesList.addItem(new KeyNamePair(pp.m_key, pp.getName()));
}
wc.setIsChanged(true);
if ( yesList.getSelectedItem() != null) if ( yesList.getSelectedItem() != null)
{ {
AuFocus focus = new AuFocus(yesList.getSelectedItem()); AuFocus focus = new AuFocus(yesList.getSelectedItem());
@ -405,23 +425,15 @@ public class WRC3SortCriteriaPanel extends WRCTabPanel implements EventListener
} }
} // migrateValueWithinYesList } // migrateValueWithinYesList
public void updateYesList(){
yesList.removeAllItems(); /**
wc.setIsChanged(true); * @param int selIndexPI,int targetIndexPI
int sortNo=10; */
for(int i=0;i<yesModel.getSize();i++){ private void updateSortNo(int selIndexPI,int targetIndexPI)
ListElement obj=(ListElement) yesModel.getElementAt(i); {
for(int j=0;j<m_pfi.length;j++){ int selSortNo = m_pfi.get(selIndexPI).getSortNo();
if(m_pfi[j].get_ID() == obj.getKey()){ m_pfi.get(selIndexPI).setSortNo(m_pfi.get(targetIndexPI).getSortNo());
String name=obj.getName(); m_pfi.get(targetIndexPI).setSortNo(selSortNo);
int ID=obj.getKey();
KeyNamePair pair=new KeyNamePair(ID, name);
yesList.addItem(pair);
m_pfi[j].setSortNo(sortNo);
sortNo=sortNo+10;
}
}
}
} }
/** /**
@ -520,45 +532,36 @@ public class WRC3SortCriteriaPanel extends WRCTabPanel implements EventListener
} }
public void onEvent(Event event) throws Exception { public void onEvent(Event event) throws Exception {
int endIndex=0;
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();
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.isSelected())
startItem.setSelected(true);
if (!(startItem.getListbox() == endItem.getListbox()))
{ {
return; //move within same list Listbox listFrom = (Listbox)startItem.getListbox();
} Listbox listTo = (Listbox)endItem.getListbox();
int startIndex = noList.getIndexOfItem(startItem); endIndex = yesList.getIndexOfItem(endItem);
ListElement element = (ListElement) noModel.getElementAt(startIndex); migrateLists (listFrom,listTo,endIndex);
noModel.removeElement(element); }else if (startItem.getListbox() == endItem.getListbox() && startItem.getListbox() == yesList)
endIndex = yesList.getIndexOfItem(endItem); {
yesModel.add(endIndex, element); List<ListElement> selObjects = new ArrayList<ListElement>();
endIndex = yesList.getIndexOfItem(endItem);
for (int j=0 ; j<m_pfi.length ; j++) { for (Object obj : yesList.getSelectedItems()) {
if (m_pfi[j].get_ID() == element.m_key) { ListItem listItem = (ListItem) obj;
m_pfi[j].setIsOrderBy(true); int index = yesList.getIndexOfItem(listItem);
m_pfi[j].setSortNo(endIndex*10); ListElement selObject = (ListElement)yesModel.getElementAt(index);
selObjects.add(selObject);
} }
migrateValueWithinYesList (endIndex, selObjects);
} }
wc.setIsChanged(true); }
} }
}
refresh();
//
noList.clearSelection();
yesList.clearSelection();
yesList.setSelectedIndex(endIndex);
}
}
} }

View File

@ -48,9 +48,9 @@ public class WRC4GroupingCriteriaPanel extends WRCTabPanel implements EventListe
@Override @Override
public void refresh() { public void refresh() {
orderfield = new ArrayList<MPrintFormatItem>(); orderfield = new ArrayList<MPrintFormatItem>();
for(int i=0 ; i < m_pfi.length ; i++){ for(int i=0 ; i < m_pfi.size(); i++){
if(m_pfi[i] != null && m_pfi[i].isOrderBy() && m_pfi[i].isPrinted()){ if(m_pfi.get(i) != null && m_pfi.get(i).isOrderBy() && m_pfi.get(i).isPrinted()){
orderfield.add(m_pfi[i]); orderfield.add(m_pfi.get(i));
} }
} }
dynamicInit(); dynamicInit();
@ -59,11 +59,8 @@ public class WRC4GroupingCriteriaPanel extends WRCTabPanel implements EventListe
@Override @Override
public void updatePFI() { public void updatePFI() {
for(int i=0 ; i<orderfield.size() ; i++){ for(int i=0 ; i<orderfield.size() ; i++){
for(int j=0 ;j<m_pfi.length ; j++){ int j = m_pfi.indexOf(getPrintFormatItem(orderfield.get(i).get_ID()));
if(orderfield.get(i).get_ID() == m_pfi[j].get_ID()){ m_pfi.get(j).setIsGroupBy(m_chkboxes[i].isChecked());
m_pfi[j].setIsGroupBy(m_chkboxes[i].isChecked());
}
}
} }
} }
@ -102,7 +99,6 @@ public class WRC4GroupingCriteriaPanel extends WRCTabPanel implements EventListe
columns.appendChild(cols[i+1]); columns.appendChild(cols[i+1]);
} }
grid.appendChild(columns); grid.appendChild(columns);
this.appendChild(wind); this.appendChild(wind);
wind.appendChild(grid); wind.appendChild(grid);
} }

View File

@ -84,9 +84,9 @@ public class WRC5SummaryFieldsPanel extends WRCTabPanel implements EventListener
@Override @Override
public void refresh() { public void refresh() {
DisplayItems = new ArrayList<MPrintFormatItem>(); DisplayItems = new ArrayList<MPrintFormatItem>();
for(int i=0 ; i<m_pfi.length ; i ++){ for(int i=0 ; i<m_pfi.size() ; i ++){
if(m_pfi[i] != null && m_pfi[i].isPrinted()){ if(m_pfi.get(i) != null && m_pfi.get(i).isPrinted()){
DisplayItems.add(m_pfi[i]); DisplayItems.add(m_pfi.get(i));
} }
} }
dynamicInit(); dynamicInit();
@ -95,17 +95,14 @@ public class WRC5SummaryFieldsPanel extends WRCTabPanel implements EventListener
@Override @Override
public void updatePFI() { public void updatePFI() {
for(int i=0 ;i<DisplayItems.size() ; i++){ for(int i=0 ;i<DisplayItems.size() ; i++){
for(int j=0 ; j<m_pfi.length ; j++){ int j = m_pfi.indexOf(getPrintFormatItem(DisplayItems.get(i).get_ID()));
if(DisplayItems.get(i).get_ID() == m_pfi[j].get_ID()){ m_pfi.get(j).setIsSummarized(m_chkSum[i].isChecked());
m_pfi[j].setIsSummarized(m_chkSum[i].isChecked()); m_pfi.get(j).setIsCounted(m_chkCount[i].isChecked());
m_pfi[j].setIsCounted(m_chkCount[i].isChecked()); m_pfi.get(j).setIsMinCalc(m_chkMin[i].isChecked());
m_pfi[j].setIsMinCalc(m_chkMin[i].isChecked()); m_pfi.get(j).setIsMaxCalc(m_chkMax[i].isChecked());
m_pfi[j].setIsMaxCalc(m_chkMax[i].isChecked()); m_pfi.get(j).setIsAveraged(m_chkMean[i].isChecked());
m_pfi[j].setIsAveraged(m_chkMean[i].isChecked()); m_pfi.get(j).setIsVarianceCalc(m_chkVariance[i].isChecked());
m_pfi[j].setIsVarianceCalc(m_chkVariance[i].isChecked()); m_pfi.get(j).setIsDeviationCalc(m_chkDesviation[i].isChecked());
m_pfi[j].setIsDeviationCalc(m_chkDesviation[i].isChecked());
}
}
} }
} }

View File

@ -14,8 +14,14 @@
package org.adempiere.webui.panel; package org.adempiere.webui.panel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.adempiere.webui.apps.form.WReportCustomization; import org.adempiere.webui.apps.form.WReportCustomization;
import org.adempiere.webui.component.Tabpanel; import org.adempiere.webui.component.Tabpanel;
import org.compiere.model.GridField;
import org.compiere.model.MField;
import org.compiere.print.MPrintFormat; import org.compiere.print.MPrintFormat;
import org.compiere.print.MPrintFormatItem; import org.compiere.print.MPrintFormatItem;
@ -25,9 +31,10 @@ public abstract class WRCTabPanel extends Tabpanel {
*/ */
private static final long serialVersionUID = -6858669581232541371L; private static final long serialVersionUID = -6858669581232541371L;
public MPrintFormatItem[] m_pfi; public ArrayList<MPrintFormatItem> m_pfi;
public MPrintFormat m_pf; public MPrintFormat m_pf;
public WReportCustomization wc; public WReportCustomization wc;
public Map<Integer, MPrintFormatItem> mapPFormatItem = new HashMap<Integer, MPrintFormatItem>();
public abstract void refresh(); public abstract void refresh();
@ -35,14 +42,21 @@ public abstract class WRCTabPanel extends Tabpanel {
public void setMPrintFormat(MPrintFormat pf) { public void setMPrintFormat(MPrintFormat pf) {
m_pf=pf; m_pf=pf;
for (MPrintFormatItem item : m_pf.getAllItems() ){
mapPFormatItem.put(item.get_ID(), item);
}
} }
public void setPrintFormatItems(MPrintFormatItem[] pfis) { public void setPrintFormatItems(ArrayList<MPrintFormatItem> pfis) {
m_pfi = pfis; m_pfi = pfis;
} }
public void setWReportCustomization(WReportCustomization parent){ public void setWReportCustomization(WReportCustomization parent){
wc=parent; wc=parent;
} }
public MPrintFormatItem getPrintFormatItem(int AD_PrintFormatItem_ID) {
return mapPFormatItem.get(AD_PrintFormatItem_ID);
}
} }