From: Anneli <an...@us...> - 2005-01-11 17:11:51
|
Update of /cvsroot/redpos/RedPOS/src/org/redpos/client/ui/plugin/function In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11881/src/org/redpos/client/ui/plugin/function Added Files: FindReceiptUI.java FindSaveReceipt.java Log Message: New function, save and find receipt --- NEW FILE: FindSaveReceipt.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.plugin.function; import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Iterator; import java.util.Vector; import javax.management.JMException; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; import org.eclipse.swt.widgets.Composite; import org.redpos.amount.Amount; import org.redpos.client.contract.POSEngineUtility; import org.redpos.client.contract.properties.PropertiesUtility; import org.redpos.client.contract.receipt.ReceiptConstants; import org.redpos.client.contract.receipt.ReceiptData; import org.redpos.client.contract.receipt.ReceiptException; import org.redpos.client.contract.receipt.ReceiptRowData; import org.redpos.client.contract.receipt.ReceiptSessionUtility; import org.redpos.client.lang.contract.Language; import org.redpos.client.ui.UIDisabler; import org.redpos.client.ui.plugin.PluginFunctionMBeanSupport; import org.redpos.client.ui.plugin.contract.PluginFunctionConstants; import org.redpos.client.ui.plugin.function.FindReceiptUI.ReceiptTableItemData; /** * UI plugin function service * * @version <tt>$Revision: 1.1 $</tt> * @author <a>hele</a> * @author <a href="mailto:an...@us...">anba</a> * @jmx.mbean name = "RedPOS.client.ui.plugin.function:service=FindSaveReceipt" * description = "RedPOS client plug-in function" * extends = "org.redpos.client.ui.plugin.PluginFunctionMBean" */ public class FindSaveReceipt extends PluginFunctionMBeanSupport implements FindSaveReceiptMBean, FindReceiptUI.FindReceiptUIListener { private Language language; private FindReceiptUI ui = null; private UserInputUI userInput; private ReceiptTableItemData selectedReceipt; /** Receipt session service utility instance * */ private ReceiptSessionUtility receiptSessionUtility = null; private POSEngineUtility posEngineUtility = null; /** * @see org.redpos.client.ui.plugin.PluginFunctionMBean#invoke(org.eclipse.swt.widgets.Composite) */ public boolean invokeFunction(Composite parent) { ui = null; if(isReceiptStarted()) { if (prepare()) { ConfirmActionUI.ConfirmListener listener = new ConfirmActionUI.ConfirmListener() { public void selectionMade(int selection) { saveReceipt(); // send notification fireNotification( PluginFunctionConstants.NOTIFICATION_FUNCTION_FINISHED, null); // enable other UI components UIDisabler.getInstance().fireEnable(); try { if (posEngineUtility.getLoginPerReceipt()) { fireNotification(PluginFunctionConstants.NOTIFICATION_LOGIN_PER_RECEIPT, null); } } catch(JMException e) { log.error(e.getMessage(), e); } } }; String yesText = getLanguageString("ui.main.dashboard.message.yes.text", "Yes"); String noText = getLanguageString("ui.main.dashboard.message.no.text", "No"); String okText = getLanguageString("ui.main.dashboard.message.ok.text", "OK"); String cancelText = getLanguageString( "ui.main.dashboard.message.cancel.text", "Cancel"); String message = getLanguageString( "ui.plugin.receipt.saveReceipt1.text", "Do you want to save current receipt?"); ConfirmActionUI confirm = new ConfirmActionUI(parent, message, ConfirmActionUI.YES_NO_SELECTION, listener, yesText, noText, okText, cancelText); parent.layout(); } else { UIDisabler.getInstance().fireEnable(); } } else { ui = new FindReceiptUI(parent, language, this); parent.layout(); } return true; } /** * Checks if current receipt contains other rows than Productrows * */ public boolean prepare() { try { ObjectName receiptSession = new ObjectName( "RedPOS.client:service=ReceiptSession"); Object parameters[] = {}; String signature[] = {}; Vector responseRow = (Vector) getServer().getAttribute(receiptSession, "Rows"); Collection rowsInCurrentReceipt = (Collection)responseRow; for(Iterator iter = rowsInCurrentReceipt.iterator(); iter.hasNext();) { ReceiptRowData element = (ReceiptRowData)iter.next(); if (element.getType() != (ReceiptConstants.TYPE_RECEIPTROW_PRODUCT)) // && element.getType() != (ReceiptConstants.TYPE_RECEIPTROW_FREETEXT)) { if (element.getStatus() != (ReceiptConstants.STATUS_RECEIPTROW_CANCELLED)) { // send message to ui String message = getLanguageString( "ui.plugin.receipt.saveReceipt2.text", "Your attempt to save current receipt failed"); sendUIMessage(message); return false; } } } } catch (Exception e) { // } return true; } /** * Save current receipt * */ private void saveReceipt() { try { ObjectName receiptSession = new ObjectName( "RedPOS.client:service=ReceiptSession"); Object parameters[] = {}; String signature[] = {}; Object response = getServer().invoke(receiptSession, "save", parameters, signature); } catch(MalformedObjectNameException e) { log.error(e.getMessage(), e); } catch(Exception e) { String message = getLanguageString( "ui.plugin.receipt.saveReceipt2.text", "Your attempt to save current receipt failed"); sendUIMessage(message); } } /** * Find receipt with date grather then given and ReceiptConstants.STATUS_RECEIPT_SAVED * * @jmx.managed-operation */ public void findReceipt(String value) { try { ObjectName receiptStorage = new ObjectName( "RedPOS.client:service=ReceiptStorage"); int status = ReceiptConstants.STATUS_RECEIPT_SAVED; SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd"); Object params[] = {sdf.parse(value), new Integer(ReceiptConstants.STATUS_RECEIPT_SAVED)}; String signature[] = {"java.util.Date", "java.lang.Integer"}; //call pos core method Vector response = (Vector) getServer().invoke( receiptStorage, "findReceiptsByDateGreaterThan", params, signature); if (response.isEmpty()) { //send message to ui String message = getLanguageString( "ui.main.message.findReceipt1.text", "There is no receipt with stated date"); sendUIMessage(message); } //add found receipt to ui for (Iterator iter = response.iterator(); iter.hasNext();) { Amount amount = new Amount(0); ReceiptData receipt = (ReceiptData) iter.next(); Collection collRowData = findRows(receipt.getReceiptId()); // iterate receipt rows for(Iterator iterat = collRowData.iterator(); iterat.hasNext();) { ReceiptRowData receiptRowData = (ReceiptRowData)iterat.next(); if (receiptRowData.getType() != ReceiptConstants.TYPE_RECEIPTROW_FREETEXT) { // in this first version of find/save receipt it is not possible to save // other rows than of type product, thats why this is commented /* if ((receiptRowData.getType() == ReceiptConstants.TYPE_RECEIPTROW_DISCOUNT_ROW_AMOUNT) || (receiptRowData.getType() == ReceiptConstants.TYPE_RECEIPTROW_DISCOUNT_ROW_PERCENT) || (receiptRowData.getType() == ReceiptConstants.TYPE_RECEIPTROW_DISCOUNT_TOTAL_AMOUNT) || (receiptRowData.getType() == ReceiptConstants.TYPE_RECEIPTROW_DISCOUNT_ROW_PERCENT)) { if (receiptRowData.getStatus() != ReceiptConstants.STATUS_RECEIPTROW_CANCELLED) amount.subtract(receiptRowData.getAmount()); } else { */ amount.add(receiptRowData.getAmount()); // } } } ui.addReceipt(receipt, amount); } } catch (Exception e) { //send message to ui String message = getLanguageString( "ui.main.message.findReceipt2.text", "The search failed"); getLog().error("findReceipt() failed: " + e.getMessage()); e.printStackTrace(); } } /** * Tries to find receiptRows for given receipt in storage service * * @param receiptId * @return @throws * Exception */ private Vector findRows(String receiptId) { try { ObjectName receiptRowService = new ObjectName( "RedPOS.client:service=ReceiptRowStorage"); Object parameters[] = {receiptId}; String signature[] = {"java.lang.String"}; Object response = getServer().invoke(receiptRowService, "findRowsByReceiptId", parameters, signature); if(response != null) return (Vector)response; else return null; } catch(Exception e) { getLog().error("findRows() failed: " + e.getMessage()); e.printStackTrace(); } return null; } public boolean isReceiptStarted() { try { return receiptSessionUtility.isReceiptStarted(); } catch(JMException e) { log.error(e.getMessage(), e); return false; } } /** * Invoked when service is started * * @see org.jboss.system.ServiceMBeanSupport#startService() */ protected void startService() throws Exception { super.startService(); language = getLanguage(); setText(language.getString("ui.plugin.receipt.findReceipt.text", "Receipt")); PropertiesUtility po = new PropertiesUtility(getServer()); receiptSessionUtility = new ReceiptSessionUtility(getServer()); posEngineUtility = new POSEngineUtility(getServer()); } /** * Invoked by the FindReceiptUI * * @see org.redpos.client.ui.plugin.function.FindReceiptUI.FindReceiptUIListener#findSelected(java.lang.String) */ public void findSelected(String value) { ui.clearTable(); findReceipt(value); } public void addReceiptSelected(ReceiptTableItemData receipt) { if (receipt == null) { //set selected receipt selectedReceipt = receipt; //remove old ui from display Composite parent = ui.getParent(); ui.dispose(); ui = null; parent.layout(); } else { startReopeningReceipt(receipt); } } /** * Reopens given receipt * * @param receipt */ private void startReopeningReceipt(ReceiptTableItemData receipt) { try { ObjectName receiptService = new ObjectName( "RedPOS.client:service=POSEngine"); Object parameters [] = {receipt.receiptData}; String signature [] = {"org.redpos.client.contract.receipt.ReceiptData"}; getServer().invoke(receiptService, "startReopeningReceipt", parameters, signature); } catch (Exception e) { //send message to ui String message = getLanguageString( "ui.main.message.findReceipt3.text", "Your attempt to select receipt failed"); sendUIMessage(message); getLog().error("startReopeningReceipt() failed: " + e.getMessage()); e.printStackTrace(); } Collection collRowData = findRows(receipt.receiptData.getReceiptId()); try { receiptSessionUtility.addReceiptRowToReopenedReceipt(collRowData); } catch(ReceiptException e1) { e1.printStackTrace(); } catch(JMException e1) { e1.printStackTrace(); } // send notification fireNotification( PluginFunctionConstants.NOTIFICATION_FUNCTION_FINISHED, null); } } --- NEW FILE: FindReceiptUI.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.plugin.function; import java.text.SimpleDateFormat; import java.util.Calendar; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StackLayout; import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.TraverseEvent; import org.eclipse.swt.events.TraverseListener; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Listener; import org.redpos.amount.Amount; import org.redpos.client.contract.receipt.ReceiptData; import org.redpos.client.lang.contract.Language; import org.redpos.client.ui.contract.FontManager; /** * The UI class for the FindReceipt plugin function * * @version <tt>$Revision: 1.1 $</tt> * @author <a>hele</a> * @author <a href="mailto:an...@us...">anba</a> */ public class FindReceiptUI extends Composite { private Text inputField; private Table receiptTable; private Language language; private FindReceiptUIListener listener; private StackLayout stack; private Composite centerStack; private Button receiptInfoBackButton; private Button receiptInfoToRegisterButton; private Composite receiptInfo; private Label receiptIDText; private Label receiptId; private Label receiptDateText; private Label receiptDate; private Label receiptCashierText; private Label receiptCashier; private Label receiptAmountText; private Label receiptAmount; /** * Constructor */ public FindReceiptUI(Composite parent, Language language, FindReceiptUIListener listener) { super(parent, SWT.NORMAL); this.language = language; this.listener = listener; setBackground(parent.getBackground()); init(); } public void init() { //set grid layout GridLayout layout = new GridLayout(); layout.verticalSpacing = 10; layout.marginHeight = 10; layout.marginWidth = 10; layout.numColumns = 3; setLayout(layout); //get font manager instance FontManager fontManager = FontManager.getInstance(this); //create input field label Label inputLabel = new Label(this, SWT.LEFT); inputLabel.setText(language.getString("ui.plugin.receipt.findreceipt.label.text", "Date:")); inputLabel.setBackground(this.getBackground()); GridData inputLabelGridData = new GridData(); inputLabelGridData.horizontalAlignment = GridData.BEGINNING; inputLabelGridData.verticalAlignment = GridData.CENTER; inputLabel.setLayoutData(inputLabelGridData); //create input field inputField = new Text(this, SWT.SINGLE | SWT.BORDER); GridData inputFieldGridData = new GridData(); inputFieldGridData.grabExcessHorizontalSpace = true; inputFieldGridData.horizontalAlignment = GridData.FILL; inputFieldGridData.verticalAlignment = GridData.CENTER; inputField.setLayoutData(inputFieldGridData); Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd"); String value = sdf.format(cal.getTime()); inputField.setText(value); // create input field keylistener KeyListener keyListener = new KeyAdapter() { public void keyReleased(KeyEvent event) { if (inputField.getText().length() == 6) findSelected(); } }; inputField.addKeyListener(keyListener); //create panel centerStack = new Composite(this, SWT.BORDER); stack = new StackLayout(); centerStack.setLayout(stack); GridData centerData = new GridData(); centerData.grabExcessHorizontalSpace = true; centerData.grabExcessVerticalSpace = true; centerData.horizontalSpan = 2; centerData.horizontalAlignment = GridData.FILL; centerData.verticalAlignment = GridData.FILL; centerStack.setLayoutData(centerData); //create table receiptTable = new Table(centerStack, SWT.SINGLE); receiptTable.setHeaderVisible(false); receiptTable.setLinesVisible(true); //set table as initial top control in stack stack.topControl = receiptTable; TableColumn idColumn = new TableColumn(receiptTable, SWT.LEFT); idColumn.setWidth(50); idColumn.setAlignment(SWT.LEFT); TableColumn dateColumn = new TableColumn(receiptTable, SWT.LEFT); dateColumn.setWidth(140); dateColumn.setAlignment(SWT.LEFT); TableColumn cashierColumn = new TableColumn(receiptTable, SWT.RIGHT); cashierColumn.setWidth(50); cashierColumn.setAlignment(SWT.RIGHT); //create receipt info composite createReceiptInfoComposite(); //set focus order using traverse listeners TraverseListener fieldTraverseListener = new TraverseListener() { public void keyTraversed(TraverseEvent e) { receiptTable.setFocus(); e.doit = false; } }; inputField.addTraverseListener(fieldTraverseListener); TraverseListener tableTraverseListener = new TraverseListener() { public void keyTraversed(TraverseEvent e) { if(e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) { inputField.setFocus(); e.doit = false; } } }; receiptTable.addTraverseListener(tableTraverseListener); //add a selection listener to the table SelectionListener tableSelectionListener = new SelectionListener() { public void widgetSelected(SelectionEvent arg0) { // ignored } public void widgetDefaultSelected(SelectionEvent arg0) { int index = receiptTable.getSelectionIndex(); if (index != -1) showReceipt(index); } }; receiptTable.addSelectionListener(tableSelectionListener); }//end init() private void createReceiptInfoComposite() { //get fontmanager instance FontManager fontManager = FontManager.getInstance(this); //create receipt info composite receiptInfo = new Composite(centerStack, SWT.NORMAL); receiptInfo.setBackground(getBackground()); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2; gridLayout.verticalSpacing = 10; receiptInfo.setLayout(gridLayout); // create receipt info header label receiptIDText= new Label(receiptInfo, SWT.LEFT); receiptIDText.setFont(fontManager.getDefaultBoldFont()); receiptIDText.setBackground(getBackground()); GridData receiptIDTextData = new GridData(); receiptIDTextData.horizontalAlignment = GridData.BEGINNING; receiptIDTextData.verticalAlignment = GridData.CENTER; receiptIDText.setLayoutData(receiptIDTextData); receiptIDText.setText(language.getString( "ui.plugin.receipt.findreceipt.receiptid.text", "Receipt:")); receiptId = new Label(receiptInfo, SWT.LEFT); receiptId.setBackground(getBackground()); GridData receiptIdData = new GridData(); receiptIdData.horizontalAlignment = GridData.BEGINNING; receiptIdData.verticalAlignment = GridData.CENTER; receiptId.setLayoutData(receiptIdData); receiptDateText= new Label(receiptInfo, SWT.RIGHT); receiptDateText.setFont(fontManager.getDefaultBoldFont()); receiptDateText.setBackground(getBackground()); GridData receiptDateTextData = new GridData(); receiptDateTextData.horizontalAlignment = GridData.BEGINNING; receiptDateTextData.verticalAlignment = GridData.CENTER; receiptDateText.setLayoutData(receiptDateTextData); receiptDateText.setText(language.getString( "ui.plugin.receipt.findreceipt.date.text", "Date:")); receiptDate = new Label(receiptInfo, SWT.RIGHT); receiptDate.setBackground(getBackground()); GridData receiptDateData = new GridData(); receiptDateData.horizontalAlignment = GridData.BEGINNING; receiptDateData.verticalAlignment = GridData.CENTER; receiptDate.setLayoutData(receiptDateData); receiptAmountText = new Label(receiptInfo, SWT.LEFT); receiptAmountText.setFont(fontManager.getDefaultBoldFont()); receiptAmountText.setBackground(getBackground()); GridData receiptAmountTextData = new GridData(); receiptAmountTextData.horizontalAlignment = GridData.BEGINNING; receiptAmountTextData.verticalAlignment = GridData.CENTER; receiptAmountText.setLayoutData(receiptAmountTextData); receiptAmountText.setText(language.getString( "ui.plugin.receipt.findreceipt.subtotal.text", "Total:")); receiptAmount = new Label(receiptInfo, SWT.LEFT); receiptAmount.setBackground(getBackground()); GridData receiptAmountData = new GridData(); receiptAmountData.horizontalAlignment = GridData.BEGINNING; receiptAmountData.verticalAlignment = GridData.CENTER; receiptAmount.setLayoutData(receiptAmountData); receiptCashierText = new Label(receiptInfo, SWT.LEFT); receiptCashierText.setFont(fontManager.getDefaultBoldFont()); receiptCashierText.setBackground(getBackground()); GridData receiptCashierTextData = new GridData(); receiptCashierTextData.horizontalAlignment = GridData.BEGINNING; receiptCashierTextData.verticalAlignment = GridData.CENTER; receiptCashierText.setLayoutData(receiptCashierTextData); receiptCashierText.setText(language.getString( "ui.plugin.receipt.findreceipt.cashier.text", "Cashier:")); receiptCashier = new Label(receiptInfo, SWT.LEFT); receiptCashier.setBackground(getBackground()); GridData receiptCashierData = new GridData(); receiptCashierData.horizontalAlignment = GridData.BEGINNING; receiptCashierData.verticalAlignment = GridData.CENTER; receiptCashierData.grabExcessHorizontalSpace = true; receiptCashier.setLayoutData(receiptCashierData); //create composite for the buttons Composite buttonComposite = new Composite(receiptInfo, SWT.NORMAL); buttonComposite.setLayout(new FillLayout()); GridData buttonCompositeData = new GridData(); buttonCompositeData.horizontalAlignment = GridData.CENTER; buttonCompositeData.verticalAlignment = GridData.END; buttonCompositeData.horizontalSpan = 2; buttonCompositeData.grabExcessVerticalSpace = true; buttonComposite.setLayoutData(buttonCompositeData); //back button receiptInfoBackButton = new Button(buttonComposite, SWT.PUSH); receiptInfoBackButton.setText(language.getString( "ui.plugin.receipt.findreceipt.string1.text", "Back")); receiptInfoBackButton.setBackground(receiptInfo.getBackground()); Listener backButtonListener = new Listener() { public void handleEvent(Event arg0) { receiptInfoBackSelected(); } }; receiptInfoBackButton.addListener(SWT.Selection, backButtonListener); //add to receipt button receiptInfoToRegisterButton = new Button(buttonComposite, SWT.PUSH); receiptInfoToRegisterButton.setText(language.getString( "ui.plugin.receipt.findreceipt.string2.text", "Continue")); receiptInfoToRegisterButton.setBackground(receiptInfo.getBackground()); Listener toRegisterButtonListener = new Listener() { public void handleEvent(Event arg0) { receiptInfoToRegisterSelected(); } }; receiptInfoToRegisterButton.addListener(SWT.Selection, toRegisterButtonListener); //add traverse listeners to handle focus order TraverseListener backButtonTraverseListener = new TraverseListener() { public void keyTraversed(TraverseEvent e) { if(e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) { receiptInfoToRegisterButton.setFocus(); e.doit = false; } } }; receiptInfoBackButton.addTraverseListener(backButtonTraverseListener); TraverseListener toRegisterButtonTraverseListener = new TraverseListener() { public void keyTraversed(TraverseEvent e) { if(e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) { receiptInfoBackButton.setFocus(); e.doit = false; } } }; receiptInfoToRegisterButton.addTraverseListener(toRegisterButtonTraverseListener); } /** * Invoked when user selects the back button in the product info composite * */ private void receiptInfoBackSelected() { stack.topControl = receiptTable; centerStack.layout(); } /** * Invoked when user selects the 'to register' button in the product info composite * */ private void receiptInfoToRegisterSelected() { ReceiptTableItemData receipt = getSelectedReceipt(); listener.addReceiptSelected(receipt); } public void setInputValue(String value) { inputField.setText(value); } public void setFocusInInput() { inputField.setFocus(); } public void setFocusInTable() { receiptTable.setFocus(); } public void clearTable() { receiptTable.removeAll(); } /** * Invoked when user presses enter in the input field. * Calls listeners findSelected(..) method */ private void findSelected() { String value = inputField.getText(); listener.findSelected(value); } public interface FindReceiptUIListener { public void findSelected(String value); public void addReceiptSelected(ReceiptTableItemData receipt); } /** * Adds a receipt to table * * @param receipt, amount */ public void addReceipt(ReceiptData receipt, Amount amount) { // create a new table item TableItem newItem = new TableItem(receiptTable, SWT.NONE); String date = receipt.getAddedDate().toString(); String[] text = {receipt.getReceiptId(), date, receipt.getCashier()}; newItem.setText(text); // newItem.setData(new ReceiptTableItemData(receipt, receiptRow)); newItem.setData(new ReceiptTableItemData(receipt, amount)); } /** * Shows more info about product at given table index * * @param tableIndex */ public void showReceipt(int tableIndex) { // get selected table item TableItem item = receiptTable.getItem(tableIndex); if(item != null) { // get receipt data ReceiptTableItemData receipt = (ReceiptTableItemData)item.getData(); // set receipt info receiptId.setText(receipt.receiptData.getReceiptId()); SimpleDateFormat sdf = new SimpleDateFormat("yyMMd hh:mm:ss"); String date = sdf.format(receipt.receiptData.getAddedDate()); receiptDate.setText(date); receiptCashier.setText(receipt.receiptData.getCashier()); receiptAmount.setText(receipt.amountTotal.toString()); receiptInfo.layout(); // show product info stack.topControl = receiptInfo; centerStack.layout(); receiptInfoToRegisterButton.setFocus(); } } /** * Returns the product that is selected in the table * * @return */ public ReceiptTableItemData getSelectedReceipt() { int index = receiptTable.getSelectionIndex(); if(index != -1) { // get selected table item TableItem item = receiptTable.getItem(index); // get product data ReceiptTableItemData receipt = (ReceiptTableItemData)item.getData(); return receipt; } else return null; } /** * Inner public class representing the receipt data inside a table item * * @author anba */ public class ReceiptTableItemData { public ReceiptData receiptData; public String recId; public Amount amountTotal; public ReceiptTableItemData(ReceiptData receipt, Amount amount) { receiptData = receipt; recId = receipt.getReceiptId(); amountTotal = amount; } } } |