Author: jleroux
Date: Mon Nov 2 23:22:46 2009 New Revision: 832186 URL: http://svn.apache.org/viewvc?rev=832186&view=rev Log: Some generics in POS Modified: ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/ManagerEvents.java ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/ConfigureItem.java Modified: ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/ManagerEvents.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/ManagerEvents.java?rev=832186&r1=832185&r2=832186&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/ManagerEvents.java (original) +++ ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/ManagerEvents.java Mon Nov 2 23:22:46 2009 @@ -21,12 +21,11 @@ import java.math.BigDecimal; import java.sql.Timestamp; import java.text.DecimalFormat; -import java.text.ParseException; -import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import javolution.util.FastMap; import net.xoetrope.xui.XProjectManager; import org.ofbiz.base.util.Debug; @@ -432,7 +431,7 @@ } PaidInOut PaidInOut = new PaidInOut(trans, pos, type); - Map mapInOut = PaidInOut.openDlg(); + Map<String, String> mapInOut = PaidInOut.openDlg(); if (null != mapInOut.get("amount")) { String amount = (String) mapInOut.get("amount"); BigDecimal amt = ZERO; @@ -526,7 +525,7 @@ } } - Map<String, String> reportMap = new HashMap<String, String>(); + Map<String, String> reportMap = FastMap.newInstance(); String reportTemplate = "totals.txt"; // miscellaneous Modified: ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/ConfigureItem.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/ConfigureItem.java?rev=832186&r1=832185&r2=832186&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/ConfigureItem.java (original) +++ ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/ConfigureItem.java Mon Nov 2 23:22:46 2009 @@ -18,18 +18,20 @@ *******************************************************************************/ package org.ofbiz.pos.screen; -import java.util.Hashtable; +import java.util.ArrayList; +import java.util.EventObject; import java.util.Iterator; import java.util.List; import java.util.Locale; -import java.util.ArrayList; -import java.util.EventObject; +import java.util.Map; + import javax.swing.DefaultListModel; import javax.swing.JList; import javax.swing.ListSelectionModel; -import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javolution.util.FastMap; import net.xoetrope.swing.XButton; import net.xoetrope.swing.XDialog; import net.xoetrope.swing.XList; @@ -46,6 +48,7 @@ import org.ofbiz.product.config.ProductConfigWrapper.ConfigOption; +@SuppressWarnings("serial") public class ConfigureItem extends XPage { /** @@ -69,8 +72,8 @@ { "r4c1", "r4c2", "r4c3", "r4c4" } }; protected ProductConfigWrapper m_pcw = null; - protected ArrayList m_buttonList = null; - protected Hashtable questionHashMap = null; + protected List<XButton> m_buttonList = null; + protected Map<String, Question> questionHashMap = null; public ConfigureItem(ProductConfigWrapper pcw, PosTransaction trans, PosScreen page) { m_pcw = pcw; @@ -91,7 +94,7 @@ m_ok = (XButton) m_dialog.findComponent("BtnOk"); m_reset = (XButton) m_dialog.findComponent("BtnReset"); - XEventHelper.addMouseHandler(this, m_ok, "ok"); + XEventHelper.addMouseHandler(this, m_ok, "OK"); XEventHelper.addMouseHandler(this, m_reset, "reset"); getButtons(); @@ -123,7 +126,7 @@ if (wasMouseClicked()) { EventObject eo = getCurrentEvent(); XButton button = (XButton) eo.getSource(); - Question question = (Question)questionHashMap.get(button.getName()); + Question question = questionHashMap.get(button.getName()); question.buttonClicked(); showItem(); m_dialog.repaint(); @@ -132,7 +135,6 @@ } public synchronized void listPressed() { - EventObject eo = getCurrentEvent(); showItem(); m_dialog.repaint(); return; @@ -158,19 +160,12 @@ GenericValue gv = m_pcw.getProduct(); listModel.addElement(gv.get("description")); - List questions = m_pcw.getQuestions(); - if (questions==null) ; // no questions, we shouldn't be here - else{ - Iterator iter = questions.iterator(); - while (iter.hasNext()) { - ConfigItem question = (ConfigItem)iter.next(); - List options = question.getOptions(); - Iterator itero = options.iterator(); - while (itero.hasNext()) { - ConfigOption configoption = (ConfigOption)itero.next(); - if (configoption.isSelected()) { - listModel.addElement(" "+configoption.getDescription()); - } + List<ConfigItem> questions = m_pcw.getQuestions(); + for (ConfigItem question : questions) { + List<ConfigOption> options = question.getOptions(); + for (ConfigOption configoption : options) { + if (configoption.isSelected()) { + listModel.addElement(" "+configoption.getDescription()); } } } @@ -181,16 +176,16 @@ private void displayQuestions() { QuestionFactory qf = new QuestionFactory(); - questionHashMap = new Hashtable(); + questionHashMap = FastMap.newInstance(); - List questions = m_pcw.getQuestions(); + List<ConfigItem> questions = m_pcw.getQuestions(); if (questions==null) ; // no questions, we shouldn't be here else{ - Iterator iter = questions.iterator(); - Iterator buttons = m_buttonList.iterator(); + Iterator<ConfigItem> iter = questions.iterator(); + Iterator<XButton> buttons = m_buttonList.iterator(); while (iter.hasNext()) { - Question buttonQuestion = qf.get((ConfigItem)iter.next()); - XButton button = (XButton)buttons.next(); + Question buttonQuestion = qf.get(iter.next()); + XButton button = buttons.next(); questionHashMap.put(button.getName(), buttonQuestion); buttonQuestion.setupButton(button); if (buttonQuestion instanceof ListQuestion) { @@ -203,7 +198,7 @@ } private void getButtons() { - ArrayList buttonList = new ArrayList(); + ArrayList<XButton> buttonList = new ArrayList<XButton>(); for(String[] buttonSingleArray : buttonArray) { for(String buttonName : buttonSingleArray) { //Debug.logInfo("ButtonName: "+buttonName, module); @@ -214,37 +209,37 @@ m_buttonList = buttonList; } - private void debugQuestions() { - //Debug.logInfo("debugQuestions",module); - GenericValue gv = m_pcw.getProduct(); - - //Debug.logInfo("Product: " +gv.get("description"), module); - - List questions = m_pcw.getQuestions(); - if (questions==null) return; // no questions, return - - Iterator iter = questions.iterator(); - while (iter.hasNext()) { - ConfigItem question = (ConfigItem)iter.next(); - /*Debug.logInfo("Question: " + question.getQuestion(), module); - Debug.logInfo("IsFirst: "+question.isFirst()+ - ", IsMandatory: "+question.isMandatory()+ - ", IsSelected: "+question.isSelected()+ - ", IsSingleChoice: "+question.isSingleChoice()+ - ", IsStandard: "+question.isStandard(), module);*/ - - List options = question.getOptions(); - Iterator itero = options.iterator(); - - while (itero.hasNext()) { - ConfigOption configoption = (ConfigOption)itero.next(); - /*Debug.logInfo("Found option " + configoption.getDescription(), module); - Debug.logInfo("IsAvailable: "+configoption.isAvailable()+ - ", IsSelected: "+configoption.isSelected(), module);*/ - //configoption.getComponents() - } - } - } +// private void debugQuestions() { +// //Debug.logInfo("debugQuestions",module); +// GenericValue gv = m_pcw.getProduct(); +// +// //Debug.logInfo("Product: " +gv.get("description"), module); +// +// List questions = m_pcw.getQuestions(); +// if (questions==null) return; // no questions, return +// +// Iterator iter = questions.iterator(); +// while (iter.hasNext()) { +// ConfigItem question = (ConfigItem)iter.next(); +// /*Debug.logInfo("Question: " + question.getQuestion(), module); +// Debug.logInfo("IsFirst: "+question.isFirst()+ +// ", IsMandatory: "+question.isMandatory()+ +// ", IsSelected: "+question.isSelected()+ +// ", IsSingleChoice: "+question.isSingleChoice()+ +// ", IsStandard: "+question.isStandard(), module);*/ +// +// List options = question.getOptions(); +// Iterator itero = options.iterator(); +// +// while (itero.hasNext()) { +// ConfigOption configoption = (ConfigOption)itero.next(); +// /*Debug.logInfo("Found option " + configoption.getDescription(), module); +// Debug.logInfo("IsAvailable: "+configoption.isAvailable()+ +// ", IsSelected: "+configoption.isSelected(), module);*/ +// //configoption.getComponents() +// } +// } +// } /* * What are the Question types? @@ -271,7 +266,7 @@ public Question get(ConfigItem question) { - List options = question.getOptions(); + List<ConfigOption> options = question.getOptions(); if (question.isSingleChoice()) { if (options.size()>2) { return new ListButtonQuestion(question); @@ -310,12 +305,12 @@ public void setupButton(XButton button) { this.button = button; - List options = question.getOptions(); + List<ConfigOption> options = question.getOptions(); if (question.isSelected()) { ConfigOption selectedOption = question.getSelected(); showOption = options.indexOf(selectedOption); } - ConfigOption configoption = (ConfigOption)options.get(showOption); + ConfigOption configoption = options.get(showOption); button.setText(configoption.getDescription()); return; } @@ -326,11 +321,11 @@ public void buttonClicked() { //only two choices, if the button is clicked, toggle - List options = question.getOptions(); - ConfigOption unselectedoption = (ConfigOption)options.get(showOption); + List<ConfigOption> options = question.getOptions(); + ConfigOption unselectedoption = options.get(showOption); unselectedoption.setSelected(false); showOption = (showOption+1)%2; - ConfigOption selectedoption = (ConfigOption)options.get(showOption); + ConfigOption selectedoption = options.get(showOption); selectedoption.setSelected(true); button.setText(selectedoption.getDescription()); return; @@ -338,19 +333,20 @@ public void reset() { showOption = 0; - List options = question.getOptions(); + List<ConfigOption> options = question.getOptions(); if (question.isSelected()) { ConfigOption selectedOption = question.getSelected(); showOption = options.indexOf(selectedOption); } - ConfigOption configoption = (ConfigOption)options.get(showOption); + ConfigOption configoption = options.get(showOption); button.setText(configoption.getDescription()); return; } } protected class ListButtonQuestion implements Question, ListQuestion{ - private XButton button = null; + @SuppressWarnings("unused") + private XButton button = null; // FIXME a bit weird, but I have no time to clean it up... private XScrollPane scrollpane = null; private ConfigItem question = null; @@ -361,7 +357,6 @@ public void setupButton(XButton button) { this.button = button; - int showOption = 0; button.setText(question.getQuestion()); return; } @@ -372,12 +367,10 @@ } public void buttonClicked() { - Iterator options = question.getOptions().iterator(); - DefaultListModel listModel = new DefaultListModel(); - - while (options.hasNext()) { - ConfigOption configoption = (ConfigOption)options.next(); + List<ConfigOption> options = question.getOptions(); + + for (ConfigOption configoption : options) { listModel.addElement(configoption.getDescription()); //Debug.logInfo("Found option " + configoption.getDescription(), module); //Debug.logInfo("IsAvailable: "+configoption.isAvailable()+ |
Free forum by Nabble | Edit this page |