diff --git a/migration/i1.0a-release/oracle/201303261217_IDEMPIERE-800.sql b/migration/i1.0a-release/oracle/201303261217_IDEMPIERE-800.sql new file mode 100644 index 0000000000..aec498f95f --- /dev/null +++ b/migration/i1.0a-release/oracle/201303261217_IDEMPIERE-800.sql @@ -0,0 +1,8 @@ +-- Mar 26, 2013 8:15:58 PM MYT +-- IDEMPIERE-800 Zk: Add API for consistent button style +INSERT INTO AD_SysConfig (AD_SysConfig_ID,EntityType,ConfigurationLevel,Value,Description,AD_SysConfig_UU,Created,Updated,AD_Client_ID,AD_Org_ID,CreatedBy,IsActive,UpdatedBy,Name) VALUES (200029,'D','S','I','T-Text, I-Image, IT-Image and Text','c86d55be-3ae7-425e-a828-8f6cb1a6977c',TO_DATE('2013-03-26 20:15:56','YYYY-MM-DD HH24:MI:SS'),TO_DATE('2013-03-26 20:15:56','YYYY-MM-DD HH24:MI:SS'),0,0,100,'Y',100,'ZK_BUTTON_STYLE') +; + +SELECT register_migration_script('201303261217_IDEMPIERE-800.sql') FROM dual +; + diff --git a/migration/i1.0a-release/postgresql/201303261217_IDEMPIERE-800.sql b/migration/i1.0a-release/postgresql/201303261217_IDEMPIERE-800.sql new file mode 100644 index 0000000000..62d4bbeabc --- /dev/null +++ b/migration/i1.0a-release/postgresql/201303261217_IDEMPIERE-800.sql @@ -0,0 +1,8 @@ +-- Mar 26, 2013 8:15:58 PM MYT +-- IDEMPIERE-800 Zk: Add API for consistent button style +INSERT INTO AD_SysConfig (AD_SysConfig_ID,EntityType,ConfigurationLevel,Value,Description,AD_SysConfig_UU,Created,Updated,AD_Client_ID,AD_Org_ID,CreatedBy,IsActive,UpdatedBy,Name) VALUES (200029,'D','S','I','T-Text, I-Image, IT-Image and Text','c86d55be-3ae7-425e-a828-8f6cb1a6977c',TO_TIMESTAMP('2013-03-26 20:15:56','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2013-03-26 20:15:56','YYYY-MM-DD HH24:MI:SS'),0,0,100,'Y',100,'ZK_BUTTON_STYLE') +; + +SELECT register_migration_script('201303261217_IDEMPIERE-800.sql') FROM dual +; + diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessDialog.java index 049f6bd687..ba543636c1 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessDialog.java @@ -23,9 +23,11 @@ import org.adempiere.util.ServerContext; import org.adempiere.webui.AdempiereWebUI; import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.component.Button; +import org.adempiere.webui.component.ConfirmPanel; import org.adempiere.webui.component.Panel; import org.adempiere.webui.component.Window; import org.adempiere.webui.desktop.IDesktop; +import org.adempiere.webui.factory.ButtonFactory; import org.adempiere.webui.part.WindowContainer; import org.adempiere.webui.process.WProcessInfo; import org.adempiere.webui.session.SessionManager; @@ -175,20 +177,14 @@ public class ProcessDialog extends Window implements EventListener, IProc @SuppressWarnings("unused") String label = Msg.getMsg(Env.getCtx(), "Start"); // Invert - Unify OK/Cancel IDEMPIERE-77 - //bOK = new Button(label.replaceAll("&", "")); - bOK = new Button(); - bOK.setImage(ThemeManager.getThemeResource("images/Ok16.png")); + bOK = ButtonFactory.createNamedButton(ConfirmPanel.A_OK); bOK.setId("Ok"); bOK.addEventListener(Events.ON_CLICK, this); - bOK.setSclass("action-image-text-button"); hbox.appendChild(bOK); - //label = Msg.getMsg(Env.getCtx(), "Cancel"); - Button btn = new Button(); - btn.setImage(ThemeManager.getThemeResource("images/Cancel16.png")); + Button btn = ButtonFactory.createNamedButton(ConfirmPanel.A_CANCEL); btn.setId("Cancel"); btn.addEventListener(Events.ON_CLICK, this); - btn.setSclass("action-image-text-button"); hbox.appendChild(btn); div.appendChild(hbox); div.setStyle("padding: 10px; text-align: center; text-align: -webkit-center; text-align: -moz-center; "); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessModalDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessModalDialog.java index c1e17314e2..e2294304af 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessModalDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessModalDialog.java @@ -33,11 +33,12 @@ import org.adempiere.util.ServerContext; import org.adempiere.webui.AdempiereWebUI; import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.component.Button; +import org.adempiere.webui.component.ConfirmPanel; import org.adempiere.webui.component.Panel; import org.adempiere.webui.component.VerticalBox; import org.adempiere.webui.component.Window; import org.adempiere.webui.event.DialogEvents; -import org.adempiere.webui.theme.ThemeManager; +import org.adempiere.webui.factory.ButtonFactory; import org.adempiere.webui.window.FDialog; import org.adempiere.webui.window.MultiFileDownloadDialog; import org.compiere.Adempiere; @@ -176,17 +177,13 @@ public class ProcessModalDialog extends Window implements EventListener, Hbox hbox = new Hbox(); hbox.setWidth("100%"); hbox.setStyle("margin-top: 10px"); - Button btn = new Button(""); - btn.setImage(ThemeManager.getThemeResource("images/Ok24.png")); - LayoutUtils.addSclass("action-button", btn); + Button btn = ButtonFactory.createNamedButton(ConfirmPanel.A_OK); btn.setId("Ok"); btn.addEventListener(Events.ON_CLICK, this); hbox.appendChild(btn); - btn = new Button(""); - btn.setImage(ThemeManager.getThemeResource("images/Cancel24.png")); + btn = ButtonFactory.createNamedButton(ConfirmPanel.A_CANCEL); btn.setId("Cancel"); - LayoutUtils.addSclass("action-button", btn); btn.addEventListener(Events.ON_CLICK, this); hbox.appendChild(btn); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaymentFormCheck.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaymentFormCheck.java index 22e802bf7f..46ae290714 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaymentFormCheck.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaymentFormCheck.java @@ -92,7 +92,7 @@ public class WPaymentFormCheck extends PaymentFormCheck implements EventListener sNumberField.setWidth("100pt"); sRoutingField.setWidth("70pt"); sOnline.setLabel(Msg.getMsg(Env.getCtx(), "Online")); - LayoutUtils.addSclass("action-text-button", sOnline); + LayoutUtils.addSclass("txt-btn", sOnline); sOnline.addActionListener(this); window.getPanel().setId("sPanel"); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaymentFormCreditCard.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaymentFormCreditCard.java index b4a7e4ecb8..6c8beb2a72 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaymentFormCreditCard.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaymentFormCreditCard.java @@ -16,7 +16,6 @@ package org.adempiere.webui.apps.form; import java.math.BigDecimal; import org.adempiere.util.PaymentUtil; -import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.component.Button; import org.adempiere.webui.component.Column; import org.adempiere.webui.component.Columns; @@ -30,6 +29,7 @@ import org.adempiere.webui.component.Row; import org.adempiere.webui.component.Rows; import org.adempiere.webui.component.Textbox; import org.adempiere.webui.editor.WNumberEditor; +import org.adempiere.webui.factory.ButtonFactory; import org.adempiere.webui.window.FDialog; import org.compiere.grid.PaymentFormCreditCard; import org.compiere.model.GridTab; @@ -64,7 +64,7 @@ public class WPaymentFormCreditCard extends PaymentFormCreditCard implements Eve private WNumberEditor kAmountField = new WNumberEditor(); private Label kApprovalLabel = new Label(); private Textbox kApprovalField = new Textbox(); - private Button kOnline = new Button(); + private Button kOnline = ButtonFactory.createNamedButton("Online"); private Label kStatus = new Label(); public WPaymentFormCreditCard(int windowNo, GridTab mTab) { @@ -85,8 +85,6 @@ public class WPaymentFormCreditCard extends PaymentFormCreditCard implements Eve kExpLabel.setText(Msg.getMsg(Env.getCtx(), "Expires")); kApprovalLabel.setText(Msg.translate(Env.getCtx(), "VoiceAuthCode")); kAmountLabel.setText(Msg.getMsg(Env.getCtx(), "Amount")); - kOnline.setLabel(Msg.getMsg(Env.getCtx(), "Online")); - LayoutUtils.addSclass("action-text-button", kOnline); kOnline.addActionListener(this); window.getPanel().setId("kPanel"); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaymentFormDirect.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaymentFormDirect.java index 432c552afc..79a8015779 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaymentFormDirect.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPaymentFormDirect.java @@ -75,7 +75,7 @@ public abstract class WPaymentFormDirect extends PaymentFormDirect implements Ev tRoutingText.setText(Msg.translate(Env.getCtx(), "RoutingNo")); tNumberText.setText(Msg.translate(Env.getCtx(), "AccountNo")); tOnline.setLabel(Msg.getMsg(Env.getCtx(), "Online")); - LayoutUtils.addSclass("action-text-button", tOnline); + LayoutUtils.addSclass("txt-btn", tOnline); tOnline.addActionListener(this); window.getPanel().setId("tPanel"); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ConfirmPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ConfirmPanel.java index 232d418218..bf725a1457 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ConfirmPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ConfirmPanel.java @@ -22,10 +22,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import org.adempiere.webui.LayoutUtils; -import org.adempiere.webui.theme.ThemeManager; -import org.compiere.util.Env; -import org.compiere.util.Msg; +import org.adempiere.webui.factory.ButtonFactory; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; import org.zkoss.zul.Hbox; @@ -75,6 +72,7 @@ public final class ConfirmPanel extends Hbox private boolean m_withText = false; private Map buttonMap = new HashMap(); + private boolean m_withImage = true; /** * Creates a button of the specified id @@ -101,34 +99,31 @@ public final class ConfirmPanel extends Hbox */ public Button createButton(String name) { - Button button = new Button(); - button.setName("btn"+name); + Button button = ButtonFactory.createNamedButton(name, m_withText, m_withImage); button.setId(name); - - String text = Msg.translate(Env.getCtx(), name); - if (!name.equals(text)) - text = text.replaceAll("[&]", ""); - else - text = null; - - if (m_withText && text != null) - { - button.setImage(ThemeManager.getThemeResource("images/"+name+"16.png")); - button.setLabel(text); - LayoutUtils.addSclass("action-text-button", button); - } - else - { - button.setImage(ThemeManager.getThemeResource("images/"+name+"24.png")); - if (text != null) - button.setTooltiptext(text); - LayoutUtils.addSclass("action-button", button); - } - buttonMap.put(name, button); return button; } + + /** + * create confirm panel with multiple options + * @param withCancelButton with cancel + * @param withRefreshButton with refresh + * @param withResetButton with reset + * @param withCustomizeButton with customize + * @param withHistoryButton with history + * @param withZoomButton with zoom + */ + public ConfirmPanel(boolean withCancelButton, + boolean withRefreshButton, + boolean withResetButton, + boolean withCustomizeButton, + boolean withHistoryButton, + boolean withZoomButton) + { + this(withCancelButton, withRefreshButton, withResetButton, withCustomizeButton, withHistoryButton, withZoomButton, ButtonFactory.isWithText()); + } /** * create confirm panel with multiple options @@ -138,26 +133,8 @@ public final class ConfirmPanel extends Hbox * @param withCustomizeButton with customize * @param withHistoryButton with history * @param withZoomButton with zoom + * @param withText */ - public ConfirmPanel(boolean withCancelButton, - boolean withRefreshButton, - boolean withResetButton, - boolean withCustomizeButton, - boolean withHistoryButton, - boolean withZoomButton) - { - this(withCancelButton, withRefreshButton, withResetButton, withCustomizeButton, withHistoryButton, withZoomButton, false); - } - - /** - * create confirm panel with multiple options - * @param withCancelButton with cancel - * @param withRefreshButton with refresh - * @param withResetButton with reset - * @param withCustomizeButton with customize - * @param withHistoryButton with history - * @param withZoomButton with zoom - */ public ConfirmPanel(boolean withCancelButton, boolean withRefreshButton, boolean withResetButton, @@ -165,8 +142,32 @@ public final class ConfirmPanel extends Hbox boolean withHistoryButton, boolean withZoomButton, boolean withText) + { + this(withCancelButton, withRefreshButton, withResetButton, withCustomizeButton, withHistoryButton, withZoomButton, withText, !withText ? true : ButtonFactory.isWithImage()); + } + + /** + * create confirm panel with multiple options + * @param withCancelButton with cancel + * @param withRefreshButton with refresh + * @param withResetButton with reset + * @param withCustomizeButton with customize + * @param withHistoryButton with history + * @param withZoomButton with zoom + * @param withText + * @param withImage Incude image for button. Note that image always included if withText is false + */ + public ConfirmPanel(boolean withCancelButton, + boolean withRefreshButton, + boolean withResetButton, + boolean withCustomizeButton, + boolean withHistoryButton, + boolean withZoomButton, + boolean withText, + boolean withImage) { m_withText = withText; + m_withImage = withImage; init(); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Messagebox.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Messagebox.java index 23fdd9f73c..e518d1cbd6 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Messagebox.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Messagebox.java @@ -21,8 +21,8 @@ import java.util.Properties; import org.adempiere.util.Callback; import org.adempiere.webui.AdempiereIdGenerator; -import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.apps.AEnv; +import org.adempiere.webui.factory.ButtonFactory; import org.adempiere.webui.theme.ThemeManager; import org.compiere.util.Env; import org.compiere.util.Msg; @@ -55,13 +55,13 @@ public class Messagebox extends Window implements EventListener private Text lblMsg = new Text(); - private Button btnOk = new Button(); - private Button btnCancel = new Button(); - private Button btnYes = new Button(); - private Button btnNo = new Button(); - private Button btnAbort = new Button(); - private Button btnRetry = new Button(); - private Button btnIgnore = new Button(); + private Button btnOk; + private Button btnCancel; + private Button btnYes; + private Button btnNo; + private Button btnAbort; + private Button btnRetry; + private Button btnIgnore; private Image img = new Image(); @@ -115,45 +115,39 @@ public class Messagebox extends Window implements EventListener lblMsg.setEncode(false); lblMsg.setValue(msg); // Invert - Unify OK/Cancel IDEMPIERE-77 - //btnOk.setLabel(Util.cleanAmp(Msg.getMsg(ctx, "OK"))); - btnOk.setImage(ThemeManager.getThemeResource("images/Ok16.png")); + btnOk = ButtonFactory.createNamedButton(ConfirmPanel.A_OK); btnOk.setId("btnOk"); btnOk.addEventListener(Events.ON_CLICK, this); - LayoutUtils.addSclass("action-text-button", btnOk); - //btnCancel.setLabel(Util.cleanAmp(Msg.getMsg(ctx, "Cancel"))); - btnCancel.setImage(ThemeManager.getThemeResource("images/Cancel16.png")); + btnCancel = ButtonFactory.createNamedButton(ConfirmPanel.A_CANCEL); btnCancel.addEventListener(Events.ON_CLICK, this); btnCancel.setId("btnCancel"); - LayoutUtils.addSclass("action-text-button", btnCancel); - btnYes.setLabel(Util.cleanAmp(Msg.getMsg(ctx, "Yes"))); - btnYes.setImage(ThemeManager.getThemeResource("images/Ok16.png")); + String yesLabel = Util.cleanAmp(Msg.getMsg(ctx, "Yes")); + btnYes = ButtonFactory.createButton(ButtonFactory.isWithText() ? yesLabel : null, + ButtonFactory.isWithImage() ? (ButtonFactory.isWithText() ? ThemeManager.getThemeResource("images/Ok16.png") : ThemeManager.getThemeResource("images/Ok24.png")) : null, + ButtonFactory.isWithText() ? null : yesLabel); btnYes.addEventListener(Events.ON_CLICK, this); btnYes.setId("btnYes"); - LayoutUtils.addSclass("action-text-button", btnYes); - btnNo.setLabel(Util.cleanAmp(Msg.getMsg(ctx, "No"))); - btnNo.setImage(ThemeManager.getThemeResource("images/Cancel16.png")); + String noLabel = Util.cleanAmp(Msg.getMsg(ctx, "No")); + btnNo = ButtonFactory.createButton(ButtonFactory.isWithText() ? noLabel : null, + ButtonFactory.isWithImage() ? ( ButtonFactory.isWithText() ? ThemeManager.getThemeResource("images/Cancel16.png") : ThemeManager.getThemeResource("images/Cancel24.png")) : null, + ButtonFactory.isWithText() ? null : noLabel); btnNo.addEventListener(Events.ON_CLICK, this); btnNo.setId("btnNo"); - LayoutUtils.addSclass("action-text-button", btnNo); - - btnAbort.setLabel("Abort"); + + btnAbort = ButtonFactory.createButton("Abort", null, null); btnAbort.addEventListener(Events.ON_CLICK, this); btnAbort.setId("btnAbort"); - LayoutUtils.addSclass("action-text-button", btnAbort); - btnRetry.setLabel("Retry"); + btnRetry = ButtonFactory.createButton("Retry", null, null); btnRetry.addEventListener(Events.ON_CLICK, this); btnRetry.setId("btnRetry"); - LayoutUtils.addSclass("action-text-button", btnRetry); - btnIgnore.setLabel("Ignore"); - btnIgnore.setImage(ThemeManager.getThemeResource("images/Ignore16.png")); + btnIgnore = ButtonFactory.createNamedButton("Ignore"); btnIgnore.addEventListener(Events.ON_CLICK, this); btnIgnore.setId("btnIgnore"); - LayoutUtils.addSclass("action-text-button", btnIgnore); Panel pnlMessage = new Panel(); pnlMessage.setStyle(MESSAGE_PANEL_STYLE); @@ -219,6 +213,8 @@ public class Messagebox extends Window implements EventListener this.imgSrc = icon; this.callback = callback; + init(); + btnOk.setVisible(false); btnCancel.setVisible(false); btnYes.setVisible(false); @@ -248,8 +244,6 @@ public class Messagebox extends Window implements EventListener if ((buttons & IGNORE) != 0) btnIgnore.setVisible(true); - init(); - this.setTitle(title); this.setPosition("center"); this.setClosable(true); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ProcessInfoDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ProcessInfoDialog.java index ea40b23d38..85f6695a7d 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ProcessInfoDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ProcessInfoDialog.java @@ -16,9 +16,8 @@ package org.adempiere.webui.component; import java.text.SimpleDateFormat; -import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.apps.AEnv; -import org.adempiere.webui.theme.ThemeManager; +import org.adempiere.webui.factory.ButtonFactory; import org.compiere.process.ProcessInfoLog; import org.compiere.util.DisplayType; import org.compiere.util.Env; @@ -42,7 +41,7 @@ public class ProcessInfoDialog extends Window implements EventListener { private static final String MESSAGE_PANEL_STYLE = "text-align:left; word-break: break-all; overflow: auto; max-height: 250pt; min-width: 230pt; max-width: 450pt;"; private Text lblMsg = new Text(); - private Button btnOk = new Button(); + private Button btnOk = ButtonFactory.createNamedButton(ConfirmPanel.A_OK); private Image img = new Image(); public static final String INFORMATION = "~./zul/img/msgbox/info-btn.png"; @@ -64,9 +63,7 @@ public class ProcessInfoDialog extends Window implements EventListener { lblMsg.setEncode(false); lblMsg.setValue(header); - btnOk.setImage(ThemeManager.getThemeResource("images/Ok16.png")); btnOk.addEventListener(Events.ON_CLICK, this); - LayoutUtils.addSclass("action-text-button", btnOk); Panel pnlMessage = new Panel(); pnlMessage.setStyle(MESSAGE_PANEL_STYLE); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/WAppsAction.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/WAppsAction.java index 87ab7c5b75..4e58a77893 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/WAppsAction.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/WAppsAction.java @@ -107,7 +107,7 @@ public class WAppsAction { m_button.setLabel(newToolTipText); } - LayoutUtils.addSclass("action-button", m_button); + LayoutUtils.addSclass("img-btn", m_button); } // Action private Button m_button; diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/factory/ButtonFactory.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/factory/ButtonFactory.java new file mode 100644 index 0000000000..e69db584f0 --- /dev/null +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/factory/ButtonFactory.java @@ -0,0 +1,138 @@ +/****************************************************************************** + * Copyright (C) 2013 Heng Sin Low * + * Copyright (C) 2013 Trek Global * + * 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.factory; + +import org.adempiere.webui.LayoutUtils; +import org.adempiere.webui.component.Button; +import org.adempiere.webui.theme.ThemeManager; +import org.compiere.model.MSysConfig; +import org.compiere.util.Env; +import org.compiere.util.Msg; +import org.compiere.util.Util; + +/** + * Factory class to create button with consistent look and feel + * @author hengsin + * + */ +public class ButtonFactory { + + private static final String ZK_BUTTON_STYLE = "ZK_BUTTON_STYLE"; + + /** + * @return true if button should have text label + */ + public static final boolean isWithText() { + String type = MSysConfig.getValue(ZK_BUTTON_STYLE, "I"); + return type.indexOf("T") >= 0; + } + + /** + * @return true if button should include an image icon + */ + public static final boolean isWithImage() { + String type = MSysConfig.getValue(ZK_BUTTON_STYLE, "I"); + return type.indexOf("I") >= 0; + } + + /** + * Create named button with default style + * @param name + * @return new button instance + */ + public static Button createNamedButton(String name) + { + return createNamedButton(name, isWithText(), isWithImage()); + } + + /** + * + * @param name button name. If withText is true, the name will be used to + * lookup the button label from ad_message + * @param withText text button + * @param withImage image button + * @return new button instance + */ + public static Button createNamedButton(String name, boolean withText, boolean withImage) + { + Button button = new Button(); + button.setName("btn"+name); + + String text = Msg.translate(Env.getCtx(), name); + if (!name.equals(text)) + text = text.replaceAll("[&]", ""); + else + text = null; + + if (withText && text != null) + { + button.setLabel(text); + if (withImage) + { + button.setImage(ThemeManager.getThemeResource("images/"+name+"16.png")); + } + LayoutUtils.addSclass("txt-btn", button); + } + else + { + button.setImage(ThemeManager.getThemeResource("images/"+name+"24.png")); + if (text != null) + button.setTooltiptext(text); + LayoutUtils.addSclass("img-btn", button); + } + + //add named class for further customization option + String className = "btn-" + name.toLowerCase(); + LayoutUtils.addSclass(className, button); + + return button; + } + + /** + * @param label + * @param image + * @param tooltiptext + * @return new button instance + */ + public static Button createButton(String label, String image, String tooltiptext) + { + Button button = new Button(); + + if (!Util.isEmpty(label)) + { + button.setLabel(label); + if (!Util.isEmpty(image)) + { + button.setImage(image); + LayoutUtils.addSclass("img-txt-btn", button); + } + else + { + LayoutUtils.addSclass("txt-btn", button); + } + } + else if (!Util.isEmpty(image)) + { + button.setImage(image); + LayoutUtils.addSclass("img-btn", button); + } + + if (!Util.isEmpty(tooltiptext)) + { + button.setTooltiptext(tooltiptext); + } + + return button; + } +} diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/CustomizeGridViewPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/CustomizeGridViewPanel.java index 2b6651fda7..a902e0e7cb 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/CustomizeGridViewPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/CustomizeGridViewPanel.java @@ -31,6 +31,7 @@ import org.adempiere.model.MTabCustomization; import org.adempiere.webui.adwindow.GridView; import org.adempiere.webui.component.Button; import org.adempiere.webui.component.Checkbox; +import org.adempiere.webui.component.ConfirmPanel; import org.adempiere.webui.component.Label; import org.adempiere.webui.component.ListHead; import org.adempiere.webui.component.ListHeader; @@ -38,6 +39,7 @@ import org.adempiere.webui.component.ListItem; import org.adempiere.webui.component.Listbox; import org.adempiere.webui.component.Panel; import org.adempiere.webui.component.SimpleListModel; +import org.adempiere.webui.factory.ButtonFactory; import org.adempiere.webui.theme.ThemeManager; import org.adempiere.webui.window.FDialog; import org.compiere.model.GridTab; @@ -245,8 +247,7 @@ public class CustomizeGridViewPanel extends Panel southPanel.setStyle("margin-top: 2px; margin-right: 4px"); @SuppressWarnings("unused") String label = Msg.getMsg(Env.getCtx(), "save"); - Button bOK = new Button(); - bOK.setImage(ThemeManager.getThemeResource("images/Ok16.png")); + Button bOK = ButtonFactory.createNamedButton(ConfirmPanel.A_OK); bOK.setId("Ok"); EventListener onClickListener = new EventListener() { @@ -261,11 +262,9 @@ public class CustomizeGridViewPanel extends Panel }; bOK.addActionListener(onClickListener); - bOK.setSclass("action-button"); southPanel.appendChild(bOK); label = Msg.getMsg(Env.getCtx(), "Cancel"); - Button btn = new Button(); - btn.setImage(ThemeManager.getThemeResource("images/Cancel16.png")); + Button btn = ButtonFactory.createNamedButton(ConfirmPanel.A_CANCEL); btn.setId("Cancel"); EventListener onClickCancelListener = new EventListener() { @@ -280,7 +279,6 @@ public class CustomizeGridViewPanel extends Panel }; btn.addActionListener(onClickCancelListener); - btn.setSclass("action-button"); southPanel.appendChild(btn); south.appendChild(southPanel); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WAttachment.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WAttachment.java index 202150fa71..a568fa2700 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WAttachment.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WAttachment.java @@ -246,20 +246,20 @@ public class WAttachment extends Window implements EventListener northPanel.appendChild(div); bSave.setEnabled(false); - bSave.setSclass("action-button"); + bSave.setSclass("img-btn"); bSave.setImage(ThemeManager.getThemeResource("images/Export24.png")); bSave.setTooltiptext(Msg.getMsg(Env.getCtx(), "AttachmentSave")); bSave.addEventListener(Events.ON_CLICK, this); bLoad.setImage(ThemeManager.getThemeResource("images/Import24.png")); - bLoad.setSclass("action-button"); + bLoad.setSclass("img-btn"); bLoad.setAttribute("org.zkoss.zul.image.preload", Boolean.TRUE); bLoad.setTooltiptext(Msg.getMsg(Env.getCtx(), "Load")); bLoad.setUpload(AdempiereWebUI.getUploadSetting()); bLoad.addEventListener(Events.ON_UPLOAD, this); bDelete.setImage(ThemeManager.getThemeResource("images/Delete24.png")); - bDelete.setSclass("action-button"); + bDelete.setSclass("img-btn"); bDelete.setTooltiptext(Msg.getMsg(Env.getCtx(), "Delete")); bDelete.addEventListener(Events.ON_CLICK, this); @@ -280,19 +280,19 @@ public class WAttachment extends Window implements EventListener southPane.setHeight("30px"); bCancel.setImage(ThemeManager.getThemeResource("images/Cancel24.png")); - bCancel.setSclass("action-button"); + bCancel.setSclass("img-btn"); bCancel.addEventListener(Events.ON_CLICK, this); bOk.setImage(ThemeManager.getThemeResource("images/Ok24.png")); - bOk.setSclass("action-button"); + bOk.setSclass("img-btn"); bOk.addEventListener(Events.ON_CLICK, this); bDeleteAll.setImage(ThemeManager.getThemeResource("images/Delete24.png")); - bDeleteAll.setSclass("action-button"); + bDeleteAll.setSclass("img-btn"); bDeleteAll.addEventListener(Events.ON_CLICK, this); bRefresh.setImage(ThemeManager.getThemeResource("images/Refresh24.png")); - bRefresh.setSclass("action-button"); + bRefresh.setSclass("img-btn"); bRefresh.addEventListener(Events.ON_CLICK, this); confirmPanel.appendChild(bDeleteAll); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/AboutWindow.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/AboutWindow.java index 9a16309162..6c2990858b 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/AboutWindow.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/AboutWindow.java @@ -21,6 +21,7 @@ import java.util.logging.Level; import org.adempiere.webui.apps.AEnv; import org.adempiere.webui.component.Button; import org.adempiere.webui.component.Checkbox; +import org.adempiere.webui.component.ConfirmPanel; import org.adempiere.webui.component.FolderBrowser; import org.adempiere.webui.component.Label; import org.adempiere.webui.component.ListHead; @@ -36,6 +37,7 @@ import org.adempiere.webui.component.Tabs; import org.adempiere.webui.component.ToolBarButton; import org.adempiere.webui.component.Window; import org.adempiere.webui.event.DialogEvents; +import org.adempiere.webui.factory.ButtonFactory; import org.adempiere.webui.theme.ThemeManager; import org.adempiere.webui.util.FeedbackManager; import org.compiere.Adempiere; @@ -152,9 +154,8 @@ public class AboutWindow extends Window implements EventListener { hbox.setParent(layout); hbox.setPack("end"); hbox.setWidth("100%"); - hbox.setVflex("0"); - Button btnOk = new Button(); - btnOk.setImage(ThemeManager.getThemeResource("images/Ok24.png")); + hbox.setVflex("min"); + Button btnOk = ButtonFactory.createNamedButton(ConfirmPanel.A_OK); btnOk.addEventListener(Events.ON_CLICK, this); btnOk.setParent(hbox); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FindWindow.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FindWindow.java index 0e9c7b18ef..71b7f4964c 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FindWindow.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FindWindow.java @@ -38,11 +38,11 @@ import java.util.logging.Level; import java.util.regex.Pattern; import org.adempiere.webui.AdempiereWebUI; -import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.component.Button; import org.adempiere.webui.component.Column; import org.adempiere.webui.component.Columns; import org.adempiere.webui.component.Combobox; +import org.adempiere.webui.component.ConfirmPanel; import org.adempiere.webui.component.Grid; import org.adempiere.webui.component.Label; import org.adempiere.webui.component.ListCell; @@ -64,6 +64,7 @@ import org.adempiere.webui.editor.WebEditorFactory; import org.adempiere.webui.event.DialogEvents; import org.adempiere.webui.event.ValueChangeEvent; import org.adempiere.webui.event.ValueChangeListener; +import org.adempiere.webui.factory.ButtonFactory; import org.adempiere.webui.part.MultiTabPart; import org.adempiere.webui.theme.ThemeManager; import org.compiere.model.GridField; @@ -304,26 +305,18 @@ public class FindWindow extends Window implements EventListener, ValueCha **/ private void initSimple() { - Button btnNew = new Button(); - btnNew.setName("btnNew"); + Button btnNew = ButtonFactory.createNamedButton(ConfirmPanel.A_NEW); btnNew.setId("btnNew"); - btnNew.setImage(ThemeManager.getThemeResource("images/New24.png")); btnNew.addEventListener(Events.ON_CLICK,this); - LayoutUtils.addSclass("action-button", btnNew); - Button btnOk = new Button(); + Button btnOk = ButtonFactory.createNamedButton(ConfirmPanel.A_OK); btnOk.setName("btnOkSimple"); btnOk.setId("btnOk"); - btnOk.setImage(ThemeManager.getThemeResource("images/Ok24.png")); btnOk.addEventListener(Events.ON_CLICK,this); - LayoutUtils.addSclass("action-button", btnOk); - Button btnCancel = new Button(); - btnCancel.setName("btnCancel"); + Button btnCancel = ButtonFactory.createNamedButton(ConfirmPanel.A_CANCEL); btnCancel.setId("btnCancel"); - btnCancel.setImage(ThemeManager.getThemeResource("images/Cancel24.png")); btnCancel.addEventListener(Events.ON_CLICK,this); - LayoutUtils.addSclass("action-button", btnCancel); Panel pnlButtonRight = new Panel(); pnlButtonRight.appendChild(btnOk); @@ -405,17 +398,12 @@ public class FindWindow extends Window implements EventListener, ValueCha btnDelete.setImage(ThemeManager.getThemeResource("images/Delete24.png")); btnDelete.addEventListener(Events.ON_CLICK, this); - Button btnOk = new Button(); + Button btnOk = ButtonFactory.createNamedButton(ConfirmPanel.A_OK); btnOk.setName("btnOkAdv"); - btnOk.setImage(ThemeManager.getThemeResource("images/Ok24.png")); btnOk.addEventListener(Events.ON_CLICK, this); - LayoutUtils.addSclass("action-button", btnOk); - Button btnCancel = new Button(); - btnCancel.setName("btnCancel"); - btnCancel.setImage(ThemeManager.getThemeResource("images/Cancel24.png")); + Button btnCancel = ButtonFactory.createNamedButton(ConfirmPanel.A_CANCEL); btnCancel.addEventListener(Events.ON_CLICK, this); - LayoutUtils.addSclass("action-button", btnCancel); Panel pnlButtonRight = new Panel(); pnlButtonRight.appendChild(btnOk); diff --git a/org.adempiere.ui.zk/WEB-INF/zk.xml b/org.adempiere.ui.zk/WEB-INF/zk.xml index be2671e8fc..112af0d53a 100644 --- a/org.adempiere.ui.zk/WEB-INF/zk.xml +++ b/org.adempiere.ui.zk/WEB-INF/zk.xml @@ -70,15 +70,6 @@ org.zkoss.zul.progressbox.position center - - org.zkoss.zul.Button.mold - trendy - - - org.adempiere.webui.component.Button.mold - trendy - - org.zkoss.zul.theme.fontSizeM diff --git a/org.adempiere.ui.zk/calendar_mini.zul b/org.adempiere.ui.zk/calendar_mini.zul index c4e7f5e73e..3496a0c344 100644 --- a/org.adempiere.ui.zk/calendar_mini.zul +++ b/org.adempiere.ui.zk/calendar_mini.zul @@ -12,7 +12,7 @@
-