001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.pos.screen;
019:
020: import java.util.Hashtable;
021: import java.util.Iterator;
022: import java.util.Locale;
023: import java.util.Map;
024:
025: import javax.swing.DefaultListModel;
026: import javax.swing.ListSelectionModel;
027:
028: import net.xoetrope.swing.XButton;
029: import net.xoetrope.swing.XDialog;
030: import net.xoetrope.swing.XList;
031: import net.xoetrope.xui.XPage;
032:
033: import org.ofbiz.base.util.UtilProperties;
034: import org.ofbiz.pos.PosTransaction;
035:
036: public class SelectProduct extends XPage {
037:
038: /**
039: * To choose a product in a list of products whith the same bar code
040: */
041: public static final String module = SelectProduct.class.getName();
042: protected static PosScreen m_pos = null;
043: protected XDialog m_dialog = null;
044: static protected Hashtable m_productsMap = new Hashtable();
045: protected XList m_productsList = null;
046: protected XButton m_cancel = null;
047: protected XButton m_select = null;
048: protected DefaultListModel m_listModel = null;
049: protected static PosTransaction m_trans = null;
050: protected static String m_productIdSelected = null;
051:
052: //TODO : make getter and setter for members (ie m_*) if needed (extern calls). For that in Eclipse use Source/Generate Getters and setters
053:
054: public SelectProduct(Hashtable saleMap, PosTransaction trans,
055: PosScreen page) {
056: m_productsMap.putAll(saleMap);
057: m_trans = trans;
058: m_pos = page;
059: }
060:
061: public String openDlg() {
062: XDialog dlg = (XDialog) pageMgr.loadPage(m_pos
063: .getScreenLocation()
064: + "/dialog/SelectProduct");
065: m_dialog = dlg;
066: dlg.setCaption(UtilProperties.getMessage("pos",
067: "SelectAProduct", Locale.getDefault()));
068: //dlg.setModal(true);
069: m_productsList = (XList) dlg.findComponent("productsList");
070: addMouseHandler(m_productsList, "DoubleClick");
071:
072: m_cancel = (XButton) dlg.findComponent("BtnCancel");
073: m_select = (XButton) dlg.findComponent("BtnSelect");
074: addMouseHandler(m_cancel, "cancel");
075: addMouseHandler(m_select, "selectProduct");
076:
077: m_listModel = new DefaultListModel();
078: for (Iterator i = m_productsMap.entrySet().iterator(); i
079: .hasNext();) {
080: Object o = i.next();
081: Map.Entry entry = (Map.Entry) o;
082: String val = entry.getValue().toString();
083: m_listModel.addElement(val);
084: }
085: m_productsList.setModel(m_listModel);
086: m_productsList.setVisibleRowCount(-1);
087: m_productsList.ensureIndexIsVisible(m_productsList
088: .getItemCount());
089: m_productsList
090: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
091: m_productsList.setToolTipText(UtilProperties.getMessage("pos",
092: "SelectProductListDblClickTip", Locale.getDefault()));
093:
094: dlg.pack();
095: dlg.showDialog(this );
096: return m_productIdSelected;
097: }
098:
099: public synchronized void DoubleClick() {
100: if (wasMouseDoubleClicked()) {
101: selectProductId();
102: }
103: }
104:
105: public synchronized void cancel() {
106: if (wasMouseClicked()) {
107: closeDlg();
108: }
109: }
110:
111: public synchronized void selectProduct() {
112: if (wasMouseClicked()) {
113: selectProductId();
114: }
115: }
116:
117: private void selectProductId() {
118: if (null != m_productsList.getSelectedValue()) {
119: String product = (String) m_productsList.getSelectedValue();
120: Iterator i = m_productsMap.entrySet().iterator();
121: while (i.hasNext()) {
122: Object o = i.next();
123: Map.Entry entry = (Map.Entry) o;
124: String val = entry.getValue().toString();
125: if (val.equals(product)) {
126: m_productIdSelected = entry.getKey().toString();
127: }
128: }
129: }
130: closeDlg();
131: }
132:
133: private void closeDlg() {
134: m_dialog.closeDlg();
135: }
136: }
|