Update of /cvsroot/redpos/RedPOS/src/org/redpos/client/ui In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29708/src/org/redpos/client/ui Modified Files: UIShellKeyListener.java POSMenuFactory.java UIShell.java POSDashboard.java POSMenuAction.java POSDashboardContext.java Added Files: POSMenuShortCommand.java Log Message: Added functionality for short commands when selecting payment Index: POSMenuFactory.java =================================================================== RCS file: /cvsroot/redpos/RedPOS/src/org/redpos/client/ui/POSMenuFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** POSMenuFactory.java 23 Nov 2004 16:02:09 -0000 1.1 --- POSMenuFactory.java 7 Mar 2005 11:13:56 -0000 1.2 *************** *** 30,33 **** --- 30,34 ---- import org.redpos.client.lang.contract.Language; + import org.redpos.client.payment.contract.PaymentInfo; import org.redpos.client.ui.plugin.contract.PluginCategoryInfo; *************** *** 46,49 **** --- 47,52 ---- private Vector services = null; + + private Vector payments = null; /** *************** *** 73,78 **** --- 76,103 ---- e.printStackTrace(); } + + // get available payments from PaymentRegistry + try + { + ObjectName paymentRegistry = new ObjectName( + "RedPOS.client.payment:service=PaymentRegistry"); + + Object[] params = {}; + String[] signature = {}; + + // call pos core method + Object response = server.invoke(paymentRegistry, "loadPayments", params, + signature); + if(response != null) + payments = (Vector)response; + } + catch(Exception e) + { + e.printStackTrace(); + } } + + /** * Creates the menu actions *************** *** 98,100 **** --- 123,148 ---- return actions; } + + /** + * Creates the payment actions + * + * @return + */ + public POSMenuAction[] createActionsPayment() + { + if(payments == null) + return null; + + // create an array of actions + POSMenuAction[] actions = new POSMenuAction[payments.size()]; + // parse payments into actions + for(int i = 0; i < payments.size(); i++) + { + PaymentInfo paymentInfo = (PaymentInfo)payments.get(i); + actions[i] = new POSMenuAction(paymentInfo.id, paymentInfo.name, paymentInfo.accelerator, + paymentInfo.statemask, paymentInfo); + } + + return actions; + } } \ No newline at end of file Index: UIShellKeyListener.java =================================================================== RCS file: /cvsroot/redpos/RedPOS/src/org/redpos/client/ui/UIShellKeyListener.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** UIShellKeyListener.java 23 Nov 2004 16:02:09 -0000 1.1 --- UIShellKeyListener.java 7 Mar 2005 11:13:56 -0000 1.2 *************** *** 72,76 **** public void keyPressed(KeyEvent event) { ! Integer keyId = new Integer(event.keyCode); // see if we have a key listener for the pressed key if(keyListeners.containsKey(keyId)) --- 72,76 ---- public void keyPressed(KeyEvent event) { ! Integer keyId = new Integer(event.keyCode); // see if we have a key listener for the pressed key if(keyListeners.containsKey(keyId)) *************** *** 81,84 **** --- 81,95 ---- listener.handleEvent(new Event()); } + + int keyCode = event.keyCode; + int statemask = event.stateMask; + Integer accelerator = new Integer(keyCode + statemask); + if (keyListeners.containsKey(accelerator)) + { + //get listener + Listener listener = (Listener)keyListeners.get(accelerator); + // invoked handleEvent(..) on listener + listener.handleEvent(new Event()); + } } *************** *** 104,107 **** keyListeners.put(new Integer(keyId), listener); } ! } \ No newline at end of file --- 115,118 ---- keyListeners.put(new Integer(keyId), listener); } ! } \ No newline at end of file Index: POSMenuAction.java =================================================================== RCS file: /cvsroot/redpos/RedPOS/src/org/redpos/client/ui/POSMenuAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** POSMenuAction.java 23 Nov 2004 16:02:09 -0000 1.1 --- POSMenuAction.java 7 Mar 2005 11:13:56 -0000 1.2 *************** *** 24,27 **** --- 24,28 ---- package org.redpos.client.ui; + import org.redpos.client.payment.contract.PaymentInfo; import org.redpos.client.ui.plugin.contract.PluginCategoryInfo; *************** *** 46,49 **** --- 47,54 ---- private String text; + private PaymentInfo paymentInfo; + + private int statemask; + /** * Constructs a new instance *************** *** 58,61 **** --- 63,79 ---- serviceInfo = uis; } + + /** + * Constructs a new instance + */ + public POSMenuAction(String id, String text, int acc, int state, + PaymentInfo payment) + { + this.id = id; + this.text = text; + accelerator = acc; + paymentInfo = payment; + statemask = state; + } /** *************** *** 88,91 **** --- 106,119 ---- return accelerator; } + + /** + * Returns action statemask + * + * @return + */ + public int getStatemask() + { + return statemask; + } /** *************** *** 115,118 **** --- 143,156 ---- return serviceInfo; } + + /** + * Returns payment info object + * + * @return + */ + public PaymentInfo getPaymentInfo() + { + return paymentInfo; + } } \ No newline at end of file --- NEW FILE: POSMenuShortCommand.java --- /* * RedPOS, the OpenSource Point of Sale * * Copyright (C) 2004-2007 Redpill AB * * This application is free software; you can redistribute * it and/or modify it under the terms of the GNU Lesser * General Public License as published by the Free Software * Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This application 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this application; if not, it can be downloaded * from http://www.gnu.org/licenses/lgpl.html. * * For more information and contacts, please visit http://www.redpos.org * */ package org.redpos.client.ui; import java.util.Iterator; import java.util.Vector; import javax.management.MBeanServer; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Widget; import org.redpos.client.lang.contract.Language; /** * TODO Enter a description and also your mail address below * * @version <tt>$Revision: 1.1 $</tt> * @author <a href="mailto:ENTER-USER@ENTER-DOMAIN">annb</a> */ public class POSMenuShortCommand implements UIDisablerListener { private MBeanServer server; private Vector listeners; /** The UI object **/ private Composite widget; /** The UI language **/ private Language lang; /** Array of all buttons in menu */ private Button[] menuButtonsPayment; /** * */ public POSMenuShortCommand(Composite parent, Language lang, MBeanServer s) { // create widget widget = new Composite(parent, SWT.NORMAL); this.lang = lang; server = s; // listen to events triggerd by the UIDisabler class UIDisabler.getInstance().addListener(this); init(); } /** * Initializes this class * */ private void init() { // set layout GridLayout layout = new GridLayout(); layout.makeColumnsEqualWidth = true; layout.horizontalSpacing = 0; layout.verticalSpacing = 0; layout.numColumns = 12; layout.marginHeight = 0; layout.marginWidth = 0; widget.setLayout(layout); // create button listener object Listener buttonListener = new Listener() { public void handleEvent(Event arg0) { buttonSelected(arg0.widget); } }; // create factory and use it to get pos menu actions POSMenuFactory factory = new POSMenuFactory(lang, server); // use factory and get payment actions POSMenuAction[] actionsPayment = factory.createActionsPayment(); menuButtonsPayment = new Button[actionsPayment.length]; for(int i = 0; actionsPayment != null && i < actionsPayment.length; i++) { // create button for action Button actionButton = new Button(widget, SWT.PUSH); actionButton.setText(actionsPayment[i].getText()); actionButton.setData(actionsPayment[i]); // create layout data for button GridData layoutData = new GridData(); layoutData.grabExcessHorizontalSpace = true; layoutData.grabExcessVerticalSpace = true; layoutData.horizontalAlignment = GridData.FILL; layoutData.verticalAlignment = GridData.FILL; actionButton.setLayoutData(layoutData); // add listener to button actionButton.addListener(SWT.Selection, buttonListener); // register key event for button UIShellKeyListener.getInstance().register(actionsPayment[i].getAccelerator() + actionsPayment[i].getStatemask(), new ButtonTrigger(actionButton)); // add button to array of buttons menuButtonsPayment[i] = actionButton; } } /** * Invoked when user presses a button in the menu * * @param button */ private void buttonSelected(Widget button) { // get action object related to button POSMenuAction action = (POSMenuAction)button.getData(); // notify listeners of the selected action this.actionSelected(action); } /** * Returns this class UI object * * @return */ public Composite getWidget() { return widget; } /** * Adds a listener * * @param listener */ public void addListener(POSMenuListener listener) { if(listeners == null) listeners = new Vector(); // check if listener hasnt been added before if(!listeners.contains(listener)) listeners.add(listener); } /** * Removes a listener * * @param listener */ public void removeListener(POSMenuListener listener) { if(listeners == null) return; if(listeners.contains(listener)) listeners.remove(listener); } /** * Sends actions to all registered listeners * * @param actionId */ private void actionSelected(POSMenuAction action) { if(listeners == null) return; // invoke action on all listeners for(Iterator iter = listeners.iterator(); iter.hasNext();) { POSMenuListener element = (POSMenuListener)iter.next(); element.somePOSMenuActionSelected(action); } } /** * Inner class implemented as a listener takes a button and selects it when triggered * * @author mats */ private class ButtonTrigger implements Listener { private Button button; public ButtonTrigger(Button b) { button = b; } /** * * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) */ public void handleEvent(Event arg0) { buttonSelected(button); } } /** * @see org.redpos.client.ui.UIDisablerListener#enableUI() */ public void enableUI() { // enable all buttons // for(int i = 0; i < menuButtonsPayment.length; i++) { menuButtonsPayment[i].setEnabled(true); } } /** * @see org.redpos.client.ui.UIDisablerListener#disableUI() */ public void disableUI() { // disable all buttons // for(int i = 0; i < menuButtonsPayment.length; i++) { menuButtonsPayment[i].setEnabled(false); } } } Index: POSDashboardContext.java =================================================================== RCS file: /cvsroot/redpos/RedPOS/src/org/redpos/client/ui/POSDashboardContext.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** POSDashboardContext.java 17 Dec 2004 12:10:48 -0000 1.2 --- POSDashboardContext.java 7 Mar 2005 11:13:56 -0000 1.3 *************** *** 45,50 **** --- 45,52 ---- import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Listener; + import org.redpos.client.contract.POSEngineUtility; import org.redpos.client.contract.product.ProductData; import org.redpos.client.lang.contract.Language; + import org.redpos.client.payment.contract.PaymentInfo; import org.redpos.client.ui.plugin.contract.PluginCategoryInfo; import org.redpos.client.ui.plugin.contract.PluginCategoryUtility; *************** *** 93,96 **** --- 95,100 ---- private MBeanServer mServer; + + private POSEngineUtility posEngineUtility; /** *************** *** 103,106 **** --- 107,111 ---- mServer = server; + posEngineUtility = new POSEngineUtility(mServer); dashboard = n; *************** *** 206,209 **** --- 211,241 ---- } + public void paymentSelected(PaymentInfo payment) + { + try + { + posEngineUtility.startSelectedPayment(payment); + // create objectname object for the payment function + ObjectName function; + try + { + function = new ObjectName("RedPOS.client.ui.plugin.function:service=Pay"); + // create a function utility instance for the logoff function + PluginFunctionUtility functionUtility = new PluginFunctionUtility(mServer, function); + // display function in the dashboard + dashboard.getContext().displayFunction(functionUtility); + } + catch(MalformedObjectNameException e) + { + //log.error(e.getMessage(), e); + } + } + catch(JMException e) + { + // log.error(e.getMessage(), e); + } + + } + /** * Displays content with given id *************** *** 238,242 **** } } ! /** * Returns content text --- 270,274 ---- } } ! /** * Returns content text *************** *** 394,403 **** else if(n.getType().equals(PluginConstants.NOTIFICATION_PLUGIN_LOGINPERRECEIPT)) { ! // create objectname object for the payment function ObjectName function; try { function = new ObjectName("RedPOS.client.ui.plugin.function:service=Logoff"); ! // create a function utility instance for the payment function PluginFunctionUtility functionUtility = new PluginFunctionUtility(mServer, function); // display function in the dashboard --- 426,435 ---- else if(n.getType().equals(PluginConstants.NOTIFICATION_PLUGIN_LOGINPERRECEIPT)) { ! // create objectname object for the logoff function ObjectName function; try { function = new ObjectName("RedPOS.client.ui.plugin.function:service=Logoff"); ! // create a function utility instance for the logoff function PluginFunctionUtility functionUtility = new PluginFunctionUtility(mServer, function); // display function in the dashboard Index: POSDashboard.java =================================================================== RCS file: /cvsroot/redpos/RedPOS/src/org/redpos/client/ui/POSDashboard.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** POSDashboard.java 23 Nov 2004 16:02:09 -0000 1.1 --- POSDashboard.java 7 Mar 2005 11:13:56 -0000 1.2 *************** *** 153,157 **** public void somePOSMenuActionSelected(POSMenuAction action) { ! setContent(action.getId()); } --- 153,162 ---- public void somePOSMenuActionSelected(POSMenuAction action) { ! if (action.getId().startsWith("RedPOS.client.payment:")) ! { ! context.paymentSelected(action.getPaymentInfo()); ! } ! else ! setContent(action.getId()); } Index: UIShell.java =================================================================== RCS file: /cvsroot/redpos/RedPOS/src/org/redpos/client/ui/UIShell.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** UIShell.java 19 Feb 2005 08:33:53 -0000 1.2 --- UIShell.java 7 Mar 2005 11:13:56 -0000 1.3 *************** *** 266,269 **** --- 266,280 ---- menuData.verticalAlignment = GridData.FILL; posMenu.getWidget().setLayoutData(menuData); + + // create pos menu2 + POSMenuShortCommand posMenuShortCommand = new POSMenuShortCommand(navigationComposite, lang, server); + // create griddata for pos menu + GridData menuData2 = new GridData(); + menuData2.grabExcessHorizontalSpace = true; + menuData2.grabExcessVerticalSpace = true; + menuData2.horizontalAlignment = GridData.FILL; + menuData2.verticalAlignment = GridData.FILL; + posMenuShortCommand.getWidget().setLayoutData(menuData2); + posMenuShortCommand.getWidget().setVisible(false); // create a dummy composite *************** *** 274,277 **** --- 285,289 ---- posDashboard = new POSDashboard(navigationComposite, server, lang); posMenu.addListener(posDashboard); // the dashboard + posMenuShortCommand.addListener(posDashboard); // listens to the // menu |