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.ResourceBundle;
021: import java.util.Enumeration;
022: import java.util.Hashtable;
023: import java.util.Locale;
024: import java.util.Map;
025:
026: import javax.swing.DefaultComboBoxModel;
027:
028: import net.xoetrope.swing.XButton;
029: import net.xoetrope.swing.XDialog;
030: import net.xoetrope.swing.XEdit;
031: import net.xoetrope.swing.XLabel;
032: import net.xoetrope.swing.XComboBox;
033: import net.xoetrope.xui.XPage;
034:
035: import org.ofbiz.base.util.UtilMisc;
036: import org.ofbiz.base.util.UtilProperties;
037: import org.ofbiz.pos.PosTransaction;
038:
039: public class PaidInOut extends XPage {
040:
041: /**
042: * To allow creating or choising a reason for a PAID IN or OUT
043: */
044: public static final String module = PaidInOut.class.getName();
045: protected static PosScreen m_pos = null;
046: protected XDialog m_dialog = null;
047: protected XLabel m_amoutLabel = null;
048: protected XEdit m_amountEdit = null;
049: protected XLabel m_reasonLabel = null;
050: static protected Hashtable m_reasonMap = new Hashtable();
051: protected XComboBox m_reasonsCombo = null;
052: protected XButton m_cancel = null;
053: protected XButton m_ok = null;
054: protected DefaultComboBoxModel m_comboModel = null;
055: protected static PosTransaction m_trans = null;
056: protected String m_type = null;
057:
058: //TODO : make getter and setter for members (ie m_*) if needed (extern calls). For that in Eclipse use Source/Generate Getters and setters
059:
060: public PaidInOut(PosTransaction trans, PosScreen page, String type) {
061: m_trans = trans;
062: m_pos = page;
063: m_type = type;
064: }
065:
066: public Map openDlg() {
067: m_dialog = (XDialog) pageMgr.loadPage(m_pos.getScreenLocation()
068: + "/dialog/PaidInOut");
069: m_amountEdit = (XEdit) m_dialog.findComponent("amountEdit");
070: m_reasonsCombo = (XComboBox) m_dialog
071: .findComponent("ReasonsCombo");
072:
073: m_cancel = (XButton) m_dialog.findComponent("BtnCancel");
074: m_ok = (XButton) m_dialog.findComponent("BtnOk");
075: m_amoutLabel = (XLabel) m_dialog.findComponent("amoutLabel");
076: m_reasonLabel = (XLabel) m_dialog.findComponent("reasonLabel");
077: addMouseHandler(m_cancel, "cancel");
078: addMouseHandler(m_ok, "verify");
079:
080: m_comboModel = new DefaultComboBoxModel();
081: ResourceBundle reasons = null;
082: Enumeration reasonsKeys = null;
083:
084: if (m_type.equals("IN")) {
085: m_dialog.setCaption(UtilProperties.getMessage("pos",
086: "PaidInTitle", Locale.getDefault()));
087: reasons = ResourceBundle.getBundle(m_pos
088: .getScreenLocation()
089: + "/dialog/PaidIn", Locale.getDefault());
090: reasonsKeys = reasons.getKeys();
091: } else { // OUT
092: m_dialog.setCaption(UtilProperties.getMessage("pos",
093: "PaidOutTitle", Locale.getDefault()));
094: reasons = ResourceBundle.getBundle(m_pos
095: .getScreenLocation()
096: + "/dialog/PaidOut", Locale.getDefault());
097: reasonsKeys = reasons.getKeys();
098: }
099:
100: while (reasonsKeys.hasMoreElements()) {
101: String key = (String) reasonsKeys.nextElement();
102: String val = reasons.getString(key);
103: m_comboModel.addElement(val);
104: }
105: m_reasonsCombo.setModel(m_comboModel);
106: m_reasonsCombo.setToolTipText(UtilProperties.getMessage("pos",
107: "CreateOrChooseReasonInOut", Locale.getDefault()));
108:
109: m_dialog.pack();
110: m_reasonsCombo.requestFocusInWindow();
111: m_dialog.showDialog(this );
112: return UtilMisc.toMap("amount", m_amountEdit.getText(),
113: "reason", (String) m_reasonsCombo.getSelectedItem());
114: }
115:
116: public synchronized void cancel() {
117: if (wasMouseClicked()) {
118: m_dialog.closeDlg();
119: }
120: }
121:
122: public synchronized void verify() {
123: if (wasMouseClicked()) {
124: String amount = m_amountEdit.getText();
125: String reason = (String) m_reasonsCombo.getSelectedItem();
126: if (null != amount && amount.length() > 0 && null != reason
127: && reason.length() > 0) {
128: m_dialog.closeDlg();
129: }
130: }
131: }
132: }
|