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.text.SimpleDateFormat;
021: import java.util.Date;
022: import java.util.Locale;
023:
024: import net.xoetrope.swing.XButton; //import org.ofbiz.pos.screen.XFocusDialog;
025: import net.xoetrope.swing.XEdit;
026: import net.xoetrope.swing.XDialog;
027: import net.xoetrope.xui.XPage;
028:
029: import org.ofbiz.base.util.Debug;
030: import org.ofbiz.base.util.UtilProperties;
031: import org.ofbiz.pos.PosTransaction;
032:
033: public class SaveSale extends XPage {
034:
035: /**
036: * To save a sale. 2 modes : save and keep the current sale or save and clear the current sale.
037: */
038: public static final String module = SaveSale.class.getName();
039: protected static PosScreen m_pos = null;
040: protected XDialog m_dialog = null;
041: protected XEdit m_saleName = null;
042: protected XButton m_cancel = null;
043: protected XButton m_save = null;
044: protected XButton m_saveAndClear = null;
045: protected static PosTransaction m_trans = null;
046: public static SimpleDateFormat sdf = new SimpleDateFormat(
047: UtilProperties.getMessage("pos", "DateTimeFormat", Locale
048: .getDefault()));
049:
050: //TODO : make getter and setter for members (ie m_*) if needed (extern calls). For that in Eclipse use Source/Generate Getters and setters
051:
052: public SaveSale(PosTransaction trans, PosScreen page) {
053: m_trans = trans;
054: m_pos = page;
055: }
056:
057: public void openDlg() {
058: m_dialog = (XDialog) pageMgr.loadPage(m_pos.getScreenLocation()
059: + "/dialog/savesale");
060: m_saleName = (XEdit) m_dialog.findComponent("saleName");
061: //m_dialog.setM_focused(m_saleName);
062: m_saleName.setText(m_pos.session.getUserId() + " "
063: + sdf.format(new Date()));
064: m_dialog.setCaption(UtilProperties.getMessage("pos",
065: "SaveASale", Locale.getDefault()));
066:
067: m_cancel = (XButton) m_dialog.findComponent("BtnCancel");
068: m_save = (XButton) m_dialog.findComponent("BtnSave");
069: m_saveAndClear = (XButton) m_dialog
070: .findComponent("BtnSaveAndClear");
071:
072: addMouseHandler(m_cancel, "cancel");
073: addMouseHandler(m_save, "save");
074: addMouseHandler(m_saveAndClear, "saveAndClear");
075:
076: m_dialog.pack();
077: m_dialog.showDialog(this );
078: }
079:
080: public synchronized void cancel() {
081: if (wasMouseClicked()) {
082: this .m_dialog.closeDlg();
083: }
084: }
085:
086: public synchronized void save() {
087: if (wasMouseClicked()) {
088: String sale = m_saleName.getText();
089: if (null != sale) {
090: saveSale(sale);
091: }
092: }
093: }
094:
095: public synchronized void saveAndClear() {
096: if (wasMouseClicked()) {
097: String sale = m_saleName.getText();
098: if (null != sale) {
099: saveSale(sale);
100: m_trans.voidSale();
101: m_pos.refresh();
102: }
103: }
104: }
105:
106: private void saveSale(String sale) {
107: final ClassLoader cl = this .getClassLoader(m_pos);
108: Thread.currentThread().setContextClassLoader(cl);
109: m_trans.saveSale(sale, m_pos);
110: this .m_dialog.closeDlg();
111: }
112:
113: private ClassLoader getClassLoader(PosScreen pos) {
114: ClassLoader cl = pos.getClassLoader();
115: if (cl == null) {
116: try {
117: cl = Thread.currentThread().getContextClassLoader();
118: } catch (Throwable t) {
119: }
120: if (cl == null) {
121: Debug
122: .log(
123: "No context classloader available; using class classloader",
124: module);
125: try {
126: cl = this .getClass().getClassLoader();
127: } catch (Throwable t) {
128: Debug.logError(t, module);
129: }
130: }
131: }
132: return cl;
133: }
134: }
|