- simple preference support, pending translation work
This commit is contained in:
Heng Sin Low 2009-05-22 00:37:43 +00:00
parent 2e18141da5
commit f0ec1f2bc8
5 changed files with 248 additions and 41 deletions

View File

@ -26,6 +26,7 @@ import org.compiere.model.GridField;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.Events;
@ -39,25 +40,35 @@ public class WYesNoEditor extends WEditor
{
public static final String[] LISTENER_EVENTS = {Events.ON_CHECK};
private static final CLogger logger;
static
{
logger = CLogger.getCLogger(WYesNoEditor.class);
}
private boolean oldValue = false;
public WYesNoEditor(GridField gridField)
{
super(new Checkbox(), gridField);
init();
}
private void init()
public WYesNoEditor(String columnName, String label,
String description, boolean mandatory, boolean readonly,
boolean updateable) {
super(new Checkbox(), columnName, label, description, mandatory, readonly, updateable);
init();
}
private void init()
{
super.label.setValue("");
super.label.setTooltiptext("");
getComponent().setLabel(gridField.getHeader());
if (gridField != null)
getComponent().setLabel(gridField.getHeader());
else
getComponent().setLabel(label.getValue());
label.setValue("");
label.setTooltiptext("");
}
public void onEvent(Event event)
@ -111,13 +122,13 @@ public class WYesNoEditor extends WEditor
else
{
logger.log(Level.SEVERE,
"New field value of unknown type, Type: "
"New field value of unknown type, Type: "
+ value.getClass()
+ ", Value: " + value);
getComponent().setChecked(false);
}
}
@Override
public Checkbox getComponent() {
return (Checkbox) component;

View File

@ -20,11 +20,11 @@ package org.adempiere.webui.panel;
import java.util.Properties;
import org.adempiere.webui.LayoutUtils;
import org.adempiere.webui.component.Grid;
import org.adempiere.webui.component.Label;
import org.adempiere.webui.component.Messagebox;
import org.adempiere.webui.component.ToolBarButton;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.window.WPreference;
import org.compiere.model.MClient;
import org.compiere.model.MOrg;
import org.compiere.model.MRole;
@ -46,77 +46,87 @@ import org.zkoss.zul.Vbox;
*/
public class UserPanel extends Vbox implements EventListener
{
/**
*
*/
private static final long serialVersionUID = 5340541881809458772L;
private static final long serialVersionUID = -45350536628290540L;
private Properties ctx;
private Grid grid;
private ToolBarButton logout = new ToolBarButton();
private ToolBarButton role = new ToolBarButton();
private ToolBarButton preference = new ToolBarButton();
private Label lblUserNameValue = new Label();
private WPreference preferencePopup;
public UserPanel()
{
this.ctx = Env.getCtx();
init();
}
private void init()
{
this.setStyle("text-align:right");
// Elaine 2008/11/07 - fix the layout problem in IE7
this.setWidth("100%");
this.setAlign("right");
//
lblUserNameValue.setValue(getUserName() + "@" + getClientName() + "." + getOrgName());
lblUserNameValue.setStyle("text-align:right");
LayoutUtils.addSclass("headerFont", lblUserNameValue);
this.appendChild(lblUserNameValue);
Hbox hbox = new Hbox();
preference.setLabel(Msg.getMsg(Env.getCtx(), "Preference"));
preference.addEventListener(Events.ON_CLICK, this);
preference.setStyle("text-align:right");
LayoutUtils.addSclass("headerFont", preference);
preference.setParent(hbox);
Separator sep = new Separator("vertical");
sep.setBar(true);
sep.setParent(hbox);
role.setLabel(this.getRoleName());
role.addEventListener(Events.ON_CLICK, this);
role.setStyle("text-align:right");
LayoutUtils.addSclass("headerFont", role);
role.setParent(hbox);
Separator sep = new Separator("vertical");
sep = new Separator("vertical");
sep.setBar(true);
sep.setParent(hbox);
logout.setLabel(Msg.getMsg(Env.getCtx(),"Logout"));
logout.addEventListener(Events.ON_CLICK, this);
logout.setStyle("text-align:right");
LayoutUtils.addSclass("headerFont", logout);
logout.setParent(hbox);
this.appendChild(hbox);
this.appendChild(hbox);
}
private String getUserName()
{
MUser user = MUser.get(ctx);
return user.getName();
}
private String getRoleName()
{
MRole role = MRole.getDefault(ctx, false);
return role.getName();
}
private String getClientName()
{
MClient client = MClient.get(ctx);
return client.getName();
}
private String getOrgName()
{
int orgId = Env.getAD_Org_ID(ctx);
@ -134,7 +144,7 @@ public class UserPanel extends Vbox implements EventListener
public void onEvent(Event event) throws Exception {
if (event == null)
return;
if (logout == event.getTarget())
{
SessionManager.logoutSession();
@ -145,6 +155,16 @@ public class UserPanel extends Vbox implements EventListener
roleInfo = roleInfo.replace(Env.NL, "<br>");
Messagebox.showDialog(roleInfo, "Role Info", Messagebox.OK, Messagebox.INFORMATION);
}
else if (preference == event.getTarget())
{
if (preferencePopup != null)
{
preferencePopup.detach();
}
preferencePopup = new WPreference();
preferencePopup.setPage(this.getPage());
preferencePopup.open(preference);
}
}
}

View File

@ -0,0 +1,33 @@
/******************************************************************************
* Copyright (C) 2009 Low Heng Sin *
* Copyright (C) 2009 Idalica Corporation *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.adempiere.webui.util;
import java.util.Properties;
import org.compiere.model.MPreference;
/**
*
* @author hengsin
*
*/
public class MUserPreference extends MPreference {
private static final long serialVersionUID = -3424015890197944847L;
public MUserPreference(Properties ctx, int AD_Preference_ID, String trxName) {
super(ctx, AD_Preference_ID, trxName);
setClientOrg(0, 0);
}
}

View File

@ -31,9 +31,6 @@ import org.compiere.util.Language;
*/
public final class UserPreference implements Serializable {
/**
*
*/
private static final long serialVersionUID = 4965009332046125297L;
/** Language */
public static final String P_LANGUAGE = "Language";
@ -115,12 +112,14 @@ public final class UserPreference implements Serializable {
MPreference preference = query.setParameters(new Object[]{m_AD_User_ID, attribute}).firstOnly();
if (preference == null) {
preference = new MPreference(Env.getCtx(), 0, null);
preference = new MUserPreference(Env.getCtx(), 0, null);
preference.setAD_User_ID(m_AD_User_ID);
preference.setAD_Org_ID(0);
preference.setAttribute(attribute);
} else {
if (preference.getAD_Client_ID() > 0 || preference.getAD_Org_ID() > 0) {
preference = new MUserPreference(Env.getCtx(), preference.getAD_Preference_ID(), null);
}
}
preference.setAD_Org_ID(0);
preference.setValue(value);
preference.saveEx();
}

View File

@ -0,0 +1,144 @@
/******************************************************************************
* Copyright (C) 2009 Low Heng Sin *
* Copyright (C) 2009 Idalica Corporation *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.adempiere.webui.window;
import org.adempiere.webui.component.Label;
import org.adempiere.webui.component.Listbox;
import org.adempiere.webui.component.ListboxFactory;
import org.adempiere.webui.component.ToolBar;
import org.adempiere.webui.component.ToolBarButton;
import org.adempiere.webui.editor.WYesNoEditor;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.util.UserPreference;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Div;
import org.zkoss.zul.Popup;
import org.zkoss.zul.Separator;
import org.zkoss.zul.Space;
/**
*
* @author hengsin
*
*/
public class WPreference extends Popup implements EventListener {
private static final long serialVersionUID = 7163067116469715021L;
private WYesNoEditor autoCommit;
private WYesNoEditor autoNew;
private WYesNoEditor tabCollapsible;
private Listbox tabPlacement;
public WPreference() {
super();
init();
}
private void init() {
this.setStyle("padding: 5px");
Div div = new Div();
div.setStyle("background-color: transparent !important; border: none; margin: 5px;");
autoCommit = new WYesNoEditor("AutoCommit", Msg.getMsg(Env.getCtx(), "AutoCommit", true),
null, false, false, true);
div.appendChild(autoCommit.getComponent());
autoCommit.getComponent().setTooltiptext(Msg.getMsg(Env.getCtx(), "AutoCommit", false));
this.appendChild(div);
autoNew = new WYesNoEditor("AutoNew", Msg.getMsg(Env.getCtx(), "AutoNew", true),
null, false, false, true);
autoNew.getComponent().setTooltiptext(Msg.getMsg(Env.getCtx(), "AutoNew", false));
div = new Div();
div.setStyle("background-color: transparent !important; border: none; margin: 5px;");
div.appendChild(autoNew.getComponent());
this.appendChild(div);
tabCollapsible = new WYesNoEditor("WindowTabCollapsible", Msg.getMsg(Env.getCtx(), "WindowTabCollapsible", true),
null, false, false, true);
tabCollapsible.getComponent().setTooltiptext(Msg.getMsg(Env.getCtx(), "WindowTabCollapsible", false));
div = new Div();
div.setStyle("background-color: transparent !important; border: none; margin: 5px;");
div.appendChild(tabCollapsible.getComponent());
this.appendChild(div);
div = new Div();
div.setStyle("background-color: transparent !important; border: none; margin: 5px;");
Label label = new Label(Msg.getMsg(Env.getCtx(), "WindowTabPlacement"));
div.appendChild(label);
div.appendChild(new Space());
tabPlacement = ListboxFactory.newDropdownListbox();
tabPlacement.appendItem("Left", "Left");
tabPlacement.appendItem("Right", "Right");
div.appendChild(tabPlacement);
this.appendChild(div);
Separator separator = new Separator();
separator.setSpacing("20px");
div = new Div();
div.setStyle("background-color: transparent !important; border: none; margin: 5px;");
div.appendChild(separator);
this.appendChild(div);
ToolBar toolbar = new ToolBar();
toolbar.setAlign("end");
this.appendChild(toolbar);
ToolBarButton btn = new ToolBarButton("");
btn.setName("btnSave");
btn.setImage("/images/Save24.png");
btn.setTooltiptext(Msg.getMsg(Env.getCtx(),"Save"));
btn.addEventListener(Events.ON_CLICK, this);
toolbar.appendChild(btn);
UserPreference preference = SessionManager.getSessionApplication().getUserPreference();
autoCommit.setValue(preference.getProperty(UserPreference.P_AUTO_COMMIT));
autoNew.setValue(preference.getProperty(UserPreference.P_AUTO_NEW));
tabCollapsible.setValue(preference.getProperty(UserPreference.P_WINDOW_TAB_COLLAPSIBLE));
tabPlacement.setValue(preference.getProperty(UserPreference.P_WINDOW_TAB_PLACEMENT));
}
public void onEvent(Event event) throws Exception {
if (Events.ON_CLICK.equals(event.getName())) {
// if (event.getTarget().getId().equals(ConfirmPanel.A_CANCEL)) {
// this.detach();
// } else if (event.getTarget().getId().equals(ConfirmPanel.A_OK)) {
// onSave();
// }
onSave();
}
}
private void onSave() {
UserPreference preference = SessionManager.getSessionApplication().getUserPreference();
preference.setProperty(UserPreference.P_AUTO_COMMIT,
(Boolean)autoCommit.getValue() ? "Y" : "N");
preference.setProperty(UserPreference.P_AUTO_NEW,
(Boolean)autoNew.getValue() ? "Y" : "N");
preference.setProperty(UserPreference.P_WINDOW_TAB_COLLAPSIBLE,
(Boolean)tabCollapsible.getValue() ? "Y" : "N");
preference.setProperty(UserPreference.P_WINDOW_TAB_PLACEMENT,
(String)tabPlacement.getSelectedItem().getValue());
preference.savePreference();
//update context
Env.setAutoCommit(Env.getCtx(), "y".equalsIgnoreCase(preference.getProperty(UserPreference.P_AUTO_COMMIT)));
Env.setAutoNew(Env.getCtx(), "y".equalsIgnoreCase(preference.getProperty(UserPreference.P_AUTO_NEW)));
this.detach();
}
}