- Timestamp:
- 07/29/11 14:33:59 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swing/DlgInsert.java
r134 r139 29 29 30 30 public class DlgInsert extends JDialog { 31 31 32 32 /** 33 33 * Id for object serialization. … … 43 43 * Launch the application. 44 44 */ 45 public static void showDialog(List<Event<?>> sequences, int selectedIndex, final boolean insertBefore) { 45 public static void showDialog(List<Event<?>> sequences, int selectedIndex, 46 final boolean insertBefore) { 46 47 try { 47 DlgInsert dialog = new DlgInsert(sequences, selectedIndex, insertBefore); 48 DlgInsert dialog = new DlgInsert(sequences, selectedIndex, 49 insertBefore); 48 50 dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 49 51 dialog.setVisible(true); … … 56 58 * Create the dialog. 57 59 */ 58 public DlgInsert(final List<Event<?>> sequences, final int selectedIndex, final boolean insertBefore) { 59 60 public DlgInsert(final List<Event<?>> sequences, final int selectedIndex, 61 final boolean insertBefore) { 62 60 63 final javax.swing.DefaultListModel modelListTargets = new javax.swing.DefaultListModel(); 61 64 62 65 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 63 66 setTitle("Insert testcase"); 64 65 67 66 68 setModal(true); 67 69 setBounds(100, 100, 522, 482); … … 73 75 final JPanel panelTextEquals = new JPanel(); 74 76 final JPanel panelFileEquals = new JPanel(); 75 76 77 77 78 // JComboBox: comboBoxTestcase 78 79 comboBoxTestcase.addActionListener(new ActionListener() { 79 80 public void actionPerformed(ActionEvent arg0) { 80 81 if ("comboBoxChanged".equals(arg0.getActionCommand())) { 81 82 // TextEquals83 if (comboBoxTestcase.getSelectedIndex() == 0) {82 83 // TextEquals 84 if (comboBoxTestcase.getSelectedIndex() == 0) { 84 85 panelTextEquals.setVisible(true); 85 86 panelFileEquals.setVisible(false); 86 87 } 87 // FileEquals88 else if (comboBoxTestcase.getSelectedIndex() == 1) {88 // FileEquals 89 else if (comboBoxTestcase.getSelectedIndex() == 1) { 89 90 panelTextEquals.setVisible(false); 90 91 panelFileEquals.setVisible(true); … … 93 94 } 94 95 }); 95 comboBoxTestcase.setModel(new DefaultComboBoxModel(new String[] {"TextEquals", "OutputFileEquals"})); 96 comboBoxTestcase.setModel(new DefaultComboBoxModel(new String[] { 97 "TextEquals", "OutputFileEquals" })); 96 98 comboBoxTestcase.setSelectedIndex(0); 97 99 comboBoxTestcase.setBounds(128, 11, 178, 20); 98 100 contentPanel.add(comboBoxTestcase); 99 101 // *** 100 101 102 // JLabel 102 103 // JLabel 103 104 JLabel label = new JLabel("Testcase:"); 104 105 label.setBounds(10, 14, 86, 14); 105 106 contentPanel.add(label); 106 107 107 108 JLabel label_1 = new JLabel("Expected value:"); 108 109 label_1.setBounds(10, 11, 83, 14); 109 110 110 111 JLabel label_2 = new JLabel("Target:"); 111 112 label_2.setBounds(10, 38, 86, 14); 112 113 // *** 113 114 114 115 115 // JTextField: textFieldExpectedValue 116 116 textFieldExpectedValue = new JTextField(); … … 118 118 textFieldExpectedValue.setBounds(116, 8, 368, 20); 119 119 // *** 120 121 120 122 121 // JPanel: panel 123 122 panelTextEquals.setLayout(null); … … 127 126 panelTextEquals.add(label_2); 128 127 panelTextEquals.add(textFieldExpectedValue); 129 128 130 129 JScrollPane scrollPane = new JScrollPane(); 131 130 scrollPane.setBounds(116, 36, 368, 163); 132 131 panelTextEquals.add(scrollPane); 133 132 134 133 final JList listTargets = new JList(modelListTargets); 135 134 scrollPane.setViewportView(listTargets); 136 137 for(int i=0; i<sequences.size(); i++) { 138 if(sequences.get(i).getTarget() != " ") modelListTargets.addElement(sequences.get(i).getTarget()); 135 136 for (int i = 0; i < sequences.size(); i++) { 137 if (sequences.get(i).getTarget() != " ") 138 modelListTargets.addElement(sequences.get(i).getTarget()); 139 139 } 140 140 listTargets.setSelectedIndex(0); 141 142 141 143 142 panelFileEquals.setBounds(10, 260, 494, 140); 144 143 contentPanel.add(panelFileEquals); 145 144 panelFileEquals.setLayout(null); 146 145 panelFileEquals.setVisible(false); 147 146 148 147 JLabel lblNewLabel = new JLabel("Actual file:"); 149 148 lblNewLabel.setBounds(10, 11, 89, 14); 150 149 panelFileEquals.add(lblNewLabel); 151 150 152 151 textFieldActualFile = new JTextField(); 153 152 textFieldActualFile.setBounds(10, 36, 474, 20); 154 153 panelFileEquals.add(textFieldActualFile); 155 154 textFieldActualFile.setColumns(10); 156 155 157 156 JButton btnNewButton = new JButton("Search file"); 158 157 btnNewButton.addMouseListener(new MouseAdapter() { 159 158 public void mouseClicked(MouseEvent arg0) { 160 159 final JFileChooser fc = new JFileChooser(); 161 if(fc.showOpenDialog(contentPanel) == 0) { textFieldExpectedFile.setText(fc.getSelectedFile().getAbsolutePath()); } 160 if (fc.showOpenDialog(contentPanel) == 0) { 161 textFieldExpectedFile.setText(fc.getSelectedFile() 162 .getAbsolutePath()); 163 } 162 164 } 163 165 }); 164 166 btnNewButton.setBounds(99, 80, 89, 23); 165 167 panelFileEquals.add(btnNewButton); 166 168 167 169 JLabel lblNewLabel_1 = new JLabel("Expected file:"); 168 170 lblNewLabel_1.setBounds(10, 84, 89, 14); 169 171 panelFileEquals.add(lblNewLabel_1); 170 172 171 173 textFieldExpectedFile = new JTextField(); 172 174 textFieldExpectedFile.setColumns(10); … … 182 184 okButton.addMouseListener(new MouseAdapter() { 183 185 public void mouseClicked(MouseEvent arg0) { 184 185 //FileEquals 186 if(panelFileEquals.isVisible()) { 187 if(textFieldActualFile.getText().length() == 0) JOptionPane.showMessageDialog(null, "Please declare an actual file.", "No actual file declared", JOptionPane.OK_OPTION); 188 else if(! new File(textFieldExpectedFile.getText()).exists()) { 189 if(textFieldExpectedFile.getText().length() == 0) JOptionPane.showMessageDialog(null, "Please choose an expected file.", "No expected file chosen", JOptionPane.OK_OPTION); 190 else JOptionPane.showMessageDialog(null, "The expected file \"" + textFieldActualFile.getText() + "\" does not exist.", "Expected file does not exist", JOptionPane.OK_OPTION); 186 187 // FileEquals 188 if (panelFileEquals.isVisible()) { 189 if (textFieldActualFile.getText().length() == 0) 190 JOptionPane.showMessageDialog(null, 191 "Please declare an actual file.", 192 "No actual file declared", 193 JOptionPane.OK_OPTION); 194 else if (!new File(textFieldExpectedFile.getText()) 195 .exists()) { 196 if (textFieldExpectedFile.getText().length() == 0) 197 JOptionPane.showMessageDialog(null, 198 "Please choose an expected file.", 199 "No expected file chosen", 200 JOptionPane.OK_OPTION); 201 else 202 JOptionPane.showMessageDialog( 203 null, 204 "The expected file \"" 205 + textFieldActualFile 206 .getText() 207 + "\" does not exist.", 208 "Expected file does not exist", 209 JOptionPane.OK_OPTION); 191 210 return; 192 } 193 else { 211 } else { 194 212 FileEqualsReplay file = new FileEqualsReplay(); 195 file.setActualFile(textFieldActualFile.getText()); 196 file.setExpectedFile(textFieldExpectedFile.getText()); 197 198 AssertEvent<FileEqualsReplay> e = new AssertEvent<FileEqualsReplay>("FileEquals"); 213 file.setActualFile(textFieldActualFile 214 .getText()); 215 file.setExpectedFile(textFieldExpectedFile 216 .getText()); 217 218 AssertEvent<FileEqualsReplay> e = new AssertEvent<FileEqualsReplay>( 219 "FileEquals"); 199 220 e.addReplayEvent(file); 200 221 e.setTarget(" "); 201 if(insertBefore) sequences.add(selectedIndex, e); 202 else sequences.add(selectedIndex+1, e); 222 if (insertBefore) 223 sequences.add(selectedIndex, e); 224 else 225 sequences.add(selectedIndex + 1, e); 203 226 } 204 227 } 205 // TextEquals228 // TextEquals 206 229 else { 207 if(textFieldExpectedValue.getText().length() == 0) { 208 JOptionPane.showMessageDialog(null, "\"Expected value\" is missing.", "Expected value", JOptionPane.OK_OPTION); 230 if (textFieldExpectedValue.getText().length() == 0) { 231 JOptionPane 232 .showMessageDialog( 233 null, 234 "\"Expected value\" is missing.", 235 "Expected value", 236 JOptionPane.OK_OPTION); 209 237 return; 210 } 211 else if(listTargets.getSelectedIndex() == -1) { 212 JOptionPane.showMessageDialog(null, "Please select a target.", "No target selected", JOptionPane.OK_OPTION); 238 } else if (listTargets.getSelectedIndex() == -1) { 239 JOptionPane.showMessageDialog(null, 240 "Please select a target.", 241 "No target selected", 242 JOptionPane.OK_OPTION); 213 243 return; 214 } 215 else { 244 } else { 216 245 TextEqualsReplay text = new TextEqualsReplay(); 217 text.setExpectedValue(textFieldExpectedValue.getText()); 218 text.setTarget(modelListTargets.get(listTargets.getSelectedIndex()).toString()); 219 220 AssertEvent<TextEqualsReplay> e = new AssertEvent<TextEqualsReplay>("TextEquals"); 246 text.setExpectedValue(textFieldExpectedValue 247 .getText()); 248 text.setTarget(modelListTargets.get( 249 listTargets.getSelectedIndex()) 250 .toString()); 251 252 AssertEvent<TextEqualsReplay> e = new AssertEvent<TextEqualsReplay>( 253 "TextEquals"); 221 254 e.addReplayEvent(text); 222 255 e.setTarget(" "); 223 if(insertBefore) sequences.add(selectedIndex, e); 224 else sequences.add(selectedIndex+1, e); 256 if (insertBefore) 257 sequences.add(selectedIndex, e); 258 else 259 sequences.add(selectedIndex + 1, e); 225 260 } 226 261 } 227 262 228 263 dispose(); 229 264 } … … 234 269 // *** 235 270 } 236 271 237 272 { 238 273 // JButton: cancelButton 239 274 JButton cancelButton = new JButton("Cancel"); 240 275 cancelButton.addMouseListener(new MouseAdapter() { 241 242 public void mouseClicked(MouseEvent arg0) { dispose(); } 276 277 public void mouseClicked(MouseEvent arg0) { 278 dispose(); 279 } 243 280 }); 244 281 cancelButton.setActionCommand("Cancel");
Note: See TracChangeset
for help on using the changeset viewer.