Improve management of the server push update info thread.

Improve dynamic display handling for table editor.
This commit is contained in:
Heng Sin Low 2008-11-25 15:55:27 +00:00
parent 07f062f826
commit d136ea9057
24 changed files with 107 additions and 128 deletions

View File

@ -181,6 +181,8 @@ public class AdempiereWebUI extends Window implements EventListener, IWebClient
mSession.logout();
}
appDesktop.logout();
SessionManager.clearSession();
super.getChildren().clear();
Page page = this.getPage();

View File

@ -63,7 +63,6 @@ import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.util.WebDoc;
import org.zkoss.lang.Threads;
import org.zkoss.util.media.AMedia;
import org.zkoss.zhtml.Button;
import org.zkoss.zk.ui.Component;
@ -114,6 +113,10 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl
private MGoal[] m_goals = null;
private List<MQuery> queryZoom = null;
private Thread updateInfoThread;
private UpdateInfoRunnable updateInfoRunnable;
private static final String key = "queryZoom";
@ -355,9 +358,10 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl
updateInfo();
Thread infoThread = new Thread(new UpdateInfoRunnable(layout.getDesktop()), "UpdateInfo");
infoThread.setDaemon(true);
infoThread.start();
updateInfoRunnable = new UpdateInfoRunnable(layout.getDesktop());
updateInfoThread = new Thread(updateInfoRunnable, "UpdateInfo");
updateInfoThread.setDaemon(true);
updateInfoThread.start();
}
private String goalsDetail(int AD_Table_ID, Panelchildren panel)
@ -474,27 +478,35 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl
private class UpdateInfoRunnable implements Runnable {
private org.zkoss.zk.ui.Desktop desktop;
private boolean stop = false;
UpdateInfoRunnable(org.zkoss.zk.ui.Desktop desktop) {
this.desktop = desktop;
}
public void run()
{
while(true) {
while(!stop) {
try {
Thread.sleep(60000); // Update every one minutes
} catch (InterruptedException e1) {
if (stop) break;
}
try {
// get full control of desktop
Executions.activate(desktop);
try {
updateInfo();
Threads.sleep(5000);// Update each 5 seconds
updateInfo();
} catch (Error ex) {
throw ex;
logger.log(Level.SEVERE, "UpdateInfo Thread error="+ex.getLocalizedMessage(), ex);
break;
} finally {
// release full control of desktop
Executions.deactivate(desktop);
}
} catch (Exception e) {
logger.log(Level.WARNING, "Failed to run UpdateInfo", e);
}
} catch (Throwable e) {
logger.log(Level.SEVERE, "UpdateInfo Thread error="+e.getLocalizedMessage(), e);
break;
}
}
}
}
@ -984,4 +996,11 @@ public class Desktop extends AbstractUIPart implements MenuListener, Serializabl
public Component getComponent() {
return layout;
}
public void logout() {
if (updateInfoThread != null && updateInfoThread.isAlive()) {
updateInfoRunnable.stop = true;
updateInfoThread.interrupt();
}
}
}

View File

@ -14,11 +14,13 @@ package org.adempiere.webui.component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.table.AbstractTableModel;
import org.adempiere.webui.LayoutUtils;
import org.adempiere.webui.editor.WEditor;
import org.compiere.model.GridField;
import org.compiere.model.GridTab;
import org.compiere.model.GridTable;
@ -298,4 +300,35 @@ public class GridPanel extends Borderlayout implements EventListener
public Listbox getListbox() {
return listbox;
}
public void dynamicDisplay(int col) {
if (!gridTab.isOpen())
{
return;
}
// Selective
if (col > 0)
return;
boolean noData = gridTab.getRowCount() == 0;
List<WEditor> list = renderer.getEditors();
for (WEditor comp : list)
{
GridField mField = comp.getGridField();
if (mField != null && mField.getIncluded_Tab_ID() <= 0)
{
if (noData)
{
comp.setReadWrite(false);
}
else
{
comp.dynamicDisplay();
boolean rw = mField.isEditable(true); // r/w - check Context
comp.setReadWrite(rw);
}
}
} // all components
}
}

View File

@ -14,7 +14,9 @@ package org.adempiere.webui.component;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -116,6 +118,9 @@ public class GridTabListItemRenderer implements ListitemRenderer, ListitemRender
if (editor != null) {
editor.addValueChangeListener(dataBinder);
cell.appendChild(editor.getComponent());
if (editor.getComponent() instanceof Checkbox) {
cell.setStyle("text-align:center");
}
gridField.addPropertyChangeListener(editor);
editor.setValue(gridField.getValue());
WEditorPopupMenu popupMenu = editor.getPopupMenu();
@ -255,4 +260,16 @@ public class GridTabListItemRenderer implements ListitemRenderer, ListitemRender
public boolean isInitialize() {
return !editors.isEmpty();
}
/**
*
* @return active editor list
*/
public List<WEditor> getEditors() {
List<WEditor> editorList = new ArrayList<WEditor>();
if (!editors.isEmpty())
editorList.addAll(editors.values());
return editorList;
}
}

View File

@ -36,7 +36,7 @@ import org.zkoss.zk.ui.event.Events;
*/
public class WAccountEditor extends WEditor
{
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE, Events.ON_FOCUS};
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE};
private MAccountLookup m_mAccount;
@ -173,10 +173,6 @@ public class WAccountEditor extends WEditor
{
cmd_button();
}
else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null)
{
this.setReadWrite(gridField.isEditable(true));
}
}
public String[] getEvents()

View File

@ -23,7 +23,7 @@ public class WAssignmentEditor extends WEditor {
private final static CLogger log = CLogger.getCLogger(WAssignmentEditor.class);
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_FOCUS};
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK};
private boolean m_readWrite;
private Object m_value;
@ -153,10 +153,6 @@ public class WAssignmentEditor extends WEditor {
fireValueChange(vce);
}
}
else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null)
{
this.setReadWrite(gridField.isEditable(true));
}
}
}

View File

@ -26,7 +26,7 @@ import org.zkoss.zk.ui.event.Events;
*/
public class WBinaryEditor extends WEditor
{
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_FOCUS};
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK};
/** Logger */
private static CLogger log = CLogger.getCLogger(WBinaryEditor.class);
@ -127,9 +127,5 @@ public class WBinaryEditor extends WEditor
if (!dialog.isCancel() && dialog.isChange())
m_data = dialog.getData();
}
else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null)
{
this.setReadWrite(gridField.isEditable(true));
}
}
}

View File

@ -48,7 +48,7 @@ import org.zkoss.zk.ui.event.Events;
*/
public class WButtonEditor extends WEditor
{
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_FOCUS};
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK};
private static final CLogger logger;
@ -274,9 +274,5 @@ public class WButtonEditor extends WEditor
evtListener.actionPerformed(actionEvent);
}
}
else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null)
{
this.setReadWrite(gridField.isEditable(true));
}
}
}

View File

@ -37,7 +37,7 @@ import org.zkoss.zk.ui.event.Events;
*/
public class WDateEditor extends WEditor
{
private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE, Events.ON_FOCUS};
private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE};
private static final CLogger logger;
static
@ -119,10 +119,6 @@ public class WDateEditor extends WEditor
super.fireValueChange(changeEvent);
oldValue = newValue;
}
else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null)
{
this.setReadWrite(gridField.isEditable(true));
}
}
@Override

View File

@ -29,7 +29,7 @@ import org.zkoss.zk.ui.event.Events;
*/
public class WDatetimeEditor extends WEditor
{
private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE, Events.ON_FOCUS};
private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE};
private static final CLogger logger;
static
@ -112,10 +112,6 @@ public class WDatetimeEditor extends WEditor
super.fireValueChange(changeEvent);
oldValue = newValue;
}
else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null)
{
this.setReadWrite(gridField.isEditable(true));
}
}
@Override

View File

@ -35,7 +35,7 @@ import org.zkoss.zul.Fileupload;
*/
public class WFilenameEditor extends WEditor
{
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE, Events.ON_FOCUS};
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE};
private static final CLogger log = CLogger.getCLogger(WFilenameEditor.class);
@ -98,10 +98,6 @@ public class WFilenameEditor extends WEditor
{
cmd_file();
}
else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null)
{
this.setReadWrite(gridField.isEditable(true));
}
}
/**

View File

@ -33,7 +33,7 @@ import org.zkoss.zk.ui.event.Events;
*/
public class WImageEditor extends WEditor
{
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_FOCUS};
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK};
private static final CLogger logger;
@ -150,9 +150,5 @@ public class WImageEditor extends WEditor
ValueChangeEvent vce = new ValueChangeEvent(this, gridField.getColumnName(), oldValue, newValue);
fireValueChange(vce);
}
else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null)
{
this.setReadWrite(gridField.isEditable(true));
}
}
}

View File

@ -40,7 +40,7 @@ import org.zkoss.zk.ui.event.Events;
**/
public class WLocationEditor extends WEditor implements EventListener, PropertyChangeListener
{
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_FOCUS};
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK};
private static CLogger log = CLogger.getCLogger(WLocationEditor.class);
private static final long serialVersionUID = 1L;
@ -163,10 +163,6 @@ public class WLocationEditor extends WEditor implements EventListener, PropertyC
}
setValue(ii);
}
else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null)
{
this.setReadWrite(gridField.isEditable(true));
}
}
/**

View File

@ -49,7 +49,7 @@ import org.zkoss.zk.ui.event.Events;
public class WLocatorEditor extends WEditor implements EventListener, PropertyChangeListener
{
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_FOCUS};
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK};
private String m_columnName;
private MLocatorLookup m_mLocator;
@ -216,10 +216,6 @@ public class WLocatorEditor extends WEditor implements EventListener, PropertyCh
return;
setValue (ld.getValue(), true);
}
else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null)
{
this.setReadWrite(gridField.isEditable(true));
}
}
/**

View File

@ -39,7 +39,7 @@ import org.zkoss.zk.ui.event.Events;
*/
public class WNumberEditor extends WEditor
{
public static final String[] LISTENER_EVENTS = {Events.ON_CHANGE, Events.ON_FOCUS};
public static final String[] LISTENER_EVENTS = {Events.ON_CHANGE};
public static final int MAX_DISPLAY_LENGTH = 20;
@ -112,10 +112,6 @@ public class WNumberEditor extends WEditor
super.fireValueChange(changeEvent);
oldValue = newValue;
}
else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null)
{
this.setReadWrite(gridField.isEditable(true));
}
}
@Override

View File

@ -38,7 +38,7 @@ import org.zkoss.zk.ui.event.Events;
*/
public class WPAttributeEditor extends WEditor implements ContextMenuListener
{
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE, Events.ON_FOCUS};
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE};
private static final CLogger log = CLogger.getCLogger(WPAttributeEditor.class);
@ -130,10 +130,6 @@ public class WPAttributeEditor extends WEditor implements ContextMenuListener
{
cmd_dialog();
}
else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null)
{
this.setReadWrite(gridField.isEditable(true));
}
}
/**

View File

@ -56,7 +56,7 @@ import org.zkoss.zk.ui.event.Events;
*/
public class WSearchEditor extends WEditor implements ContextMenuListener, ValueChangeListener, IZoomableEditor
{
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE, Events.ON_OK, Events.ON_FOCUS};
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE, Events.ON_OK};
private Lookup lookup;
private String m_tableName = null;
private String m_keyColumnName = null;
@ -223,11 +223,6 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value
}
actionButton("");
}
else if (Events.ON_FOCUS.equalsIgnoreCase(e.getName()) && gridField != null)
{
this.setReadWrite(gridField.isEditable(true));
}
}
@Override

View File

@ -44,7 +44,7 @@ public class WStringEditor extends WEditor implements ContextMenuListener
{
private static final String EDITOR_EVENT = "EDITOR";
private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE, Events.ON_FOCUS};
private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE};
private String oldText;
@ -157,10 +157,6 @@ public class WStringEditor extends WEditor implements ContextMenuListener
super.fireValueChange(changeEvent);
oldText = newText;
}
else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null)
{
this.setReadWrite(gridField.isEditable(true));
}
}
@Override

View File

@ -50,7 +50,7 @@ import org.zkoss.zk.ui.event.Events;
public class WTableDirEditor extends WEditor implements ListDataListener,
ContextMenuListener, IZoomableEditor
{
public final static String[] LISTENER_EVENTS = {Events.ON_SELECT, Events.ON_FOCUS};
public final static String[] LISTENER_EVENTS = {Events.ON_SELECT};
private static final CLogger logger;
@ -266,10 +266,6 @@ ContextMenuListener, IZoomableEditor
super.fireValueChange(changeEvent);
oldValue = newValue;
}
else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null)
{
this.setReadWrite(gridField.isEditable(true));
}
}
public String[] getEvents()

View File

@ -30,7 +30,7 @@ import org.zkoss.zul.Timebox;
*/
public class WTimeEditor extends WEditor
{
private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE, Events.ON_FOCUS};
private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE};
private static final CLogger logger;
static
@ -104,10 +104,6 @@ public class WTimeEditor extends WEditor
super.fireValueChange(changeEvent);
oldValue = newValue;
}
else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null)
{
this.setReadWrite(gridField.isEditable(true));
}
}
@Override

View File

@ -29,7 +29,7 @@ import org.zkoss.zk.ui.event.Events;
public class WUrlEditor extends WEditor
{
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE, Events.ON_FOCUS};
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE};
public WUrlEditor(GridField gridField)
{
@ -108,10 +108,6 @@ public class WUrlEditor extends WEditor
FDialog.warn(0, this.getComponent(), "URLnotValid", message);
}
else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null)
{
this.setReadWrite(gridField.isEditable(true));
}
}
public String[] getEvents()

View File

@ -37,7 +37,7 @@ import org.zkoss.zk.ui.event.Events;
*/
public class WYesNoEditor extends WEditor
{
public static final String[] LISTENER_EVENTS = {Events.ON_CHECK, Events.ON_FOCUS};
public static final String[] LISTENER_EVENTS = {Events.ON_CHECK};
private static final CLogger logger;
static
@ -69,10 +69,6 @@ public class WYesNoEditor extends WEditor
super.fireValueChange(changeEvent);
oldValue = newValue;
}
else if (Events.ON_FOCUS.equalsIgnoreCase(event.getName()) && gridField != null)
{
this.setReadWrite(gridField.isEditable(true));
}
}
public void propertyChange(PropertyChangeEvent evt)

View File

@ -493,31 +493,7 @@ DataStatusListener, IADTabpanel
// Selective
if (col > 0)
{
GridField changedField = gridTab.getField(col);
String columnName = changedField.getColumnName();
ArrayList<GridField> dependants = gridTab.getDependantFields(columnName);
logger.config("(" + gridTab.toString() + ") "
+ columnName + " - Dependents=" + dependants.size());
if (dependants.size() == 0 && changedField.getCallout().length() > 0)
{
for (WEditor comp : editors)
{
if (columnName.equals(comp.getColumnName()))
{
boolean manMissing = false;
boolean noValue = changedField.getValue() == null || changedField.getValue().toString().length() == 0;
if (noValue && changedField.isEditable(true) && changedField.isMandatory(true))
{
manMissing = true;
}
comp.setBackground(manMissing || changedField.isError());
break;
}
}
return;
}
}
return;
boolean noData = gridTab.getRowCount() == 0;
logger.config(gridTab.toString() + " - Rows=" + gridTab.getRowCount());
@ -802,6 +778,7 @@ DataStatusListener, IADTabpanel
if (listPanel.isVisible()) {
listPanel.updateListIndex();
listPanel.dynamicDisplay(col);
}
if (!includedPanel.isEmpty()) {

View File

@ -230,6 +230,8 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
for (int tab = 0; tab < tabSize; tab++)
{
initTab(query, tab);
if (tab == 0 && curTab == null && m_findCancelled)
return false;
}
Env.setContext(ctx, curWindowNo, "WindowName", gridWindow.getName());
}
@ -238,7 +240,9 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To
initEmbeddedTab(query, embeddedTabindex);
}
curTab.getTableModel().setChanged(false);
if (curTab != null)
curTab.getTableModel().setChanged(false);
if (embeddedTabindex < 0)
{
curTabIndex = 0;