/** Load data. */ private ArrayList loadData() { try { ArrayList vos = new ArrayList(); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("orders.txt"))); String line = null; SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); OrdersVO vo = null; String[] t = null; while ((line = br.readLine()) != null) { t = line.split(";"); vo = new OrdersVO(); vos.add(vo); vo.setOrderDate(sdf.parse(t[0])); vo.setCategory(t[1]); vo.setSubCategory(t[2]); vo.setCountry(t[3]); vo.setZone(t[4]); vo.setAgent(t[5]); vo.setItem(t[6]); vo.setSellQty(new BigDecimal(t[7])); vo.setSellAmount(new BigDecimal(t[8])); } br.close(); return vos; } catch (Exception ex) { ex.printStackTrace(); return new ArrayList(); } }
/** Load data from server and construct panel content. */ public final void reloadData(DocumentsFrame frame) { try { // remove all panel content... clearData(); frame.getGrid().getOtherGridParams().put(ApplicationConsts.PROPERTIES_FILTER, filters); // retrieve customized input controls list... GridParams gridParams = new GridParams(); DefaultMutableTreeNode node = frame.getHierarTreePanel().getSelectedNode(); if (node != null) { HierarchyLevelVO vo = (HierarchyLevelVO) node.getUserObject(); HierarchyLevelVO root = (HierarchyLevelVO) ((DefaultMutableTreeNode) node.getRoot()).getUserObject(); gridParams .getOtherGridParams() .put(ApplicationConsts.PROGRESSIVE_HIE01, vo.getProgressiveHIE01()); gridParams .getOtherGridParams() .put(ApplicationConsts.ROOT_PROGRESSIVE_HIE01, root.getProgressiveHIE01()); } else gridParams.getOtherGridParams().remove(ApplicationConsts.PROGRESSIVE_HIE01); gridParams .getOtherGridParams() .put( ApplicationConsts.PROGRESSIVE_HIE02, frame.getHierarTreePanel().getProgressiveHIE02()); gridParams.getOtherGridParams().put(ApplicationConsts.LOAD_ANCIENTS, Boolean.TRUE); Response res = ClientUtils.getData("loadLevelProperties", gridParams); if (res.isError()) { JOptionPane.showMessageDialog( ClientUtils.getParentFrame(this), ClientSettings.getInstance().getResources().getResource("Error while loading data") + ":\n" + res.getErrorMessage(), ClientSettings.getInstance().getResources().getResource("Loading Data Error"), JOptionPane.ERROR_MESSAGE); return; } ArrayList rows = ((VOListResponse) res).getRows(); if (rows.size() > 0) { // adding customized input controls... LevelPropertyVO inputControlInfo = null; int row = 0; int col = 0; LabelControl labelControl = null; TextControl textControl = null; DateControl dateControl = null; NumericControl numericControl = null; for (int i = 0; i < rows.size(); i++) { inputControlInfo = (LevelPropertyVO) rows.get(i); labelControl = new LabelControl(); labelControl.setText(inputControlInfo.getDescriptionSYS10()); innerPanel.add( labelControl, new GridBagConstraints( col++, row, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); if (inputControlInfo.getPropertyTypeDOC21().equals(ApplicationConsts.TYPE_TEXT)) { textControl = new TextControl(); textControl.setMaxCharacters(255); textControl.setLinkLabel(labelControl); innerPanel.add( textControl, new GridBagConstraints( col, row, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 15), 0, 0)); textControl.addFocusListener(new ControlFocusListener(inputControlInfo, textControl)); } else if (inputControlInfo.getPropertyTypeDOC21().equals(ApplicationConsts.TYPE_DATE)) { dateControl = new DateControl(); dateControl.setLinkLabel(labelControl); innerPanel.add( dateControl, new GridBagConstraints( col, row, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 15), 0, 0)); dateControl.addFocusListener(new ControlFocusListener(inputControlInfo, dateControl)); } else if (inputControlInfo.getPropertyTypeDOC21().equals(ApplicationConsts.TYPE_NUM)) { numericControl = new NumericControl(); numericControl.setDecimals(5); numericControl.setLinkLabel(labelControl); innerPanel.add( numericControl, new GridBagConstraints( col, row, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 15), 0, 0)); numericControl.addFocusListener( new ControlFocusListener(inputControlInfo, numericControl)); } col++; if (col >= 2) { innerPanel.add( new JPanel(), new GridBagConstraints( col, row, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); row++; col = 0; } } row++; innerPanel.add( new JPanel(), new GridBagConstraints( col, row, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); innerPanel.add( new JPanel(), new GridBagConstraints( 0, row, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(5, 5, 5, 5), 0, 0)); this.revalidate(); this.repaint(); } } catch (Exception ex) { ex.printStackTrace(); } }
/** Create data. */ private void createData() { try { String[] categories = new String[] {"Hardware", "Software"}; String[][] subCategories = new String[][] { {"PC", "Monitor", "Printer"}, {"O.S.", "IDEs", "Office Appl.", "Database", "Games", "Other SW"} }; String[] agents = new String[] {"Agent 1", "Agent 2", "Agent 3"}; String[] countries = new String[] {"Italy", "France", "Germany", "Other"}; String[][] zones = new String[][] { {"North Italy", "Center Italy", "South Italy"}, {"Paris", "Outside Paris"}, {"East", "West"}, {"Iberica Peninsula", "U.K. & Ireland", "Be.Ne.Lux.", "East Europe"} }; HashMap items = new HashMap(); items.put("PC", new String[] {"Dell", "HP"}); items.put("Monitor", new String[] {"LG", "Sony", "Philips"}); items.put("Printer", new String[] {"HP", "Epson"}); items.put("O.S.", new String[] {"Windows", "Linux", "Mac"}); items.put("IDEs", new String[] {"JBuilder", "IBM RAD", "MS Visual Studio .NET"}); items.put("Office Appl.", new String[] {"MS Office 2007", "Open Office"}); items.put("Database", new String[] {"Oracle", "MS SQLServer", "Sybase", "IBM DB2"}); items.put("Games", new String[] {"Need4Speed", "Fifa"}); items.put("Other SW", new String[] {"Norton AV", "Photoshop"}); FileOutputStream out = new FileOutputStream("orders.txt"); String line = null; int i = 0; Calendar cal = Calendar.getInstance(); cal.set(cal.YEAR, 2007); cal.set(cal.MONTH, 0); cal.set(cal.DAY_OF_MONTH, 1); cal.set(cal.HOUR_OF_DAY, 0); cal.set(cal.MINUTE, 0); cal.set(cal.SECOND, 0); cal.set(cal.MILLISECOND, 0); long t = cal.getTimeInMillis(); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); String date = null; int maxRows = 2000000; String[] ii = null; String[] sub = null; String[] z = null; do { date = sdf.format(new java.util.Date(t)); for (int k1 = 0; k1 < categories.length; k1++) { sub = subCategories[k1]; for (int k2 = 0; k2 < sub.length; k2++) { if (i >= maxRows) break; for (int k3 = 0; k3 < countries.length; k3++) { z = zones[k3]; for (int k4 = 0; k4 < z.length; k4++) for (int k5 = 0; k5 < agents.length; k5++) { if (i >= maxRows) break; ii = (String[]) items.get(sub[k2]); for (int k6 = 0; k6 < ii.length; k6++) { if (i >= maxRows) break; line = date + ";" + categories[k1] + ";" + sub[k2] + ";" + countries[k3] + ";" + z[k4] + ";" + agents[k5] + ";" + ii[k6] + ";" + new BigDecimal(Math.random() * 10) .setScale(0, BigDecimal.ROUND_HALF_UP) + ";" + new BigDecimal(Math.random() * 1000) .setScale(2, BigDecimal.ROUND_HALF_UP) + ";" + "\n"; out.write(line.getBytes()); out.flush(); i++; } } } } } t += 86400000; } while (i < maxRows); out.close(); } catch (Exception ex) { ex.printStackTrace(); } }