1 package com.calipso.reportgenerator.userinterface; 2 3 import com.calipso.reportgenerator.common.*; 4 import com.calipso.reportgenerator.userinterface.PivotTable; 5 6 import javax.swing.*; 7 import java.awt.*; 8 import java.awt.event.ActionListener ; 9 import java.awt.event.ActionEvent ; 10 import java.util.Vector ; 11 import java.util.List ; 12 import java.util.Iterator ; 13 14 18 19 public class DimensionValuesSearcherUI extends JDialog implements ActionListener { 20 21 private DimensionValuesSearcher searcher; 22 private ReportResult reportResult; 23 private JComboBox cboDimension; 24 private JTextField tfValue; 25 private JRadioButton btRow; 26 private JRadioButton btColumn; 27 private JButton btAccept; 28 private JButton btCancel; 29 private int searchLastIndex; 30 31 39 public DimensionValuesSearcherUI(Frame owner, boolean modal, ReportResult reportResult, PivotTable table, ReportGeneratorConfiguration conf) throws HeadlessException { 40 super(owner, modal); 41 Image icon = conf.getImage("icon"); 42 if(icon != null) { 43 owner.setIconImage(icon); 44 } 45 this.reportResult = reportResult; 46 searcher = new DimensionValuesSearcher(table); 47 searchLastIndex = 0; 48 setTitle(LanguageTraslator.traslate("332")); 49 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 50 setLocation((screenSize.width - 250) / 2, (screenSize.height - 200) / 2); 51 initialize(reportResult.getReportSpec().getDimensions()); 52 } 53 54 58 private void initialize(Object [] dimensions) { 59 getContentPane().setLayout(new BorderLayout()); 60 JPanel centerPanel = new JPanel(new BorderLayout()); 61 JPanel valuesSearchingPanel = new JPanel(new GridLayout(2, 2)); 62 valuesSearchingPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), com.calipso.reportgenerator.common.LanguageTraslator.traslate("282"))); 63 JLabel lbDimension = new JLabel(com.calipso.reportgenerator.common.LanguageTraslator.traslate("280")); 64 cboDimension = new JComboBox(getDimensions(dimensions)); 65 JLabel lbValue = new JLabel(com.calipso.reportgenerator.common.LanguageTraslator.traslate("281")); 66 tfValue = new JTextField(); 67 valuesSearchingPanel.add(lbDimension); 68 valuesSearchingPanel.add(cboDimension); 69 valuesSearchingPanel.add(lbValue); 70 valuesSearchingPanel.add(tfValue); 71 JPanel typeSearchingPanel = new JPanel(new GridLayout(1, 2)); 72 typeSearchingPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), com.calipso.reportgenerator.common.LanguageTraslator.traslate("191"))); 73 ButtonGroup btGroup = new ButtonGroup(); 74 btRow = new JRadioButton(com.calipso.reportgenerator.common.LanguageTraslator.traslate("110")); 75 btRow.addActionListener(this); 76 btColumn = new JRadioButton(com.calipso.reportgenerator.common.LanguageTraslator.traslate("111")); 77 btColumn.addActionListener(this); 78 btRow.setSelected(true); 79 btGroup.add(btRow); 80 btGroup.add(btColumn); 81 typeSearchingPanel.add(btRow); 82 typeSearchingPanel.add(btColumn); 83 centerPanel.add(valuesSearchingPanel, BorderLayout.CENTER); 84 centerPanel.add(typeSearchingPanel, BorderLayout.SOUTH); 85 JPanel southPanel = new JPanel(new BorderLayout()); 86 JPanel decidePanel = new JPanel(); 87 JPanel decideEastPanel = new JPanel(new FlowLayout()); 88 btAccept = new JButton(com.calipso.reportgenerator.common.LanguageTraslator.traslate("284")); 89 btAccept.addActionListener(this); 90 btCancel = new JButton(com.calipso.reportgenerator.common.LanguageTraslator.traslate("132")); 91 btCancel.addActionListener(this); 92 decideEastPanel.add(btAccept); 93 decideEastPanel.add(btCancel); 94 decidePanel.add(decideEastPanel, BorderLayout.WEST); 95 southPanel.add(decidePanel, BorderLayout.CENTER); 96 getContentPane().add(centerPanel, BorderLayout.CENTER); 97 getContentPane().add(southPanel, BorderLayout.SOUTH); 98 pack(); 99 } 100 101 107 private Vector getDimensions(Object [] dimensions) { 108 Vector elements = new Vector (); 109 for(int i = 0 ; i < dimensions.length ; i++) { 110 ReportDimensionSpec dimensionSpec = (ReportDimensionSpec) dimensions[i]; 111 elements.add(dimensionSpec.getCaption()); 112 } 113 return elements; 114 } 115 116 121 private boolean getSearchType() { 122 if(btRow.isSelected()) { 123 return true; 124 } 125 return false; 126 } 127 128 136 private int getDimensionIndex(List dimensions, String dimension) { 137 Iterator iterator = dimensions.iterator(); 138 for(int i = 0 ; iterator.hasNext() ; i++) { 139 QueryDimension queryDimension = (QueryDimension) iterator.next(); 140 if(reportResult.getReportSpec().getDimensionFromName(queryDimension.getName()).getCaption().equals(dimension)) { 141 return i; 142 } 143 } 144 return -1; 145 } 146 147 151 public void actionPerformed(ActionEvent e) { 152 if(e.getSource() == btAccept) { 153 findValue(); 154 return; 155 } 156 if(e.getSource() == btCancel) { 157 dispose(); 158 return; 159 } 160 } 161 162 165 private void findValue() { 166 if(getSearchType()) { 167 int index = getDimensionIndex(reportResult.getReportQuery().getRowDimensions(), cboDimension.getSelectedItem().toString()); 168 if(index != -1){ 169 searchLastIndex = searcher.searchDimensionValues(searchLastIndex, tfValue.getText(), index, true); 170 } 171 if(searchLastIndex == -1 || index == -1) { 172 searchLastIndex = 0; 173 JOptionPane.showMessageDialog(this, com.calipso.reportgenerator.common.LanguageTraslator.traslate("285") + tfValue.getText().trim()); 174 } 175 } else { 176 int index = getDimensionIndex(reportResult.getReportQuery().getColumnDimensions(), cboDimension.getSelectedItem().toString()); 177 if(index != -1){ 178 searchLastIndex = searcher.searchDimensionValues(searchLastIndex, tfValue.getText(), index, false); 179 } 180 if(searchLastIndex == -1 || index == -1) { 181 searchLastIndex = 0; 182 JOptionPane.showMessageDialog(this, com.calipso.reportgenerator.common.LanguageTraslator.traslate("285") + tfValue.getText().trim()); 183 } 184 } 185 } 186 } 187 | Popular Tags |