IDEMPIERE-583 Delete Selection Panel improvement.
This commit is contained in:
parent
7246f49bab
commit
80f2dee5e9
|
@ -417,6 +417,15 @@ public class ADWindowToolbar extends FToolbar implements EventListener<Event>
|
|||
public void enableDelete(boolean enabled)
|
||||
{
|
||||
this.btnDelete.setDisabled(!enabled);
|
||||
}
|
||||
|
||||
public boolean isDeleteEnable()
|
||||
{
|
||||
return !btnDelete.isDisabled();
|
||||
}
|
||||
|
||||
public void enableDeleteSelection(boolean enabled)
|
||||
{
|
||||
this.btnDeleteSelection.setDisabled(!enabled);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,11 +25,9 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
@ -46,9 +44,6 @@ import org.adempiere.webui.apps.HelpWindow;
|
|||
import org.adempiere.webui.apps.ProcessModalDialog;
|
||||
import org.adempiere.webui.apps.form.WCreateFromFactory;
|
||||
import org.adempiere.webui.apps.form.WCreateFromWindow;
|
||||
import org.adempiere.webui.component.Button;
|
||||
import org.adempiere.webui.component.ConfirmPanel;
|
||||
import org.adempiere.webui.component.Listbox;
|
||||
import org.adempiere.webui.component.Mask;
|
||||
import org.adempiere.webui.component.ProcessInfoDialog;
|
||||
import org.adempiere.webui.component.Window;
|
||||
|
@ -60,7 +55,6 @@ import org.adempiere.webui.event.ActionListener;
|
|||
import org.adempiere.webui.event.DialogEvents;
|
||||
import org.adempiere.webui.event.ToolbarListener;
|
||||
import org.adempiere.webui.exception.ApplicationException;
|
||||
import org.adempiere.webui.factory.ButtonFactory;
|
||||
import org.adempiere.webui.panel.ADForm;
|
||||
import org.adempiere.webui.panel.InfoPanel;
|
||||
import org.adempiere.webui.panel.WAttachment;
|
||||
|
@ -84,7 +78,6 @@ import org.compiere.model.GridTab;
|
|||
import org.compiere.model.GridTable;
|
||||
import org.compiere.model.GridWindow;
|
||||
import org.compiere.model.GridWindowVO;
|
||||
import org.compiere.model.Lookup;
|
||||
import org.compiere.model.MImage;
|
||||
import org.compiere.model.MProcess;
|
||||
import org.compiere.model.MQuery;
|
||||
|
@ -97,7 +90,6 @@ import org.compiere.process.ProcessInfoLog;
|
|||
import org.compiere.process.ProcessInfoUtil;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
import org.compiere.util.Util;
|
||||
|
@ -115,8 +107,6 @@ import org.zkoss.zk.ui.util.Clients;
|
|||
import org.zkoss.zul.Column;
|
||||
import org.zkoss.zul.Columns;
|
||||
import org.zkoss.zul.Div;
|
||||
import org.zkoss.zul.Hbox;
|
||||
import org.zkoss.zul.Listitem;
|
||||
import org.zkoss.zul.Menuitem;
|
||||
import org.zkoss.zul.Menupopup;
|
||||
import org.zkoss.zul.Window.Mode;
|
||||
|
@ -970,6 +960,14 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
|
|||
//Deepak-Enabling customize button IDEMPIERE-364
|
||||
if(!(adTabbox.getSelectedTabpanel() instanceof ADSortTab))
|
||||
toolbar.enableCustomize(((ADTabpanel)adTabbox.getSelectedTabpanel()).isGridView());
|
||||
if (adTabbox.getSelectedTabpanel().isGridView())
|
||||
{
|
||||
toolbar.enableDeleteSelection(toolbar.isDeleteEnable());
|
||||
}
|
||||
else
|
||||
{
|
||||
toolbar.enableDeleteSelection(false);
|
||||
}
|
||||
focusToActivePanel();
|
||||
}
|
||||
|
||||
|
@ -1403,6 +1401,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
|
|||
toolbar.enableNew(!changed && insertRecord && !tabPanel.getGridTab().isSortTab());
|
||||
toolbar.enableRefresh(!changed);
|
||||
toolbar.enableDelete(!changed && !readOnly && !tabPanel.getGridTab().isSortTab() && !processed);
|
||||
toolbar.enableDeleteSelection(!changed && !readOnly && !tabPanel.getGridTab().isSortTab() && !processed && tabPanel.isGridView());
|
||||
//
|
||||
if (readOnly && adTabbox.getSelectedGridTab().isAlwaysUpdateField())
|
||||
{
|
||||
|
@ -1447,6 +1446,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
|
|||
{
|
||||
toolbar.enableNew(true);
|
||||
toolbar.enableDelete(false);
|
||||
toolbar.enableDeleteSelection(false);
|
||||
}
|
||||
|
||||
// Transaction info
|
||||
|
@ -1623,6 +1623,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
|
|||
adTabbox.getSelectedTabpanel().dynamicDisplay(0);
|
||||
toolbar.enableNew(false);
|
||||
toolbar.enableDelete(false);
|
||||
toolbar.enableDeleteSelection(false);
|
||||
breadCrumb.enableFirstNavigation(adTabbox.getSelectedGridTab().getCurrentRow() > 0);
|
||||
breadCrumb.enableLastNavigation(adTabbox.getSelectedGridTab().getCurrentRow() + 1 < adTabbox.getSelectedGridTab().getRowCount());
|
||||
toolbar.enableTabNavigation(breadCrumb.hasParentLink(), adTabbox.getSelectedDetailADTabpanel() != null);
|
||||
|
@ -1670,6 +1671,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
|
|||
adTabbox.getSelectedTabpanel().dynamicDisplay(0);
|
||||
toolbar.enableNew(false);
|
||||
toolbar.enableDelete(false);
|
||||
toolbar.enableDeleteSelection(false);
|
||||
breadCrumb.enableFirstNavigation(adTabbox.getSelectedGridTab().getCurrentRow() > 0);
|
||||
breadCrumb.enableLastNavigation(adTabbox.getSelectedGridTab().getCurrentRow() + 1 < adTabbox.getSelectedGridTab().getRowCount());
|
||||
toolbar.enableTabNavigation(false);
|
||||
|
@ -2019,198 +2021,43 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
|
|||
*/
|
||||
public void onDeleteSelection()
|
||||
{
|
||||
if (adTabbox.getSelectedGridTab().isReadOnly())
|
||||
if (adTabbox.getSelectedGridTab().isReadOnly() || !adTabbox.getSelectedTabpanel().isGridView())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//show table with deletion rows -> value, name...
|
||||
final Window messagePanel = new Window();
|
||||
messagePanel.setBorder("normal");
|
||||
messagePanel.setWidth("600px");
|
||||
messagePanel.setTitle(Msg.getMsg(Env.getCtx(), "Find").replaceAll("&", "") + ": " + title);
|
||||
messagePanel.setClosable(true);
|
||||
messagePanel.setSizable(true);
|
||||
messagePanel.setWidgetAttribute(AdempiereWebUI.WIDGET_INSTANCE_NAME, "deleteSelection");
|
||||
|
||||
final Listbox listbox = new Listbox();
|
||||
listbox.setHeight("400px");
|
||||
|
||||
// Display the first 5 fields data exclude Organization, Client and YesNo field data
|
||||
ArrayList<String> columnNames = new ArrayList<String>();
|
||||
GridField[] fields = adTabbox.getSelectedGridTab().getFields();
|
||||
if(adTabbox.getSelectedGridTab().getField("DocumentNo")!=null){
|
||||
columnNames.add(adTabbox.getSelectedGridTab().getField("DocumentNo").getColumnName());
|
||||
}
|
||||
if(adTabbox.getSelectedGridTab().getField("Line")!=null){
|
||||
columnNames.add(adTabbox.getSelectedGridTab().getField("Line").getColumnName());
|
||||
}
|
||||
if(adTabbox.getSelectedGridTab().getField("Value")!=null){
|
||||
columnNames.add(adTabbox.getSelectedGridTab().getField("Value").getColumnName());
|
||||
}
|
||||
if(adTabbox.getSelectedGridTab().getField("Name")!=null){
|
||||
columnNames.add(adTabbox.getSelectedGridTab().getField("Name").getColumnName());
|
||||
}
|
||||
for(int i = 0; i < fields.length; i++)
|
||||
{
|
||||
GridField field = fields[i];
|
||||
if(field.getColumnName().equalsIgnoreCase("AD_Org_ID")
|
||||
|| field.getColumnName().equalsIgnoreCase("AD_Client_ID")
|
||||
|| field.getDisplayType() == DisplayType.YesNo)
|
||||
continue;
|
||||
if (!columnNames.contains(field.getColumnName()))
|
||||
{
|
||||
columnNames.add(field.getColumnName());
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<String> data = new ArrayList<String>();
|
||||
int noOfRows = adTabbox.getSelectedGridTab().getRowCount();
|
||||
for(int i=0; i<noOfRows; i++)
|
||||
{
|
||||
StringBuffer displayValue = new StringBuffer();
|
||||
if("".equals(adTabbox.getSelectedGridTab().getKeyColumnName()))
|
||||
{
|
||||
ArrayList<String> parentColumnNames = adTabbox.getSelectedGridTab().getParentColumnNames();
|
||||
for (Iterator<String> iter = parentColumnNames.iterator(); iter.hasNext();)
|
||||
{
|
||||
String columnName = iter.next();
|
||||
GridField field = adTabbox.getSelectedGridTab().getField(columnName);
|
||||
if(field.isLookup()){
|
||||
Lookup lookup = field.getLookup();
|
||||
if (lookup != null){
|
||||
displayValue = displayValue.append(lookup.getDisplay(adTabbox.getSelectedGridTab().getValue(i,columnName))).append(" | ");
|
||||
} else {
|
||||
displayValue = displayValue.append(adTabbox.getSelectedGridTab().getValue(i,columnName)).append(" | ");
|
||||
}
|
||||
} else {
|
||||
displayValue = displayValue.append(adTabbox.getSelectedGridTab().getValue(i,columnName)).append(" | ");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
displayValue = displayValue.append(adTabbox.getSelectedGridTab().getValue(i,adTabbox.getSelectedGridTab().getKeyColumnName()));
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for(int j=0; j < columnNames.size() && count < 5; j++)
|
||||
{
|
||||
Object value = adTabbox.getSelectedGridTab().getValue(i, columnNames.get(j));
|
||||
if(value == null) continue; // skip when value is null
|
||||
String text = value.toString().trim();
|
||||
if(text.length() == 0) continue; // skip when value is empty
|
||||
GridField field = adTabbox.getSelectedGridTab().getField(columnNames.get(j));
|
||||
if(field != null)
|
||||
{
|
||||
if (field.isLookup())
|
||||
{
|
||||
Lookup lookup = field.getLookup();
|
||||
if (lookup != null)
|
||||
text = lookup.getDisplay(value);
|
||||
}
|
||||
else if (DisplayType.isDate(field.getDisplayType()))
|
||||
{
|
||||
text = DisplayType.getDateFormat(field.getDisplayType()).format(value);
|
||||
}
|
||||
}
|
||||
if(text.length() > 30)
|
||||
text = text.substring(0, 30); // display the first 30 characters
|
||||
displayValue = displayValue.append(" | ").append(text);
|
||||
count++;
|
||||
}
|
||||
|
||||
data.add(displayValue.toString());
|
||||
}
|
||||
|
||||
for(int i = 0; i < data.size(); i++)
|
||||
{
|
||||
String record = data.get(i);
|
||||
listbox.appendItem(record, record);
|
||||
}
|
||||
|
||||
listbox.setMultiple(true);
|
||||
messagePanel.appendChild(listbox);
|
||||
|
||||
Div div = new Div();
|
||||
div.setStyle("text-align: center");
|
||||
messagePanel.appendChild(div);
|
||||
|
||||
Hbox hbox = new Hbox();
|
||||
hbox.setStyle("padding-top: 2px");
|
||||
div.appendChild(hbox);
|
||||
|
||||
Button btnOk = ButtonFactory.createNamedButton(ConfirmPanel.A_OK);
|
||||
// Invert - Unify OK/Cancel IDEMPIERE-77
|
||||
btnOk.addEventListener(Events.ON_CLICK, new EventListener<Event>()
|
||||
{
|
||||
public void onEvent(Event event) throws Exception
|
||||
{
|
||||
FDialog.ask(curWindowNo, messagePanel, "DeleteSelection", new Callback<Boolean>() {
|
||||
|
||||
final int[] indices = adTabbox.getSelectedGridTab().getSelection();
|
||||
if(indices.length > 0) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(Env.getContext(ctx, curWindowNo, "_WinInfo_WindowName", false)).append(" - ")
|
||||
.append(indices.length).append(" ").append(Msg.getMsg(Env.getCtx(), "Selected"));
|
||||
FDialog.ask(sb.toString(), curWindowNo, null,"DeleteSelection", new Callback<Boolean>() {
|
||||
@Override
|
||||
public void onCallback(Boolean result)
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
logger.fine("ok");
|
||||
Set<Listitem> selectedValues = listbox.getSelectedItems();
|
||||
if(selectedValues != null)
|
||||
{
|
||||
for(Iterator<Listitem> iter = selectedValues.iterator(); iter.hasNext();)
|
||||
{
|
||||
Listitem li = iter.next();
|
||||
if(li != null)
|
||||
if (logger.isLoggable(Level.FINE)) logger.fine((String) li.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
int[] indices = listbox.getSelectedIndices();
|
||||
public void onCallback(Boolean result) {
|
||||
if(result){
|
||||
adTabbox.getSelectedGridTab().clearSelection();
|
||||
Arrays.sort(indices);
|
||||
int offset = 0;
|
||||
int count = 0;
|
||||
for (int i = 0; i < indices.length; i++)
|
||||
{
|
||||
adTabbox.getSelectedGridTab().navigate(indices[i]-offset);
|
||||
if (adTabbox.getSelectedGridTab().dataDelete())
|
||||
{
|
||||
offset++;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
adTabbox.getSelectedTabpanel().dynamicDisplay(0);
|
||||
|
||||
messagePanel.dispose();
|
||||
MRecentItem.publishChangedEvent(Env.getAD_User_ID(ctx));
|
||||
statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "Deleted")+": "+count, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
logger.fine("cancel");
|
||||
statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "Selected")+": 0", false);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
hbox.appendChild(btnOk);
|
||||
|
||||
Button btnCancel = ButtonFactory.createNamedButton(ConfirmPanel.A_CANCEL);
|
||||
btnCancel.addEventListener(Events.ON_CLICK, new EventListener<Event>()
|
||||
{
|
||||
public void onEvent(Event event) throws Exception
|
||||
{
|
||||
messagePanel.dispose();
|
||||
}
|
||||
});
|
||||
hbox.appendChild(btnCancel);
|
||||
hbox.setPack("end");
|
||||
hbox.setHflex("1");
|
||||
|
||||
messagePanel.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener<Event>() {
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
hideBusyMask();
|
||||
focusToActivePanel();
|
||||
}
|
||||
});
|
||||
getComponent().getParent().appendChild(messagePanel);
|
||||
showBusyMask(messagePanel);
|
||||
LayoutUtils.openOverlappedWindow(getComponent(), messagePanel, "middle_center");
|
||||
}
|
||||
//
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.compiere.util.Msg;
|
|||
import org.compiere.util.Util;
|
||||
import org.zkoss.zk.au.out.AuScript;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
import org.zkoss.zk.ui.HtmlBasedComponent;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
|
@ -69,6 +70,7 @@ import org.zkoss.zul.impl.XulElement;
|
|||
*/
|
||||
public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt, RendererCtrl, EventListener<Event> {
|
||||
|
||||
public static final String GRID_ROW_INDEX_ATTR = "grid.row.index";
|
||||
private static final String CELL_DIV_STYLE = "border: none; height: 100%; cursor: pointer; ";
|
||||
private static final String CELL_DIV_STYLE_ALIGN_CENTER = CELL_DIV_STYLE + "text-align:center; ";
|
||||
private static final String CELL_DIV_STYLE_ALIGN_RIGHT = CELL_DIV_STYLE + "text-align:right; ";
|
||||
|
@ -195,7 +197,7 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
|
|||
WButtonEditor editor = new WButtonEditor(gridField, rowIndex);
|
||||
editor.setValue(gridTab.getValue(rowIndex, gridField.getColumnName()));
|
||||
editor.setReadWrite(gridField.isEditable(gridRowCtx, true,true));
|
||||
editor.getComponent().setAttribute("grid.row.index", rowIndex);
|
||||
editor.getComponent().setAttribute(GRID_ROW_INDEX_ATTR, rowIndex);
|
||||
editor.addActionListener(buttonListener);
|
||||
component = editor.getComponent();
|
||||
} else {
|
||||
|
@ -365,12 +367,28 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
|
|||
}
|
||||
|
||||
Cell cell = new Cell();
|
||||
cell.setWidth("28px");
|
||||
cell.setTooltiptext(Msg.getMsg(Env.getCtx(), "Select"));
|
||||
Checkbox selection = new Checkbox();
|
||||
selection.setAttribute(GRID_ROW_INDEX_ATTR, rowIndex);
|
||||
selection.setChecked(gridTab.isSelected(rowIndex));
|
||||
cell.setStyle("background-color: transparent !important;");
|
||||
selection.addEventListener(Events.ON_CHECK, this);
|
||||
|
||||
if (!selection.isChecked()) {
|
||||
if (gridPanel.selectAll.isChecked()) {
|
||||
gridPanel.selectAll.setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
cell.appendChild(selection);
|
||||
row.appendChild(cell);
|
||||
|
||||
cell = new Cell();
|
||||
cell.setWidth("18px");
|
||||
cell.addEventListener(Events.ON_CLICK, this);
|
||||
cell.setTooltiptext(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "EditRecord")));
|
||||
|
||||
//TODO: checkbox for selection and batch action ( delete, export, complete, etc )
|
||||
// cell.appendChild(new Checkbox());
|
||||
row.appendChild(cell);
|
||||
|
||||
int colIndex = -1;
|
||||
|
@ -425,7 +443,6 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
|
|||
div.setAttribute("columnName", gridPanelFields[i].getColumnName());
|
||||
div.addEventListener(Events.ON_CLICK, rowListener);
|
||||
div.addEventListener(Events.ON_DOUBLE_CLICK, rowListener);
|
||||
row.addEventListener(Events.ON_CLICK, rowListener);
|
||||
row.appendChild(div);
|
||||
}
|
||||
|
||||
|
@ -434,6 +451,7 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
|
|||
}
|
||||
|
||||
row.setStyle("cursor:pointer");
|
||||
row.addEventListener(Events.ON_CLICK, rowListener);
|
||||
row.addEventListener(Events.ON_OK, rowListener);
|
||||
}
|
||||
|
||||
|
@ -442,14 +460,14 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
|
|||
*/
|
||||
public void setCurrentRow(Row row) {
|
||||
if (currentRow != null && currentRow.getParent() != null && currentRow != row) {
|
||||
Cell cell = (Cell) currentRow.getFirstChild();
|
||||
Cell cell = (Cell) currentRow.getChildren().get(1);
|
||||
if (cell != null) {
|
||||
cell.setStyle("background-color: transparent");
|
||||
cell.setSclass("row-indicator");
|
||||
}
|
||||
}
|
||||
currentRow = row;
|
||||
Cell cell = (Cell) currentRow.getFirstChild();
|
||||
Cell cell = (Cell) currentRow.getChildren().get(1);
|
||||
if (cell != null) {
|
||||
cell.setSclass("row-indicator-seld");
|
||||
}
|
||||
|
@ -494,8 +512,8 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
|
|||
GridField[] gridPanelFields = gridPanel.getFields();
|
||||
int columnCount = gridPanelFields.length;
|
||||
org.zkoss.zul.Columns columns = grid.getColumns();
|
||||
//skip indicator column
|
||||
int colIndex = 0;
|
||||
//skip selection and indicator column
|
||||
int colIndex = 1;
|
||||
for (int i = 0; i < columnCount; i++) {
|
||||
if (!gridPanelFields[i].isDisplayedGrid() || gridPanelFields[i].isToolbarButton()) {
|
||||
continue;
|
||||
|
@ -677,6 +695,9 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
|
|||
|
||||
public void onEvent(Event event) throws Exception {
|
||||
if (Events.ON_CLICK.equals(event.getName())) {
|
||||
if (Executions.getCurrent().getAttribute("gridView.onSelectRow") != null)
|
||||
return;
|
||||
System.out.println(event);
|
||||
Event evt = new Event(Events.ON_CLICK, _grid, event.getTarget());
|
||||
Events.sendEvent(_grid, evt);
|
||||
evt.stopPropagation();
|
||||
|
@ -711,7 +732,7 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
|
|||
buttonListener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
WButtonEditor editor = (WButtonEditor) event.getSource();
|
||||
Integer rowIndex = (Integer) editor.getComponent().getAttribute("grid.row.index");
|
||||
Integer rowIndex = (Integer) editor.getComponent().getAttribute(GRID_ROW_INDEX_ATTR);
|
||||
if (rowIndex != null) {
|
||||
int newRowIndex = gridTab.navigate(rowIndex);
|
||||
if (newRowIndex == rowIndex) {
|
||||
|
@ -732,6 +753,10 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
|
|||
Events.sendEvent(gridPanel, new Event(DetailPane.ON_EDIT_EVENT, gridPanel));
|
||||
else
|
||||
Events.sendEvent(event.getTarget().getParent(), event);
|
||||
} else if (event.getTarget() instanceof Checkbox) {
|
||||
Executions.getCurrent().setAttribute("gridView.onSelectRow", Boolean.TRUE);
|
||||
Checkbox checkBox = (Checkbox) event.getTarget();
|
||||
Events.sendEvent(gridPanel, new Event("onSelectRow", gridPanel, checkBox));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.adempiere.base.Core;
|
|||
import org.adempiere.model.MTabCustomization;
|
||||
import org.adempiere.util.GridRowCtx;
|
||||
import org.adempiere.webui.apps.AEnv;
|
||||
import org.adempiere.webui.component.Checkbox;
|
||||
import org.adempiere.webui.component.Columns;
|
||||
import org.adempiere.webui.component.EditorBox;
|
||||
import org.adempiere.webui.component.Grid;
|
||||
|
@ -36,6 +37,8 @@ import org.compiere.model.GridField;
|
|||
import org.compiere.model.GridTab;
|
||||
import org.compiere.model.GridTable;
|
||||
import org.compiere.model.MSysConfig;
|
||||
import org.compiere.model.StateChangeEvent;
|
||||
import org.compiere.model.StateChangeListener;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
|
@ -63,7 +66,7 @@ import org.zkoss.zul.event.ZulEvents;
|
|||
* @author Low Heng Sin
|
||||
*
|
||||
*/
|
||||
public class GridView extends Vbox implements EventListener<Event>, IdSpace, IFieldEditorContainer
|
||||
public class GridView extends Vbox implements EventListener<Event>, IdSpace, IFieldEditorContainer, StateChangeListener
|
||||
{
|
||||
private static final String HEADER_GRID_STYLE = "border: none; margin:0; padding: 0;";
|
||||
|
||||
|
@ -121,6 +124,8 @@ public class GridView extends Vbox implements EventListener<Event>, IdSpace, IFi
|
|||
|
||||
private boolean detailPaneMode;
|
||||
|
||||
protected Checkbox selectAll;
|
||||
|
||||
public GridView()
|
||||
{
|
||||
this(0);
|
||||
|
@ -161,6 +166,8 @@ public class GridView extends Vbox implements EventListener<Event>, IdSpace, IFi
|
|||
|
||||
setStyle(HEADER_GRID_STYLE);
|
||||
gridFooter.setStyle(HEADER_GRID_STYLE);
|
||||
|
||||
addEventListener("onSelectRow", this);
|
||||
}
|
||||
|
||||
protected void createListbox() {
|
||||
|
@ -199,6 +206,9 @@ public class GridView extends Vbox implements EventListener<Event>, IdSpace, IFi
|
|||
{
|
||||
if (init) return;
|
||||
|
||||
if (this.gridTab != null)
|
||||
this.gridTab.removeStateChangeListener(this);
|
||||
|
||||
setupFields(gridTab);
|
||||
|
||||
setupColumns();
|
||||
|
@ -211,6 +221,8 @@ public class GridView extends Vbox implements EventListener<Event>, IdSpace, IFi
|
|||
|
||||
private void setupFields(GridTab gridTab) {
|
||||
this.gridTab = gridTab;
|
||||
gridTab.addStateChangeListener(this);
|
||||
|
||||
tableModel = gridTab.getTableModel();
|
||||
columnWidthMap = new HashMap<Integer, String>();
|
||||
GridField[] tmpFields = ((GridTable)tableModel).getFields();
|
||||
|
@ -393,15 +405,29 @@ public class GridView extends Vbox implements EventListener<Event>, IdSpace, IFi
|
|||
if (!AEnv.isTablet())
|
||||
{
|
||||
Frozen frozen = new Frozen();
|
||||
frozen.setColumns(1);
|
||||
//freeze selection and indicator column
|
||||
frozen.setColumns(2);
|
||||
listbox.appendChild(frozen);
|
||||
}
|
||||
|
||||
org.zkoss.zul.Column selection = new Column();
|
||||
selection.setWidth("28px");
|
||||
try{
|
||||
selection.setSort("none");
|
||||
} catch (Exception e) {}
|
||||
selection.setStyle("border-right: none");
|
||||
selectAll = new Checkbox();
|
||||
selection.appendChild(selectAll);
|
||||
selectAll.setId("selectAll");
|
||||
selectAll.addEventListener(Events.ON_CHECK, this);
|
||||
columns.appendChild(selection);
|
||||
|
||||
org.zkoss.zul.Column indicator = new Column();
|
||||
indicator.setWidth("18px");
|
||||
try {
|
||||
indicator.setSort("none");
|
||||
} catch (Exception e) {}
|
||||
indicator.setStyle("border-left: none");
|
||||
columns.appendChild(indicator);
|
||||
listbox.appendChild(columns);
|
||||
columns.setSizable(true);
|
||||
|
@ -584,6 +610,72 @@ public class GridView extends Vbox implements EventListener<Event>, IdSpace, IFi
|
|||
{
|
||||
listModel.setPage(pgNo);
|
||||
onSelectedRowChange(0);
|
||||
gridTab.clearSelection();
|
||||
}
|
||||
}
|
||||
else if (event.getTarget() == selectAll)
|
||||
{
|
||||
toggleSelectionForAll(selectAll.isChecked());
|
||||
}
|
||||
else if (event.getName().equals("onSelectRow"))
|
||||
{
|
||||
Checkbox checkbox = (Checkbox) event.getData();
|
||||
int rowIndex = (Integer) checkbox.getAttribute(GridTabRowRenderer.GRID_ROW_INDEX_ATTR);
|
||||
if (checkbox.isChecked())
|
||||
{
|
||||
gridTab.addToSelection(rowIndex);
|
||||
if (!selectAll.isChecked() && isAllSelected())
|
||||
{
|
||||
selectAll.setChecked(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gridTab.removeFromSelection(rowIndex);
|
||||
if (selectAll.isChecked())
|
||||
selectAll.setChecked(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAllSelected() {
|
||||
org.zkoss.zul.Rows rows = listbox.getRows();
|
||||
List<Component> childs = rows.getChildren();
|
||||
boolean all = false;
|
||||
for(Component comp : childs) {
|
||||
org.zkoss.zul.Row row = (org.zkoss.zul.Row) comp;
|
||||
Component firstChild = row.getFirstChild();
|
||||
if (firstChild instanceof Cell) {
|
||||
firstChild = firstChild.getFirstChild();
|
||||
}
|
||||
if (firstChild instanceof Checkbox) {
|
||||
Checkbox checkbox = (Checkbox) firstChild;
|
||||
if (!checkbox.isChecked())
|
||||
return false;
|
||||
else
|
||||
all = true;
|
||||
}
|
||||
}
|
||||
return all;
|
||||
}
|
||||
|
||||
private void toggleSelectionForAll(boolean b) {
|
||||
org.zkoss.zul.Rows rows = listbox.getRows();
|
||||
List<Component> childs = rows.getChildren();
|
||||
for(Component comp : childs) {
|
||||
org.zkoss.zul.Row row = (org.zkoss.zul.Row) comp;
|
||||
Component firstChild = row.getFirstChild();
|
||||
if (firstChild instanceof Cell) {
|
||||
firstChild = firstChild.getFirstChild();
|
||||
}
|
||||
if (firstChild instanceof Checkbox) {
|
||||
Checkbox checkbox = (Checkbox) firstChild;
|
||||
checkbox.setChecked(b);
|
||||
int rowIndex = (Integer) checkbox.getAttribute(GridTabRowRenderer.GRID_ROW_INDEX_ATTR);
|
||||
if (b)
|
||||
gridTab.addToSelection(rowIndex);
|
||||
else
|
||||
gridTab.removeFromSelection(rowIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -903,4 +995,21 @@ public class GridView extends Vbox implements EventListener<Event>, IdSpace, IFi
|
|||
renderer.focusToNextEditor(ref);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateChange(StateChangeEvent event) {
|
||||
switch(event.getEventType()) {
|
||||
case StateChangeEvent.DATA_NEW:
|
||||
case StateChangeEvent.DATA_QUERY:
|
||||
case StateChangeEvent.DATA_REFRESH_ALL:
|
||||
if (selectAll.isChecked())
|
||||
selectAll.setChecked(false);
|
||||
break;
|
||||
case StateChangeEvent.DATA_DELETE:
|
||||
case StateChangeEvent.DATA_IGNORE:
|
||||
if (!selectAll.isChecked() && isAllSelected())
|
||||
selectAll.setChecked(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -289,6 +289,11 @@ public class FDialog
|
|||
return ask(windowNo, comp, adMessage, (Callback<Boolean>)null);
|
||||
}
|
||||
|
||||
public static boolean ask(int windowNo, Component comp, String adMessage, final Callback<Boolean> callback)
|
||||
{
|
||||
return ask(AEnv.getDialogHeader(Env.getCtx(), windowNo), windowNo, comp, adMessage, callback);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* Ask Question with question icon and (OK) (Cancel) buttons
|
||||
*
|
||||
|
@ -299,7 +304,7 @@ public class FDialog
|
|||
* @return true, if OK
|
||||
*/
|
||||
|
||||
public static boolean ask(int windowNo, Component comp, String adMessage, final Callback<Boolean> callback)
|
||||
public static boolean ask(String title, int windowNo, Component comp, String adMessage, final Callback<Boolean> callback)
|
||||
{
|
||||
Callback<Integer> msgCallback = null;
|
||||
if (callback != null)
|
||||
|
@ -313,7 +318,7 @@ public class FDialog
|
|||
};
|
||||
}
|
||||
String s = Msg.getMsg(Env.getCtx(), adMessage).replace("\n", "<br>");
|
||||
int response = Messagebox.showDialog(s, AEnv.getDialogHeader(Env.getCtx(), windowNo),
|
||||
int response = Messagebox.showDialog(s, title,
|
||||
Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION, msgCallback, (msgCallback == null));
|
||||
|
||||
return (response == Messagebox.OK);
|
||||
|
|
Loading…
Reference in New Issue