[ adempiere-ZK Web Client-2787754 ] UserPreferemce should save with ad_org_id = 0

[ adempiere-ZK Web Client-2787755 ] Add WindowTabPlacement user preference
This commit is contained in:
Heng Sin Low 2009-05-06 09:39:36 +00:00
parent f009f414c6
commit 39e39490c0
5 changed files with 157 additions and 95 deletions

View File

@ -24,25 +24,41 @@ import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
/**
*
*
* @author <a href="mailto:hengsin@gmail.com">Low Heng Sin</a>
*
*/
public class ADButtonTabList extends Panel implements IADTabList, EventListener {
/**
*
*
*/
private static final long serialVersionUID = -9203013067784673646L;
private List<ADTabLabel> listItems = new ArrayList<ADTabLabel>();
private List<EventListener> listeners = new ArrayList<EventListener>();
private List<EventListener> listeners = new ArrayList<EventListener>();
private IADTab tabbox;
private int selectedIndex = 0;
private int tabPlacement = IADTab.LEFT;
public ADButtonTabList() {
this.setStyle("margin:0;padding:0");
}
/**
* Set tab placement ( left or right )
* @param tabPlacement
*/
public void setTabplacement(int tabPlacement) {
if (tabPlacement != IADTab.LEFT && tabPlacement != IADTab.RIGHT)
return;
else if (tabPlacement == this.tabPlacement)
return;
else {
this.tabPlacement = tabPlacement;
this.invalidate();
}
}
public synchronized void refresh() {
List childs = getChildren();
int childCount = childs.size();
@ -56,7 +72,7 @@ public class ADButtonTabList extends Panel implements IADTabList, EventListener
Text text = new Text(tabLabel.label);
button.appendChild(text);
int s = tabbox.getSelectedIndex();
if ( s == i) {
button.setSclass("adwindow-navbtn-sel");
button.setDynamicProperty("disabled", null);
@ -64,7 +80,7 @@ public class ADButtonTabList extends Panel implements IADTabList, EventListener
if (!tabbox.canNavigateTo(s, i)) {
button.setDynamicProperty("disabled", "disabled");
button.setSclass("adwindow-navbtn-dis");
if (!tabbox.isDisplay(i))
if (!tabbox.isDisplay(i))
button.setVisible(false);
else
button.setVisible(true);
@ -74,12 +90,12 @@ public class ADButtonTabList extends Panel implements IADTabList, EventListener
button.setVisible(true);
}
}
String style = "margin-left:" + (tabLabel.tabLevel*15+5) + "px";
String style = (tabPlacement == IADTab.LEFT ? "margin-left:" : "margin-right:") + (tabLabel.tabLevel*15+5) + "px";
String width = (195 - tabLabel.tabLevel*15)+"px";
style = style + "; width:" + width;
style = style + "; width:" + width;
button.setStyle(style);
button.setParent(this);
button.addEventListener(Events.ON_CLICK, this);
}
@ -90,22 +106,22 @@ public class ADButtonTabList extends Panel implements IADTabList, EventListener
}
public void setSelectedIndex(int index) {
this.selectedIndex = index;
this.selectedIndex = index;
}
public synchronized void setItems(List<ADTabLabel> listItems) {
this.listItems = listItems;
refresh();
}
public void setADTab(IADTab adTab) {
this.tabbox = adTab;
}
public void addSelectionEventListener(EventListener listener) {
public void addSelectionEventListener(EventListener listener) {
listeners.add(listener);
}
public boolean removeSelectionEventListener(EventListener listener) {
return listeners.remove(listener);
}
@ -121,10 +137,10 @@ public class ADButtonTabList extends Panel implements IADTabList, EventListener
}
i++;
}
selectedIndex = i;
for (EventListener listener : listeners) {
listener.onEvent(selectEvent);
}
}
}
}

View File

@ -40,19 +40,19 @@ public class CompositeADTab extends AbstractADTab
{
/** Logger */
private static CLogger log = CLogger.getCLogger (CompositeADTab.class);
private List<ADTabListModel.ADTabLabel> tabLabelList = new ArrayList<ADTabListModel.ADTabLabel>();
private Div div;
protected ADButtonTabList tabList;
public CompositeADTab()
{
tabList = new ADButtonTabList();
tabList.setADTab(this);
}
protected Component doCreatePart(Component parent)
{
div= new Div();
@ -64,14 +64,14 @@ public class CompositeADTab extends AbstractADTab
}
return div;
}
@Override
protected void doAddTab(GridTab gTab, IADTabpanel tabPanel) {
tabPanel.setParent(div);
tabPanel.setVisible(false);
ADTabListModel.ADTabLabel tabLabel = new ADTabListModel.ADTabLabel(gTab.getName(), gTab.getTabLevel());
tabLabelList.add(tabLabel);
tabLabelList.add(tabLabel);
}
/**
@ -81,11 +81,11 @@ public class CompositeADTab extends AbstractADTab
public void evaluate (DataStatusEvent e)
{
tabList.setItems(tabLabelList);
super.evaluate(e);
} // evaluate
@Override
protected void updateTabState() {
tabList.refresh();
@ -102,7 +102,7 @@ public class CompositeADTab extends AbstractADTab
}
return null;
}
public int getSelectedIndex() {
for(int i = 0; i < tabPanelList.size(); i++) {
if (tabPanelList.get(i).isVisible())
@ -110,11 +110,11 @@ public class CompositeADTab extends AbstractADTab
}
return -1;
}
public void addSelectionEventListener(EventListener listener) {
tabList.addSelectionEventListener(listener);
}
public Component getTabSelectionComponent() {
return tabList;
}
@ -128,7 +128,7 @@ public class CompositeADTab extends AbstractADTab
}
newTabpanel.createUI();
newTabpanel.setVisible(true);
if (tabList.getSelectedIndex() != newIndex)
tabList.setSelectedIndex(newIndex);
}
@ -139,5 +139,12 @@ public class CompositeADTab extends AbstractADTab
public Component getComponent() {
return div;
}
}
/**
* @param tabPlacement
*/
public void setTabplacement(int tabPlacement) {
tabList.setTabplacement(tabPlacement);
}
}

View File

@ -20,44 +20,44 @@ import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.EventListener;
/**
*
*
* @author <a href="mailto:hengsin@gmail.com">Low Heng Sin</a>
*
*/
public interface IADTab extends UIPart {
/**
*
*
* @return selected tab index
*/
public int getSelectedIndex();
/**
*
*
* @param tab index
*/
public void setSelectedIndex(int i);
/**
* @param oldTabIndex
* @param newTabIndex
* @return
*/
public boolean updateSelectedIndex(int oldTabIndex, int newTabIndex);
/**
* @return selected tab panel reference
*/
public IADTabpanel getSelectedTabpanel();
/**
*
*
* @param fromIndex
* @param toIndex
* @return boolean
*/
public boolean canNavigateTo(int fromIndex, int toIndex);
/**
* @param index
* @return boolean
@ -65,7 +65,7 @@ public interface IADTab extends UIPart {
public boolean isDisplay(int index);
/**
*
*
* @param tab
* @param tabPanel
*/
@ -87,7 +87,7 @@ public interface IADTab extends UIPart {
public String getPath();
/**
*
*
* @param listener
*/
public void addSelectionEventListener(EventListener listener);
@ -96,7 +96,7 @@ public interface IADTab extends UIPart {
* @return tab selection component
*/
public Component getTabSelectionComponent();
/**
* @return boolean
*/
@ -106,5 +106,17 @@ public interface IADTab extends UIPart {
* @param index
* @return IADTabpanel
*/
public IADTabpanel getADTabpanel(int index);
public IADTabpanel getADTabpanel(int index);
/**
* constant for tab placement
*/
public final int LEFT = 0;
public final int RIGHT = 1;
/**
* Set tab placement ( left or right )
* @param tabPlacement
*/
public void setTabplacement(int tabPlacement);
}

View File

@ -27,6 +27,7 @@ import org.adempiere.webui.component.Tabbox;
import org.adempiere.webui.component.Tabpanel;
import org.adempiere.webui.component.Tabs;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.util.UserPreference;
import org.compiere.model.GridWindow;
import org.compiere.model.MQuery;
import org.compiere.util.CLogger;
@ -39,16 +40,17 @@ import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.KeyEvent;
import org.zkoss.zkex.zul.Borderlayout;
import org.zkoss.zkex.zul.Center;
import org.zkoss.zkex.zul.East;
import org.zkoss.zkex.zul.North;
import org.zkoss.zkex.zul.South;
import org.zkoss.zkex.zul.West;
import org.zkoss.zul.Tab;
/**
*
*
* This class is based on org.compiere.apps.APanel written by Jorg Janke.
* @author Jorg Janke
*
*
* @author <a href="mailto:agramdass@gmail.com">Ashley G Ramdass</a>
* @author <a href="mailto:hengsin@gmail.com">Low Heng Sin</a>
* @date Feb 25, 2007
@ -69,14 +71,16 @@ public class ADWindowPanel extends AbstractADWindowPanel
private West west;
private East east;
private Keylistener keyListener;
public ADWindowPanel(Properties ctx, int windowNo)
{
super(ctx, windowNo);
}
public ADWindowPanel(Properties ctx, int windowNo, GridWindow gridWindow,
int tabIndex, IADTabpanel tabPanel) {
super(ctx, windowNo, gridWindow, tabIndex, tabPanel);
@ -84,7 +88,7 @@ public class ADWindowPanel extends AbstractADWindowPanel
protected Component doCreatePart(Component parent)
{
{
layout = new Borderlayout();
if (parent != null) {
layout.setParent(parent);
@ -94,7 +98,7 @@ public class ADWindowPanel extends AbstractADWindowPanel
} else {
layout.setPage(page);
}
if (!isEmbedded())
{
North n = new North();
@ -105,35 +109,50 @@ public class ADWindowPanel extends AbstractADWindowPanel
toolbar.setParent(n);
toolbar.setWindowNo(getWindowNo());
}
South s = new South();
South s = new South();
layout.appendChild(s);
s.setCollapsible(false);
statusBar.setParent(s);
LayoutUtils.addSclass("adwindow-status", statusBar);
if (!isEmbedded() && adTab.isUseExternalSelection())
{
west = new West();
layout.appendChild(west);
west.setSplittable(false);
west.setAutoscroll(true);
LayoutUtils.addSclass("adwindow-nav", west);
adTab.getTabSelectionComponent().setParent(west);
String tabPlacement = SessionManager.getSessionApplication().getUserPreference().getProperty(UserPreference.P_WINDOW_TAB_PLACEMENT);
if (tabPlacement == null || "left".equalsIgnoreCase(tabPlacement))
{
west = new West();
layout.appendChild(west);
west.setSplittable(false);
west.setAutoscroll(true);
LayoutUtils.addSclass("adwindow-nav", west);
adTab.setTabplacement(IADTab.LEFT);
adTab.getTabSelectionComponent().setParent(west);
}
else
{
east = new East();
layout.appendChild(east);
east.setSplittable(false);
east.setAutoscroll(true);
LayoutUtils.addSclass("adwindow-nav", east);
adTab.setTabplacement(IADTab.RIGHT);
adTab.getTabSelectionComponent().setParent(east);
}
LayoutUtils.addSclass("adwindow-nav-content", (HtmlBasedComponent) adTab.getTabSelectionComponent());
}
contentArea = new Center();
contentArea.setParent(layout);
contentArea.setAutoscroll(true);
contentArea.setFlex(true);
adTab.createPart(contentArea);
if (parent instanceof Tabpanel) {
TabOnCloseHanlder handler = new TabOnCloseHanlder();
((Tabpanel)parent).setOnCloseHandler(handler);
}
if (!isEmbedded()) {
if (keyListener != null)
keyListener.detach();
@ -143,7 +162,7 @@ public class ADWindowPanel extends AbstractADWindowPanel
keyListener.addEventListener(Events.ON_CTRL_KEY, toolbar);
keyListener.addEventListener(Events.ON_CTRL_KEY, this);
}
return layout;
}
@ -156,9 +175,9 @@ public class ADWindowPanel extends AbstractADWindowPanel
public Borderlayout getComponent() {
return layout;
}
@Override
public boolean initPanel(int adWindowId, MQuery query) {
boolean retValue = super.initPanel(adWindowId, query);
@ -188,7 +207,7 @@ public class ADWindowPanel extends AbstractADWindowPanel
}
class TabOnCloseHanlder implements ITabOnCloseHandler {
public void onClose(Tabpanel tabPanel) {
if (ADWindowPanel.this.onExit()) {
Tab tab = tabPanel.getLinkedTab();
@ -198,7 +217,7 @@ public class ADWindowPanel extends AbstractADWindowPanel
List childs = tabs.getChildren();
for(int i = 0; i < childs.size(); i++) {
if (childs.get(i) == tab) {
if (i > 0)
if (i > 0)
tabbox.setSelectedIndex((i-1));
break;
}
@ -206,7 +225,7 @@ public class ADWindowPanel extends AbstractADWindowPanel
}
tabPanel.detach();
tab.detach();
if (getWindowNo() > 0)
if (getWindowNo() > 0)
SessionManager.getAppDesktop().unregisterWindow(getWindowNo());
}
}

View File

@ -24,15 +24,15 @@ import org.compiere.util.Env;
import org.compiere.util.Language;
/**
*
*
* @author hengsin
* @author Teo Sarca, www.arhipac.ro
* <li>FR [ 2694043 ] Query. first/firstOnly usage best practice
*/
public final class UserPreference implements Serializable {
/**
*
*
*/
private static final long serialVersionUID = -1792570749461784394L;
/** Language */
@ -51,30 +51,36 @@ public final class UserPreference implements Serializable {
/** Warehouse Name */
public static final String P_WAREHOUSE = "Warehouse";
private static final String DEFAULT_WAREHOUSE = "";
/** Auto Commit */
public static final String P_AUTO_COMMIT = "AutoCommit";
private static final String DEFAULT_AUTO_COMMIT = "Y";
/** Language Name Context **/
public static final String LANGUAGE_NAME = "#LanguageName";
/** window tab placement **/
public static final String P_WINDOW_TAB_PLACEMENT = "WindowTabPlacement";
public static final String DEFAULT_WINDOW_TAB_PLACEMENT = "Left";
/** Ini Properties */
private static final String[] PROPERTIES = new String[] {
private static final String[] PROPERTIES = new String[] {
P_LANGUAGE,
P_ROLE,
P_ROLE,
P_CLIENT,
P_ORG,
P_ORG,
P_WAREHOUSE,
P_AUTO_COMMIT};
P_AUTO_COMMIT,
P_WINDOW_TAB_PLACEMENT};
/** Ini Property Values */
private static final String[] VALUES = new String[] {
private static final String[] VALUES = new String[] {
DEFAULT_LANGUAGE,
DEFAULT_ROLE,
DEFAULT_CLIENT,
DEFAULT_ORG,
DEFAULT_CLIENT,
DEFAULT_ORG,
DEFAULT_WAREHOUSE,
DEFAULT_AUTO_COMMIT};
DEFAULT_AUTO_COMMIT,
DEFAULT_WINDOW_TAB_PLACEMENT};
/** Container for Properties */
private Properties props = new Properties();
@ -95,12 +101,14 @@ public final class UserPreference implements Serializable {
String attribute = PROPERTIES[i];
String value = props.getProperty(attribute);
MPreference preference = query.setParameters(new Object[]{m_AD_User_ID, attribute}).firstOnly();
MPreference preference = query.setParameters(new Object[]{m_AD_User_ID, attribute}).firstOnly();
if (preference == null) {
preference = new MPreference(Env.getCtx(), 0, null);
preference = new MPreference(Env.getCtx(), 0, null);
preference.setAD_User_ID(m_AD_User_ID);
preference.setAD_Org_ID(0);
preference.setAttribute(attribute);
}
preference.setAD_Org_ID(0);
preference.setValue(value);
preference.saveEx();
}
@ -125,8 +133,8 @@ public final class UserPreference implements Serializable {
MPreference preference = query.setParameters(new Object[]{m_AD_User_ID, attribute}).firstOnly();
if (preference != null) {
value = preference.getValue();
}
}
props.setProperty(attribute, value);
}
}
@ -153,7 +161,7 @@ public final class UserPreference implements Serializable {
/***************************************************************************
* Set Property
*
*
* @param key
* Key
* @param value
@ -170,7 +178,7 @@ public final class UserPreference implements Serializable {
/**
* Set Property
*
*
* @param key
* Key
* @param value
@ -182,7 +190,7 @@ public final class UserPreference implements Serializable {
/**
* Set Property
*
*
* @param key
* Key
* @param value
@ -194,7 +202,7 @@ public final class UserPreference implements Serializable {
/**
* Get Propery
*
*
* @param key
* Key
* @return Value
@ -211,7 +219,7 @@ public final class UserPreference implements Serializable {
/**
* Get Propery as Boolean
*
*
* @param key
* Key
* @return Value