IDEMPIERE-4442 Change Locator Dialog TableDirect (#242)

* IDEMPIERE-4442 Change Locator Dialog TableDirect

* IDEMPEIRE-4442 Fixed inconsitent Locator
This commit is contained in:
igorpojzl 2020-09-07 13:49:10 +02:00 committed by GitHub
parent ee48ef2be4
commit e18d8001d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 45 deletions

View File

@ -44,6 +44,7 @@ import org.compiere.model.Lookup;
import org.compiere.model.MBPartnerLocation; import org.compiere.model.MBPartnerLocation;
import org.compiere.model.MColumn; import org.compiere.model.MColumn;
import org.compiere.model.MLocation; import org.compiere.model.MLocation;
import org.compiere.model.MLocator;
import org.compiere.model.MLookup; import org.compiere.model.MLookup;
import org.compiere.model.MRole; import org.compiere.model.MRole;
import org.compiere.model.MTable; import org.compiere.model.MTable;
@ -372,7 +373,7 @@ ContextMenuListener, IZoomableEditor
getComponent().setSelectedItem(null); getComponent().setSelectedItem(null);
oldValue = value; oldValue = value;
if (getComponent() instanceof EditorAutoComplete) if (getComponent() instanceof EditorAutoComplete && gridField!=null) // IDEMPIERE-4442 Fix NPE, for Autocomplete in non Grid Usage.
updateStyle(); updateStyle();
} }
} }
@ -427,6 +428,15 @@ ContextMenuListener, IZoomableEditor
found = true; found = true;
} }
} }
else if (obj instanceof MLocator)
{
MLocator lookupKNPair = (MLocator) obj;
getComponent().appendItem(lookupKNPair.getValue(), lookupKNPair.getM_Locator_ID());
if (!found && oldValue != null && lookupKNPair.getM_Locator_ID() == (Integer) oldValue)
{
found = true;
}
}
} }
if (!found && oldValue != null) if (!found && oldValue != null)
{ {

View File

@ -41,6 +41,7 @@ import org.adempiere.webui.component.Row;
import org.adempiere.webui.component.Rows; 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.adempiere.webui.editor.WTableDirEditor;
import org.adempiere.webui.theme.ThemeManager; import org.adempiere.webui.theme.ThemeManager;
import org.adempiere.webui.util.ZKUpdateUtil; import org.adempiere.webui.util.ZKUpdateUtil;
import org.compiere.model.MLocator; import org.compiere.model.MLocator;
@ -77,7 +78,7 @@ public class WLocatorDialog extends Window implements EventListener<Event>
private Grid mainPanel = GridFactory.newGridLayout(); private Grid mainPanel = GridFactory.newGridLayout();
private Listbox lstLocator = new Listbox(); private WTableDirEditor locatorField = null;
private Listbox lstWarehouse = new Listbox(); private Listbox lstWarehouse = new Listbox();
private Listbox lstLocatorType = new Listbox(); private Listbox lstLocatorType = new Listbox();
@ -144,9 +145,9 @@ public class WLocatorDialog extends Window implements EventListener<Event>
m_WindowNo = windowNo; m_WindowNo = windowNo;
this.title = title; this.title = title;
m_mLocator = mLocator;
initComponents(); initComponents();
m_mLocator = mLocator;
m_M_Locator_ID = M_Locator_ID; m_M_Locator_ID = M_Locator_ID;
m_mandatory = mandatory; m_mandatory = mandatory;
m_only_Warehouse_ID = only_Warehouse_ID; m_only_Warehouse_ID = only_Warehouse_ID;
@ -167,10 +168,8 @@ public class WLocatorDialog extends Window implements EventListener<Event>
lblLevelZ.setValue(Msg.getElement(Env.getCtx(), "Z")); lblLevelZ.setValue(Msg.getElement(Env.getCtx(), "Z"));
lblKey.setValue(Msg.translate(Env.getCtx(), "Value")); lblKey.setValue(Msg.translate(Env.getCtx(), "Value"));
lstLocator.setMold("select"); locatorField = new WTableDirEditor(m_mLocator , Msg.translate(Env.getCtx(), "M_Locator_ID"), "", true, false, true, true);
lstLocator.setRows(0); LayoutUtils.addSclass("z-label", locatorField.getComponent());
LayoutUtils.addSclass("z-label", lstLocator);
chkCreateNew.setLabel(Msg.getMsg(Env.getCtx(), "CreateNew")); chkCreateNew.setLabel(Msg.getMsg(Env.getCtx(), "CreateNew"));
lstWarehouse.setMold("select"); lstWarehouse.setMold("select");
@ -200,8 +199,8 @@ public class WLocatorDialog extends Window implements EventListener<Event>
Row row = new Row(); Row row = new Row();
rows.appendChild(row); rows.appendChild(row);
row.appendChild(lblLocator); row.appendChild(lblLocator);
row.appendChild(lstLocator); row.appendChild(locatorField.getComponent());
ZKUpdateUtil.setHflex(lstLocator, "1"); ZKUpdateUtil.setHflex(locatorField.getComponent(), "1");
row = new Row(); row = new Row();
rows.appendChild(row); rows.appendChild(row);
@ -393,23 +392,10 @@ public class WLocatorDialog extends Window implements EventListener<Event>
} }
} }
int selectedIndex = -1; if(m_M_Locator_ID > 0)
for (int i = 0; i < m_mLocator.getSize(); i++) locatorField.setValue(m_M_Locator_ID);
{
MLocator obj = (MLocator) m_mLocator.getElementAt(i); locatorField.getComponent().addEventListener(Events.ON_SELECT, this);
if (obj.getM_Locator_ID() == m_M_Locator_ID && m_M_Locator_ID > 0)
selectedIndex = i;
lstLocator.appendItem(obj.toString(), obj);
}
if (lstLocator.getItemCount() > 0) {
if (selectedIndex >= 0)
lstLocator.setSelectedIndex(selectedIndex);
else
lstLocator.setSelectedIndex(0);
}
lstLocator.addEventListener(Events.ON_SELECT, this);
displayLocator(); displayLocator();
@ -432,10 +418,10 @@ public class WLocatorDialog extends Window implements EventListener<Event>
private void displayLocator() private void displayLocator()
{ {
MLocator l = null; MLocator l = null;
ListItem listitem = lstLocator.getSelectedItem(); Integer M_Locator_ID = (Integer)locatorField.getValue();
if (listitem != null) if (M_Locator_ID != null)
l = (MLocator) listitem.getValue(); l = MLocator.get(Env.getCtx(), M_Locator_ID);
if (l == null) if (l == null)
return; return;
@ -646,8 +632,8 @@ public class WLocatorDialog extends Window implements EventListener<Event>
listitem = new ListItem(); listitem = new ListItem();
listitem.setValue(loc); listitem.setValue(loc);
lstLocator.appendItem(loc.get_TableName(), loc); locatorField.actionRefresh();
lstLocator.setSelectedIndex(lstLocator.getItemCount() - 1); locatorField.setValue(m_M_Locator_ID);
} // createNew } // createNew
if (log.isLoggable(Level.CONFIG)) log.config("M_Locator_ID=" + m_M_Locator_ID); if (log.isLoggable(Level.CONFIG)) log.config("M_Locator_ID=" + m_M_Locator_ID);
@ -660,13 +646,7 @@ public class WLocatorDialog extends Window implements EventListener<Event>
public Integer getValue() public Integer getValue()
{ {
ListItem listitem = lstLocator.getSelectedItem(); return (Integer) locatorField.getValue();
MLocator l = (MLocator) listitem.getValue();
if (l != null && l.getM_Locator_ID() != 0)
return Integer.valueOf(l.getM_Locator_ID());
return null;
} // getValue } // getValue
/** /**
@ -678,11 +658,8 @@ public class WLocatorDialog extends Window implements EventListener<Event>
{ {
if (m_change) if (m_change)
{ {
ListItem listitem = lstLocator.getSelectedItem(); Integer locator_id = (Integer) locatorField.getValue();
MLocator l = listitem != null ? (MLocator)listitem.getValue() : null; return locator_id == m_M_Locator_ID;
if (l != null)
return l.getM_Locator_ID() == m_M_Locator_ID;
} }
return m_change; return m_change;
} // getChange } // getChange
@ -704,7 +681,7 @@ public class WLocatorDialog extends Window implements EventListener<Event>
m_change = true; m_change = true;
this.detach(); this.detach();
} }
else if (event.getTarget() == lstLocator) else if (event.getTarget() == locatorField.getComponent())
displayLocator(); displayLocator();
else if (event.getTarget() == chkCreateNew) else if (event.getTarget() == chkCreateNew)
enableNew(); enableNew();